none
how do you check which compiler you are using in c++

Answers

  • The compiler will predefine some macros that you can detect to determine which compiler you are using.

    For example, Microsoft Visual C++ is defining _MSC_VER to a value:
     
    MSVC++ 9.0   _MSC_VER = 1500
    MSVC++ 8.0   _MSC_VER = 1400
    MSVC++ 7.1   _MSC_VER = 1310
    MSVC++ 7.0   _MSC_VER = 1300
    MSVC++ 6.0   _MSC_VER = 1200
    MSVC++ 5.0   _MSC_VER = 1100
    


    You should be able to make use of something like #ifdef _MSC_VER and #if _MSC_VER > 1400 or whatever your specific needs are.


    You can also detect symbols like __WIN32__ to detect if you are in a Windows build environment.  Some compilers will define __unix__ or __APPLE__ if your build environment is of that variety.

    Or for gcc you can use something like this:

    /* Test for GCC > 3.2.0 */
    #if __GNUC__ > 3 || \
        (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \
            (__GNUC_MINOR__ == 2 &&  __GNUC_PATCHLEVEL__ > 0))
    


    You can also detect __STDC__ to see if you are using an ANSI C compiler.


    • Proposed as answer by Wesley Yao Tuesday, December 29, 2009 2:58 AM
    • Marked as answer by Wesley Yao Monday, January 04, 2010 2:55 AM
    Monday, December 28, 2009 1:13 PM

All replies