各个编译器预定义的表示编译器类型和版本号的宏

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.

Table of Content - Compilers

Borland Turbo C

TypeMacroFormat
Identification__TURBOC__.
Version__TURBOC__?
Example

Turbo C__TURBOC__
2.0397
3.0661

Official siteWikipedia

Borland C++

TypeMacroFormat
Identification__BORLANDC__.
Version__BORLANDC__?
Example

Borland C++C++ Builder__BORLANDC__
2.0.0x200
3.0.0x400
3.1.0x410
4.0.0x452
5.0.0x500
5.021.00x520
.3.00x530
.4.00x540
5.55.00x550
5.51.0x551

Official siteGoogle DirectoryWikipedia

Comeau C++

TypeMacroFormatDescription
Identification__COMO__..
Version__COMO_VERSION__VRRV = Version
RR = Revision
Example

Comeau C++__COMO_VERSION__
2.3230

Official site

Compaq C/C++

TypeMacroFormatDescription
Identification__DECC.C compiler
Version__DECC_VERVVRRTPPPPVV = Version
RR = Revision
T = Type (9 = official)
PPPP = Patch
Identification__DECCXX.C++ compiler
Version__DECCXX_VERAs __DECC_VER.
Identification__VAXC.Obsolete
IdentificationVAXC.Obsolete
Example

Compaq C/C++__DECC_VER
6.0-00160090001

Official site

Cray C

TypeMacroDescription
Identification_CRAYC.
Version_RELEASEVersion
Version_RELEASE_MINORRevision

Official site

Cygwin

TypeMacro
Identification__CYGWIN__

Official siteWikipedia

Diab C/C++

TypeMacroFormatDescription
Identification__DCC__1.
Version__VERSION_NUMBER__VRPPV = Version
R = Revision
PP = Patch
Example

Diab C/C++__VERSION_NUMBER__
4.4g4426

Official site

Digital Mars

TypeMacroFormatDescription
Identification__DMC__..
Identification__SC__.Obsolete
Identification__ZTC__.Obsolete
Version__DMC__0xVRPV = Version
R = Revision
PP = Patch
Example

Digital Mars__DMC__
7.00x700
7.20x720
8.00x800

Official site

DJGPP

TypeMacroDescription
Identification__DJGPP__.
Version__DJGPP__Version
Version__DJGPP_MINOR__Revision
Identification__GO32__Defined by DJGPP 1.x
Example

DJGPP__DJGPP____DJGPP_MINOR__
2.0121

Official siteGoogle DirectoryWikipedia

EKOPath

TypeMacroDescription
Identification__PATHCC__.
Version__PATHCC__Version
Version__PATHCC_MINOR__Revision
Version__PATHCC_PATCHLEVEL__Patch
Example

EKOPath__PATHCC____PATHCC_MINOR____PATHCC_PATCHLEVEL__
2.0200

Official site

EDG C++ Front End

TypeMacroFormatDescription
Identification__EDG__..
Version__EDG_VERSION__VRRV = Version
RR = Revision
Example

EDG C++__EDG_VERSION__
2.30230

Official site

GNU C/C++

TypeMacroDescription
Identification__GNUC__.
Version__GNUC__Version
Version__GNUC_MINOR__Revision
Version__GNUC_PATCHLEVEL__Patch (introduced in version 3.0)
Example

GNU C/C++__GNUC____GNUC_MINOR____GNUC_PATCHLEVEL__
2.7.x27.
3.0.2302

Alternative Version

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

#if defined(__GNUC__)
# if defined(__GNUC_PATCHLEVEL__)
#  define __GNUC_VERSION__ (__GNUC__ * 10000 /
                            + __GNUC_MINOR__ * 100 /
                            + __GNUC_PATCHLEVEL__)
# else
#  define __GNUC_VERSION__ (__GNUC__ * 10000 /
                            + __GNUC_MINOR__ * 100)
# endif
#endif

The format of this new macro is:

TypeMacroFormatDescription
Version__GNUC_VERSION__VVRRPPVV = Version
RR = Revision
PP = Patch
Example of Alternative Version

GNU C/C++__GNUC_VERSION__
2.7.x20700
3.0.230002

Official siteGoogle DirectoryWikipedia

Green Hill C/C++

TypeMacroFormatDescription
Identification__ghs__..
Version__GHS_VERSION_NUMBER__VRPV = Version
R = Revision
P = Patch
Version__GHS_REVISION_DATE__Epoch time.
Example

Green Hill C/C++__GHS_VERSION_NUMBER__
4.2.1421

Official siteWikipedia

HP ANSI C

TypeMacro
Identification__HP_cc

Official site

HP aCC

TypeMacroFormatDescription
Identification__HP_aCC..
Version__HP_aCC1From version A.01.15 (and A.03.13)
Version__HP_aCCVVRRPPVV = Version
RR = Revision
PP = Patch

