So, I was teaching base C programming to a student for a test.
Talking about array declaration, I told him:
"you can do this"
int myArray[10];
-> show him that the code compiles
"you can do this, too"
#define ARRAY_SIZE 10
[...]
int myArray[ARRAY_SIZE];
-> show him that the code compiles
"but you can't do this!"
int arraySize = 10;
int myArray[arraySize];
-> show him that the code won't compile...... but it actually compiles!
myWholeLifeIsALie.jpg
I was using DevC++ with MinGW.
Sweating, I switched on Linux and made a simple test program
#include <stdio.h>
int main()
{
int size;
int i;
scanf("%d", &size);
int array[size];
for(i = 0; i < size; i++)
array[i] = i*2;
return 0;
}
It compiles and run both with g++ and gcc.
Instead, MS Visual Studio 2010 compiler tells me that he "expected constant expression". That's what I was expecting from g++/gcc, too.
I think I'm missing something dumb here, but I can't even...