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

Daniel Bünzli daniel.buenzli at erratique.ch
Fri Oct 17 14:46:12 BST 2014

Le vendredi, 17 octobre 2014 à 13:35, Trevor Smith a écrit :
> Hello,
> I am working on a ctypes binding to libuv [https://github.com/joyent/libuv], and I have two questions:
> 1) Is the recommended way to interact with C-defines the way described in this thread? http://lists.ocaml.org/pipermail/ctypes/2014-February/000064.html
I think so. If you want to pattern match you can have a look here:


> 2) What is the recommended way to deal with struct fields that vary depending upon platform?
> Libuv is a cross platform library, and has platform-specific fields for its structs. For example see the struct uv_loop_s.
I'm not familiar with the API but having a look at:  


Then I wouldn't bother at all about the private fields, just describe the constant part of the struct (and do you even need to ? It seems only stop_flag is interesting here, you could aswell treat the struct as an abstract data type). Now if really needed I would define C accessors for each private field and raise if the field is not available for the platform and ctypes-bind to these accessors.



More information about the Ctypes mailing list