BOOL, BOOLEAN, bool

在Windows Driver编程中我们看到很多人混用 BOOL, BOOLEAN。究竟他们有什么区别呢?

定义

// define in minwindef.h
typedef int BOOL;

// define in winnt.h
typedef BYTE BOOLEAN;

这两个变量定义在不同头文件中。从定义我们可以看到BOOL实际上是int型占4个字节,BOOLEAN是unsigned char类型占一个字节。

//define in minwindef.h

#ifndef FALSE
#define FALSE               0
#endif

#ifndef TRUE
#define TRUE                1
#endif

对于BOOL, BOOLEAN变量我们一般对其用大写FALSE, TRUE进行赋值而不用false, true。从定义可以看出他们是宏分别代表0和1。

对于bool,和BOOL BOOLEAN不同它是一个c++的关键字,对其进行赋值请使用小写的false, true.

posted @ 2016-12-14 16:38  橙成  阅读(463)  评论(0)    收藏  举报