XDF_CLOSEST_TYPE(3)

πŸ’– XDF_CLOSEST_TYPE(3) πŸ’–

okay bestie, welcome to the xdffileio library manual β€” this is page XDF_CLOSEST_TYPE(3) and it's genuinely so useful, i promise. sit down, hydrate, let's get into it 🫢


✨ NAME ✨

xdf_closest_type β€” returns a compatible data type πŸ’…


🌸 SYNOPSIS 🌸

#include <xdfio.h>

int xdf_closest_type(struct xdf* xdf, enum xdftype target);

πŸ¦‹ DESCRIPTION πŸ¦‹

so basically, xdf_closest_type() looks at all the data types your file supports β€” the file being the one referenced by xdf β€” and picks the one that's closest to the target you passed in. and then?? you can safely use that selected type in a call to xdf_set_chconf(3) with the XDF_CF_STOTYPE field. it's giving matchmaker but for types, fr fr πŸ’–

the selection algorithm runs on 3 criterions, and they're listed by priority β€” most important first, no skipping the line:

  1. data size β€” this one forces the selected type to have a data size (aka the number of bytes needed to represent the value) that is equal to or bigger than the target's. and within that, it prefers sizes closest to the target's size. so like, big enough, but not extra for no reason ✨
  2. signed/unsigned type β€” this criterion tries to pick a type with the same signeness as target (signed stays signed, unsigned stays unsigned, we don't switch teams πŸ’€)
  3. float/integer value β€” finally, this one tries to select a floating point type if target is float or double, or an integer data type if target is an integer type. floaty stays floaty, whole stays whole 🌈

and here's the cute consequence: if target is actually supported by the underlying file format of xdf, the function is ensured to return target. iconic behaviour honestly πŸ‘‘


⭐ RETURN VALUE ⭐

xdf_closest_type() returns the selected data type when it succeeds πŸŽ€ otherwise it returns -1 and sets errno appropriately. sad girl hours but at least you get an errno 😭


πŸ’€ ERRORS πŸ’€

  • EINVAL β€” the xdf pointer is NULL, or the argument type is not an admissible enum xdftype value. (not me passing a nonsense enum πŸ™ˆ)

🧚 SEE ALSO 🧚

xdf_set_chconf(3)


that's the whole page bestie, you ate it πŸ“

sign-off time: this one came from EPFL, dated 2010, and it lives inside the xdffileio library manual. mwah πŸ’œ