10b57cec5SDimitry Andric /*===---- stddef.h - Basic type definitions --------------------------------=== 20b57cec5SDimitry Andric * 30b57cec5SDimitry Andric * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric * See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric * 70b57cec5SDimitry Andric *===-----------------------------------------------------------------------=== 80b57cec5SDimitry Andric */ 90b57cec5SDimitry Andric 105f757f3fSDimitry Andric /* 115f757f3fSDimitry Andric * This header is designed to be included multiple times. If any of the __need_ 125f757f3fSDimitry Andric * macros are defined, then only that subset of interfaces are provided. This 135f757f3fSDimitry Andric * can be useful for POSIX headers that need to not expose all of stddef.h, but 145f757f3fSDimitry Andric * need to use some of its interfaces. Otherwise this header provides all of 155f757f3fSDimitry Andric * the expected interfaces. 165f757f3fSDimitry Andric * 170fca6ea1SDimitry Andric * When clang modules are enabled, this header is a textual header to support 180fca6ea1SDimitry Andric * the multiple include behavior. As such, it doesn't directly declare anything 190fca6ea1SDimitry Andric * so that it doesn't add duplicate declarations to all of its includers' 200fca6ea1SDimitry Andric * modules. 215f757f3fSDimitry Andric */ 220fca6ea1SDimitry Andric #if defined(__MVS__) && __has_include_next(<stddef.h>) 230fca6ea1SDimitry Andric #undef __need_ptrdiff_t 240fca6ea1SDimitry Andric #undef __need_size_t 250fca6ea1SDimitry Andric #undef __need_rsize_t 260fca6ea1SDimitry Andric #undef __need_wchar_t 270fca6ea1SDimitry Andric #undef __need_NULL 280fca6ea1SDimitry Andric #undef __need_nullptr_t 290fca6ea1SDimitry Andric #undef __need_unreachable 300fca6ea1SDimitry Andric #undef __need_max_align_t 310fca6ea1SDimitry Andric #undef __need_offsetof 320fca6ea1SDimitry Andric #undef __need_wint_t 33*36b606aeSDimitry Andric #include <__stddef_header_macro.h> 340fca6ea1SDimitry Andric #include_next <stddef.h> 350fca6ea1SDimitry Andric 360fca6ea1SDimitry Andric #else 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric #if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \ 395f757f3fSDimitry Andric !defined(__need_rsize_t) && !defined(__need_wchar_t) && \ 405f757f3fSDimitry Andric !defined(__need_NULL) && !defined(__need_nullptr_t) && \ 415f757f3fSDimitry Andric !defined(__need_unreachable) && !defined(__need_max_align_t) && \ 425f757f3fSDimitry Andric !defined(__need_offsetof) && !defined(__need_wint_t) 430b57cec5SDimitry Andric #define __need_ptrdiff_t 440b57cec5SDimitry Andric #define __need_size_t 455f757f3fSDimitry Andric /* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is 465f757f3fSDimitry Andric * enabled. */ 475f757f3fSDimitry Andric #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 485f757f3fSDimitry Andric #define __need_rsize_t 495f757f3fSDimitry Andric #endif 500b57cec5SDimitry Andric #define __need_wchar_t 51*36b606aeSDimitry Andric #if !defined(__STDDEF_H) || __has_feature(modules) 52*36b606aeSDimitry Andric /* 53*36b606aeSDimitry Andric * __stddef_null.h is special when building without modules: if __need_NULL is 54*36b606aeSDimitry Andric * set, then it will unconditionally redefine NULL. To avoid stepping on client 55*36b606aeSDimitry Andric * definitions of NULL, __need_NULL should only be set the first time this 56*36b606aeSDimitry Andric * header is included, that is when __STDDEF_H is not defined. However, when 57*36b606aeSDimitry Andric * building with modules, this header is a textual header and needs to 58*36b606aeSDimitry Andric * unconditionally include __stdef_null.h to support multiple submodules 59*36b606aeSDimitry Andric * exporting _Builtin_stddef.null. Take module SM with submodules A and B, whose 60*36b606aeSDimitry Andric * headers both include stddef.h When SM.A builds, __STDDEF_H will be defined. 61*36b606aeSDimitry Andric * When SM.B builds, the definition from SM.A will leak when building without 62*36b606aeSDimitry Andric * local submodule visibility. stddef.h wouldn't include __stddef_null.h, and 63*36b606aeSDimitry Andric * SM.B wouldn't import _Builtin_stddef.null, and SM.B's `export *` wouldn't 64*36b606aeSDimitry Andric * export NULL as expected. When building with modules, always include 65*36b606aeSDimitry Andric * __stddef_null.h so that everything works as expected. 66*36b606aeSDimitry Andric */ 670b57cec5SDimitry Andric #define __need_NULL 68*36b606aeSDimitry Andric #endif 695f757f3fSDimitry Andric #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || \ 705f757f3fSDimitry Andric defined(__cplusplus) 715f757f3fSDimitry Andric #define __need_nullptr_t 725f757f3fSDimitry Andric #endif 735f757f3fSDimitry Andric #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L 745f757f3fSDimitry Andric #define __need_unreachable 755f757f3fSDimitry Andric #endif 765f757f3fSDimitry Andric #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ 775f757f3fSDimitry Andric (defined(__cplusplus) && __cplusplus >= 201103L) 785f757f3fSDimitry Andric #define __need_max_align_t 795f757f3fSDimitry Andric #endif 805f757f3fSDimitry Andric #define __need_offsetof 815f757f3fSDimitry Andric /* wint_t is provided by <wchar.h> and not <stddef.h>. It's here 825f757f3fSDimitry Andric * for compatibility, but must be explicitly requested. Therefore 835f757f3fSDimitry Andric * __need_wint_t is intentionally not defined here. */ 84*36b606aeSDimitry Andric #include <__stddef_header_macro.h> 850b57cec5SDimitry Andric #endif 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric #if defined(__need_ptrdiff_t) 885f757f3fSDimitry Andric #include <__stddef_ptrdiff_t.h> 890b57cec5SDimitry Andric #undef __need_ptrdiff_t 900b57cec5SDimitry Andric #endif /* defined(__need_ptrdiff_t) */ 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric #if defined(__need_size_t) 935f757f3fSDimitry Andric #include <__stddef_size_t.h> 940b57cec5SDimitry Andric #undef __need_size_t 950b57cec5SDimitry Andric #endif /*defined(__need_size_t) */ 960b57cec5SDimitry Andric 975f757f3fSDimitry Andric #if defined(__need_rsize_t) 985f757f3fSDimitry Andric #include <__stddef_rsize_t.h> 995f757f3fSDimitry Andric #undef __need_rsize_t 1005f757f3fSDimitry Andric #endif /* defined(__need_rsize_t) */ 1010b57cec5SDimitry Andric 1020b57cec5SDimitry Andric #if defined(__need_wchar_t) 1035f757f3fSDimitry Andric #include <__stddef_wchar_t.h> 1040b57cec5SDimitry Andric #undef __need_wchar_t 1050b57cec5SDimitry Andric #endif /* defined(__need_wchar_t) */ 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andric #if defined(__need_NULL) 1085f757f3fSDimitry Andric #include <__stddef_null.h> 1090b57cec5SDimitry Andric #undef __need_NULL 1100b57cec5SDimitry Andric #endif /* defined(__need_NULL) */ 1110b57cec5SDimitry Andric 1125f757f3fSDimitry Andric #if defined(__need_nullptr_t) 1135f757f3fSDimitry Andric #include <__stddef_nullptr_t.h> 1145f757f3fSDimitry Andric #undef __need_nullptr_t 1155f757f3fSDimitry Andric #endif /* defined(__need_nullptr_t) */ 116bdd1243dSDimitry Andric 1175f757f3fSDimitry Andric #if defined(__need_unreachable) 1185f757f3fSDimitry Andric #include <__stddef_unreachable.h> 1195f757f3fSDimitry Andric #undef __need_unreachable 1205f757f3fSDimitry Andric #endif /* defined(__need_unreachable) */ 12106c3fb27SDimitry Andric 1225f757f3fSDimitry Andric #if defined(__need_max_align_t) 1235f757f3fSDimitry Andric #include <__stddef_max_align_t.h> 1245f757f3fSDimitry Andric #undef __need_max_align_t 1255f757f3fSDimitry Andric #endif /* defined(__need_max_align_t) */ 1265f757f3fSDimitry Andric 1275f757f3fSDimitry Andric #if defined(__need_offsetof) 1285f757f3fSDimitry Andric #include <__stddef_offsetof.h> 1295f757f3fSDimitry Andric #undef __need_offsetof 1305f757f3fSDimitry Andric #endif /* defined(__need_offsetof) */ 1310b57cec5SDimitry Andric 1320b57cec5SDimitry Andric /* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use 1330b57cec5SDimitry Andric __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */ 1340b57cec5SDimitry Andric #if defined(__need_wint_t) 1355f757f3fSDimitry Andric #include <__stddef_wint_t.h> 1360b57cec5SDimitry Andric #undef __need_wint_t 1370b57cec5SDimitry Andric #endif /* __need_wint_t */ 1380b57cec5SDimitry Andric 1390fca6ea1SDimitry Andric #endif /* __MVS__ */ 140