GNU C++ how to check when -std=c++0x is in effect?

There seems, with gcc 4.4.4, to be only one predefined macro hinting that -std=c++0x is in effect:

#define __GXX_EXPERIMENTAL_CXX0X__ 1

I don’t have access to gcc 4.5.0 , but you can check that one yourself:

[16:13:41 0 ~] $ g++ -E -dM -std=c++0x -x c++ /dev/null >b
[16:13:44 0 ~] $ g++ -E -dM -std=c++98 -x c++ /dev/null >a
[16:13:50 0 ~] $ diff -u a b
--- a   2010-06-02 16:13:50.200787591 +0200
+++ b   2010-06-02 16:13:44.456912378 +0200
@@ -20,6 +20,7 @@
 #define __linux 1
 #define __DEC32_EPSILON__ 1E-6DF
 #define __unix 1
+#define __GXX_EXPERIMENTAL_CXX0X__ 1
 #define __LDBL_MAX_EXP__ 16384
 #define __linux__ 1
 #define __SCHAR_MAX__ 127

For one-line command do,

g++ -E -dM -std=c++98 -x c++ /dev/null > std1 && g++ -E -dM -std=c++0x -x c++ /dev/null > std2 && diff -u std1 std2 | grep '[+|-]^*#define' && rm std1 std2

gives you something like:

+#define __GXX_EXPERIMENTAL_CXX0X__ 1

Leave a Comment