This is a mistake (or "wart" if you want to be generous).
The rest of this answer applies only to GCC and the standard Gnu library libraries. The man pages link to the linux system (but I added links to man7.org ).
The DOMAIN macro comes from the support of math.h System V. (See man matherr .) System V support is usually _SVID_SOURCE by defining the macro of the _SVID_SOURCE function (see man feature_test_macros ), but it is included with many other extensions if _GNU_SOURCE defined, or by default if function macros are not defined.
gcc predefines _GNU_SOURCE for C programs if the --std option --std omitted or set to gnu## . The various options --std=c## call the __STRICT_ANSI__ definition. Therefore, compiling C code with some explicit C standard will suppress System V extensions. This is necessary because System V extensions are not standards compliant, even Posix, as they pollute the global namespace. ( DOMAIN is just one example of this contamination.)
However, g++ defines _GNU_SOURCE even if --std=c++## is specified, and therefore the System V extension will expand. (Thanks to @dyp for linking to this libstdC ++ FAQ. And this is a long and unconvincing discussion on the mailing list since 2001 Gcc )
An ugly workaround is to configure the functions yourself, and then undefine __USE_SVID :
#include <features.h> #undef __USE_SVID #include <random> #include <iostream> int main(){ std::cout << DOMAIN << std::endl; return 0; }
( Live on coliru )
IMHO, this is not necessary. But there it is.
source share