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 -> CAML linking: loosing values in arrays??
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-01-11 (19:08)
From: Daniel Andor <da209@c...>
Subject: [Caml-list] C -> CAML linking: loosing values in arrays??
Hi All,

I'm trying to call a numerical routine I wrote in caml from c.  I'm using the 
-output-obj option of ocamlopt, and have stub functions in c that convert the 
parameters.  Since it's for numerics, I want to pass arrays of doubles.  So I 
use make_float_array from below to convert a 4dimensional doube array into a 
value ready to be passed to caml.

value make_float(double *d) 
  /* value of d intentionally ignored while we debug... */
  return copy_double(0.0);

#define NUM_DIMS 4
value make_float_array(double *ds)
  int i;
  double* p[NUM_DIMS+1];
  for (i=0; i<NUM_DIMS; i++)
    p[i] = &(ds[i]);
  return alloc_array(make_float,p);

The caml code gets called correctly, and from within it I can see that the 
length or the arrays and the content are bogus (they come out length 2, not 
4, with the first elements looking like this: 62.6141, not 0.0).

If I pass a non-array double using copy_double(), it works and I get the 
correct number on the other side.

Any ideas as to where I've gone wrong?

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: