-4

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.

va_start

    #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.

Andres
  • 1
  • 1
  • C23 != C++23, `-std=c++23` doesn't make sense. – 273K Aug 28 '23 at 15:55
  • C++: https://en.cppreference.com/w/cpp/utility/variadic/va_start – 273K Aug 28 '23 at 16:01
  • @273K `-std=c++23` does make sense. It is just not the same as `-std=c23`. – user17732522 Aug 28 '23 at 16:22
  • @Andres: Although the website is called cppreference it contains a reference for C++ as well as one for C. You are looking at a page for the C reference, not the C++ one. The C++ version is at https://en.cppreference.com/w/cpp/utility/variadic/va_start and as you can see it doesn't list the change from C23 for any C++ version, not C++23 either. C++ is not a superset of C and not all C features are supported by C++. – user17732522 Aug 28 '23 at 16:23
  • C23 is C, not C++. There is no `va_list` in C++. – Sam Varshavchik Aug 28 '23 at 16:31
  • @SamVarshavchik -- `va_list` is in C++; it comes from ``and from ``. – Pete Becker Aug 28 '23 at 16:36
  • _@Andreas_ Provide a [mcve] of what you're actually doing please! The information you posted is insufficient to reproduce your errors. – πάντα ῥεῖ Aug 28 '23 at 16:41
  • Oh, I did not notice that it was C, thank you. – Andres Aug 28 '23 at 16:47
  • 1
    @πάνταῥεῖ I had added the runnable snippet directly to Godbolt, but I will edit the post so the code is complete. – Andres Aug 28 '23 at 16:48

0 Answers0