I do a lot of cross platform development in C/C++, targeting Linux, Windows, macOS, using GCC, MSVC, clang etc.
In order to have cross platform support, it is sometimes needed to add platform dependent or compiler dependent code. I compiled a list of the most important macros I use. This might be helpful for some others as well.
Macro | Definition |
---|---|
__linux__ |
Linux and Linux-derived |
__ANDROID__ |
Android |
#if defined(__linux__) && !defined(__ANDROID__) |
Linux (non-Android) |
__APPLE__ |
Darwin (macOS and iOS) |
_WIN32 |
Windows (32- and 64-bit) |
_WIN64 |
Windows 64-bit |
_MSC_VER |
Visual Studio |
__GNUC__ |
gcc |
__clang__ |
clang |
__EMSCRIPTEN__ |
emscripten |
__MINGW32__ |
MinGW 32, MinGW-w64 32-bit |
__MINGW64__ |
MinGW-w64 64-bit |
ARM9 (1) |
Nintendo DS (ARM9) |
_3DS (1) |
Nintendo 3DS |
__SWITCH__ (1) |
Nintendo Switch |
(1) These are defined by the makefiles provided by devkitpro using the -D
option, they are not built into the inofficial compilers.
Top comments (0)