From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: void main ? Date: Thu, 03 Jul 1997 20:14:30 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 28 Message-ID: <33BC0826.592@cs.com> References: <5pgjia$5v3 AT fishlab15 DOT fsh DOT mtu DOT edu> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp102.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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 | ---------------------------------------------------------------------