"unix" C++ preprocessor macro is undefined with -std=c++11 "unix" C++ preprocessor macro is undefined with -std=c++11 unix unix

"unix" C++ preprocessor macro is undefined with -std=c++11


Yes, it's very deliberate. This is explained in the GCC manual (which behaves the same as icpc in this respect):

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.

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

The -std=c++11 option requests strict conformance. The -std=gnu++11 option is the non-strict equivalent, which will define unix as well as __unix__.


I would assume this is deliberate, yes. Under the C++11 standard (and the other formally published C++ standards), conforming compilers cannot declare whatever macros and other global symbols they want, because those could interfere with the program's use of those names. Outside the specific list of standard reserved names (which does not include unix), compilers must use macro names starting with a double underscore, which are reserved for the compiler's use.

When you don't specify any language standard the compiler is going with its default behavior, which eschews strict standards compliance in favor of backwards compatibility.