Practically, I want to know how to use an array value for another array's size declaration. I have this test-code :
main(){
int sz[3]={1,2,3};
int track1[ sz[0] ]={111};
int track2[ sz[1] ]={222,222};
int track3[ sz[2] ]={333,333,333};
printf("%d %d %d\n", track1[0],track2[1],track3[2]);
}
These are the warnings and errors I get:
test2.c: In function ‘main’:
test2.c:4: error: variable-sized object may not be initialized
test2.c:4: warning: excess elements in array initializer
test2.c:4: warning: (near initialization for ‘track1’)
test2.c:5: error: variable-sized object may not be initialized
test2.c:5: warning: excess elements in array initializer
test2.c:5: warning: (near initialization for ‘track2’)
test2.c:5: warning: excess elements in array initializer
test2.c:5: warning: (near initialization for ‘track2’)
test2.c:6: error: variable-sized object may not be initialized
test2.c:6: warning: excess elements in array initializer
test2.c:6: warning: (near initialization for ‘track3’)
test2.c:6: warning: excess elements in array initializer
test2.c:6: warning: (near initialization for ‘track3’)
test2.c:6: warning: excess elements in array initializer
test2.c:6: warning: (near initialization for ‘track3’)
test2.c:8: warning: incompatible implicit declaration of built-in function ‘printf’
What's the problem here, and ovarall is this even possible, what I've tried ?