Mail Archives: djgpp/1996/09/08/01:20:35
Tom Wheeley wrote:
>
> OK, then I want my program to return struct foo, and I want the command line
> in one long string.
>
> struct foo main(char *cmdline);
>
> Do you think this will work?
Hehe... I like that example. :) If I have reckoned correctly, this is what
the above code will produce:
1) Any attempt to access cmdline will probably cause a SIGSEGV due to NULL
pointer dereference. This is because the int-sized pointer represented by
cmdline will actually be passed the value of argc, which likely is a single
digit integer, and CWSDPMI barfs on accessing memory below 1K.) However,
under any DPMI that doesn't support NULL pointer protection, code which
attempts to use cmdline will start merrily playing with the innards of the
computer's OS and probably cause all manner of hard crashes and other
problems, like reformatting the hard drive.
2) When main() exits, that struct foo will actually be resolved as a pointer
to a temporary block of static memory (or memory allocated from the stack; I
don't remember which). So the 4-byte value returned in eax will be the
address of this block, and the (AFAIK) 1-byte return code to the OS will be
the lower 1 byte of this address. This won't cause any hard crashes, but
will play merry havoc with any program which depended on the return value
for further processing.
Remember - the ANSI standard exists for a reason! You play with it at your
own risk!
John
--
--------------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com |
| * Proud user of DJGPP! * | http://www.cs.com/fighteer |
| ObJoke: If Bill Gates were a robber, not only would he |
| shoot you, but he'd send you a bill for the bullets. |
--------------------------------------------------------------------------
- Raw text -