Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: register variable declaration question Message-ID: <1988Nov9.175833.2308@utzoo.uucp> Organization: U of Toronto Zoology References: <624@scotty.UUCP> Date: Wed, 9 Nov 88 17:58:33 GMT In article <624@scotty.UUCP> jwr@scotty.UUCP (Dier Retlaw Semaj) writes: >When should one declare a parameter to be a register variable? ... >Is there a cutoff point where declaring the parameter >to be a register variable is no longer efficient? A precise answer is very implementation-dependent. Modern compilers will often ignore "register" entirely anyway, and figure it out for themselves. (NB, the 4BSD VAX compilers are antiques.) A reasonable rule of thumb is that it's worth making a parameter "register" only if it is used more than two or three times within the function. Whether you *should* make the parameter "register", given that it appears to be worthwhile, depends on how many other "register" variables you have in the function. Simpleminded compilers will often fill available registers first-come-first-served, so if registers are scarce, a "register" parameter used half a dozen times might get a register when a "register" loop variable used thousands of times doesn't. There is no entirely graceful solution to this. The number 3 is magic for historical reasons (the pdp11 had 3 user-available registers), and one can also argue that if "register" is any good at all, there will probably be 3 or 4 of them. What I tend to do is to use "register" on the three "hottest" variables, declare the rest "REGISTER", insert the following near the beginning: #ifndef REGISTER #define REGISTER register #endif and then use "-DREGISTER=" if I'm working on a machine with few registers. More elaborate schemes are possible, but I suspect they're not worth the added trouble unless you have zillions of local variables in a single function. >Should I immediately assign >the value of the parameter to a local register variable? This is unlikely to have any advantage over declaring the parameter itself "register", and might even be worse. -- The Earth is our mother. | Henry Spencer at U of Toronto Zoology Our nine months are up. |uunet!attcan!utzoo!henry henry@zoo.toronto.edu