Everything
7.4.10 <stdarg.h>

Enables referencing of variable arguments for functions with such arguments.
The following macros are implementation-defined.

Type

Definition Name

Description

Type

(macro)

va_list

Indicates the types of variables used in common by the va_start, va_arg, and va_end macros in order to reference variable arguments.

Function

(macro)

va_start

Executes initialization processing for performing variable argument referencing.

va_arg

Enables referencing of the argument following the argument currently being referenced for a function with variable arguments.

va_end

Terminates referencing of the arguments of a function with variable arguments.

va_copy <-lang=c99>

Copies variable arguments.

 

An example of a program using the macros defined by this standard include file is shown below.

[Format]

  1   #include <stdio.h>
  2   #include <stdarg.h>
  3
  4   extern void prlist(int count, ...);
  5
  6   void main( )
  7   {
  8       prlist(1, 1);
  9       prlist(3, 4, 5, 6);
 10       prlist(5, 1, 2, 3, 4, 5);
 11   }
 12
 13   void prlist(int count, ...)
 14   {
 15       va_list ap;
 16       int i;
 17
 18       va_start(ap, count);
 19       for(i=0; i<count; i++)
 20           printf("%d", va_arg(ap, int));
 21       putchar('\n');
 22       va_end(ap);
 23  }

 

Explanation:

This example implements function prlist, in which the number of data items to be output is specified in the first argument and that number of subsequent arguments are output.

In line 18, the variable argument reference is initialized by va_start. Each time an argument is output, the next argument is referenced by the va_arg macro (line 20). In the va_arg macro, the type name of the argument (in this case, int type) is specified in the second argument.

When argument referencing ends, the va_end macro is called (line 22).