有没有一个成语在功能之外的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__ {}