I need a language lawyer with authoritative sources.
Take a look at the following test program which compiles cleanly under gcc:
#include <stdio.h>
void foo(int *a) {
a[98] = 0xFEADFACE;
}
void bar(int b[]) {
*(b+498) = 0xFEADFACE;
}
int main(int argc, char **argv) {
int a[100], b[500], *a_p;
*(a+99) = 0xDEADBEEF;
*(b+499) = *(a+99);
foo(a);
bar(b);
printf("a[98] == %X\na[99] == %X\n", a[98], a[99]);
printf("b[498] == %X\nb[499] == %X\n", b[498], b[499]);
a_p = a+98;
*a_p = 0xDEADFACE;
printf("a[98] == %X\na[99] == %X\n", a[98], a[99]);
}
It produces the output I expect:
anon@anon:~/study/test_code$ gcc arrayType.c -o arrayType
anon@anon:~/study/test_code$ ./arrayType
a[98] == FEADFACE
a[99] == DEADBEEF
b[498] == FEADFACE
b[499] == DEADBEEF
a[98] == DEADFACE
a[99] == DEADBEEF
Are a and b the same type? Is int *a
handled as the same type as int a[]
internally in the compiler?
From a practical point of view int a[100], b[500], *a_p, b_a[];
all seem to be the same type. It's hard for me to believe that the compiler is constantly adjusting these types in the various circumstances in my above example. I'm happy to be proven wrong.
Can someone settle this question for me definitively and in detail ?