main() linkage
Wayne Throop
throopw at sheol.UUCP
Fri Dec 1 12:33:20 AEST 1989
> tanner at cdis-1.uucp (Dr. T. Andrews)
> It is interesting to hear that the practice of declaring as "void"
> a function which does not return a value is erroneous.
It may be that Dr. Andrews hasn't been listening to this thread
carefully. The point is not that the USERs code does not return a
value. The point is that your "main" function is very probably linked
with a system module (often called "crt0") which declares main to return
an int. Hence, your module and the system module disagree as to the
type of main.
Or to look at the point another way, the system has already defined the
type of main... you are only providing an implementation. It simply
does not matter if that implementation doesn't desire to return a value,
the contract it has with the system, already declared in the above
mentioned module (usually called "crt0") requires it to do so.
> Yes, other people have posted hypothetical but not unreasonable
> examples where it would be more difficult to handle such cases.
> In no case is it impossible to handle a void "main" which doesn't
> return.
Again, careful perusal of this thread will reveal at least one
NON-hypothetical case of C language systems where main's access to its
arguments would be disrupted by misdeclaring main's type. I would call
this a case where the "void main", even though it does not return,
cannot really be said to be successfully "handled".
Now, granted, main could be made even more of a special case than it
already is, and implementations could be required to jump through hoops
when the function being compiled happens to be named main, but the
current situation seems to be the correct tradeoff to me.
Remember, the point is that the main routine's type is specified on
paper, but in concrete terms in a module that essentially every C
program links against. Declaring a single entity in two different
ways in two different places is NOT wise.
--
Wayne Throop <backbone>!mcnc!rti!sheol!throopw or sheol!throopw at rti.rti.org
More information about the Comp.lang.c
mailing list