When we compile some cross -platform programs, we will inevitably encounter _win32 __linux__ what is the macro of the compiler or the compiler environment.It indicates some information of the current platform environment to the compiler.
When we compile some cross -platform programs, we will inevitably encounter _win32 , Linux What are the macroscopic macro of the compiler environment.There are many differences between _win32 and win32 before.But there is a list here, making a memo.
For example, a code that can only be compiled under the Unix-Like platform in a set.If you compile the wrong error on the non-Unix-Like platform, then my code can add a macro to check whether it is a UNIX environment.If it is normally compiled, the error is thrown directly.
#ifndef __unix__
#error This program should be complied and work in UNIX-LIKE platform.
#endif
The complete code is as follows:
#ifndef __unix__
#error This program should be complied and work in UNIX-LIKE platform.
#endif
#include<stdio.h>intmain(){printf("this is unix-like platform");return0;}
This code can be compiled normally in the Mac OS and Linux environments, and an error will be reported under Windows.
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.
For more information see the FreeBSD porters handbook. GNU aka GNU/Hurd
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
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. GNU/Linux
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.
#if defined(sun) || defined(**sun) # if defined(**SVR4) || defined(svr4) /_ Solaris / # else / SunOS _/ # endif #endif Example
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. SVR4 Environment
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. UnixWare