Determining the value of the preprocessor token

How can I determine that the definition value __GNUC__belongs to my C ++ compiler?

+3
source share
3 answers

You can get all the predefined GCC macros with this:

g++ -dM -E - < /dev/null

A quick grep will give you what you want.

+7
source

Use gccthe "preprocess only" mode ( -E) (and give it input via STDIN, not a file for convenience):

[tomalak@renee ~]$ echo "__GNUC__" | g++ -E -
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
4

I'm not sure what the first four lines of output are, but the final line is what you are looking for.

+3
source

This works for any macro:

echo "int main() {}" | gcc -xc++ -ggdb3 -
readelf --debug-dump=macro a.out | grep MACRO_YOU_ARE_LOOKING_FOR

or

dwarfdump -m a.out | grep MACRO_YOU_ARE_LOOKING_FOR
+1
source

All Articles