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

前端 未结 3 1034
梦毁少年i
梦毁少年i 2020-11-29 18:38

My system compiler (gcc42) works fine with the TR1 features that I want, but trying to support newer compiler versions other than the systems, trying to accessing TR1 header

相关标签:
3条回答
  • 2020-11-29 18:53

    If you compile with -std=c++0x, then __GXX_EXPERIMENTAL_CXX0X__ will be defined.

    0 讨论(0)
  • 2020-11-29 19:03

    Well, from gcc-4.7 onwards you'll be able to check __cplusplus:

    "G++ now sets the predefined macro __cplusplus to the correct value, 199711L for C++98/03, and 201103L for C++11"

    This should be the correct, standard-compliant way to do it. Unfortunately, it doesn't work for most gcc installed in the wild.

    0 讨论(0)
  • 2020-11-29 19:11

    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
    
    0 讨论(0)
提交回复
热议问题