Ruby 4.1.0dev (2026-09-26 revision b49347c28a15c475eba951ce426564647aeeacf0)
stdckdint.h
1#ifndef RBIMPL_STDCKDINT_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_STDCKDINT_H
22#include "ruby/internal/config.h"
23#include "ruby/internal/cast.h"
26
27#ifdef __has_include
28# if __has_include(<stdckdint.h>)
29# /* Conforming C23 situation; e.g. recent clang */
30# define RBIMPL_HAVE_STDCKDINT_H
31# endif
32#else
33# ifdef HAVE_STDCKDINT_H
34# /* Some OSes (most notably FreeBSD) have this file. This is what
35# * configure saw when ruby itself was built, so only fall back to it
36# * when the compiler cannot answer __has_include for itself. */
37# define RBIMPL_HAVE_STDCKDINT_H
38# endif
39#endif
40
41#ifdef __cplusplus
42# /* It seems OS/Compiler provided stdckdint.h tend not support C++ yet.
43# * Situations could improve someday but in a meantime let us work around.
44# */
45# undef RBIMPL_HAVE_STDCKDINT_H
46#endif
47
48#ifdef RBIMPL_HAVE_STDCKDINT_H
49# /* Take that. */
50# include <stdckdint.h>
51
52#elif RBIMPL_HAS_BUILTIN(__builtin_add_overflow)
53# define ckd_add(x, y, z) RBIMPL_CAST((bool)__builtin_add_overflow((y), (z), (x)))
54# define ckd_sub(x, y, z) RBIMPL_CAST((bool)__builtin_sub_overflow((y), (z), (x)))
55# define ckd_mul(x, y, z) RBIMPL_CAST((bool)__builtin_mul_overflow((y), (z), (x)))
56# define __STDC_VERSION_STDCKDINT_H__ 202311L
57
58#/* elif defined(__cplusplus) */
59#/* :TODO: if we assume C++11 we can use `<type_traits>` to implement them. */
60
61#else
62# /* intentionally leave them undefined */
63# /* to make `#ifdef ckd_add` etc. work as intended. */
64# undef ckd_add
65# undef ckd_sub
66# undef ckd_mul
67# undef __STDC_VERSION_STDCKDINT_H__
68#endif
69
70#endif /* RBIMPL_STDCKDINT_H */
Defines RBIMPL_HAS_BUILTIN.
C99 shim for <stdbool.h>