Objective-C中的bool,Boolean和BOOL之间有什么区别吗? [英] Is there any difference between bool, Boolean, and BOOL in Objective-C?
问题描述
我知道BOOL实际上是带符号char的typedef,但是布尔值呢?
I know BOOL is actually a typedef of signed char, but what about Boolean?
bool,Boolean和BOOL有什么区别?
What is the difference between bool, Boolean and BOOL?
推荐答案
Boolean
是旧的Carbon关键字(历史Mac类型),定义为unsigned char
. BOOL
是定义为signed char
的Objective-C类型. bool
是_Bool
标准C类型的定义版本.它定义为int
.使用BOOL
.
Boolean
is an old Carbon keyword (historic Mac type), defined as an unsigned char
. BOOL
is an Objective-C type defined as signed char
. bool
is a defined version of the _Bool
standard C type. It's defined as an int
. Use BOOL
.
编辑(2019):苹果在某些新文档中讨论了BOOL
的基础实现.基本上,在macOS上,BOOL
最终仍然是signed char
,但是在iOS和相关平台上,它下面是本机C bool
.
Edit (2019): Apple talks about the underlying implementation of BOOL
in some new documentation. Basically, on macOS, BOOL
is still ultimately a signed char
, but on iOS and related platforms, it a native C bool
underneath.
这篇关于Objective-C中的bool,Boolean和BOOL之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!