xref: /freebsd/contrib/llvm-project/clang/lib/Headers/stddef.h (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1 /*===---- stddef.h - Basic type definitions --------------------------------===
2  *
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
6  *
7  *===-----------------------------------------------------------------------===
8  */
9 
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)
13 
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)
19 #define __STDDEF_H
20 #endif
21 #define __need_ptrdiff_t
22 #define __need_size_t
23 #define __need_wchar_t
24 #define __need_NULL
25 #define __need_STDDEF_H_misc
26 /* __need_wint_t is intentionally not defined here. */
27 #endif
28 
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)
33 #define _PTRDIFF_T
34 #endif
35 typedef __PTRDIFF_TYPE__ ptrdiff_t;
36 #endif
37 #undef __need_ptrdiff_t
38 #endif /* defined(__need_ptrdiff_t) */
39 
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)
44 #define _SIZE_T
45 #endif
46 typedef __SIZE_TYPE__ size_t;
47 #endif
48 #undef __need_size_t
49 #endif /*defined(__need_size_t) */
50 
51 #if defined(__need_STDDEF_H_misc)
52 /* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is
53  * enabled. */
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)
58 #define _RSIZE_T
59 #endif
60 typedef __SIZE_TYPE__ rsize_t;
61 #endif
62 #endif /* defined(__need_STDDEF_H_misc) */
63 
64 #if defined(__need_wchar_t)
65 #ifndef __cplusplus
66 /* Always define wchar_t when modules are available. */
67 #if !defined(_WCHAR_T) || __has_feature(modules)
68 #if !__has_feature(modules)
69 #define _WCHAR_T
70 #if defined(_MSC_EXTENSIONS)
71 #define _WCHAR_T_DEFINED
72 #endif
73 #endif
74 typedef __WCHAR_TYPE__ wchar_t;
75 #endif
76 #endif
77 #undef __need_wchar_t
78 #endif /* defined(__need_wchar_t) */
79 
80 #if defined(__need_NULL)
81 #undef NULL
82 #ifdef __cplusplus
83 #  if !defined(__MINGW32__) && !defined(_MSC_VER)
84 #    define NULL __null
85 #  else
86 #    define NULL 0
87 #  endif
88 #else
89 #  define NULL ((void*)0)
90 #endif
91 #ifdef __cplusplus
92 #if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
93 namespace std { typedef decltype(nullptr) nullptr_t; }
94 using ::std::nullptr_t;
95 #endif
96 #endif
97 #undef __need_NULL
98 #endif /* defined(__need_NULL) */
99 
100 #if defined(__need_STDDEF_H_misc)
101 #if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
102 #include "__stddef_max_align_t.h"
103 #endif
104 #define offsetof(t, d) __builtin_offsetof(t, d)
105 #undef __need_STDDEF_H_misc
106 #endif  /* defined(__need_STDDEF_H_misc) */
107 
108 /* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use
109 __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
110 #if defined(__need_wint_t)
111 /* Always define wint_t when modules are available. */
112 #if !defined(_WINT_T) || __has_feature(modules)
113 #if !__has_feature(modules)
114 #define _WINT_T
115 #endif
116 typedef __WINT_TYPE__ wint_t;
117 #endif
118 #undef __need_wint_t
119 #endif /* __need_wint_t */
120 
121 #endif
122