CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
base.h
Go to the documentation of this file.
1
#pragma once
2
5
157
158
#if defined(_MSC_VER)
159
160
#include <intrin.h>
161
#include <
assert.h
>
162
163
#define _COMPILER_MSVC 1
164
165
// C11 thread local
166
#define _Thread_local __declspec(thread)
167
168
// C11 static assert
169
#define _Static_assert static_assert
170
171
// Nullability qualifiers
172
// SAL is much more powerful than these
173
#define _Nonnull
174
#define _Nullable
175
#define _Null_unspecified
176
177
// Pure functions
178
#define _Pure
179
180
#define _Analysis_noreturn _Analysis_noreturn_
181
182
// We use inline functions for metaprogramming and really, REALLY want them
183
// to be inlined
184
#define _meta_inline __forceinline
185
#define _no_inline __declspec(noinline)
186
#pragma warning (disable:6255)
187
#define stackAlloc(sz) _alloca(sz)
188
189
// Sometimes things need to be aligned precisely
190
#define alignMem(bytes) __declspec(align(bytes))
191
192
// Hint that some functions never return
193
#define _no_return __declspec(noreturn)
194
195
#if defined(_WIN32)
196
#define _PLATFORM_WIN 1
197
#define _PLATFORM_STR "win"
198
#else
199
// this should be impossible
200
#error Unsupported operating system ???
201
#endif
202
203
#if defined(_M_IX86)
204
#define _ARCH_X86 1
205
#define _ARCH_STR "x86"
206
#define _32BIT 1
207
#elif defined (_M_X64)
208
#define _ARCH_X64 1
209
#define _ARCH_STR "x64"
210
#define _64BIT 1
211
#else
212
#error Unsupported architecture
213
#endif
214
215
#elif defined (__clang__) || (defined(__GNUC__) && __GNUC__ > 4)
216
217
#if defined(__clang__)
218
#define _COMPILER_CLANG 1
219
220
// Nullability qualifiers
221
#pragma clang diagnostic ignored "-Wnullability-completeness"
222
223
#elif defined(__GNUC__)
224
#define _COMPILER_GCC 1
225
226
// Nullability qualifiers
227
#define _Nonnull
228
#define _Nullable
229
#define _Null_unspecified
230
231
#endif
232
233
// Pure functions
234
#define _Pure __attribute__((pure))
235
236
#if defined(__clang_analyzer__)
237
#define _Analysis_noreturn __attribute__((noreturn))
238
#else
239
#define _Analysis_noreturn
240
#endif
241
242
// C11 thread local is already supported
243
244
// We use inline functions for metaprogramming and really, REALLY want them
245
// to be inlined
246
#define _meta_inline __attribute__((always_inline)) inline
247
#define _no_inline __attribute__((noinline))
248
#define stackAlloc(sz) alloca(sz)
249
250
// Sometimes things need to be aligned precisely
251
#define alignMem(bytes) __attribute__((aligned(bytes)))
252
253
// Hint that some functions never return
254
#define _no_return __attribute__((noreturn))
255
256
#if defined(__linux__)
257
#include <alloca.h>
258
#define _PLATFORM_UNIX 1
259
#define _PLATFORM_LINUX 1
260
#define _PLATFORM_STR "linux"
261
#elif defined(__FreeBSD__)
262
#define _PLATFORM_UNIX 1
263
#define _PLATFORM_FBSD 1
264
#define _PLATFORM_STR "fbsd"
265
#elif defined(__EMSCRIPTEN__)
266
#define _PLATFORM_WASM 1
267
#define _PLATFORM_STR "wasm"
268
#else
269
#error Unsupported operating system
270
#endif
271
272
#if defined(__x86_32__)
273
#define _ARCH_X86 1
274
#define _ARCH_STR "x86"
275
#define _32BIT 1
276
#elif defined(__x86_64__)
277
#define _ARCH_X64 1
278
#define _ARCH_STR "x64"
279
#define _64BIT 1
280
#elif defined (__aarch64__)
281
#define _ARCH_ARM64 1
282
#define _ARCH_STR "arm64"
283
#define _64BIT 1
284
#elif defined(__EMSCRIPTEN__)
285
#define _ARCH_WASM 1
286
#define _ARCH_STR "wasm32"
287
#define _32BIT 1
288
#else
289
#error Unsupported architecture
290
#endif
291
292
#else
293
#error Unsupported compiler
294
#endif
295
296
#if defined(_32BIT)
297
#define _word_align alignMem(4)
298
#elif defined(_64BIT)
299
#define _word_align alignMem(8)
300
#else
301
#error Unsupported architecture
302
#endif
303
304
#define _PLATFORM_ARCH_STR (_PLATFORM_STR "-" _ARCH_STR)
305
assert.h
Runtime assertion macros and failure handling.
cx
platform
base.h
Generated by
1.9.8