Strange warning in a C function const multidimensional-array argument

前端 未结 6 1872
长发绾君心
长发绾君心 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:25

    To practically solve this, one could use a struct, and the change of double[4][4] into the a-bit-awkward double (*)[4] is avoided, and constness also works intuitively — while the same amount of memory is used:

    struct mat4 {
            double m[4][4];
    };
    
    void myfunc(struct mat4 *r, const struct mat4 *a, const struct mat4 *b)
    {
    }
    
    int main(void)
    {
            struct mat4 mr, ma, mb;
            myfunc(&mr, &ma, &mb);
    }
    

提交回复
热议问题