Anyway to see list of preprocessor defined macros?
Asked Answered
I

2

13

I'd like to see all macros that are defined by the invocation of the compiler I'm using. Is there any way to do this? I have seen in the manual it says you can use cpp -dM but this doesn't work for me. Perhaps I'm doing something wrong?

When I run:

cpp -dM

I get no output at all from the preprocessor. If I try adding -dM as an option on gcc, I don't notice any difference.

Interlace answered 5/6, 2012 at 20:59 Comment(4)
"Doesn't work for me" - please be more descriptive!Larson
On my Linux computer, the output of cpp -dM < /dev/null | wc -l is 124, so there are 124 predefined values. cpp -dM < /dev/null | less shows me what they are. What is the output of those commands on your computer?Blockbuster
Sorry I tried to clear it up a littleInterlace
Rob thank you I'll have to try and figure out how to do that from windows, which unfortunately I am stuck using. I'm using code sourcery cross compiler for arm. (A gcc port essentially)Interlace
U
18

You can use:

gcc -dM -E - < /dev/null

Note that you can also get the compiler macros in addition with this command:

touch bla.c && gcc -dM -E bla.c

For example on my computer:

$ touch bla.c && gcc -dM -E bla.c | wc -l
486
$ gcc -dM -E - < /dev/null | wc -l
124
$
Unclothe answered 5/6, 2012 at 21:9 Comment(3)
also useful are -xc, -xc++ and -std=... so you can compare language and dialect-specific definitionsHunter
@Hunter actually I tried first gcc -xc -dM -E - < /dev/null for my second example, but this does not seem to work with -dM (same result as in the first example)Unclothe
@Hunter ok so it has been fixed because it doesn't on my gcc-4.4.3/LinuxUnclothe
A
5

By default, cpp -dM will read its input file from standard input and write to standard output. Since you're not trying to preprocess any input, you can pass it the empty input using /dev/null:

# Option 1
cpp -dM < /dev/null
# Optio n2
cpp -dM /dev/null

On Windows, you can use the NUL pseudofile instead of /dev/null.

Atombomb answered 5/6, 2012 at 21:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.