Standard C++ Library Reference ISO/IEC (VERSION3)

Next
<stdarg.h>
Include the standard header <stdarg.h> to access the unnamed additional arguments
(arguments with no corresponding parameter declarations) in a function that accepts a varying
number of arguments. To access the additional arguments:
The program must first execute the macro va_start within the body of the function to
initialize an object with context information.
Subsequent execution of the macro va_arg, designating the same context information,
yields the values of the additional arguments in order, beginning with the first unnamed
argument. You can execute the macro va_arg from any function that can access the
context information saved by the macro va_start.
If you have executed the macro va_start in a function, you must execute the macro
va_end in the same function, designating the same context information, before the
function returns.
You can repeat this sequence (as needed) to access the arguments as often as you want.
You declare an object of type va_list to store context information. va_list can be either
an array type or a non-array type. Whether or not va_list is an array type affects how the
program shares context information with functions that it calls. The address of the first element
of an array is passed, rather than the object itself. So an array type is effectively passed by
reference, while a non-array type is passed by value.
For example:
#include <stdarg.h>
void va_cat(char *s, ...)
{
char *t;
va_list ap;
va_start(ap, s);
while (t = va_arg(ap, char *)) null pointer ends list
{
s += strlen(s); skip to end
strcpy(s, t); and copy a string
}
va_end(ap);
}
The function va_cat concatenates an arbitrary number of strings onto the end of an existing