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

Zev Sero zvs at bby.oz.au
Fri Jul 6 10:03:37 AEST 1990


In article <4238 at jato.Jpl.Nasa.Gov> kaleb at mars.jpl.nasa.gov (Kaleb Keithley) writes:

   Furthermore, on p. 164 (Ibid.) it is stated:

   Within main, return expr is equivalent to exit(expr).  exit has the
   advantage...

   If exit() is used rather than return, I submit that declaring main as 
   returning type void is not only legal, but correct, as lint plus ANSI
   compilers will complain that there is no return statement.


Precisely.  Except that it is not legal to use
	 exit();
The exit function requires an int argument, and a return from main
requires the same int argument.  While ANSI compilers should
apparently not complain about not returning from main when exit
has been used, if exit has been properly prototyped they *must*
complain about calling it with no arguments.

So main() must be declared int (or allowed to default to int), and the
only legal ways to leave the program are exit(int); or return int;
If exit is not called from main, but from elsewhere, main will require
a dummy return.
--
				Zev Sero  -  zvs at bby.oz.au
...but we've proved it again and again
that if once you have paid him the danegeld,
you never get rid of the Dane.		- Rudyard Kipling



More information about the Comp.lang.c mailing list