considerare:Tipo incompatibile con se stesso in GCC 5 quando si utilizza -Wwrite-stringhe
char f(const char (*x)[4]);
void foo(void) {
typeof(*"FOO") x[4];
f(&x);
}
Compilare con -Wwrite-strings
:
gcc-5 -c gcc5.c -Wwrite-strings
Si ottiene:
gcc5.c: In function ‘foo’:
gcc5.c:5:7: warning: passing argument 1 of ‘f’ from incompatible pointer type [-Wincompatible-pointer-types]
f(&x);
^
gcc5.c:1:6: note: expected ‘const char (*)[4]’
but argument is of type ‘const char (*)[4]’
char f(const char (*x)[4]);
^
Sembra un insetto in gcc, a meno che mi manchi qualcosa?
Nota: -Wwrite-strings
cambia il tipo di stringhe letterali:
Quando si compila C, dare costanti stringa del tipo "const char [lunghezza]"
In C, il tipo di "*" FOO "' è 'char'. '-Wwrite-stringhe 'dovrebbe cambiare questo (rendendo il compilatore non standard)?Se non lo è, il bug mostra il tipo di '& x' come' const char (*) [4] ': non c'è' const'. –
Sembra un insetto. Prendi in considerazione la possibilità di presentare una segnalazione di bug. – fuz
@PascalCuoq: Anche così, un 'char (*) [4]' è convertibile in 'const char (*) [4]' corretto? Perché dovrebbe essere un "tipo di puntatore incompatibile"? –