No subject

5.61/UUNET-internet-primary uunet!homxb.att.com!wilber
Fri Dec 27 22:02:00 PST 1991


Subject: Re:  Variable Length Array Passing

Thomas Breuel writes:
>rms writes:
>|    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.

I'm with Stallman on this one.  It is a bad idea to allow resizing of variable
sized arrays declared within the function body, and it is absurd to allow
resizing of variable arrays that are formal parameters.  The latter case is
absurd for the simple reason that the array size is determined by the *caller*,
not the callee.  The purpose of passing the array dimensions is to inform the
callee about a *pre-existing* array.

Calculating the size of a formal parameter inside the function body opens up a
large can of worms.  How far down can the assignment to the size parameter
be?  Can it be inside a conditional statement?  Can it be done indirectly, like
this?
	foo(int a[an], int n)
	{
	  long *p = &an;
	  bar(p, n);  /* Set *p to n*n */
        }

No matter how we handle formal parameters that are variable sized arrays some
sort of cruft is required -- there will be crufty syntax, or crufty scoping
rules, or crufty restrictions on parameter ordering -- but we can at least keep
the cruft inside the function header, and not let it spill into the function
body.

Bob Wilber    wilberahomxb.att.com



More information about the Numeric-interest mailing list