Predefined macros are macro definitions provided by the compiler.
Compiler-related Macros#
Different compilers provide their own set of predefined macros.
- GCC
__GNUC__: Major version of GCC.__GNUC_MINOR__: Minor version of GCC.__GNUC_PATCHLEVEL__: Patch level of GCC.
- Clang
__clang__: Defined when using the Clang compiler.__clang_major__: Major version of Clang.__clang_minor__: Minor version of Clang.__clang_patchlevel__: Patch level of Clang.
- MSVC
_MSC_VER: Version number of MSVC._MSC_BUILD: MSVC build number.
Operating System-related Macros#
- Windows
_WIN32: Defined on both 32-bit and 64-bit Windows systems._WIN64: Defined only on 64-bit Windows systems.
- Unix or Unix-like
__unix__: Defined on Unix and Unix-like systems (e.g., Linux).__APPLE__: Defined on macOS and iOS systems.__linux__: Defined on Linux systems.__FreeBSD__: Defined on FreeBSD systems.__OpenBSD__: Defined on OpenBSD systems.__NetBSD__: Defined on NetBSD systems.__DragonFly__: Defined on DragonFly BSD systems.__sun: Defined on Solaris systems.__hpux: Defined on HP-UX systems.__sgi: Defined on IRIX systems.__AIX: Defined on AIX systems.
- Others
__ANDROID__: Defined on the Android platform.__CYGWIN__: Defined in the Cygwin environment.
Standard Library-related Macros#
__cplusplus: Indicates whether the compiler is compiling C++ code. If the compiler is compiling C++ code, the value of this macro is nonzero; otherwise, it is undefined.__STDC__: Indicates whether the compiler follows the C standard. If the compiler follows the C standard, the value of this macro is 1; otherwise, it is undefined.__STDC_VERSION_: Version of the C standard.
Hardware Architecture-related Macros#
__arm__: ARM architecture.__x86_64__: x86_64 architecture.
Feel free to point out any omissions