我有一些代码在GCC 4.8.4下编译得很好.我最近升级了我的系统,现在有了GCC 5.2.1,我收到了关于不兼容指针类型的警告.我已经将问题提取到一个重现错误的小例子:
typedef const double ConstSpiceDouble;
void foo(const double (*)[3]);
int main(int argc, char **argv) {
double a[3][3] = {{1,2,3},{1,2,3},{1,2,3}};
foo((ConstSpiceDouble (*)[3])a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在实际代码中,typedef,函数定义和类型转换都在我控制范围之外的库中,否则我只需修复转换和匹配的函数.这是我从编译器得到的消息:
$ gcc -Werror -c test.c
test.c: In function ‘main’:
test.c:9:7: error: passing argument 1 of ‘foo’ from incompatible pointer type [-Werror=incompatible-pointer-types]
foo((ConstSpiceDouble (*)[3])a);
^
test.c:4:6: note: expected ‘const double (*)[3]’ but argument is of type ‘const ConstSpiceDouble (*)[3] {aka const double (*)[3]}’
void foo(const double (*)[3]);
^
cc1: all warnings being treated as …Run Code Online (Sandbox Code Playgroud)