[ocaml-ctypes] Defines, and Structs with platform-specific fields

Jeremy Yallop yallop at gmail.com
Sat Oct 25 19:31:05 BST 2014


On 20 October 2014 21:46, Jeremy Yallop <yallop at gmail.com> wrote:
> This discussion is a useful reminder that ctypes really needs support
> for retrieving struct layout details from the declared API.  I'll look
> at how to add that support later this week and report back.

I've added support for retrieving struct layout from C in a pull request:

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

It works in a very similar fashion to cstubs: you put your struct
declaration inside a functor

  module Bindings(S : Cstubs_structs.STRUCT) =
  struct
    open S
    let cell       = structure "cell"
    let payload = field cell int "payload"
    let next      = field cell (ptr cell) "next"
    let ()          = seal cell
  end

and then call Cstubs_structs.write_c to generate an ML module with
which to instantiate the functor.

The pull request has more details and some illustrative tests.


More information about the Ctypes mailing list