void main() (second proof of non-portability)

bdm659 at csc.anu.oz bdm659 at csc.anu.oz
Sun Nov 19 06:08:02 AEST 1989


In article <314 at charyb.COM>, will at charyb.COM (Will Crowder) writes:
> In article <1018.25642ba8 at csc.anu.oz> bdm659 at csc.anu.oz writes:
>
> [lots of stuff about void main() unportability having to do with passing
>  return values on the stack]
>
> I've used a 6 or so C compilers in 3 very different environments,
> (680x0, 80x86, SPARC), and all of them pass return values in registers.
>
> The question I have is this: for every C compiler I've used, it doesn't
> matter how many arguments you call a function with.  The return linkage
> will still work, because it's the *caller's* job to fix up the stack
> after the function returns.  Are there any implementations in which this
> is not true?  Can someone point me to a C compiler which does use a vastly
> different calling convention?  I'm just curious.  Passing return values
> on the stack doesn't seem like a very good performance move, and most
> machines have at least one register to pass something in...If the caller
> needs the contents of that register saved, it can save it itself before
> calling the function...again, stack frame integrity is the caller's
> responsibility in C (or at least any sane implementation), no?

Since functions can return values which are quite large (eg. structures),
some mechanism other than registers must be used sometimes.  The compiler
can use whatever mechanism it pleases so long as it is consistent.  The
method might even depend on the type instead of the size, so you can't even
suppose that a function can be safely declared int in one place and
struct {int i;} in another.

Brendan.



More information about the Comp.lang.c mailing list