<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2006/02/962385fdb164edd1ed6b71a33b90aec6"
  from="Olivier Andrieu &lt;oandrieu@n...&gt;"
  author="Olivier Andrieu"
  date="2006-02-12T20:40:34"
  subject="Re: [Caml-list] C interface style question"
  prev="2006/02/a51f7a8ac5ce6d0b7ddd632d1c82c550"
  next="2006/02/20b9bddf6cd70a75c82f40d837c93956"
  prev-in-thread="2006/01/a8a5a8a9ee7fd2b71cc74835c2f7b924"
  next-in-thread="2006/02/d346c56a895af1e7acafba888010f84d"
  prev-thread="2006/01/36aaa28f8a610df461cd41838dff2a3c"
  next-thread="2006/01/dd3c4505af44836e5904d9997aab0d9e"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="C interface style question">
<msg 
  url="2006/01/d95e069e55697ffbd5bfd2b43dc9ec6f"
  from="Thomas Fischbacher &lt;Thomas.Fischbacher@P...&gt;"
  author="Thomas Fischbacher"
  date="2006-01-18T18:28:33"
  subject="C interface style question">
<msg 
  url="2006/01/ec4103913cc97b03dbc616a8131ab411"
  from="Gerd Stolpmann &lt;info@g...&gt;"
  author="Gerd Stolpmann"
  date="2006-01-18T19:18:19"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/01/00eee80fddf45046f944857209faffd5"
  from="Florent Monnier &lt;fmonnier@l...&gt;"
  author="Florent Monnier"
  date="2006-01-18T20:24:20"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/01/1323ce1ea39467d6d7be0b514c1541bd"
  from="Gerd Stolpmann &lt;info@g...&gt;"
  author="Gerd Stolpmann"
  date="2006-01-18T21:31:09"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/01/1cd9530d13e9ad5abfe68e8cdf25f0ef"
  from="Florent Monnier &lt;fmonnier@l...&gt;"
  author="Florent Monnier"
  date="2006-01-18T23:12:47"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/01/1ad7bee43eb78cb91ec000e9eb6ab3b7"
  from="Robert Roessler &lt;roessler@r...&gt;"
  author="Robert Roessler"
  date="2006-01-19T00:07:48"
  subject="Re: [Caml-list] C interface style question">
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2006/01/70a71816df29b78ccbc20c9f41a34754"
  from="Jacques Garrigue &lt;garrigue@m...&gt;"
  author="Jacques Garrigue"
  date="2006-01-19T00:38:28"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/01/3b66654b5637672f592f341b8c2c6d77"
  from="skaller &lt;skaller@u...&gt;"
  author="skaller"
  date="2006-01-19T03:17:43"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/01/7811ef53b64e211284b6520300de7d77"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2006-01-19T14:09:00"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/01/1a6aec97d6ff701a0aa3a56f7cf6237c"
  from="Thomas Fischbacher &lt;Thomas.Fischbacher@P...&gt;"
  author="Thomas Fischbacher"
  date="2006-01-19T14:17:34"
  subject="Re: [Caml-list] C interface style question">
</msg>
<msg 
  url="2006/01/7ea9f4f55a50f3a997ade75e2bbe9008"
  from="Thomas Fischbacher &lt;Thomas.Fischbacher@P...&gt;"
  author="Thomas Fischbacher"
  date="2006-01-19T14:24:59"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/01/3ccfd582e9d3ecef281400eaace1a9f7"
  from="Olivier Andrieu &lt;oandrieu@n...&gt;"
  author="Olivier Andrieu"
  date="2006-01-19T14:53:00"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/01/a8a5a8a9ee7fd2b71cc74835c2f7b924"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2006-01-20T10:49:27"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/02/962385fdb164edd1ed6b71a33b90aec6"
  from="Olivier Andrieu &lt;oandrieu@n...&gt;"
  author="Olivier Andrieu"
  date="2006-02-12T20:40:34"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/02/d346c56a895af1e7acafba888010f84d"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2006-02-13T09:45:25"
  subject="Re: [Caml-list] C interface style question">
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2006/01/e7b42fa015233da439ea8381752144a3"
  from="Thomas Fischbacher &lt;Thomas.Fischbacher@P...&gt;"
  author="Thomas Fischbacher"
  date="2006-01-19T15:15:19"
  subject="Re: [Caml-list] C interface style question">
</msg>
<msg 
  url="2006/01/0a655cea5a4df9a51acd73c898e41525"
  from="Thomas Fischbacher &lt;Thomas.Fischbacher@P...&gt;"
  author="Thomas Fischbacher"
  date="2006-01-30T13:12:42"
  subject="On Store_field()">
<msg 
  url="2006/01/674a9b2c80facff77a5118b448d41b46"
  from="Olivier Andrieu &lt;oandrieu@n...&gt;"
  author="Olivier Andrieu"
  date="2006-01-30T14:05:32"
  subject="Re: [Caml-list] On Store_field()">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2006/01/85633c91a5c3a30e200faa80bdd97520"
  from="Thomas Fischbacher &lt;Thomas.Fischbacher@P...&gt;"
  author="Thomas Fischbacher"
  date="2006-01-19T12:13:43"
  subject="Re: [Caml-list] C interface style question">
<msg 
  url="2006/01/663b3dcd51ed2c9256855f5f6e129a8b"
  from="Jacques Garrigue &lt;garrigue@m...&gt;"
  author="Jacques Garrigue"
  date="2006-01-19T13:49:36"
  subject="Re: [Caml-list] C interface style question">
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
Replying to a somehow old message here ...

 Damien Doligez [Friday 20 January 2006] :
 &gt;
 &gt; On Jan 19, 2006, at 15:52, Olivier Andrieu wrote:
 &gt; 
 &gt; &gt;  Thomas Fischbacher [Thursday 19 January 2006] :
 &gt; &gt;&gt; One more question about this: can I interface a C function in such
 &gt; &gt;&gt; a way that it uses an OCaml float array to store its output data,
 &gt; &gt;&gt; i.e. pass &amp;(Double_field(ml_output,0)) as a double* "output
 &gt; &gt;&gt; parameter"?
 &gt; &gt;
 &gt; &gt; You can only do this on platform that accept doubles aligned on word
 &gt; &gt; boundaries (such as x86). On those platforms, OCaml's config.h
 &gt; &gt; undefines ARCH_ALIGN_DOUBLE. So your code might look like this :
 &gt; &gt;
 &gt; &gt; ,----
 &gt; &gt; |   double *c_array;
 &gt; &gt; | #ifdef ARCH_ALIGN_DOUBLE
 &gt; &gt; |   c_array = /* allocate temporary storage and copy the caml float  
 &gt; &gt; array */
 &gt; &gt; | #else
 &gt; &gt; |   c_array = (double *) ml_array;
 &gt; &gt; | #endif
 &gt; &gt; |
 &gt; &gt; |   /* use c_array */
 &gt; &gt; |
 &gt; &gt; | #ifdef ARCH_ALIGN_DOUBLE
 &gt; &gt; |   free (c_array);
 &gt; &gt; | #endif
 &gt; &gt; `----
 &gt; 
 &gt; This is correct, except for the way you get the pointer.  You should  
 &gt; do it
 &gt; properly with &amp;(Double_field(ml_array,0)).  There is no guarantee that
 &gt; 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 &amp;(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

</contents>

</message>

