是否有可能在编译时检测到vsnprintf()的第四个参数少于vsnprintf()的第三个参数所要求的?我的意思是:
#include <stdio.h>
#include <stdarg.h>
void foo(const char* format, ...)
{
char buffer[256];
va_list args;
va_start (args, format);
vsnprintf(buffer, 256, format, args); // args may points to fewer arguments than expected in the format
va_end (args);
}
int main ()
{
foo("%d %d", 1); // the format requires two arguments, but only one is provided, so a warning from the compiler is expected here
return 0;
}
gcc -Wall main.c
编译上述代码而不发出警告
为foo
应用属性
__attribute__((__format__(__printf__, 1, 2)))
void foo(const char* format, ...) {
用-Werror=format
编译