我有以下文件aaa.c
:
int Test(const int * const * int_array, int count) {
int min = int_array[0][0];
for (int i = 1; i < count; ++i) {
if (min > int_array[i][0])
min = int_array[i][0];
}
return min;
}
void test_Test(void) {
int i[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int *pi[10] = { &i[0], &i[1], &i[2], &i[3], &i[4], &i[5],
&i[6], &i[7], &i[8], &i[9] };
Test(pi, 10);
}
当我使用gcc -c aaa.c
编译它时,会产生以下警告:
% gcc -c aaa.c
aaa.c: In function ‘test_Test’:
aaa.c:14:8: warning: passing argument 1 of ‘Test’ from incompatible pointer type
[-Wincompatible-pointer-types]
Test(pi, 10);
^~
aaa.c:1:5: note: expected ‘const int * const*’ but argument is of type ‘int **’
int Test(const int * const * int_array, int count) {
^~~~
为什么呢?什么资格赛被丢弃了? const int * const * int_array
当然不会丢弃int **
所有的限定词。