title: VS compilation warning: result of 32-bit shift implicitly converted to 64 bits
body: <p>Visual Studio 2013 issues an annoying (and seemingly irrelevant) compilation warning on:</p>
  
  <pre><code>#include &lt;stdint.h&gt;
  
  #define PRECISION 16
  
  uint64_t hi = 0;
  for (uint8_t i = 0; i &lt; PRECISION; i++)
  {
      if (some_condition)
      {
          hi += 1 &lt;&lt; (PRECISION - 1 - i);
      }
  }
  </code></pre>
  
  <p>Here is the compilation warning:</p>
  
  <pre><code>warning C4334: '&lt;&lt;' :
  result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
  </code></pre>
  
  <p>It seems to be resolved when changing <code>1 &lt;&lt; (PRECISION - 1 - i)</code> to <code>1 &lt;&lt; (PRECISION - 1)</code>.</p>
  
  <p>So I've been trying to figure out what could possibly go wrong in <code>1 &lt;&lt; (PRECISION - 1 - i)</code>.</p>
  
  <p>Obviously, if <code>i &gt;= PRECISION</code>, then the shift-left operation would yield undefined behavior.</p>
  
  <p>However, the variable <code>i</code> does not exceed the value of <code>PRECISION - 1</code>.</p>
  
  <p>Moreover, even if we assume that the compiler cannot infer this fact, I don't see what this compilation warning has to do with a potential undefined behavior due to the shift-left operand.</p>
  
  <p>Perhaps it assumes that the unsigned value of <code>PRECISION - 1 - i</code> can be larger than 31.</p>
  
  <p>But how exactly am I supposed to tell the compiler that it never does?</p>
  
  <p>I found <a href="https://stackoverflow.com/q/31558314/1382251">one related question</a>, but there are no proper answers provided.</p>
  
  <p>Thanks</p>