How to fix C error ‘unknown type name va_list’

Problem:

You have C code like

va_list ap;
int mode = va_arg(ap, int);

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

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

Solution:

Add

#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.