Re: [NXC] ArrayInit for 2D arrays
Posted: 05 Jun 2011, 18:49
Looks like a bug in the compiler.
This:
Expands to:
See the "redeclaration" of
Using
This:
Code: Select all
#define ArrayInitD2(type,arr,val,arrlen1,arrlen2) while(1) {type arrtemp[]; ArrayInit(arrtemp,val,arrlen2); ArrayInit(arr,arrtemp,arrlen1); break;}
task main()
{
int myBar[][];
float myFoo[][];
ArrayInitD2(int, myBar, 123, 10, 20)
ArrayInitD2(float, myFoo, 12.34, 8, 16)
// some random array readings
NumOut(0,56, myBar[0][0]);
NumOut(0,48, myBar[5][5]);
NumOut(0,40, myBar[9][19]);
NumOut(0,32, myFoo[3][0]);
NumOut(0,24, myFoo[7][15]);
while(1);
}
Code: Select all
#define ArrayInitD2(type,arr,val,arrlen1,arrlen2) while(1) {type arrtemp[]; ArrayInit(arrtemp,val,arrlen2); ArrayInit(arr,arrtemp,arrlen1); break;}
task main()
{
int myBar[][];
float myFoo[][];
while(1) {int arrtemp[]; ArrayInit(arrtemp,123,20); ArrayInit(myBar,arrtemp,10); break;}
while(1) {float arrtemp[]; ArrayInit(arrtemp,12.34,16); ArrayInit(myFoo,arrtemp,8); break;}
// some random array readings
NumOut(0,56, myBar[0][0]);
NumOut(0,48, myBar[5][5]);
NumOut(0,40, myBar[9][19]);
NumOut(0,32, myFoo[3][0]);
NumOut(0,24, myFoo[7][15]);
while(1);
}
arrtemp
as a float[]
on line 8
?Using
for
doesn't help either:
Code: Select all
#define ArrayInitD2(type,arr,val,arrlen1,arrlen2) for(type arrtemp[]; 1; ) {ArrayInit(arrtemp,val,arrlen2); ArrayInit(arr,arrtemp,arrlen1); break;}