ended3월 21일· 1 sources

C Bit-Field Pitfalls

C 비트 필드(Bit-Field)의 함정

Why it matters

C bit-fields declared with unsigned int can produce unexpected results when used in shift expressions, because the C99 standard's integer promotion rules may convert them to signed int before the operation. This leads to divergent behavior between compilers: MSVC treats the shift result as unsigned (zero-extended), while gcc and clang treat it as signed (sign-extended) when promoting to uint64_t. The root cause is ambiguity in the C99 standard regarding whether a bit-field retains its declared unsigned type or is promoted to signed int when its value range fits within int.

1
Sources
+0
24h
Growth
172d
Active
bit-fieldC99integer promotiongccMSVC

Sources

Related Issues