title: Visual Studio 2010 (C++): suppress C4706 warning temporarily
body: <p>When you compile the following C++ source file in Visual Studio 2010 with warning level /W4 enabled</p>
  
  <pre><code>#include &lt;cstdio&gt;  // for printf
  #include &lt;cstring&gt; // for strcmp
  
  char str0[] = "Hello";
  char str1[] = "World";
  
  int main()
  {
      int result;
  
      if (result = strcmp(str0, str1)) // line 11
      {
          printf("Strings are different\n");
      }
  }
  </code></pre>
  
  <p>you get the following warning</p>
  
  <blockquote>
    <p>warning C4706: assignment within conditional expression</p>
  </blockquote>
  
  <p>for line 11.</p>
  
  <p>I want to suppress this warning exactly at this place. So I tried Google and found this page: <a href="http://msdn.microsoft.com/en-us/library/2c8f766e(v=VS.100).aspx">http://msdn.microsoft.com/en-us/library/2c8f766e(v=VS.100).aspx</a></p>
  
  <p>So I changed the code to the following - hoping this would solve the problem:</p>
  
  <pre><code>#include &lt;cstdio&gt;  // for printf
  #include &lt;cstring&gt; // for strcmp
  
  char str0[] = "Hello";
  char str1[] = "World";
  
  int main()
  {
      int result;
  
  #pragma warning(push)
  #pragma warning(disable : 4706)
      if (result = strcmp(str0, str1))
  #pragma warning(pop)
      {
          printf("Strings are different\n");
      }
  }
  </code></pre>
  
  <p>It didn't help.</p>
  
  <p>This variant didn't help either:</p>
  
  <pre><code>#include &lt;cstdio&gt;  // for printf
  #include &lt;cstring&gt; // for strcmp
  
  char str0[] = "Hello";
  char str1[] = "World";
  
  int main()
  {
      int result;
  
  #pragma warning(push)
  #pragma warning(disable : 4706)
      if (result = strcmp(str0, str1))
      {
  #pragma warning(pop)
          printf("Strings are different\n");
      }
  }
  </code></pre>
  
  <p>To avoid one further inquiry: I cleaned the solution before each compilation. So this is probably not the fault.</p>
  
  <p>So in conclusion: how do I suppress the C4706 exactly at this place?</p>
  
  <p><strong>Edit</strong> Yes, rewriting is possible - but I really want to know why the way I try to suppress the warning (that is documented officially on MSDN) doesn't work - where is the mistake?</p>