#include "../common.h"
#define my_printf_a(level,__format__,...) \
my_printf(level,__format__"<%s %d %s>", ##__VA_ARGS__,__FILE__,__LINE__, __FUNCTION__);
int my_printf(int level,const char*format,...)
{
va_list ap_list;
char ap_buf[200]={0};
va_start(ap_list,format);
vsprintf(ap_buf,format,ap_list);
printf("[%d](%s)\n",level,ap_buf);
}
int main()
{
my_printf_a(1,"%s %d","abcde",7);
my_printf_a(3,"%d %s",9,"xyz");
}
##__VA_ARGS__获取被宏定义的不定参数
__FILE__,__LINE__, __FUNCTION__分别获取代码所在的文件,行和函数
宏定义printf例子:
#include "../common.h"
#define TRACE_CMH(__format__, ...) \
printf(__format__ "%s(%d)-<%s>: " "\n", ##__VA_ARGS__,__FILE__, __LINE__, __FUNCTION__)
int main()
{
TRACE_CMH("%s :%d\n","aaaa",999);
}