Swap by name

Root Boy Jim rbj at icst-cmr.ARPA
Wed Jul 9 10:20:54 AEST 1986


	> 	~> call by value-result
	> 
	> 	I was thinking of the caller squirrelling away the value
	> 	in a temporary location, passing it by reference (thus
	> 	allowing modification by the callee) and then copying the
	> 	result to the real variable. [me]
	> 
	> That works too---which just goes to show that there is more than
	> one way to skin a function. [chris at maryland (as in Torek)]

Changing the subject a bit here, I am referencing Wayne Throop's article
on taking the address of a register variable, where he quotes H&S (how
about that folks, they're mainstream enuf to be ref'ed like K&R).

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?

As H&S notes, some machines have registers that really *are* addressable,
so this does provide something that is missing, and is not just syntactic
sugaring. Even if it were, look at all the language implementation
chatter we have removed. Just let the user say what he means.

I agree with H&S that the syntax `ought' not to be illegal, but go the
other way with the fix. They wish to ignore the register declaration
making the variable auto, whereas I wish to simulate register addressibility.

Consider a function which uses a register variable heavily in three or
four loops. Now consider modifying the code to include a call to one that
wants the address of a variable. Oops! All too often the fix is to change
the register declaration to auto rather than add the extra variable and
two assignments. Down the drain goes performance.

	(Root Boy) Jim Cottrell		<rbj at icst-cmr.arpa>
	Yow!  Is my fallout shelter termite proof?



More information about the Comp.lang.c mailing list