Strange lint mumblings

Guy Harris guy at auspex.UUCP
Wed Dec 21 03:53:52 AEST 1988


>    Is exit() garuanteed to be called on exit of a program with return?

All the UNIX C implementations I know of call "exit()" if you return
from "main()".  I think the dpANS explicitly requires this.

>    Is there any inherent advantage of exit() over return for exiting
>    main?

In dpANS C, and in any implementation that, when the ANS comes out, is
conformant to the ANS, no.  The return value of "main" is the exit
status passed to "exit()".

In some UNIX C implementations, yes; returning from "main()" always
causes "exit()" to be called with an argument of 0.  (This is true in
SunOS releases from 2.0 to 3.5, I think; this was fixed in 4.0.  I
remember somebody claiming it was true of some Amdahl UTS release as
well.)

In non-UNIX releases, it may also be true; I don't know which of them
either 1) cause "exit()" to be called if you return from "main()" or 2)
use the return value of "main()" as the argument to "exit()".

>    Is there any danger in randomly switching from one to the other?

"Randomly"?  As in

	if (rand() & 0x80)
		exit(1);
	else
		return 1;

If you know your code is always going to be built and run on an
implementation that does it right, no, they're equivalent.  Otherwise,
"exit()" is safer.



More information about the Comp.lang.c mailing list