3 ms·
Super agree. I read up on bit fields [0] a while ago and some of the details about them are bonkers: > Multiple adjacent bit-fields are usually packed together
by camgunz 5y ago
Super agree. I read up on bit fields [0] a while ago and some of the details about them are bonkers:
> Multiple adjacent bit-fields are usually packed together (although this behavior is implementation-defined)
> The special unnamed bit-field of size zero can be forced to break up padding.
> int b:3; may have the range of values 0..7 or -4..3 in C
> on some platforms, bit-fields are packed left-to-right, on others right-to-left
I wouldn't touch them unless I absolutely had to, and knew I could guarantee compiler and platform.
[0]: https://en.cppreference.com/w/cpp/language/bit_field https://en.cppreference.com/w/cpp/language/bit_field
- deaddodo 5y agoThey're pretty safe on the two most popular ISAs: aarch64 and amd64.
- ncmncm 5y agoSafe enough to make people complacent, anyway.
- alternatetwo 5y agoEven then, msvc and gcc still generate them differently ...