va_arg macro i
s used to retrieve next argument
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.
type va_arg ( va_list ap, type )
- 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.
- 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.
Returns the next additional argument as an expression of type type
/* va_arg example */
int FindMax ( int amount, ...)
int main ()
m= FindMax (7,702,422,631,834,892,104,772);
printf ("The greatest one is: %d\n",m);
function takes as its first parameter the
amount of additional arguments it is going to get. The first additional
argument is retrieved and used as an initial reference for comparison,
and then the remaining additional arguments are retrieved in a loop and
compared to return the greatest one (which in this case is 892