I have some concepts about the VLA and its behavior that I need to clarify.
AFIK since C99 it's possible to declare VLA into local scopes:
int main(int argc, char **argv)
{
// function 'main' scope
int size = 100;
int array[size];
return 0;
}
But it is forbidden in global scopes:
const int global_size = 100;
int global_array[global_size]; // forbidden in C99, allowed in C++
int main(int argc, char **argv)
{
int local_size = 100;
int local_array[local_size];
return 0;
}
The code above declares a VLA in C99 because the const modifier doesn't creates a compile-time value. In C++ global_size is a compile-time value so, global_array doesn't becomes a VLA.
What I need to know is: Is my reasoning correct? The behaviour that I've described is correct?
I also want to know: Why the VLA in global scope aren't allowed? are forbidden both in C and C++? What reason is there for the behavior of arrays into global and local scope were different?