What OS and compiler is this?
11Aug2006
I was trying to find out how to tell, from within a C program under GCC, what OS the code was being compiled under. I was porting RPCemu to MacOSX, and wanted to switch between big and little endian code without doing something clunky in autoconf.
I Googled for lists of pre-defined C pre-processor macros, but found didn't find any. Eventually, I discovered that you can get a list of the macros under GCC on a particular platform by creating an empty c file (empty.c) and running this command:
gcc -std=c99 -E -dM empty.c
Linux - gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-56)
#define HAVE_BUILTIN_SETJMP 1 #define unix 1 #define i386 1 #define SIZE_TYPE unsigned int #define ELF 1 #define GNUC_PATCHLEVEL 3 #define GNUC_RH_RELEASE 56 #define __linux 1 #define __unix 1 #define linux 1 #define STDC_VERSION 199901L #define USER_LABEL_PREFIX #define STDC_HOSTED 1 #define WCHAR_TYPE long int #define gnu_linux 1 #define WINT_TYPE unsigned int #define GNUC 3 #define STRICT_ANSI 1 #define __GXX_ABI_VERSION 102 #define GNUC_MINOR 2 #define STDC 1 #define PTRDIFF_TYPE int #define tune_i386 1 #define REGISTER_PREFIX #define NO_INLINE 1 #define __i386 1 #define VERSION "3.2.3 20030502 (Red Hat Linux 3.2.3-56)"
Mac - powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5341)
#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 GNUC_PATCHLEVEL 1 #define SHRT_MAX 32767 #define LDBL_MAX 1.79769313486231580793728971405301e+308L #define APPLE_CC 5341 #define UINTMAX_TYPE long long unsigned int #define LDBL_MAX_EXP 1024 #define SCHAR_MAX 127 #define USER_LABEL_PREFIX _ #define STDC_HOSTED 1 #define LDBL_HAS_INFINITY 1 #define DBL_DIG 15 #define FLT_EPSILON 1.19209290e-7F #define LDBL_MIN 2.00416836000897277799610805135016e-292L #define ppc 1 #define __strong #define APPLE 1 #define DECIMAL_DIG 33 #define LDBL_HAS_QUIET_NAN 1 #define DYNAMIC 1 #define GNUC 4 #define DBL_MAX 1.7976931348623157e+308 #define DBL_HAS_INFINITY 1 #define STRICT_ANSI 1 #define __weak #define DBL_MAX_EXP 1024 #define LONG_LONG_MAX 9223372036854775807LL #define __GXX_ABI_VERSION 1002 #define FLT_MIN_EXP (-125) #define DBL_MIN 2.2250738585072014e-308 #define DBL_HAS_QUIET_NAN 1 #define REGISTER_PREFIX #define NO_INLINE 1 #define _ARCH_PPC 1 #define FLT_MANT_DIG 24 #define VERSION "4.0.1 (Apple Computer, Inc. build 5341)" #define BIG_ENDIAN 1 #define SIZE_TYPE long unsigned int #define FLT_RADIX 2 #define LDBL_EPSILON 4.94065645841246544176568792868221e-324L #define NATURAL_ALIGNMENT 1 #define FLT_HAS_QUIET_NAN 1 #define FLT_MAX_10_EXP 38 #define LONG_MAX 2147483647L #define FLT_HAS_INFINITY 1 #define STDC_VERSION 199901L #define _BIG_ENDIAN 1 #define LDBL_MANT_DIG 106 #define WCHAR_TYPE int #define FLT_DIG 6 #define INT_MAX 2147483647 #define LONG_DOUBLE_128 1 #define FLT_MAX_EXP 128 #define DBL_MANT_DIG 53 #define WINT_TYPE int #define LDBL_MIN_EXP (-968) #define MACH 1 #define LDBL_MAX_10_EXP 308 #define DBL_EPSILON 2.2204460492503131e-16 #define INTMAX_MAX 9223372036854775807LL #define FLT_DENORM_MIN 1.40129846e-45F #define PIC 1 #define FLT_MAX 3.40282347e+38F #define FLT_MIN_10_EXP (-37) #define INTMAX_TYPE long long int #define GNUC_MINOR 0 #define DBL_MAX_10_EXP 308 #define LDBL_DENORM_MIN 4.94065645841246544176568792868221e-324L #define PTRDIFF_TYPE int #define LDBL_MIN_10_EXP (-291) #define LDBL_DIG 31 #define POWERPC 1
- Printer-friendly version
- Login to post comments
- 1753 reads
