自定义debug函数

简单的DEBUG宏

/********************** debug.h *************************/
#ifndef  _DEBUG_H_
#define  _DEBUG_H_

#define DEBUG
#ifdef DEBUG
//#define  TOY_DEBUG(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
#define  TOY_DEBUG(format, ...) printf (format, ## __VA_ARGS__)
#else
#define  TOY_DEBUG(format, ...)
#endif

#endif //_DEBUG_H_

/********************main.c*****************************/
int main (void) {         debug_printf("hello\n");         debug_printf("hello, %d\n", 10);
        return 0; }
/* 定义级别的DEBUG函数
*/
#include <stdio.h> #include <stdlib.h> #ifdef MY_DEBUG #include <stdarg.h> int debug_level; void debug(int level, const char *fmt, ...) { if( level <= debug_level ) { va_list ap; va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); } } #else void debug(int level, const char *fmt, ...) { } #endif
原文地址:https://www.cnblogs.com/cfox/p/2751054.html