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"
via:
value ocaml_getCharWidth(value code)
{
double x, y;
Push_roots(r,1);
r[0] = alloc_tuple(2);
getCharWidth(Int_val(code),&x,&y);
Store_double_val(Field(r[0],0),x);
Store_double_val(Field(r[0],1),y);
Pop_roots();
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
christo@nextsolution.co.jp Fax: 0424-98-1500