Mail Archives: djgpp/1997/07/04/03:24:45
Stephen A. Cleary wrote:
>
> Think about it a minute... if your compiler/OS wasn't too smart, when the OS loads up your program, it will assume that it returns int, so when your program ends, the OS would try to pop an extra int off the stack. This is why all C (and C++) programs are officially integer-returning.
Normally, the return value of main() is stored in the 'al' register.
When the program exits, the operating system will look in this register
to find the exit code (probably the crt0 code reads it and passes it
along), and if main is declared as void, it will take whatever it
happens to find there. This applies to all programs, not just C/C++.
If you then have a shell script, batch file, or calling program which
depends on this exit code to make some decision, you have now fed it an
effectively random value. Results may range from inconvenient to
disastrous, depending on what the caller does with that value. For
example, if your program is called from Make and returns a nonzero exit
code, Make will abort. C'est la vie.
P.S.: Please format your messages so that the lines are 70-80
characters long. As they are they are extremely difficult to read.
Thanks.
--
---------------------------------------------------------------------
| John M. Aldrich | "Deductive logic is tautological; |
| aka Fighteer I | there is no way to get a new truth |
| mailto:fighteer AT cs DOT com | out of it." |
| http://www.cs.com/fighteer | - Lazarus Long |
---------------------------------------------------------------------
- Raw text -