c语言之函数或者变量的weak属性
来源:互联网 发布:linux如何打开命令窗口 编辑:程序博客网 时间:2024/05/21 07:00
转自:http://blog.chinaunix.net/uid-20593827-id-1918496.html
c语言之函数或者变量的weak属性
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”)));
- c语言之函数或者变量的weak属性
- gcc中函数或者变量的weak属性
- 关于gcc中函数或变量的weak属性
- c语言变量的属性
- C语言变量的属性
- C语言总结之变量的三个属性
- 详解C/C++语言中Static 变量 或者 static函数的作用
- C语言变量属性
- C语言的那些秘密之---函数返回局部变量
- C语言的那些秘密之---函数返回局部变量
- C语言的那些秘密之---函数返回局部变量
- C语言的那些秘密之---函数返回局部变量
- C语言的那些秘密之---函数返回局部变量
- C语言的那些秘密之---函数返回局部变量
- C语言的那些秘密之---函数返回局部变量
- C语言的那些秘密之---函数返回局部变量
- C语言的那些秘密之---函数返回局部变量
- C语言的那些秘密之---函数返回局部变量
- 算法研究之合并两个已排序的数组java版
- 需求 - 1 - 强制更新的嵌套项
- (转)浅谈SPI总线
- cpp 文件打印LOG
- java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, ho
- c语言之函数或者变量的weak属性
- 将ppt格式转换为pdf格式
- 【论坛】游戏开发大板上线公告
- hdoj 1050 Moving Tables
- Django之第一个app<5>
- [Android]简单的在线翻译应用
- 1038. Recover the Smallest Number (30)好题
- maven 工程 dubbo服务的xml配置文件报错的问题
- iOS AutoLayout自动布局中级开发教程(5)-修改约束的值,延迟加载