From: Andrew Crabtree Message-Id: <199707041624.AA073873448@typhoon.rose.hp.com> Subject: Re: void main ? To: fighteer AT cs DOT com Date: Fri, 04 Jul 1997 9:24:08 PDT Cc: djgpp AT delorie DOT com In-Reply-To: <33BC0826.592@cs.com>; from "John M. Aldrich" at Jul 03, 97 8:14 pm Precedence: bulk > > 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++. Sure, for the i386 class machines I would agree that void main is never going to cause any problem other than a garbage return value. The point I think was that on other architectures (I can't think of any modern ones, maybe the 6502), return values may go on a stack, in which case you could have problems. Andrew