clang 19.0.0git
stddef.h
Go to the documentation of this file.
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/*
11 * This header is designed to be included multiple times. If any of the __need_
12 * macros are defined, then only that subset of interfaces are provided. This
13 * can be useful for POSIX headers that need to not expose all of stddef.h, but
14 * need to use some of its interfaces. Otherwise this header provides all of
15 * the expected interfaces.
16 *
17 * When clang modules are enabled, this header is a textual header. It ignores
18 * its header guard so that multiple submodules can export its interfaces.
19 * Take module SM with submodules A and B, whose headers both include stddef.h
20 * When SM.A builds, __STDDEF_H will be defined. When SM.B builds, the
21 * definition from SM.A will leak when building without local submodule
22 * visibility. stddef.h wouldn't include any of its implementation headers, and
23 * SM.B wouldn't import any of the stddef modules, and SM.B's `export *`
24 * wouldn't export any stddef interfaces as expected. However, since stddef.h
25 * ignores its header guard when building with modules, it all works as
26 * expected.
27 *
28 * When clang modules are not enabled, the header guards can function in the
29 * normal simple fashion.
30 */
31#if !defined(__STDDEF_H) || __has_feature(modules) || \
32 (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1) || \
33 defined(__need_ptrdiff_t) || defined(__need_size_t) || \
34 defined(__need_rsize_t) || defined(__need_wchar_t) || \
35 defined(__need_NULL) || defined(__need_nullptr_t) || \
36 defined(__need_unreachable) || defined(__need_max_align_t) || \
37 defined(__need_offsetof) || defined(__need_wint_t)
38
39#if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \
40 !defined(__need_rsize_t) && !defined(__need_wchar_t) && \
41 !defined(__need_NULL) && !defined(__need_nullptr_t) && \
42 !defined(__need_unreachable) && !defined(__need_max_align_t) && \
43 !defined(__need_offsetof) && !defined(__need_wint_t)
44#define __STDDEF_H
45#define __need_ptrdiff_t
46#define __need_size_t
47/* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is
48 * enabled. */
49#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
50#define __need_rsize_t
51#endif
52#define __need_wchar_t
53#define __need_NULL
54#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || \
55 defined(__cplusplus)
56#define __need_nullptr_t
57#endif
58#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
59#define __need_unreachable
60#endif
61#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
62 (defined(__cplusplus) && __cplusplus >= 201103L)
63#define __need_max_align_t
64#endif
65#define __need_offsetof
66/* wint_t is provided by <wchar.h> and not <stddef.h>. It's here
67 * for compatibility, but must be explicitly requested. Therefore
68 * __need_wint_t is intentionally not defined here. */
69#endif
70
71#if defined(__need_ptrdiff_t)
72#include <__stddef_ptrdiff_t.h>
73#undef __need_ptrdiff_t
74#endif /* defined(__need_ptrdiff_t) */
75
76#if defined(__need_size_t)
77#include <__stddef_size_t.h>
78#undef __need_size_t
79#endif /*defined(__need_size_t) */
80
81#if defined(__need_rsize_t)
82#include <__stddef_rsize_t.h>
83#undef __need_rsize_t
84#endif /* defined(__need_rsize_t) */
85
86#if defined(__need_wchar_t)
87#include <__stddef_wchar_t.h>
88#undef __need_wchar_t
89#endif /* defined(__need_wchar_t) */
90
91#if defined(__need_NULL)
92#include <__stddef_null.h>
93#undef __need_NULL
94#endif /* defined(__need_NULL) */
95
96#if defined(__need_nullptr_t)
97#include <__stddef_nullptr_t.h>
98#undef __need_nullptr_t
99#endif /* defined(__need_nullptr_t) */
100
101#if defined(__need_unreachable)
102#include <__stddef_unreachable.h>
103#undef __need_unreachable
104#endif /* defined(__need_unreachable) */
105
106#if defined(__need_max_align_t)
107#include <__stddef_max_align_t.h>
108#undef __need_max_align_t
109#endif /* defined(__need_max_align_t) */
110
111#if defined(__need_offsetof)
112#include <__stddef_offsetof.h>
113#undef __need_offsetof
114#endif /* defined(__need_offsetof) */
115
116/* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use
117__WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
118#if defined(__need_wint_t)
119#include <__stddef_wint_t.h>
120#undef __need_wint_t
121#endif /* __need_wint_t */
122
123#endif