开发者

Determining value of preprocessor token

How can I tell what the value of the __GNU开发者_运维知识库C__ definition is on my C++ compiler?


You can get all the GCC predefined macros with this:

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

A quick grep will get you what you want.


Use gcc's "preprocess only" mode (-E) (and give it input via STDIN rather than 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're looking for.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