Why is the order of bit fields in the bytes of structs not defined by the language itself?
问题 I came across a problem today where I discovered the way the bit fields in my bytes are ordered is dependent on the endianness of my processor. Take the next example: struct S { uint8_t a : 3; uint8_t b : 5; }; This struct takes one byte but the bit layout depends on the machine: Little endian: b4 b3 b2 b1 b0 a2 a1 a0 Big endian: a2 a1 a0 b4 b3 b2 b1 So on a little endian machine it starts filling from the LSB and on a big endian machine it start filling from the MSB. I once heard Stroustrup