BOOL与bool区别
2009-10-14 13:40
405 查看
1、先查看定义:
BOOL是微软定义的宏,实际上是int型占4个字节,该定义位于VC目录下WINDEF.H、AFX.H,可以找到如下代码:
bool是C/C++关键字,关于MSDN2005帮助文档中,解释如下:
This keyword is a built-in type. A variable of this type can have values true and false. Conditional expressions have the type bool and so have values of type bool. For example,
The values true and false have the following relationship:
When a postfix or prefix ++ operator is applied to a variable of type bool, the variable is set to true. The postfix or prefix -- operator cannot be applied to a variable of this type.
The bool type participates in integral promotions. An r-value of type bool can be converted to an r-value of type int, with false becoming zero and true becoming one. As a distinct type, bool participates in overload resolution.
2、定义BOOL与bool原因(TRUE FALSE 与 true false)
在查阅很多资料后,请教了这方面朋友侦探,下面是他的解释如下:
BOOL是微软定义的宏,实际上是int型占4个字节,该定义位于VC目录下WINDEF.H、AFX.H,可以找到如下代码:
// WINDEF.H typedef unsigned long DWORD; typedef int BOOL; typedef unsigned char BYTE; typedef unsigned short WORD; typedef float FLOAT; // AFX.H #define FALSE 0 #define TRUE 1 #define NULL 0
bool是C/C++关键字,关于MSDN2005帮助文档中,解释如下:
This keyword is a built-in type. A variable of this type can have values true and false. Conditional expressions have the type bool and so have values of type bool. For example,
i!=0now has true or false depending on the value of
i.
The values true and false have the following relationship:
When a postfix or prefix ++ operator is applied to a variable of type bool, the variable is set to true. The postfix or prefix -- operator cannot be applied to a variable of this type.
The bool type participates in integral promotions. An r-value of type bool can be converted to an r-value of type int, with false becoming zero and true becoming one. As a distinct type, bool participates in overload resolution.
2、定义BOOL与bool原因(TRUE FALSE 与 true false)
在查阅很多资料后,请教了这方面朋友侦探,下面是他的解释如下:
Koma 12:15:48 C语言中已经有true和false还有null,微软为什么还定义TRUE, FALSE, NULL? 侦探 12:19:42 因为true,false, null内存空间占用1 而TRUE, FALSE, NULL内存空间占用4 侦探 12:20:45 根据intel CPU的内存分页机制,4字节可以防止内存松散,防止产生更多的内存碎片,有利于数据的传输
相关文章推荐
- BOOL和bool的区别
- C#中bool与Boolean有什么区别
- BOOL与bool区别
- c++中BOOL和bool的区别
- BOOL和bool的区别
- PHP 变量函数 empty()、is_null()、isset()、(bool) 的区别
- vc中bool与BOOL的区别
- -(void)viewWillAppear:(BOOL)animated,- (void)viewDidLoad 的区别。
- Bool 和 BOOL 的区别
- BOOL与bool 的区别
- -(void)viewWillAppear:(BOOL)animated,- (void)viewDidLoad 的区别
- MFC中BOOL和bool的区别大不大
- C#中bool与Boolean有什么区别
- BOOL和bool的区别
- C++----练习--bool类型作为特别的int要区别对待
- bool,_Bool和BOOL的区别
- [转载]BOOL和bool的区别
- C++中BOOL和bool的区别
- VC中BOOL和bool的区别
- c++中BOOL和bool的区别