The FLI :c-array
type converts between Lisp structures and C arrays. In C, pointers are used to access the elements of an array. The implementation of the :c-array
type takes this into account, by automatically dereferencing any pointers returned when accessing an array using foreign-aref
, unlike :foreign-array
.
Note that :c-array
uses the C convention that the first index value of an array is 0
.
The following code defines a 3 by 3 array of integers.
(setq array1 (fli:allocate-foreign-object
:type '(:c-array :int 3 3)))
The next example defines an array of arrays of bytes.
(setq array2 (fli:allocate-foreign-object
:type '(:c-array (:c-array :byte 3) 2)))
See foreign-aref and foreign-array-pointer for more examples on the use of arrays.