Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!necntc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Conformant Arrays in C (a better solution?) Message-ID: <2739@haddock.ISC.COM> Date: 27 Feb 88 02:10:03 GMT References: <8802240725.AA22255@jade.berkeley.edu> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 41 In article <8802240725.AA22255@jade.berkeley.edu> ERICMC@USU.BITNET (Eric McQueen) writes: >Summary: Standard run-time function would be a better solution. > >As has been pointed out several times [recently in <2336@umd5.umd.edu> by >Chris Torek (chris@trantor.umd.edu)], the following is already possible: >void matmul( double **a, double **b, double **c, int p, int q, int r) {...} >and is much simpler. The only problem I see with this is that it is >difficult to declare such an array in the calling procedure. Yes. >[X3J11 should standardize a function to allocate such row-vector arrays, e.g. > float **a = d2malloc( sizeof(float), nrows, ncols ); ] Now we have a problem. How does the routine know that the row vectors should be "float *" rather than some other pointer type? This design implicitly assumes that all pointers look alike. Now, you can (and do) assert that only "strange systems" have this problem, but that doesn't make it go away. If you insist that an ANSI implementation must supply d2malloc(), and that strange systems must therefore be non-ANSI, you're going against the X3J11 charter to work on as many systems as possible. If you allow an implementation to omit d2malloc(), it kind of defeats the purpose of putting it into the standard. To put it another way, if I know of a system where your function can't possibly be implemented, I can't comfortably use it in my portable programs, even if it somehow gets put in the standard. What can we salvage? As you mentioned, you could make explicit functions for the most common datatypes (int, long, float, double). The implicit rule that all struct pointers are equivalent allows you to do it for generic structs, too; this ought to be useful. Alternately, you could petition X3J11 to add this with the syntax float **a = d2malloc( float, nrows, ncols ); where the first argument is the type. On non-strange systems this has the simple implementation you outlined; the first argument is used only as a parameter to sizeof(). On strange systems, this would require assistance from the compiler via a builtin. (Cf. ) Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint