转念一想,其实工程中需要的操作系统的宏定义是这样的,更多的硬件宏定义就到对应的硬件手册查查。 
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #ifdef _WIN32    //define something for Windows (32-bit and 64-bit, this part is common)    #ifdef _WIN64       //define something for Windows (64-bit only)    #else       //define something for Windows (32-bit only)    #endif #elif __APPLE__     #include "TargetConditionals.h"     #if TARGET_IPHONE_SIMULATOR          // iOS Simulator     #elif TARGET_OS_IPHONE         // iOS device     #elif TARGET_OS_MAC         // Other kinds of Mac OS     #else     #   error "Unknown Apple platform"     #endif #elif __ANDROID__     // android #elif __linux__     // linux #elif __unix__ // all unices not caught above     // Unix #elif defined(_POSIX_VERSION)     // POSIX #else #   error "Unknown compiler" #endif 
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 
 
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 
 
 
Type 
Macro 
 
 
Identification 
UTS 
 
Type 
Macro 
Description 
 
 
Identification 
AMIGA 
Identification 
__amigaos__Defined by GNU C 
 
 
Type 
Macro 
 
 
Identification 
aegis 
 
Type 
Macro 
 
 
Identification 
apollo 
 
Based on Nucleus OS.
Type 
Macro 
 
 
Identification 
__BEOS__ 
 
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++ 
 
 
Type 
Macro 
Format 
Description 
 
 
Identification 
__FreeBSD__``__NetBSD__``__OpenBSD__``__bsdi__``__DragonFly__ 
Version 
BSDYYYYMM 
YYYY = Year MM = MonthMust be included from <sys/param.h> 
 
Version 
BSD4_2``BSD4_3``BSD4_4Must be included from <sys/param.h> 
 
Identification 
_SYSTYPE_BSDDefined by DEC C 
 
 
Example 
Version 
BSDMacro 
 
 
4.3 Net2 
199103 
 
4.4 
199306 
BSD4_4 
4.4BSD-Lite2 
199506 
 
 
Type 
Macro 
 
 
Identification 
__bsdi__ 
 
Type 
Macro 
 
 
Identification 
__convex__ 
 
Type 
Macro 
 
 
Identification 
__CYGWIN__ 
 
Type 
Macro 
 
 
Identification 
DGUX 
Identification 
__DGUX__ 
Identification 
__dgux__ 
 
Type 
Macro 
 
 
Identification 
__DragonFly__ 
 
Type 
Macro 
 
 
Identification 
_SEQUENT_ 
Identification 
sequent 
 
Type 
Macro 
 
 
Identification 
__ECOS 
 
Type 
Macro 
 
 
Identification 
__EMX__ 
 
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 .
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 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.
Type 
Macro 
 
 
Identification 
__gnu_linux__ 
 
Type 
Macro 
 
 
Identification 
__hiuxmpp 
 
Type 
Macro 
Description 
 
 
Identification 
_hpuxDefined by HP UPC 
 
Identification 
hpux 
Identification 
__hpux 
 
Type 
Macro 
Format 
Description 
 
 
Identification 
__OS400__ 
Version 
__OS400_TGTVRM__VRM 
V = Version R = RevisionM = Modification 
 
 
Type 
Macro 
 
 
Identification 
__INTEGRITY 
 
Type 
Macro 
Description 
 
 
Identification 
__INTERIXDefined by GNU C and Visual Studio 
 
 
Type 
Macro 
 
 
Identification 
sgi 
Identification 
__sgi 
 
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 
linuxObsolete (not POSIX compliant) 
 
Identification 
__linuxObsolete (not POSIX compliant) 
 
 
Type 
Macro 
 
 
Identification 
__Lynx__ 
 
Type 
Macro 
Description 
 
 
Identification 
macintoshMac OS 9 
 
Identification 
MacintoshMac OS 9 
 
Identification 
__APPLE__ && __MACH__Mac OS X``Defined by GNU C and Intel C++ 
 
 
Type 
Macro 
Description 
 
 
Identification 
__OS9000Defined by Ultimate C/C++ 
 
Identification 
_OSKDefined by Ultimate C/C++ 
 
 
Type 
Macro 
 
 
Identification 
__minix 
 
Type 
Macro 
 
 
Identification 
__MORPHOS__ 
 
Type 
Macro 
 
 
Identification 
mpeix 
Identification 
__mpexl 
 
Type 
Macro 
 
 
Identification 
MSDOS 
Identification 
__MSDOS__ 
Identification 
_MSDOS 
Identification 
__DOS__ 
 
Type 
Macro 
Format 
Description 
 
 
Identification 
__NetBSD__ 
Version 
BSD 
Version 
NetBSD'V'_'R'V = Version R = RevisionMust be included from <sys/param.h> 
 
Version 
__NetBSD_Version__VVRRAAPP00 
VV = Version RR = RevisionAA = Release PP = PatchFrom NetBSD 1.2D (?) until NetBSD 2.0H``Must be included from <sys/param.h> 
 
Version 
__NetBSD_Version__VVRR00PP00 
VV = Version RR = RevisionPP = Patch From NetBSD 2.99.9Must 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 
 
 
Type 
Macro 
 
 
Identification 
__TANDEM 
 
Type 
Macro 
 
 
Identification 
__nucleus__ 
 
Type 
Macro 
Format 
Description 
 
 
Identification 
__OpenBSD__ 
Version 
BSD 
Version 
OpenBSD'V'_'R'V = Version R = RevisionMust be included from <sys/param.h> 
 
 
Example 
OpenBSD 
Macro 
 
 
3.1 
OpenBSD3_1 
3.9 
OpenBSD3_9 
 
