I'm going to make a C/C++ code that supports multiple platforms You want to determine which platform the preprocessor is using. Where can I find relevant information?
c c++ cross-platform preprocessor os-detection
The list of macros available for most compilers is [here], See [here]
for predefined macros in the GCC compilerExample in gcc
#ifdef _WIN32
//define something for Windows (32-bit and 64-bit, this part is common)
#ifdef _WIN64
//define something for Windows (64-bit only)
#endif
#elif __APPLE__
#include "TargetConditionals.h"
#if TARGET_IPHONE_SIMULATOR
// // iOS Simulator
#elif TARGET_OS_IPHONE
// // iOS device
#elif TARGET_OS_MAC
// // Other kinds of Mac OS
#else
# # error "Unknown Apple platform"
#endif
#elif __linux__
// // linux
#elif __unix__ // all unices not caught above
// // Unix
#elif defined(_POSIX_VERSION)
// // POSIX
#else
# # error "Unknown compiler"
#endif
The results of this macro depend on the compiler
_WIN32
detects windows as well as 32-bit (x86)
You can also write _WIN32 #ifdef
instead of The_WIN64 #ifdef
© 2024 OneMinuteCode. All rights reserved.