<bdo id='qT7zY'></bdo><ul id='qT7zY'></ul>
  1. <i id='qT7zY'><tr id='qT7zY'><dt id='qT7zY'><q id='qT7zY'><span id='qT7zY'><b id='qT7zY'><form id='qT7zY'><ins id='qT7zY'></ins><ul id='qT7zY'></ul><sub id='qT7zY'></sub></form><legend id='qT7zY'></legend><bdo id='qT7zY'><pre id='qT7zY'><center id='qT7zY'></center></pre></bdo></b><th id='qT7zY'></th></span></q></dt></tr></i><div id='qT7zY'><tfoot id='qT7zY'></tfoot><dl id='qT7zY'><fieldset id='qT7zY'></fieldset></dl></div>

    <small id='qT7zY'></small><noframes id='qT7zY'>

      <tfoot id='qT7zY'></tfoot>
      <legend id='qT7zY'><style id='qT7zY'><dir id='qT7zY'><q id='qT7zY'></q></dir></style></legend>

      Objective-C:BOOL vs bool

      时间:2023-10-05

      <i id='64WLL'><tr id='64WLL'><dt id='64WLL'><q id='64WLL'><span id='64WLL'><b id='64WLL'><form id='64WLL'><ins id='64WLL'></ins><ul id='64WLL'></ul><sub id='64WLL'></sub></form><legend id='64WLL'></legend><bdo id='64WLL'><pre id='64WLL'><center id='64WLL'></center></pre></bdo></b><th id='64WLL'></th></span></q></dt></tr></i><div id='64WLL'><tfoot id='64WLL'></tfoot><dl id='64WLL'><fieldset id='64WLL'></fieldset></dl></div>
      <legend id='64WLL'><style id='64WLL'><dir id='64WLL'><q id='64WLL'></q></dir></style></legend>
        <tbody id='64WLL'></tbody>
        • <bdo id='64WLL'></bdo><ul id='64WLL'></ul>
            • <tfoot id='64WLL'></tfoot>

                <small id='64WLL'></small><noframes id='64WLL'>

                本文介绍了Objective-C:BOOL vs bool的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我看到了新类型"BOOL(YESNO).

                I saw the "new type" BOOL (YES, NO).

                我读到这种类型几乎就像一个字符.

                I read that this type is almost like a char.

                为了测试我做了:

                NSLog(@"Size of BOOL %d", sizeof(BOOL));
                NSLog(@"Size of bool %d", sizeof(bool));
                

                很高兴看到两个日志都显示1"(有时在 C++ 中 bool 是一个 int 而它的 sizeof 是 4)

                Good to see that both logs display "1" (sometimes in C++ bool is an int and its sizeof is 4)

                所以我只是想知道 bool 类型是否有问题?

                So I was just wondering if there were some issues with the bool type or something ?

                我可以只使用 bool(这似乎有效)而不会降低速度吗?

                Can I just use bool (that seems to work) without losing speed?

                推荐答案

                objc.h中的定义:

                #if (TARGET_OS_IPHONE && __LP64__)  ||  TARGET_OS_WATCH
                typedef bool BOOL;
                #else
                typedef signed char BOOL; 
                // BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C" 
                // even if -funsigned-char is used.
                #endif
                
                #define YES ((BOOL)1)
                #define NO  ((BOOL)0)
                

                所以,是的,您可以假设 BOOL 是一个字符.您可以使用 (C99) bool 类型,但 Apple 的所有 Objective-C 框架和大多数 Objective-C/Cocoa 代码都使用 BOOL,因此如果 typedef 只改变使用 BOOL.

                So, yes, you can assume that BOOL is a char. You can use the (C99) bool type, but all of Apple's Objective-C frameworks and most Objective-C/Cocoa code uses BOOL, so you'll save yourself headache if the typedef ever changes by just using BOOL.

                这篇关于Objective-C:BOOL vs bool的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Android:如何检查 Google 是否可用? 下一篇:在objective-c中YES/NO,TRUE/FALSE和true/false之间有区别吗?

                相关文章

                <tfoot id='p4Tyz'></tfoot>

              1. <i id='p4Tyz'><tr id='p4Tyz'><dt id='p4Tyz'><q id='p4Tyz'><span id='p4Tyz'><b id='p4Tyz'><form id='p4Tyz'><ins id='p4Tyz'></ins><ul id='p4Tyz'></ul><sub id='p4Tyz'></sub></form><legend id='p4Tyz'></legend><bdo id='p4Tyz'><pre id='p4Tyz'><center id='p4Tyz'></center></pre></bdo></b><th id='p4Tyz'></th></span></q></dt></tr></i><div id='p4Tyz'><tfoot id='p4Tyz'></tfoot><dl id='p4Tyz'><fieldset id='p4Tyz'></fieldset></dl></div>
                  <bdo id='p4Tyz'></bdo><ul id='p4Tyz'></ul>

                  1. <small id='p4Tyz'></small><noframes id='p4Tyz'>

                    <legend id='p4Tyz'><style id='p4Tyz'><dir id='p4Tyz'><q id='p4Tyz'></q></dir></style></legend>