Cocoa中存在哪些定义(例如__LP64__和__arm64__),它们可以在编译时区分平台?它们在何处或如何定义? [英] What definitions exist like __LP64__ and __arm64__ in Cocoa that differentiate platforms at compile time? Where or how are they defined?

查看:132
本文介绍了Cocoa中存在哪些定义(例如__LP64__和__arm64__),它们可以在编译时区分平台?它们在何处或如何定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着 arm64 作为 iphoneos 平台的标准体系结构的引入,在某些情况下有必要为64/32体系结构.

With the introduction of arm64 as a standard architecture for the iphoneos platform it's necessary in some cases to implement compile-time conditions for code that is specific to the 64/32 architecture.

如果您查看 CoreGraphics/CGBase.h 以及一些流行的开源项目是如何提供对arm64的支持很明显,您可以像下面这样检查64位运行时的存在:

If you look at CoreGraphics/CGBase.h and how some popular open source projects are providing support for arm64 it's clear that you can check for the presence of the 64bit runtime like so:

#if defined(__LP64__) && __LP64__
...
#else
...
#endif

还可以专门检查 arm64 (而不是仅检查64位运行时),如

It's also possible to check specifically for arm64 (as opposed to just a 64bit runtime) as mentioned in this fix for erikdoe/ocmock

#ifdef __arm64__
...
#else
....
#endif

是否有关于这些定义的完整列表或文档?他们在哪里定义或如何?

Is there a comprehensive list, or documentation for these kinds of definitions? Where or how are they defined?

推荐答案

这些宏不是特定于Cocoa的,而是特定于CLANG的,可以在命令行上用以下命令列出:

Those macros are not specific to Cocoa, they are specific to CLANG, and they can be listed on the command line with:

clang -dM -E -x c /dev/null

不同的CLANG版本附带不同数量的功能标志,这些功能标志可以在配置时打开或关闭,或者取决于编译器在哪个平台和操作系统上运行.可以在其测试标头,每个受支持系统的变体也分散在测试目录中.每个文档的文档取决于该标志是特定于CLANG还是在链接的标准库之一中定义(例如, __ llvm __

Different CLANG versions ship with varying amounts of feature flags which can get turned on and off at configuration time or depending on which platform and OS the compiler is running on. A fairly comprehensive list can be found in their testing headers with variants for each supported system also scattered around in the testing directory. Documentation for each depends on whether the flag is specific to CLANG, or defined in one of the standard libraries it links against (for example __llvm__ is defined by CLANG, but __WCHAR_WIDTH__ is defined by LibC). There is really no comprehensive list with definitive documentation for this reason. Different platforms are allowed to do things slightly differently so long as they adhere to language specifications.

大多数有趣的公共Objective-C宏都存在于Foundation中,靠近 Foundation/NSObjCRuntime.h 的底部.

The majority of the interesting public Objective-C macros exist in Foundation near the bottom of Foundation/NSObjCRuntime.h.

这篇关于Cocoa中存在哪些定义(例如__LP64__和__arm64__),它们可以在编译时区分平台?它们在何处或如何定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