c語言自定義BOOL函數


C語言中沒有BOOL類型變量,它是C++獨有的,由於使用BOOL類型可以使代碼更具有可讀性,很多編程者都在C中自己定義了類似的應用,一般方法有兩種:

第一種:采用宏定義方式

typedef int BOOL;

#define  true 1

#define false 0

或寫為:

#ifndef bool

#define bool int

#endif

#ifndef true
#define true 1
#endif


#ifndef false
#define false 0
#endif

第二種:采用枚舉型變量方式

typedef enum{false=0,true}BOOL;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM