C/C++预定义编译宏

36 篇文章 0 订阅
26 篇文章 0 订阅

 

Pre-defined C/C++ Compiler Macros

https://sourceforge.net/p/predef/wiki/Home/

The macros are found here:

General guidelines are found here:

Introduction

C and C++ compilers automatically define certain macros that can be used to check for compiler or operating system features. This is useful when writing portable software.

These pages lists various pre-defined compiler macros that can be used to identify standards, compilers, operating systems, hardware architectures, and even basic run-time libraries at compile-time.

For example, if we want to use a generic or opaque pointer type, we use void pointers. However, ancient K&R compilers (from the time before the first ANSI C standard) do not support void pointers. Instead we can define our own type:

#if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_EXTENSIONS)

typedef void * t_pointer;

#else

typedef char * t_pointer;

#endif

Another example, Microsoft Visual C++ version 4.2 added a pragma to reduce compilation times by only including a file once (if _MSC_VER is not defined then it will evaluate to 0 (zero) — however, some compilers may complain about an undefined macro)

#if defined(_MSC_VER) && (_MSC_VER >= 1020)

#pragma once

#endif

The macros contained in these pages have been obtained through vendor documentation, the defines script, contributors, and third-party source code. No guarantee about the correctness of the macros is given.

An often-used alternative is Autoconf, which is a more powerful tool to examine various types of features, including compilation options. However, Autoconf is fairly Unix-centric, and requires a Unix layer on other platforms (e.g. Cygwin on Windows). Other alternatives are BuildtoolCMakeSConsPMKJamAnt, and Bakefile.

Contributors

Bjorn Reese, Daniel Stenberg, Greg Roelofs, Steven G. Johnson, Wlodzimierz ABX Skiba, Marc Finet, Philip Newton, Mitchell Charity, Christian Klutz, Seo Sanghyeon, Chris Adami, Geoff Clare, Dan Fandrich, Mike Gorchak, Yuri D'Elia, Gynvael Coldwind, Alain Tauch, Vadim Zeitlin, Steve White, Thomas David Rivers, Tom Honermann, Martin Mitas, Dinesh Chhadwa, Erik Faye-Lund, Leo Davis, Paul Hsieh, Roland Schwarz, Darko Kolakovic, Andy Buonviri, Ming Kin Lai, Kent Johnson, Helmut Bauer, Oliver Schneider, Ron Pimblett, Jose Luis Rodriguez Garcia, Jeroen Ruigrok van der Werven, Uffe Jakobsen, Bryan Ashby, Bruno Haible, Artur Bac, Terry Schwarz, Leo Davis, Markus Duft, William Dang, Paul Green, Ruben Van Boxem, Pau Garcia i Quiles, Mikulas Patocka, Leo Davis, Mark Ferry, Holger Machens, Simon Watts, Paul Hargrove, Hans-Christoph Steiner, Gerald Combs, Denys Bulant, Massimo Morara, Jeremy Bennett, Guillem Jover, Riku Voipio, Jacques Pelletier, Mark Jarvin, Georg Sauthoff, Scot Jenkins, Grzegorz Brzęczyszczykiewicz, John Dallman, Gianmichele Toglia, Robbie Groenewoudt, Andreas Mohr, Алексей Пюрецкий, Sverre Hvammen Johansen, Stefan Tauner, Daniel Garcia, Ozkan Sezer, Dean Saridakis, Frank Long, Kevin Adler.

Top

Language Standards

Language standards requires the existence of pre-defined macros.

Name

Macro

Standard

C89

__STDC__

ANSI X3.159-1989

C90

__STDC__

ISO/IEC 9899:1990

C94

__STDC_VERSION__ = 199409L

ISO/IEC 9899-1:1994

C99

__STDC_VERSION__ = 199901L

ISO/IEC 9899:1999

C11

__STDC_VERSION__ = 201112L

ISO/IEC 9899:2011

C++98

__cplusplus = 199711L

ISO/IEC 14882:1998

C++11

__cplusplus = 201103L

ISO/IEC 14882:2011

C++14

__cplusplus = 201402L

ISO/IEC 14882:2014

C++/CLI

__cplusplus_cli = 200406L

ECMA-372

DSP-C

 

ISO/IEC JTC1/SC22 WG14/N854

EC++

__embedded_cplusplus

Embedded C++

Example: C Standards

#if defined(__STDC__)
# define PREDEF_STANDARD_C_1989
# if defined(__STDC_VERSION__)
#  if (__STDC_VERSION__ >= 199409L)
#   define PREDEF_STANDARD_C_1994
#  endif
#  if (__STDC_VERSION__ >= 199901L)
#   define PREDEF_STANDARD_C_1999
#  endif
# endif
#endif

Notice that not all compliant compilers provides the correct pre-defined macros. For example, Microsoft Visual C++ does not define __STDC__, or Sun Workshop 4.2 supports C94 without setting __STDC_VERSION__ to the proper value. Extra checks for such compilers must be added.

Notice that some compilers, such as the HP aC++, use the value 199707L to indicate the C++98 standard. This value was used in an earlier proposal of the C++98 standard.

Example: Pre-C89

In continuation of the above example, pre-C89 compilers do not recognize certain keywords. Let the preprocessor remove those keywords for those compilers.

#if !defined(PREDEF_STANDARD_C_1989) && !defined(__cplusplus)
# define const
# define volatile
#endif

Unix Standards

There are several related Unix standards, such as POSIXX/Open, and LSB.

Unix standards require the existence macros in the <unistd.h> header file.

Name

Macro

Standard

POSIX.1-1988

_POSIX_VERSION = 198808L

 

POSIX.1-1990

_POSIX_VERSION = 199009L

ISO/IEC 9945-1:1990

POSIX.2

_POSIX2_C_VERSION = 199209L

ISO/IEC 9945-2:1993

POSIX.1b-1993

_POSIX_VERSION = 199309L

IEEE 1003.1b-1993

POSIX.1-1996

_POSIX_VERSION = 199506L

IEEE 1003.1-1996

POSIX.1-2001

_POSIX_VERSION = 200112L

IEEE 1003.1-2001

POSIX.1-2008

_POSIX_VERSION = 200809L

IEEE 1003.1-2008

XPG3

_XOPEN_VERSION = 3

X/Open Portability Guide 3 (1989)

XPG4

_XOPEN_VERSION = 4

X/Open Portability Guide 4 (1992)

SUS

_XOPEN_VERSION = 4 && _XOPEN_UNIX

X/Open Single UNIX Specification (UNIX95)

SUSv2

_XOPEN_VERSION = 500

X/Open Single UNIX Specification, Version 2 (UNIX98)

SUSv3

_XOPEN_VERSION = 600

Open Group Single UNIX Specification, Version 3 (UNIX03)

SUSv4

_XOPEN_VERSION = 700

Open Group Single UNIX Specification, Version 4

LSB

__LSB_VERSION__ = VR

Linux Standards Base

V = Version
R = Revision

Example: Unix Standards

The following examples assumes the definition of these macros.

#if defined(unix) || defined(__unix__) || defined(__unix)
# define PREDEF_PLATFORM_UNIX
#endif
#if defined(PREDEF_PLATFORM_UNIX)
# include <unistd.h>
# if defined(_XOPEN_VERSION)
#  if (_XOPEN_VERSION >= 3)
#   define PREDEF_STANDARD_XOPEN_1989
#  endif
#  if (_XOPEN_VERSION >= 4)
#   define PREDEF_STANDARD_XOPEN_1992
#  endif
#  if (_XOPEN_VERSION >= 4) && defined(_XOPEN_UNIX)
#   define PREDEF_STANDARD_XOPEN_1995
#  endif
#  if (_XOPEN_VERSION >= 500)
#   define PREDEF_STANDARD_XOPEN_1998
#  endif
#  if (_XOPEN_VERSION >= 600)
#   define PREDEF_STANDARD_XOPEN_2003
#  endif
#  if (_XOPEN_VERSION >= 700)
#   define PREDEF_STANDARD_XOPEN_2008
#  endif
# endif
#endif

Notice that not all compliant compilers provides the correct pre-defined macros. For example, IBM xlC supports Unix without setting any of the __unix__ macros. Extra checks for such compilers must be added.

Top

Compilers  

ACC

Type

Macro

Identification

_ACC_

Altium MicroBlaze C

Type

Macro

Format

Description

Identification

__CMB__

  

Version

__VERSION__

VRRR

V=Version
RRR=Revision

Version

__REVISION__

P

P=Patch

Version

__BUILD__

VRRRPPP

Build number

Example

Altium MicroBlaze C

__VERSION__

__REVISION__

__BUILD__

1.0r2

1000

2

 

1.22.2

  

1022001

Altium C-to-Hardware

Type

Macro

Format

Description

Identification

__CHC__

  

Version

__VERSION__

VRRR

V=Version
RRR=Revision

Version

__REVISION__

P

P=Patch
Beta releases set this to -1

Version

__BUILD__

VRRRPPP

Build number

Example

Altium C-to-Hardware

__VERSION__

__REVISION__

__BUILD__

2.1r1

2001

1

 

1.22.2

  

1022001

Amsterdam Compiler Kit

Type

Macro

Identification

__ACK__

ARM Compiler

Type

Macro

Format

Description

Identification

__CC_ARM

  

Version

__ARMCC_VERSION

VRPBBB

V = Version
R = Revision
P = Patch
BBB = Build

Notice 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.0

300503

Aztec C

Type

Macro

Format

Description

Identification

AZTEC_C
__AZTEC_C__

  

Version

__VERSION

VRR

V = Version
RR = Revision

Example

Aztec C

__VERSION

5.20

520

Borland C++

Type

Macro

Format

Identification

__BORLANDC__

 

Version

__BORLANDC__

?

Identification

__CODEGEARC__

 

Version

__CODEGEARC__

From C++ Builder 2006

Example

Borland C++

C++ Builder

__BORLANDC__

__CODEGEARC__

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

 

5.6.4

 

0x562

 
 

2006

0x570

0x570

 

2007

0x590

0x590

 

2009

0x613

0x613

 

2010

0x621

0x621

 

XE

0x630

0x630

 

XE2

0x640

0x640

 

XE3

0x650

0x650

 

XE4

0x660

0x660

CC65

Type

Macro

Format

Description

Identification

__CC65__

  

Version

__CC65__

0xVRP

V = Version
R = Revision
P = Patch

Example

Version

__CC65__

2.10.1

0x2A1

Clang

Type

Macro

Format

Identification

__clang__

 

Version

__clang_major__

Version

Version

__clang_minor__

Revision

Version

__clang_patchlevel__

Patch

Notice that clang also defines the GNU C version macros, but you should use the clang feature checking macros to detect the availability of various features.

The values of the __clang_major____clang_minor__, and __clang_patchlevel__ macros are not consistent across distributions of the Clang compiler. For example, the Clang 3.1 distribution available at http://clang.llvm.org defines __clang_major__ and __clang_minor__ as 3 and 1 respectively. The version of Clang distributed with Apple XCode 4.4 is branded as "Apple Clang 4.0" and derives from the open source Clang 3.1 distribution, but defines these macros with the values 4 and 0 respectively. Apple's Clang distribution can be identified by the presence of the __apple_build_version__macro.

Comeau C++

Type

Macro

Format

Description

Identification

__COMO__

  

Version

__COMO_VERSION__

VRR

V = Version
RR = Revision

Example

Comeau C++

__COMO_VERSION__

2.3

230

Compaq C/C++

Type

Macro

Format

Description

Identification

__DECC

 

C compiler

Version

__DECC_VER

VVRRTPPPP

VV = Version
RR = Revision
T = Type (9 = official)
PPPP = Patch

Identification

__DECCXX

 

C++ compiler

Version

__DECCXX_VER

As __DECC_VER

 

Identification

__VAXC

 

Obsolete

Identification

VAXC

 

Obsolete

Example

Compaq C/C++

__DECC_VER

6.0-001

60090001

Convex C

Type

Macro

Identification

__convexc__

CompCert

Type

Macro

Identification

__COMPCERT__

Coverity C/C++ Static Analyzer

Type

Macro

Identification

__COVERITY__

Cray C

Type

Macro

Description

Identification

_CRAYC

 

Version

_RELEASE

Version

Version

_RELEASE_MINOR

Revision

Diab C/C++

Type

Macro

Format

Description

Identification

__DCC__

1

 

Version

__VERSION_NUMBER__

VRPP

V = Version
R = Revision
PP = Patch

Example

Diab C/C++

__VERSION_NUMBER__

4.4g

4426

DICE C

Type

Macro

Identification

_DICE

Digital Mars

Type

Macro

Format

Description

Identification

__DMC__

  

Version

__DMC__

0xVRP

V = Version
R = Revision
P = Patch

Example

Digital Mars

__DMC__

7.0

0x700

7.2

0x720

8.0

0x800

Dignus Systems/C++

Type

Macro

Format

Description

Identification

__SYSC__

  

Version

__SYSC_VER__

VRRPP

V = Version
RR = Revision
PP = Patch

Example

Systems/C

__SYSC_VER__

1.80.32

18032

DJGPP

Type

Macro

Description

Identification

__DJGPP__

 

Version

__DJGPP__

Version

Version

__DJGPP_MINOR__

Revision

Identification

__GO32__

Defined by DJGPP 1.x

Example

DJGPP

__DJGPP__

__DJGPP_MINOR__

2.01

2

1

EDG C++ Frontend

Type

Macro

Format

Description

Identification

__EDG__

  

Version

__EDG_VERSION__

VRR

V = Version
RR = Revision

Example

EDG C++

__EDG_VERSION__

2.30

230

2.45

245

EKOPath

Type

Macro

Description

Identification

__PATHCC__

 

Version

__PATHCC__

Version

Version

__PATHCC_MINOR__

Revision

Version

__PATHCC_PATCHLEVEL__

Patch

Example

EKOPath

__PATHCC__

__PATHCC_MINOR__

__PATHCC_PATCHLEVEL__

2.0

2

0

0

Fujitsu C++

Type

Macro

Identification

__FCC_VERSION

GCC C/C++

Type

Macro

Description

Identification

__GNUC__

 

Version

__GNUC__

Version

Version

__GNUC_MINOR__

Revision

Version

__GNUC_PATCHLEVEL__

Patch (introduced in version 3.0)

Notice that the meaning of the __GNUC__ macro has changed subtly over the years, from identifying the GNU C/C++ compiler to identifying any compiler that implements the GNU compiler extensions (see the Feature request - a macro defined for GCC discussion for further information). For example, the Intel C++ on Linux also defines these macros from version 8.1 (see the Intel C++ Compiler 8.1 for Linux Release Notes and Intel Compilers for Linux: Compatibility with GNU Compilers.)

Example

GNU C/C++

__GNUC__

__GNUC_MINOR__

__GNUC_PATCHLEVEL__

2.7.x

2

7

N/A

3.0.2

3

0

2

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:

Type

Macro

Format

Description

Version

__GNUC_VERSION__

VVRRPP

VV = Version
RR = Revision
PP = Patch

Example of Alternative Version

GNU C/C++

__GNUC_VERSION__

2.7.x

20700

3.0.2

30002

Green Hill C/C++

Type

Macro

Format

Description

Identification

__ghs__

  

Version

__GHS_VERSION_NUMBER__

VRP

V = Version
R = Revision
P = Patch

Version

__GHS_REVISION_DATE__

Epoch time

 

Example

Green Hill C/C++

__GHS_VERSION_NUMBER__

4.2.1

421

HP ANSI C

Type

Macro

Identification

__HP_cc

HP aC++

Type

Macro

Format

Description

Identification

__HP_aCC

  

Version

__HP_aCC

1

From version A.01.15 (and A.03.13)

Version

__HP_aCC

VVRRPP

VV = Version
RR = Revision
PP = Patch

From version A.01.21 (and A.03.25)

Example

HP aCC

__HP_aCC

A.01.21

12100

IAR C/C++

Type

Macro

Format

Description

Identification

__IAR_SYSTEMS_ICC__

  

Version

__VER__

VRR

V = Version
RR = Revision

Example

IAR C/C++

__VER__

3.34

334

IBM XL C/C++

Type

Macro

Format

Description

Identification

__xlc__

  

Identification

__xlC__

  

Version

__xlC__

0xVVRR

VV = Version
RR = Revision

Version

__xlC_ver__

0x0000PPBB

PP = Patch
BB = Build

Identification

__IBMC__

 

From ?

Identification

__IBMCPP__

 

From ?

Version

__IBMC__
__IBMCPP__

VRP

V = Version
R = Revision
P = Patch

Notice 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__

__xlC_ver__

3.1

0x0301

 

4.5

0x0405

 

5.0

0x0500

 

12.01.0000.0004

0x0C01

0x00000004

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.

Type

Macro

Format

Description

Identification

__IBMC__

  

Identification

__IBMCPP__

  

Version

__IBMC__
__IBMCPP__

NVRRM

N = 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__

0xNVRRPPPP

N = Product (see above)
V = Version
RR = Revision
PPPP = Patch

Defined for z/OS XL C/C++

Notice 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. Alternatively, the macro identifying z/OS (__MVS__) can be used to distinguish between them.

#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.7

41070

0x41070000

1.13

41130

0x410D0000

ImageCraft C

Type

Macro

Identification

__IMAGECRAFT__

Intel C/C++

Type

Macro

Format

Description

Identification

__INTEL_COMPILER

  

Identification

__ICC

 

Obsolete

Identification

__ECC

 

Obsolete

Identification

__ICL

  

Version

__INTEL_COMPILER

VRP

V = Version
R = Revision
P = Patch

Version

__INTEL_COMPILER_BUILD_DATE

YYYYMMDD

YYYY = Year
MM = Month
DD = Day

Example

Intel C/C++

__INTEL_COMPILER

__INTEL_COMPILER_BUILD_DATE

5.0

500

 

6.0

600

 

8.0

800

 

9.0

900

20060222

KAI C++

Type

Macro

Format

Description

Identification

__KCC

  

Version

__KCC_VERSION

0xVRPP

V = Version
R = Revision
PP = Patch (a = 01, b = 02, ...)

Example

KAI C++

__KCC_VERSION

4.0d

4004

KEIL CARM

Type

Macro

Format

Description

Identification

__CA__

  

Identification

__KEIL__

  

Version

__CA__

VRR

V = Version
RR = Revision

Example

Keil CARM

__CA__

1.01

101

KEIL C166

Type

Macro

Format

Description

Identification

__C166__

  

Version

__C166__

VRR

V = Version
RR = Revision

Example

Keil C166

__C166__

5.01

501

KEIL C51

Type

Macro

Format

Description

Identification

__C51__

  

Identification

__CX51__

  

Version

__C51__

VRR

V = Version
RR = Revision

Example

Keil C51

__C51__

7.01

701

LCC

Type

Macro

Identification

__LCC__

LLVM

Type

Macro

Identification

__llvm__

MetaWare High C/C++

Type

Macro

Identification

__HIGHC__

Metrowerks CodeWarrior

Type

Macro

Format

Description

Identification

__MWERKS__

  

Identification

__CWCC__

 

From 4.2.0

Version

__MWERKS__

1

Until CodeWarrior 7

Version

__MWERKS__

0xVRPP

V = Version
R = Revision
PP = Patch

From CodeWarrior 7

Version

__CWCC__

0xVRPP

V = Version
R = Revision
PP = Patch

From 4.2.0

Example

Metrowerks C/C++

__MWERKS__

__CWCC__

2.0

0x2000

 

2.2

0x2200

 

4.2.0

0x4200

0x4200

Microsoft Visual C++

Type

Macro

Format

Description

Identification

_MSC_VER

  

Version

_MSC_VER

VVRR

VV = Version
RR = Revision

Version

_MSC_FULL_VER

VVRRPPPP

VV = Version
RR = Revision
PPPP = Patch

From Visual C++ 6.0 Processor Pack

Version

_MSC_FULL_VER

VVRRPPPPP

VV = Version
RR = Revision
PPPPP = Patch

From Visual C++ 8.0

Version

_MSC_BUILD

B

B = Build number

From Visual C++ 9.0

Example

Visual C++ 1 2

_MSC_VER

_MSC_FULL_VER

1.0

800

 

3.0

900

 

4.0

1000

 

4.2

1020

 

5.0

1100

 

6.0

1200

 

6.0 SP6

1200

12008804

7.0

1300

13009466

7.1 (2003)

1310

13103077

8.0 (2005)

1400

140050727

9.0 (2008)

1500

150021022

9.0 SP1

1500

150030729

10.0 (2010)

1600

160030319

10.0 (2010) SP1

1600

160040219

11.0 (2012)

1700

170050727

12.0 (2013)

1800

180021005

14.0 (2015)

1900

190023026

14.0 (2015 Update 1)

1900

190023506

14.0 (2015 Update 2)

1900

190023918

14.0 (2015 Update 3)

1900

190024210

15.0 (2017)

1910

191025017

Microtec C/C++

Type

Macro

Identification

_MRI

Microway NDP C

Type

Macro

Identification

__NDPC__
__NDPX__

MinGW and MinGW-w64

MinGW (formerly known as MinGW32) is a toolchain for creating 32 Bit Windows executables. The MinGW-w64 projects offers toolchains for creating 32 Bit and 64 Bit Windows executables. The following table shows which macros are defined by each toolchain:

Type

Macro

Description

MinGW32

MinGW-w64 32 Bit

MinGW-w64 64 Bit

Identification

__MINGW32__

 

defined

defined

defined

Version

__MINGW32_MAJOR_VERSION

Version

defined

defined

defined

Version

__MINGW32_MINOR_VERSION

Revision

defined

defined

defined

Identification

__MINGW64__

 

-

-

defined

Version

__MINGW64_VERSION_MAJOR

Version

-

defined

defined

Version

__MINGW64_VERSION_MINOR

Revision

-

defined

defined

Notice that __MINGW32_MAJOR_VERSION__MINGW32_MINOR_VERSION__MINGW64_VERSION_MAJOR, and __MINGW64_VERSION_MINOR
are only defined if appropriate headers are included. Appropriate headers are 
<stdlib.h><stdio.h><windows.h><windef.h>, and probably more.

Examples

__MINGW32_MAJOR_VERSION

__MINGW32_MINOR_VERSION

__MINGW64_VERSION_MAJOR

__MINGW64_VERSION_MINOR

Description

2

4

  

MinGW32 2.4

3

20

  

MinGW32 3.20

3

11

2

0

MinGW-w64 2.0

MIPSpro

Type

Macro

Format

Description

Identification

__sgi

  

Identification

sgi

  

Version

_COMPILER_VERSION

VRP

V = Version
R = Revision
P = Patch

Until ?

Version

_SGI_COMPILER_VERSION

VRP

V = Version
R = Revision
P = Patch

From ?

Example

MIPSpro

_COMPILER_VERSION

_SGI_COMPILER_VERSION

6.0.2

602

 

7.2.1

721

 

7.4.4

 

744

Miracle C

Type

Macro

Identification

MIRACLE

MPW C++

Type

Macro

Format

Description

Identification

__MRC__

  

Identification

MPW_C

  

Identification

MPW_CPLUS

  

Version

__MRC__

0xVVRR

VV = Version
RR = Revision

Example

MPW C++

__MRC__

5.0

0x500

Norcroft C

Type

Macro

Format

Description

Identification

__CC_NORCROFT

  

Version

__ARMCC_VERSION

V.R

V = Version
R = Revision

Notice 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.69

4.69

4.90

4.90

NWCC

Type

Macro

Identification

__NWCC__

Open64

Type

Macro

Format

Description

Identification

__OPEN64__

 

Contains the full version as a string

Identification

__OPENCC__

  

Version

__OPENCC__

V

V = Version

Version

__OPENCC_MINOR__

R

R = Revision

Version

__OPENCC_PATCHLEVEL__

P.B

P = Patch
B = Build

Notice that __OPENCC_PATCHLEVEL__ can be a floating-point number (e.g. 5.2 for Open64 version 4.2.5.2) so it cannot be used by the preprocessor to compare patch-levels.

Oracle Pro*C Precompiler

Type

Macro

Identification

ORA_PROC

Oracle Solaris Studio

Type

Macro

Format

Description

Identification

__SUNPRO_C

 

C compiler

Version

__SUNPRO_C

0xVRP

V = Version
R = Revision
P = Patch

Until version 5.9

Version

__SUNPRO_C

0xVRRP

V = Version
RR = Revision
P = Patch

From later releases

Identification

__SUNPRO_CC

 

C++ compiler

Version

__SUNPRO_CC

As __SUNPRO_C

 

Example

Compiler version

Solaris Studio

__SUNPRO_C

4.2

4.2

0x420

5.0

5.0

0x500

5.2

6.1

0x520

5.3

6.2

0x530

5.4

7

0x540

5.5

8

0x550

5.6

9

0x560

5.7

10

0x570

5.8

11

0x580

5.9

12

0x590

5.10

12.1

0x5100

5.11

12.2

0x5110

5.12

12.3

0x5120

The name of Oracle Solaris Studio has changed over the years (e.g. Sun Studio, Sun Workshop, Forte Developer) but we do not make this distinction in the table above.

Pacific C

Type

Macro

Identification

__PACIFIC__

Palm C/C++

Type

Macro

Format

Description

Identification

_PACC_VER

  

Version

_PACC_VER

0xVRRPPBBB

V = Version
RR = Revision
PP = Patch
BBB = Build

Example

Palm C/C++

_PACC_VER

1.0.0.13

0x1000000D

Pelles C

Type

Macro

Format

Description

Identification

__POCC__

  

Version

__POCC__

VRR

V = Version
RR = Revision

Example

Pelles C

__POCC__

3.00

300

Portland Group C/C++

Type

Macro

Description

Identification

__PGI

 

Version

__PGIC__

Version

Version

__PGIC_MINOR__

Revision

Version

__PGIC_PATCHLEVEL__

Patch

Example

PGI C/C++

__PGIC__

__PGIC_MINOR__

__PGIC_PATCHLEVEL__

7.0.1

7

0

1

11.9

11

9

0

Renesas C/C++

Type

Macro

Format

Description

Identification

__RENESAS__

  

Identification

__HITACHI__

  

Version

__RENESAS_VERSION__

0xVVRR

V = Version
R = Revision
P = Patch

Version

__RENESAS_VERSION__

0xVVRRPP00

From ?

Version

__HITACHI_VERSION__

0xVVRR

As above

Example

Renesas C/C++

__HITACHI_VERSION__

__RENESAS_VERSION__

5.1C

0x0501

 

8.0

0x8000

0x8000

1.00.00

 

0x01000000

SAS/C

Type

Macro

Format

Description

Identification

SASC

  

Identification

__SASC

  

Identification

__SASC__

  

Version

__VERSION__

 

Until ?

Version

__REVISION__

 

Until ?

Version

__SASC__

VRR

V = Version
RR = Revision

From ?

Example

SAS/C

__SASC__

__VERSION__

__REVISION__

5.10

 

5

10

6.50

650

  

SCO OpenServer

Type

Macro

Identification

_SCO_DS

Small Device C Compiler

Type

Macro

Format

Description

Identification

SDCC

  

Version

SDCC

VRP

V = Version
R = Revision
P = Patch

Example

SDCC Version

SDCC Macro

2.5.6

256

SN Compiler

Type

Macro

Identification

__SNC__

Stratus VOS C

Type

Macro

Description

Identification

__VOSC__

 

Version

__VOSC__

0 = K&R compiler
1 = ANSI C compiler

Symantec C++

Type

Macro

Format

Description

Identification

__SC__

  

Version

__SC__

0xVVRR

VV = Version
RR = Revision

TenDRA C/C++

Type

Macro

Identification

__TenDRA__

Texas Instruments C/C++ Compiler

Type

Macro

Format

Description

Identification

__TI_COMPILER_VERSION__

  

Identification

_TMS320C6X

 

All C6000 compilers

Version

__TI_COMPILER_VERSION__

VVVRRRPPP

VVV = Version
RRR = Revision
PPP = Patch

Example

TI C/C++

__TI_COMPILER_VERSION__

4.9.1

4009001

7.3.1

7003001

THINK C

Type

Macro

Description

Version

THINKC3

Version 3.x

Version

THINKC4

Version 4.x

Tiny C

Type

Macro

Identification

__TINYC__

Turbo C/C++

Type

Macro

Format

Description

Identification

__TURBOC__

  

Version

__TURBOC__

0xVVRR

VV = Version
RR = Revision

This pattern does not apply to the values between 0x295 and 0x400.

Example

Turbo C

Turbo C++

__TURBOC__

2.01

 

0x201

 

1.00

0x295

 

1.01

0x296

 

2.00

0x297

Ultimate C/C++

Type

Macro

Description

Identification

_UCC

 

Version

_MAJOR_REV = V
_MINOR_REV = R

V = Version
R = Revision

Example

Ultimate C/C++

_MAJOR_REV

_MINOR_REV

2.1

2

1

USL C

Type

Macro

Format

Description

Identification

__USLC__

  

Version

__SCO_VERSION__

VRRYYYYMM

V = Version
RR = Revision
YYYY = Year
MM = Month

Example

USL C

__SCO_VERSION__

Description

3.2

302199801

 

3.4

304200805

UnixWare 7.1.4 UDK C++ (CC)

4.2

402200805

UnixWare 7.1.4 UDK C (cc)

VBCC

Type

Macro

Identification

__VBCC__

Watcom C++

Type

Macro

Format

Description

Identification

__WATCOMC__

  

Version

__WATCOMC__

VVRR

VV = Version
RR = Revision

Notice that Watcom C++ became Open Watcom C++ after version 11.0, and the official version numbering (but not the version macro) was restated at version 1.0.

Example

Watcom C++

Open Watcom C++

__WATCOMC__

10.5

 

1050

11.0

 

1100

 

1.0

1200

 

1.7

1270

Zortech C++

Type

Macro

Format

Description

Identification

__ZTC__

  

Version

__ZTC__

0xVRP

V = Version
R = Revision
P = Patch


Top

Standard C Libraries

Bionic libc

The following macro is defined in the <sys/cdefs.h> header file. It may be best to include it via the <sys/types.h> header file, which is required by POSIX.

Type

Macro

Idenfication

__BIONIC__

GNU glibc

The following macros have to be included from the <features.h> header file.

Type

Macro

Description

Version

__GNU_LIBRARY__
__GNU_LIBRARY_MINOR__

Until version 5

Version

__GLIBC__
__GLIBC_MINOR__

From version 6

Notice that the <features.h> header file does not exist on all platforms, so it cannot be included without further ado. However, since it is included by other GNU glibc header files, a better way to obtain the above-mentioned macros is to include the <limits.h> header file (see e.g. paragraph 4/6 in ISO/IEC 9899:1999).

klibc

Type

Macro

Format

Description

Identification

__KLIBC__

 

Zero is a valid value

Version

__KLIBC__

 

Version

Version

__KLIBC_MINOR__

 

Revision

Version

__KLIBC_PATCHLEVEL__

 

Patch

Version

__KLIBC_VERSION__

0xVVRRPPPP

VV = Version
RR = Revision
PPPP = Patch

uClibc

The following macros have to be included from the <features.h> header file.

Type

Macro

Description

Identification

__UCLIBC__

 

Version

__UCLIBC_MAJOR__

Version

Version

__UCLIBC_MINOR__

Revision

Version

__UCLIBC_SUBLEVEL__

Patch

VMS libc

Type

Macro

Format

Description

Identification

__CRTL_VER

  

Version

__CRTL_VER

VVRREPPTT

VV = Version
RR = Revision
E = Edit number
PP = Patch (01 = A, ... 26 = Z)
TT = Type (22 = official)

Notice that I am not sure about the format of __CRTL_VER, but it seems to follow that of __VMS_VER.

z/OS libc

Type

Macro

Format

Description

Identification

__LIBREL__

 

Host

Identification

__TARGET_LIB__

 

Target

Version

__LIBREL__

0xNVRRPPPP

N = Product (0 = C/370, 1 = MVS, 2 = OS/390, 4 = z/OS)
V = Version
RR = Revision
PPPP = Patch

Defined for z/OS XL C/C++

Version

__TARGET_LIB__

As above

 

Example

Library

__LIBREL__

OS/390 2.10

0x220A0000

z/OS 1.1

0x41010000

z/OS 1.6

0x41060000

Standard C++ Libraries

Dinkumware

Type

Macro

Format

Description

Identification

_CPPLIB_VER

 

Defined for Dinkumware 2.0 and later

Version

_CPPLIB_VER

VVRR

VV = Version
RR = Revision

Example

Dinkumware

Visual C++

_CPPLIB_VER

3.06

 

306

3.08

 

308

4.05

2005

405

5.03

2008

503

5.05

2008 SP1

505

5.20

2010

520

5.40

2012

540

6.10

2013

610

GNU libstdc++

One of the standard header files must be included before any of the following macros are defined.

Type

Macro

Format

Description

Version

__GLIBCPP__

YYYYMMDD

YYYY = Year
MM = Month
DD = Day

From GCC 3.0.0 until GCC 3.4.0

Version

__GLIBCXX__

YYYYMMDD

YYYY = Year
MM = Month
DD = Day

From GCC 3.4.0

Example

GCC

__GLIBCPP__

__GLIBCXX__

3.0.0

20010615

 

3.1.0

20020514

 

3.2.0

20020814

 

3.3.0

20030513

 

3.4.0

 

20040419

Intel C++ Run-Time Libraries

Type

Macro

Identification

__INTEL_CXXLIB_ICC

libc++

One of the standard header files must be included before any of the following macros are defined.

Type

Macro

Format

Description

Version

_LIBCPP_VERSION

VRRR

V = Version
RRR = Revision

Version

_LIBCPP_ABI_VERSION

V

V = ABI Version

Other Libraries

Microsoft Foundation Classes

Type

Macro

Format

Description

Identification

_MFC_VER

  

Version

_MFC_VER

0xVVRR

VV = Version
RR = Revision

Example

MFC

_MFC_VER

4.21

0x0421

6.0

0x0600

7.0

0x0700

 

Top

OperatingSystems 

AIX

Type

Macro

Description

Identification

_AIX

 

Version

_AIX'VR'

V = Version
R = Revision

Identification

__TOS_AIX__

Defined by xlC

Example

If _AIX is defined, then the following macros can be used to determine the version. Notice that the macros indicates the mentioned version or higher. For example, if _AIX43 is defined, then _AIX41 will also be defined.

AIX Version

Macro

3.2.x

_AIX3
_AIX32

4.1

_AIX41

4.3

_AIX43

Android

Type

Macro

Format

Description

Identification

__ANDROID__

  

Version

__ANDROID_API__

V

V = API Version

Must be included from <android/api-level.h>

Notice that Android is based on Linux, and that the Linux macros also are defined for Android.

Example

Android Version

__ANDROID_API__

1.0

1

1.1

2

1.5

3

1.6

4

2.0

5

2.0.1

6

2.1

7

2.2

8

2.3

9

2.3.3

10

3.0

11

Amdahl UTS

Type

Macro

Identification

UTS

AmigaOS

Type

Macro

Description

Identification

AMIGA

 

Identification

__amigaos__

Defined by GNU C

Apollo AEGIS

Type

Macro

Identification

aegis

Apollo Domain/OS

Type

Macro

Identification

apollo

Bada

Based on Nucleus OS.

BeOS

Type

Macro

Identification

__BEOS__

Blue Gene

Type

Macro

Description

Identification

__bg__

All Blue Gene systems

Defined by XL C/C++ and GNU C

Version

__bgq__

Blue Gene/Q

Defined for XL C/C++ and GNU C

Identification

__THW_BLUEGENE__

All Blue Gene systems

Defined by XL C/C++

Version

__TOS_BGQ__

Blue Gene/Q

Defined by XL C/C++

BSD Environment

Type

Macro

Format

Description

Identification

__FreeBSD__
__NetBSD__
__OpenBSD__
__bsdi__
__DragonFly__

  

Version

BSD

YYYYMM

YYYY = Year
MM = Month

Must be included from <sys/param.h>

Version

BSD4_2
BSD4_3
BSD4_4

 

Must be included from <sys/param.h>

Identification

_SYSTYPE_BSD

 

Defined by DEC C

Example

Version

BSD

Macro

4.3 Net2

199103

 

4.4

199306

BSD4_4

4.4BSD-Lite2

199506

 

BSD/OS

Type

Macro

Identification

__bsdi__

ConvexOS

Type

Macro

Identification

__convex__

Cygwin Environment

Type

Macro

Identification

__CYGWIN__

DG/UX

Type

Macro

Identification

DGUX

Identification

__DGUX__

Identification

__dgux__

DragonFly

Type

Macro

Identification

__DragonFly__

DYNIX/ptx

Type

Macro

Identification

_SEQUENT_

Identification

sequent

eCos

Type

Macro

Identification

__ECOS

EMX Environment

Type

Macro

Identification

__EMX__

FreeBSD

Type

Macro

Format

Description

Identification

__FreeBSD__

  

Identification

__FreeBSD_kernel__

 

From FreeBSD 8.3, 9.1, and 10.0.1

Version

BSD

  

Version

__FreeBSD__

V

V = Version

Version

__FreeBSD_version

?

Must be included from <osreldate.h>

Example

FreeBSD

__FreeBSD__

__FreeBSD_version

1.x

1

 

2.0-RELEASE

2

119411

2.2-RELEASE

2

220000

3.0-RELEASE

3

300005

4.0-RELEASE

4

400017

4.5-RELEASE

4

450000

For more information see the FreeBSD porters handbook.

GNU aka GNU/Hurd

The official name of this operating system is GNU. Hurd is the kernel in the GNU operating system. It is often listed as GNU/Hurd since there is also GNU/Linux and GNU/kFreeBSD, which are most of the GNU operating system with the Linux and FreeBSD kernels respectively.

Type

Macro

Identification

__GNU__ 1

Identification

__gnu_hurd__ 1

GNU/kFreeBSD

GNU/kFreeBSD is one of the Debian distros that is based on the FreeBSD kernel rather than the Linux or Hurd kernels.

Type

Macro

Identification

__FreeBSD_kernel__ && __GLIBC__

Notice that FreeBSD also defines __FreeBSD_kernel__ so the __GLIBC__ macro must be checked to distinguish it.

GNU/Linux

Type

Macro

Identification

__gnu_linux__

HI-UX MPP

Type

Macro

Identification

__hiuxmpp

HP-UX

Type

Macro

Description

Identification

_hpux

Defined by HP UPC

Identification

hpux

 

Identification

__hpux

 

IBM OS/400

Type

Macro

Format

Description

Identification

__OS400__

  

Version

__OS400_TGTVRM__

VRM

V = Version
R = Revision
M = Modification

INTEGRITY

Type

Macro

Identification

__INTEGRITY

Interix Environment

Type

Macro

Description

Identification

__INTERIX

Defined by GNU C and Visual Studio

IRIX

Type

Macro

Identification

sgi

Identification

__sgi

Linux kernel

Systems based on the Linux kernel define these macros. There are two major Linux-based operating systems: GNU/Linux and Android, and numerous others like Ångström or OpenEmbedded

Type

Macro

Description

Identification

__linux__

1

Identification

linux

Obsolete (not POSIX compliant)

Identification

__linux

Obsolete (not POSIX compliant)

LynxOS

Type

Macro

Identification

__Lynx__

MacOS

Type

Macro

Description

Identification

macintosh

Mac OS 9

Identification

Macintosh

Mac OS 9

Identification

__APPLE__ && __MACH__

Mac OS X

Defined by GNU C and Intel C++

Microware OS-9

Type

Macro

Description

Identification

__OS9000

Defined by Ultimate C/C++

Identification

_OSK

Defined by Ultimate C/C++

MINIX

Type

Macro

Identification

__minix

MorphOS

Type

Macro

Identification

__MORPHOS__

MPE/iX

Type

Macro

Identification

mpeix

Identification

__mpexl

MSDOS

Type

Macro

Identification

MSDOS

Identification

__MSDOS__

Identification

_MSDOS

Identification

__DOS__

NetBSD

Type

Macro

Format

Description

Identification

__NetBSD__

  

Version

BSD

  

Version

NetBSD'V'_'R'

 

V = Version
R = Revision

Must be included from <sys/param.h>

Version

__NetBSD_Version__

VVRRAAPP00

VV = Version
RR = Revision
AA = Release
PP = Patch

From NetBSD 1.2D (?) until NetBSD 2.0H

Must be included from <sys/param.h>

Version

__NetBSD_Version__

VVRR00PP00

VV = Version
RR = Revision
PP = Patch

From NetBSD 2.99.9

Must be included from <sys/param.h>

Example

NetBSD

__NetBSD_Version__

Macro

0.8

 

NetBSD0_8

0.9

 

NetBSD0_9

1.0

 

NetBSD1_0 = 1

1.0A

 

NetBSD1_0 = 2

1.2D

102040000

 

1.2.1

102000100

 

NonStop

Type

Macro

Identification

__TANDEM

Nucleus RTOS

Type

Macro

Identification

__nucleus__

OpenBSD

Type

Macro

Format

Description

Identification

__OpenBSD__

  

Version

BSD

  

Version

OpenBSD'V'_'R'

 

V = Version
R = Revision

Must be included from <sys/param.h>

Example

OpenBSD

Macro

3.1

OpenBSD3_1

3.9

OpenBSD3_9

OS/2

Type

Macro

Identification

OS2

Identification

_OS2

Identification

__OS2__

Identification

__TOS_OS2__

Palm OS

Type

Macro

Description

Identification

__palmos__

Defined by GNU C in PRC-Tools

Plan 9

Type

Macro

Identification

EPLAN9

Pyramid DC/OSx

Type

Macro

Identification

pyr

QNX

Type

Macro

Format

Description

Identification

__QNX__

 

QNX 4.x

Identification

__QNXNTO__

 

QNX 6.x

Version

_NTO_VERSION

VRR

V = Version
RR = Revision

Only available when __QNXNTO__ is defined.

Must be included from <sys/neutrino.h>

Version

BBNDK_VERSION_CURRENT

VVRRRRPPPP

V = Version
RRRR = Revision
PPPP = Patch

Only available on Blackberry 10

From Blackberry 10.1.0

Must be included from <bbndk.h>

Example

QNX

_NTO_VERSION

6.2

620

Reliant UNIX

Type

Macro

Identification

sinux

SCO OpenServer

Type

Macro

Description

Identification

M_I386

Defined by GNU C

Identification

M_XENIX

Defined by GNU C

Identification

_SCO_DS

 

Solaris

Type

Macro

Description

Identification

sun

 

Identification

__sun

 

Version

__'System'_'Version'

System = uname -s
Version = uname -r
Any illegal character is replaced by an underscore.

Defined by Sun Studio

Use the SVR4 macros to distinguish between Solaris and SunOS.

#if defined(sun) || defined(__sun)
# if defined(__SVR4) || defined(__svr4__)
/* Solaris */
# else
/* SunOS */
# endif
#endif

Example

Solaris

Macro

2.7

__SunOS_5_7

8

__SunOS_5_8

Stratus VOS

Type

Macro

Format

Description

Identification

__VOS__

  

Version

__VOS__

V

V = Version

Notice that the __VOS__ macro is defined by the compiler, but as several compilers can co-exist in the same OS release, the version number is not reliable.

