Why can I take the address of a register variable?

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;
// error
// register int global2 = 3;

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?

+4
source share
2 answers

True, historically you could not take the address of a variable register.

. ++ , register

... , (3.7.3).

, ... . , register, ++.

+5

g++ register. , , , , .

- C, , , .

, , ( Intel ), wetware .

+1

All Articles