Variable Length Array Passing, summary of proposals

Thomas M. Breuel uunet!ai.mit.edu!tmb
Mon Dec 23 09:17:10 PST 1991


|    int
|    foo (double a[an],int n)
|    {
|      an = n;
|      ...
|    }
|
|    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.
|
|We already have a general rule that the size of an array is computed
|just once when the array declaration is executed, and never changes
|thereafter.  Making the language inconsistent is bad design.

There are no arrays with variable dimensions (i.e., dimensions that are
computed at runtime) in C currently, hence there is no rule about when
or how often dimensions get computed.  So, I don't see how this
proposal makes the language inconsistent.

If it really bothers you, you could, of course, impose a rule
that dimensions be computed and assigned only once. I'd find
such a rule arbitrary and unneccesary.

Arguably, this proposal differs in some ways from the semantics that
GNU CC implements for variable dimension stack allocated arrays, but as
far as I can see, there is no conflict, since allocation and argument
passing are two completely different operations.

|There is already a way you can get a similar result.  I can't
|illustrate it for 1D, because it involves using a pointer for the
|"innermost" dimension.  Here is an example of the 2D case: [...]

The intent behind this proposal was primarily that it avoids any sort
of special syntax for the expressions that are used to compute array
bounds. The fact that it is "natural" to treat the dimension variables
like any other integral variables and that this allows you to change
dimensions later is something that sort of falls out.

If you want to allow general expressions for array bounds computations
and unrestricted argument order, I think this is the simplest and most
natural way of doing it. None of the standard C scoping rules are
altered, and you can use shared local temporaries in the computation of
the bounds, something that no other proposal (Cray or RMS) allow.

						Thomas.



More information about the Numeric-interest mailing list