[Nickle] About arrays and things
Keith Packard
keithp at keithp.com
Mon Jun 30 09:41:18 PDT 2003
Around 1 o'clock on Jun 30, Bart Massey wrote:
> It probably
> depends on whether one views the i in the typedef to be
> bound at type-def time, or at type-use time. Nickle
> chooses the latter view.
Isn't this backwards? I think nickle should choose to evaluate all
expressions where they occur and not where the value is used.
int i = 3;
typedef int[i] t;
t a1 = {1,2,3};
This should be invalid -- typedefs will (for at least a while) be
evaluated in global scope, so 'i' will not be available. Instead:
global int i = 3;
typedef int[i] t;
t a1 = { 1, 2, 3 };
i = 4;
t a2 = { 1, 2, 3 }; /* t is still an array of 3 ints */
Currently, the dimension expression is compiled whereever a declaration
uses it. This is clearly wrong -- it will be evaluated as many times as
it is used:
global int i = 3;
typedef int [++i] t;
for (int j = 0; j = 7; j++) {
t q;
bar (q);
}
If we use 'late' evaluation (as nickle currently does), we get 'bar'
called with ever larger arrays...
-keith
More information about the Nickle
mailing list