Pre-defined C/C++ Compiler Macros

Index Standards Compilers Operating Systems Architecture

Operating Systems

Incomplete.
 
Name Macro Comment
AIX
_AIX
__TOS_AIX__ [__xlC__]
If _AIX is defined, then the following macros can be used to determine the version. Please note that the macros indicates the mentioned version or higher. For example, if _AIX43 is defined, then _AIX41 will also be defined. 
AIX Macro
3.2.x _AIX3, _AIX32
4.1 _AIX41
4.3 _AIX43
AmigaOS
AMIGA
__amigaos__ [__GNUC__]
 
BEOS __BEOS__  
BSD/OS
bsdi
__bsdi__
 
Cray Unicos
_UNICOS
_CRAY
_UNICOS = V V = Version
DG/UX
DGUX
__DGUX__
__dgux__
 
DYNIX/ptx
_SEQUENT_
sequent
 
FreeBSD __FreeBSD__ Use the BSD macro if feasible.

The __FreeBSD__ macro determines the major version number. 
FreeBSD __FreeBSD__
1.x 1
2.x 2

The __FreeBSD_version macro determines the entire version number (this macro must be included from <osreldate.h>).

Examples
 
FreeBSD __FreeBSD_version
2.0-RELEASE 119411
2.2-RELEASE 220000
3.0-RELEASE 300005
4.0-RELEASE 400017
4.5-RELEASE 450000

HP/UX
hpux [__GNUC__]
__hpux
_HPUX_SOURCE
 
Hurd __GNU__  
IRIX
sgi
mips
_SGI_SOURCE
 
Linux
linux
__linux
 
Mac OS 9
macintosh
Macintosh
 
Mac OS X
__MACOSX__
__APPLE__ [__GNUC__]
 
MPE/iX
mpeix
__mpexl
 
MSDOS
MSDOS
__MSDOS__
_MSDOS
__DOS__
 
NetBSD __NetBSD__ Use the BSD macro if feasible.

Version is defined with a macro in <sys/param.h> 
NetBSD Macro
0.8 NetBSD0_8
0.9 NetBSD0_9
1.0 NetBSD1_0 = 1
1.0A NetBSD1_0 = 2

OpenBSD __OpenBSD__ Use the BSD macro if feasible.

Version is defined with a macro in <sys/param.h> 
Version Macro OpenBSD
3.1 OpenBSD3_1 200206

OS/2
OS2
_OS2
__OS2__
__TOS_OS2__
 
OSF/1
__osf__
__osf
 
Pyramid DC/OS pyr  
QNX
__QNX__
__QNXNTO__
 
Reliant UNIX sinix  
SCO OpenServer
M_I386 [__GNUC__]
M_XENIX [__GNUC__]
__SCO_DS
__SCO_C_DIALECT
 
Solaris
sun
__sun
__SUNPRO_C
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

The Sun Compiler supports macros of the type __System_Version, where System is the result of the 'uname -s' command and Version of 'uname -r', and any illegal characters are replaced by an underscore.
Solaris Macro
2.7
__SunOS_5_7
8
__SunOS_5_8

Ultrix
ultrix
__ultrix
__ultrix__
unix & vax
 
UnixWare
sco
_UNIXWARE7
 
VMS
VMS
__VMS
__VMS_VER = VVRREPPTT VV = Version

RR = Revision

E = Edit number

PP = Patch (01 = A, ... 26 = Z)

TT = Type (22 = official)

Examples
 
VMS __VMS_VER
6.1 60100022
6.2 60200022
6.2-1I 60210922

Win32 API
_WIN32
__WIN32__
__TOS_WIN__
 

Operating Environments

 
Name Macro Comment
BSD __FreeBSD__
__NetBSD__
__OpenBSD__
__bsdi__
_BSD_SOURCE
_SYSTYPE_BSD [__DECC]
The following macros have to been included from <sys/param.h> 
  • BSD
  • BSD4_2
  • BSD4_3
  • BSD4_4
Examples
 
Version BSD Macro
4.3 Net2 199103
4.4 199306 BSD4_4
4.4BSD-Lite2 199506
SVR4 __sysv__
__SVR4
__svr4__
_SVR4_SOURCE
_SYSTYPE_SVR4 [__sgi]
 
Unix unix
__unix__
__unix
Generic macros, of which at least one is defined on a Unix compliant platform.

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

U/Win _UWIN  
Wind/U _WINDU_SOURCE
Wind/U _WINDU_SOURCE
3.1.2 0x030102

$Id: preos.html,v 1.3 2004/05/31 09:13:35 breese Exp $