Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6318279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:37:18+00:00 2026-05-24T15:37:18+00:00

When you compile the following C++ source file in Visual Studio 2010 with warning

  • 0

When you compile the following C++ source file in Visual Studio 2010 with warning level /W4 enabled

#include <cstdio>  // for printf
#include <cstring> // for strcmp

char str0[] = "Hello";
char str1[] = "World";

int main()
{
    int result;

    if (result = strcmp(str0, str1)) // line 11
    {
        printf("Strings are different\n");
    }
}

you get the following warning

warning C4706: assignment within conditional expression

for line 11.

I want to suppress this warning exactly at this place. So I tried Google and found this page: http://msdn.microsoft.com/en-us/library/2c8f766e(v=VS.100).aspx

So I changed the code to the following – hoping this would solve the problem:

#include <cstdio>  // for printf
#include <cstring> // 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");
    }
}

It didn’t help.

This variant didn’t help either:

#include <cstdio>  // for printf
#include <cstring> // 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");
    }
}

To avoid one further inquiry: I cleaned the solution before each compilation. So this is probably not the fault.

So in conclusion: how do I suppress the C4706 exactly at this place?

Edit 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:37:18+00:00Added an answer on May 24, 2026 at 3:37 pm

    In MSDN Libray: http://msdn.microsoft.com/en-us/library/2c8f766e(v=VS.100).aspx, There is the section as follows.

    For warning numbers in the range 4700-4999, which are the ones
    associated with code generation, the state of the warning in effect
    when the compiler encounters the open curly brace of a function will
    be in effect for the rest of the function. Using the warning pragma in
    the function to change the state of a warning that has a number larger
    than 4699 will only take effect after the end of the function. The
    following example shows the correct placement of warning pragmas to
    disable a code-generation warning message, and then to restore it.

    So ‘#pragma warning’ only works for an each function/method.

    Please see the following code for more detail.

    #include <cstdio>  // for printf
    #include <cstring> // for strcmp
    
    char str0[] = "Hello";
    char str1[] = "World";
    
    #pragma warning(push)
    #pragma warning( disable : 4706 )
    void func()
    {
        int result;
        if (result = strcmp(str0, str1)) // No warning
        {
            printf("Strings are different\n");
        }
    #pragma warning(pop)
    }
    
    int main()
    {
        int result;
    
        if (result = strcmp(str0, str1)) // 4706 Warning.
        {
            printf("Strings are different\n");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes when i try to build/compile a downloaded source, i get following warning: ld:
Visual Studio 2008 I am using the following source code that compiles ok using
Can someone explain the following behaviour (I'm using Visual Studio 2010). header: #pragma once
I downloaded and compiled CppUnit to compile with Visual Studio 2010. After the conversion,
When trying to compile the following code, I am getting a warning that line
Problem Description: Occassionally when debugging, I get the following error. I'm using visual studio
I have a file Employee.as with the following source code. I am unable to
The following is the content of my source file: Number= 010010 Name= Jan Mayen
I have the following source file (CUDA_Integral_Image.cu) for a class of the same name:
I am trying to compile a Java source file on command prompt with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.