From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA31879; Thu, 7 Jun 2001 16:40:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA31981 for ; Thu, 7 Jun 2001 16:40:31 +0200 (MET DST) Received: from gwsmtp.thomson-csf.com (gwsmtp.thomson-csf.com [195.101.39.226]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f57EeB925004 for ; Thu, 7 Jun 2001 16:40:14 +0200 (MET DST) Received: from thomplex.thomson-csf.com (200.3.2.2) by gwsmtp.thomson-csf.com (NPlex 5.1.053) id 3B1E908C00016A82 for caml-list@inria.fr; Thu, 7 Jun 2001 16:45:24 +0200 Received: from thomplex.thomson-csf.com (200.3.2.2) by thomplex.thomson-csf.com (NPlex 5.1.053) id 3B1C6AF20005121F for caml-list@inria.fr; Thu, 7 Jun 2001 16:40:07 +0200 Received: from mes1.ela.detexis.thomson-csf.com (61.14.31.2) by dexplex.detexis.thomson-csf.com (NPlex 5.1.053) id 3B18A4810000B173 for caml-list@inria.fr; Thu, 7 Jun 2001 16:40:01 +0200 Received: from mes1.ela.detexis.thomson-csf.com (61.14.31.2) by mes1.ela.detexis.thomson-csf.com (NPlex 5.1.053) id 3AE92A030002837E for caml-list@inria.fr; Thu, 7 Jun 2001 16:38:17 +0200 Received: from 61.25.85.156 by mes1.ela.detexis.thomson-csf.com (InterScan E-Mail VirusWall NT); Thu, 07 Jun 2001 16:38:17 +0200 (Paris, Madrid (heure d'été)) Message-ID: <3B1F91D8.7AFF0264@fr.thalesgroup.com> Date: Thu, 07 Jun 2001 16:38:16 +0200 From: francois bereux X-Mailer: Mozilla 4.75 [fr]C-CCK-MCD (WinNT; U) X-Accept-Language: fr-FR MIME-Version: 1.0 To: caml-list@inria.fr Subject: [Caml-list] interfacing C with Ocaml (beginner questions) Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: Quoted-Printable Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Dear list members, I have two (beginnner) questions about linking C and Ocaml. Following the documentation, I built a very simple example (see code below) that runs fine by doing : ocamlc -c add.c ocamlc -c math.mli ocamlc -c prog.ml ocamlc -custom -o myprog myprog.cmo add.o If I run ./myprog, I get the expected result. 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 ? 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 ? Thank you in advance for any help, Fran=E7ois ------------- add.c ----------------- #include #include value add(value x, value y) { CAMLparam2(x,y); return Val_int(Int_val(x)+Int_val(y)); } ------------- math.mli ----------------- external add: int -> int -> int =3D "add";; --------------myprog.ml--------------- open Math;; let x=3D3 and y=3D86 in print_int (add x y);; ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr