sometime when writing c or c++ code you need to write a code specific to the compiler/OS. and to this job the compiler have some predefined macros to detect the compiler or the OS.
Checking for OS:
to check which platform the code is compiled use these predefined macros:
for Windows : _WIN32 for Windows 64 bit : _WIN64 ( _WIN32 included ) for Mac OS & IOS : __APPLE__ for Linux & Linux-derived: __linux__ for Android : __ANDROID__ ( __linux__ included ) for Akaros : __ros__ for NaCL : __native_client__ for AsmJS : __asmjs__ for Fuschia : __Fuchsia__
Checking for Compiler:
to check wich compiler used:
Visual Studio _MSC_VER gcc __GNUC__ clang __clang__ emscripten __EMSCRIPTEN__ (for asm.js and webassembly) MinGW 32 __MINGW32__ MinGW-w64 32bit __MINGW32__ MinGW-w64 64bit __MINGW64__
Top comments (1)
There is an awesome page with a lot a defines from OS, compilers, etc: sourceforge.net/p/predef/wiki/Home/