3 ms·
Interesting, I saw some low level code that assumes that bits are neatly packed. Some C decisions really confuses me. What would be the point of this one?
by shultays 4y ago
Interesting, I saw some low level code that assumes that bits are neatly packed.
Some C decisions really confuses me. What would be the point of this one?
- layer8 4y agoThe alignment restrictions for memory accesses on some architectures may prevent bitfields from crossing certain address boundaries, hence implementations may need to reorder and/or pad the fields. The alternative would have been to either fail compilation for bitfield combinations that are incompatible with the target platform, which would arguably be worse, because you couldn’t portably use bitfields at all then, or to force implementations to generate code with case distinctions, possibly depending on the actual alignment at runtime, performing the bitfield accesses using multiple memory accesses if necessary.