Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!rutgers!husc6!Diamond!mlandau From: mlandau@Diamond.BBN.COM (Matt Landau) Newsgroups: comp.lang.c Subject: Return vs. exit in main() [WAS Re: "exit 0;" - or - "exit (0);" ?] Message-ID: <2330@diamond.Diamond.BBN.COM> Date: Fri, 21-Nov-86 12:40:11 EST Article-I.D.: diamond.2330 Posted: Fri Nov 21 12:40:11 1986 Date-Received: Fri, 21-Nov-86 20:32:17 EST References: <6355@alice.UUCP> <1556@batcomputer.tn.cornell.edu> Reply-To: mlandau@Diamond.BBN.COM (Matt Landau) Distribution: net Organization: BBN Laboratories, Inc., Cambridge, MA Lines: 29 Summary: return != exit In article <1556@batcomputer.tn.cornell.edu> braner@batcomputer.UUCP (braner) writes: >Actually, I now think that what I've seen was "return n;" in main(), >which I guess has the same effect as exit(n); - or does it? It is implementation-dependent whether return(x) and exit(x) are equivilent from within main(). In most (all?) compilers, there is a startup routine that calls the user's main; nowhere is it cast in stone what this startup routine does when main returns a value to it. I know of compilers that fit each of the following descriptions: - startup routine expects main to be "void main", and does not accept a return value, but always returns 0 to the operating system upon completion - startup routine expects main to be "int main", but ignores any value returned by main and always returns 0 to the OS - startup routine uses the return value of main as its own return value to the OS In the last case, return and exit are equivilient; in the other two cases, you must use exit(x) to exit with some status other than 0. Does the most recent ANSI draft have anything to say on this subject? -- Matt Landau BBN Laboratories, Inc. mlandau@diamond.bbn.com 10 Moulton Street, Cambridge MA 02238 ...seismo!diamond.bbn.com!mlandau (617) 497-2429