void va_start( va_list ap, parmN );
(until C23)void va_start( va_list ap, ... );
(since C23)The va_start
macro enables access to the variable arguments following the named argument parmN
(until C23).
va_start
shall be invoked with an instance to a valid va_list object ap
before any calls to va_arg.
If parmN
is declared with register
storage class specifier, with an array type, with a function type, or with a type not compatible with the type that results from default argument promotions, the behavior is undefined.
Only the first argument passed to va_start
is evaluated. Any additional arguments are neither expanded nor used in any way.
(none)
[edit] Example#include <stdio.h> #include <stdarg.h> int add_nums_C99(int count, ...) { int result = 0; va_list args; va_start(args, count); // count can be omitted since C23 for (int i = 0; i < count; ++i) { result += va_arg(args, int); } va_end(args); return result; } #if __STDC_VERSION__ > 201710L // Same as above, valid since C23 int add_nums_C23(...) { int result = 0; va_list args; va_start(args); int count = va_arg(args, int); for (int i = 0; i < count; ++i) { result += va_arg(args, int); } va_end(args); return result; } #endif int main(void) { printf("%d\n", add_nums_C99(4, 25, 25, 50, 50)); #if __STDC_VERSION__ > 201710L printf("%d\n", add_nums_C23(4, 25, 25, 50, 50)); #endif }
Possible output:
[edit] ReferencesRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4