“#ifdef”在宏内部
可能的重复:
#define 内的#ifdef
如何在宏中成功使用字符“#”?当我做类似的事情时它会尖叫:
#define DO(WHAT) \
#ifdef DEBUG \
MyObj->WHAT() \
#endif \
Possible Duplicate:
#ifdef inside #define
How do I use the character "#" successfully inside a Macro? It screams when I do something like that:
#define DO(WHAT) \
#ifdef DEBUG \
MyObj->WHAT() \
#endif \
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你不能那样做。你必须这样做:
do { } while(0)
避免空语句。例如,请参阅此问题 。You can't do that. You have to do something like this:
The
do { } while(0)
avoids empty statements. See this question, for example.它尖叫是因为你不能这样做。
我建议采用以下替代方案:
It screams because you can't do that.
I suggest the following as an alternative:
看来您想要做的事情可以这样实现,而不会遇到任何问题:
顺便说一句,最好使用 NDEBUG 宏,除非您有更具体的理由不这样做。
NDEBUG
更广泛地用作表示不调试的宏。例如,可以禁用标准assert
宏通过定义NDEBUG。你的代码将变成:It seems that what you want to do can be achieved like this, without running into any problems:
Btw, better use the
NDEBUG
macro, unless you have a more specific reason not to.NDEBUG
is more widely used as a macro that means no-debugging. For example the standardassert
macro can be disabled by definingNDEBUG
. Your code would become:你可以像这样做同样的事情:
You can do the same thing like this:
怎么样:
How about: