FFI_PREP_CIF_VAR(3)

πŸ’… ffi_prep_cif_var(3) β€” bestie's guide to variadic call prep πŸŽ€

okay so you're in section 3 of the manual (the library-functions girlies), and this page is all about ffi_prep_cif_var β€” the function you reach for when the function you're calling is a variadic one. yes, like printf-core. we're getting the ffi_cif struct ready to be handed off to ffi_call. let's GO ✨


✨ NAME ✨

ffi_prep_cif_var β€” prepares a ffi_cif structure for use with ffi_call when you're calling variadic functions. that's the whole job. she's a specialist πŸ’…


🌸 SYNOPSIS 🌸

#include <ffi.h>

ffi_status
ffi_prep_cif_var(ffi_cif *cif, ffi_abi abi, unsigned int nfixedargs,
    unsigned int ntotalargs, ffi_type *rtype, ffi_type **atypes);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like, the ffi_prep_cif_var function gets a ffi_cif structure ready to go for use with ffi_call, specifically for variadic functions. think of it as doing her hair and makeup before the big performance, no cap.

here's the cast of characters, bestie:

  • abi β€” tells her which set of calling conventions to use. the vibe check of the platform, basically.
  • atypes β€” an array of ntotalargs pointers to ffi_type structs, and each one describes the data type, size and alignment of one argument. all of them. every single one. πŸ‘‘
  • rtype β€” points to an ffi_type that describes the data type, size and alignment of the return value.
  • nfixedargs β€” must contain the number of fixed (i.e. non-variadic) arguments. this is not optional, this is the assignment.
🫢 lowkey important: if you're calling a function that is not variadic, you do NOT use this one β€” you use ffi_prep_cif instead. wrong function, wrong energy, don't do it.

πŸ’– RETURN VALUES πŸ’–

  • FFI_OK β€” returned upon successful completion. slay, we ate, periodt ✨
  • FFI_BAD_TYPEDEF β€” returned if cif is NULL, or if atypes or rtype is malformed. she said "this typedef is giving nothing" 😭
  • FFI_BAD_ABI β€” returned if abi doesn't refer to a valid ABI.

and psa bestie: the available ABIs are defined in <ffitarget.h>. go look there, iykyk πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘


that's the whole page, babe πŸŽ€ this one came from the ffi_prep_cif_var(3) manual page, dated January 25, 2011 β€” yeah she's an elder but she still eats. go forth and prep those variadic calls, main character πŸŒˆπŸ’œ

πŸ“¦ where this page comes from