title: c++ for loop temporary variable use
body: <p>Which of the following is better and why? (Particular to c++)</p>
  
  <p>a.</p>
  
  <pre><code>int i(0), iMax(vec.length());//vec is a container, say std::vector
  for(;i &lt; iMax; ++i)
  {
    //loop body
  }
  </code></pre>
  
  <p>b.</p>
  
  <pre><code>for( int i(0);i &lt; vec.length(); ++i)
  {
    //loop body
  }
  </code></pre>
  
  <p>I have seen advice for (a) because of the call to length function. This is bothering me. Doesn't any modern compiler do the optimization of (b) to be similar to (a)?</p>