Lely core libraries  2.2.5
features.h
Go to the documentation of this file.
1 
22 #ifndef LELY_FEATURES_H_
23 #define LELY_FEATURES_H_
24 
25 #if defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L
26 #error This file requires compiler and library support for the ISO C99 standard.
27 #endif
28 
29 #if defined(__cplusplus) && __cplusplus < 201103L
30 #error This file requires compiler and library support for the ISO C++11 standard.
31 #endif
32 
33 #ifdef _MSC_VER
34 #if _MSC_VER < 1900
35 #error This file requires Microsoft Visual C++ 2015 or later.
36 #endif
37 // Disable warnings about deprecated POSIX functions.
38 #pragma warning(disable : 4996)
39 #endif
40 
41 #ifdef _WIN32
42 // Windows 7 is the minimum supported version.
43 #if !defined(NTDDI_VERSION) || (NTDDI_VERSION < NTDDI_WIN7)
44 #undef NTDDI_VERSION
45 #define NTDDI_VERSION NTDDI_WIN7
46 #endif
47 #if !defined(_WIN32_WINNT) || _WIN32_WINNT < _WIN32_WINNT_WIN7
48 #undef _WIN32_WINNT
49 #define _WIN32_WINNT _WIN32_WINNT_WIN7
50 #endif
51 #if !defined(WINVER) || WINVER < _WIN32_WINNT
52 #undef WINVER
53 #define WINVER _WIN32_WINNT
54 #endif
55 #ifndef WIN32_LEAN_AND_MEAN
56 #define WIN32_LEAN_AND_MEAN
57 #endif
58 #include <windef.h>
59 #endif
60 
61 // <limits.h> is guaranteed to be present, even in freestanding environments,
62 // and will typically include <features.h>, which we need but cannot portably
63 // include directly.
64 #include <limits.h>
65 
66 // Include a (platform-specific) header which defines the POSIX feature test
67 // macros.
68 #ifdef __GLIBC__
69 #include <bits/posix_opt.h>
70 #elif defined(__NEWLIB__)
71 #include <sys/features.h>
72 #endif
73 
74 #ifndef CLANG_PREREQ
75 #if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__)
76 #define CLANG_PREREQ(major, minor) \
77  ((__clang_major__ << 16) + __clang_minor__ >= ((major) << 16) + (minor))
78 #else
79 #define CLANG_PREREQ(major, minor) 0
80 #endif
81 #endif
82 
83 #ifndef GNUC_PREREQ
84 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
85 #define GNUC_PREREQ(major, minor) \
86  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((major) << 16) + (minor))
87 #else
88 #define GNUC_PREREQ(major, minor) 0
89 #endif
90 #endif
91 
92 #ifndef __has_attribute
93 #define __has_attribute(x) 0
94 #endif
95 
96 #ifndef __has_builtin
97 #define __has_builtin(x) 0
98 #endif
99 
100 #ifndef __has_declspec_attribute
101 #define __has_declspec_attribute(x) 0
102 #endif
103 
104 #ifndef __has_extension
105 #define __has_extension __has_feature
106 #endif
107 
108 #ifndef __has_feature
109 #define __has_feature(x) 0
110 #endif
111 
112 #ifndef __has_include
113 #define __has_include(x) 1
114 #endif
115 
116 #ifndef __STDC_CONSTANT_MACROS
117 #define __STDC_CONSTANT_MACROS 1
118 #endif
119 
120 #ifndef __STDC_LIMIT_MACROS
121 #define __STDC_LIMIT_MACROS 1
122 #endif
123 
124 #ifndef __STDC_NO_ATOMICS__
125 // GCC versions older than 4.9 do not properly advertise the absence of
126 // <stdatomic.h>.
127 // clang-format off
128 #if defined(__cplusplus) || defined(_MSC_VER) \
129  || (defined(__GNUC__) && !GNUC_PREREQ(4, 9) \
130  && !defined(__clang__)) \
131  || (defined(__clang__) && !__has_extension(c_atomic))
132 // clang-format on
133 #define __STDC_NO_ATOMICS__ 1
134 #endif
135 #endif
136 
137 #ifndef __STDC_NO_THREADS__
138 // Although recent versions of Cygwin do provide <threads.h>, it requires
139 // <machine/_threads.h>, which is missing.
140 #if defined(__cplusplus) || defined(_MSC_VER) || defined(__CYGWIN__)
141 #define __STDC_NO_THREADS__ 1
142 #endif
143 #endif
144 
145 #ifndef __STDC_NO_VLA__
146 #if defined(__cplusplus) || defined(_MSC_VER)
147 #define __STDC_NO_VLA__ 1
148 #endif
149 #endif
150 
151 #ifdef __cplusplus
152 
153 #ifndef __cpp_exceptions
154 #if (defined(_MSC_VER) && _HAS_EXCEPTIONS) \
155  || (defined(__GNUC__) && defined(__EXCEPTIONS)) \
156  || (defined(__clang__) && __has_feature(cxx_exceptions))
157 #define __cpp_exceptions __cplusplus
158 #endif
159 #endif
160 
161 #ifndef __cpp_rtti
162 #if (defined(_MSC_VER) && _CPPRTTI) \
163  || (defined(__GNUC__) && defined(__GXX_RTTI)) \
164  || (defined(__clang__) && __has_feature(cxx_rtti))
165 #define __cpp_rtti __cplusplus
166 #endif
167 #endif
168 
169 #endif // __cplusplus
170 
172 // clang-format off
173 #if !defined(_Alignas) && !(__STDC_VERSION__ >= 201112L \
174  && (GNUC_PREREQ(4, 7) || __has_feature(c_alignas)))
175 // clang-format on
176 #if __cplusplus >= 201103L && (GNUC_PREREQ(4, 8) || __has_feature(cxx_alignas))
177 #define _Alignas alignas
178 #elif defined(__GNUC__) || __has_attribute(__aligned__)
179 #define _Alignas(x) __attribute__((__aligned__(x)))
180 #elif defined(_MSC_VER) || defined(__declspec) \
181  || __has_declspec_attribute(align)
182 #define _Alignas(x) __declspec(align(x))
183 #else
184 #define _Alignas(x)
185 #endif
186 #endif
187 
189 // clang-format off
190 #if !defined(_Alignof) && !(__STDC_VERSION__ >= 201112L \
191  && (GNUC_PREREQ(4, 7) || __has_feature(c_alignof)))
192 // clang-format on
193 #if __cplusplus >= 201103L && (GNUC_PREREQ(4, 8) || __has_feature(cxx_alignof))
194 #define _Alignof alignof
195 #elif defined(__GNUC__)
196 #define _Alignof(x) __alignof__(x)
197 #elif defined(_MSC_VER)
198 #define _Alignof(x) __alignof(x)
199 #else
200 #include <stddef.h>
201 #define _Alignof(type)(offsetof(struct { char c; type x; }, x))
202 #endif
203 #endif
204 
209 // clang-format off
210 #if !defined(_Noreturn) && !(__STDC_VERSION__ >= 201112L \
211  && (GNUC_PREREQ(4, 7) || CLANG_PREREQ(3, 3)))
212 // clang-format on
213 #if defined(__GNUC__) || __has_attribute(__noreturn__)
214 #define _Noreturn __attribute__((__noreturn__))
215 #elif defined(_MSC_VER) || defined(__declspec) \
216  || __has_declspec_attribute(noreturn)
217 #define _Noreturn __declspec(noreturn)
218 #else
219 #define _Noreturn
220 #endif
221 #endif
222 
231 // clang-format off
232 #if !defined(_Thread_local) && !(__STDC_VERSION__ >= 201112L \
233  && (GNUC_PREREQ(4, 7) || __has_feature(c_thread_local)))
234 // clang-format on
235 #if __cplusplus >= 201103L \
236  && (GNUC_PREREQ(4, 8) || __has_feature(cxx_thread_local))
237 #define _Thread_local thread_local
238 #elif defined(__GNUC__)
239 #define _Thread_local __thread
240 #elif defined(_MSC_VER) || defined(__declspec) \
241  || __has_declspec_attribute(thread)
242 #define _Thread_local __declspec(thread)
243 #else
244 #define _Thread_local
245 #endif
246 #endif
247 
248 #ifndef format_printf__
249 #if defined(__GNUC__) || __has_attribute(__format__)
250 #ifdef __MINGW32__
251 #define format_printf__(i, j) \
252  __attribute__((__format__(__gnu_printf__, (i), (j))))
253 #else
254 #define format_printf__(i, j) __attribute__((__format__(__printf__, (i), (j))))
255 #endif
256 #else
257 #define format_printf__(i, j)
258 #endif
259 #endif
260 
261 #ifndef __WORDSIZE
262 // clang-format off
264 #if !defined(__ILP32__) && (defined(__LP64__) || defined(_WIN64) \
265  || defined(_M_AMD64) || defined(__amd64__) || defined(_M_IA64) \
266  || defined(__ia64__) || defined(_M_X64) || defined(__x86_64__) \
267  || defined(__aarch64__))
268 // clang-format on
269 #define __WORDSIZE 64
270 #else
271 #define __WORDSIZE 32
272 #endif
273 #endif
274 
275 #ifndef LONG_BIT
276 #ifdef _WIN32
278 // long remains 32-bits on 64-bit Windows.
279 #define LONG_BIT 32
280 #else
281 #define LONG_BIT __WORDSIZE
282 #endif
283 #endif
284 
285 #ifndef LEVEL1_DCACHE_LINESIZE
286 
292 #define LEVEL1_DCACHE_LINESIZE 64
293 #endif
294 
295 #define LELY_INGORE_EMPTY_TRANSLATION_UNIT \
296  typedef int lely_ignore_empty_translation_unit__;
297 
298 #ifndef LELY_VLA_SIZE_MAX
299 #define LELY_VLA_SIZE_MAX 256
301 #endif
302 
303 #endif // LELY_FEATURES_H_
This header file is part of the C11 and POSIX compatibility library; it includes <stddef.h> and defines any missing functionality.