Register variables...
maxwell at speedy.DEC
maxwell at speedy.DEC
Sat Jun 29 00:46:55 AEST 1985
It's a shame that we're all too often hampered by the lack of good
optimizing compilers.
The only reason that K&R's C *has* register variables in the first place is
because their original C compiler (and most later ones) can't generate
reasonable code without (and often even with) them. These compilers require
'hints' about variable use. The trouble is, many compilers take the hint
indiscriminatly, without regard for the program itself. (The variety of
assignment operators are there for the same reason).
The 'register' storage class qualifier should generally be *ignored* by a
good compiler: the compiler should place values (and not just variables
necessarily, but common subexpressions as well) in registers as it sees fit.
E.g. a compiler can realize that a variable is used inside a loop and
generate code accordingly, etc.
Not to blow DEC's horn too loudly, but the VAX C compiler *is* a good
compiler, at least by this definition. Declaring a variable 'register'
increases the likelyhood of that variable getting a register (increases its
priority); but generally the compiler keeps track of variable usage (up to
32 of them) and generates code according to their use. 'register' variables
are otherwise treated *exactly* like regular 'auto' ones.
For those who might be interested, the compiler technology used by the VAX C
compiler is described in "Engineering a Compiler: VAX-11 Code Generation and
Optimization", Digital Press. Perhaps PCC (et al) users should read books
like this and rewrite a few compiler backends.
-+- Sid "some of my best friends write compilers" Maxwell, DEC @ Spit Brook
Rd, Nashua NH
"I seriously doubt that the opinion, as expressed in the preceding message,
is necessarily shared by anyone else, including my employer. So there."
More information about the Comp.lang.c
mailing list