我有一个处理静态二维数组的函数,将数组元素视为常数:
void test_function(const char arr[3][3]);
我正在尝试调用以下函数:
char my_var[3][3] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };
test_function(my_var);
使用gcc编译(不带任何标志),我收到以下警告:
test.c:9:8: warning: passing argument 1 of 'test_function' from incompatible pointer type
test_function(my_var);
^
test.c:4:6: note: expected 'const char (*)[3]' but argument is of type 'char (*)[3]'
void test_function(const char arr[3][3]);
如果我从“test_function”的原型中移除“const”,这个警告就会消失。但这并不是我真正想要的。
当使用clang编译时,同时使用“-pedantic-errors”和“-Wall”,我没有收到任何有关指针不兼容的警告。
我只是想了解为什么gcc在这种情况下会输出这样的警告。
为什么我的指针/数组不兼容?
-Werror
编译)。 - nneonneo