bool t1 =1;//true or false
BOOL t2 = 3;//YES or NO
Boolean t3 =1; //unsigned char type
boolean_t t4 = 1;//int type
NSAssert(t1,@"bool t1 is NO");//通过测试
NSAssert(t2,@"BOOL t2 is NO");//通过测试
NSAssert(t3,@"Boolean t3 is NO");//通过测试
NSAssert(t4,@"boolean_t t4 is NO");//通过测试
bool 是int型,bool b 当b!=0 有 b=true
BOOL 是unsigned
char型,BOOL b 当b=1 有 b=YES
Boolean
是char型
boolean_t
是int型
注意:上述类型作为判断条件时只要变量值不为零,则条件成立。

本文详细解析了C语言中的bool类型与Objective-C中的BOOL类型的实现方式及其区别。介绍了bool作为int类型,非零即真;BOOL为unsigned char类型,1代表YES;Boolean为char类型;boolean_t为int类型的特点。
7965

被折叠的 条评论
为什么被折叠?



