Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9085823
  • 博文数量: 1732
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 19830
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1732)

文章存档

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: Android平台

2015-07-29 18:41:44

gcc中函数或者变量的weak属性
http://blog.chinaunix.net/uid-20593827-id-1918496.html

gcc reference里提到:

A function with this attribute has its name emitted as a weak
symbol instead of a global name. This is primarily for the naming
of library routines that can be overridden by user code.

weak symbol
Having two or more global symbols of the same name will not cause a conflict as long as all but one of them are declared as being weak symbols. The linker ignores the definitions of the weak symbols and uses the normal global symbol definition to resolve all references, but the weak symbols will be used if the normal global symbol is not available. A weak symbol can be used to name functions and data that can be overridden by user code. A weak symbol is also referred to as a weak alias, or simply weak.


通过简单的例子可以看出,weak属性可以让编译器在编译的时候忽略函数未定义的错误。

$cat weak.c 
extern void foo() __attribute__((weak)); 
int main() { 
   if (foo) foo(); 

$ gcc weak.c -o weak
$ ./weak 
$



weak alias 具有和weak symbol类似的作用。
int __centon() { return(100); }
void centon() __attribute__((weak,alias(“__centon”)));
阅读(3214) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~