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

  • Home
  • SEARCH
  • 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 668379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:01:59+00:00 2026-05-14T00:01:59+00:00

I like (bool) way more, but it generates warnings. How do i get rid

  • 0

I like (bool) way more, but it generates warnings. How do i get rid off the warnings?

I have code like:

bool something_else = 0;

void switcher(int val = -1){
    if(val != -1){
        something_else = (bool)val;
    }else{
        something_else ^= 1;
    }
}

Should i just do it like everyone else and use ‘!!’ or make it somehow hide the warning messages when using (bool) ? Or is ‘!!’ actually faster than (bool) ?

I would like to use (bool) and so i have to hide the warning, but how?

Edit: Visual Studio 2008 i am using, sorry i forgot to tell.

Edit 2: The warning message is warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) And it comes on the line something_else = (bool)val; And on the line something_else = val; But not on the line something_else = !!val;

The problem is, i want it to respect that i want to convert it to boolean. I dont want to hide all boolean warnings, because sometimes they saved my ass.

  • 1 1 Answer
  • 1 View
  • 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-14T00:02:00+00:00Added an answer on May 14, 2026 at 12:02 am

    another way:

    switch (val) {
      case -1: something_else = !something_else; break;
      case  0: something_else = false; break;
      default: something_else = true; break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code goes something like this: protected bool IsOKToSend() { bool IsOK = true;
I have a class like so: public class ClassA { public bool MethodA() {
I want to pass some parameters to my MVC UserControl like ShowTitle(bool) and the
Like the Delicious submission bookmark-let, I'd like to have some standard JavaScript I can
Like most *nix people, I tend to play with my tools and get them
Is there any way to make a function call only once? Suppose I have
I wasn't sure how to word the question but I would like to step
Like many others on this site I am considering a move to ASP.NET MVC
Like it says.
Like many of you, I use ReSharper to speed up the development process. When

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.