How to fix C error 'unknown type name va_list'

Problem:

You have C code like

main.c
va_list ap;
int mode = va_arg(ap, int);

but when you try to compile it you see a warning message like

error_message.txt
main.c: In function ‘main’:
main.c:4:2: error: unknown type name ‘va_list’
  va_list ap;
  ^~~~~~~

Solution

Add

stdarg_include.c
#include <stdarg.h>

at the top of the source file where the error occured. This will include the definitions for va_list and the va_arg function.


Check out similar posts by category: C/C++, GCC Errors