bool和BOOL有什么区别

如题所述

第1个回答  推荐于2016-08-26
BOOL和bool
1、类型不同
bool为布尔型用作逻辑判断
BOOL在<windef.h>typedef int BOOL;
在<wtypes.h>typedef long BOOL;
2、长度不同
bool只有一个字节
BOOL长度视实际环境来定,一般可认为是4个字节
3、取值不同
bool取值false和true,是0和1的区别; false可以代表0,但true有很多种,并非只有1。
如果数个bool对象列在一起,可能会各占一个Byte,这取决于编译器。
BOOL是微软定义的typedef int BOOL(在windef.h中)。与bool不同,它是一个三值逻辑,
TRUE/FALSE/ERROR,返回值为大于0的整数时为TRUE,返回值为0时候,为FALSE,返回值为-1时为ERROR。
Win32 API中很多返回值为BOOL的函数都是三值逻辑。比如GetMessage().
BOOL GetMessage(
LPMSG lpMsg, // message information
HWND hWnd, // handle to window
UINT wMsgFilterMin, // first message
UINT wMsgFilterMax // last message);
If the function retrieves a message other than WM_QUIT, the return value is nonzero.
If the function retrieves the WM_QUIT message, the return value is zero.
If there is an error, the return value is -1.本回答被提问者和网友采纳
相似回答