is there anything wrong with return(n) from main?

Guy Harris guy at gorodish.Sun.COM
Fri Jul 1 17:21:17 AEST 1988


>      For some unknown reason, I have always felt uncomfortable
> doing a return(n) from main: I used exit(n) instead.  Can anybody
> think of any possible reason why a return is not a good idea?

Some implementations don't properly implement "return(n)" from "main".  SunOS's
C implementations did not do so from SunOS 2.0 to SunOS 3.5; they implement it
correctly in 4.0.  I seem to remember somebody claiming some other
implementation did not do so.

I think every S5 implementation from AT&T handled "return(n)" from "main"
correctly, as did 4.[23]BSD; this does not, of course, guarantee that any
particular implementation derived from either or both of those will do so
correctly.

ANSI C mandates it, so everybody's going to have to get with the program
eventually.



More information about the Comp.lang.c mailing list