29.10.2014 Views

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

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> Coding Practices<br />

5.19 Inline functions<br />

Inline functions offer a trade-off between code size and per<strong>for</strong>mance. By default, <strong>the</strong> compiler<br />

decides <strong>for</strong> itself whe<strong>the</strong>r to inline code or not. As a general rule, when compiling with -Ospace,<br />

<strong>the</strong> compiler makes sensible decisions about inlining with a view to producing code of minimal<br />

size. This is because code size <strong>for</strong> embedded systems is of fundamental importance. When<br />

compiling with -Otime, <strong>the</strong> compiler inlines in most cases, but still avoids large code growth.<br />

In most circumstances, <strong>the</strong> decision to inline a particular function is best left to <strong>the</strong> compiler.<br />

However, you can give <strong>the</strong> compiler a hint that a function is required to be inlined by using <strong>the</strong><br />

appropriate inline keyword.<br />

Functions that are qualified with <strong>the</strong> __inline, inline, or __<strong>for</strong>ceinline keywords are called<br />

inline functions. In C++, member functions that are defined inside a class, struct, or union, are<br />

also inline functions.<br />

The compiler also offers a range of o<strong>the</strong>r facilities <strong>for</strong> modifying its behavior with respect to<br />

inlining. There are several factors you must take into account when deciding whe<strong>the</strong>r to use<br />

<strong>the</strong>se facilities, or more generally, whe<strong>the</strong>r to inline a function at all.<br />

The linker is able to apply some degree of function inlining to functions that are very short.<br />

5.19.1 See also<br />

Concepts<br />

• <strong>Compiler</strong> decisions on function inlining on page 5-30<br />

• Restriction on overriding compiler decisions about function inlining on page 5-35<br />

Reference<br />

<strong>Compiler</strong> Reference:<br />

• --autoinline, --no_autoinline on page 3-14<br />

• __<strong>for</strong>ceinline on page 5-5<br />

• --<strong>for</strong>ceinline on page 3-40<br />

• __inline on page 5-7.<br />

Linker Reference:<br />

• --inline, --no_inline on page 2-64.<br />

<strong>ARM</strong> DUI 0375C Copyright © 2007-2008, 2011 <strong>ARM</strong>. All rights reserved. 5-29<br />

ID061811<br />

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!