HP C/iX Library Reference Manual (30026-90004)

380 Chapter5
HP C/iX Library Function Descriptions
va_arg
va_arg
Initializes a variable to the beginning of an argument list.
Syntax
#include <stdarg.h>
type va_arg (va_list
ap
,
type
);
Parameters
ap
A pointer to a double, as defined by type va_list in <varargs.h>. This
variable must be initialized with the macro va_start.
type
A data type, either built-in or user-defined.
Return Values
x The value of the next argument in the call, returned as a variable of type
type
.
Description
This macro returns the value of the next argument in the argument list of functions that
can be called with a variable number of arguments.
The macros va_start, va_arg, and va_end determine the arguments of functions with
variable-length argument lists. Functions with variable-length argument lists are
indicated by the ellipsis in the function header.
Successive invocations of va_arg return the values of the remaining arguments in
succession. The ap argument is used by the macro to maintain the context of each
successive call. This argument must be initialized by a call to va_start prior to calling
va_arg.
The macro assumes that the return value is of type
type
. No error checking is performed.
If there is no next argument when va_arg is called , or if
type
is not compatible with the
type of the actual next argument, the value returned is unpredictable.
When writing functions with a variable number of arguments, you should provide a
method for the calling procedure to either pass the number of actual arguments, or signal
the end of the argument list. In addition, the calling program and function being called
must cooperate closely as to the data types of the items in the variable argument list.
NOTE
The header <varargs.h> also contains this macro. However, <varargs.h>
header is not defined by the ANSI C standard.