Explanation for warning when passing two-dimensional array
Steve Dondley
s@dondley.com
Mon Aug 26 01:23:00 GMT 2002
When compiling the following program with line 7:
1 #include <stdio.h>
2 int twod (int *);
3
4 int main(void) {
5 int array[2][3] = { 0, 1, 2, 7, 4, 6 };
6 // twod((int *) array); /* WITH THIS LINE, NO WARNING */
7 twod(array); /* GIVES WARNING*/
8 return 0;
9 }
10
11 int twod (int *twodarray) {
12 printf("%d", *(twodarray + 3));
13 return 0;
14 }
I get this warning: 'passing arg 1 of `twod' from incompatible pointer
type'.
I'm not sure why, however. Why is a type cast necessary, as shown in line
6, to suppress the warning? You don't need a type cast when passing
one-dimensional arrays. Why do you need one for two-dimensional arrays?
More information about the Gcc-help
mailing list