Browse thread
How to pass C pointers to Caml
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2010-03-01 (13:23) |
From: | Jianzhou Zhao <jianzhou@s...> |
Subject: | Re: [Caml-list] How to pass C pointers to Caml |
On Mon, Mar 1, 2010 at 1:22 AM, Florent Monnier <monnier.florent@gmail.com> wrote: > Le lundi 1 mars 2010 04:55:00, Jianzhou Zhao a écrit : >> I have been calling OCaml code from C in my project. >> The C code has some pointers to C structures. >> I got 'seg fault' when calling the OCaml function receiving >> C structure pointers. >> >> 18.7 at http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html >> gives the examples that pass int into OCaml. These examples work for me. >> But, Does OCaml support to pass C structure pointers to OCaml? > > Yes it does. Just cast your pointer to the type value. > > In this tutorial there is an example "Pointers to C structures": > http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.php#ref_ptr > > the pointer to a C struct is wrapped on the ocaml side by an abstract type > called "t" here, and it is provided back to C with print_t / dump_ptr. Thanks. This tutorial helps a lot when calling C from OCaml. What I was doing is more like calling OCaml from C, at section http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.php#ref_mlfromc. Because my main program is C. In this case, does OCaml have any restriction when passing a C pointer (which points to a struct) to OCaml runtme in this direction? Jianzhou > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- Jianzhou