Guardian Native C Library Calls Reference Manual (G06.28+, H06.04+)

va_start(3) Guardian Native C Library Calls Ref
erence Manual
NAME
va_start - Initializes processing for a variable-length parameter list
LIBRARY
None. This application program interface is implemented as a macro.
SYNOPSIS
#include <stdarg.h>
void va_start(
va_list ap,
parmn);
PARAMETERS
ap This parameter is used to extract parameters from the parameter list.
parmn The identier of the rightmost named parameter in the function declaration for
the function that has a variable-length parameter list.
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_start initializes ap to the parameter following parmn.
NOTES
The parmn parameter should not be declared with the register storage class, with a function or
array type, or with a type that is not compatible with the type that results after application of the
default parameter promotions.
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 specied by the rst 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);
}
740 Hewlett-Packard Company 527192-005