I have a function taking a static two-dimensional array and treating the elements of the elements of the array as being constant:
void test_function(const char arr[3][3]);
I am trying to call such a function as follows:
char my_var[3][3] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };
test_function(my_var);
When compiling with gcc (without any flag), I get the following warning:
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]);
If I remove the const
from test_function
's prototype, the warning goes away. But it is not really what I want.
When compiling with clang with both -pedantic-errors
and -Wall
I don't get any warning about pointer incompatibility.
I just would like to understand why gcc outputs such a warning in this case.
Why would my pointers/arrays be incompatible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…