Register Addresses

Root Boy Jim rbj at icst-cmr.ARPA
Thu Jul 10 03:05:59 AEST 1986


> 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.

Are you arguing that because Fortran is gross, it is okay for C to be
gross also?  Yitch.

	No, I think fortran does the right thing here.

> 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.

In other words, you are breaking the semantics of C.  This is a very
bad thing, certainly not worth it for the rather minor gain in
convenience or efficiency that you propose.  Let the programmer assign
the register variable to an auto variable and pass the auto variable's
address -- it is in the tradition of C to make programmers perform
optimizations like this if they really want them.

> 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.

This is an issue of lifetime, not scope.

	Okay, scope in the time domain :-)

Also, a glitch where
something that should be allowed isn't and causes an error message
(taking the address of a register variable) is MUCH better than a
glitch where something that should be allowed, and is according to the
manual, quietly fails (using static_p).

	Except that I've never wanted to do what you propose, and
	I have often wanted the address of a register.

	We all know registers are different from `regular' (auto)
	variables. It's just a question of what differences.
	Taking the address of any auto variable is risky business;
	you can easily forget if it's valid or not. Why should it
	be surprising that registers are more transient?

Do you have a Zippy quote database, from which a line is randomly
selected for each letter/news item you send out?  Sort of a Zippy
"fortune"?

	Make that `Pinhead Fortune'. Yow! It comes with GNU EMACS.

	(Root Boy) Jim Cottrell		<rbj at icst-cmr.arpa>
	I just forgot my whole philosophy of life!!!



More information about the Comp.lang.c mailing list