如何显示在GCC编译时的#define的值 [英] How do I show the value of a #define at compile time in gcc
本文介绍了如何显示在GCC编译时的#define的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,我已经得到尽可能:
So far I've got as far as:
#define ADEFINE "23"
#pragma message ("ADEFINE" ADEFINE)
其中一期工程,但如果ADEFINE是不是一个字符串?
Which works, but what if ADEFINE isn't a string?
#define ADEFINE 23
#pragma message ("ADEFINE" ADEFINE)
原因:
警告:畸形的#pragma消息,忽视
warning: malformed ‘#pragma message’, ignored
在理想情况下,我想能够应付任何价值,包括不确定的。
Ideally I'd like to be able to deal with any value, including undefined.
推荐答案
要显示宏这不是字符串,字符串化宏:
To display macros which aren't strings, stringify the macro:
#define STRINGIFY(s) XSTRINGIFY(s)
#define XSTRINGIFY(s) #s
#define ADEFINE 23
#pragma message ("ADEFINE=" STRINGIFY(ADEFINE))
如果您有/想提振,则可以使用的提振stringize 来为你做它:
If you have/want boost, you can use boost stringize to do it for you:
#include <boost/preprocessor/stringize.hpp>
#define ADEFINE 23
#pragma message ("ADEFINE=" BOOST_PP_STRINGIZE(ADEFINE))
这篇关于如何显示在GCC编译时的#define的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文