1. 直接打印调试
#ifndef _DEBUG
#define dbgprint(X) printf( #X "=%d/n",(X))
#else
#define dbgprint(X)
#endif
int main(int argc, char* argv[])
{
dbgprint(argc);
return 0;
}
2. 打印调试、日志打印(gcc下支持,vc6不支持,vc8支持可变参数宏)
#define DEBUG
#define LOG_FILE __FILE__".log"
#ifdef DEBUG
#define dbgprint(format,args...) fprintf(stderr, format, ##args)
#define logprint(format,args...) {FILE* fp=fopen(LOG_FILE,"a+");fprintf(fp,"line %d: "format,__LINE__,##args);fclose(fp);}
#else
#define dbgprint(format,args...)
#define logprint(format,args...)
#endif
#define LOG_FILE __FILE__".log"
#ifdef DEBUG
#define dbgprint(format,args...) fprintf(stderr, format, ##args)
#define logprint(format,args...) {FILE* fp=fopen(LOG_FILE,"a+");fprintf(fp,"line %d: "format,__LINE__,##args);fclose(fp);}
#else
#define dbgprint(format,args...)
#define logprint(format,args...)
#endif
3. vfprintf
void _db_print(const char *format,...)
{
va_list args;
va_start(args, format);
vfprintf(stderr,format, args);
va_end(args);
}
{
va_list args;
va_start(args, format);
vfprintf(stderr,format, args);
va_end(args);
}