What if you need a pointer to an integer with a value of 42? :)
C ++ references are very similar to automatically dereferenced pointers. You can create a permalink to a literal, for example:
const int &x = 42;
This effectively requires the compiler to initialize a pointer with an integer address with a value of 42, as you could later do this:
const int *y = &x;
Combine this with the fact that compilers must have logic in order to distinguish between a value that does not have an accepted address and one that has, so it knows to store it in memory. The first does not have to be a place for memory, because it can be completely temporary and stored in a register, or it can be eliminated by optimization. Accepting the address of a value is potentially an alias; the compiler cannot track and block the optimization. Thus, using the & operator can force a value, regardless of what it is, into memory.
So, you may have discovered an error that combined these two effects.
source share