Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!ctrsol!emory!mephisto!mcnc!rti!sheol!throopw From: throopw@sheol.UUCP (Wayne Throop) Newsgroups: comp.lang.c Subject: Re: main() linkage Message-ID: <0245@sheol.UUCP> Date: 1 Dec 89 01:33:20 GMT References: <2387@stl.stc.co.uk> <744@lakart.UUCP> <0175@sheol.UUCP> <11665@smoke.BRL.MIL> <7755@cdis-1.uucp> Lines: 39 > tanner@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 !mcnc!rti!sheol!throopw or sheol!throopw@rti.rti.org