ae2f_docs
Loading...
Searching...
No Matches
cc.h
Go to the documentation of this file.
1/**
2 * @file cc.h
3 * @brief Utility marks which could partially be available with gnu compiler.
4 * @details Keys.h will utilise it to have keywords
5 * */
6#include "./LangVer.h"
7
8/**
9 * @def _ae2f_gnuc
10 * @brief Available when compiled with gcc compiler.
11 *
12 * @def N_ae2f_gnuc
13 * @brief Available when not compiled with gnu compiler.
14 * */
15#undef _ae2f_gnuc
16#undef N_ae2f_gnuc
17#if defined(__GNUC__)
18#define _ae2f_gnuc(a) a
19#define N_ae2f_gnuc(a)
20#else
21#define _ae2f_gnuc(a)
22#define N_ae2f_gnuc(a) a
23#endif
24
25/**
26 * @def _ae2f_msvc
27 * @brief Available when compiled with msvc.
28 *
29 * @def N_ae2f_msvc
30 * @brief Available when not compiled with msvc.
31 * */
32#undef _ae2f_msvc
33#undef N_ae2f_msvc
34#if defined(_MSC_VER)
35#define _ae2f_msvc(a) a
36#define N_ae2f_msvc(a)
37#else
38#define _ae2f_msvc(a)
39#define N_ae2f_msvc(a) a
40#endif
41
42/**
43 * @def ae2f_ccpure
44 * @brief Keyword as `[[pure]]` on C23.
45 * */
46#undef ae2f_ccpure
47#if _ae2f_gnuc(!)0
48#define ae2f_ccpure __attribute__((pure))
49#elif __ae2f_stdcheck_C(202300L) && ae2f_stdcc_v
50#define ae2f_ccpure [[pure]]
51#else
52#define ae2f_ccpure
53#endif
54
55
56/**
57 * @def ae2f_ccconst
58 * @brief Keyword as `[[const]]` on C23..
59 * */
60#undef ae2f_ccconst
61#if _ae2f_gnuc(!)0
62#define ae2f_ccconst __attribute__((const))
63#elif __ae2f_stdcheck_C(202300L) && ae2f_stdcc_v
64#define ae2f_ccconst [[const]]
65#else
66#define ae2f_ccconst
67#endif
68
69/**
70 * @def ae2f_restrict
71 * @brief Keyword as `restrict` on C99.
72 * */
73#undef ae2f_restrict
74#if _ae2f_gnuc(!)0
75#define ae2f_restrict __restrict
76#elif _ae2f_msvc(!)0
77#define ae2f_restrict __restrict
78#elif __ae2f_stdcheck_C(199900L) && ae2f_stdcc_v
79#define ae2f_restrict restrict
80#else
81#define ae2f_restrict
82#endif
83
84/**
85 * @def ae2f_retnew
86 * @brief The returning pointer does not alias to existing object.
87 * */
88#undef ae2f_retnew
89#if _ae2f_msvc(1) +0
90#define ae2f_retnew __declspec(restrict)
91#elif _ae2f_gnuc(!)0
92#define ae2f_retnew __attribute__((malloc))
93#else
94#define ae2f_retnew
95#endif
96
97/**
98 * @def ae2f_decl
99 * @brief Function declare for shared object
100 * */
101#undef ae2f_decl
102#if _ae2f_msvc(1) +0
103#define ae2f_decl __declspec(dllimport)
104#else
105#define ae2f_decl
106#endif
107
108/**
109 * @def ae2f_impl
110 * @brief Function implementation for shared object
111 * */
112#undef ae2f_impl
113#if _ae2f_gnuc(!)0
114#define ae2f_impl __attribute__((visibility("default")))
115#elif _ae2f_msvc(!)0
116#define ae2f_impl __declspec(dllexport)
117#else
118#define ae2f_impl
119#endif
120
121/**
122 * @def ae2f_noexcept
123 * @brief marker that this function does not throw something.
124 * */
125#undef ae2f_noexcept
126#if _ae2f_gnuc(!)0
127#define ae2f_noexcept __attribute__((nothrow))
128#elif _ae2f_msvc(!)0
129#define ae2f_noexcept __declspec(nothrow)
130#elif ae2f_stdcc_v >= 201100L
131#define ae2f_noexcept noexcept
132#else
133#define ae2f_noexcept
134#endif
135
136
137/**
138 * @def ae2f_inline
139 * @brief `inline`
140 * */
141#undef ae2f_inline
142#if _ae2f_gnuc(!)0
143#define ae2f_inline __inline__
144#elif _ae2f_msvc(!)0
145#define ae2f_inline __inline
146#elif ae2f_stdc_v >= 199900L || ae2f_stdcc_v
147#define ae2f_inline inline
148#else
149#define ae2f_inline
150#endif
151
152/**
153 * @def ae2f_fallthrough
154 * @brief explicitly tells compiler that fallthrough on switch is expected.
155 * */
156#undef ae2f_fallthrough
157#if _ae2f_gnuc(!)0
158#define ae2f_fallthrough __attribute__((fallthrough))
159#elif _ae2f_msvc(!)0 && _MSC_VER >= 1934
160#define ae2f_fallthrough [[fallthrough]]
161#elif ae2f_stdc_v >= 202300L || ae2f_stdcc_v
162#define ae2f_fallthrough [[fallthrough]]
163#else
164#define ae2f_fallthrough
165#endif
166
167
168/**
169 * @def ae2f_expected
170 * @brief expectes `a` as `true`.
171 *
172 * @def ae2f_expected_not
173 * @brief expectes `a` as `false`.
174 * */
175#undef ae2f_expected
176#undef ae2f_expected_not
177#if _ae2f_gnuc(!)0
178#define ae2f_expected(a) (__builtin_expect(!!(a), 1))
179#define ae2f_expected_not(a) (__builtin_expect(!!(a), 0))
180#elif _ae2f_msvc(!)0 && _MSVC_LANG >= 202002L || ae2f_stdcc_v >= 202002L
181#define ae2f_expected(a) (a) [[likely]]
182#define ae2f_expected_not(a) (a) [[unlikely]]
183#else
184#define ae2f_expected(a) a
185#define ae2f_expected_not(a) a
186#endif
187
188#undef ae2f_unexpected
189#define ae2f_unexpected ae2f_expected_not
190
191#undef ae2f_unexpected_but_if
192#define ae2f_unexpected_but_if(a) if(ae2f_expected_not(a))
193
194#undef ae2f_expected_if
195#define ae2f_expected_if(a) if(ae2f_expected(a))
196
197#undef ae2f_unexpected_else
198#define ae2f_unexpected_else(a) if(!ae2f_unexpected(a))
199
200#undef ae2f_expected_but_else
201#define ae2f_expected_but_else(a) if(!(ae2f_expected(a)))
202
203/**
204 * @def ae2f_unreachable
205 * @brief tells the compiler that below this keyword is not expected to be reached.
206 * */
207#undef ae2f_unreachable
208#if _ae2f_gnuc(!)0
209#define ae2f_unreachable() __builtin_unreachable()
210#elif _ae2f_msvc(!)0
211#define ae2f_unreachable() __assume(0)
212#else
213#define ae2f_unreachable()
214#endif
215
216/**
217 * @def ae2f_assume
218 * @brief tells the compiler that value if `a` is `false`,
219 * below this keyword is not expected to be reached.
220 * @see ae2f_unreachable
221 * */
222#undef ae2f_assume
223#if _ae2f_gnuc(!)0 && (__GNUC__ >= 13)
224#define ae2f_assume(a) __attribute__((__assume__(a)))
225#elif _ae2f_msvc(!)0
226#define ae2f_assume(a) __assume(a)
227#else
228#define ae2f_assume(a) if(!(a)) { ae2f_unreachable(); }
229#endif
#define ae2f_assume(a)
tells the compiler that value if a is false, below this keyword is not expected to be reached.
Definition cc.h:228
#define ae2f_ccpure
Keyword as [[pure]] on C23.
Definition cc.h:52
#define ae2f_unexpected
Definition cc.h:189
#define ae2f_ccconst
Keyword as [[const]] on C23..
Definition cc.h:66
#define ae2f_noexcept
marker that this function does not throw something.
Definition cc.h:133
#define ae2f_restrict
Keyword as restrict on C99.
Definition cc.h:81
#define ae2f_expected_not(a)
expectes a as false.
Definition cc.h:185
#define ae2f_unreachable()
tells the compiler that below this keyword is not expected to be reached.
Definition cc.h:213
#define _ae2f_msvc(a)
Available when compiled with msvc.
Definition cc.h:38
#define _ae2f_gnuc(a)
Available when compiled with gcc compiler.
Definition cc.h:21
#define ae2f_inline
inline
Definition cc.h:149
#define ae2f_expected(a)
expectes a as true.
Definition cc.h:184