logo

C Bit-Field Pitfalls

Posted by fanf2 |2 hours ago |2 comments

pjmlp 24 minutes ago

It is much safer to pack/unpack bits manually than trusting bitfields will work as expected.

mwkaufma 29 minutes ago

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).

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?