[NTLUG:Discuss] RE: Extremely simple C program...
Steve Baker
sjbaker1 at airmail.net
Mon Aug 12 19:41:03 CDT 2002
Preston wrote:
> Originally main was always ment to have return type int.
It still *is* meant to have a return of 'int'.
> So you could make
> main's return type int and then just add the line: return 0; at the end.
> Most compilers today don't require this.
It's not the compiler that's at issue here. It's the operating system.
Most (if not all) OS's allow you to read the exit status of a program and
use that to tell whether it worked or not. If main returns 'void' then
the exit status is some kind of uninitialised garbage - which means that
sooner or later, some program (like 'make' - or a shell script that uses
${status}) will check that return result and get very confused.
That the compiler lets you 'get away with it' is *not* a good thing!
----------------------------- Steve Baker -------------------------------
Mail : <sjbaker1 at airmail.net> WorkMail: <sjbaker at link.com>
URLs : http://www.sjbaker.org
http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net
http://prettypoly.sf.net http://freeglut.sf.net
http://toobular.sf.net http://lodestone.sf.net
More information about the Discuss
mailing list