c – 在功能之外吞下分号的宏

有没有一个成语在功能之外的cpp宏之后强制分号?

函数内部使用的宏的已知解决方案是:

#define MACRO(x) \
  do {
    x * 2;
  } while(0)

不过说我有一个如下所示的宏:

#define DETAIL(warning) _Pragma(#warning)
#define WARNING_disABLE(warning) DETAIL(GCC diagnostic ignore warning)

我可以把那个强制在分析结束之后的分号放在宏中.该声明可以在函数中或外部使用:

WARNING_disABLE("-Wunused-local-typedefs")
#include "boost/filesystem.hpp"
void foo(const int x) {
    WARNING_disABLE("-Wsome-warning")
    ...
}

是否有任何C/C++语法将强制分析器中的分号在文件中的任何一点没有副作用?

编辑:可能的用例:

#define MY_CPPUNIT_TEST_SUITE(test_suite_class) \
  WARNING_PUSH \
  /* the declaration of the copy assignment operator has been suppressed */ \
  INTEL_WARNING_disABLE(2268) \
  /* the declaration of the copy assignment operator has been suppressed */ \
  INTEL_WARNING_disABLE(2270) \
  /* the declaration of the copy constructor operator has been suppressed */ \
  INTEL_WARNING_disABLE(2273) \
  CPPUNIT_TEST_SUITE(test_suite_class); \
  WARNING_POP \
  /* force a semi-colon */ \
  UDP_KEYSTONE_DLL_LOCAL struct __udp_keystone_cppunit_test_suite ## __LINE__ {}

解决方法

#define DETAIL(warning) _Pragma(#warning) struct X ## __LINE__ {}

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...