1、AIX

Developer:     IBM
Distributions:     AIX
Processors:     POWER

004.png

代码:
#if defined(_AIX)
/* IBM AIX. ------------------------------------------------- */
#endif

2、BSD

Developer:     Open source
Distributions:     DragonFly BSD, FreeBSD, OpenBSD, NetBSD
Processors:     x86, x86-64, Itanium, POWER, SPARC, etc.

005.png

代码:
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
    #include <sys/param.h>
#if defined(BSD)
/* BSD (DragonFly BSD, FreeBSD, OpenBSD, NetBSD). ----------- */
#endif
#endif

3、HP-UX

Developer:     Hewlett-Packard
Distributions:     HP-UX
Processors:     Itanium

06.png


代码:
#if defined(__hpux)
/* Hewlett-Packard HP-UX. ----------------------------------- */
#endif

4、Linux

Developer:     Open source
Distributions:     Centos, Debian, Fedora, OpenSUSE, RedHat, Ubuntu
Processors:     x86, x86-64, POWER, etc.

007.png

代码:
#if defined(__linux__)
/* Linux. --------------------------------------------------- */
#endif

5、OSX, iOS, and Darwin

Developer:     Apple and open source
Distributions:     OSX, iOS, Darwin
Processors:     x86, x86-64, ARM

008.png

代码:
#if defined(__APPLE__) && defined(__MACH__)
/* Apple OSX and iOS (Darwin). ------------------------------ */
    #include <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR == 1
/* iOS in Xcode simulator */
#elif TARGET_OS_IPHONE == 1
/* iOS on iPhone, iPad, etc. */
#elif TARGET_OS_MAC == 1
/* OSX */
#endif
#endif

6、Solaris

Developer:     Oracle and open source
Distributions:     Oracle Solaris, Open Indiana
Processors:     x86, x86-64, SPARC

009.png

代码:
#if defined(__sun) && defined(__SVR4)
/* Solaris. ------------------------------------------------- */
#endif

7、Windows with Cygwin (POSIX)

Developer:     Open source
Distributions:     Cygwin
Processors:     x86

010.png

代码:
#if defined(__CYGWIN__) && !defined(_WIN32)
/* Cygwin POSIX under Microsoft Windows. -------------------- */
#endif

8、Windows, Cygwin (non-POSIX), and MinGW

Developer:     Microsoft
Distributions:     Windows XP, Vista, 7, 8
Processors:     x86, x86-64

011.png

代码:
#if defined(_WIN64)
/* Microsoft Windows (64-bit). ------------------------------ */
#elif defined(_WIN32)
/* Microsoft Windows (32-bit). ------------------------------ */
#endif

9、POSIX

Developer:     Standard
Distributions:     All current UNIX-style OSes, including BSD, Linux, OSX, and Solaris
Processors:     x86, x86-64, ARM, POWER, SPARC, etc.

代码:
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) &&                                         defined(__MACH__)))
/* UNIX-style OS. ------------------------------------------- */
    #include <unistd.h>
#if defined(_POSIX_VERSION)
/* POSIX compliant */
#endif
#endif

10、UNIX

Developer:     De facto standard
Distributions:     All current UNIX-style OSes, including BSD, Linux, OSX, and Solaris
Processors:     x86, x86-64, ARM, POWER, SPARC, etc.

012.png

代码:
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) &&     defined(__MACH__)))
/* UNIX-style OS. ------------------------------------------- */

#endif

【参考文档】http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system