liveBook · Manning

Va_arg

As explained in Modern C, Third Edition

va_arg is a C library macro that retrieves the next argument from a va_list using a specified type.

va_arg retrieves the next value from a va_list, but requires the caller to specify its type explicitly. A variadic function initializes the list with va_start, then repeatedly applies va_arg inside a loop. section 17.4.2

Summing variadic double arguments

A function receiving n double values can retrieve each value with va_arg(ap, double), adding it to a running sum on each iteration. The function must receive n separately: va_arg does not reveal the list length. section 17.4.2

void va_start(va_list ap, ...);
void va_end(va_list ap);
\textit{type} va_arg(va_list ap, \textit{type});
void va_copy(va_list dest, va_list src);

The related variadic macros show va_arg alongside va_start, va_end, and va_copy. section 17.4.2

How Modern C, Third Edition covers it

How deep it goes
Explains typed retrieval and length management, but does not descend into va_list implementation internals.
Examples
Uses a variadic function that sums n double values and retrieves each with an explicit double type.
What it assumes
Assumes familiarity with functions and introduces va_list initialization, explicit types, and caller-supplied list length.
What you can do after
Apply via C library macros to retrieve typed arguments from a variadic function.
How it connects
Connects va_arg to variadic functions, va_list, va_start, va_end, and argument-length conventions.

Also explained in

Compare how 2 books explain va_arg →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.