Guardian Native C Library Calls Reference Manual (G06.28+, H06.05+)
va_arg(3) Guardian Native C Library Calls Ref
erence Manual
NAME
va_arg - Returns a parameter from a variable-length parameter list
LIBRARY
None. This application program interface is implemented as a macro.
SYNOPSIS
#include <stdarg.h>
type va_arg(
va_list ap,
type);
PARAMETERS
ap This parameter is used to extract parameters from the parameter list.
type A type name, expressed so that a pointer to an object of this type can be gen-
erated by appending an * (asterisk).
DESCRIPTION
The stdarg macros allow you to write portable functions that accept a variable number of param-
eters. Subroutines that have variable-length parameter lists but do not use these macros are not
portable because different systems use different parameter-passing conventions.
va_arg() expands to an expression that has the type and value of the next parameter in the list.
The first invocation of va_arg( ) after the invocation of va_start() returns the parameter immedi-
ately following the parmn specified in the va_start() call, the next invocation returns the next
parameter, and so on.
EXAMPLES
The following example uses the stdarg macros to copy a variable-length parameter list that con-
sists of pointers to strings into an array, then passes the array and the number of pointers in it to
the function f2. The number of pointers is specified by the first argument to f1.
#include <stdarg.h>
#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);
}
RELATED INFORMATION
Functions: va_start(3), va_end(3), vfprintf(3).
7−42 Hewlett-Packard Company 527192-007