记录学习源码遇到的函数属性关键字使用
attribute((constructor))
如果函数被设定为constructor属性,则该函数会在main()函数执行之前被自动的执行;若函数被设定为destructor属性,则该函数会在main()函数执行之后或者exit()被调用后被自动的执行。
// 出自Hook +load 方法
attribute((used))
1、通知编译器在目标文件中保留一个静态函数,即使它没有被引用。
2、标记为attribute__((used))的函数被标记在目标文件中,以避免链接器删除未使用的节。
3、静态变量也可以标记为used,方法是使用 attribute((used))。
static int lose_this(int);
static int keep_this(int) __attribute__((used)); // retained in object file
static int keep_this_too(int) __attribute__((used)); // retained in object file
attribute((noinline))
声明为非内联函数。
// 出自runloop 源码
static void __CFRunLoopDoObservers() __attribute__((noinline));
具体为什么要使用这个属性,还不明白,好像不使用默认就是非内联的~~