Variable Length Array Passing, summary of proposals

Thomas M. Breuel uunet!ai.mit.edu!tmb
Sun Dec 22 07:28:59 PST 1991


OK. Here is a summary of the proposals I have seen so far (note that I
have followed the tradition of this thread and used 1D arrays, even
though the issue really only becomes important with >1D arrays).

(0) Simple:

        float f(foo b,double a[g(b)]) {...}

	All identifiers used in the array dimension expressions must
	be passed before they are used in the expression.

(1) General Cray:

	float f(double a[g(b)],foo b) {...}

	Array dimensions can be arbitrary expressions.

	This is not difficult to implement conceptually, but may be
	nontrivial in some compilers (like GCC). It is also subtly
	different from traditional C scoping rules.

(2) Restricted Cray:

	float f(double a[n],int n) {...}

	Array dimensions can only be given as identifiers.

	This looks like it's easy to parse: "double a[n]" defines both
	the identifier "a" and "n", and the later declaration "n"
	only defines the placement of "n" in the argument list and
	its exact type.

(3) Steve Clamage:

	float f(double a[int n]) {...}

	I think this is the same idea as in (2), but with a different
	syntax. With this particular syntax, I foresee pitfalls or
	"gotchas" about passing the dimensions.

(4) Richard Stallman:

	int foo (a, int n; double a[n]) { ... }

	int foo ([a, n] int n, double a[n]) { ... }

	These are easy to implement according to Stallman.

(5) Assignable:

	int foo(double a[an],int n) {
		an = n;
		...
	}

	An argument declaration of the form "T a[b][c]" defines an
	array "a" and two integer variables "b" and "c" used in index
	computations (and bounds checking). "b" and "c" can be used
	like any other variables of integral type (but their exact
	type is implementation dependent).

	This syntax is arguably the most powerful, since it would also
	let you change dimension "on the fly" and use arbitrary code
	(not just expressions) to compute array dimensions.

In general, I think the issues we should be thinking about are:

(a) is it important to be able to use arbitrary expressions for
    the computation of array dimensions, or do simple identifiers
    suffice?

(b) is it important that arguments used in array dimension
    expressions can be passed after the array?

(c) is it important that the standard C scoping rules be
    followed religiously?

I write vision code, which involves a lot of 2D arrays. (a) isn't
really important to me: simple identifiers suffice for array
dimensions, and I'd actually not mind if the language itself forced
everybody to do this. In general, (c) is important to me, but the
differences in practice between proposal (1) and normal scoping rules
are negligible.  (b) is a little more important to me, but that is
mostly a question of style and convention.

Personally, I'd be quite happy with (0), (2), or (5). I think (1)
would be ideal, but I suspect some implementors like RMS will think
it's too hairy to implement, and some people will object to the new
scoping rules. I strongly object to both (3) and (4).  They are
syntactically unobvious and/or cumbersome to use.

				     Thomas.




More information about the Numeric-interest mailing list