C语言中的调试宏

来源:互联网 发布:茶道入门软件 编辑:程序博客网 时间:2024/06/06 15:43
#ifdef DEBUG#define debug_printf(fmt, ...) printf(fmt, ##__VA_ARGS__)#else#define debug_printf(fmt, ...) #endif

其中##在没有参数的时候去掉前面的","号,否则在没有参数的时候,编译会报错。

#include <stdio.h>#ifdef DEBUG#define debug_printf(fmt, ...) printf(fmt, ##__VA_ARGS__)#else#define debug_printf(fmt, ...) #endifint main(int argc, char *argv[]){char* arr = "liuwei";int a = 3;debug_printf("hello, %d, %s\n", a, arr);}


0 0
原创粉丝点击