Am trying to use bitfields in a portable way but am not sure my solution is the best one. I could be missing something.
I am declaring the bitfields conditionally based on the target-architecture. I have something like
Code:
struct CMDInvalDevEntry {
#ifdef __BIG_ENDIAN_BITFIELD
uint16_t devid; /* device to invalidate */
uint64_t reserved_1:44;
uint32_t type:4; /* command type */
#else
uint16_t devid;
uint64_t reserved_1:44;
uint32_t type:4;
#endif /* __BIG_ENDIAN_BITFIELD */
uint64_t reserved_2;
} __attribute((packed));
Is there a better way to do this ?