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

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

All Replies

  • Sunday, December 27, 2009 6:32 AM
     
     
    Exactly
  • Sunday, December 27, 2009 3:12 PM
     
     
    why why why why WHY
    «_Superman_»
    Microsoft MVP (Visual C++)
  • Monday, December 28, 2009 1:13 PM
     
     Answered Has Code
    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
    •