美文网首页工程架构
__has_feature详解

__has_feature详解

作者: Miridescent | 来源:发表于2018-06-14 15:51 被阅读63次

在iOS开发中总能看见__has_feature宏,最常见的例如__has_feature(objc_arc),表示支持自动引用计数机制(ARC),类似的还有objc_arc_weakobjc_arc_fields
__has_feature在Clang文档中的定义是这样的

__has_feature and __has_extension
These function-like macros take a single identifier argument that is the name of a feature. __has_feature evaluates to 1 if the feature is both supported by Clang and standardized in the current language standard or 0 if not (but see below), while __has_extension evaluates to 1 if the feature is supported by Clang in the current language (either as a language extension or a standard language feature) or 0 if not. They can be used like this:

大致的意思是通过给定的值,判断编译器是否支持该特性
类似的特性检测宏还有__has_builtin__has_attribute等,他们都属于Feature Checking Macros
类似的还有Include File Checking Macros大类的宏定义,用于检测是否包含文件,常见的有 __has_include

Clang Language Extensions文档连接

__has_feature支持哪些参数,可以看一下Clang源码PPMacroExpansion.cpp文件中的HasFeature方法,在文件的855行到1005行,方法再结合文档,基本可以熟练的使用这个宏了

PPMacroExpansion.cpp文件代码连接

相关文章

  • __has_feature详解

    在iOS开发中总能看见__has_feature宏,最常见的例如__has_feature(objc_arc),表...

  • iOS 单例宏

    #if __has_feature(objc_arc) #define SYNTHESIZE_SINGLETON_...

  • #if ! __has_feature(objc_arc)#warning This file must be c...

  • __has_feature

    https://www.jianshu.com/p/79c98dd0fbca

  • __has_feature总结

    持续更新中..... objc_arc 解释:ARC支持 objc_class_property 解释:类属性SD...

  • LLVM __has_feature

    今天在项目中遇到了__has_feature(objc_arc)宏,通过查找文档发现该宏语句是用来判断clang(...

  • ARC的判断

    可以用宏判断是否为ARC环境 #if __has_feature(objc_arc) // ARC #else /...

  • 关于iOS weakify 和 strongify _Pragm

    关于iOS weakify 和 strongify 的解释 进行相关的解释说明__has_feature:某些特性...

  • iOS中arc的设置与使用

    先记录一下,宏定义判断是否支持arc#if ! __has_feature(objc_arc) 原文链接 http...

  • 我眼中的开源库源码之JSONModel(二)

    我们接着上回的思路看,上面第一行就是一个条件编译。 #if !__has_feature(objc_arc)#er...

网友评论

    本文标题:__has_feature详解

    本文链接:https://www.haomeiwen.com/subject/rhdyeftx.html