SVR4 Environment

Type

Macro

Description

Identification

__sysv__

 

Identification

__SVR4

 

Identification

__svr4__

 

Identification

_SYSTYPE_SVR4

Defined on IRIX

Syllable

Type

Macro

Identification

__SYLLABLE__

Symbian OS

Type

Macro

Identification

__SYMBIAN32__

Tru64 (OSF/1)

Type

Macro

Identification

__osf__

Identification

__osf

Ultrix

Type

Macro

Identification

ultrix

Identification

__ultrix

Identification

__ultrix__

Identification

unix & vax

UNICOS

Type

Macro

Format

Description

Identification

_UNICOS

  

Version

_UNICOS

V

V = Version

UNICOS/mp

Type

Macro

Description

Identification

_CRAY
__crayx1

 

UNIX Environment

Type

Macro

Identification

__unix__

Identification

__unix

Notice that not all compilers defines these macros, e.g. the xlC or the DEC C/C++ compiler, so it may be better to use the POSIX or X/Open standard macros instead.

UnixWare

Type

Macro

Identification

sco

Identification

_UNIXWARE7

U/Win Environment

Type

Macro

Identification

_UWIN

VMS

Type

Macro

Format

Description

Identification

VMS

  

Identification

__VMS

  

Version

__VMS_VER

VVRREPPTT

VV = Version
RR = Revision
E = Edit number
PP = Patch (01 = A, ... 26 = Z)
TT = Type (22 = official)

Example

VMS

__VMS_VER

6.1

60100022

6.2

60200022

6.2-1I

60210922

VxWorks

Type

Macro

Description

 

Identification

__VXWORKS__

Defined by GNU C and Diab (from ?)

 

Identification

__vxworks

Defined by GNU C and Diab (from ?)

 

Version

_WRS_VXWORKS_MAJOR

Version

Must be included from <version.h>

 

Version

_WRS_VXWORKS_MINOR

Revision

Must be included from <version.h>

 

Version

_WRS_VXWORKS_MAINT

Patch/maintenance

Must be included from <version.h>

 

Mode

__RTP__

For real-time mode

 

Mode

_WRS_KERNEL

For kernel mode

 

Example

VxWorks

_WRS_VXWORKS_MAJOR

_WRS_VXWORKS_MINOR

_WRS_VXWORKS_MAINT

6.2

6

2

0

Windows

Type

Macro

Description

Identification

_WIN16

Defined for 16-bit environments 1

Identification

_WIN32

Defined for both 32-bit and 64-bit environments 1

Identification

_WIN64

Defined for 64-bit environments 1

Identification

__WIN32__

Defined by Borland C++

Identification

__TOS_WIN__

Defined by xlC

Identification

__WINDOWS__

Defined by Watcom C/C++

Windows CE

Type

Macro

Format

Description

Identification

_WIN32_WCE

 

Defined by Embedded Visual Studio C++

Version

_WIN32_WCE

VRR

V = Version
R = Revision

Identification

WIN32_PLATFORM_'P'

 

P = Platform

Version

WIN32_PLATFORM_'P'

V

P = Platform
V = Version

Example

Version

_WIN32_WCE

2.01

201

2.11

211

3.0

300

4.0

400

4.1

410

4.2

420

5.0

501

 

Platform

Macro

Value

H/PC 2000

WIN32_PLATFORM_HPC2000

 

H/PC Pro 2.11

WIN32_PLATFORM_HPCPRO

211

H/PC Pro 3.0

WIN32_PLATFORM_HPCPRO

300

Pocket PC

WIN32_PLATFORM_PSPC

1

Pocket PC 2002

WIN32_PLATFORM_PSPC

310

Windows Mobile 2003

WIN32_PLATFORM_PSPC

400

Smartphone 2002

WIN32_PLATFORM_WFSP

100

Wind/U Environment

Type

Macro

Format

Description

Identification

_WINDU_SOURCE

  

Version

_WINDU_SOURCE

0xVVRRPP

VV = Version
RR = Revision
PP = Patch

Example

Wind/U

_WINDU_SOURCE

3.1.2

0x030102

z/OS

Type

Macro

Description

Identification

__MVS__

Host

Identification

__HOS_MVS__

Host

Identification

__TOS_MVS__

Target


Top

Architectures 

Alpha

Type

Macro

Description

Identification

__alpha__

Defined by GNU C

Version

__alpha_ev'V'__

V = Version

Identification

__alpha

Defined by DEC C

Identification

_M_ALPHA

Defined by Visual Studio

Example

CPU

Macro

Alpha EV4

__alpha_ev4__

Alpha EV5

__alpha_ev5__

Alpha EV6

__alpha_ev6__

AMD64

Type

Macro

Description

Identification

__amd64__
__amd64
__x86_64__
__x86_64

Defined by GNU C and Sun Studio

Identification

_M_X64
_M_AMD64

Defined by Visual Studio

Notice that x32 can be detected by checking if the CPU uses the ILP32 data model.

ARM

Type

Macro

Description

Identification

__arm__

Defined by GNU C and RealView

Identification

__thumb__

Defined by GNU C and RealView in Thumb mode

Version

__ARM_ARCH_'V'__

V = Version

Defined by GNU C 1

Identification

__TARGET_ARCH_ARM
__TARGET_ARCH_THUMB

Defined by RealView

Version

__TARGET_ARCH_ARM = V
__TARGET_ARCH_THUMB = V

V = Version

Version

__TARGET_ARCH_'VR'

VR = Version and Revision

Identification

_ARM

Defined by ImageCraft C

Identification

_M_ARM

Defined by Visual Studio

Identification

_M_ARMT

Defined by Visual Studio in Thumb mode

Version

_M_ARM = V

V = Version

Identification

__arm

Defined by Diab

Example

CPU

Macro

_M_ARM

ARM 2

__ARM_ARCH_2__

 

ARM 3

__ARM_ARCH_3__
__ARM_ARCH_3M__

 

ARM 4T

__ARM_ARCH_4T__
__TARGET_ARM_4T

 

ARM 5

__ARM_ARCH_5__
__ARM_ARCH_5E__

5

ARM 5T

__ARM_ARCH_5T__
__ARM_ARCH_5TE__
__ARM_ARCH_5TEJ__

 

ARM 6

__ARM_ARCH_6__
__ARM_ARCH_6J__
__ARM_ARCH_6K__
__ARM_ARCH_6Z__
__ARM_ARCH_6ZK__

6

ARM 6T2

__ARM_ARCH_6T2__

 

ARM 7

__ARM_ARCH_7__
__ARM_ARCH_7A__
__ARM_ARCH_7R__
__ARM_ARCH_7M__
__ARM_ARCH_7S__

7

ARM64

Type

Macro

Description

Identification

__aarch64__

Defined by GNU C 1

Blackfin

Type

Macro

Description

Identification

__bfin
__BFIN__

Defined by GNU C

Convex

Type

Macro

Description

Identification

__convex__

Defined by GNU C

Version

__convex_'V'__

V = Version

Example

CPU

Macro

Convex C1

__convex_c1__

Convex C2

__convex_c2__

Convex C32xx series

__convex_c32__

Convex C34xx series

__convex_c34__

Convex C38xx series

__convex_c38__

Epiphany

Type

Macro

 

Identification

__epiphany__

 

HP/PA RISC

Type

Macro

Description

Identification

__hppa__

Defined by GNU C

Identification

