Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2001-06-07 (15:05)
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:

> 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:

Markus Mottl

Markus Mottl,,
Bug reports:  FAQ:
To unsubscribe, mail  Archives: