Re: bool or BOOL in MFC projects

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Wed, 19 Dec 2007 11:02:55 -0500, David Wilkinson <no-reply@xxxxxxxxxxxx>
wrote:

Joseph M. Newcomer wrote:
But if(p) is a type violation.

Conversion of pointer to bool is an accepted feature of the C++
language. It is used, for example in the idiom

int i;
while (cin >> i)
{
// do something to i
}

(std::ios has conversion to void*, not to bool).

Ironically, the conversion to bool has more undesirable side effects than
the conversion to void*, mainly because bools can be used in arithmetic
expressions.

--
Doug Harrison
Visual C++ MVP
.



Relevant Pages

  • void * instead of bool
    ... Why is there void* conversion to check for std::istream failure bit? ... When I try to return an istream from a function that actually returns bool, ... I get the following warning: ...
    (comp.lang.cpp)
  • Re: I Need an IsNumeric Method
    ... public bool IsNumeric ... //Try a double conversion. ... try to convert and catch the exception ... > o Don't forget that .5 is generally considered okay, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Testing for nullptr for a ref object
    ... I'm must admit I haven't read much of the C++/CLI standard. ... my interpretation is that the compiler will consider a conversion ... from x to bool better than the check against nullptr. ... So if a conversion from x to bool exists it will be chosen over the ...
    (microsoft.public.dotnet.languages.vc)
  • Re: boolean usage
    ... "An object declared as type _Bool is large enough to store the ... That mearely constrains the values that result from conversion. ... The width includes any padding bits. ... "The precision of an integer type is the number of bits it uses ...
    (comp.lang.c)
  • Re: void * instead of bool
    ... If you have a conversion to bool then the following nonsense would compile ... Conversion to void* is less likely to be called accidentally. ... > (performance warning) ...
    (comp.lang.cpp)