Va_arg, va_end, va_start functions, Va_arg, va_end, va_start – Zilog Z80380 User Manual
Page 89
UM004001-COR1103
4–25
Run Time Environment
Library Functions
va_arg, va_end, va_start
FUNCTIONS
Header file statement:
#include
Syntax:
type va_arg
( va_list arg_ptr, type );
void va_end
( va_list arg_ptr );
void va_start
( va_list arg_ptr, prev_param )
The va_arg, va_end, and va_start macros provide a portable way to access the arguments to a
function when the function takes a variable number of arguments. The macros are listed
below:
Macro
Description
va_arg
Macro to retrieve current argument
va_end
Macro to reset arg_ptr
va_list
The typedef for the pointer to list of arguments
va_start
Macro to set arg_ptr to beginning of list of optional arguments
The macros assume that the function takes a fixed number of required arguments, followed
by a variable number of optional arguments. The required arguments are declared as ordinary
parameters to the function and can be accessed through the parameter names. The optional
arguments are accessed through the macros in STDARG.H, which set a pointer to the first
optional argument in the argument list, retrieve arguments from the list, and reset the pointer
when argument processing is completed.
The ANSI C standard macros, defined in STDARG.H, are used as follows:
•
All required arguments to the function are declared as parameters in the usual way.
•
The va_start macro sets arg_ptr to the first optional argument in the list of arguments
passed to the function. The argument arg_ptr must have va_list type. The argument
prev_param is the name of the required parameter immediately preceding the first
optional argument in the argument list. If prev_param is declared with the register
storage class, the macro’s behavior is undefined. The va_start macro must be used
before va_arg is used for the first time.
Parameter
Description
arg_ptr
Pointer to list of arguments
prev_param
Pointer preceding first optional argument
type
Type of argument to be retrieved