struct bitfield {
int i = 0; // ok
int j : 8 = 0; // error: lvalue required as left operand of assignment
};
What is the correct syntax to in
You can write a constructor with initializer list to give default values to your bitfields.
struct bitfield {
int i;
int j : 8;
bitfield() : i(0), j(0) {};
};
You can also create read-only fields with default values.
struct _UserRegister1
{
uint8_t _RES0 : 1;
const uint8_t reserved1 : 1;
uint8_t _HTRE : 1;
const uint8_t reserved2 : 3;
uint8_t _VDDS : 1;
uint8_t _RES1 : 1;
_UserRegister1() : reserved1(1), reserved2(7) {};
};