main() arguments, was Re: typedef-ing an array

Bob Goudreau goudreau at larrybud.rtp.dg.com
Sat Jul 7 02:01:21 AEST 1990


In article <4254 at jato.Jpl.Nasa.Gov>, kaleb at mars.jpl.nasa.gov (Kaleb
Keithley) writes:
> >
> >> It also strikes me that what may be missing from the standard is a
statement
> >> along the lines of "... use of exit() from main() is illegal..."  Not to 
> >> mention that K&R2 is a little misleading in this area also.
> >
> >Say what?  Who has ever claimed that use of exit() from main() is not
> >legal?
> 
> I don't think anyone ever said it was illegal.  

Then why does it strike you that such a statement is missing from the
standard?
 
> By implication I was trying to state that the use of exit() from 
> (ANSI Std. C defined):
>    int main(int argc; char **argv) { ... }
> was inconsistant.  Maybe I'm picking nits, but main() should use return
> instead of exit based on this.  If the ANSI Std. is going to define a
> the way that main() is declared, then they should define the corresponding
> exit (not the funcion) from function main().  And IMHO, return is the
> correct exit method from int main().
> 
> if main() is defined as returning a value of type int, then the use of
> exit is not consistant with the defined return value of the function.
> ....
> Furthermore, had you read my (and others) previous posting on this subject,
> you'd have seen my reference to K&R2 that stated that exit() from main()
> and return from main() were equivalent.

But, as you mention, the standard explicitly states that the two
methods are *equivalent* (see excerpt below), so in what way is the
standard inconsistent?  It says essentially, "you can do it this way
or you can do it that way, but both of those ways are equivalent".


	2.1.2.2.3  Program Termination

	A return from the initial call to the |main| function is
	equivalent to calling the |exit| function with the value
	returned by the |main| function as its argument.  If the
	|main| function executes a return that specifies no value,
	the termination status returned to the host environment is
	undefined.

------------------------------------------------------------------------
Bob Goudreau				+1 919 248 6231
Data General Corporation
62 Alexander Drive			goudreau at dg-rtp.dg.com
Research Triangle Park, NC  27709	...!mcnc!rti!xyzzy!goudreau
USA



More information about the Comp.lang.c mailing list