How to use macros to check which compiler and language version you have?

  • BOOST can be used? - Vladimir Gamalyan
  • @VladimirGamalian preferably by standard methods - user229736
  • The standard about it says nothing unfortunately. - Vladimir Gamalyan
  • If there are places in the code that are rigidly connected with the compiler used, use constructions like this: #if defined( _MSC_VER > ... ) ... #elif defined( __GNUC__ > N ) ... #endif Perhaps it will help))) - isnullxbh

1 answer 1

Each particular compiler defines its own macros; There are no common macros that the compiler can specify.

As for the language version, there are predefined macros of the type __STDC__ or __STDC_VERSION__ , but their specific values ​​are left to the implementations.

For example, from the standard:

_ _ STDC_VERSION _ _
It is a predetermined implementation.

So it is better to look at the documentation for different compilers and collect macros defined in them. And then check - if there is such a macro, it means that this is such a compiler, and its version is like this ... _MSC_VER type in Visual C ++.

  • and __cplusplus ? - user229736
  • one
    But he does not say anything about the compiler and its version. Theoretically, the standard draft says The name _ _ cplusplus is defined to the value 201103L when compiling a C++ translation unit. , but, for example, VC ++ 2015 gives its value to 199711 ... - Harry
  • @Harry, but in theory, he can determine the version of the language. But why? Type C ++ 03 - we use custom predicates in std :: find, C ++ 11 - we can create lambdas .. It’s kind of stupid .. ( - isnullxbh
  • one
    определенные предопределенные definitely - αλεχολυτ
  • @alexolut Not that tongue gets messed up, not the keyboard :) - Harry