Path: utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: main() arguments, was Re: typedef-ing an array Message-ID: <17017@haddock.ima.isc.com> Date: 3 Jul 90 19:18:27 GMT References: <78627@srcsip.UUCP> <78633@srcsip.UUCP> <25247@mimsy.umd.edu> <4238@jato.Jpl.Nasa.Gov> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 31 In article <4238@jato.Jpl.Nasa.Gov> kaleb@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@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().