Pre-defined C/C++ Compiler Macros

Index Standards Compilers Operating Systems Architecture

Compilers

Most compilers defines macros to indicate the compiler and its version. These are useful to avoid bugs in certain compiler versions, or to check for the existance of certain features.
 
Name Macro Version
Borland Turbo C __TURBOC__ __TURBOC__ 

Examples
 
Turbo C __TURBOC__
2.0 397
3.0 661

Borland C++ __BORLANDC__ __BORLANDC__ 

Examples
 
Borland C++ C++ Builder __BORLANDC__
2.0   0x200
3.0   0x400
3.1   0x410
4.0   0x452
5.0   0x500
5.02 1.0 0x520
  3.0 0x530
  4.0 0x540
5.5 5.0 0x550
5.51   0x551

Comeau C++ __COMO__
__COMO_VERSION__ = VRR V = Version

RR = Revision

Examples
 
Comeau C++ __COMO_VERSION__
2.30 230

Compaq C __DECC
VAXC
__VAXC
__DECC_VER = VVRRTPPPP VV = Version

RR = Revision

T = Type (9 = official)

PPPP = Patch

Examples
 
DEC C __DECC_VER
6.0-001 60090001


The older bundled DEC C compiler does not define __DECC. Instead the following can be used

     #if defined(__osf__) && defined(__LANGUAGE_C__)
     /* Old DEC C compiler */
     #endif
     
Compaq C++ __DECCXX As __DECC (using __DECCXX_VER)
Cray C/C++ _CRAYC
_REVISION = V V = Version
Cygwin __CYGWIN__ ?
Diab C/C++ __DCC__
__VERSION_NUMBER__ = VRPP V = Version

R = Revision

PP = Patch

Examples
 
Diab C/C++ __VERSION_NUMBER__
4.4q 4426

Digital Mars
Symatec C++
Zortech C++
__DMC__
__SC__
__ZTC__
__DMC__ = 0xVRP V = Version

R = Revision

P = Patch

Examples
 
Digital Mars __DMC__
7.0 0x700
7.2 0x720
8.0 0x800

GCC __GNUC__
__GNUC__ Version
__GNUC_MINOR__ Revision
__GNUC_PATCHLEVEL__ Patch (Introduced with version 3.x)

Examples
 
GCC __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__
2.7.x 2 7
3.0.2 3 0 2


If you prefer a single version macro, you can define the following.

#if defined(__GNUC__)
# if defined(__GNU_PATCHLEVEL__)
#  define __GNUC_VERSION__ (__GNUC__ * 10000 \
                            + __GNUC_MINOR__ * 100 \
                            + __GNUC_PATCHLEVEL__)
# else
#  define __GNUC_VERSION__ (__GNUC__ * 10000 \
                            + __GNUC_MINOR__ * 100)
# endif
#endif
The syntax of this new macro is:
 
__GNUC_VERSION__ = VVRRPP VV = Version

RR = Revision

PP = Patch

Examples
 
GCC __GNUC_VERSION__
2.7.x 20700
3.0.2 30002

HP ANSI C / aC++ __HP_cc
__HP_aCC
__HP_aCC = VVRRPP VV = Version

RR = Revision

PP = Patch

Examples
 
HP aC++ __HP_aCC
A.01.21 012100


The __HP_aCC macro was introduced in version A.01.15 (and A.03.13), where it is set to 1. Beginning with version A.01.21 (and A.03.25) __HP_aCC is set as above.

The C compiler defines the __HP_cc macro, and the C++ compiler the __HP_aCC macro.

IBM xlC __xlC__
__IBMC__
__IBMCPP__
__xlC__ = 0xVVRR VV = Version

RR = Revision

Examples
 
IBM xlC __xlC__
3.1 0x0301
5.0 0x0500


Older versions of xlC does not define any of these macros, but can be detected with

     #if defined(_AIX) && !defined(__GNUC__)
     /* Old xlC compiler */
     #endif
     
Intel __INTEL_COMPILER
__ICC
__INTEL_COMPILER = VRP V = Version

R = Revision

P = Patch

Examples
 
Intel C __INTEL_COMPILER
4.0 400
5.0 500

KAI C++ __KCC
__KCC_VERSION = 0xVRPP V = Version

R = Revision

PP = Patch (a = 01, b = 02, ...)

Examples
 
KAI C++ __KCC_VERSION
4.0d 4004


Please note that Intel has has discontinued development of the KAI C++ compiler in spring 2002.

LCC __LCC__ ?
MetaWare High C/C++ __HIGHC__ ?
Metrowerks Codewarrior __MWERKS__
__MWERKS__ = 0xVRPP V = Version

R = Revision

PP = Patch

Examples
 
Metrowerks C/C++ __MWERKS__
2.0 0x2000
2.2 0x2200


Starting with CodeWarrior 7 __MWERKS__ is defined as above (prior versions defined __MWERKS__ to 1).

MinGW __MINGW32__ ?
MIPSpro sgi
__sgi
__COMPILER_VERSION = VRP V = Version

R = Revision

P = Patch

Examples
 
MIPSpro __COMPILER_VERSION
6.0.2 602
7.2.1 721

MPW C++ __MRC__
MPW_C
MPW_CPLUS
__MRC__ = 0xVVRR VV = Version

RR = Revision

Examples
 
MPW C++ __MRC__
5.0 0x500

MS Visual C++ _MSC_VER Examples
 
Visual C++ _MSC_VER
1.0 800
3.0 900
4.0 1000
4.2 1020
5.0 1100
6.0 1200
Norcroft C __CC_NORCROFT
__ARMCC_VERSION = V.R V = Version

R = Revision

Notice that the __ARMCC_VERSION macro is assigned a floating-point number, so it cannot be used by the preprocessor to compare versions. 

Examples
 
Norcroft C __ARMCC_VERSION
4.69 4.69
4.90 4.90

SAS/C SASC
__SASC
__SASC__
__SASC__ = VRR
__VERSION__ =V
__REVISION__ = RR
V = Version
RR = Revision

Examples

 
SAS/C __SASC__ __VERSION__ __REVISION__
5.10
5 10
6.50 650

SCO OpenServer _SCO_DS N/A
Sun Workshop C/C++ __SUNPRO_C
__SUNPRO_CC
__SUNPRO_C = 0xVRP V = Version

R = Revision

P = Patch

Examples
 
Workshop Pro __SUNPRO_C
4.2 0x420
5.0 0x500


__SUNPRO_C is defined when compiling C, and __SUNPRO_CC when compiling C++. 

The version of the compiler can be determined from either of these macros, but is illustrated above for the __SUNPRO_C macro. It may be a good idea to define a version macro like this

     #if defined(__SUNPRO_C)
     # define __SUNPRO_VERSION __SUNPRO_C
     #elif defined(__SUNPRO_CC_
     # define __SUNPRO_VERSION __SUNPRO_CC
     #endif
     
Tiny C
__TINYC__
Always set to 1
USL C __USLC__
__SCO_VERSION__ = 0xVRRYYYYMM V = Version

RR = Revision

YYYY = Year

MM = Month

Examples
 
USL C __SCO_VERSION
3.2 302199801

Watcom C++ __WATCOMC__ Examples
 
Watcom C++ __WATCOMC__
10.5 1050
11.0 1100

Example: int8_t

Expanding on the int8_t example from the Standards section.
# if defined(_MSC_VER) && (_MSC_VER >= 1100)
typedef __int8 int8_t;
# endif

$Id: precomp.html,v 1.3 2004/05/31 09:13:34 breese Exp $