Admittedly this is a very silly question, but one that I was thinking about the other day. Sometimes in source I see registers defined like so:
union
{
uint8_t byte;
struct
{
uint8_t bit1 :1;
uint8_t bit2 :1;
uint8_t bit3_4 :2;
uint8_t rsvd :4;
} bitfield;
} SomeReg_t;
Other times I see just a standard struct:
struct
{
uint8_t bit1 :1;
uint8_t bit2 :1;
uint8_t bit3_4 :2;
uint8_t rsvd :4;
} SomeReg_t;
I wrote a quick example to show what I mean:
https://onlinegdb.com/r1H3Xuqe4
The question is, in regard to bitfields, what are the differences in these two definitions. When would you use one vs the other for bitfields.