다음 코드가 실행되면 gcc 컴파일러가 경고를 표시하고 프로그램이 중단됩니다. 왜 그럴 수 없습니까? 누군가가 그것을 분명히하면 큰 도움이 될 것입니다.가변 인수 형식이 c의 va_arg 함수
#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
왜 k & r book에 언급되어 있지 않습니까? – Dhatri
@vindhya : 나는 잘 모른다. –
충분히 흥미로운 점은'va_arg()'을 가지고있는 컴파일러가'char'를 사용하는 경우'int'를 모을 수 있다는 것입니다. Microsoft Visual Studio 2005는'va_arg()'에 다음과 같이 선언되어 있습니다 :'#define _crt_va_arg (ap, t) (* (t *) (ap + = _INTSIZEOF (t)) - _INTSIZEOF ~define_INTSIZEOF (n) (sizeof (n) + sizeof (int) - 1) & ~ (sizeof (int) - 1))의 추가 매크로 정의' –