return in main is *not* equivalent to exit() (was Re: main() arguments)
Martin Weitzel
martin at mwtech.UUCP
Thu Jul 5 00:33:15 AEST 1990
In article <4238 at jato.Jpl.Nasa.Gov> kaleb at mars.UUCP (Kaleb Keithley) writes:
>
>Furthermore, on p. 164 (Ibid.) [K&R2] it is stated:
>
>Within main, return expr is equivalent to exit(expr). exit has the
>advantage...
K&R2 is right?
Nearly right! I'll never forget the day when I tracked down what
seemed to be a really wierd problem in some printer driving code
to the following (still buggy!) program:
#include <stdio.h>
int main(argc, argv)
int argc; char **argv; /* OK so, Chris? :-) */
{
char buffer[BUFSIZ];
setbuf(stdout, buffer);
........ /* some code which produced output */
return 0;
}
Note that the bug could be eliminated by replacing `return 0;'
with `exit (0);'. Well, after that the cause for this problem
became obvious to me ... of course, all of you readers out there
in net-world allready know what the problem is, don't you :-)
--
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83
More information about the Comp.lang.c
mailing list