Mail Archives: djgpp/1995/03/26/00:53:44
Amazingly enough PhishFan said:
> I keep getting "Segmentation Faults (errors???)" every time I
> try to run my code (using GO32 to run the program). This error ONLY
> occurs when I try to do something like allocate memory (ie. malloc) or
> maybe when using strcpy to copy strings referenced by pointers etc..
>
> It seems like I'm missing some simple command line switch with go32,
> since the same exact program runs fine on the actual SUN OS.
Just because a program appears to run fine on a certain system,
doesn't mean that it's correct.
It sounds like your program is at fault. Some things to check:
That you're not freeing something twice. That all calls to
malloc() succeed. That you don't have any fence post errors (ie,
forgetting to allocate space for \0 in a string).
Also, since you mention strings, are you perhaps trying to
initialize a string within a declaration, then strying to write
into that string? if so, don't. "constants are meant to be
constants" as the gcc manual says. GCC tries to prevent you from
doing that. (you can check this by compiling with
-fwritable-strings and see if your error goes away; if it does,
you should prolly change your coding style because you'll most
likely run into bugs later).
At anyrate, the most likely suspect is your code.
I'd suggest using a debugging malloc to help track things down.
The GNU malloc package on prep.ai.mit.edu in pub/gnu/.... would
work (I think djgpp comes with the BSD malloc package by default,
which is more freely distributable than the GNU malloc is).
Another package that is actually a wrapper around malloc rather
than a drop in replacement can be found in snippets package, an
assortment of useful C routines. Check your favorite SimTel site
(where you pickedup djgpp) and check out .../msdos/c/snip9404.zip
(i think that's the file name).
mrc
--
Mike Castle .-=NEXUS=-. Life is like a clock: You can work constantly
mcastle AT cs DOT umr DOT edu and be right all the time, or not work at all
mcastle AT umr DOT edu and be right at least twice a day. -- mrc
We are all of us living in the shadow of Manhattan. -- Watchmen
- Raw text -