Download Compiler Reference

Transcript
Compiler-specific Features
Usage
Functions and variable declarations
For declarations, this storage class specifies an extern object declaration that,
even if not present, does not cause the linker to fault an unresolved reference.
For example:
__weak void f(void);
...
f(); // call f weakly
If the reference to a missing weak function is made from code that compiles to a
branch or branch link instruction, then either:
•
The reference is resolved as branching to the next instruction. This
effectively makes the branch a NOP.
•
The branch is replaced by a NOP instruction.
Function definitions
Functions defined with __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 chooses one for use by all calls.
Functions declared with __weak and then defined without __weak behave as
nonweak functions.
Restrictions
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() {}
ARM DUI 0376C
ID061811
Copyright © 2007-2008, 2011 ARM. All rights reserved.
Non-Confidential
5-17