va_start

Header: <cstdarg>

The va_start macro enables access to the variable arguments following the named argument parm_n.

# Declarations

void va_start( std::va_list ap, parm_n );

# Parameters

# Notes

va_start is required to support parm_n with overloaded operator&.

# Example

#include <cstdarg>
#include <iostream>
 
int add_nums(int count...)
{
    int result = 0;
    std::va_list args;
    va_start(args, count);
    for (int i = 0; i < count; ++i)
        result += va_arg(args, int);
    va_end(args);
    return result;
}
 
int main()
{
    std::cout << add_nums(4, 25, 25, 50, 50) << '\n';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
CWG 273C++98it was unclear whether va_start is required tosupport parm_ns with overloaded operator&required
LWG 2099C++98the behavior was undefined if parm_n isdeclared with a function, array, or reference typethe behavior is undefined ifparm_n is of reference type

# See also