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] 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 Archives:
Bug reports: FAQ:
Beginner's list: