04.01.2015 Views

RealView Compilation Tools - ARM Information Center

RealView Compilation Tools - ARM Information Center

RealView Compilation Tools - ARM Information Center

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Compiler-specific Features<br />

See also<br />

• __value_in_regs on page 5-13 in the Compiler User Guide.<br />

4.1.19 __weak<br />

This keyword instructs the compiler to export symbols weakly.<br />

The __weak keyword can be applied to function and variable declarations, and to<br />

function definitions.<br />

Usage<br />

Functions and variable declarations<br />

For declarations, this storage class specifies an extern object declaration<br />

that, even if not present, does not cause the linker to fault an unresolved<br />

reference.<br />

For example:<br />

__weak void f(void);<br />

...<br />

f(); // call f weakly<br />

If the reference to a missing weak function is made from code that<br />

compiles to a branch or branch link instruction, then either:<br />

• The reference is resolved as branching to the next instruction. This<br />

effectively makes the branch a NOP.<br />

• The branch is replaced by a NOP instruction.<br />

Function definitions<br />

Functions defined with __weak export their symbols weakly. A weakly<br />

defined function behaves like a normally defined function unless a non<br />

weakly defined function of the same name is linked into the same image.<br />

If both a non weakly defined function and a weakly defined function exist<br />

in the same image then all calls to the function resolve to call the non<br />

weak function. If multiple weak definitions are available, the linker<br />

chooses one for use by all calls.<br />

Functions declared with __weak and then defined without __weak behave<br />

as non weak functions.<br />

<strong>ARM</strong> DUI 0348C Copyright © 2007-2010 <strong>ARM</strong>. All rights reserved. 4-21<br />

ID101213<br />

Non-Confidential,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!