From version A.01.21 (and A.03.25)

HP aCC__HP_aCC
A.01.21012100

Official site

IBM XL C/C++

TypeMacroFormatDescription
Identification__xlC__..
Version__xlC__0xVVRRVV = Version
RR = Revision
Identification__IBMC__.From ?
Identification__IBMCPP__.From ?
Version__IBMC__
__IBMCPP__
VRPV = Version
R = Revision
P = Patch

Please note that the z/OS C/C++ compiler also defines __IBMC__ and __IBMCPP__ macros, but with a different syntax. See the entry on the z/OS C/C++ compiler below for further information.

Example

IBM XL C/C++__xlC____IBMC__
3.10x0301.
4.50x0405450
5.00x0500500

Official siteWikipedia

IBM z/OS C/C++

This is the XL C/C++ compiler for mainframes (e.g. z/OS). The entry on XL C/C++ has been split into two for clarity.

TypeMacroFormatDescription
Identification__IBMC__..
Identification__IBMCPP__..
Version__IBMC__
__IBMCPP__
NVRRMN = Product (0 = C/370, 1 = MVS, 2 = OS/390, 4 = z/OS)
V = Version
RR = Revision
P = Patch

Defined for z/OS XL C/C++
Version__COMPILER_VER__0xNVRRPPPPN = Product (see above)
V = Version
RR = Revision
PPPP = Patch

Defined for z/OS XL C/C++

Please note that XL C/C++ also defines __IBMC__ and __IBMCPP__ macros, but with a different syntax. You can use __xlC__ (only defined for XL C/C++) or __COMPILER_VER__ (only defined for z/OS C/C++) to distinguish between the two.

#if defined(__IBMC__) || defined(__IBMCPP__)
# if defined(__COMPILER_VER__)
/* z/OS C/C++ so __IBMC__ is defined as NVRRM */
# else
/* XL C/C++ so __IBMC__ is defined as VRP */
# endif
#endif
Example

IBM z/OS XL C/C++__IBMC____COMPILER_VER__
1.7410700x41070000

Official siteWikipedia

IAR C/C++

TypeMacroFormatDescription
Identification__IAR_SYSTEMS_ICC__..
Version__VER__VRRV = Version
RR = Revision
Example

IAR C/C++__VER__
3.34334

Official site

Intel C/C++

TypeMacroFormatDescription
Identification__INTEL_COMPILER..
Identification__ICC.Obsolete
Identification__ECC.Obsolete
Identification__ICL..
Version__INTEL_COMPILERVRPV = Version
R = Revision
P = Patch
Version__INTEL_COMPILER_BUILD_DATEYYYYMMDDYYYY = Year
MM = Month
DD = Day
Example

Intel C/C++__INTEL_COMPILER__INTEL_COMPILER_BUILD_DATE
5.0500.
6.0600.
8.0800.
9.090020060222

Official site

KAI C++

TypeMacroFormatDescription
Identification__KCC..
Version__KCC_VERSION0xVRPPV = Version
R = Revision
PP = Patch (a = 01, b = 02, ...)
Example

KAI C++__KCC_VERSION
4.0d4004

Official site

Keil CARM

TypeMacroFormatDescription
Identification__CA__..
Identification__KEIL__..
Version__CA__VRRV = Version
R = Revision
Example

Keil CARM__CA__
1.01101

Official site

Keil C166

TypeMacroFormatDescription
Identification__C166__..
Version__C166__VRRV = Version
R = Revision
Example

Keil C166__C166__
5.01501

Official site

Keil C51

TypeMacroFormatDescription
Identification__C51__..
Identification__CX51__..
Version__C51__VRRV = Version
R = Revision
Example

Keil C51__C51__
7.01701

Official site

LCC

TypeMacro
Identification__LCC__

Official siteWikipedia

LLVM

TypeMacro
Identification__llvm__

Official siteWikipedia

MetaWare High C/C++

TypeMacro
Identification__HIGHC__

Official site

Metrowerks CodeWarrior

TypeMacroFormatDescription
Identification__MWERKS__..
Version__MWERKS__1Until CodeWarrior 7
Version__MWERKS__0xVRPPV = Version
R = Revision
PP = Patch

From CodeWarrior 7
Example

Metrowerks C/C++__MWERKS__
2.00x2000
2.20x2200

Official siteWikipedia

MinGW

TypeMacroDescription
Identification__MINGW32__.
Version__MINGW32_MAJOR_VERSIONVersion
Version__MINGW32_MINOR_VERSIONRevision
Example

MinGW__MINGW32_MAJOR_VERSION__MINGW32_MINOR_VERSION
2.424

Official siteWikipedia

MIPSpro

TypeMacroFormatDescription
Identification__sgi..
Identificationsgi..
Version_COMPILER_VERSIONVRPV = Version
R = Revision
P = Patch

