24.3.14 Bit-Fields Straddling a Storage Unit Boundary

The standard indicates that implementations can determine whether bit-fields cross a storage unit boundary. In the CCI, bit-fields do not straddle a storage unit boundary; a new storage unit is allocated to the structure, and padding bits fill the gap.

Note that the size of a storage unit differs with each compiler and target device, as this is based on the size of the base data type (for example, int) from which the bit-field type is derived. For MPLAB XC8, this unit is 8-bits in size; for MPLAB XC16, it is 16 bits; and for MPLAB XC32, it is 32 bits in size. For MPLAB XC-DSC compiler, the size depends on the device used.

Example

The following shows a structure containing bit-fields being defined.

struct {
        unsigned first  : 6;
        unsigned second : 6;
} order;

Under the CCI and using MPLAB XC8, the storage allocation unit is byte sized. The bit-field second is allocated a new storage unit since there are only 2 bits remaining in the first storage unit in which first is allocated. The size of this structure, order, is 2 bytes.

Differences

This allocation is identical with that used by all previous compilers.

Migration to the CCI

No action required.