Variable-length arrays
Peter S. Shenkin
uunet!avogadro.barnard.columbia.edu!shenkin
Sat Dec 21 21:26:09 PST 1991
From: Stephen D. Clamage <uunet!taumet.com!steveauunet.UU.NET>
[[ Comments deleted concerning problems which may arise with
float f( double a[n], int n );
These are the first such comments I've seen that indicate that this syntax
might cause problems for the user, as distinguished from the compiler-writer.
Perhaps someone from Cray would care to reply? However, I see possible
problems with Stephen's modest proposal, which was: ]]
> I have a modest proposal. Follow the example of ISO Pascal conformant
> array parameters. Declare the size parameter of the array inside the
> brackets:
> float f(double a[int n]);
How is this function to be called? Do you mean to imply that it should be
called as follows:
var = f( array[43] ); /* within f, n is assigned value 43 */
If so, how would I pass an array to f whose first element is array[12], and
which has a total of 43 elements, starting with array[12]? If I understand
you correctly, I would have to say:
var = f( (&(array[12]))[43] );
I don't have the precedence rules in my head; thus probably I have more parens
in this expression than are necessary; nevertheless, this seems awkward and
non-intuitive for the programmer. Aside from the awkwardness, it also
requires a specific calling order, which I think most of us feel is
undesirable. If we're going to require a specific calling order, I would
much rather revert to the simpler form:
float f( int n, double a[n] );
where n has to be declared first.
But I would like to see someone from Cray respond to Stephen's remark about
difficulties in the simple prototype "float f( double a[n], int n )" if
there should be a typedef around called n.
-P.
-P.
************************f*u*cn*rd*ths*u*cn*gt*a*gd*jb*************************
Peter S. Shenkin, Department of Chemistry, Barnard College, New York, NY 10027
(212)854-1418 shenkinaavogadro.barnard.columbia.edu shenkinacunixc.BITNET
********** "I've got algorithm -- who could ask for anything more?" **********
More information about the Numeric-interest
mailing list