title: gcc complains: variable-sized object may not be initialized
body: <p>I've looked at these and they do not answer my question:</p>
  
  <p><a href="https://stackoverflow.com/questions/9688219/variable-sized-object-may-not-be-initialized">variable-sized object may not be initialized</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3082914/c-compile-error-variable-sized-object-may-not-be-initialized">C compile error: &quot;Variable-sized object may not be initialized&quot;</a></p>
  
  <p><a href="https://stackoverflow.com/questions/6550653/error-variable-sized-object-may-not-be-initialized-but-why">Error: Variable-sized object may not be initialized. But why?</a></p>
  
  <p><br />I am trying to write some fairly portable <code>c</code> code:</p>
  
  <pre><code>int main () 
  {
      const int foo=13;
      int bar[foo]={0};
      return 0;
  }
  </code></pre>
  
  <p><br />
  I get a <code>variable-sized object may not be initialized</code> error when compiling as <code>c</code> code using either:</p>
  
  <ul>
  <li><strong>gcc 4.3.4</strong></li>
  <li><strong>arm-linux-gnueabi-gcc 4.4.5</strong></li>
  </ul>
  
  <p>And if i compile it as <code>c</code> in <strong>VS2008</strong> i get a slightly different <code>error C2057: expected constant expression</code></p>
  
  <p><br />I understand that here, the <code>c</code> code compiler is not recognising <code>const int foo=13;</code> to be truely constant; for example we might have</p>
  
  <pre><code>void a(int fool) 
  {    
      const int foo=fool;
      int bar[foo]={0};
  }
  </code></pre>
  
  <p><br />I also realise that <a href="http://ideone.com/jbx7h" rel="nofollow noreferrer">unlike the gcc compilers</a>, the <strong>VS2008</strong> compiler has no concept of <a href="http://en.wikipedia.org/wiki/C99" rel="nofollow noreferrer">C99 variable-length arrays</a>. And that MS apparently has not mentioned any future support.</p>
  
  <p><br />And yet, <code>cpp</code> code compilation with either <strong>gcc</strong> or <strong>MS</strong> compilers is altogether different/cleverer ?!</p>
  
  <ul>
  <li><a href="http://ideone.com/mv6UB" rel="nofollow noreferrer">this fails to compile</a> </li>
  <li><a href="http://ideone.com/ylJ6R" rel="nofollow noreferrer">but this will compile</a></li>
  </ul>
  
  <p><br />
  And also <em>what i do not understand</em> regarding the <strong>gcc</strong> <code>c</code> code compiler is:</p>
  
  <ul>
  <li>since <a href="http://ideone.com/CBrsq" rel="nofollow noreferrer">this code</a> <em>does</em> compile,</li>
  <li>why <a href="http://ideone.com/Br6cC" rel="nofollow noreferrer">this code</a> <em>does not</em> compile..</li>
  <li>and yet <a href="http://ideone.com/qstJP" rel="nofollow noreferrer">this code</a> <strong>does</strong> compile?</li>
  </ul>
  
  <p><br />(NB: in this last case, <strong>MS</strong> <code>c</code> code compilation fails; consistently as with <code>int bar[foo]={0};</code>)</p>