Path: utzoo!mnetor!uunet!husc6!hao!ames!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: `noalias' vs `register' Message-ID: <9796@mimsy.UUCP> Date: 15 Dec 87 18:09:02 GMT References: <6829@brl-smoke.ARPA> <9753@mimsy.UUCP> <6830@brl-smoke.ARPA> <6833@brl-smoke.ARPA> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 73 >>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! Sure it is. Watch: >The "noalias" type qualifier promises that the object can only be >modified by a single handle.... So does `register'. The key difference between `register' and `noalias' is that with `register' variables, the compiler refuses to allow you even to begin to provide a second handle for an object (by taking its address). >...thereby permitting the optimizer to do things that are not >safe otherwise.... 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'. f() { register int r; ... r = 1; g(&r); if (r == 1) ... Oops, this is illegal. f() { noalias int r; ... r = 1; g(&r); if (r == 1) ... Is this true? Depends on the exact definition of noalias. Change it a bit: f1() { /* noalias */ int r; ... g(&r); r = 1; z(); if (r == 1) ... Is it? Without the `noalias', not necessarily; with `noalias', yes. So now we can discard the `register' keyword, since noalias is just a stronger form of it. (N.B.: `can' != `should'.) 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. The real difference between the two keywords is that `noalias' says `even if I appear to be aliasing a variable, I am not', while `register' says `I promise not to alias this variable and you should stop me if I appear to do so'. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris