You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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 Buildtool, CMake, SCons, PMK, Jam, Ant, and Bakefile.
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.