[racket-dev] FFI: C arrays and unions

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Aug 20 13:26:44 EDT 2011

The FFI now includes support for C arrays and unions.

As Eli has noted, libffi (which Racket uses for calls to foreign
functions) doesn't exactly support arrays within structs (which is one
the main places to use arrays), but we're trying something. If you run
into problems, be at least a little suspicious of the FFI
implementation for now.

Use `_array' to construct an array ctype, and use `array-ref' and
`array-set!' on Racket representations of arrays. The `_array',
`array-ref', and `array-set!' functions support multiple dimensions.

Use `_union' to construct an array ctype, and use `union-ref' and
`union-set!' on Racket representations of unions. The union support is
minimal for now; variants are accessed by position instead of by a
name.



Posted on the dev mailing list.