Next: , Previous: , Up: Types   [Index]


2.3.3 Size and Alignment

libffi will set the size and alignment fields of an ffi_type object for you. It does so using its knowledge of the ABI.

You might expect that you can simply read these fields for a type that has been laid out by libffi. However, there are some caveats.

So, before examining these fields, it is safest to pass the ffi_type object to ffi_prep_cif first. This function will do all the needed setup.

ffi_type *desired_type;
ffi_abi desired_abi;
…
ffi_cif cif;
if (ffi_prep_cif (&cif, desired_abi, 0, desired_type, NULL) == FFI_OK)
  {
    size_t size = desired_type->size;
    unsigned short alignment = desired_type->alignment;
  }