bool & BOOL
-
bool
uses 1 byte. It is a data type built into the compiler.BOOL
uses 4 bytes. it is a type definition of anint
in the filewindef.h
.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
BOOL
was a workaround used before compilers supportedbool
(or for use in C, which doesn't supportbool
).BOOL
isn't actually a distinct type but a synonym forint
:// From "WINDEF.H":
typedef int BOOL;Similarly, the constants
TRUE
andFALSE
are just#defines
for the numbers 1 and 0. On the other handbool
is a type.Steve
-
1、BOOL is Microsoft's macro . In fact, is only 4 bytes of int type. This definitions ,you can find it in the VC setup directory (WINDEF.h、AFX.H), It can be found this following code:
// 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 0bool is C/C + + keywords, about MSDN2005 help document, explained below: 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!=0 now 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、Define BOOL and bool of the reasons. In the memory space,the true、false、null is occupying 1 bytes.But TRUE、FALSE、NULL is occupying 4 bytes. According to the Intel CPU's paging memory mechanism, 4 bytes can prevent memory inattentive, it can prevent to produce more ram pieces,and help the data transmission. ;P