Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/share/doc/libffi7/html/ drwxr-xr-x | |
| Viewing file: Select action/file-type: Next: Type Example, Previous: Size and Alignment, Up: Types [Index] 2.3.4 Arrays, Unions, and Enumerations2.3.4.1 Arrays‘libffi’ does not have direct support for arrays or unions. However, they can be emulated using structures. To emulate an array, simply create an ffi_type array_type; ffi_type **elements int i; elements = malloc ((n + 1) * sizeof (ffi_type *)); for (i = 0; i < n; ++i) elements[i] = array_element_type; elements[n] = NULL; array_type.size = array_type.alignment = 0; array_type.type = FFI_TYPE_STRUCT; array_type.elements = elements; Note that arrays cannot be passed or returned by value in C –
structure types created like this should only be used to refer to
members of real However, a phony array type like this will not cause any errors from ‘libffi’ if you use it as an argument or return type. This may be confusing. 2.3.4.2 UnionsA union can also be emulated using One simple way to do this is to ensue that each element type is laid out. Then, give the new structure type a single element; the size of the largest element; and the largest alignment seen as well. This example uses the ffi_abi desired_abi;
ffi_type union_type;
ffi_type **union_elements;
int i;
ffi_type element_types[2];
element_types[1] = NULL;
union_type.size = union_type.alignment = 0;
union_type.type = FFI_TYPE_STRUCT;
union_type.elements = element_types;
for (i = 0; union_elements[i]; ++i)
{
ffi_cif cif;
if (ffi_prep_cif (&cif, desired_abi, 0, union_elements[i], NULL) == FFI_OK)
{
if (union_elements[i]->size > union_type.size)
{
union_type.size = union_elements[i];
size = union_elements[i]->size;
}
if (union_elements[i]->alignment > union_type.alignment)
union_type.alignment = union_elements[i]->alignment;
}
}
2.3.4.3 Enumerations
Next: Type Example, Previous: Size and Alignment, Up: Types [Index] |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0067 ]-- |