GNU Compilers vs. Visual Studio on Arrays Highlighted w / Length Constant w / in Scope

I know that if you set a dynamic value in c / C ++, you cannot use this value in brackets to highlight an array (which would make it the so-called variable length array (VLA), which the current C ++ standard does not support) ...

see further:
C ++: Variable Length Array
http://en.wikipedia.org/wiki/Variable-length_array

What I did not quite understand (and what I did not see exactly here) is the reason that the GNU c / C ++ compilers ( gcc, g++) are okay using dynamic allocation based on integer value (as far as I can tell) , while this value is a constant in the field of distribution of the array, but Visual Studiodoes not support it and refuses to compile the code, spitting out errors.

eg. ing++

void Foo(const unsigned int bar)
{
  double myStuff[bar];
  //... do stuff...
}

... compiles just fine ...

But the same code refuses to compile in VS versions that I used, unless I go to the bar, constin all areas or is #define, static constetc.

, , , GNU , , malloc, -.

:

  • (VS GNU) , ?
  • VS, [] , , const malloc?
  • - , , GNU?
+4
2

VLA C C99 on. ++.

g++ VLA C90 ++, -pedantic, , .

Visual Studio VLA C, ++. VS C89, AFAIK MS C .

, C:

6.7.6.2
...
2 , ( 6.2.3), . , .

, VLA static ; , , , , . , .

+5

GNU , -pedantic, .

#include <iostream>

int main()
{
    int foo = 10;
    int bar[foo];
}

:

g++-4.8 -std=c++11 -O2 -pedantic -pthread main.cpp && ./a.out
main.cpp: In function ‘int main()’:
main.cpp:6:16: warning: ISO C++ forbids variable length array ‘bar’ [-Wvla]
     int bar[foo];
                ^
+3

All Articles