Quoted from the book “Thinking in C ++” in the section on register variables: “There are restrictions on the use of register variables. You cannot accept or calculate the address of a register variable. A register variable can only be declared within a block (you cannot have global or static register variables).
So, I wrote this part of the program for testing:
int global = 2;
int main() {
register int local2 = 2;
cout << local2 << " " << &local2 << endl;
}
However, g ++ does not generate errors and the local2 address is issued. So why can I accept the address without errors?
source
share