Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!uakari.primate.wisc.edu!xanth!mcnc!rti!xyzzy!meissner From: meissner@dg-rtp.dg.com (Michael Meissner) Newsgroups: comp.lang.c Subject: Re: void main() Message-ID: <513@xyzzy.UUCP> Date: 20 Nov 89 21:22:27 GMT References: <89321.113706CMH117@PSUVM.BITNET> Sender: usenet@xyzzy.UUCP Reply-To: meissner@tiktok.dg.com (Michael Meissner) Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 34 In article <89321.113706CMH117@PSUVM.BITNET> CMH117@PSUVM.BITNET (Charles Hannum) writes: | The basic problem is that you ass/u/me that the compiler will always return | values in a register. If this is the case, then fine. But it is emphatically | **NOT** the case. Making such gross assumptions about the way any particular | compiler works is just begging for trouble. C was never defined to return | values on the stack. The way this is done may vary from compiler to compiler, | and to ass/u/me it does it one particular way makes your code non-portable. An internal DG C compiler that produced 16-bit Eclipse code DID NOT return function results in a register, in order to be compatible with the original AOS common language runtime environment. Functions which return values would have an extra word passed, which pointed to the return area. All of the arguments were then moved down one stack slot. A void function (ie, subroutine) would not push the return address. The 32 bit MV C compiler (which is a supported product) does believe the user when they call a void function, and assumes accumulator Ac0 is not modified by the function. If the function called really does return something (error indication, # bytes printed, etc.), it will mess up optimization. | If all you want to do is disable the warning, just add a return(0) at the end | of your main() function. Even if it isn't optimized out, it will only take | a couple of bytes. This is a much better alternative than declaring main() | as a void. Besides it's the correct thing to do.... | Michael Meissner, Data General. If compiles where much Uucp: ...!mcnc!rti!xyzzy!meissner faster, when would we Internet: meissner@dg-rtp.DG.COM have time for netnews?