Datasheet
ARM Compiler Reference
3-28 Copyright © 1999-2001 ARM Limited. All rights reserved. ARM DUI 0067D
Packed structures
A packed structure is one where the alignment of the structure, and of the fields within
it, is always 1. Floating-point types cannot be fields of packed structures.
Packed structures are defined with the
__packed
qualifier. (See ARM-specific keywords
on page 3-10.) There is no command-line option to change the default packing of
structures.
Bitfields
In nonpacked structures, the ARM compilers allocate bitfields in containers. A
container is a correctly aligned object of a declared type. Bitfields are allocated so that
the first field specified occupies the lowest-addressed bits of the word, depending on
configuration:
Little-endian Lowest addressed means least significant.
Big-endian Lowest addressed means most significant.
A bitfield container can be any of the integral types.
Note
The compiler warns about non
int
bitfields. You can disable this warning with the
-Wb
compiler option.
A plain bitfield, declared without either
signed
or
unsigned
qualifiers, is treated as
unsigned
. For example,
int x:10
allocates an unsigned integer of 10 bits.
A bitfield is allocated to the first container of the correct type that has a sufficient
number of unallocated bits, for example:
struct X {
int x:10;
int y:20;
};
The first declaration creates an integer container and allocates 10 bits to
x
. At the second
declaration, the compiler finds the existing integer container with a sufficient number
of unallocated bits, and allocates
y
in the same container as
x
.
A bitfield is wholly contained within its container. A bitfield that does not fit in a
container is placed in the next container of the same type. For example, the declaration
of z overflows the container if an additional bitfield is declared for the structure above: