Mail Archives: djgpp/1996/11/06/01:02:26
On 5 Nov 1996, Matthew Miller wrote:
> the same. With DJGPP, running the exe. produces an endless loop
> of seg. faults.
You have just learned from your own experience that working in a
protected-mode environment can save you much grief and embarrassment,
because it doesn't let you reference wild pointers as easy as real-mode
DOS does.
Your problem is a couple of lines such as this:
> KeyWords = (char **) malloc ( sizeof(char) );
^^^^^^
Since you want KeyWords to be an array of pointers, you should instead do
this:
KeyWords = (char **) malloc ( sizeof(char *) );
^^^^^^^^
The effect is that the array thus allocated is 1/4 of the size you want
it to be, since in DJGPP sizeof(char *) = 4 and sizeof(char) = 1. Then
when you proceed to fill this array with pointers to char, you eventually
begin to overwrite memory beyond the limits of the space allocated for
the array. BC lets you get away with this, but DJGPP catches this and
crashes your program.
(There might be other problems in your program, but once I saw this one,
I stopped looking for others.)
Btw, the stack trace printed when the program segfaults includes
information that you should use to begin debugging. Just run the `symify'
program when the stack trace is still on the screen. (The DJGPP FAQ list,
available as v2/faq202b.zip from the same place you get DJGPP, explains
you how to use `symify' in section 9.2.)
- Raw text -