I have a struct with bit-fields (totally 32 bit width) and I have a 32-bit variable. When I try to assign the variable value to my struct, I got an error:
Use a union.
union foo { struct { uint8_t a : 4; uint8_t b : 4; uint8_t c : 4; uint8_t d : 4; uint16_t e; }; uint32_t allfields; }; int main(void) { union foo a; a.allfields = 0; a.b = 3; return 0; }