Register Addresses

Root Boy Jim rbj at icst-cmr.ARPA
Thu Jul 10 01:41:38 AEST 1986


Sam Kendall of Thinking Machines writes:
	In article <2036 at brl-smoke.ARPA> you write:
	>I have said all along that there is no reason why a compiler can't
	>perform the following transformation:
	>
	>		LEGAL				DESIRED
	>	foo()				foo()
	>	{	register int j;		{	register int j;
	>		auto	 int k;	
	>		k = j;
	>		bar(&k);			bar(&j);
	>		j = k;
	>	}				}
	>
	>Sort of a Call by Value-Result, eh?
	
	You mean that the compiler should transform the users's code on the
	right into the code on the left, I assume. 

Yes.
	How would you handle this:
	
		f(){
			register int j;
	
			j = 0;
			bar(&j);
			j = 1;
			if (*static_p == j)	/* this test wil fail */
				...
		}
	
		int *static_p;
	
		bar(p)  int *p;
		{
			static_p = p;
		}
	
	Of course, your transformation would work in most cases, but for the
	compiler to verify that would take some pretty sophisticated global
	analysis.  A compiler that could actually do such global analysis could
	convert the register variable to non-register auto when it can't verify
	your transformation is okay.

Good point. We certainly have introduced another glitch here, but one we
are all familiar with. Consider in FORTRAN that when you call a subroutine
as CALL FOO(ARG). Your poor variable (passed by reference) is subject to
modification by FOO. To avert this, you can CALL FOO(ARG + 0). This
forces a temporary location to be generated for the expression, thereby
forcing a call by value.

But back to C. I have traded absolute pointer accuracy for temporary
pointer convenience. That is, the address of a register variable is
only valid for the life of the callee.

But Wait! That's a Mimic! Register variables are really fast auto
variables, so after `f' returns, your static_p is worthless anyhow.

It seems I have merely narrowed the scope a bit. Is it worth it?
Possibly. Scope glitches seem less limiting than storage class ones.

You pays your money and you takes your choice.

	(Root Boy) Jim Cottrell		<rbj at icst-cmr.arpa>
	I'm dressing up in an ill-fitting IVY-LEAGUE SUIT!! Too late...
	



More information about the Comp.lang.c mailing list