title: Preventing the optimizer from optimizing a variable away in visual studio
body: <p>Sometimes when writing benchmarks I have found it useful to use an "opaque" function which prevents the optimizer from completely removing a variable.  On gcc and clang I have an implementation using inline assembly which seems to work as I want in all cases I have tested so far.  Here is a simple example of what I am interested in (<a href="http://goo.gl/03EGrJ" rel="noreferrer">example on godbolt</a>):</p>
  
  <pre><code>template&lt;class T&gt; 
  void opaque(T&amp;&amp; t)
  {
      asm volatile("" : "+r" (t));
  }
  
  int test(int a) { return a + 5; }
  
  int main()
  {
      int a = 10;
      opaque(a);
      return test(a);
  }
  </code></pre>
  
  <p>The above code generates the following assembly:</p>
  
  <pre><code>movl    $10, %eax
  addl    $5, %eax
  ret
  </code></pre>
  
  <p>whereas, without the opaque function it generates:</p>
  
  <pre><code>movl    $15, %eax
  ret
  </code></pre>
  
  <p>How would I write an equivalent to the opaque function for the visual studio compiler (specifically 2013)?</p>