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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C and C++ Implementation Details<br />

• In RVCT v2.0 and above, double and long long data types are<br />

eight-byte aligned. This enables efficient use of the LDRD and STRD<br />

instructions in <strong>ARM</strong>v5TE and above.<br />

• Bitfield alignment depends on how the bitfield is declared. See<br />

Bitfields in packed structures on page 5-12 for more information.<br />

• All other types are aligned on word boundaries.<br />

Structures can contain padding to ensure that fields are correctly aligned and that the<br />

structure itself is correctly aligned. Figure 5-1 shows an example of a conventional,<br />

non-packed structure. Bytes 1, 2, and 3 are padded to ensure correct field alignment.<br />

Bytes 11 and 12 are padded to ensure correct structure alignment. The sizeof() function<br />

returns the size of the structure including padding.<br />

Figure 5-1 Conventional non-packed structure example<br />

The compiler pads structures in one of the following ways, according to how the<br />

structure is defined:<br />

• Structures that are defined as static or extern are padded with zeros.<br />

• Structures on the stack or heap, such as those defined with malloc() or auto, are<br />

padded with whatever is previously stored in those memory locations. You cannot<br />

use memcmp() to compare padded structures defined in this way (see Figure 5-1).<br />

Use the --remarks option to view the messages that are generated when the compiler<br />

inserts padding in a struct.<br />

Structures with empty initializers are permitted in C++:<br />

struct<br />

{<br />

int x;<br />

} X = { };<br />

struct {char c; int x; short s} ex1;<br />

0 1 2 3<br />

However, if you are compiling C, or compiling C++ with the -cpp and--c90 options, an<br />

error is generated.<br />

c<br />

s<br />

padding<br />

4 5 7 8<br />

x<br />

9 10 11 12<br />

padding<br />

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

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!