您的位置:首页 > 其它

Debug宏

2016-01-06 13:39 225 查看
#include <stdio.h>
#include <stdarg.h>

#define DEBUG(args)  printf args

///////////////////////////////

void Dbg(int level, const char *message, ...)
{
va_list l;

if (level < 2)
{
return;
}

va_start(l, message);
vprintf(message, l);
va_end(l);
}

#define DBG(arg) Dbg arg

/////////////////////////////////

void Dbg2(const char *message, ...)
{
va_list l;

va_start(l, message);
vprintf(message, l);
va_end(l);
}

#define DBG2(level, line) \
if (level < 2) {}       \
else Dbg2 line

#define LOGE2(line) DBG2(0, line)

int main(int argc, char **argv)
{
//v1
DEBUG(("a%s\n", "b"));

//v2
Dbg(3, "a%s\n", "b");
DBG((3, "a%s\n", "b"));

//v3
DBG2(3, ("a%s\n", "b"));
LOGE2(("a%s\n", "b"));
return 0;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: