#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>/*包含va_list 和va_start _va_end的头文件*/
int debug = 1;/*定义全局变量作为打印开关*/
void debug_print(const char *fmt,...)/*...的前面必须是char型的指针变量*/
{
if(debug)
{
va_list valist;/*c语言中可变参数的宏*/
char buff[512] = {0};
va_start(valist,fmt);
vsprintf(buff,fmt,valist);/*vsprintf(char *string,char *fmt,va_list parm)*/
va_end(valist);
printf("%s",buff);
}
return;
}
void main()
{
debug_print("%s->%d\n",__FUNCTION__,__LINE__);
debug_print("%s->%d%d\n",__FUNCTION__,__LINE__,__LINE__);
debug_print(" 1--------liqiang---------%s->%d i:%d\n",__FUNCTION__,__LINE__,10);
}