This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: register variable is clobbered by passing parameter to a function
Hi,
On Tue, 16 Mar 2004, Wolfgang Kuehn wrote:
> I know, what I do.
You believe you know what you do, but ...
> The register keyword is not obligatory for the compiler, he can use a
... this, and ...
> This behaviour says in conclusion, that you never has to use the register
> keyword, because the compiler makes what he want.
... this indicates that in fact you don't. You confuse the "register"
keyword (which is an official ISO C keyword, but merely a hint to the
compiler where to place the variable, ignored mostly by GCC) with register
variables (those with an added 'asm ("d0")') which is an GCC extension.
> a.. Global register variables reserve registers throughout the program. This
> may be useful in programs such as programming language interpreters which
> have a couple of global variables that are accessed very often.
This says nothing about local register variables, like you used.
In essence local register variables don't contain the value you think they
do. They really represent the register itself at the point of the
reference, i.e. depend on how the compiler choose to layout the code
surrounding that reference. In particular they don't prevent other values
from being placed into the same register (in difference to global register
vars).
Ciao,
Michael.