Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!purdue!decwrl!decvax!virgin!satco!aaron From: aaron@satco.UUCP (Aaron Pelton) Newsgroups: comp.lang.c Subject: Re: Strange lint mumblings Summary: furthur questions about exit versus return Message-ID: <179@satco.UUCP> Date: 19 Dec 88 20:36:21 GMT References: <416@marob.MASA.COM> <719@auspex.UUCP> Organization: Saturday Co., Waterbury, VT Lines: 38 In article <719@auspex.UUCP>, guy@auspex.UUCP (Guy Harris) writes: > > > exit(0); /* followed immediately by main's closing brace */ > >causes lint to complain: > >(137) warning: main() returns random value to invocation environment > > status. To fix this, either change > exit(0); > to > return 0; > (with parentheses added as per local preferences) or add > /*NOTREACHED*/ > after the "exit(0)". This raises the question of what return does at the end of main as opposed to what exit does. It is stated that exit() does assorted cleanup jobs. return seems only to be specified as exiting a function. Given the following: main() { printf("hello world\n"); exit(0); } and the same with return(0) in place of exit, I came up with a grand total of four lines difference in asm code. exit() seemed to be called in both cases. Is exit() garuanteed to be called on exit of a program with return? Is there any inherent advantage of exit() over return for exiting main? Is there any danger in randomly switching from one to the other? -- Aaron Pelton | If it sounds like an opinion, it's probably mine. aaron@satco.UUCP | Only R. Crusoe could have it all done by Friday {decvax,uunet}!virgin!satco!aaron | So much for self taught C programming.....