va_list: Type to hold information about variable arguments
This type is used as a parameter for the macros defined in cstdarg to retrieve the additional arguments of a function.
Each compiler may implement this type in its own way. It is only intended to be used as the type for the object used as first argument for the va_start, va_arg and va_end macros.
va_start is in charge of initializing an object of this type, so that subsequent calls to va_arg with it retrieve the additional arguments passed to the function.
Before a function that has initialized a va_list object with va_start returns, the va_end shall be executed.
va_start: Initialize a variable argument list
void va_start ( va_list ap, paramN );
Initializes the object of type va_list passed as argument ap to hold the information needed to retrieve the additional arguments after parameter paramN with function va_arg.
A function that executes va_start, shall also execute va_end before it returns.
Parameters
ap
Object of type va_list that will hold the information needed to retrieve the additional arguments with va_arg.
paramN
Parameter name of the last named parameter in the function definition.
va_arg: Retrieve next argument
type va_arg ( va_list ap, type );
This macro expands to an expression that has the type type and the value of the next argument in the variable arguments list.
The next call to this macro will expand to the following argument in the same order as passed to the function.
Notice that va_arg cannot determine the actual type of the argument passed to the function, but uses whatever type is passed as the type macro argument as its type.
Notice also that va_arg does not determine either whether the retrieved argument is the last argument passed to the function (or even if it is an element past the end of that list). The function should be designed in such a way that the amount of parameters can be inferred in some way by the values of either the named parameters or the additional arguments already read.
Parameters
ap
Object of type va_list with information about the additional arguments an their retrieval state. This object shall have been initialized by an initial call to va_start before the first call to va_arg.
type
A type name. This type name is used as the type of the expression this macro expands to (i.e., its return type).
For a type expression to be suitable for its use with va_arg it must be such that when an asterisk (*) would be appended to its right the resulting expression would be a valid pointer type to a type object.
Return Value
Returns the next additional argument as an expression of type type.
va_end: End using variable argument list
void va_end ( va_list ap );
Performs the appropiate actions to facilitate a normal return by a function that has used the va_list object ap to retrieve its additional arguments.
This macro should be executed before the function returns whenever va_start has been previously used in that function.
Parameters
ap
va_list object previously initialized by va_start in the same function.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment