[M3devel] a trouble with passing records by value..

hendrik at topoi.pooq.com hendrik at topoi.pooq.com
Wed Sep 1 17:47:14 CEST 2010


On Tue, Aug 31, 2010 at 09:24:07PM -0500, Rodney M. Bates wrote:
> If the writers of an ABI actually *required* that small structs/records be
> passed in registers, then they have made a big blunder.   In C, formal
> parameters are l-values,

but they are copies of the corresponding actual parameters.

> and in Modula-3, they are designators, regardless
> of the parameter mode. Thus taking their address must always be possible,
> to comply with language semantics, which means they must be in memory.
>
> The only possible resolutions are
>
> 1) Declare that language semantics trump ABI requirements and defy the ABI.

On most platforms I ever had to be binary-compatible with in a C 
interpreter I dealt with long long ago, declaring the formal parameters 
as "..." (like printf) kept them in storage on the stack.

-- hendrik

>
> 2) Pass them in registers at the time of control transfer, but store them
>    in memory in the prologue, then access them from memory thereafter.

That's what the more optimizing compilers did, except they only ccopied 
them to memory if the called code actually needed them to be in memory.  
And they also watched out for functions  whose addresses were taken, or 
were accessible by external linkage.

But it mattered whether the function had a prototoype, and whether 
parameters were declared as "...".

-- hendrik



More information about the M3devel mailing list