Strange warning in a C function const multidimensional-array argument

前端 未结 6 1871
长发绾君心
长发绾君心 2020-11-29 11:43

I\'m getting some strange warnings about this code:

typedef double mat4[4][4];

void mprod4(mat4 r, const mat4 a, const mat4 b)
{
/* yes, function is empty *         


        
6条回答
  •  北海茫月
    2020-11-29 12:07

    I think in C99, you can do this, but I'm not sure it will help:

    void mprod4(double mr[4][4], double ma[const 4][const 4], double mb[const 4][const 4])
    {
    
    }
    

    I haven't got a C99 compiler handy but I remember reading something in the C99 specification regarding qualifiers within the [] for arrays as arguments. You can also put static in there (e.g. ma[static 4]) but of course that means something else.

    Edit

    Here it is, section 6.7.3.5 paragraph 7.

    A declaration of a parameter as “array of type” shall be adjusted to “qualified pointer to type”, where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. If the keyword static also appears within the [ and ] of the array type derivation, then for each call to the function, the value of the corresponding actual argument shall provide access to the first element of an array with at least as many elements as specified by the size expression.

提交回复
热议问题