public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Explanation for warning when passing two-dimensional array
@ 2002-08-26  1:23 Steve Dondley
  2002-08-26  8:24 ` John Love-Jensen
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Dondley @ 2002-08-26  1:23 UTC (permalink / raw)
  To: gcc-help

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?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Explanation for warning when passing two-dimensional array
  2002-08-26  1:23 Explanation for warning when passing two-dimensional array Steve Dondley
@ 2002-08-26  8:24 ` John Love-Jensen
  0 siblings, 0 replies; 2+ messages in thread
From: John Love-Jensen @ 2002-08-26  8:24 UTC (permalink / raw)
  To: Steve Dondley, gcc-help

Hi Steve,

int array[6];
typedef int two[2];
two beray[3]; // just like: int beray[2][3]

Due to C behavior, the variable name array is promiscuously, intrinsically
considered as an standin for an int*.

Also due to C behavior, the variable name beray is promiscuously,
intrinsically considered as a standin for two*.  Is two an int?  Nope.

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-08-26 15:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-26  1:23 Explanation for warning when passing two-dimensional array Steve Dondley
2002-08-26  8:24 ` John Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).