How to list compiler predefined macros
Clang/LLVM:
clang -dM -E -x c /dev/null
clang++ -dM -E -x c++ /dev/null
GNU GCC/G++:
gcc -dM -E -x c /dev/null
g++ -dM -E -x c++ /dev/null
How to detect the operating system type using compiler predefined macros
Linux
#if defined(__linux__)
/* Linux. --------------------------------------------------- */
#endif
BSD
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#include <sys/param.h>
#if defined(BSD)
/* BSD (DragonFly BSD, FreeBSD, OpenBSD, NetBSD). ----------- */
#endif
#endif
Reference
0 comments:
Post a Comment