Platform Identification

This is a list of preprocessor macros defined for various compilers and OSs, for use in conditional compilation.

Programming language

 * __STDC__ : with the value 1, indicates ISO/IEC 9899 (C), either 1990 (ANSI C) or 1999 (C99) versions. may also be defined by C++ implementations with implementation-defined value.
 * __STDC_VERSION__ : the version of C supported; for C99, has the value 199901L.
 * __STDC_HOSTED__ : defined if the C implementation is hosted
 * __cplusplus : defined for C++

Operating systems

 * Linux : __linux__
 * Solaris : __sun && __SVR4
 * MS Windows (32-bit) : _WIN32 (Always defined with Visual C++).   _WIN32_IE defines the version of Internet Explorer extensions available.  See msdn (http://msdn.microsoft.com) for more information.
 * Cygwin : __CYGWIN32__, __CYGWIN__, unix, __unix__, __unix</tt>
 * OpenVMS : __VMS</tt>

Compilers

 * GCC : __GNUC__</tt>; __GNUC_MAJOR__</tt> (major version, e.g. 4); __GNUC_MINOR__</tt> (minor version, e.g. 1)
 * Sun Studio : __SUNPRO_C</tt> (C compiler); __SUNPRO_CC</tt> (C++ compiler). both defined to the compiler's version in hex, e.g. 0x580 for 5.8
 * MS Visual C++ : _MSC_VER</tt> Major and minor versions of the compiler, in decimal. "1310 represents version 13 and a 1.0 point point release."  For VC 2005, it is 1400 (0x578)
 * Intel C/C++ : __INTEL_COMPILER</tt>

Feature selection
In addition to macros provided by the implementation, on many implementations the user can define macros to select the features provided by the implementation.

Windows
WINVER</tt>, _WIN32_WINDOWS</tt>, and _WIN32_WINNT</tt> define version levels for the headers, need to be set by the programmer to a specific version to enable "newer" functionality. It is also possible to set these values lower than the default used by a particular version of the Platform SDK in order to disable use of features not supported on prior versions of the Windows OS.

Unix
Various macros can be defined to select the standard the implementation should provide. These should usually be given on the compiler command line to ensure they are set before any headers are included.

POSIX

 * _POSIX_SOURCE</tt> : POSIX.1-1990
 * _POSIX_SOURCE && _POSIX_C_SOURCE=2</tt> : POSIX.1-1990 + POSIX.2-1992
 * _POSIX_C_SOURCE=199309L</tt> : POSIX.1b-1993
 * _POSIX_C_SOURCE=199506L</tt> : POSIX.1c-1996
 * <tt>_POSIX_C_SOURCE=200112L</tt> : POSIX.1-2001

X/Open Common Applications Environment (CAE) Portability Guide (XPG), Single Unix Specification (SUS) and Networking Services (XNS)

 * <tt>_XOPEN_SOURCE</tt> (with no value or with any value less than 500) : XPG issue 3
 * <tt>_XOPEN_SOURCE</tt> (with no value or with any value less than 500) && <tt>_XOPEN_VERSION=4</tt> : XPG issue 4
 * <tt>_XOPEN_SOURCE</tt> (with no value or with any value less than 500) && <tt>_XOPEN_SOURCE_EXTENDED=1</tt> : XPG issue 4v2 (= SUSv1, includes XNS4)
 * <tt>_XOPEN_SOURCE=500</tt> : SUSv2
 * <tt>_XOPEN_SOURCE=600</tt> : SUSv3 (not supported for C++ under Solaris)

Non-standard extensions

 * <tt>__EXTENSIONS__</tt> : (Solaris) provides, in addition to the features of the selected standard, all Solaris features not in conflict with the selected standard
 * <tt>_GNU_SOURCE</tt> : (GNU glibc) provides GNU-specific extensions not specific in the selected standard