Cited from the book "Thinking in c++" the section about register variable: "There are restrictions to the use of register variables. You cannot take or compute 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 piece of program to test:
int global = 2;
// error
// register int global2 = 3;
int main() {
register int local2 = 2;
cout << local2 << " " << &local2 << endl;
}
However g++ generates no error and the address of local2 is printed out. So why I can take the address with no error?