1 .\" @(#)varargs.3 6.3 (Berkeley) 5/15/86
3 .TH STDARG 3 "May 15, 1986"
6 stdarg \- variable argument list
12 void va_start(va_list \fIap\fP, \fIargtypeN\fP \fIparmN\fP)
13 \fItype\fP va_arg(va_list \fIap\fP, \fItype\fP)
14 void va_end(va_list \fIap\fP)
18 This set of macros provides a means of writing portable procedures that
19 accept variable argument lists.
20 Routines having variable argument lists (such as
24 are inherently nonportable, since different
25 machines use different argument passing conventions.
27 A function that accepts a variable argument list is declared with "..." at
28 the end of its parameter list. It must have at least one normal argument
29 before the "...". For example:
33 int printf(const char *format, ...) { /* code */ }
34 int fprintf(FILE *stream, const char *format, ...) { /* code */ }
39 is a type which is used for the variable
41 within the body of a variable argument function which is used to traverse
47 is called to initialize
49 to the beginning of the list. The last true parameter of the function,
51 must be supplied to allow
53 to compute the address of the first variable parameter.
58 will return the next argument in the list pointed to by
61 is the type to which the expected argument will be converted
62 when passed as an argument.
64 Different types can be mixed, but it is up
65 to the routine to know what type of argument is
66 expected, since it cannot be determined at runtime.
70 must be used to finish up.
72 Multiple traversals, each bracketed by
80 \fB#include\fP <stdarg.h>
82 execl(\fBconst char\fP *path, \fB...\fP)
85 \fBchar\fP *args[100];
88 \fBva_start\fP(ap, path);
89 \fBwhile\fP ((args[argno++] = \fBva_arg\fP(ap, \fBchar\fP *)) != NULL) {}
91 \fBreturn\fP execv(path, args);
96 It is up to the calling routine to determine how many arguments
97 there are, since it is not possible to determine this from the
98 stack frame. For example,
100 passes a null pointer to signal the end of the list.
102 can tell how many arguments are supposed to be there by the format.
108 may be arbitrarily complex;
111 might contain an opening brace,
112 which is closed by a matching brace in
114 Thus, they should only be used where they could
115 be placed within a single complex statement.
117 It is impossible to properly show the macros as C declarations as is
118 done in the synopsis. They can never be coded as C functions, because
119 all three macros use their arguments by address, and the
121 field is certainly impossible.
122 Just look at them as being part of the C language, like