How to use macros to check which compiler and language version you have?
|
1 answer
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 - oneBut 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
|
#if defined( _MSC_VER > ... ) ... #elif defined( __GNUC__ > N ) ... #endifPerhaps it will help))) - isnullxbh