Strange lint mumblings

Chris Torek chris at mimsy.UUCP
Fri Dec 30 06:35:18 AEST 1988


This has been mentioned before but I had better do it again:

>In article <599 at micropen> dave at micropen (David F. Carlson) writes:
>>... Rather, use return at the end of main().

In article <1700 at valhalla.ee.rochester.edu> badri at valhalla.ee.rochester.edu
(Badri Lokanathan) writes:
>Alas, some of us (at least I) have gotten used to the easy clean up facility
>that exit() provides. That is, flushing all I/O buffers and closing
>them. return(status) works cleanly if the programmer takes care of this.

In what the dpANS calls a hosted environment---that is, in all the
interesting cases; in freestanding environments like a Unix kernel,
one generally cannot exit at all---return(expr) from main and
exit(expr) have identical effects.  The startup code that calls main
reads, essentially,

	exit(main(argc, argv, envp));

There are a few exceptions, notably some versions of SunOS.  These
read

	(void) main(argc, argv, envp);
	exit(0);

so that return(expr) from main is the same as exit(0).  There should
never be any difference between

	main() { return (0); }

and

	main() { exit(0); }

even on the buggiest implementations around.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list