I am using C++ 11 and this is an example code fragment where I am not able to understand the internal workings of the language.
This works -
int main(){
int n;
cin>>n;
int a[n]; // THIS WORKS due the the extensions
However, this does not work -
int main(){
int n;
cin>>n;
int a[n] = {0} // This does not work;
I am compiling this using:
g++ -std=c++0x file.cpp -o file
- I understand that VLA's are not part of the C++ standard and the GNU C++ provides it via compiler extensions.
- I also understand that the memory is allocated at runtime using alloca.
- What I don't understand is that, if A works, why can B not work?
Aucun commentaire:
Enregistrer un commentaire