To understand the bit field memory storage, I have created the test program below.
#include
int main()
{
int a;
typedef struct {
For linux on x86 the relevant ABI document can be found here(pdf).
Specifically related to bitfields:
‘‘Plain’’ bit-fields (that is, those neither
signednorunsigned) always have nonnegative values. Although they may have typechar,short,int, orlong(which can have negative values), these bit-fields have the same range as a bit-field of the same size with the correspondingunsignedtype.Bit-fields obey the same size and alignment rules as other structure and union members, with the following additions:
Bit-fields are allocated from right to left (least to most significant). A bit-field must entirely reside in a storage unit appropriate for its declared type. Thus a bit-field never crosses its unit boundary.
Bit-fields may share a storage unit with other
struct/unionmembers, including members that are not bit-fields. Of course,structmembers occupy different parts of the storage unit. Unnamed bit-fields’ types do not affect the alignment of a structure or union, although individual bit-fields’ member offsets obey the alignment constraints.
The