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

Karl Heuer karl at haddock.ima.isc.com
Wed Jul 4 05:18:27 AEST 1990


In article <4238 at jato.Jpl.Nasa.Gov> kaleb at mars.UUCP (Kaleb Keithley) writes:
>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.

Silencing lint is not the same as making the program correct.  ANSI could
have made `void main' legal, and in fact I suggested it to them, but it was
rejected.  (I've since taken the opposite approach that they should have
supported only one legal prototype for main() instead of two.)

The traditional implementation of lint has a documented bug in that it doesn't
know that exit() is a dead function.  Some compilers (including gcc with
proper headers) do know about this, and so will not emit that warning.

>Second bone to pick is the assertion that main() has two arguments (???)
>Since when?

I believe it became official in December, 1989, but it's probably been in
there since the first Draft.

>What about the third allowable argument; envp?  I know that both UNIX and DOS
>(M'soft C compilers anyway) support char **envp as the third parameter

It's a valid (though somewhat useless%) non-Standard extension.  The portable
way to get at the environment is with getenv(), which works even if the
environment is not implemented as an array of strings.

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint
________
% Even on Unix systems, the global variable `environ' is more convenient than
  the third argument to main().



More information about the Comp.lang.c mailing list