Reading arguments from a variadic function
double sumIt(size_t n, ...) { double ret = 0.0; va_list va; va_start(va, n); for (size_t i = 0; i < n; ++i) ret += va_arg(va, double); va_end(va); return ret; } Each loop iteration retrieves the next variadic argument as a double. The function supplies the count separately; va_arg does not discover the list length or its end. section 16.5.2
va_arg is a function-like macro from stdarg.h. It receives a va_list and an explicit type, returns the next argument with that type, and advances the argument-list state. section 16.5.2
TAKEAWAY
- Match the requested type to the arguments supplied by the caller; argument-type encoding and end detection remain the programmer’s responsibility. section 16.5.2
- Initialize the va_list with va_start using the last named parameter, retrieve values with va_arg, and finish with va_end. section 16.5.2

