addressing register variable

I have a few doubts regarding the register variable. Though the C standard says that it is illegal to access the address of a register variable, the GCC compiler gave only warning. At run-time also, there was no error (probably, the register variable is converted into an 'auto' variable by the compiler).

Suppose the register variable is not converted into 'auto' variable, then at run-time, will it give error? So far I've not come across a situation where the variable declared as 'register' is actually put into a register. It looks like everytime the GCC compiler turns it into 'auto' variable. From a program, how to find whether the variable is actually put into a register or it is made an auto variable?

Comments

  • : I have a few doubts regarding the register variable. Though the C standard says that it is illegal to access the address of a register variable, the GCC compiler gave only warning. At run-time also, there was no error (probably, the register variable is converted into an 'auto' variable by the compiler).
    :
    : Suppose the register variable is not converted into 'auto' variable, then at run-time, will it give error? So far I've not come across a situation where the variable declared as 'register' is actually put into a register. It looks like everytime the GCC compiler turns it into 'auto' variable. From a program, how to find whether the variable is actually put into a register or it is made an auto variable?
    :

    The keyword "register" is only a hint to the compiler how to handle the variable. The compiler is free to do with that whatever it wants. Most modern compiler ignore it because they are better at optimizing code than humans are. So probably your compiler just ignores the register keyword like M$ VC++ 6.0/7.0 compilers do.

    Ignoring that little fact, taking the address of a register variable is a compile-time error, not runtime. If the compiler did not ignore register keyword then it should have produced an error, not a warning.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion