iOS中的UIKIT_EXTERN
2016-02-01 13:41
387 查看
<span style="font-size:18px;">#ifdef __cplusplus #define UIKIT_EXTERN extern "C" __attribute__((visibility ("default"))) #else #define UIKIT_EXTERN extern __attribute__((visibility ("default"))) #endif #define UIKIT_STATIC_INLINE static inline</span>
其中__cplusplus 是cpp中的自定义宏,那么定义了这个宏的话表示这是一段cpp的代码,也就是说,上面的代码的含义是:如果这是一段cpp的代码,那么加入extern"C"和其中的代码。
extern是C/C++语言中表明函数和全局变量作用范围(可见性)的关键字,该关键字告诉编译器,其声明的函数和变量可以在本模块或其它模块中使用。
那extern "C"呢?C++之父在设计C++之时,考虑到当时已经存在了大量的C代码,为了支持原来的C代码和已经写好C库,需要在C++中尽可能的支持C,而
extern "C"就是其中的一个策略。
__attribute__是GNU C的一种机制,用法为_attribute__
((attribute-list))。当项目需要作为一个库被外包引用的时候通常在编译时可以用参数-fvisibility指定所有符号的可见性。在编译命令中加入 -fvisibili
b5c9
ty=hidden参数,会将所有默认的public的属性变为hidden。此时,如果对函数设置__attribute__((visibility ("default")))参数,使特定的函数仍然按默认的public属性处理,则-fvisibility=hidden参数不会对该函数起作用。所以,设置了-fvisibility=hidden参数之后,只有设置了__attribute__((visibility
("default")))的函数才是对外可见的。
总结:如果需要让类或方法可以让库外被引用,就需要使用以上代码确保代码的可见性。
相关文章推荐
- Divide and conquer:4 Values whose Sum is 0(POJ 2785)
- String、StringBuffer和StringBuilder区别
- Build glibc-2.6
- java中queue的使用
- STL之优先队列priority_queue浅析
- c#使用FluentNHibernate,多数据库连接,一个程序,连接多个数据库
- UIView的setNeedLayout layoutIfNeeded LayoutSubviews
- poj2031 Building a Space Station(最小生成树)
- iOS--UITabbarController自定义
- 使用UE4发布安卓平台游戏
- easyui行按钮
- 高逼格UI-ASD(Android Support Design)
- Lintcode: Segment Tree Query II
- Unique ID策略
- U3D转UE4指南
- jenkins Hudson fails build with UnsupportedOperationException due to attempted modification of Simpl
- UIScrollView的delegate方法妙用之让UICollectionView滑动到某个你想要的位置
- An error occurred while installing json (1.8.0), and Bundler cannot continue.
- Unique ID的特性需求分析
- jquey实现对cookie的操作