Checksum: 58950
Lines: 27
Path: utzoo!sq!msb
From: msb@sq.uucp (Mark Brader)
Date: Sat, 26-Dec-87 15:51:25 EST
Message-ID: <1987Dec26.155125.26600@sq.uucp>
Newsgroups: comp.lang.c
Subject: Re: exit(main(argc,argv,env));
Summary: return in main() considered superior to exit()
References: <10875@brl-adm.ARPA> <176@fxgrp.UUCP> <1286@laidbak.UUCP> <184@fxgrp.UUCP>
Reply-To: msb@sq.UUCP (Mark Brader)
Organization: SoftQuad Inc., Toronto

Lloyd Zusman (ljz@fxgrp.UUCP) writes:
> But upon reflection, I have to agree that it is better to always
> use an exit() statement in main() instead of relying on return [ or
> even worse, using neither return nor exit(), as is often done ].
> If even one C compiler doesn't use exit() with main() the way it
> is done in the GNU crt0 module, then you have unpredictable results
> if exit() is left out of main().

I once met a C compiler that didn't implement ++ correctly for pointers
to structures.  Does this mean that we should all stop using ++?

I suggest that return is the better thing to use in main().  If you use
exit(), you're making the assumption that this function will always be
the mainline of its program; if you use return, you can wrap another
mainline around it by just changing the name of the original one.

Also, if this practice is followed, a call to exit() really stands out
as an abnormal return path, like longjmp().

Of course, if main() is recursive, the two forms are not equivalent;
but not many people write recursive mainlines, and those that do are
old enough to look after themselves.


Mark Brader				"C takes the point of view
SoftQuad Inc., Toronto			 that the programmer is always right"
utzoo!sq!msb, msb@sq.com				-- Michael DeCorte
