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 ?
and bool (true, false). which to use ? when ? can it be mixed ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER