Strange lint mumblings

Aaron Pelton aaron at satco.UUCP
Tue Dec 20 06:36:21 AEST 1988


In article <719 at auspex.UUCP>, guy at 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 at satco.UUCP            | Only R. Crusoe could have it all done by Friday
{decvax,uunet}!virgin!satco!aaron | So much for self taught C programming.....



More information about the Comp.lang.c mailing list