According to my memory the following piece of code should compile fine on C++ but not in C.
Only problem is how to test it? It compiled fine with g++ and also with gcc. I’m assuming that g++ is C++ compiler and gcc is C compiler. I’ve tried it with mingw under Windows. Am I correct? if not then how to compile it using C compiler.
int main() {
const int i = 1;
const int j = 2;
const int k = 3;
int array[i + j + k];
return 0;
}
No, that will compile in C99, which has support for variable length arrays. To get strict C89 behavior, try compiling with:
That gives:
c89 means use C89, pedantic-errors means error on non-C89 code.