Macros for GCC/G++ to differentiate Linux and Mac OSX?

Viet picture Viet · Apr 2, 2010 · Viewed 37.9k times · Source

Macros for GCC/G++ to differentiate Linux and Mac OSX?

Answer

themoondothshine picture themoondothshine · Apr 2, 2010

The next time you want to check out pre-defined macros supported by GCC on a platform, run the preprocessor with the flag -dM. It'll list out all the predefined macros available on the system. For example:

$ touch dummy.hxx
$ cpp -dM ./dummy.hxx
#define __DBL_MIN_EXP__ (-1021)
#define __FLT_MIN__ 1.17549435e-38F
#define __CHAR_BIT__ 8
#define __WCHAR_MAX__ 2147483647
#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
#define __FLT_EVAL_METHOD__ 0
#define __DBL_MIN_10_EXP__ (-307)
#define __FINITE_MATH_ONLY__ 0
#define __SHRT_MAX__ 32767
#define __LDBL_MAX__ 1.18973149535723176502e+4932L
#define __UINTMAX_TYPE__ long unsigned int
#define __linux 1
#define __unix 1
#define __linux__ 1
...