分类:
2008-10-13 16:58:14
1,(C99)
#ifdef DEBUG
#include
#define debug(...) \
do\
{ \
printf("%s#%s(Line %d) ",__FILE__,__FUNCTION__,__LINE__);\
printf(__VA_ARGS__);\
}while(0)
#else
#define debug(x...)
#endif
2,(C99)
#ifdef DEBUG
#include
#define debug(x...) \
do\
{\
printf("%s#%s(Line %d) ",__FILE__,__FUNCTION__,__LINE__);\
printf(x);\
}while(0)
#else
#define debug(x...)
#endif
3,
#include
#include
void user_printf(const char * format,...)
{
va_list arg;
printf("%s#%s(Line %d) ",__FILE__,__FUNCTION__,__LINE__);
va_start(arg,format);
vprintf(format,arg);
va_end(arg);
}
#ifdef DEBUG
#define debug user_printf
#else
#define debug
#endif
注:3有问题,FILE, FUNCTION和LINE返回的是当前函数的结果,C规范中有没有规定获取函数被调用位置的类似结果呢?如果你知道,麻烦告知,谢谢!