Mail Archives: djgpp/1997/04/16/01:02:25
Jawed Karim wrote:
>
> /*
> compile the following code with DJGPP and run it. Observe the output.
> Then, run DJP on the executable and run it again. The output differs! I
> think that qualifies as a bug, because compressed EXE's should not
> behave any differently than uncompressed EXE's.
> */
No, this is quite simply a major bug in your program. Allow me to
explain, but first let me ask you where in the nine hells you learned
C? And who taught you to be so "polite"? Oh, well... here goes:
> #include <stdio.h>
>
> void main(void)
This is a nono. main() must return an integer value to the operating
system - this forms the return code of the program! Don't leave it out,
despite what many C books tell you. They are WRONG.
> {
> char *string = NULL;
>
> if (*string != NULL)
This will never work as intended, because you're dereferencing 'string'
before comparing it to NULL. Try just "if ( string != NULL )" here.
This should have caused a segmentation violation when you ran the
program, unless you tried it under Windows. In DOS, all you'd get is a
crash.
> printf("\n%s\n", string);
> }
BTW, the reason for the different behavior with djp is that the data at
the virtual address '0x0' is probably part of the program's executable
code, or some internal structure of the program, and thus differs when
the executable itself is different.
I'm surprised that this program worked at all, and didn't cause all
sorts of nasty crashes.
--
John M. Aldrich <fighteer AT cs DOT com>
* Anything that happens, happens.
* Anything that, in happening, causes something else to happen,
causes something else to happen.
* Anything that, in happening, causes itself to happen again, happens
again.
* It doesn't necessarily do it in chronological order, though.
--- Douglas Adams
- Raw text -