我很想知道 register
存储说明符在 C/C++
中的行为。以下程序在 C++
中有效,但在 C
中无效。
int main()
{
register int i;
int* b = &i; // Valid in C++ but not in C
}
那么,我的问题是,为什么 C++ 允许对寄存器变量使用地址运算符 (&)?
P.S:我知道 register 存储说明符在现代编译器中已被弃用。
最佳答案
您的答案可以在这里找到:
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.
关于c++ - 在 C++ 中注册存储说明符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41942156/