---
name: "checkint"
section: "3"
platform: "macos"
package: "removefile"
version: "85.100.6"
release: "macOS 26.5"
platforms: ["macos"]
url: "https://new.carta.tech/checkint/3"
---

# checkint(3)

detect overflow in arithmetic

## NAME

**check\_int32\_add**, **check\_uint32\_add**, **check\_int64\_add**, **check\_uint64\_add**, **check\_int32\_sub**, **check\_uint32\_sub**, **check\_int64\_sub**, **check\_uint64\_sub**, **check\_int32\_mul**, **check\_uint32\_mul**, **check\_int64\_mul**, **check\_uint64\_mul**, **check\_int32\_div**, **check\_uint32\_div**, **check\_int64\_div**, **check\_uint64\_div**, – detect overflow in arithmetic

## SYNOPSIS

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

*int32\_t*\

**check\_int32\_add**(*int x*, *int y*, *int \*err*);

*uint32\_t*\

**check\_uint32\_add**(*int x*, *int y*, *int \*err*);

*int64\_t*\

**check\_int64\_add**(*int x*, *int y*, *int \*err*);

*uint64\_t*\

**check\_uint64\_add**(*int x*, *int y*, *int \*err*);

*int32\_t*\

**check\_int32\_sub**(*int x*, *int y*, *int \*err*);

*uint32\_t*\

**check\_uint32\_sub**(*int x*, *int y*, *int \*err*);

*int64\_t*\

**check\_int64\_sub**(*int x*, *int y*, *int \*err*);

*uint64\_t*\

**check\_uint64\_sub**(*int x*, *int y*, *int \*err*);

*int32\_t*\

**check\_int32\_mul**(*int x*, *int y*, *int \*err*);

*uint32\_t*\

**check\_uint32\_mul**(*int x*, *int y*, *int \*err*);

*int64\_t*\

**check\_int64\_mul**(*int x*, *int y*, *int \*err*);

*uint64\_t*\

**check\_uint64\_mul**(*int x*, *int y*, *int \*err*);

*int32\_t*\

**check\_int32\_div**(*int x*, *int y*, *int \*err*);

*uint32\_t*\

**check\_uint32\_div**(*int x*, *int y*, *int \*err*);

*int64\_t*\

**check\_int64\_div**(*int x*, *int y*, *int \*err*);

*uint64\_t*\

**check\_uint64\_div**(*int x*, *int y*, *int \*err*);

## DESCRIPTION

The **check\_\<type\>\_\<operation\>**(*x*, *y*, *err*) family of functions perform the specified arithmetic operation (addition, subtraction,  multiplication, or division) with the left operand of *x* and right operand of *y* and return the arithmetic result with the specified type.

Either operand  *x* or  *y* (or both) can be of any type that is compatible to signed or unsigned 8-bit, 16-bit, 32-bit, or 64-bit integers.

The *err* argument is  *or*'ed by flags in the function to indicate if an overflow has occurred.  The possible flag values are:

```
CHECKINT_NO_ERROR		no overflow has occurred
CHECKINT_OVERFLOW_ERROR		overflow has occurred
CHECKINT_TYPE_ERROR		operand is of an incompatible type
```

The *err* argument is not cleared in calls to the  **check\_\<type\>\_\<operation\>**(*x*, *y*, *err*) functions.  Detected overflow persists in the  *err* argument until *err* is reset to CHECKINT\_NO\_ERROR.

## RETURN VALUES

If successful, the **check\_\<type\>\_\<operation\>**() functions will return the arithmetic result of performing the operation with left operand *x* and right operand *y* (even when overflow error occurs).

If any other error occurs, the return value is -1 and the argument *err* will be set to indicate the error.

## EXAMPLES

```
/* Create a variable to store overflow flag */
int32_t err = CHECKINT_NO_ERROR;
/* Use checkint API to perform an arithmetic operation and
 * store result in variable. */
int32_t arithmetic_result = check_int32_add(UINT_MAX, 1, &err);
/* Check status of overflow flag */
if (err & CHECKINT_OVERFLOW_ERROR) {
    /* Perform overflow resolution code */
    fprintf(stderr, "Overflow detected!\n");
}
/* Check for type error */
else if (err & CHECKINT_TYPE_ERROR) {
    /* Deal with incompatible types error */
    fprintf(stderr, "Incompatible types!\n");
}
/* Reset overflow flag for next operation */
err = CHECKINT_NO_ERROR;
```

## ERRORS

The  **check\_\<type\>\_\<operation\>**() functions may fail if:

```
[CHECKINT_TYPE_ERROR]		operand is of an incompatible type
```

## HISTORY

The **checkint**() API was introduced in Mac OS X 10.5.
