gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:09:12 32 4
gpt4 key购买 nike

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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com