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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:10:06+00:00 2026-05-15T20:10:06+00:00

I have just installed the Windows SDK v7.1 (MSVC 10.0) and running my code

  • 0

I have just installed the Windows SDK v7.1 (MSVC 10.0) and running my code through (almost) full warning level (W3, default for qmake’s CONFIG += warn_on) and am surprised about warning C4800: 'type' : forcing value to bool 'true' or 'false' (performance warning)

In the following code, stream is an std::istream and token is a std::string.

// in some function returning bool
return (stream >> token) // triggers warning c4800:
                         // '(void *)': forcing value to bool 'true' or 'false' (performance warning)`
// somewhere else
if( stream >> token ) // does not trigger warning c4800

What is going on here? I don’t even get why the warning is triggered in the first place. I thought the first bit of code already returned a bool anyways.

I understand this is nitpicking and the warning shouldn’t even exist, but it’s the only one in my code between MSVC’s /W3 and gcc’s -Wall -pedantic, so I’d like to know 🙂

SMALL UPDATE: I understand that the warning is designed to let you know you’re assuming int->bool conversion, but 1) why would you even still use bool (==typedef int mostly) and 2) why would an if(2) not convert 2 to true or false, I thought that was the whole idea of a predicate, being true or false.

  • 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-15T20:10:07+00:00Added an answer on May 15, 2026 at 8:10 pm

    What is going on here? I don’t even get why the warning is triggered in the first place. I thought the first bit of code already returned a bool anyways.

    1. Streams have an implicit conversion operator that returns a void*. (That’s a version of the safe bool idiom. It’s done this way because there is less contexts in which void* compiles than bool, so there’s less contexts in which the implicit conversion could kick in unwanted.)[1]

    2. Streams’ operator>>() returns a reference to its left operand – the stream. That’s so you can chain input operations: strm >> value1 >> value2 is executed as ((strm >> value1) >> value2).

    Now, when you say if( strm >> value ), strm >> value is executed and a stream returned. In order to put that into an if statement, the implicit conversion into void* is performed, and that pointer is then checked for being NULL or not.
    That’s no different from if(ptr), the if statement implicit converts its condition to bool, but compilers would never warn about that, because the condition not being a bool is so common.

    With the return, this is different. If you want to return a certain type, usually the expression you return should be of that type. VC’s warning is quite annoying and for me in 99 out of 100 times it was superfluous. But the remaining 1% (never a performance concern, BTW; I think that is silly about the warning) made me glad the warning is there.

    The workaround for this warning is to

    return 0 != <expression>
    

    where <expression> is whatever you think should be considered a boolean value.

    [1] ISTR Stroustrup writing somewhere that an operator bool() would silently compile if you messed up the operators: ostrm >> 5; (note the >> instead of <<) would compile fine, but silently do the wrong thing. (It converts the boolean to an integer and right-shifts that 5 times, then discard the value.)

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

Sidebar

Related Questions

I have just installed the Platform SDK for Windows Server 2008 and .NET 3.5
I just installed apache (1.3.33) via cygwin running on Windows XP. I have the
Have just installed docblox on windows using PEAR. Am running into the error 'can
I have just installed Git For Windows , and created my SSH key using
I have just installed Java JDK 6u33 in Windows XP. Even though I didn't
I have just installed that latest stable release of TortoiseSVN on Windows Server 2003
I have just installed SQL Server 2008 including Reporting Services on Windows Server 2003.
O/S: Windows 7 ,Home Premium I have just installed IIS manager Express from Web
I have the problem I just installed the new Monodevelop 2.2.2 on Windows but
I have just installed OpenCV on my Windows 7 machine. As a result, I

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.