Re: bool or BOOL in MFC projects
- From: "David Webber" <dave@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 19 Dec 2007 09:22:44 -0000
"David Lowndes" <DavidL@xxxxxxxxxxxxxxx> wrote in message news:kfrgm35tmrvee99ei8pgh9k5uq5vtdd3b0@xxxxxxxxxx
I recall being bitten by code like this:
if ( Api() == TRUE )
{..
}
... which failed under Windows 95 because the API returned a non-zero
value rather than TRUE.
A few thoughts:
Yes. In fact I avoid "==TRUE" like the plague, and by extension "==true" though that should be safer I guess.
But the whole point of the Boolean concept is that you can use
BOOL b;
....
if( b )
Writing if( b==TRUE ) is a tautology in the sense that "b==TRUE" is an expression which (in principle) evaluates to a Boolean, which you are then testing with if() :-)
In fact, correct me if I am wrong, expressions comparing integers a<b a==b return an integer 1 or 0 don't they? My 1991 copy of Stroustrup predates "bool", and so I am never sure about things like this :-) They haven't changed it have they? If not, the BOOL concept appears implicit in the language, even if it is Windows which actually defines the type BOOL.
[I vaguely remember that a==b was not at one stage required to return 1 if true, but maybe that is prehistory.]
Anyway the ability of the if( ... ) to accept or reject the operand on the basis of being zero or non-zero is one of the extremely useful facets of C/C++ and I would never write for a pointer p if( p==NULL ) or the other favourite if( NULL==p ) because if( p ) is perfectly clear!
Just my 2d worth,
Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
.
- Follow-Ups:
- Re: bool or BOOL in MFC projects
- From: David Lowndes
- Re: bool or BOOL in MFC projects
- From: Joseph M . Newcomer
- Re: bool or BOOL in MFC projects
- References:
- bool or BOOL in MFC projects
- From: Vaclav
- Re: bool or BOOL in MFC projects
- From: Stuart Redmann
- Re: bool or BOOL in MFC projects
- From: David Ching
- Re: bool or BOOL in MFC projects
- From: Ian Semmel
- Re: bool or BOOL in MFC projects
- From: Brian Muth
- Re: bool or BOOL in MFC projects
- From: David Lowndes
- bool or BOOL in MFC projects
- Prev by Date: Re: bool or BOOL in MFC projects
- Next by Date: Re: bool or BOOL in MFC projects
- Previous by thread: Re: bool or BOOL in MFC projects
- Next by thread: Re: bool or BOOL in MFC projects
- Index(es):
Relevant Pages
|