Is GCC mishandling a pointer to a va_list passed to a function?

后端 未结 4 1410
日久生厌
日久生厌 2020-11-30 08:48

The question \'Pass va_list or pointer to va_list?\' has an answer which quotes the standard (ISO/IEC 9899:1999 - §7.15 \'Variable arguments , f

4条回答
  •  旧时难觅i
    2020-11-30 09:14

    The problem is not specific to va_list. The following code results in a similar warning:

    typedef char *test[1];
    
    void x(test *a)
    {
    }
    
    void y(test o)
    {
        x(&o);
    }
    

    The problem stems from the way C handles function variables that are also arrays, probably due to the fact that arrays are passed as reference and not by value. The type of o is not the same as the type of a local variable of type test, in this case: char *** instead of char *(*)[1].

    Returning to the original issue at hand, the easy way to work around it is to use a container struct:

    struct va_list_wrapper {
        va_list v;
    };
    

    and there would be no typing problems passing a point to it.

提交回复
热议问题