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
Need help: O'Caml C Interface
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Frank Christoph <christo@n...>
Subject: Need help: O'Caml C Interface

I have a C function 

  void getCharWidth(int code, double *x, double *y);

which returns its values in the two pointer arguments.  I tried to write a
stub function that creates a 2-tuple and passes it back:

  external width : int -> float * float = "ocaml_getCharWidth"


value ocaml_getCharWidth(value code)
  double x, y;

  r[0] = alloc_tuple(2);
  return r[0];

where I used Store_double_val because, as far as I can see, there is no
"Val_double" macro.  However, this gives me a segmentation fault.  I'm not
really sure I understand how the *_roots functions work.  Do the two local
variables x and y need to be declared as of type value?  If so, how can I
pass them to getCharWidth (since Double_val doesn't return an lvalue)?  What
am I doing wrong?

Frank Christoph                 Next Solution Co.      Tel: 0424-98-1811                             Fax: 0424-98-1500