I am trying to use this functionality, specifically the C23 version so I don't need to pass the second parameter.
void va_start( va_list ap, ... ); //(since C23)
When running the provider example on cppreference, and choosing GCC 13.1(C23)
, it works as expected. I installed GCC 13.2 in my machine and I haven't been able to reproduce this.
I also checked the include files that were installed, and the intended implementation is there.
I have tried the compile flags suggested by gnu, -std=c++23
, -std=c++2b
, -std=c++23
, -std=gnu++23
(even the -enable-experimental
) and none of them seems to work. I wonder what is it that I am missing.
#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
}
Running the same snippet from cppreference on godbolt and adding those flags don't seem to work either.