Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] interfacing C and OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Lex Stein <stein@e...>
Subject: Re: [Caml-list] interfacing C and OCaml

Hi, In the C code allocate a memory block value of size 5 with tag 0.

CAMLparam0 ();
CAMLlocal2 (v, v1);
static value * clos;

v = alloc_tuple (5);
/* assign to the fields using the Store_Field macro */

clos = caml_named_value ("c_function_name")

/* where c_function_name is registered from within the Caml code
   via (Callback.register "c_function_name" function_name)
Then just call the Caml routine via callback like so: */

v1 = callback (*clos, v);

Remember to return from the C function with one of the CAMLreturn
macros to be friendly with the garbage collector.

Let me know if you have any further questions/problems with Caml/C
interaction. I'm happy to help.

Lex

--
Lex Stein                     http://www.eecs.harvard.edu/~stein/
stein@eecs.harvard.edu        TEL: 617-233-0246


On Thu, 26 Jun 2003, Jung Woon Ho wrote:

> Hi,
>
> Can anybody explain me if there is anyway that I can pass in
> a (int*int*int*int*int) from a C function to OCaml.
>
> Thank you.
>
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners