BOOL和bool的區別

來源:互聯網
上載者:User

轉自:http://www.cppblog.com/Lee7/archive/2008/12/14/69394.html

一、
1、類型不同
BOOL為int型
bool為布爾型
2、長度不同
bool只有一個位元組
BOOL長度視實際環境來定,一般可認為是4個位元組
3、取值不同
bool取值false和true,是0和1的區別
BOOL取值FALSE和TRUE,是0和非0的區別
二:
bool是標準C++資料類型,可取值true和false。單獨佔一個位元組,
如果數個bool對象列在一起,可能會各佔一個bit,這取決於編譯器。
BOOL是微軟定義的typedef int BOOL。與bool不同,它是一個三值邏輯,
TRUE/FALSE/ERROR,傳回值為>0的整數為TRUE,0為FALSE,-1為ERROR。
Win32 API中很多傳回值為BOOL的函數都是三值邏輯。比如GetMessage().
三:
大BOOL和小bool之間的區別:
1、類型不同
BOOL為int型
bool為布爾型
2、長度不同
bool只有一個位元組
BOOL長度視實際環境來定,一般可認為是4個位元組
3、取值不同
bool取值false和true,是0和1的區別
BOOL取值FALSE和TRUE,是0和非0的區別
4、例子
bool x=3;  //警示
bool x=1;  //正確
BOOL x=3;  //正確
BOOL x=3.3;  //警示
註:windows為了相容問題定義的基礎變數。
typedef unsigned long        DWORD;
typedef int                  BOOL;
typedef unsigned char        BYTE;
typedef unsigned short      WORD;
typedef float                FLOAT;
typedef FLOAT                *PFLOAT;
typedef BOOL near            *PBOOL;
typedef BOOL far            *LPBOOL;
typedef BYTE near            *PBYTE;
typedef BYTE far            *LPBYTE;
typedef int near            *PINT;
typedef int far              *LPINT;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.