Available No. of Registers

Gregory Smith greg at utcsri.UUCP
Wed Feb 18 03:38:50 AEST 1987


In article <4141 at utcsri.UUCP> flaps at utcsri.UUCP (Alan J Rosenthal) writes:
>>order of appearance solves my problem -- I just put the variables in order
>>of importance and let the compilers handle it from there.
>
>Unfortunately, this is not sufficient in the case of register formals.
>Consider something like:
>
>	f(n)
>	register int n;
>	{    register int i;
>
>where it is considered more useful to put 'i' in a register than 'n'.  It
>is not possible to arrange the declarations in the appropriate order, and
>
>	f(nformal)
>	int nformal;
>	{	register int i,n = nformal;
>
>, which is often recommended, wastes an int on all machines.
				^^^^^^^^^^^^^^^^^^^^^^^^^^^^
How so? To my understanding, declaring a formal to be register is
equivalent to asking for a local register var which is to be initialized
to the value of the formal. I.e:

foo(x) register int x; {  statements....
and
foo(xf) { register int x = xf; statements....

are exactly equivalent, provided a register is available. Thus the 'often
recommended' solution only wastes an int when the local var (in this
case n) cannot be put in a register.

Since most C implementations pass parameters on the stack, declaring
a formal to be 'register' results in a copy operation from the stack
to the register. This copy is implicit in the foo(x) example; the same
copy is explicit in the foo(xf) example.

-- 
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg
Have vAX, will hack...



More information about the Comp.lang.c mailing list