-BfaB: Bitfield Byte Allocation

Group

CODE GENERATION

Scope

Function

Syntax
-BfaB(MS|LS)

Arguments

MS: Most significant bit in byte first (left to right)

LS: Least significant bit in byte first (right to left)

Default
-BfaBLS

Defines

__BITFIELD_MSWORD_FIRST__

__BITFIELD_LSWORD_FIRST__

__BITFIELD_MSBYTE_FIRST__

__BITFIELD_LSBYTE_FIRST__

__BITFIELD_MSBIT_FIRST__

__BITFIELD_LSBIT_FIRST__

Pragmas

None

Description

Normally, bits in byte bitfields are allocated from the least significant bit to the most significant bit. This produces less code overhead if a byte bitfield is allocated only partially.

Example

The following listing uses the default condition and uses the three least significant bits.

Listing: Example struct used for the next listing


struct {unsigned char b: 3; } B;
  // the default is using the 3 least significant bits

This allows just a mask operation without any shift to access the bitfield.

To change this allocation order, you can use the -BfaBMS or -BfaBLS options, shown in the the following listing.

Listing: Examples of changing the bitfield allocation order


struct {
  char b1:1;

  char b2:1;

  char b3:1;

  char b4:1;

  char b5:1;

} myBitfield;

  7                  0

  --------------------

  |b1|b2|b3|b4|b5|####|  (-BfaBMS)

  --------------------

  7                  0

  --------------------

  |####|b5|b4|b3|b2|b1|  (-BfaBLS)

  --------------------
See also

Bitfield Allocation