---
name: "xdf_closest_type"
section: "3"
platform: "linux"
package: "libxdffileio-dev"
version: "0.3-4+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/xdf_closest_type"
---

# xdf\_closest\_type(3)

Returns a compatible data type

## NAME

xdf\_closest\_type - Returns a compatible data type

## SYNOPSIS

**#include \<xdfio.h\>**

**int xdf\_closest\_type(struct xdf\*** *xdf***, enum xdftype** *target***);**\

## DESCRIPTION

**xdf\_closest\_type**() selects among the data types supported by the file referenced by *xdf* the type that is the closest to the *target* argument. The selected type can then be safely used in a call to [**xdf\_set\_chconf**(3)](/xdf_set_chconf/3.md) with the **XDF\_CF\_STOTYPE** field.

The selection algorithm is based on the 3 following criterions (cited by priority, i.e. most important cited first): data size, signed/unsigned type, float/integer value. The data size criterion forces the selected type to have a data size (number of byte to represent the value) equal or bigger than the one of the target type (with a preference with sizes the closest to the size of *target*). The signed/unsigned criterion tries to select a type that has the same signeness (signed or unsigned data type) as the target. Finally the float/integer criterion tries to select a floating point type if *target* is float or double or an integer data type if *target* is an integer type.

As a consequence, if *target* is supported by the underlying file format of *xdf*, the function is ensured to return *target*.

## RETURN VALUE

**xdf\_closest\_type**() returns the selected data type in case of success, otherwise -1 and *errno* is set appropriately.

## ERRORS

- **EINVAL**

  the *xdf* pointer is **NULL**, or the argument *type* is not an admissible **enum xdftype** value.

## SEE ALSO

[**xdf\_set\_chconf**(3)](/xdf_set_chconf/3.md)
