This might seem like a beginner's question, but I am interested in the way that a compiler normally creates arrays of variable-dimensions, like in the following program.
#include<iostream>
int main(){
int n;
std::cin>>n;
int a[n];
}
From what I've learnt, in C all the initializer values must be constant, so that the compiler knows how much memory to reserve inside the function, normally by subtracting the stack pointer in order to accomodate the number of elements the array holds.
This makes sense to me. However, I don't quite understand how compilers treat the above program, since it seems to work with G++(MinGW) , but fails with Cl, Microsoft's C++ compiler. I suspect that GCC allocates memory on the heap trough a non-standard extension, but I am not sure of this.
Also, Microsoft's compiler is not renowned for being standards-compliant, so I wouldn't be surprised if it may actually be wrong in the way it treats the above program.