Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: `noalias' vs `register' Message-ID: <6845@brl-smoke.ARPA> Date: 16 Dec 87 00:44:48 GMT References: <6829@brl-smoke.ARPA> <9753@mimsy.UUCP> <6830@brl-smoke.ARPA> <6833@brl-smoke.ARPA> <9796@mimsy.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 47 In article <9796@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >>>In article <9770@mimsy.UUCP> I wrote >>>... why not just use `register'? ... [because] you cannot take the >>>address of a register. >To which, in article <6833@brl-smoke.ARPA>, gwyn@brl-smoke.ARPA >(Doug Gwyn) replies: >>That's not the answer! > f() { > register int r; > ... > r = 1; > g(); > if (r == 1) ... >Does the `if' succeed? Yes, because there is no way for g() to >alter `r'. That is true for any auto; "register" has nothing to do with it! If you mean that there is no way to form a pointer to r, that is of course correct, but a red herring. >All I have been saying all along is that `register' and `noalias' >really mean the same thing to a compiler that does not automatically >put `register' vairables in machine registers. No! No! No! "register" acts as a storage class while "noalias" is a type qualifier. This distinction shows up clearly when one compares register thing *p; /* p is possibly in a register */ and noalias thing *p; /* (*p), not p, is unaliased */ Consider adding to your choice of the above the following code: *p = 1; { /* should be a function, shown in-line for simplicity */ thing *q = (thing *)p; /* cast necessary if noalias */ *q = 0; } if ( *p ) ; /* noalias is allowed to get here */ else ; /* register always gets here */ See the difference? (I actually oversimplified the example. Don't take it too literally.) Another way to see that there is a difference is to realize that all the pointer parameters in the standard C library can be qualified noalias, except for memmove(). One would not say this of "register". Consideration of what is special about memmove() should provide a clue.