Why does Rust bindgen even attempt bitfields?

I currently don't have an answer to this question.

Basically I have this issue where I don't know how FFI should handle C bitfields. They're tricky, error-prone and implementation-defined.

How does Golang deal with this? It doesn't.

And to be fair, Rust doesn't either.

But then why does bindgen attempt to have bitfields at all. Yes, I see the unsafe but wouldn't it be "safer" to recommend exporting C helper functions to deal with this? I actually don't understand how any crate can say they have "C-compatible" bitfields.

My mental model right now is: if the compilers are LLVM-based, then ABI should match up. This is most likely wrong.

If you see any inaccuracies, typos or have comments, please reach out @mdaverde.