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.

C and C++ Implementation Details<br />

Note<br />

The same basic rules apply to bitfield declarations with different container types. For<br />

example, adding an int bitfield to the example structure gives:<br />

struct X<br />

{<br />

int x:10;<br />

char y:8;<br />

int z:5;<br />

}<br />

The compiler allocates an int container starting at the same location as the int x:10<br />

container and allocates a byte-aligned char and 5-bit bitfield, see Figure 5-3.<br />

Bit number<br />

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0<br />

free<br />

z<br />

y<br />

padding<br />

x<br />

Figure 5-3 Bitfield allocation 2<br />

You can explicitly pad a bitfield container by declaring an unnamed bitfield of size zero.<br />

A bitfield of zero size fills the container up to the end if the container is not empty. A<br />

subsequent bitfield declaration starts a new empty container.<br />

Bitfields in packed structures<br />

Bitfield containers in packed structures have an alignment of 1. Therefore, the<br />

maximum bit padding for a bitfield in a packed structure is 7 bits. For an unpacked<br />

structure, the maximum padding is 8*sizeof(container-type)–1 bits.<br />

5-12 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!