c++ - "unix"C++ 预处理器宏未使用 -std=c++11 定义

标签 c++ c++11 unix preprocessor icc

unixpreproc.cpp

#ifdef unix
#warning "unix is defined"
#endif

#ifdef __unix__
#warning "__unix__ is defined"
#endif

void main() {}

使用英特尔 C++ 编译器 19.0.3:

icpc -o unixpreproc unixpreproc.cpp 显示 unix__unix__ 宏都定义了

但是

icpc -std=c++11 -o unixpreproc unixpreproc.cpp 显示仅定义了 __unix__。这是故意的吗?是not documented in the Intel compiler manual .

最佳答案

是的,这是非常刻意的。这在 GCC 手册中有解释(在这方面与 icpc 的行为相同):

The C standard requires that all system-specific macros be part of the reserved namespace. All names which begin with two underscores, or an underscore and a capital letter, are reserved for the compiler and library to use as they wish. However, historically system-specific macros have had names with no special prefix; for instance, it is common to find unix defined on Unix systems. For all such macros, GCC provides a parallel macro with two underscores added at the beginning and the end. If unix is defined, __unix__ will be defined too. There will never be more than two underscores; the parallel of _mips is __mips__.

When the -ansi option, or any -std option that requests strict conformance, is given to the compiler, all the system-specific predefined macros outside the reserved namespace are suppressed. The parallel macros, inside the reserved namespace, remain defined.

参见 https://gcc.gnu.org/onlinedocs/cpp/System-specific-Predefined-Macros.html

-std=c++11 选项要求严格遵守。 -std=gnu++11 选项是非严格等效的,它将定义 unix 以及 __unix__

关于c++ - "unix"C++ 预处理器宏未使用 -std=c++11 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57304931/

相关文章:

c++ - SFINAE 在函数前加符号与其名称

regex - 在 Linux 中查找具有匹配模式的文件

c++ - 没有显式特化声明的显式模板特化

c++ - xcode 4.6 iostream 文件未找到错误?

c++ - 无法将派生类存储在基类指针的 vector 中

unix - 如何在 SFTP 中传输二进制文件?

linux - 将最新的文件名放入比特定时间早的变量中

c++ - 关于正确使用智能指针的问题

c++ - C++ 打印 → 在 Windows 控制台上

c++ - 为什么抛出局部变量调用 moves 构造函数?