[ocaml-ctypes] Bit field encoding.

Jeremy Yallop yallop at gmail.com
Wed May 28 03:36:59 BST 2014


On 20 May 2014 14:53, Philippe Veber <philippe.veber at gmail.com> wrote:
> Thanks a lot Jeremy for your answer! I have chosen to write helper C
> functions to access the records containing bitfields, so that I let the
> compiler do its business without caring too much. I guess that no field
> after a bitfield definition in a struct can be reliably accessed either
> (with ctypes), even if it's not a bitfield itself (as there is no means to
> know if the bitfield was packed or padded). Is that right?

Yes, I think that's strictly true, although it's probably possible to
predict how things will be laid out in particular cases.

In a future release there'll be the option to query the C compiler
about struct layout directly, at which point we should have better
guarantees about access to structs with bitfields:

   https://github.com/ocamllabs/ocaml-ctypes/pull/62

Jeremy.


More information about the Ctypes mailing list