Ho una funzione di prendere una statica matrice bidimensionale e trattare gli elementi degli elementi della matrice come costante:tipi di puntatore non compatibili e constness
void test_function(const char arr[3][3]);
Sto cercando di chiamare una funzione come segue :
char my_var[3][3] = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0} };
test_function(my_var);
Quando si compila con GCC (senza bandiera), ottengo il seguente avvertimento:
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]);
Se rimuovo il prototipodal prototipo test_function
, l'avviso scompare. Ma non è proprio quello che voglio.
Durante la compilazione con clang con sia -pedantic-errors
e -Wall
Non ricevo alcun avviso sull'incompatibilità del puntatore.
Vorrei solo capire perché gcc emette un avviso di questo tipo in questo caso. Perché i miei indicatori/array potrebbero essere incompatibili?
Voglio dire che questo è un bug di GCC - il fatto che Clang non produca alcuna diagnosi mi rende piuttosto sospetto. A proposito, dovresti notare che in realtà è un avvertimento, non un errore (sembra che tu stia compilando con '-Werror'). – nneonneo