I have a struct defined as:
typedef struct {
uint8_t field1 : 6,
uint8_t field2 : 1,
uint8_t field3 : 1
} myStruct;
and then:
myStruct s;
What is a safe way to assign an 8-bit value to all the fields at once, i.e.:
s = 10;
The compiler gives error when trying to assign like this (obviously, I'm not even implying this is the way to do it :) ).
Would this be recommended:
uint8_t a = 10;
s = * ((myStruct*) &a);
?