Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register storage specifier in C++

I am curious to know to behavior of register storage specifier in C/C++. Following program valid in C++, but in case of C it's not valid.

int main()
{
        register int i;
        int* b = &i; // Valid in C++ but not in C
}

So, My question I, Why C++ allowed address operator(&) to a register variable?

P.S : I know register storage specifier is deprecated in modern compiler.

like image 392
msc Avatar asked Feb 03 '26 00:02

msc


1 Answers

Your answer can be found here:

http://en.cppreference.com/w/cpp/language/storage_duration

In C, the address of a register variable cannot be taken, but in C++, a variable declared register is semantically indistinguishable from a variable declared without any storage class specifiers.

like image 66
Mikel F Avatar answered Feb 05 '26 13:02

Mikel F



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!