在宏中包含#warning以便稍后评估?

时间:2012-01-30 20:43:42

标签: c++ macros

  

可能重复:
  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)。

1 个答案:

答案 0 :(得分:5)

使用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