weak symbol属性

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属性可以让编译器在编译的时候忽略函数未定义的错误。
extern void food() __attribute__((weak)); 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值