我收到 gcc 编译器的警告,如果执行以下代码,程序将中止我不明白为什么?如果有人澄清它会很有帮助。
#include<stdio.h>
#include<stdarg.h>
int f(char c,...);
int main()
{
char c=97,d=98;
f(c,d);
return 0;
}
int f(char c,...)
{
va_list li;
va_start(li,c);
char d=va_arg(li,char);
printf("%c\n",d);
va_end(li);
}
GCC 告诉我这个:
warning: 'char’ is promoted to ‘int’ when passed through ‘...’ [enabled by default]
note: (so you should pass ‘int’ not ‘char’ to ‘va_arg’)
note: if this code is reached, the program will abort