我知道在 C++ 中,标识符中的双下划线是为编译器保留的。我有一些 C 代码,在相应的头文件中具有与此类似的特征:
extern "C" {
#define HELLO__THERE 1
int hello__out__there( int );
}
我将在 C++ 项目中使用此 header ,并计划在 C++ 中执行以下操作:
if (HELLO__THERE == abc)
hello__out__there(foo);
标准涵盖了 C++ 中可接受的行为吗?
最佳答案
在 C++03 标准 17.4.3.1.2 全局名称
中,下划线的使用被定义为保留:
Each name that contains a double underscore (_ _) or begins with an underscore followed by an upper- case letter (2.11) is reserved to the implementation for any use.
保留意味着它可能用于任何符合规范的实现,因此不建议使用它。
关于C++ 使用 C 代码在定义和标识符中使用双下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6756059/