VLAs as arbitrary expressions
Thomas M. Breuel
uunet!ai.mit.edu!tmb
Sat Dec 21 03:33:16 PST 1991
Let me make a different array syntax proposal. Assume
that instead of trying to squeeze the array bounds expressions
in the header, we allow the user to compute them in the body
of the function. For example:
double foo(double a[n][m],int r[l],int a,int b) {
float t=sqrt(a);
n=(int)t;
m=b;
l=a*b;
...
}
That is, the declaration "double a[n][m]" would declare a variable
length array "a" and two integral variables "n" and "m" (of
unspecified integral type). These will be used in the body for index
computations.
Note that it would be OK for the user to use "n" and "m" as
he would any other integral variables. However, taking the
address of one of them or changing them inside an inner loop
could obviously inhibit some optimizations.
This proposal should be easy to implement even in GCC, and it would
also get around the syntactic limitations (no temporaries, etc.)
on writing expressions for array bounds in the Cray proposal.q
What about it?
Thomas.
More information about the Numeric-interest
mailing list