Datasheet
ARM Compiler Reference
3-30 Copyright © 1999-2001 ARM Limited. All rights reserved. ARM DUI 0067D
struct X {
int x:10;
char y:8;
int z:5;
}
The compiler allocates an
int
container starting at the same location as the
int x:10
container and allocates a byte-aligned
char
and 5-bit bitfield (Figure 3-3).
Figure 3-3 Bitfield allocation 2
You can explicitly pad a bitfield container by declaring an unnamed bitfield of size zero.
A bitfield of zero size fills the container up to the end if the container is non-empty. A
subsequent bitfield declaration starts a new empty container.
Bitfields in packed structures
Bitfield containers in packed structures have an alignment of 1. Therefore, the
maximum bit padding for a bitfield in a packed structure is 7 bits. For an unpacked
structure, the maximum padding is
8*sizeof(container-type)–1 bits
.
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
x
yz
padding
Bit number
free