Variable Length Array Passing, new proposals

Steve Hanson uunet!mips.com!sah
Fri Dec 27 10:32:55 PST 1991


   Date: Mon, 23 Dec 91 22:01:10 -0500
   From: rmsagnu.ai.mit.edu (Richard Stallman)

   I think that the syntax int foo(float a[int n]) makes sense in
   conjunction with a proposal for arrays that are first-class citizens.
   It should not be too hard to parse, because declarations start with
   recognizable keywords that distinguish them from expressions.

   But first-class arrays would be a large addition to the language.  I
   don't think we should link the current variable-length array scheme,
   which is mostly complete in itself, to a further large extension.

   Meanwhile, people will still want ways to pass variable-length arrays
   as pointers, just as they now pass fixed arrays as pointers.
   So I think we still need a scheme for that.

   I think we should save foo(float a[int n]) for use with arguments that
   are first-class arrays.


Here's a variation on the theme that disposes of the dimension declaration
altogether and treats variable-length arrays mostly as second class objects
with the exception the dimensions are implied in the formal argment list
(sort of how the destination address of functions returning structs are
implied in some implementations, but different in that we provide a means
for the user to read them)
An example of a single-dimension array is:
	void foo( a[*] );
The actual dimension is defined to be of type long.
A macro or builtin is defined to read the dimensions:
	#define length(a,n) ... // implementation dependent, where a is
				// array name and n the N-th index. For
				// single dimension n is 1.
Calls pass the array address and dimensions just as you would in traditional
C:
	foo(&a[y],n);
In fact, the definition syntax for a single-dimension array in traditional C 
would not change:
	void foo(a,n)
	int a[];
	long j;{}

There's no ambiguity in the syntax and semantics seems straight forward. Has
this style of proposal already been discussed and rejected?







More information about the Numeric-interest mailing list