代码之家  ›  专栏  ›  技术社区  ›  TerryP

GNUC++如何检查STD=C++ +0x何时生效?

  •  37
  • TerryP  · 技术社区  · 15 年前

    /usr/local/lib/gcc45/include/c++/bits/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
    

    必须提供一个额外的开关是没有问题的,在这个系统(FreeBSD)下支持gcc4.4和4.5,但显然它改变了局面!

    #include <tr1/foo>
    using std::tr1::foo;
    

    使用-std=c++0x的较新(4.5)版本的编译器:

    #include <foo>
    using std::foo;
    

    不管怎样,使用预处理器,我可以知道G++是否运行了C++启用的0x特性?

    像这样的东西正是我要找的 :

    #ifdef __CXX0X_MODE__
    #endif
    

    但我没有在手册里或网上找到任何东西。

    3 回复  |  直到 15 年前
        1
  •  36
  •   James McNellis    15 年前

    如果你用 -std=c++0x ,那么 __GXX_EXPERIMENTAL_CXX0X__

        2
  •  82
  •   abumusamq    12 年前

    #define __GXX_EXPERIMENTAL_CXX0X__ 1
    

    我没有访问gcc 4.5.0的权限,但您可以自己检查:

    [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
    

    对于一行命令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
    

    +#define __GXX_EXPERIMENTAL_CXX0X__ 1
    
        3
  •  17
  •   emsr    13 年前

    gcc-4.7 以后,您将能够检查\uu cplusplus:

    “G+现在将预定义的宏、.c++的PLUS添加到正确的值,对于C++ 98/03,以及对C++ 11的201103L,则将其定义为“1997年11L”。

    推荐文章