Link to home
Start Free TrialLog in
Avatar of has
has

asked on

BOOL vs bool

what is the difference between BOOL (TRUE, FALSE)
and bool (true, false). which to use ? when ? can it be mixed ?
ASKER CERTIFIED SOLUTION
Avatar of Tommy Hui
Tommy Hui

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of has
has

ASKER

thanks
Also note - many MFC functions (and Win32 API functions) expect and return BOOL rather than bool.  If you are writing message handlers that return BOOL, say, don't be tempted to change them to return bool instead.  If you do then your code will break.

However, in your own code, using bool has the advantage that the compiler knows about the type, and will stop you (without a cast) assigning arbitary int values to a bool variable (like you can do with BOOL).  It also ensures the a bool only ever contains 'true' or 'false' (0 or 1).  A BOOL with any non-zero value will test as true, but if you do a comparison with TRUE, you get a fail.

So for compiler error detection, and memory size, go for bool, but always convert to/from BOOL when dealing with MFC and Win32 API.