Instead through iteration like for or do which assign values to element of array, deliver list or vector directly to the ctype function imported by ffi.<br>Because I think that operating the list or vector with built-in functions is more conveniently than the ctype array.<br>In the reference, I find _array/list and _array/vector function, here is the description:<br><br><div class="SIntrapara">"Like <span class="RktSym"><a class="RktValLink" data-pltdoc="x">_array</a></span>, but the Racket representation is a list (or list
of lists for a multidimensional array) of elements copied to and from
an underlying C array."<br><br>and I test the two functions, after deliver their cpointers as arguments to ctype function, the list or vector doesn't change. here is my code:<br><br>#lang racket<br>(require ffi/unsafe<br> ffi/unsafe/define)<br><br>(define-ffi-definer define-sm (ffi-lib "scalam"))<br><br>;;----------------------------------------------<br> ; sm add element of array with 1.<br>;<br>; int sm(int m, int n, double * p)<br>; {<br>; int i, j;<br>; double *p_end;<br>; p_end = p + (m * n) - 1;<br>; for (;p <= p_end; p++)<br>; (*p) = (* p) + 1;<br>; <br>; return 0;<br>; }<br>;---------------------------------------------------------<br>(define-sm sm (_fun _int _int _pointer -> _int)) <br><br>(define t (_array/vector _double 3))<br>(define x (malloc t))<br>(define a (ptr-ref x t 0))<br><br>(for ((i '(0 1 2)))<br> (vector-set! a i (+ i 1.0)))<br><br>(define info (sm 3 1 x))<br><br>(for ((i '(0 1 2)))<br> (display (vector-ref a i))<br></div>;=====================<br>a doesn't change. or is there something wrong?<br><br>thank you.<br><div><div style="color:#909090;font-family:Arial Narrow;font-size:12px">------------------</div><div style="font-size:14px;font-family:Verdana;color:#000;">lhk</div></div><div> </div>