From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 117C1BB81 for ; Sun, 12 Feb 2006 21:40:34 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k1CKeXfl010203 for ; Sun, 12 Feb 2006 21:40:33 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA32677 for ; Sun, 12 Feb 2006 21:40:33 +0100 (MET) Received: from mallaury.nerim.net (smtp-100-sunday.noc.nerim.net [62.4.17.100]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k1CKeWgr010200; Sun, 12 Feb 2006 21:40:32 +0100 Received: from karryall.dnsalias.org (oandrieu.pck.nerim.net [213.41.240.180]) by mallaury.nerim.net (Postfix) with ESMTP id 6CE0D4F3A4; Sun, 12 Feb 2006 21:40:20 +0100 (CET) Received: by karryall.dnsalias.org (Postfix, from userid 500) id 7AD78596FE6; Sun, 12 Feb 2006 21:40:32 +0100 (CET) From: Olivier Andrieu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <17391.40256.369673.840468@karryall.dnsalias.org> Date: Sun, 12 Feb 2006 21:40:32 +0100 To: Damien Doligez Cc: caml users Subject: Re: [Caml-list] C interface style question In-Reply-To: <0E70B6E0-7C47-40FD-B5C7-51F497847047@inria.fr> References: <20060119.093955.97297811.garrigue@math.nagoya-u.ac.jp> <1137640656.8943.183.camel@rosella> <02FDC6F0-122C-42BA-A2F4-15E2B08248C8@inria.fr> <17359.42955.268490.985894@karryall.dnsalias.org> <0E70B6E0-7C47-40FD-B5C7-51F497847047@inria.fr> X-Mailer: VM 7.19 under Emacs 21.4.1 X-Miltered: at concorde with ID 43EF9D41.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43EF9D40.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; andrieu:01 oandrieu:01 nerim:01 caml-list:01 damien:01 andrieu:01 ocaml:01 doubles:01 aligned:01 ocaml's:01 config:01 ifdef:01 ifdef:01 pointer:01 mlvalues:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 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