在编写代码的时候,不可避免的会出现冗余,导致一段代码重复出现,我们可以利用宏来避免这种情况,虽然不能完全避免,至少冗余的情况会有所改善
一个demo程序
#include <stdio.h>
#define _CHECK_VAL_NOT_ZERO(stmt, fmt, ...) do { \
if((stmt != 0)) { \
printf(fmt, ##__VA_ARGS__); \
} \
} while(0)
int main(){
_CHECK_VAL_NOT_ZERO(i, "i != 0, i = %d\n", i);
return 0;
}
相关的文章:
http://blog.youkuaiyun.com/liufei_learning/article/details/5438481
http://blog.youkuaiyun.com/liufei_learning/article/details/5438493