0

I basically have the following lines of code

void func1(size_t sz1)
{
    double arr[sz1];
}

When I use the Microsoft Visual C++ 2019 (C) Compiler, error C2057 is thrown. When I use the MinGW64 Compiler (C), I don't get an error and the code works as expected. Does the MinGW64 Compiler automatically use mallaoc or why don't I get an error with this Compiler too? Furthermore, do I have to expect any troubles when using the lines of code above instead of malloc?

Steradiant
  • 233
  • 2
  • 13

1 Answers1

1

Well looking at c++ array - expression must have a constant value, it seems like g++ has this feature (so likely mingw also uses this). It seems that the compiler will alloc under the hood, but the problem becomes ofc that your code is not portable across compilers.

Tarranoth
  • 124
  • 1
  • 5