Chris said:
Please clear my doubt. When do we declare a variable to be a register
variable?
Almost never.
It's an optimisation-for-speed hint that's unnecessary for
many modern compilers. [...]
Worse, it can turn out to be a pessimization -- even for
older compilers that (as a rule) paid more heed to `register'
than do their modern successors.
I recall encountering two kinds of situations where over-
enthusiastic use of `register' actually slowed things down
(there are probably others, but these are the two types I
found myself debugging):
1) An "obedient" compiler would dedicate registers to the
tagged variables, thus making those registers unavailable for
other purposes. This could make the generated code slower than
it would have been otherwise; for example, intermediate results
of sub-expressions might be forced into memory due to shortage
of available registers to hold them.
2) In order to make enough registers available for `register'
variables, the function prologue and epilogue might need more
register-save and register-restore operations than would have
been the case otherwise. Entering and leaving the function
would then take longer, and this could in some cases outweigh
the gain of, er, registering all those variables.
The long and short was that `register' is/was a portable
expression of a non-portable intent, with implementation-specific
effects. It could be valuable if used with care in code intended
for a specific compiler on a specific machine, but was problematic
in code intended for wider portability.