Until ?
Version_SGI_COMPILER_VERSIONVRPV = Version
R = Revision
P = Patch

From ?
Example

MIPSpro_COMPILER_VERSION_SGI_COMPILER_VERSION
6.0.2602.
7.2.1721.
7.4.4.744

Official site

MPW C++

TypeMacroFormatDescription
Identification__MRC__..
IdentificationMPW_C..
IdentificationMPW_CPLUS..
Version__MRC__0xVVRRVV = Version
RR = Revision
Example

MPW C++__MRC__
5.00x500

Official site

Microsoft Visual C++

TypeMacroFormatDescription
Identification_MSC_VER..
Version_MSC_VERVVRRVV = Version
RR = Revision
Version_MSC_FULL_VERVVRRPPPPVV = Version
RR = Revision
PPPP = Patch

From ?
Version_MSC_FULL_VERVVRRPPPPPVV = Version
RR = Revision
PPPPP = Patch

From ?

Please note that _MSC_FULL_VER is not officially documented by the vendor.

Example

Visual C++_MSC_VER_MSC_FULL_VER
1.0800.
3.0900.
4.01000.
4.21020.
5.01100.
6.01200.
6.0 SP6120012008804
7.0130013009466
7.1 (2003)131013103077
8.0 (2005)1400140050727

Official siteGoogle DirectoryWikipedia

Microtec C/C++

TypeMacro
Identification_MRI

Official site

Norcroft C

TypeMacroFormatDescription
Identification__CC_NORCROFT..
Version__ARMCC_VERSIONV.RV = Version
R = Revision

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

Example

Norcroft C__ARMCC_VERSION
4.694.69
4.904.90

Pacific C

TypeMacro
Identification__PACIFIC__

Official site

Palm C/C++

TypeMacroFormatDescription
Identification_PACC_VER..
Version_PACC_VER0xVRRPPBBBV = Version
RR = Revision
PP = Patch
BBB = Build
Example

Palm C/C++_PACC_VER
1.0.0.130x1000000D

Official siteGoogle Directory

Pelles C

TypeMacroFormatDescription
Identification__POCC__..
Version__POCC__VRRV = Version
RR = Revision
Example

Pelles C__POCC__
3.00300

Official site

Portland Group C/C++

TypeMacro
Identification__PGI

Official site

RealView C

TypeMacroFormatDescription
Identification__CC_ARM..
Version__ARMCC_VERSIONVRPBBBV = Version
R = Revision
P = Patch
BBB = Build

Please note that the __ARMCC_VERSION macro is also used as version indicator for Norcroft C, but that the format is different.

Example

Realview C__ARMCC_VERSION
3.0300503

Official site

SAS/C

TypeMacroFormatDescription
IdentificationSASC..
Identification__SASC..
Identification__SASC__..
Version__VERSION__.Until ?
Version__REVISION__.Until ?
Version__SASC__VRRV = Version
RR = Revision

From ?
Example

SAS/C__SASC____VERSION____REVISION__
5.10.510
6.50650..

Official site

SCO OpenServer

TypeMacro
Identification_SCO_DS

Official site

Small Device C Compiler

TypeMacroFormatDescription
IdentificationSDCC..
VersionSDCCVRPV = Version
R = Revision
P = Patch
Example

SDCC VersionSDCC Macro
2.5.6256

Official siteGoogle DirectoryWikipedia

Sun Studio

TypeMacroFormatDescription
Identification__SUNPRO_C.C compiler
Version__SUNPRO_C0xVRPV = Version
R = Revision
P = Patch
Identification__SUNPRO_CC.C++ compiler
Version__SUNPRO_CCAs __SUNPRO_C.
Example

Sun Studio__SUNPRO_C
4.20x420
5.00x500

Official site

Systems/C and Systems/C++

TypeMacroFormatDescription
Identification__SYSC__.C compiler
Version__SYSC_VER__VRRPPV = Version
RR = Revision
PP = Patch
Example

Systems/C__SYSC_VER__
1.80.3218032

Official site

TenDRA C/C++

TypeMacro
Identification__TenDRA__

Official siteWikipedia

Tiny C

TypeMacro
Identification__TINYC__

Official site

Ultimate C/C++

TypeMacroDescription
Identification_UCC.
Version_MAJOR_REV = V
_MINOR_REV = R
V = Version
R = Revision
Example

Ultimate C/C++_MAJOR_REV_MINOR_REV
2.121

USL C

TypeMacroFormatDescription
Identification__USLC__..
Version__SCO_VERSION0xVRRYYYYMMV = Version
RR = Revision
YYYY = Year
MM = Month
Example

USL C__SCO_VERSION
3.2302199801

Official site

Watcom C++

TypeMacroFormatDescription
Identification__WATCOMC__..
Version__WATCOMC__VVRRVV = Version
RR = Revision
Example

Watcom C++__WATCOMC__
10.51050
11.01100

Official siteWikipedia
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值