[ocaml-ctypes] Another dumb question
skaller at internode.on.net
Thu Dec 28 00:29:09 GMT 2017
> On 28 Dec. 2017, at 00:31, Jeremy Yallop <yallop at gmail.com> wrote:
> On 27 December 2017 at 05:33, john skaller <skaller at internode.on.net> wrote:
>> This should be a quicky….
>> Suppose I have some messy struct in C which is generally used
>> via a pointer. Eg
> The usual way of dealing with this is to define a struct using
> ‘structure' without calling 'field' or 'seal',
I started to do this. But I began to think it was dangerous.
The client of the binding is going to have to do some
low level work to use the binding, which is a bit nasty.
However exposing the structures and letting them poke
about in them feels too dangerous.
And a key struct also uses bitfield :)
In C++ you’d provide a constructor, and some accessor
and mutator methods, and make the actual data private.
In Ocaml, it feels more natural in these cases where
functional operations are favoured to make the structure
opaque, and if necessary for construction, write
some methods in C, and then provide binding to them.
skaller at users.sourceforge.net
More information about the Ctypes