29.12.2014 Views

RealView Compilation Tools Compiler Reference Guide - ARM ...

RealView Compilation Tools Compiler Reference Guide - ARM ...

RealView Compilation Tools Compiler Reference Guide - ARM ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>Compiler</strong>-specific Features<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 />

int *f2() { return &i; }<br />

__weak void f(void);<br />

typedef void (*FP)(void);<br />

FP g() { return f; }<br />

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

// '&i' returns non-NULL if<br />

// compiled and linked /rwpi<br />

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

// 'g' returns non-NULL if<br />

// compiled and linked /ropi<br />

See also<br />

• Chapter 7 Using the <strong>ARM</strong> Librarian in the Linker <strong>Guide</strong> for more information on<br />

library searching.<br />

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

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!