This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: Arrays and unions
On 08/20/2011 07:40 PM, Eli Barzilay wrote:
> An issue that we had open for a long time is a lack of support for
> arrays and unions. We've finally implemented them, both in a similar
> way:
>
> libffi_type = malloc(sizeof(ffi_type));
> libffi_type->size = sz;
> libffi_type->alignment = align;
> libffi_type->type = FFI_TYPE_STRUCT;
> libffi_type->elements = elements;
>
> The question is -- is FFI_TYPE_STRUCT the right choice here?
For unions, yes. They must be laid out in the same way as structs.
There's no way to pass an array by value in C, so no C ABI can support
passing arrays, and AFAICS there's nothing that libffi can do with
them. If you want to wrap arrays in structs in your native code
that'll be fine.
Andrew.