title: GNU Compilers vs. Visual Studio on Arrays Allocated w/ Length Constant w/in a Scope
body: <p>I'm aware that if you set a dynamic value in c/c++ you can't use that value within brackets to allocate an array (which would make it a so-called variable length array (VLA), which the <a href="http://www.stroustrup.com/C++11FAQ.html" rel="nofollow noreferrer">current C++ standard</a> does not support)...<br/><br/>
  i.e. See:<br/>
  <a href="https://stackoverflow.com/questions/17318007/c-variable-length-array">C++ : Variable Length Array</a><br/>
  <a href="http://en.wikipedia.org/wiki/Variable-length_array" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Variable-length_array</a><br/></p>
  
  <p>What I don't quite get (and what I haven't see asked precisely here) is why GNU c/c++ compilers (<code>gcc</code>, <code>g++</code>) are okay with using dynamic allocation based on an integer value (as far as I can tell) so long as that value is a constant within the scope of the array allocation, but <code>Visual Studio</code>'s does not support this and will refuse to compile the code, spitting out errors.</p>
  
  <p>e.g. in <code>g++</code></p>
  
  <pre><code>void Foo(const unsigned int bar)
  {
    double myStuff[bar];
    //... do stuff...
  }
  </code></pre>
  
  <p>...compiles just fine...</p>
  
  <p>But the same code refuses to compile in versions of VS I've used, unless whatever I pass to bar is <code>const</code> in all scopes or is a <code>#define</code>, <code>static const</code>, etc.</p>
  
  <p>I would suspect that maybe GNU compilers  use the scope to infer that this value is a constant within that scope and either simply assign it to a malloc or handle it specially somehow.  </p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Who (VS or GNU) is closer to the standard in terms of how they
  handle this? </li>
  <li>Is there a way to do this VS using <code>[]</code> on a value that's constant within scope, but not globally <code>const</code> throughout the entire program without a <code>malloc</code> call?</li>
  <li>Are there any issues I should be aware of if I use this in my
  GNU-compiled code?</li>
  </ol>