Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!brl-adm!brl-smoke!smoke!rbj@icst-cmr.ARPA From: rbj@icst-cmr.ARPA (Root Boy Jim) Newsgroups: net.lang.c Subject: Register Addresses Message-ID: <2051@brl-smoke.ARPA> Date: Wed, 9-Jul-86 11:41:38 EDT Article-I.D.: brl-smok.2051 Posted: Wed Jul 9 11:41:38 1986 Date-Received: Thu, 10-Jul-86 04:59:30 EDT Sender: news@brl-smoke.ARPA Lines: 67 Sam Kendall of Thinking Machines writes: In article <2036@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 I'm dressing up in an ill-fitting IVY-LEAGUE SUIT!! Too late...