Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site decwrl.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!dec-rhea!dec-speedy!maxwell From: maxwell@speedy.DEC Newsgroups: net.lang.c Subject: Register variables... Message-ID: <2943@decwrl.UUCP> Date: Fri, 28-Jun-85 10:46:55 EDT Article-I.D.: decwrl.2943 Posted: Fri Jun 28 10:46:55 1985 Date-Received: Sun, 30-Jun-85 00:13:52 EDT Sender: daemon@decwrl.UUCP Organization: DEC Engineering Network Lines: 33 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."