Xref: utzoo comp.arch:7434 comp.lang.c:14497 Path: utzoo!utgpu!watmath!clyde!att!rutgers!mit-eddie!uw-beaver!cornell!mailrus!uflorida!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.arch,comp.lang.c Subject: Re: The & (address) operator and register allocation Message-ID: <9048@smoke.BRL.MIL> Date: 2 Dec 88 20:54:01 GMT References: <1224@cps3xx.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 46 In article <1224@cps3xx.UUCP> rang@cpswh.cps.msu.edu (Anton Rang) writes: > scanf("%d", &N); > for (i=0; iwould the final program have to read N from memory each time? Or does >the C standard provide that some keyword (like 'volatile') be used to >avoid possibly unsafe optimizations (like moving N into a register in >the above example--the address of N could have been saved in scanf() ). Trying to answer what it is that I think you're really asking: 1. The C compiler code generator must allocate actual (non-register) storage for anything whose address is needed, so in the above example N's primary definition must be in addressable memory. However, a good optimizer can copy that location into a register for the loop test, and if nothing inside the loop could possibly (according to the C virtual machine model) alter the contents of N, it need not reload that cached value from memory for each test. There are optimizers that do this. 2. scanf() is required to look at its actual arguments each time it is called -- that's the whole point of function parameters. 3. It is true that functions, being separately compilable entities, can be designed so that they stash away pointers for later use, and that so-called "aliasing" (multiple possible reference paths to the same object) is a factor that has to be dealt with when designing a C implementation. The best example is a function having two pointer parameters. What if it is called with both parameters pointing to the same object? The rules of C require that each access via one of the parameters be considered as "killing" the value accessed via the other parameter, so that the other must be "reloaded" the next time it is used. The ill-fated "noalias" type qualifier was intended to provide a way for the programmer to promise that such pointers would NOT access overlapping objects, so that the cached contents accessed via the two pointers would be known to be independently modifiable without interfering with each other. That would have allowed a higher degree of optimization, especially on vector architectures like many supercomputers. As it now stands (without "noalias"), a conforming implementation must make a worst-case assumption and handle possible aliasing correctly. No keyword is needed to specify this; it's the default (and now the only) behavior. > Are there any architectures which allow taking the "address" of a >register (say, having a reserved page)? Registers also have memory addresses on some architectures, for example DEC PDP-11. I've never heard of a compiler exploiting this.