I have the following layout of memory (pseudo code):
struct {
union {
fieldA : 45;
struct {
fieldB1 : 12;
fieldB2 : 33;
}
}
fieldC : 19;
}
i.e., the memory of field A can be sometimes used for other purposes (fields B1 and B2). I want this struct to be as packed as possble, i.e. 64bit in size.
It seems like no matter what I do (packed attributes for example) the union is always padded with 3 bits to get 48bits (6Bytes) before fieldC (which is also padded of course).
Use a typedef or a struct with a single
uint64_t. Write getters and setters for every field using bitfield operations.