English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] C <-> OCaml questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-06-17 (09:35)
From: Jérôme_Marant <jerome.marant@f...>
Subject: [Caml-list] C <-> OCaml questions

  I'm currently writing OCaml bindings for some C libraries and
  I would like to get some details about how to convert C pointers
  to OCaml types.

  Let's assume we have the following C function:

    Bar * Foo(char *S);

  In OCaml, I would like to convert the (Bar *) type to

   type bar

  Question: how do I perform the conversion? Should I allocate
  a bloc of size sizeof(Bar *), assign the pointer value to it
  and return it to OCaml?
  How can I make it portable, i.e. independant on the size of
  pointers ? (32 or 64 bits).

   Let's assume we have the same C function:

   Bar * Foo(char *S);

   The OCaml matching function should be:

   val foo: string -> bar

   Now assume that NULL is a significant value for S.
   How can I tell OCaml to pass NULL to the C function?
   Should I create a specific version of foo with no
   argument but which passed NULL in the C interface?

  Thanks in advance.


Jérôme Marant
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