__HPPA__

Defined by Stratus VOS C

Identification

__hppa

 

Version

_PA_RISC'V'_'R'

V = Version
R = Revision

See also OpenPA.net.

Example

CPU

Macro

PA RISC 1.0

_PA_RISC1_0

PA RISC 1.1

_PA_RISC1_1
__HPPA11__
__PA7100__

PA RISC 2.0

_PA_RISC2_0
__RISC2_0__
__HPPA20__
__PA8000__

Intel x86

Type

Macro

Format

Description

Identification

i386
__i386
__i386__

 

Defined by GNU C

Version

__i386__
__i486__
__i586__
__i686__

 

Defined by GNU C

Identification

__i386

 

Defined by Sun Studio

Identification

__i386
__IA32__

 

Defined by Stratus VOS C

Identification

_M_I86

 

Only defined for 16-bits architectures

Defined by Visual Studio, Digital Mars, and Watcom C/C++ (see note below)

Identification

_M_IX86

 

Only defined for 32-bits architectures

Defined by Visual Studio, Intel C/C++, Digital Mars, and Watcom C/C++

Version

_M_IX86

V00

V = Version

Identification

__X86__

 

Defined by Watcom C/C++

Identification

_X86_

 

Defined by MinGW32

Identification

__THW_INTEL__

 

Defined by XL C/C++

Identification

__I86__

 

Defined by Digital Mars

Version

__I86__

V

V = Version

Identification

__INTEL__

 

Defined by CodeWarrior

Identification

__386

 

Defined by Diab

Notice that Watcom C/C++ defines _M_IX86 for both 16-bits and 32-bits architectures. Use __386__ or _M_I386 to detect 32-bits architectures in this case.

Notice that the Stratus VOS is big-endian on IA32, so these macros cannot be used to detect endianness if __VOS__ is set.

Example

CPU

_M_IX86

__I86__

80386

300

3

80486

400

4

Pentium

500

5

Pentium Pro/II

600

6

Intel Itanium (IA-64)

Type

Macro

Format

Description

Identification

__ia64__
_IA64
__IA64__

 

Defined by GNU C

Identification

__ia64

 

Defined by HP aCC

Identification

_M_IA64

 

Defined by Visual Studio

Identification

_M_IA64

 

Defined by Intel C/C++

Version

_M_IA64

?

 

Identification

__itanium__

 

Defined by Intel C/C++

Example

CPU

_M_IA64 (Intel C/C++)

 

64100

Motorola 68k

Type

Macro

Description

Identification

__m68k__

Defined by GNU C

Version

__mc'V'__
__mc'V'
mc'V'

V = Version

Identification

M68000

Defined by SAS/C

Identification

__MC68K__

Defined by Stratus VOS C

Version

__MC'V'__

V = Version

Example

CPU

Macro

68000

__mc68000__
__MC68000__

68010

__mc68010__

68020

__mc68020__
__MC68020__

68030

__mc68030__
__MC68030__

68040

__mc68040__

68060

__mc68060__

MIPS

Type

Macro

Description

Identification

__mips__
mips

Defined by GNU C

Version

_MIPS_ISA = _MIPS_ISA_MIPS'V'

V = MIPS ISA level

Version

_R3000
_R4000
_R5900

 

Identification

__mips

Defined by MIPSpro and GNU C

Version

__mips

The value indicates the MIPS ISA (Instruction Set Architecture) level

Version

__MIPS_ISA'V'__

V = MIPS ISA level

Identification

__MIPS__

Defined by Metrowerks

Example

CPU

_MIPS_ISA

GNU C Macro

__mips

MIPSpro Macro

R2000

_MIPS_ISA_MIPS1

 

1

 

R3000

_MIPS_ISA_MIPS1

_R3000

1

 

R6000

_MIPS_ISA_MIPS2

 

2

__MIPS_ISA2__

R4000

 

_R4000

  

R4400

_MIPS_ISA_MIPS3

 

3

__MIPS_ISA3__

R8000

_MIPS_ISA_MIPS4

 

4

__MIPS_ISA4__

R10000

_MIPS_ISA_MIPS4

 

4

__MIPS_ISA4__

PowerPC

Type

Macro

Description

Identification

__powerpc
__powerpc__
__powerpc64__
__POWERPC__
__ppc__
__ppc64__
__PPC__
__PPC64__
_ARCH_PPC
_ARCH_PPC64

Defined by GNU C

Version

__ppc'V'__

V = Version

Identification

_M_PPC

Defined by Visual Studio

Version

_M_PPC

?

Identification

_ARCH_PPC
_ARCH_PPC64

Defined by XL C/C++

Version

_ARCH_'V'

V = Version

Version

__PPCGECKO__

Gekko

Defined by CodeWarrior

Version

__PPCBROADWAY__

Broadway

Defined by CodeWarrior

Version

_XENON

Xenon

Identification

__ppc

Defined by Diab

Example

CPU

_M_PPC

Macro

XL Macro

PowerPC 440

  

_ARCH_440

PowerPC 450

  

_ARCH_450

PowerPC 601

601

__ppc601__

_ARCH_601

PowerPC 603

603

__ppc603__

_ARCH_603

PowerPC 604

604

__ppc604__

_ARCH_604

PowerPC 620

620

  

Pyramid 9810

Type

Macro

Identification

pyr

RS/6000

Type

Macro

Description

Identification

__THW_RS6000

Defined by XL C/C++

Identification

_IBMR2

 

Identification

_POWER

 

Identification

_ARCH_PWR
_ARCH_PWR2
_ARCH_PWR3
_ARCH_PWR4

 

SPARC

Type

Macro

Description

Identification

__sparc__

Defined by GNU C

Identification

__sparc

Defined by Sun Studio

Version

__sparc_v8__
__sparc_v9__

Defined by GNU C

Version

__sparcv8
__sparcv9

Defined by Sun Studio

Example

CPU

Sun Studio Macro

GNU C Macro

SPARC v8 (SuperSPARC)

__sparcv8

__sparc_v8__

SPARC v9 (UltraSPARC)

__sparcv9

__sparc_v9__

SuperH

Type

Macro

Description

Identification

__sh__

Defined by GNU C

Version

__sh1__
__sh2__
__sh3__
__SH3__
__SH4__
__SH5__

 

SystemZ

Type

Macro

Description

Identification

__370__
__THW_370__

Identifies System/370

Defined by XL C/C++

Identification

__s390__

Identifies System/390

Defined by GNU C

Identification

__s390x__

Identifies z/Architecture

Defined by GNU C

Identification

__zarch__

Identifies z/Architecture

Defined by clang

Identification

__SYSC_ZARCH__

Identifies z/Architecture

Defined by Systems/C

TMS320

Type

Macro

Description

Identification

_TMS320C2XX
__TMS320C2000__

C2000 series

Identification

_TMS320C5X
__TMS320C55X__

C5000 series

Identification

_TMS320C6X
__TMS320C6X__

C6000 series

Example

DSP

Macro

C28xx

_TMS320C28X

C54x

_TMS320C5XX

C55x

__TMS320C55X__

C6200

_TMS320C6200

C6400

_TMS320C6400

C6400+

_TMS320C6400_PLUS

C6600

_TMS320C6600

C6700

_TMS320C6700

C6700+

_TMS320C6700_PLUS

C6740

_TMS320C6740

TMS470

Type

Macro

Identification

__TMS470__

 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值