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

Roger House roger at everexn.uucp
Fri Jul 6 05:02:56 AEST 1990


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

>Second bone to pick is the assertion that main() has two arguments (???)
>Since when?  What about the third allowable argument; envp?   I know that
>both UNIX and DOS (M'soft C compilers anyway) support char **envp (or
>char *envp[] if you will) as the third parameter to main.

According to p11 of the Rationale for ANSI C:

	main is the only function that may portably be declared either
	with zero or two arguments.  (The number of arguments must or-
	dinarily match exactly between invocation and definition.)  This
	special case simply recognizes the widespread practice of leaving
	off the arguments to main when the program does not access the 
	program argument strings.  While many implementations support
	more than two arguments to main, such practice is neither 
	blessed nor forbidden by the Standard; a program that defines
	main with three arguments is not *strictly conforming*.


							Roger House



More information about the Comp.lang.c mailing list