Enables referencing of variable arguments for functions with such arguments.
The following macros are implementation-defined.
Indicates the types of variables used in common by the va_start, va_arg, and va_end macros in order to reference variable arguments. |
||
Executes initialization processing for performing variable argument referencing. |
||
Enables referencing of the argument following the argument currently being referenced for a function with variable arguments. |
||
Terminates referencing of the arguments of a function with variable arguments. |
||
va_copy <-lang=c99> |
An example of a program using the macros defined by this standard include file is shown below.
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 }
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).