Conformant Arrays in C

Doug Gwyn gwyn at brl-smoke.ARPA
Sun Feb 21 01:43:06 AEST 1988


In article <42529 at sun.uucp> dgh%dgh at Sun.COM (David Hough) writes:
>     The Draft, like traditional C, disallows the equivalent
>        void matmul(x,lx,cx,...)
>        int lx, cx;
>        double x[lx][cx] ;

Yes, indeed, this is a pain.  I discussed the possibility of
allowing something like this several years ago with Dennis
Ritchie and Steve Johnson, and the consensus was that it was
"doable", although specifying it correctly is tricky.

>        void matmul(double a[?ar][?ac], /* ar >= p, ac >= q */
>                    double b[?br][?bc], /* br >= q, bc >= r */
>                    double c[?cr][?cc], /* cr >= p, cc >= r */
>                    int p,              /* 0 <= p <= min(ar,cr) */
>                    int q,              /* 0 <= q <= min(ac,br) */
>                    int r)              /* 0 <= r <= min(bc,cc) */

I didn't see how this proposal would work.  For correct code
to be generated, all but one of the array dimensions has to
be known via the calling sequence.  There seem to be only
two ways to achieve this:  (1) rely on explicit dimension
parameters, as in the first example; (2) automatically pass
extra size information along with the array address.  The
second approach is incompatible with current treatment of
arrays, unless the function prototype has parameters declared
some special way (perhaps using yet another type qualifier),
so that the compilers will pass array information specially
for the particular function.  In other words, to make method
(2) work, more must be involved than just the function
definition.  Is this what was intended by your second example?
(Since the body of the example didn't make use of ar, ac, etc.,
it's hard to be sure.)



More information about the Comp.lang.c mailing list