Strange warning in a C function const multidimensional-array argument

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

    Compiler is just being anal.

    You're passing an argument that is essentially a non-const pointer, and the function is declared to accept a const pointer as an argument. These two are, in fact, incompatible. It is not a real problem because the compiler is still supposed to work as long as you can assign the value of the first type to the variable of the second type. Hence a warning but not an error.

    EDIT: looks like gcc does not complain about other con-const to const conversions, e.g. passing char* where a const char* is expected. In this case, I'm inclined to agree that Joseph Myers from Bugzilla is correct.

提交回复
热议问题