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 486159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:28:30+00:00 2026-05-13T01:28:30+00:00

This question extends Why use !! when converting int to bool? . I thought

  • 0

This question extends Why use !! when converting int to bool?.

I thought I was being cool when I did something like:

bool hasParent() {
    return this->parentNode;
}

Where this->parentNode is NULL when there is no parent node.

But I’m getting:

warning C4800: ‘Node *’ : forcing value to bool ‘true’ or ‘false’ (performance warning)

Even with a (bool) cast, the warning still doesn’t go away.

What’s the deal, yo? Why is that a performance warning? I thought it’d be less efficient to write something like:

bool hasParent() {
    if (this->parentNode)
        return true;
    else
        return false;
}

But the second version generates no warnings and the compiler seems a lot happier. Which is faster though?

  • 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-13T01:28:30+00:00Added an answer on May 13, 2026 at 1:28 am

    There’s a discussion on Microsoft Connect about this (What is the performance implication of converting to bool in C++?). The example given to Microsoft is:

    $ cat -n t.cpp && cl -c -W3 -O2 -nologo -Fa t.cpp
    1 bool f1 (int i)
    2 {
    3 return i & 2;
    4 }
    5
    6 bool f2 (int i)
    7 {
    8 const bool b = i & 2;
    9 return b;
    10 }
    11
    12 bool f3 (int i)
    13 {
    14 const bool b = 0 != (i & 2);
    15 return b;
    16 }
    t.cpp
    t.cpp(3) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
    t.cpp(8) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
    

    And Microsoft’s response (from the developer responsible for the warning) is:

    This warning is surprisingly helpful, and found a bug in my code just yesterday. I think Martin is taking “performance warning” out of context.

    It’s not about the generated code, it’s about whether or not the programmer has signalled an intent to change a value from int to bool. There is a penalty for that, and the user has the choice to use “int” instead of “bool” consistently (or more likely vice versa) to avoid the “boolifying” codegen. The warning is suppressed in the third case below because he’s clearly signalled his intent to accept the int->bool transition.

    It is an old warning, and may have outlived its purpose, but it’s behaving as designed here

    So basically the MS developer seems to be saying that if you want to ‘cast’ an int to bool you should more properly do it by using “return this->parentNode != 0” instead of an implicit or explicit cast.

    Personally, I’d be interested to know more about what kind of bugs the warning uncovers. I’d think that this warning wouldn’t have a whole lot of value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 231k
  • Answers 231k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the following function like this: Image('/path/to/original.image', '1/1', '150*', './thumb.jpg');… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer Check you database schema to see if the field (referenced… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer I figured out the problem - there was a session… May 13, 2026 at 2:13 am

Related Questions

I have a Java JDBC application that uses multiple threads to retrieve information from
i'm trying to understand java behaviour. Using this interfaces : public interface IA {}
I have read in many places that network connection in a j2me app should
Just got a question about generics, why doesn't this compile when using a generic
Consider the following: package MyApp::CGI; use Moose; use MooseX::NonMoose; use Data::Dumper; extends 'CGI::Application'; BEGIN

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.