I’m currently writing an OCaml binding to LXC (Linux Containers), and have some questions w.r.t. usage of ctypes.
1. Using function pointer as function?
My understanding after going through the ctypes document is one can convert an OCaml function to a function pointer to C side, carry function pointer around etc, but cannot use a C function pointer in OCaml’s side directly as if it’s a normal OCaml function.
Is this correct?
Context is LXC stores function pointers in the main struct (
lxc_container), and one would invoke the function via lines like
c->do_stuff(c, arg1, arg2, ...) to access the functionality.
Right now I’m relying on glue code generated using cinaps to access and invoke function pointer on C’s side, which seems to work fine. But I’m curious if there’s a better way.
2. Equivalent of
const * in ctypes?
It seems that I cannot specify a
const pointer via ctypes, which would make sense, but I want to double check I’m not being silly in any case.
Thanks very much for your time!