><i>The troublesome behavior is demonstrated by the lines performing the left shift. We take a 12-bit wide bit-field, shift it left by 20 bits so ...</i><p>this is nonsense. I don't know what they expect would happen, but who cares? I wouldn't shift a 12 bit field by more than ±11 bits.<p>you can shift the "enclosing" word of memory if you want, just put the original definition in a union.
by fsckboy
|
Mar 21, 2026, 8:39:30 PM
It is much safer to pack/unpack bits manually than trusting bitfields will work as expected.
by pjmlp
|
Mar 21, 2026, 8:39:30 PM
tl;dr standard is unclear if they should respect the signed-ness of the declaration (MSCV), or always promote to int before converting to a receiving type (GCC, Clang).<p>I suppose you could say MS's choice reflects a commitment to backwards compatibility, whereas GCC/Clang is always chomping at the bit to introduce more aggressive optimizations that signed-integer-undefined-behavior affords?
by mwkaufma
|
Mar 21, 2026, 8:39:30 PM