title: C99: Can I declare variables in the beginning of a block in a 'for'?
body: <p>Is the following code legal according to C99?</p>
  
  <pre><code>...
  for(....) {
  int x = 4;
  ...
  }
  ...
  </code></pre>
  
  <p>You can assume that before line 3 the variable x was never declared.</p>
  
  <p><a href="http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1336.pdf" rel="nofollow noreferrer" title="C99">C99 (PDF) </a></p>
  
  <p>Until now I have only found the following, but I dont think that this is enough:</p>
  
  <p>A block allows a set of declarations and statements to be grouped into one syntactic unit.
  The initializers of objects that have automatic storage duration, and the variable length
  array declarators of ordinary identifiers with block scope, are evaluated and the values are
  stored in the objects (including storing an indeterminate value in objects without an
  initializer) each time the declaration is reached in the order of execution, as if it were a
  statement, and within each declaration in the order that declarators appear.</p>
  
  <p>From page 145 of that PDF.</p>