Platform Identification

From Cppwiki

Jump to: navigation, search

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

Contents

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
OpenVMS 
__VMS

Compilers

GCC 
__GNUC__; __GNUC_MAJOR__ (major version, e.g. 4); __GNUC_MINOR__ (minor version, e.g. 1)
Sun Studio 
__SUNPRO_C (C compiler); __SUNPRO_CC (C++ compiler). both defined to the compiler's version in hex, e.g. 0x580 for 5.8
MS Visual C++ 
_MSC_VER 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

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, _WIN32_WINDOWS, and _WIN32_WINNT 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 
POSIX.1-1990
_POSIX_SOURCE && _POSIX_C_SOURCE=2 
POSIX.1-1990 + POSIX.2-1992
_POSIX_C_SOURCE=199309L 
POSIX.1b-1993
_POSIX_C_SOURCE=199506L 
POSIX.1c-1996
_POSIX_C_SOURCE=200112L 
POSIX.1-2001

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

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

Non-standard extensions

__EXTENSIONS__ 
(Solaris) provides, in addition to the features of the selected standard, all Solaris features not in conflict with the selected standard
_GNU_SOURCE 
(GNU glibc) provides GNU-specific extensions not specific in the selected standard
Personal tools