Must main return a value?

Lawrence H. Miller lmiller at aero.org
Sat Jun 29 10:24:10 AEST 1991


In article <16575 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>In article <7830001 at hpwrce.HP.COM> walterm at hpwrce.HP.COM (Walter Murray) writes:
>>Many people have written that the main function must return a value.
>>I can't find such a requirement in the Standard.  I have read 2.1.2.2.3
>>and 3.6.6.4.  Am I missing something?
>
>You must be -- 2.1.2.2.3 states explicitly "If the main function executes a
>return that specifies no value, the termination status returned to the host
>environment is undefined."  That meets the condition for causing undefined
>behavior on at least two counts.


The question one might ask of a standards body is why this is "undefined"
and not "implementation defined," since it clearly involves the program's
interaction with its host.  This is, in fact, alluded to in the description
of the exit() function in 4.10.4.3:

	If the value [returned] is EXIT_SUCCESS...
	If the value [returned] is EXIT_FAILURE...
	Otherwise the status returned is implementation-defined.

-- 
Larry Miller
The Aerospace Corporation
lmiller at aero.org
(213 soon to be 310)336-5597



More information about the Comp.std.c mailing list