title: "Array index in initialiser exceeds array bounds"
body: <p>I would like to make use of C99 designated array initialisers to help make my code more self-documenting but I'm running into the problem described below.</p>
  
  <p>Suppose I have a enumeration and an array mapping the enumerants to some other useful data structure, for example:</p>
  
  <pre><code>enum { STATE_IDLE = 0, STATE_WORKING, STATE_PANIC };
  int32_t const g_stress_levels[3] = {
          [STATE_IDLE] = 10,
          [STATE_WORKING] = 40,
          [STATE_PANIC] = 90
  };
  </code></pre>
  
  <p>The above compiles with no warnings with TDM-GCC-32 gcc 4.8.1 and <code>-std=c99</code>. The snippet below does not and instead raises the error "array index in initialiser exceeds array bounds".</p>
  
  <pre><code>enum { STATE_IDLE = 0, STATE_WORKING, STATE_PANIC, TOTAL_STATES };
  int32_t const g_stress_levels[TOTAL_STATES] = {
          [STATE_IDLE] = 10,
          [STATE_WORKING] = 40,
          [STATE_PANIC] = 90
  };
  </code></pre>
  
  <p><a href="https://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/Designated-Inits.html" rel="nofollow">The GCC docs</a> state "the index values must be constant expressions, even if the array being initialized is automatic".
  I've always thought however that <code>enum</code> is a constant expression, so why might this be the case?</p>