This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>.
All rights reserved.
Released under the GNU General Public License.
va_arg
Prototype
#include <stdarg.h>
type va_arg(va_list ap, type);
Description
The va_arg
macro gets the next argument,
of type type, from the variable argument list ap
.
The ap
variable is modified so that the next call returns the next
argument.
The ap
parameter should be previously initialized
with va_start
and the type parameter should be of the
same type as the user passed argument (or at least of the same size).
Example
#include <stdarg.h>
#include <stdio.h>
/*
* Sum the argument integers.
* For example:
* sum_args(4, 5, 3, 2, 1);
* Returns:
* 11
*/
int sum_args(int num_args, ...)
{
va_list ap;
int sum = 0;
va_start(ap, num_args);
while (num_args--)
sum += va_arg(ap, int);
va_end(ap);
return sum;
}
References
ISO C 9899:1990 7.8.1.2