I understand that in C, if a variable is explicitly specified with the register
keyword, then one cannot use the &
operator on it, and that makes sense to me that there's no such thing as "address" of a variable that's always kept in a register.
My question is, if the compiler decides on its own to store a variable in register rather than spilling it, then what happens with the &
operator during code execution?
I can think of two ways that the compiler might try to handle this:
- Try to emulate the
&
behavior, but this seems hairy and I have no idea how one would do this rigorously and efficiently. - Always spill a variable if the
&
operator is used with this variable.
Does C take one of these approaches or does it do something else in this case?