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.36 Per<strong>for</strong>mance penalty associated with marking whole structures as packed<br />

Reading from and writing to whole structures qualified with __packed requires unaligned<br />

accesses and can <strong>the</strong>re<strong>for</strong>e incur a per<strong>for</strong>mance penalty.<br />

When optimizing a struct that is packed, <strong>the</strong> compiler tries to deduce <strong>the</strong> alignment of each<br />

field, to improve access. However, it is not always possible <strong>for</strong> <strong>the</strong> compiler to deduce <strong>the</strong><br />

alignment of each field in a __packed struct. In contrast, when individual fields in a struct are<br />

declared as __packed, fast access is guaranteed to naturally aligned members within <strong>the</strong> struct.<br />

There<strong>for</strong>e, when <strong>the</strong> use of a packed structure is required, it is recommended that you always<br />

pack individual fields of <strong>the</strong> structure, ra<strong>the</strong>r than <strong>the</strong> entire structure itself.<br />

Note<br />

Declaring individual non-aligned fields of a struct as __packed also has <strong>the</strong> advantage of making<br />

it clearer to <strong>the</strong> programmer which fields of <strong>the</strong> struct are not naturally aligned.<br />

5.36.1 See also<br />

Concepts<br />

• Unaligned fields in structures on page 5-47.<br />

Reference<br />

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

• #pragma pack(n) on page 5-56<br />

• __packed on page 5-9.<br />

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

ID061811<br />

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!