Type 
Macro 
 
 
Identification 
OS2 
Identification 
_OS2 
Identification 
__OS2__ 
Identification 
__TOS_OS2__ 
 
Type 
Macro 
Description 
 
 
Identification 
__palmos__Defined by GNU C inPRC-Tools  
 
 
Type 
Macro 
 
 
Identification 
EPLAN9 
 
Type 
Macro 
 
 
Identification 
pyr 
 
Type 
Macro 
Format 
Description 
 
 
Identification 
__QNX__QNX 4.x 
 
Identification 
__QNXNTO__QNX 6.x 
 
Version 
_NTO_VERSIONVRR 
V = Version RR = RevisionOnly available when __QNXNTO__ is defined.``Must be included from <sys/neutrino.h> 
 
Version 
BBNDK_VERSION_CURRENTVVRRRRPPPP 
V = Version RRRR = RevisionPPPP = Patch Only available on [Blackberry 10](http://en.wikipedia.org/wiki/Blackberry_10)From Blackberry 10.1.0``Must be included from <bbndk.h> 
 
 
Example 
Type 
Macro 
 
 
Identification 
sinux 
 
Type 
Macro 
Description 
 
 
Identification 
M_I386Defined by GNU C 
 
Identification 
M_XENIXDefined by GNU C 
 
Identification 
_SCO_DS 
 
Type 
Macro 
Description 
 
 
Identification 
sun 
Identification 
__sun 
Version 
__'System'_'Version'System =uname -sVersion = uname -rAny illegal character is replaced by an underscore.``Defined by Sun Studio 
 
 
Use the SVR4 macros to distinguish between Solaris and SunOS.
1 2 3 4 5 6 7 #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 
 
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.
Type 
Macro 
Description 
 
 
Identification 
__sysv__ 
Identification 
__SVR4 
Identification 
__svr4__ 
Identification 
_SYSTYPE_SVR4Defined on IRIX 
 
 
Type 
Macro 
 
 
Identification 
__SYLLABLE__ 
 
Type 
Macro 
 
 
Identification 
__SYMBIAN32__ 
 
Type 
Macro 
 
 
Identification 
__osf__ 
Identification 
__osf 
 
Type 
Macro 
 
 
Identification 
ultrix 
Identification 
__ultrix 
Identification 
__ultrix__ 
Identification 
unix & vax 
 
Type 
Macro 
Format 
Description 
 
 
Identification 
_UNICOS 
Version 
_UNICOSV 
V = Version 
 
 
Type 
Macro 
Description 
 
 
Identification 
_CRAY``__crayx1 
 
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.
Type 
Macro 
 
 
Identification 
sco 
Identification 
_UNIXWARE7 
 
Type 
Macro 
 
 
Identification 
_UWIN 
 
Type 
Macro 
Format 
Description 
 
 
Identification 
VMS 
Identification 
__VMS 
Version 
__VMS_VERVVRREPPTT 
VV = Version RR = RevisionE = 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 
 
 
Type 
Macro 
Description 
 
 
Identification 
__VXWORKS__Defined by GNU C and Diab (from ?) 
 
Identification 
__vxworksDefined by GNU C and Diab (from ?) 
 
Version 
_WRS_VXWORKS_MAJORVersion``Must be included from <version.h> 
 
Version 
_WRS_VXWORKS_MINORRevision``Must be included from <version.h> 
 
Version 
_WRS_VXWORKS_MAINTPatch/maintenance``Must be included from <version.h> 
 
Mode 
__RTP__For real-time mode 
 
Mode 
_WRS_KERNELFor kernel mode 
 
 
Example 
VxWorks 
_WRS_VXWORKS_MAJOR_WRS_VXWORKS_MINOR_WRS_VXWORKS_MAINT 
 
6.2 
6 
2 
0 
 
 
Type 
Macro 
Description 
 
 
Identification 
_WIN16Defined for 16-bit environments1  
 
Identification 
_WIN32Defined for both 32-bit and 64-bit environments1  
 
Identification 
_WIN64Defined for 64-bit environments1  
 
Identification 
__WIN32__Defined by Borland C++ 
 
Identification 
__TOS_WIN__Defined by xlC 
 
Identification 
__WINDOWS__Defined by Watcom C/C++ 
 
 
Type 
Macro 
Format 
Description 
 
 
Identification 
_WIN32_WCEDefined by Embedded Visual Studio C++ 
 
Version 
_WIN32_WCEVRR 
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_HPCPRO211 
 
H/PC Pro 3.0 
WIN32_PLATFORM_HPCPRO300 
 
Pocket PC 
WIN32_PLATFORM_PSPC1 
 
Pocket PC 2002 
WIN32_PLATFORM_PSPC310 
 
Windows Mobile 2003 
WIN32_PLATFORM_PSPC400 
 
Smartphone 2002 
WIN32_PLATFORM_WFSP100 
 
 
Type 
Macro 
Format 
Description 
 
 
Identification 
_WINDU_SOURCE 
Version 
_WINDU_SOURCE0xVVRRPP 
VV = Version RR = RevisionPP = Patch 
 
 
Example 
Wind/U 
_WINDU_SOURCE 
 
3.1.2 
0x030102 
 
 
Type 
Macro 
Description 
 
 
Identification 
__MVS__Host 
 
Identification 
__HOS_MVS__Host 
 
Identification 
__TOS_MVS__Target 
 
 
Wiki: Home