This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]