04.01.2015 Views

RealView Compilation Tools - ARM Information Center

RealView Compilation Tools - ARM Information Center

RealView Compilation Tools - ARM Information Center

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.

Compiler-specific Features<br />

Example<br />

This example demonstrates how pack(2) aligns integer variable b to a 2-byte boundary.<br />

typedef struct<br />

{<br />

char a;<br />

int b;<br />

} S;<br />

#pragma pack(2)<br />

typedef struct<br />

{<br />

char a;<br />

int b;<br />

} SP;<br />

S var = { 0x11, 0x44444444 };<br />

SP pvar = { 0x11, 0x44444444 };<br />

The layout of S is as shown in Figure 4-1, while the layout of SP is as shown in<br />

Figure 4-2. In Figure 4-2, x denotes one byte of padding.<br />

0 1 2 3<br />

a padding<br />

4 5 6 7<br />

b b b b<br />

Figure 4-1 Nonpacked structure S<br />

0 1 2 3<br />

a x b b<br />

4 5<br />

b b<br />

Note<br />

SP is a 6-byte structure. There is no padding after b.<br />

Figure 4-2 Packed structure SP<br />

See also<br />

• __packed on page 4-11<br />

<strong>ARM</strong> DUI 0348C Copyright © 2007-2010 <strong>ARM</strong>. All rights reserved. 4-69<br />

ID101213<br />

Non-Confidential,

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

Saved successfully!

Ooh no, something went wrong!