GCCG with C++11
Martin Sebor
msebor@redhat.com
Thu May 28 15:51:00 GMT 2015
On 05/28/2015 09:24 AM, Hotmail (ArbolOne) wrote:
> If I am not mistaken _MSC_VER >= 1600 is the version that started
> implementing C++11. So, I test for that version of the compiler in my
> code, i.e.
> #ifdef _MSC_VER >= 1600
> ....
> #endif
> I would like to do the same for __GNUG__, but what version of g++
> started implementing C++11?
The standard specifies that implementations conforming to C++
11 must define the __cplusplus macro to 201103L, and recommends
that non-conforming compilers (presumably those that aim to be
C++11 conforming but whose support is incomplete) should use
a value with at most five decimal digits.
C++ 98 defines __cplusplus to 199711L, and C++ 14 to 201402L.
With that, the following should cover past and future cases:
#if __cplusplus == 199711L
// C++ 98 conforming implementation
#elif __cplusplus == 201103L
// C++ 11 conforming implementation
#elif __cplusplus == 201402L
// C++ 14 conforming implementation
#elif __cplusplus > 201402L
// future C++ implementation
#elif 0 < __cplusplus && __cplusplus < 100000L
// non-conforming C++ implementation
#else
// not C++ or a non-conforming C++ implementation
#endif
Though it seems to me that the recommendation in the footnote
below quoted from 16.8 Predefined Macros, blurs the distinction
between incomplete C++ implementations targeting C++ 11 and 14
(and 17).
157) It is intended that future versions of this standard
will replace the value of this macro with a greater value.
Non-conforming compilers should use a value with at most
five decimal digits.
Martin
More information about the Gcc-help
mailing list