Hi, guys. I couldn't find any information about this after googling for a while (blame my googling skills), so I thought I'd just ask.
So, here's the deal. In Dev-C++ (which I think uses the GCC compiler) the following would compile correct without error:
(And now that I checked, it compiles without error in "http://cpp.sh/" too)
1 2 3 4 5 6 7 8 9 10
#include <iostream>
int main()
{
int size;
std::cin >> size;
int arr[size];
return 0;
}
While of course, the C++ standard obvious doesn't allow you to declare an array of a non-constant size and it doesn't work in Visual Studio, which instead would have you dynamically allocate memory for it:
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
int main()
{
int size;
std::cin >> size;
int *arr = newint[size];
delete[] arr;
return 0;
}
My question is, if anyone knows, what exactly happens in Dev-C++ and why does it even work?
what exactly happens in Dev-C++ and why does it even work?
It is GNU extension bringing C99 VLA into C++.
I suggest to explicitely set standard to standard C++ and not gnu extention in compiler options and compile with -pedantic-errors flag (which disallows standard violations)