在稍后评估的宏中包含#warning? [复制]
Posted
技术标签:
【中文标题】在稍后评估的宏中包含#warning? [复制]【英文标题】:Include #warning within a macro to be evaluated later? [duplicate] 【发布时间】:2012-01-30 20:43:41 【问题描述】:可能重复:Does there exist a static_warning?
我经常使用分散在我的代码中的#warning 来标记我需要返回的地方。
喜欢:
#warning The blahblah hasn't been implemented yet; use foo to do so.
我想创建一个宏,它可选择不显示与我的笔记特别相关的警告,但显示来自编译器和其他库的实际警告。
类似:
#ifdef SUPPRESS_NOTES
#define BUILD_NOTE
#else
#define BUILD_NOTE #warning Note: msg
#endif
不幸的是,#warning 首先得到评估。有什么办法可以做到这一点?我使用 GCC (MinGW)。
【问题讨论】:
尤其是this answer 【参考方案1】:使用GCC online doc 中的 TODO Makro,这就是你想要的:
#define DO_PRAGMA(x) _Pragma (#x)
#define TODO(x) DO_PRAGMA(message ("TODO - " #x))
#ifdef SUPRESS_NOTES
# define BUILD_NOTE
#else
# define BUILD_NOTE DO_PRAGMA(message ("The blahblah hasn't been implemented " \
"yet; use foo to do so."))
#endif
【讨论】:
谢谢,我不知道如何让它们以正确的顺序解决。以上是关于在稍后评估的宏中包含#warning? [复制]的主要内容,如果未能解决你的问题,请参考以下文章