본문 바로가기
42seoul

[C/에러] va_arg로 가변 인자 받을 때 고려할 점

by ohojee 2022. 12. 10.
warning: second argument to 'va_arg' is of promotable type 'char'; this va_arg has undefined behavior because arguments will be promoted to 'int' [-Wvarargs]
 
printf 함수를 만들던 중 이러한 경고가 떴다.
 
문제가 있었던 코드는 아래와 같고, va_arg는 char을 받을 수 없고, char을 int로 promote해서 받는다고 한다.
ft_print_char(va_arg(ap, char), &cnt);​

그 외에도 float → double, int → int/unsigned int로 promote한다고 한다.

 

 

참고 블로그

https://stackoverflow.com/questions/28054194/char-type-in-va-arg

 

댓글