I'm considering the use of a combination between OCaml and C code in a new application. It seems that calling C code from Ocaml is simple:
external name : type = C-function-name
However, it seems also that in the other way around (calling OCaml from C) is more complicated:
static void
call_ocaml_void (const char * name)
{ CAMLparam0 () ;
CAMLlocal1 (ostr) ;
ostr = caml_copy_string (name);
value * func = caml_named_value ("ocaml_puts") ;
if (func == NULL)
puts ("caml_named_value failed!") ;
else
caml_callback (*func, ostr) ;
CAMLreturn0 ;
} /* call_ocaml_void */
(Example from this page)
And especially, it involves copying.
Could anyone tell me if it is possible to allow access to a data structure from both languages? So the functions could pass only pointers to the structure, but both languages can read it anyway.
The objective is to do all the operations with OCaml, and then pass the data to the C environment in an efficient way.
Thanks!