BOOL和bool有什么区别? [英] What is the difference between BOOL and bool?
问题描述
在VC ++中,我们的数据类型"BOOL"可以假定值为TRUE或FALSE,而我们的数据类型"bool"可以假定值为True或false.
In VC++ we have the data type "BOOL" which can assume the value TRUE or FALSE, and we have the data type "bool", which can assume the value true or false.
它们之间有什么区别,何时应使用每种数据类型?
What is the difference between them and when should each data type be used?
推荐答案
bool
是内置的C ++类型,而BOOL
是定义为int
的Microsoft特定类型.您可以在windef.h
中找到它:
bool
is a built-in C++ type while BOOL
is a Microsoft specific type that is defined as an int
. You can find it in windef.h
:
typedef int BOOL;
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
bool
的值是true
和false
,而对于BOOL
,您可以使用任何int
值,尽管TRUE
和FALSE
宏在windef.h
标头中定义
The values for a bool
are true
and false
, whereas for BOOL
you can use any int
value, though TRUE
and FALSE
macros are defined in the windef.h
header.
这意味着sizeof
运算符将为bool
产生1(尽管标准状态是bool
的大小由实现定义),而对于BOOL
则产生4.
This means that the sizeof
operator will yield 1 for bool
(the standard states, though, that the size of bool
is implementation defined), and 4 for BOOL
.
来源: Codeguru文章
这篇关于BOOL和bool有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!