__attribute__((used)) 函数属性

3122次阅读  |  发布于3年以前

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

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8