GCC _attribute__ weak weakref
来源:互联网 发布:淘宝评论看不见 编辑:程序博客网 时间:2024/05/22 03:18
#include <stdio.h> /*void test(){ printf("the test for weak refrence!\n"); }*/ static __attribute__ ((weakref("test"))) void foo(); int main(){ if(foo) foo(); }
如果test函数有定义,执行main程序时将执行test函数;
如果test函数没有定义,执行main函数时foo地址为0,不执行foo函数。??
In GNU C, you declare certain things about functions called in your program which help the compiler optimize function calls and check your code more carefully.
The keyword __attribute__
allows you to specify special attributes when making a declaration. This keyword is followed by an attribute specification inside double parentheses.
The following attributes are currently defined for functions on all targets: aligned
, alloc_size
, noreturn
, returns_twice
, noinline
,noclone
, always_inline
, flatten
, pure
, const
, nothrow
, sentinel
, format
, format_arg
, no_instrument_function
,
no_split_stack
, section
, constructor
, destructor
, used
, unused
, deprecated
, weak
, malloc
, alias
, ifunc
,warn_unused_result
, nonnull
, gnu_inline
, externally_visible
, hot
,
cold
, artificial
, error
and warning
.
Several other attributes are defined for functions on particular target systems. Other attributes, including section
are supported for variables declarations (see Variable Attributes) and for types (see Type Attributes).
GCC plugins may provide their own attributes.
You may also specify attributes with `__' preceding and following each keyword. This allows you to use them in header files without being concerned about a possible macro of the same name. For example, you may use __noreturn__
instead of noreturn
.
alias ("
target")
alias
attribute causes the declaration to be emitted as an alias for another symbol, which must be specified. For instance,void __f () { /* Do something. */; } void f () __attribute__ ((weak, alias ("__f")));
defines `f' to be a weak alias for `__f'. In C++, the mangled name for the target must be used. It is an error if `__f' is not defined in the same translation unit.
Not all target machines support this
......
.....
weak
weak
attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions which can be overridden in user code, though it can also be used with non-function declarations. Weak symbols are supported for ELF targets, and also for a.out targets when using the GNU assembler and linker.weakref
weakref ("
target ")
weakref
attribute marks a declaration as a weak reference. Without arguments, it should be accompanied by an alias
attribute naming the target symbol. Optionally, the target may be given as an argument to weakref
itself. In either case, weakref
implicitly marks the declaration as weak
. Without a target, given as an argument to weakref
or to alias
, weakref
is equivalent to weak
.static int x() __attribute__ ((weakref ("y"))); /* is equivalent to... */ static int x() __attribute__ ((weak, weakref, alias ("y"))); /* and to... */ static int x() __attribute__ ((weakref)); static int x() __attribute__ ((alias ("y")));
A weak reference is an alias that does not by itself require a definition to be given for the target symbol. If the target symbol is only referenced through weak references, then it becomes aweak
undefined symbol. If it is directly referenced, however, then such strong references prevail, and a definition will be required for the symbol, not necessarily in the same translation unit.
The effect is equivalent to moving all references to the alias to a separate translation unit, renaming the alias to the aliased symbol, declaring it as weak, compiling the two separate translation units and performing a reloadable link on them.
- GCC _attribute__ weak weakref
- gcc weak/alias/weakref/__typeof()属性总结
- _attribute__ 之weak,alias属性
- gcc weak symbol
- gcc: __attribute__ ((weak))
- gcc之weak,alias属性
- gcc attribute weak & alias应用
- gcc attribute weak & alias应用
- gcc __attribute__ ((weak, alias (#name)))
- gcc attribute weak & alias应用
- gcc attribute weak & alias应用
- Weakref应用
- 2011-08-17 gcc属性之weak。
- gcc __attribute__ ((weak, alias (#name))) 1
- GCC __attribute__ 之weak,alias属性
- python weakref模块
- [Pyhton]weakref 弱引用
- Python笔记:weakref模块
- iOS 一般设置
- ECMALL网站验证码不显示
- php设置编码格式的方法
- 块设备驱动-流程
- Mahout – Clustering (聚类篇)
- GCC _attribute__ weak weakref
- 设置TinyMCE在线HTML编辑控件只读
- 项目篇 - 如何熟悉项目
- MySql中LongText字段对应Hibernate映射文件的设置(转)
- JDBC_使用PreparedStatement执行update操作
- java.lang.ClassNotFoundException: org.jaxen.JaxenException
- Semi-continuity
- 取字符串的长度strlen()函数
- PE文件格式TLS回调