What is the difference between BOOL and bool?(BOOL 和 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 是 Microsoft 特定的类型,定义为一个 int.您可以在 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 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:BOOL 和 bool 有什么区别?
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
