How to write safe and user friendly c/c++ #define macros

孤者浪人 提交于 2019-12-05 16:42:43

A common approach when you want your macro to do nothing, and toggle this behavior with the preprocessor, is to use the void(0) operation.

#if SOMETHINGS
#define macro(x)    do{                      \
                        ... some code line ; \
                        ... some code line ; \
                    }while(0)
#else
#define macro(x) ((void)(0))
#endif

This way you won't break compilation whenever nulling out macro operations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!