I'm reading about VLAs in C Primer Plus, and this book strictly says that the introduction of VLAs to C began with the C99 standard. Whenever I attempt to declare a loop control variable within the header of a for loop, gcc informs me that this action only allowed in C99 mode. However, the following test code compiles and works (although it prints garbage variables, which is to be expected considering none of the array elements were initialized).
#include <stdio.h>
int main(){
int x;
int i = 9;
int array[i];
for(x = 0; x < i; x++)
printf("%d\n", array[x]);
return 0;
}
If I'm not in C99 mode, how could this possibly be legal?
warning: ISO C90 forbids variable length array ‘array’
– Speedwell