c语言之函数或者变量的weak属性
2015-08-28 09:57
309 查看
转自: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属性可以让编译器在编译的时候忽略函数未定义的错误。
weak alias 具有和weak symbol类似的作用。
int __centon() { return(100); }
void centon() __attribute__((weak,alias(“__centon”)));
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”)));
相关文章推荐
- cpp 文件打印LOG
- 【more effective c++读书笔记】【第3章】异常(1)
- 【more effective c++读书笔记】【第3章】异常(1)
- C语言undefined behaviour未定义行为
- Effective C++——条款8(第2章)
- C++ string学习
- 关于C++的模板偏特化和萃取编程技法
- POJ C++程序设计 编程题#3 编程作业—多态与虚函数
- C++的数据类型
- C++的数据类型
- POJ C++程序设计 编程题#2 编程作业—多态与虚函数
- POJ C++程序设计 编程题#1 编程作业—多态与虚函数
- C语言堆栈入门——堆和栈的区别
- C语言中的abs()函数和exp()函数的用法
- C语言之指针与地址
- C语言的数学计算库
- php大力力 [033节] 随便看看:PHP程序员学习C++
- [C++11 并发编程] 14 关联任务与期望
- Lily上课时使用字母数字图片教小朋友们学习英语单词,每次都需要把这些图片按照大小(ASCII码值从小到大)排列收好。请大家给Lily帮忙,通过C语言解决。
- C语言 文件单词的检索与计数