Anyway to see list of preprocessor defined macros?

巧了我就是萌 提交于 2019-12-12 08:26:55

问题


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.


回答1:


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
$



回答2:


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.



来源:https://stackoverflow.com/questions/10904873/anyway-to-see-list-of-preprocessor-defined-macros

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!