---
name: "Comparison.h"
section: "3"
platform: "linux"
package: "libzycore-doc"
version: "1.5.2-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Comparison.h"
---

# Comparison.h(3)

## NAME

include/Zycore/Comparison.h

## SYNOPSIS

`#include <Zycore/Defines.h>`\
 `#include <Zycore/Types.h>`\

### Macros

\#define **ZYAN\_DECLARE\_EQUALITY\_COMPARISON**(name,  type)\
 \#define **ZYAN\_DECLARE\_EQUALITY\_COMPARISON\_FOR\_FIELD**(name,  type,  field\_name)\
 \#define **ZYAN\_DECLARE\_COMPARISON**(name,  type)\
 \#define **ZYAN\_DECLARE\_COMPARISON\_FOR\_FIELD**(name,  type,  field\_name)\

### Typedefs

typedef **ZyanBool**(\* **ZyanEqualityComparison**) (const void \*left, const void \*right)\
 typedef ZyanI32(\* **ZyanComparison**) (const void \*left, const void \*right)\

### Functions

ZYAN\_INLINE **ZYAN\_DECLARE\_EQUALITY\_COMPARISON** (ZyanEqualsPointer, void \*const) ZYAN\_INLINE ZYAN\_DECLARE\_EQUALITY\_COMPARISON(ZyanEqualsBool\
 ZYAN\_INLINE **ZyanBool** ZYAN\_INLINE **ZYAN\_DECLARE\_EQUALITY\_COMPARISON** (ZyanEqualsNumeric8, ZyanU8) ZYAN\_INLINE ZYAN\_DECLARE\_EQUALITY\_COMPARISON(ZyanEqualsNumeric16\
 ZYAN\_INLINE **ZyanBool** ZYAN\_INLINE ZyanU16 ZYAN\_INLINE **ZYAN\_DECLARE\_EQUALITY\_COMPARISON** (ZyanEqualsNumeric32, ZyanU32) ZYAN\_INLINE ZYAN\_DECLARE\_EQUALITY\_COMPARISON(ZyanEqualsNumeric64\
 ZYAN\_INLINE **ZyanBool** ZYAN\_INLINE ZyanU16 ZYAN\_INLINE ZyanU64 ZYAN\_INLINE **ZYAN\_DECLARE\_COMPARISON** (ZyanComparePointer, void \*const) ZYAN\_INLINE ZYAN\_DECLARE\_COMPARISON(ZyanCompareBool\
 ZYAN\_INLINE **ZyanBool** ZYAN\_INLINE ZyanU16 ZYAN\_INLINE ZyanU64 ZYAN\_INLINE **ZyanBool** ZYAN\_INLINE **ZYAN\_DECLARE\_COMPARISON** (ZyanCompareNumeric8, ZyanU8) ZYAN\_INLINE ZYAN\_DECLARE\_COMPARISON(ZyanCompareNumeric16\
 ZYAN\_INLINE **ZyanBool** ZYAN\_INLINE ZyanU16 ZYAN\_INLINE ZyanU64 ZYAN\_INLINE **ZyanBool** ZYAN\_INLINE ZyanU16 ZYAN\_INLINE **ZYAN\_DECLARE\_COMPARISON** (ZyanCompareNumeric32, ZyanU32) ZYAN\_INLINE ZYAN\_DECLARE\_COMPARISON(ZyanCompareNumeric64\

## Detailed Description

Defines prototypes of general-purpose comparison functions.

## Macro Definition Documentation

### #define ZYAN\_DECLARE\_COMPARISON(name, type)

**Value:**.PP

```
    ZyanI32 name(const type* left, const type* right) \
    { \
        ZYAN_ASSERT(left); \
        ZYAN_ASSERT(right); \
        \
        if (*left < *right) \
        { \
            return -1; \
        } \
        if (*left > *right) \
        { \
            return  1; \
        } \
        return 0; \
    }
```

Declares a generic comparison function for an integral data-type.

**Parameters**

*name* The name of the function. \
 *type* The name of the integral data-type.

### #define ZYAN\_DECLARE\_COMPARISON\_FOR\_FIELD(name, type, field\_name)

**Value:**.PP

```
    ZyanI32 name(const type* left, const type* right) \
    { \
        ZYAN_ASSERT(left); \
        ZYAN_ASSERT(right); \
        \
        if (left->field_name < right->field_name) \
        { \
            return -1; \
        } \
        if (left->field_name > right->field_name) \
        { \
            return  1; \
        } \
        return 0; \
    }
```

Declares a generic comparison function that compares a single integral data-type field of a struct.

**Parameters**

*name* The name of the function. \
 *type* The name of the integral data-type. \
 *field\_name* The name of the struct field.

### #define ZYAN\_DECLARE\_EQUALITY\_COMPARISON(name, type)

**Value:**.PP

```
    ZyanBool name(const type* left, const type* right) \
    { \
        ZYAN_ASSERT(left); \
        ZYAN_ASSERT(right); \
        \
        return (*left == *right) ? ZYAN_TRUE : ZYAN_FALSE; \
    }
```

Declares a generic equality comparison function for an integral data-type.

**Parameters**

*name* The name of the function. \
 *type* The name of the integral data-type.

### #define ZYAN\_DECLARE\_EQUALITY\_COMPARISON\_FOR\_FIELD(name, type, field\_name)

**Value:**.PP

```
    ZyanBool name(const type* left, const type* right) \
    { \
        ZYAN_ASSERT(left); \
        ZYAN_ASSERT(right); \
        \
        return (left->field_name == right->field_name) ? ZYAN_TRUE : ZYAN_FALSE; \
    }
```

Declares a generic equality comparison function that compares a single integral data-type field of a struct.

**Parameters**

*name* The name of the function. \
 *type* The name of the integral data-type. \
 *field\_name* The name of the struct field.

## Typedef Documentation

### typedef ZyanI32(\* ZyanComparison) (const void \*left, const void \*right)

Defines the `ZyanComparison` function prototype.

**Parameters**

*left* A pointer to the first element. \
 *right* A pointer to the second element.

**Returns**

This function should return values in the following range: `left == right -> result == 0` `left < right -> result < 0` `left > right -> result > 0`

### typedef ZyanBool(\* ZyanEqualityComparison) (const void \*left, const void \*right)

Defines the `ZyanEqualityComparison` function prototype.

**Parameters**

*left* A pointer to the first element. \
 *right* A pointer to the second element.

**Returns**

This function should return `ZYAN_TRUE` if the `left` element equals the `right` one or `ZYAN_FALSE`, if not.

## Function Documentation

### ZYAN\_INLINE ZyanBool ZYAN\_INLINE ZyanU16 ZYAN\_INLINE ZyanU64 ZYAN\_INLINE ZyanBool ZYAN\_INLINE ZyanU16 ZYAN\_INLINE ZYAN\_DECLARE\_COMPARISON (ZyanCompareNumeric32, ZyanU32)

Defines a default comparison function for 32-bit numeric values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is less than the `right` one, or `1` if the `left` value is greater than the `right` one. Defines a default comparison function for 64-bit numeric values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is less than the `right` one, or `1` if the `left` value is greater than the `right` one.

### ZYAN\_INLINE ZyanBool ZYAN\_INLINE ZyanU16 ZYAN\_INLINE ZyanU64 ZYAN\_INLINE ZyanBool ZYAN\_INLINE ZYAN\_DECLARE\_COMPARISON (ZyanCompareNumeric8, ZyanU8)

Defines a default comparison function for 8-bit numeric values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is less than the `right` one, or `1` if the `left` value is greater than the `right` one. Defines a default comparison function for 16-bit numeric values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is less than the `right` one, or `1` if the `left` value is greater than the `right` one.

### ZYAN\_INLINE ZyanBool ZYAN\_INLINE ZyanU16 ZYAN\_INLINE ZyanU64 ZYAN\_INLINE ZYAN\_DECLARE\_COMPARISON (ZyanComparePointer, void \* const)

Defines a default comparison function for pointer values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is less than the `right` one, or `1` if the `left` value is greater than the `right` one. Defines a default comparison function for `ZyanBool` values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `0` if the `left` value equals the `right` one, `-1` if the `left` value is less than the `right` one, or `1` if the `left` value is greater than the `right` one.

### ZYAN\_INLINE ZyanBool ZYAN\_INLINE ZyanU16 ZYAN\_INLINE ZYAN\_DECLARE\_EQUALITY\_COMPARISON (ZyanEqualsNumeric32, ZyanU32)

Defines a default equality comparison function for 32-bit numeric values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if not. Defines a default equality comparison function for 64-bit numeric values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if not.

### ZYAN\_INLINE ZyanBool ZYAN\_INLINE ZYAN\_DECLARE\_EQUALITY\_COMPARISON (ZyanEqualsNumeric8, ZyanU8)

Defines a default equality comparison function for 8-bit numeric values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if not. Defines a default equality comparison function for 16-bit numeric values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if not.

### ZYAN\_INLINE ZYAN\_DECLARE\_EQUALITY\_COMPARISON (ZyanEqualsPointer, void \* const)

Defines a default equality comparison function for pointer values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if not. Defines a default equality comparison function for `ZyanBool` values.

**Parameters**

*left* A pointer to the first value. \
 *right* A pointer to the second value.

**Returns**

Returns `ZYAN_TRUE` if the `left` value equals the `right` one or `ZYAN_FALSE`, if not.

## Author

Generated automatically by Doxygen for Zycore from the source code.
