{"id":41713,"date":"2024-01-09T14:48:09","date_gmt":"2024-01-09T19:48:09","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=41713"},"modified":"2024-01-10T14:46:57","modified_gmt":"2024-01-10T19:46:57","slug":"is-objective-c-bool-a-boolean-type","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/01\/09\/is-objective-c-bool-a-boolean-type\/","title":{"rendered":"Is Objective-C BOOL a Boolean Type?"},"content":{"rendered":"<p><a href=\"https:\/\/www.jviotti.com\/2024\/01\/05\/is-objective-c-bool-a-boolean-type-it-depends.html\">Juan Cruz Viotti<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.jviotti.com\/2024\/01\/05\/is-objective-c-bool-a-boolean-type-it-depends.html\">\n<p>While <code>BOOL<\/code> might look trivial, its definition is\n        rather complex. It depends on which Apple platform and\n        architecture you are targeting, which can result in unexpected\n        behavior.<\/p>\n<p>[&#8230;]<\/p>\n<p>Recently, I stumbled into a case where for the same code, macOS Intel and macOS Apple Silicon invoked different overloads.<\/p>\n<p>[&#8230;]<\/p>\n<p>As we can see, the <code>BOOL<\/code> type is either an alias\n        to <code>bool<\/code> or an alias to <code>signed char<\/code>\n        depending on the value of the <code>OBJC_BOOL_IS_BOOL<\/code>\n        preprocessor define.<\/p>\n<p>[&#8230;]<\/p>\n<p>More than a decade later, as part of the C99 specification,\n        the C language released support for boolean values through the\n        <a href=\"https:\/\/pubs.opengroup.org\/onlinepubs\/9699919799\/basedefs\/stdbool.h.html\"><code>&lt;stdbool.h&gt;<\/code><\/a>\n        header. Then, later versions of the Objective-C runtime started\n        conditionally aliasing <code>BOOL<\/code> to the new\n        <code>bool<\/code> type in modern Apple products. It is likely\n        that older platform and architecture combinations still use\n        <code>signed char<\/code> for legacy reasons.<\/p>\n<\/blockquote>\n\n<p id=\"is-objective-c-bool-a-boolean-type-update-2024-01-10\">Update (2024-01-10): <a href=\"https:\/\/twitter.com\/gparker\/status\/1745034724421308858\">Greg Parker<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/gparker\/status\/1745034724421308858\"><p>BOOL&rsquo;s type and sign-edness affect Objective-C type encodings, which are used by NSArchives and Distributed Objects and others, which affects binary and data file compatibility. BOOL&rsquo;s type also affects C and C++ function calls and data structures. It&rsquo;s not easy to change.<\/p><\/blockquote>\n\n<p>See also: <a href=\"https:\/\/news.ycombinator.com\/item?id=38909377\">Hacker News<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Juan Cruz Viotti: While BOOL might look trivial, its definition is rather complex. It depends on which Apple platform and architecture you are targeting, which can result in unexpected behavior. [&#8230;] Recently, I stumbled into a case where for the same code, macOS Intel and macOS Apple Silicon invoked different overloads. [&#8230;] As we can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2024-01-09T19:48:12Z","apple_news_api_id":"4e57df7e-2fb8-470e-9213-2d73d6ebde03","apple_news_api_modified_at":"2024-01-10T19:46:59Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/ATlfffi-4Rw6SEy1z1uveAw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[46,229,30,2385,54,71],"class_list":["post-41713","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-llvm","tag-mac","tag-macos-14-sonoma","tag-objective-c","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/41713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=41713"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/41713\/revisions"}],"predecessor-version":[{"id":41725,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/41713\/revisions\/41725"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=41713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=41713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=41713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}