GCC dump preprocessor defines
Is there a way for gcc/g++ to dump its preprocessor defines from the command line?
I mean things like __GNUC__
, __STDC__
, and so on.
Solution 1:
Yes, use -E -dM
options instead of -c.
Example (outputs them to stdout):
gcc -dM -E - < /dev/null
For C++
g++ -dM -E -x c++ - < /dev/null
From the gcc manual:
Instead of the normal output, generate a list of `#define' directives for all the macros defined during the execution of the preprocessor, including predefined macros. This gives you a way of finding out what is predefined in your version of the preprocessor. Assuming you have no file foo.h, the command
touch foo.h; cpp -dM foo.h
will show all the predefined macros.
If you use -dM without the -E option, -dM is interpreted as a synonym for -fdump-rtl-mach.
Solution 2:
I usually do it this way:
$ gcc -dM -E - < /dev/null
Note that some preprocessor defines are dependent on command line options - you can test these by adding the relevant options to the above command line. For example, to see which SSE3/SSE4 options are enabled by default:
$ gcc -dM -E - < /dev/null | grep SSE[34]
#define __SSE3__ 1
#define __SSSE3__ 1
and then compare this when -msse4
is specified:
$ gcc -dM -E -msse4 - < /dev/null | grep SSE[34]
#define __SSE3__ 1
#define __SSE4_1__ 1
#define __SSE4_2__ 1
#define __SSSE3__ 1
Similarly you can see which options differ between two different sets of command line options, e.g. compare preprocessor defines for optimisation levels -O0
(none) and -O3
(full):
$ gcc -dM -E -O0 - < /dev/null > /tmp/O0.txt
$ gcc -dM -E -O3 - < /dev/null > /tmp/O3.txt
$ sdiff -s /tmp/O0.txt /tmp/O3.txt
#define __NO_INLINE__ 1 <
> #define __OPTIMIZE__ 1