mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [C23 stdckdint.h 1/1] C23: add the stdckdint.h header for checked integer operations
       [not found] <cover.1684933006.git.Jens.Gustedt@inria.fr>
@ 2023-05-26  9:40 ` Jens Gustedt
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Gustedt @ 2023-05-26  9:40 UTC (permalink / raw)
  To: musl

These macros have a direct correspondence with gcc builtins, so the
implementation for musl is trivial. 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.
---
 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [musl] [C23 stdckdint.h 1/1] C23: add the stdckdint.h header for checked integer operations
       [not found] <cover.1685535458.git.Jens.Gustedt@inria.fr>
@ 2023-05-31 14:03 ` Jens Gustedt
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Gustedt @ 2023-05-31 14:03 UTC (permalink / raw)
  To: musl

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-31 14:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cover.1684933006.git.Jens.Gustedt@inria.fr>
2023-05-26  9:40 ` [musl] [C23 stdckdint.h 1/1] C23: add the stdckdint.h header for checked integer operations Jens Gustedt
     [not found] <cover.1685535458.git.Jens.Gustedt@inria.fr>
2023-05-31 14:03 ` Jens Gustedt

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).