We all know the basic rules for static array:
int size = 20;
char myArray[size];
is not legal. And.
const int size = 20;
char myArray[size];
is OK.
But, what about this.
int f(const int size)
{
char myArr[size];
}
void main()
{
f(2);
f(1024);
}
MSVC says it is an error, gcc seems to compile and execute it fine.
Obviously, it is not portable, but should it be accepted?
Which compiler does the right thing in that situation?
Also, if it is permited by the compiler, should it be permited by good programming standards/practice?
EDITED: The idea is that I would want stack allocation for the speed, but I would not know at compile time the size of the array. I know that there is some other solutions, and that stack alloc would probably not be a significative optimization, but I think it is an interesting usage.