3 ms·
I have several questions. If I have too bool bit fields next to each other, how are these ordered in a given byte? Even when I have a less then 8 bit field it c
by leni536 8y ago
I have several questions. If I have too bool bit fields next to each other, how are these ordered in a given byte? Even when I have a less then 8 bit field it can span over a byte boundary. Are the low bits go into the next byte or the high bits? The blog post only mentions fields greater than 8 bits.
If a field greater than 8 bits is byte-aligned, it is represented in memory with the endianness of the host. If the field is not byte-aligned, it is represented in memory in big-endian.
So is a 12 bit fild is byte-aligned if it starts at the "first" bit of a byte (whatever that is)? Is there a way to manually specify the endianness of a field? There are certainly cases where a byte-aligned big-endian field is needed on a little-endian host.
I also don't like that keeping track of the fields' address happens in comments. It would be great if there were a language element that would specify the address of a field inside a packed struct, so the compiler could verify its correctness.