There are restrictions when you qualify function and variable
declarations, and function definitions, with __weak.
- Functions and variable
declarations
A function or variable cannot
be used both weakly and nonweakly in the same compilation. For example,
the following code uses f() weakly from g() and h():
void f(void);
void g()
{
f();
}
__weak void f(void);
void h()
{
f();
}
It is not possible to use a function or variable weakly from
the same compilation that defines the function or variable. The
following code uses f() nonweakly from h():
__weak void f(void);
void h()
{
f();
}
void f() {}
The linker does not load the function or variable from a library
unless another compilation uses the function or variable nonweakly.
If the reference remains unresolved, its value is assumed to be NULL.
Unresolved references, however, are not NULL if
the reference is from code to a position-independent section or
to a missing __weak function.
- Function definitions
Weakly defined functions cannot be inlined.