A very simple code to test VLA on gcc
works fine on gcc-4.2.9 (Raspbian), but not on gcc-6.2.0 (Ubuntu). I am surprised. Though it compile without error, the output is not proper.
Code:
int len, i;
int test[len];
scanf("%d",&len);
for(i=0;i<=len;i++){
test[i]=i*i;
printf("%d\t",test[i]);}
printf("\n");
return 0;
Argument:
8
Output:
With 4.2.9 (Raspbian),
0 1 4 9 16 25 36 49 64
With 6.2.0 (Ubuntu),
0 1 4 9 16 1
It doesn't even reach to the count of 8. I am surprised. The same code works if I hard code the value of len
.
0 1 4 9 16 25 36 49 64
Any idea about what is possibly going wrong?