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-15 (15:09)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] C -> CAML linking: loosing values in arrays??
On Saturday, January 11, 2003, at 08:07 PM, Daniel Andor wrote:

> parameters.  Since it's for numerics, I want to pass arrays of doubles.

>   return alloc_array(make_float,p);

You cannot use alloc_array to return a value of type [float array].
This is because arrays of floating-point numbers are not represented
like the other array types in O'Caml: they are allocated in-line,
without the usual pointer indirection.

You will have to allocate the array with [alloc], then fill in the
elements with [Store_double_field]:

#define NUM_DIMS 4
value make_float_array(double *ds)
   int i;
   value res;

   res = alloc (NUM_DIMS*Double_wosize, Double_array_tag);
   for (i=0; i<NUM_DIMS; i++){
     Store_double_field (res, i, ds[i]);
   return res;

-- Damien

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