| 1 |
/* stdckdint.h -- checked integer arithmetic |
| 2 |
|
| 3 |
Copyright 2022-2026 Free Software Foundation, Inc. |
| 4 |
|
| 5 |
This program is free software: you can redistribute it and/or modify it |
| 6 |
under the terms of the GNU Lesser General Public License as published |
| 7 |
by the Free Software Foundation; either version 2.1 of the License, or |
| 8 |
(at your option) any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU Lesser General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU Lesser General Public License |
| 16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 17 |
|
| 18 |
#if __GNUC__ >= 3 |
| 19 |
@PRAGMA_SYSTEM_HEADER@ |
| 20 |
#endif |
| 21 |
@PRAGMA_COLUMNS@ |
| 22 |
|
| 23 |
#ifndef _@GUARD_PREFIX@_STDCKDINT_H |
| 24 |
|
| 25 |
/* The include_next requires a split double-inclusion guard. */ |
| 26 |
#if defined __cplusplus ? @HAVE_CXX_STDCKDINT_H@ : @HAVE_C_STDCKDINT_H@ |
| 27 |
# @INCLUDE_NEXT@ @NEXT_STDCKDINT_H@ |
| 28 |
#endif |
| 29 |
|
| 30 |
#ifndef _@GUARD_PREFIX@_STDCKDINT_H |
| 31 |
#define _@GUARD_PREFIX@_STDCKDINT_H |
| 32 |
|
| 33 |
/* Do nothing but include the system header if it works properly. */ |
| 34 |
# if defined __cplusplus ? !@HAVE_WORKING_CXX_STDCKDINT_H@ : !@HAVE_WORKING_C_STDCKDINT_H@ |
| 35 |
|
| 36 |
/* Avoid redefining macros. */ |
| 37 |
# undef ckd_add |
| 38 |
# undef ckd_sub |
| 39 |
# undef ckd_mul |
| 40 |
|
| 41 |
# include "intprops-internal.h" |
| 42 |
|
| 43 |
/* Store into *R the low-order bits of A + B, A - B, A * B, respectively. |
| 44 |
Return 1 if the result overflows, 0 otherwise. |
| 45 |
A, B, and *R can have any integer type other than char, bool, a |
| 46 |
bit-precise integer type, or an enumeration type. |
| 47 |
|
| 48 |
These are like the standard macros introduced in C23, except that |
| 49 |
arguments should not have side effects. The C++26 standard is |
| 50 |
expected to add this header and it's macros. */ |
| 51 |
|
| 52 |
# define ckd_add(r, a, b) ((bool) _GL_INT_ADD_WRAPV (a, b, r)) |
| 53 |
# define ckd_sub(r, a, b) ((bool) _GL_INT_SUBTRACT_WRAPV (a, b, r)) |
| 54 |
# define ckd_mul(r, a, b) ((bool) _GL_INT_MULTIPLY_WRAPV (a, b, r)) |
| 55 |
|
| 56 |
# endif /* defined __cplusplus ? @HAVE_WORKING_CXX_STDCKDINT_H@ : @HAVE_WORKING_C_STDCKDINT_H@ */ |
| 57 |
#endif /* _@GUARD_PREFIX@_STDCKDINT_H */ |
| 58 |
#endif /* _@GUARD_PREFIX@_STDCKDINT_H */ |