Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!tut.cis.ohio-state.edu!unmvax!indri!polyslo!usc!orion.cf.uci.edu!uci-ics!zola.ics.uci.edu!schmidt From: schmidt@zola.ics.uci.edu (Doug Schmidt) Newsgroups: comp.lang.c Subject: Re: Conformant arrays-- how to? Message-ID: <13101@paris.ics.uci.edu> Date: 2 May 89 02:54:09 GMT References: <4700036@m.cs.uiuc.edu> Sender: news@paris.ics.uci.edu Reply-To: Doug Schmidt Organization: University of California at Irvine: ICS Dept. Lines: 79 In article <4700036@m.cs.uiuc.edu> kenny@m.cs.uiuc.edu writes: ++ ++ Some time ago, I saw in this newsgroup a discussion for a proposal to ++ implement conformant arrays of more than one dimension in C. If I ++ remember correctly, the proposed scheme was to allow a function to be ++ expressed as: ++ ++ return_type f (int m, /* Number of rows */ ++ int n, /* Number of columns */ ++ double x [] [n]);/* x is a m x n array */ ++ { ++ .... code for f .... ++ } ++ ++ The generated code would use standard rules for pointer arithmetic, ++ except that the variable n would enter into the computation: ++ ++ sizeof (x [0] [0]) == sizeof (double) ++ sizeof (x [0]) == n * sizeof (double) ++ sizeof x == sizeof (double (*)[n]) [ == sizeof (double *) ?? ] ++ ++ and when these rules are applied, we get C's usual row-major storage ++ layout. ++ ++ Has anyone tried implementing such a scheme? (I recall that X3J11 Check out GNU GCC 1.35. I believe it implements what you are referring to: ---------------------------------------- #include /* Try using other types for TYPE, i.e., double, int, float, char, etc. */ typedef long TYPE; void tester (int i, int j, TYPE buf[i][j]) { int k, l; for (k = 0; k < i; k++) { for (l = 0; l < j; l++) printf ("buf[%d][%d] = %4d ", k, l, buf[k][l]); putchar ('\n'); } } int main (int argc, char *argv[]) { if (argc == 3) { int i = atoi (argv[1]); int j = atoi (argv[2]); int k, l; TYPE c[i][j]; for (k = 0; k < i; k++) for (l = 0; l < j; l++) c[k][l] = k * l; tester (i, j, c); return 0; } else fprintf (stderr, "usage: %s \n", argv[0]); return 1; } ---------------------------------------- This seems pretty straight-forward to understand and implement, but might it present problems on some architectures? Doug -- On a clear day, under blue skies, there is no need to seek. And asking about Buddha +------------------------+ Is like proclaiming innocence, | schmidt@ics.uci.edu | With loot in your pocket. | office: (714) 856-4043 |