有没有一个成语在功能之外的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__ {}
原文地址:https://www.jb51.cc/c/113334.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。