Hacker News new | ask | show | jobs
by Dav3xor 4131 days ago
Decent article full of good information. One exception -- the C standard is vague on how bitfields are implemented and the compiler can rearrange them in any way it pleases. You are not guaranteed efficient packing, placement order, or size.
2 comments

It's not quite that loose. Order of elements is guaranteed, same as any other structure members, and packing is guaranteed if the members fit. Whether bit fields can cross word boundaries, and endianness, are implementation defined, so bit fields are still not usable where there's any interoperability constraint.
His foo5 struct is a good example of this - there's two more bytes of padding on Darwin (at least) than what he specifies.