title: Reconfiguring C++ code to deal with `warning: unsequenced modification and access to parameter`
body: <p>I have several lines of code in a library I am compiling which are throwing warnings under clang (on OSX) like so:</p>
  
  <pre><code>warning: unsequenced modification and access to 'tmp' [-Wunsequenced]
      float tmp, fCosSqr = (tmp = cos(m_angle)) * tmp;
                                ^                 ~~~
  </code></pre>
  
  <p>This line of code looks pretty nasty and I'm finding it hard to be absolutely certain of what is going on.</p>
  
  <p>As far as I can see, the final value of <code>fCosSqr</code> is supposed to be <code>cos(m_angle)^2</code>, and the final value of <code>tmp</code> is supposed to be <code>cos(m_angle)</code> (although in fact <code>tmp</code> is not  used anywhere else in the program.)</p>
  
  <p>Presumably the warning is provided because if the assignments were done out of sequence, the unintialised value of <code>tmp</code> could be used instead of <code>cos(m_angle)</code>.</p>
  
  <hr>
  
  <p>Could I rewrite the line of code as follows:</p>
  
  <pre><code>float tmp = cos(m_angle), fCosSqr = tmp * tmp;
  </code></pre>
  
  <p>or like so:</p>
  
  <pre><code>float fCosSqr = cos(m_angle) * cos(m_angle);
  </code></pre>
  
  <p>?</p>
  
  <p>Why was the code ever written as it was? Is it supposed to provide some kind of speed gain?</p>