当我使用GCC 4.9.2编译以下程序时,出现以下警告:传递给‘P’的第1个参数类型不兼容。然而,我没有发现程序有任何错误。有什么线索吗?
typedef int Row[10];
void P(const Row A[])
{
}
int main(void)
{
Row A[10];
P(A);
return 0;
}
这是来自GCC的完整错误输出:
test.c: In function ‘main’:
test.c:12:4: warning: passing argument 1 of ‘P’ from incompatible pointer type
P(A);
^
test.c:3:6: note: expected ‘const int (*)[10]’ but argument is of type ‘int (*)[10]’
void P(const Row A[])
^
编辑:该程序能够在Clang 3.5.0和选项-pedantic -std=c89 -Wall
的情况下编译成功。
int (*)[10]
类型的参数,可以是常量也可以不是。你有不同的看法吗? - August Karlstrom