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

Kaleb Keithley kaleb at mars.jpl.nasa.gov
Fri Jul 6 11:00:47 AEST 1990


In article <1990Jul5.221205.19888 at dg-rtp.dg.com> goudreau at larrybud.rtp.dg.com (Bob Goudreau) writes:
>
>In article <4249 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.  

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.

It's just a matter of style, I suppose, but in all of my code, my main()
usually has just three statements, initialize(), process(), clean_up().  
If exit() is appropriate, then it is called close to the the event that 
requires it, so exit() from main() would be overkill.

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.

kaleb at thyme.jpl.nasa.gov            Jet Propeller Labs
Kaleb Keithley

"So that's what an invisible barrier looks like"



More information about the Comp.lang.c mailing list