tags:

views:

128

answers:

4

How do you determine what version of the C++ standard is implemented by your compiler? As far as I know, below are the standards I've known:

  • C++03
  • C++98
+2  A: 

After a quick google:

__STDC__ and __STDC_VERSION__, see here

Tor Valamo
Whether `__STDC__` is defined, and what its value is, are implementation-defined in C++.
Rob Kennedy
@Rob: Yes, it is.@Tor: I tried in VC++ 2005 but it says __STDC__ is an undeclared identifier. It is listed as one of those pre-defined macros though. However, __STDC_VERSION__ does not exist.
jasonline
+3  A: 

By my knowledge there is no overall way to do this. If you look at the headers of cross platform/multiple compiler supporting libraries you'll always find a lot of defines that use compiler specific constructs to determine such things:

/*Define Microsoft Visual C++ .NET (32-bit) compiler */
#if (defined(_M_IX86) && defined(_MSC_VER) && (_MSC_VER >= 1300)
     ...
#endif

/*Define Borland 5.0 C++ (16-bit) compiler */
#if defined(__BORLANDC__) && !defined(__WIN32__)
     ...
#endif

You probably will have to do such defines yourself for all compilers you use.

RED SOFT ADAIR
Not my expected answer though but I guess there's just no universal way of finding it out.
jasonline
+3  A: 

Depending on what you want to achieve, Boost.Config might help you. It does not provide detection of the standard-version, but it provides macros that let you check for support of specific language/compiler-features.

Space_C0wb0y
Checking for features is probably a better idea than checking standard versions, anyway. Few compilers support *everything* from a standard, but if they all support the limited number of features you need, then it doesn't really matter whether the rest of the features from a given standard are implemented and working correctly.
Rob Kennedy
A: 

__cplusplus

In C++0x the macro __cplusplus will be set to a value that differs from (is greater than) the current 199711L.

C++0x FAQ by BS

Vinzenz