Derive-C
Loading...
Searching...
No Matches
attributes.h
Go to the documentation of this file.
1#pragma once
2
3#define DC_INLINE inline __attribute__((always_inline))
4#define DC_CONST __attribute__((const))
5#define DC_PURE __attribute__((pure))
6#define DC_NODISCARD __attribute__((warn_unused_result))
7#define DC_UNUSED __attribute__((unused))
8
9// JUSTIFY: restrict keyword for pointer aliasing optimization
10// - In C: use standard 'restrict' keyword
11// - In C++: use '__restrict__' compiler extension (GCC/Clang)
12#if defined __cplusplus
13 #define DC_RESTRICT __restrict__
14#else
15 #define DC_RESTRICT restrict
16#endif
17
18// JUSTIFY: Different values for cpp
19// - When embedded in a struct (e.g. for fuzz tests), we need to avoid ODR
20#if defined __cplusplus
21 #define DC_STATIC_CONSTANT inline static constexpr
22#else
23 #define DC_STATIC_CONSTANT static const
24#endif
25
26// JUSTIFY: Changing thread local
27// - _Thread_local not part of C++ standard, though is supported by clang & GCC
28#if defined __cplusplus
29 #define DC_THREAD_LOCAL thread_local
30#else
31 #define DC_THREAD_LOCAL _Thread_local
32#endif