Defined in header <stdarg.h> | ||
void va_start( va_list ap, parmN); | (until C23) | |
void va_start( va_list ap, ...); | (since C23) | |
Theva_start macro enables access to the variable arguments following the named argumentparmN(until C23).
va_start shall be invoked with an instance to a validva_list objectap before any calls tova_arg.
If | (until C23) |
Only the first argument passed to | (since C23) |
Contents |
| ap | - | an instance of theva_list type |
| parmN | - | the named parameter preceding the first variable parameter |
(none)
#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 C23int 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__ > 201710Lprintf("%d\n", add_nums_C23(4,25,25,50,50));#endif}
Possible output:
150150
| accesses the next variadic function argument (function macro)[edit] | |
(C99) | makes a copy of the variadic function arguments (function macro)[edit] |
| ends traversal of the variadic function arguments (function macro)[edit] | |
| holds the information needed byva_start,va_arg,va_end, andva_copy (typedef)[edit] | |
C++ documentation forva_start | |