va_arg(), va_end(), and va_start()

Syntax
#include <stdarg.h>
void va_start(va_list args, param);
type va_arg(va_list args, type);
void va_end(va_list args);
Description

These macros can be used to get the parameters into an open parameter list. Calls to va_arg() get a parameter of the given type. The following listing shows how to do it:

Listing: Calling an open-parameter function


void my_func(char *s, ...) {
  va_list args;

  int     i;

  char    *q;

  va_start(args, s);

  /* First call to 'va_arg' gets the first arg. */

  i = va_arg (args, int);

  /* Second call gets the second argument. */

  q = va_arg(args, char *);

  ...

  va_end (args);

}