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

Caution<br />

You must take care when using global register variables because:<br />

• There is no check at link time to ensure that direct calls between different<br />

compilation units are sensible. If possible, define global register variables used in<br />

a program in each compilation unit of the program. In general, it is best to place<br />

the definition in a global header file. You must set up the value in the global<br />

register early in your code, before the register is used.<br />

• A global register variable maps to a callee-saved register, so its value is saved and<br />

restored across a call to a function in a compilation unit that does not use it as a<br />

global register variable, such as a library function.<br />

• Calls back into a compilation unit that uses a global register variable are<br />

dangerous. For example, if a function using a global register is called from a<br />

compilation unit that does not declare the global register variable, the function<br />

reads the wrong values from its supposed global register variables.<br />

• This storage class can only be used at file scope.<br />

Example<br />

Example 4-1 declares a global variable register allocated to r5.<br />

Example 4-1 Declaring a global integer register variable<br />

__global_reg(2) int x<br />

; v2 is the synonym for r5<br />

Example 4-2 produces an error because global register must be specified in all<br />

declarations of the same variable.<br />

Example 4-2 Global register - declaration error<br />

int x;<br />

__global_reg(1) int x; // error<br />

In C, __global_reg variables cannot be initialized at definition. Example 4-3 on<br />

page 4-9 produces an error in C, but not in C++.<br />

4-8 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!