Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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];
  p[NUM_DIMS]=NULL;
  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?

Thanks,
Daniel.
-------------------
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