I'm looking through some code that uses both bit fields and uint_t types, and I'm not sure why bit fields are used instead of the uint_t types in this context.
Here is the code that uses bitfields for context - it is a link-layer packet structure. The main takeaway I found was that bit fields are only used in structs, whereas the uint_t types are everywhere else in the code.
typedef struct PPPoEPacketStruct {
struct ethhdr ethHdr; /* Ethernet header */
unsigned int vertype:8; /* PPPoE Version (high nibble) and Type (low nibble) (must both be 1) */
unsigned int code:8; /* PPPoE code */
unsigned int session:16; /* PPPoE session */
unsigned int length:16; /* Payload length */
unsigned char payload[ETH_JUMBO_LEN]; /* A bit of room to spare */
} PPPoEPacket;
Why is this the case?