#include <stdio.h>
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int dprintf(int fd, const char *format, ...);
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);
#include <stdarg.h>
int vprintf(const char *format, va_list ap);
int vfprintf(FILE *stream, const char *format, va_list ap);
int vdprintf(int fd, const char *format, va_list ap);
int vsprintf(char *str, const char *format, va_list ap);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
例子:
__attribute__((format(printf, 3, 4)))
int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vsnprintf(nwlog + strlen(nwlog), NWLEN - strlen(nwlog) - 1, fmt, args); //正确
//snprintf(nwlog + strlen(nwlog), NWLEN - strlen(nwlog) - 1, fmt, args); //错误!
va_end(args);
return ret;
}
标签:va,经验,const,format,int,char,参数,nwlog,长度 From: https://www.cnblogs.com/huangguanyuan/p/17772265.html