|
|
|
|
|
by david2ndaccount
323 days ago
|
|
The author relies on the compiler fitting the bitfield in unused padding bytes after “speed”, but that is implementation-defined behavior (almost everything about bitfields is implementation defined). MSVC will align the unsigned bitfield to alignof(unsigned), whereas GCC and clang will use the padding bytes. To portably pack the struct, use unsigned integers and use flags (monster.flags & CAN_FLY instead of monster.can_fly). See https://c.godbolt.org/z/K7oY77KGj |
|
Bitfields in C leave way too much behavior to the compiler or undefined. It's really intolerable.