caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: francois bereux <francois.bereux@fr.thalesgroup.com>
To: caml-list@inria.fr
Subject: [Caml-list] interfacing C with Ocaml (beginner questions)
Date: Thu, 07 Jun 2001 16:38:16 +0200	[thread overview]
Message-ID: <3B1F91D8.7AFF0264@fr.thalesgroup.com> (raw)

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çois


------------- add.c -----------------
#include  <caml/mlvalues.h>
#include  <caml/memory.h>

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 = "add";;

--------------myprog.ml---------------
open Math;;

let x=3 and y=86 in
   print_int (add x y);;



-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


             reply	other threads:[~2001-06-07 14:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-07 14:38 francois bereux [this message]
2001-06-07 15:05 ` Markus Mottl
2001-06-08 17:09 Damien Doligez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3B1F91D8.7AFF0264@fr.thalesgroup.com \
    --to=francois.bereux@fr.thalesgroup.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).