1 /*===---- stddef.h - Basic type definitions --------------------------------===
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 *===-----------------------------------------------------------------------===
10 #if !defined(__STDDEF_H) || defined(__need_ptrdiff_t) || \
11 defined(__need_size_t) || defined(__need_wchar_t) || \
12 defined(__need_NULL) || defined(__need_wint_t)
14 #if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \
15 !defined(__need_wchar_t) && !defined(__need_NULL) && \
16 !defined(__need_wint_t)
17 /* Always define miscellaneous pieces when modules are available. */
18 #if !__has_feature(modules)
21 #define __need_ptrdiff_t
23 #define __need_wchar_t
25 #define __need_STDDEF_H_misc
26 /* __need_wint_t is intentionally not defined here. */
29 #if defined(__need_ptrdiff_t)
30 #if !defined(_PTRDIFF_T) || __has_feature(modules)
31 /* Always define ptrdiff_t when modules are available. */
32 #if !__has_feature(modules)
35 typedef __PTRDIFF_TYPE__
ptrdiff_t;
37 #undef __need_ptrdiff_t
38 #endif /* defined(__need_ptrdiff_t) */
40 #if defined(__need_size_t)
41 #if !defined(_SIZE_T) || __has_feature(modules)
42 /* Always define size_t when modules are available. */
43 #if !__has_feature(modules)
46 typedef __SIZE_TYPE__
size_t;
49 #endif /*defined(__need_size_t) */
51 #if defined(__need_STDDEF_H_misc)
52 /* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is
54 #if (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 && \
55 !defined(_RSIZE_T)) || __has_feature(modules)
56 /* Always define rsize_t when modules are available. */
57 #if !__has_feature(modules)
60 typedef __SIZE_TYPE__ rsize_t
;
62 #endif /* defined(__need_STDDEF_H_misc) */
64 #if defined(__need_wchar_t)
65 #if !defined(__cplusplus) || (defined(_MSC_VER) && !_NATIVE_WCHAR_T_DEFINED)
66 /* Always define wchar_t when modules are available. */
67 #if !defined(_WCHAR_T) || __has_feature(modules)
68 #if !__has_feature(modules)
70 #if defined(_MSC_EXTENSIONS)
71 #define _WCHAR_T_DEFINED
74 typedef __WCHAR_TYPE__
wchar_t;
78 #endif /* defined(__need_wchar_t) */
80 #if defined(__need_NULL)
83 # if !defined(__MINGW32__) && !defined(_MSC_VER)
89 # define NULL ((void*)0)
92 #if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
93 namespace std
{ typedef decltype(nullptr) nullptr_t
; }
94 using ::std::nullptr_t
;
98 #endif /* defined(__need_NULL) */
100 /* FIXME: This is using the placeholder dates Clang produces for these macros
101 in C2x mode; switch to the correct values once they've been published. */
102 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L
103 typedef typeof(nullptr) nullptr_t
;
104 #endif /* defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L */
106 #if defined(__need_STDDEF_H_misc) && defined(__STDC_VERSION__) && \
107 __STDC_VERSION__ >= 202000L
108 #define unreachable() __builtin_unreachable()
109 #endif /* defined(__need_STDDEF_H_misc) && >= C23 */
111 #if defined(__need_STDDEF_H_misc)
112 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
113 (defined(__cplusplus) && __cplusplus >= 201103L)
114 #include "__stddef_max_align_t.h"
116 #define offsetof(t, d) __builtin_offsetof(t, d)
117 #undef __need_STDDEF_H_misc
118 #endif /* defined(__need_STDDEF_H_misc) */
120 /* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use
121 __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
122 #if defined(__need_wint_t)
123 /* Always define wint_t when modules are available. */
124 #if !defined(_WINT_T) || __has_feature(modules)
125 #if !__has_feature(modules)
128 typedef __WINT_TYPE__
wint_t;
131 #endif /* __need_wint_t */