B.7 Variable Argument Lists: <stdarg.h>

The header <stdarg.h> provides facilities for stepping through a list of function arguments of unknown number and type.

Suppose lastarg is the last named parameter of a function f with a variable number of arguments. Then declare within f a variable of type va_list that will point to each argument in turn:

ap must be initialized once with the macro va_start before any unnamed argument is accessed:

Thereafter, each execution of the macro va_arg will produce a value that has the type and value of the next unnamed argument, and will also modify ap so the next use of va_arg returns the next argument:

The macro

must be called once after the arguments have been processed but before f is exited.

TCPL/B.07_Variable_Argument_Lists:_<stdarg.h> (last edited 2008-02-23 15:35:12 by localhost)

ch3n2k.com | Copyright (c) 2004-2022 czk.