title: Prefix Operator Strangeness in C++ and array indices
body: <p>So I just ran into a huge headache with the prefix operator.</p>
  
  <p>In my debug build in Visual C++ 2010.</p>
  
  <pre><code>someArray[++index]
  </code></pre>
  
  <p>Would correctly increment the array index and then use it to index into the array.</p>
  
  <p>In my release build it used the array index and then incremented it afterwards, causing some huge headaches.</p>
  
  <p>The weird thing is my debug build code was actually wrong for a while and I had it written as</p>
  
  <pre><code>someArray[index++]
  </code></pre>
  
  <p>This would use the index and then increment it, but the debug build was still incrementing it, and then using the value.  I didn't even realize my mistake until this morning.</p>
  
  <p>Here's a sample of the actual code.</p>
  
  <pre><code>for(unsigned int newPointIndex = 0; newPointIndex &lt; newEdgeList.size() - 1;) {
      m_edges.push_back(Edge(newEdgeList[newPointIndex], newEdgeList[++newPointIndex]));
  }
  </code></pre>
  
  <p>There is no incrementing happening in the for loop.  It happens in the actual code inside the loop while I'm indexing into the array.  I thought it was a clever little optimization, but it makes it not work in the release build.</p>
  
  <p>The second time I was indexing into the array, it was using the unincremented index in the release build, but was working in the debug build.</p>