infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
compat_c23.h
Go to the documentation of this file.
1
#pragma once
32
#include <stdbool.h>
// For bool, true, false
33
#include <stddef.h>
// For offsetof, size_t
34
43
#ifndef nullptr
44
#define nullptr ((void *)0)
45
#endif
46
55
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || (defined(_MSC_VER) && _MSC_VER >= 1900)
56
// On modern compilers, <assert.h> may also define `static_assert` as a macro.
57
// We include it here to ensure the system's definition is seen first, which
58
// allows our `#ifndef` guard to correctly prevent a redefinition warning.
59
#include <assert.h>
60
#ifndef static_assert
61
#define static_assert(cond, msg) _Static_assert(cond, msg)
62
#endif
63
#endif
64
65
// (Internal) Helper to check for native C23-style attributes [[...]]
66
#if defined(__has_c_attribute)
67
#define COMPAT_HAS_C_ATTRIBUTE(x) __has_c_attribute(x)
68
#else
69
#define COMPAT_HAS_C_ATTRIBUTE(x) 0
70
#endif
71
86
#if COMPAT_HAS_C_ATTRIBUTE(nodiscard)
87
#define c23_nodiscard [[nodiscard]]
88
#elif defined(__GNUC__) || defined(__clang__)
89
#define c23_nodiscard __attribute__((warn_unused_result))
90
#elif defined(_MSC_VER)
91
#define c23_nodiscard _Check_return_
92
#else
93
#define c23_nodiscard
94
#endif
95
107
#if COMPAT_HAS_C_ATTRIBUTE(deprecated)
108
#define c23_deprecated [[deprecated]]
109
#elif defined(__GNUC__) || defined(__clang__)
110
#define c23_deprecated __attribute__((deprecated))
111
#elif defined(_MSC_VER)
112
#define c23_deprecated __declspec(deprecated)
113
#else
114
#define c23_deprecated
115
#endif
116
127
#if COMPAT_HAS_C_ATTRIBUTE(fallthrough)
128
#define c23_fallthrough [[fallthrough]]
129
#elif defined(__GNUC__) || defined(__clang__)
130
#define c23_fallthrough __attribute__((fallthrough))
131
#else
132
#define c23_fallthrough
/* fallthrough */
133
#endif
134
145
#if COMPAT_HAS_C_ATTRIBUTE(maybe_unused)
146
#define c23_maybe_unused [[maybe_unused]]
147
#elif defined(__GNUC__) || defined(__clang__)
148
#define c23_maybe_unused __attribute__((unused))
149
#else
150
#define c23_maybe_unused
151
#endif
src
common
compat_c23.h
Generated by
1.9.8