在iOS開發(fā)中總能看見__has_feature
宏,最常見的例如__has_feature(objc_arc)
,表示支持自動(dòng)引用計(jì)數(shù)機(jī)制(ARC),類似的還有objc_arc_weak
、objc_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
等
__has_feature
支持哪些參數(shù)湿故,可以看一下Clang源碼PPMacroExpansion.cpp
文件中的HasFeature
方法阿趁,在文件的855行到1005行,方法再結(jié)合文檔坛猪,基本可以熟練的使用這個(gè)宏了