Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!ncar!ames!oliveb!3comvax!bridge2!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Strange lint mumblings Message-ID: <758@auspex.UUCP> Date: 20 Dec 88 17:53:52 GMT References: <416@marob.MASA.COM> <719@auspex.UUCP> <179@satco.UUCP> Reply-To: guy@auspex.UUCP (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 34 > 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.