Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] interfacing C with Ocaml (beginner questions)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <mottl@m...>
Subject: Re: [Caml-list] interfacing C with Ocaml (beginner questions)
On Thu, 07 Jun 2001, francois bereux wrote:
> a) Is it possible (and if yes, how shall I do) to build a toplevel
> where my add function defined in C would be available ?

Yes, it is possible: just use the command "ocamlmktop" to link your
program, using all required files as arguments. This will produce
a toplevel.

If you find it cumbersome to remember how to link stuff for specific
targets, you can also use "OcamlMakefile", which automates all these
steps. Then you'd only have to write "make top" if you want to create
a toplevel out of your project. You can get it here:

  http://www.ai.univie.ac.at/~markus/home/ocaml_sources.html

> b) I managed to have C and Ocaml communicate using the Val_int and
> Int_val macros to convert value to the appropriate int type. But how
> should I proceed if I want that add operates on float (in Caml) i.e. on
> double in C ?
> I found a Double_val macro, but no Val_double. What is the solution ?

You have to use "copy_double" if you want to make an OCaml-float out
of a C-double. Note that this really allocates memory, it's not just a
conversion. See the chapter on interfacing to C in the manual for details:

  http://caml.inria.fr/ocaml/htmlman/manual030.html

Regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr