Hacker News new | ask | show | jobs
by jws 1567 days ago
The layout of a bit field in C is implementation defined. That makes them not a great choice for interfacing with hardware registers/descriptors or interoperating with binary file formats. (unless you are fine welding yourself to a specific set of compilers)

In applications like this where you really don't care about the layout of bits, they are just fine.

However… there is a violation in this library. As nrdvana points out in another comment, the "uint8_t ssolen:4" and the "uint8_t type : 2" fields are assumed to layout on top of each other using the same bits of the same byte, but this isn't really guaranteed by the C standard, though I think any sane compiler will do it.

1 comments

(author here)

I think I read the order of a struct members is guaranteed. So ssolen and type should not overlap ?