<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">_array produces a ctype, not an actual
array itself. To get an array you can create one with malloc or
you can call a C function through the ffi.<br>
<br>
If you use malloc then you get back a generic #<cpointer>
type which you can convert to an array using ptr-ref as per the
docs:<br>
<br>
"Since an array is treated like a struct, casting a pointer type
to an array type does not work. Instead, use ptr-ref with a
pointer, an array type constructed with _array, and index 0 to
convert a pointer to a Racket representation that works with
array-ref and array-set!."<br>
<br>
-> (require ffi/unsafe)<br>
-> (define t (_array _int 3))<br>
-> (define x (malloc t))<br>
-> (define a (ptr-ref x t 0))<br>
-> a<br>
#<array><br>
-> (array? a)<br>
#t<br>
-> (array-ref a 1)<br>
1056768<br>
-> (array-set! a 1 12)<br>
-> (array-ref a 1)<br>
12<br>
<br>
Or as an ffi function type (-> _int -> (_array _int 3)),
although I didn't test that.<br>
<br>
On 12/13/2012 11:48 PM, 刘海宽 wrote:<br>
</div>
<blockquote cite="mid:tencent_44AE6DB42AC19FA5775E3150@qq.com"
type="cite">in the reference, I see the _array function, but I
don't understand well, when i try to do, always output errors, can
anyone give me an example? <br>
here is my test in REPL:<br>
<br>
racket@> (_array _int 3)<br>
#<ctype><br>
racket@> (array? (_array _int 3)) ; why?<br>
#f<br>
racket@> <br>
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">____________________
Racket Users list:
<a class="moz-txt-link-freetext" href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a>
</pre>
</blockquote>
<br>
</body>
</html>