# Difference between bool and BOOL

### Question

• Similarly, there is double and DOUBLE where the lower case is highlighted by VS.

Can someone tell me the difference?
Friday, June 26, 2009 5:37 PM

• The type "bool" is a fundamental C++ type that can take on the values "true" and "false". When a non-bool x is converted to a bool, non-zero becomes true and zero becomes false, as if you had written x != 0. When bool is converted to non-bool, true becomes 1 and false becomes 0.

The type "BOOL" is a Windows type, and it's just a typedef for int. As such, it can assume all values of int, with non-zero meaning true and zero meaning false, and it behaves exactly like int, because it is int. Therefore, it would normally be erroneous to compare a BOOL to TRUE, because usually any non-zero value of BOOL is considered true. (You shouldn't compare a bool to true as it is redundant.) Also, if you assign a BOOL to a narrower type T, there can be truncation, and a non-zero (true) BOOL value can end up a T equal to zero (false).

As for DOUBLE vs. double, searching the Windows headers reveals it's just a typedef for double.

Doug Harrison (Visual C++ MVP)
• Marked as answer by Friday, June 26, 2009 6:46 PM
Friday, June 26, 2009 6:38 PM

### All replies

• The type "bool" is a fundamental C++ type that can take on the values "true" and "false". When a non-bool x is converted to a bool, non-zero becomes true and zero becomes false, as if you had written x != 0. When bool is converted to non-bool, true becomes 1 and false becomes 0.

The type "BOOL" is a Windows type, and it's just a typedef for int. As such, it can assume all values of int, with non-zero meaning true and zero meaning false, and it behaves exactly like int, because it is int. Therefore, it would normally be erroneous to compare a BOOL to TRUE, because usually any non-zero value of BOOL is considered true. (You shouldn't compare a bool to true as it is redundant.) Also, if you assign a BOOL to a narrower type T, there can be truncation, and a non-zero (true) BOOL value can end up a T equal to zero (false).

As for DOUBLE vs. double, searching the Windows headers reveals it's just a typedef for double.

Doug Harrison (Visual C++ MVP)
• Marked as answer by Friday, June 26, 2009 6:46 PM
Friday, June 26, 2009 6:38 PM
• Very thorough explaination!!
Thanks a lot!
Friday, June 26, 2009 6:46 PM
• BOOL is invented before bool is standardized, and will probably remain to be defined as int to provide backword campatibility.
the underline type of other windows types like WPARAM change over time though.