Conformant Arrays in C (a better solution?)

Mark Brader msb at sq.uucp
Tue Mar 1 11:51:38 AEST 1988


Karl Heuer (karl at haddock.ima.isc.com) writes:
> ... Alternately, you could petition X3J11 to add this with the syntax
>   float **a = d2malloc( float, nrows, ncols );
> where the first argument is the type. ... [in general]
> ... this would require assistance from the compiler via a builtin.
> 
> Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint

Well, there is also this:

	float **a;
	d2malloc (a, float, nrows, ncols);

with
	#define d2malloc(var,type,nr,nc) { \
		int _i, _j = (nc);\
		(var) = ((type) **) malloc ((_i = (nr)) * sizeof ((type) *));\
		while (_i) (var)[--(_i)] = ((type) *) malloc (sizeof ((type)));\
	}
[Not tested; checks of return status of malloc() omitted for brevity]

But I find this at least equally unsatisfactory.  Certainly there is nothing
in the Draft now that requires a macro that may expand to a statement, and
the above can't be done without temporary variables, thus requiring {...}.

And besides all THAT, what do you do when you want a *3*-dimensional array?

To me, the choice is between the Fortran approach and no change.

Mark Brader		    "Howeb45 9 qad no5 und8ly diturvrd v7 7jis dince
SoftQuad Inc., Toronto	     9 qas 8mtillihemt mot ikkfavpur4d 5esoyrdeful
utzoo!sq!msb, msb at sq.com     abd fill if condif3nce on myd3lf."      -- Cica



More information about the Comp.lang.c mailing list