The & (address) operator and register allocation

Henry Spencer henry at utzoo.uucp
Sun Dec 4 08:18:43 AEST 1988


In article <1224 at cps3xx.UUCP> rang at cpswh.cps.msu.edu (Anton Rang) writes:
>... Since the C language doesn't
>have call-by-reference, is it possible to allocate variables which are
>passed by reference into registers?

Within limits.  Barring the possibility that the machine allows pointers
to registers, the requirement is that the register and memory copies track
changes to each other.  This is tricky but not entirely impossible, at
least in restricted cases with some arguably-dubious assumptions.

>...the above example--the address of N could have been saved in scanf()...

The compiler may know that it isn't, since scanf is a standard library
function.  It may even know it for your own functions, if it does fancy
interprocedural analysis.

>  Are there any architectures which allow taking the "address" of a
>register...

The original Berkeley RISC design had registers with addresses, carefully
set up in such a way that you could pass pointers to them around freely.
The idea was to maximize the ability to put local variables into registers.
I don't know of anybody commercial who's copied this idea.
-- 
SunOSish, adj:  requiring      |     Henry Spencer at U of Toronto Zoology
32-bit bug numbers.            | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list