"Meghavvarn am" <me********@yah oo.com> writes:
To add to Pete here is what I have to say :
1. Declaring a register variable, suggests the compiler to use a
register on the processor exclusively for that variable and hence
access to this variable becomes incredibly fast.
The compiler, especially if invoked in an optimizing mode, will
attempt to analyze your program to determine which variables should be
assigned to registers for the best possible performance. It can even
assign a variable to a register for part of its lifetime, and use the
same register for a different variable in a different part of the
code, something you can't easily do with the "register" keyword.
example:
Registers typically don't have addresses, but you can still legally
take the address of x or y. If you do so in a section of code where
the compiler has decided to assign the variable to a register, the
compiler will simply not assign it to a register for that section of
code; it's the compiler's job to generate code that behaves properly.
According to the common wisdom these days, the main effect of using
the "register" keyword is to interfere with the compiler's
determination of which variables should be assigned to registers.
Modern compilers are probably better at making this determination than
you are (or than I am). (This wasn't the case for the compilers that
existed when the register keyword was introduced. Times change.)
Bottom line: Don't bother using the "register" keyword. Leave the
compiler alone and it will do a better job of optimization than you
can.
--
Keith Thompson (The_Other_Keit h)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.