void main()

Michael Meissner meissner at dg-rtp.dg.com
Tue Nov 21 08:22:27 AEST 1989


In article <89321.113706CMH117 at PSUVM.BITNET> CMH117 at 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 at dg-rtp.DG.COM			have time for netnews?



More information about the Comp.lang.c mailing list