Non-Confidential | ![]() | ARM DUI0375E | ||
| ||||
Home > Compiler-specific Features > __weak |
This keyword instructs the compiler to export symbols weakly.
__weak
keyword can be applied to function and variable declarations,
and to function definitions.extern
object declaration that, even if not present, does not cause the linker to fault an
unresolved reference. __weak void f(void); ... f(); // call f weakly
NOP
.NOP
instruction.__weak
export their symbols weakly. A
weakly defined function behaves like a normally defined function unless a nonweakly
defined function of the same name is linked into the same image. If both a nonweakly
defined function and a weakly defined function exist in the same image then all calls
to the function resolve to call the nonweak function. If multiple weak definitions are
available, the linker generates an error message, unless the linker option
--muldefweak
is used. In this case, the linker chooses one for use
by all calls.__weak
and then defined without
__weak
behave as nonweak functions.__weak
.f()
weakly from
g()
and h()
:void f(void); void g() { f(); } __weak void f(void); void h() { f(); }
f()
nonweakly from h()
:__weak void f(void); void h() { f(); } void f() {}
NULL
. Unresolved references,
however, are not NULL
if the reference is from code to a
position-independent section or to a missing __weak
function.__weak const int c; // assume 'c' is not present in final link const int *f1() { return &c; } // '&c' returns non-NULL if // compiled and linked /ropi __weak int i; // assume 'i' is not present in final link int *f2() { return &i; } // '&i' returns non-NULL if // compiled and linked /rwpi __weak void f(void); // assume 'f' is not present in final link typedef void (*FP)(void); FP g() { return f; } // 'g' returns non-NULL if // compiled and linked /ropi