title: C4127: Conditional Expression is Constant
body: <p>The following code generates warning C4127 (conditional expression is constant) in Visual Studio 2010 (where alias_wchar_t is an alias for wchar_t):</p>
  
  <pre><code>if (sizeof(alias_wchar_t) == sizeof(wchar_t)) // warning occurs here
  {
      // do stuff
  }
  else
  {
      // do other stuff
  }
  </code></pre>
  
  <p>What's the most elegant way to resolve this, short of suppressing the warning?</p>
  
  <p>The best solution I've come up with is to stuff the conditional into a static bool, and use that as the condition. There's a goodly amount of code above and below the if-else, so I wrap the whole thing in braces to limit the scope of the variable as much as possible:</p>
  
  <pre><code>// &lt;snip&gt;
  
  {
      static bool isSameSize = (sizeof(alias_wchar_t) == sizeof(wchar_t));
      if (isSameSize)
      {
          // do stuff
      }
      else
      {
          // do other stuff
      }
  }
  
  // &lt;snip&gt;
  </code></pre>
  
  <p>This feels pretty gross though. This seems like it should be resolvable at compile-time rather than runtime, but the preprocessor doesn't know about sizeof. Is there a cleaner, more elegant way to resolve this?</p>