BOOL和bool的区别

来源:互联网 发布:淘宝精仿手表 编辑:程序博客网 时间:2024/05/02 20:07

[转]BOOL和bool的区别

1、类型不同
 
  BOOL为int型
 
  bool为布尔型
 
  2、长度不同
  bool只有一个字节
 
  BOOL长度视实际环境来定,一般可认为是4个字节
  3、取值不同
 
  bool取值false和true,是0和1的区别; false可以代表0,但true有很多种,并非只有1。
 
  如果数个bool对象列在一起,可能会各占一个bit,这取决于编译器。
 
  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.
 
http://blog.sina.com.cn/s/blog_5d97bfa40100wbgp.html
原创粉丝点击