From: Olivier Andrieu <oandrieu@nerim.net>
To: Damien Doligez <damien.doligez@inria.fr>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] C interface style question
Date: Sun, 12 Feb 2006 21:40:32 +0100 [thread overview]
Message-ID: <17391.40256.369673.840468@karryall.dnsalias.org> (raw)
In-Reply-To: <0E70B6E0-7C47-40FD-B5C7-51F497847047@inria.fr>
Replying to a somehow old message here ...
Damien Doligez [Friday 20 January 2006] :
>
> On Jan 19, 2006, at 15:52, Olivier Andrieu wrote:
>
> > Thomas Fischbacher [Thursday 19 January 2006] :
> >> One more question about this: can I interface a C function in such
> >> a way that it uses an OCaml float array to store its output data,
> >> i.e. pass &(Double_field(ml_output,0)) as a double* "output
> >> parameter"?
> >
> > You can only do this on platform that accept doubles aligned on word
> > boundaries (such as x86). On those platforms, OCaml's config.h
> > undefines ARCH_ALIGN_DOUBLE. So your code might look like this :
> >
> > ,----
> > | double *c_array;
> > | #ifdef ARCH_ALIGN_DOUBLE
> > | c_array = /* allocate temporary storage and copy the caml float
> > array */
> > | #else
> > | c_array = (double *) ml_array;
> > | #endif
> > |
> > | /* use c_array */
> > |
> > | #ifdef ARCH_ALIGN_DOUBLE
> > | free (c_array);
> > | #endif
> > `----
>
> This is correct, except for the way you get the pointer. You should
> do it
> properly with &(Double_field(ml_array,0)). There is no guarantee that
> the value ml_array points to the first element of the array.
Err... I don't get it.
in mlvalues.h, I have (with ARCH_ALIGN_DOUBLE undefined) :
#define Double_val(v) (* (double *)(v))
#define Double_field(v,i) Double_val((value)((double *)(v) + (i)))
so &(Double_field(ml_array, 0)) looks pretty equivalent to a simple
cast to double*, no ?
Also how would it happen that ml_array does not point to first element
of the array ?
--
Olivier
next prev parent reply other threads:[~2006-02-12 20:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-18 18:28 Thomas Fischbacher
2006-01-18 19:18 ` [Caml-list] " Gerd Stolpmann
2006-01-18 20:32 ` Florent Monnier
2006-01-18 21:31 ` Gerd Stolpmann
2006-01-18 23:21 ` Florent Monnier
2006-01-18 23:43 ` Robert Roessler
2006-01-19 0:39 ` Jacques Garrigue
2006-01-19 3:17 ` skaller
2006-01-19 14:09 ` Damien Doligez
2006-01-19 14:17 ` Thomas Fischbacher
2006-01-19 14:24 ` Thomas Fischbacher
2006-01-19 14:52 ` Olivier Andrieu
2006-01-20 10:49 ` Damien Doligez
2006-02-12 20:40 ` Olivier Andrieu [this message]
2006-02-13 9:45 ` Damien Doligez
2006-01-19 15:15 ` Thomas Fischbacher
2006-01-30 13:12 ` On Store_field() Thomas Fischbacher
2006-01-30 14:05 ` [Caml-list] " Olivier Andrieu
2006-01-19 12:13 ` [Caml-list] C interface style question Thomas Fischbacher
2006-01-19 13:49 ` Jacques Garrigue
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17391.40256.369673.840468@karryall.dnsalias.org \
--to=oandrieu@nerim.net \
--cc=caml-list@inria.fr \
--cc=damien.doligez@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox