cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cstdarg
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstdarg (stdarg.h)
macros:
· va_arg
· va_end
· va_start
types::
· va_list

-

cstdarg (stdarg.h) header

Variable arguments handling

This header defines macros to access the individual arguments of a list of unnamed arguments whose number and types are not known to the called function.

A function may accept a varying number of additional arguments without corresponding parameter declarations by including a comma and three dots (,...) after its regular named parameters:

return_type function_name ( parameter_declarations , ... );

To access these additional arguments the macros va_start, va_arg and va_end, declared in this header, can be used:

  • First, va_start initializes the list of variable arguments as ava_list.
  • Subsequent executions of va_arg yield the values of the additional arguments in the same order as passed to the function.
  • Finally, va_end shall be executed before the function returns.

The header, describes one type:

va_list Type to hold information about variable arguments (type)

And three functions:

va_start Initialize a variable argument list (macro)
va_arg Retrieve next argument (macro)
va_end End using variable argument list (macro)

Some implementations of C compilers (such as ISO C99-compliant compilers) also include a va_copy macro to duplicate a va_list object, but this is not part of ISO C++ standard.

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us