This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Explanation for warning when passing two-dimensional array
- From: "Steve Dondley" <s at dondley dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Mon, 26 Aug 2002 04:27:53 -0400
- Subject: Explanation for warning when passing two-dimensional array
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?