|
Message-Id: <323b1aaf4c7e31010ead4eae127d0d580f319ce6.1685535458.git.Jens.Gustedt@inria.fr> Date: Wed, 31 May 2023 16:03:34 +0200 From: Jens Gustedt <Jens.Gustedt@...ia.fr> To: musl@...ts.openwall.com Subject: [C23 stdckdint.h 1/1] C23: add the stdckdint.h header for checked integer operations These macros have a direct correspondence to gcc builtins, so the implementation is trivial for compilers that have this. Note that this only intefaces the type-generic features, so no function symbol is added to the library. Since also this is a new header that only exposes its contents when it is explicitly included, no feature test macros are needed. As there are no function symbols added, for the compilation of musl itself this header makes no change. If on the other hand a user uses a macro from this header with a compiler that does not support that functionality, the compilation will fail. --- include/stdckdint.h | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 include/stdckdint.h diff --git a/include/stdckdint.h b/include/stdckdint.h new file mode 100644 index 00000000..893126dc --- /dev/null +++ b/include/stdckdint.h @@ -0,0 +1,8 @@ +#ifndef __STDC_VERSION_STDCKDINT_H__ +#define __STDC_VERSION_STDCKDINT_H__ 202311L + +#define ckd_add(R, A, B) __builtin_add_overflow ((A), (B), (R)) +#define ckd_sub(R, A, B) __builtin_sub_overflow ((A), (B), (R)) +#define ckd_mul(R, A, B) __builtin_mul_overflow ((A), (B), (R)) + +#endif -- 2.34.1
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.