gcc function __attribute__

原创 2019-01-13

attribute可以设置函数&变量属性。总结常用的gcc Attribute syntax,已备用查询。

总结常用的gcc Attribute syntax,已备用查询。

__attribute__((format()))  

按照指定格式进行参数检查

__attribute__((__always_inline__))

强制内联

__attribute__((deprecated("Use xxx: instead")

标记废弃方法

__attribute__((__unused__))

标记函数或变量可能不会用到

__attribute__((visibility("visibility_type")))

标记动态库符号是否可见,有以下取值:

default:符号可见,可导出。

hidden:符号隐藏,不可导出,只能在本动态库内调用。

__attribute__((objc_designated_initializer))

明确指定用于初始化的方法。一个优秀的设计,初始化接口可以有多个,但最终多个初始化初始化接口都会调用designed initializer方法。

__attribute__((unavailable))

__attribute__((unavailable("Must use xxx: instead.")));

标记方法被禁用,不能直接调用。但这并不意味着改方法不能被调用,在Objective-C中使用runtime依然可以调用。

__attribute__((section("segment,section")))

将一个指定的数据储存到我们需要的段和section中。

__attribute__((constructor))

attribute((constructor))标记的函数,会在main函数之前或动态库加载时执行。在mach-o中,被attribute((constructor))标记的函数会在_DATA,__mod_init_func section中。

当多个被标记attribute((constructor))的方法想要有顺序的执行,怎么办?

attribute((constructor))是支持优先级的:_attribute((constructor(1)))

__attribute__((destructor))

attribute((constructor))相反:被attribute((destructor))标记的函数,会在main函数退出或动态库卸载时执行。在mach-o中此类函数会放在 _DATA,__mod_term_func section中。

参考:https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

# gcc

相关文章:

iOS 抓取网络数据包
iOS Crash log符号化
分享AppStore审核的一些经验教训
Let’s Encrypt acme.sh 泛域名证书
UTF-8 BOM EF BB BF 问题

发表留言

您的电子邮箱地址不会被公开,必填项已用*标注。