[cffi-devel] A question about arrays and enums

Luís Oliveira luismbo at gmail.com
Mon Mar 7 10:14:54 UTC 2011


Hello Nik,

On Mar 2, 2011 6:01 PM, "nitralime" <nitralime at googlemail.com> wrote:
> Hopefully here is the right place to ask CFFI user related questions.
> What would be an appropriate CFFI definition for the following C entities?
>
> 1) typedef enum {
>        a = 0x01,
>        b = 0x02,
>        c = a | b,
>        d = 0x04 | c
>    } test;

It's a bit cumbersome to express that with CFFI. Something like
(defcenum (:a 1) ... (:c #.(logior 1 2)) ...).


> 2) typedef char XXX[8];
>
> How are the C arrays handled in CFFI?

There are some array operations such as mem-aref, and you can allocate
them using foreign-alloc. defcstruct supports arrays via :count.
There's also an :array type that will convert C arrays to Lisp arrays,
but it has some limitations and it's
undocumented (see src/types.lisp).

HTH,

--
Luís Oliveira
http://r42.eu/~luis




More information about the cffi-devel mailing list