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 />

Restrictions<br />

There are restrictions when you qualify function and variable declarations, and function<br />

definitions, with __weak.<br />

Functions and variable declarations<br />

A function or variable cannot be used both weakly and non weakly in the<br />

same compilation. For example the following code uses f() weakly from<br />

g() and h():<br />

void f(void);<br />

void g()<br />

{<br />

f();<br />

}<br />

__weak void f(void);<br />

void h()<br />

{<br />

f();<br />

}<br />

It is not possible to use a function or variable weakly from the same<br />

compilation that defines the function or variable. The following code uses<br />

f() non weakly from h():<br />

__weak void f(void);<br />

void h()<br />

{<br />

f();<br />

}<br />

void f() {}<br />

The linker does not load the function or variable from a library unless<br />

another compilation uses the function or variable non weakly. If the<br />

reference remains unresolved, its value is assumed to be NULL. Unresolved<br />

references, however, are not NULL if the reference is from code to a<br />

position-independent section or to a missing __weak function.<br />

Function definitions<br />

Weakly defined functions cannot be inlined.<br />

Example<br />

__weak const int c;<br />

// assume 'c' is not present in final link<br />

const int *f1() { return &c; } // '&c' returns non-NULL if<br />

// compiled and linked /ropi<br />

__weak int i;<br />

// assume 'i' is not present in final link<br />

int *f2() { return &i; } // '&i' returns non-NULL if<br />

// compiled and linked /rwpi<br />

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

Non-Confidential,<br />

ID101213

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

Saved successfully!

Ooh no, something went wrong!