c++ - 在 C++ 中注册存储说明符

标签 c++ cpu-registers

我很想知道 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/

相关文章:

assembly - 为什么我们在汇编的CALLEE中出现 "PUSH EBP"和 "MOV EBP, ESP"?

c++ - 隐式转换 : is the following warning valid?

c++ - 从数组中删除重复项的算法不起作用

c++ - cuda 文件组织的有效方式 : . cpp .h .cu .cuh .curnel 文件

c++ - 使用 boost::hana 传递反射

assembly - 将值加载到 LC3 中的寄存器中

c++ - 为什么一个字会大于 1 个字节?

c++ - 调试期间 Qt Creator 中的外设寄存器

assembly - V*** 和 F*** 浮点 ARM 指令有什么区别?

c++ - MQL4:对象 = (类*)NULL;