2 * Copyright (c) 2023 Dag-Erling Smørgrav
4 * SPDX-License-Identifier: BSD-2-Clause
7 #ifndef __STDC_VERSION_STDCKDINT_H__
8 #define __STDC_VERSION_STDCKDINT_H__ 202311L
10 #include <sys/cdefs.h>
12 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 2023
14 #if __GNUC_PREREQ__(5, 1) || __has_builtin(__builtin_add_overflow)
15 #define ckd_add(result, a, b) \
16 (_Bool)__builtin_add_overflow((a), (b), (result))
18 #define ckd_add(result, a, b) \
19 _Static_assert(0, "checked addition not supported")
22 #if __GNUC_PREREQ__(5, 1) || __has_builtin(__builtin_sub_overflow)
23 #define ckd_sub(result, a, b) \
24 (_Bool)__builtin_sub_overflow((a), (b), (result))
26 #define ckd_sub(result, a, b) \
27 _Static_assert(0, "checked subtraction not supported")
30 #if __GNUC_PREREQ__(5, 1) || __has_builtin(__builtin_mul_overflow)
31 #define ckd_mul(result, a, b) \
32 (_Bool)__builtin_mul_overflow((a), (b), (result))
34 #define ckd_mul(result, a, b) \
35 _Static_assert(0, "checked multiplication not supported")