Va_start, Synopsis, Example – Zilog ZUSBOPTS User Manual
Page 483

UM017105-0511
Standard Functions
Zilog Developer Studio II – ZNEO™
User Manual
455
Synopsis
#include
void va_end(va_list ap);
Example
The function f1 gathers into an array a list of arguments that are pointers to strings (but not
more than MAXARGS arguments), then passes the array as a single argument to function
f2. The number of pointers is specified by the first argument to f1.
#include
extern void f2(int n, char *array[]);
#define MAXARGS 31
void f1(int n_ptrs,...) {
va_list ap;
char *array[MAXARGS];
int ptr_no = 0;
if (n_ptrs > MAXARGS)
n_ptrs
=
MAXARGS;
va_start(ap, n_ptrs);
while (ptr_no < n_ptrs)
array[ptr_no++] = va_arg(ap, char *);
va_end(ap);
f2(n_ptrs, array);
}
Each call to f1 has in scope the definition of the function of a declaration such as
void
f1(int, ...);
va_start
Is executed before any access to the unnamed arguments.
The parameter
ap
points to an object that has type
va_list
. The parameter
parmN
is the
identifier of the rightmost parameter in the variable parameter list in the function defini-
tion (the one just before the , ...). The
va_start
macro initializes
ap
for subsequent use
by
va_arg
and
va_end
.
Synopsis
#include
void va_start(va_list ap, parmN);