1f4a2713aSLionel Sambuc /*===---- stddef.h - Basic type definitions --------------------------------=== 2f4a2713aSLionel Sambuc * 3f4a2713aSLionel Sambuc * Copyright (c) 2008 Eli Friedman 4f4a2713aSLionel Sambuc * 5f4a2713aSLionel Sambuc * Permission is hereby granted, free of charge, to any person obtaining a copy 6f4a2713aSLionel Sambuc * of this software and associated documentation files (the "Software"), to deal 7f4a2713aSLionel Sambuc * in the Software without restriction, including without limitation the rights 8f4a2713aSLionel Sambuc * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9f4a2713aSLionel Sambuc * copies of the Software, and to permit persons to whom the Software is 10f4a2713aSLionel Sambuc * furnished to do so, subject to the following conditions: 11f4a2713aSLionel Sambuc * 12f4a2713aSLionel Sambuc * The above copyright notice and this permission notice shall be included in 13f4a2713aSLionel Sambuc * all copies or substantial portions of the Software. 14f4a2713aSLionel Sambuc * 15f4a2713aSLionel Sambuc * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16f4a2713aSLionel Sambuc * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17f4a2713aSLionel Sambuc * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18f4a2713aSLionel Sambuc * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19f4a2713aSLionel Sambuc * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20f4a2713aSLionel Sambuc * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21f4a2713aSLionel Sambuc * THE SOFTWARE. 22f4a2713aSLionel Sambuc * 23f4a2713aSLionel Sambuc *===-----------------------------------------------------------------------=== 24f4a2713aSLionel Sambuc */ 25f4a2713aSLionel Sambuc 26*0a6a1f1dSLionel Sambuc #if !defined(__STDDEF_H) || defined(__need_ptrdiff_t) || \ 27*0a6a1f1dSLionel Sambuc defined(__need_size_t) || defined(__need_wchar_t) || \ 28*0a6a1f1dSLionel Sambuc defined(__need_NULL) || defined(__need_wint_t) 29f4a2713aSLionel Sambuc 30*0a6a1f1dSLionel Sambuc #if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \ 31*0a6a1f1dSLionel Sambuc !defined(__need_wchar_t) && !defined(__need_NULL) && \ 32*0a6a1f1dSLionel Sambuc !defined(__need_wint_t) 33*0a6a1f1dSLionel Sambuc /* Always define miscellaneous pieces when modules are available. */ 34*0a6a1f1dSLionel Sambuc #if !__has_feature(modules) 35*0a6a1f1dSLionel Sambuc #define __STDDEF_H 36*0a6a1f1dSLionel Sambuc #endif 37*0a6a1f1dSLionel Sambuc #define __need_ptrdiff_t 38*0a6a1f1dSLionel Sambuc #define __need_size_t 39*0a6a1f1dSLionel Sambuc #define __need_wchar_t 40*0a6a1f1dSLionel Sambuc #define __need_NULL 41*0a6a1f1dSLionel Sambuc #define __need_STDDEF_H_misc 42*0a6a1f1dSLionel Sambuc /* __need_wint_t is intentionally not defined here. */ 43*0a6a1f1dSLionel Sambuc #endif 44*0a6a1f1dSLionel Sambuc 45*0a6a1f1dSLionel Sambuc #if defined(__need_ptrdiff_t) 46f4a2713aSLionel Sambuc #if !defined(_PTRDIFF_T) || __has_feature(modules) 47f4a2713aSLionel Sambuc /* Always define ptrdiff_t when modules are available. */ 48f4a2713aSLionel Sambuc #if !__has_feature(modules) 49f4a2713aSLionel Sambuc #define _PTRDIFF_T 50f4a2713aSLionel Sambuc #endif 51f4a2713aSLionel Sambuc typedef __PTRDIFF_TYPE__ ptrdiff_t; 52f4a2713aSLionel Sambuc #endif 53*0a6a1f1dSLionel Sambuc #undef __need_ptrdiff_t 54*0a6a1f1dSLionel Sambuc #endif /* defined(__need_ptrdiff_t) */ 55f4a2713aSLionel Sambuc 56*0a6a1f1dSLionel Sambuc #if defined(__need_size_t) 57f4a2713aSLionel Sambuc #if !defined(_SIZE_T) || __has_feature(modules) 58f4a2713aSLionel Sambuc /* Always define size_t when modules are available. */ 59f4a2713aSLionel Sambuc #if !__has_feature(modules) 60f4a2713aSLionel Sambuc #define _SIZE_T 61f4a2713aSLionel Sambuc #endif 62f4a2713aSLionel Sambuc typedef __SIZE_TYPE__ size_t; 63f4a2713aSLionel Sambuc #endif 64*0a6a1f1dSLionel Sambuc #undef __need_size_t 65*0a6a1f1dSLionel Sambuc #endif /*defined(__need_size_t) */ 66f4a2713aSLionel Sambuc 67*0a6a1f1dSLionel Sambuc #if defined(__need_STDDEF_H_misc) 68f4a2713aSLionel Sambuc /* ISO9899:2011 7.20 (C11 Annex K): Define rsize_t if __STDC_WANT_LIB_EXT1__ is 69f4a2713aSLionel Sambuc * enabled. */ 70f4a2713aSLionel Sambuc #if (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1 && \ 71f4a2713aSLionel Sambuc !defined(_RSIZE_T)) || __has_feature(modules) 72f4a2713aSLionel Sambuc /* Always define rsize_t when modules are available. */ 73f4a2713aSLionel Sambuc #if !__has_feature(modules) 74f4a2713aSLionel Sambuc #define _RSIZE_T 75f4a2713aSLionel Sambuc #endif 76f4a2713aSLionel Sambuc typedef __SIZE_TYPE__ rsize_t; 77f4a2713aSLionel Sambuc #endif 78*0a6a1f1dSLionel Sambuc #endif /* defined(__need_STDDEF_H_misc) */ 79f4a2713aSLionel Sambuc 80*0a6a1f1dSLionel Sambuc #if defined(__need_wchar_t) 81f4a2713aSLionel Sambuc #ifndef __cplusplus 82f4a2713aSLionel Sambuc /* Always define wchar_t when modules are available. */ 83f4a2713aSLionel Sambuc #if !defined(_WCHAR_T) || __has_feature(modules) 84f4a2713aSLionel Sambuc #if !__has_feature(modules) 85f4a2713aSLionel Sambuc #define _WCHAR_T 86f4a2713aSLionel Sambuc #if defined(_MSC_EXTENSIONS) 87f4a2713aSLionel Sambuc #define _WCHAR_T_DEFINED 88f4a2713aSLionel Sambuc #endif 89f4a2713aSLionel Sambuc #endif 90f4a2713aSLionel Sambuc typedef __WCHAR_TYPE__ wchar_t; 91f4a2713aSLionel Sambuc #endif 92f4a2713aSLionel Sambuc #endif 93*0a6a1f1dSLionel Sambuc #undef __need_wchar_t 94*0a6a1f1dSLionel Sambuc #endif /* defined(__need_wchar_t) */ 95f4a2713aSLionel Sambuc 96*0a6a1f1dSLionel Sambuc #if defined(__need_NULL) 97f4a2713aSLionel Sambuc #undef NULL 98f4a2713aSLionel Sambuc #ifdef __cplusplus 99f4a2713aSLionel Sambuc # if !defined(__MINGW32__) && !defined(_MSC_VER) 100f4a2713aSLionel Sambuc # define NULL __null 101f4a2713aSLionel Sambuc # else 102f4a2713aSLionel Sambuc # define NULL 0 103f4a2713aSLionel Sambuc # endif 104f4a2713aSLionel Sambuc #else 105f4a2713aSLionel Sambuc # define NULL ((void*)0) 106f4a2713aSLionel Sambuc #endif 107f4a2713aSLionel Sambuc #ifdef __cplusplus 108f4a2713aSLionel Sambuc #if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED) 109f4a2713aSLionel Sambuc namespace std { typedef decltype(nullptr) nullptr_t; } 110f4a2713aSLionel Sambuc using ::std::nullptr_t; 111f4a2713aSLionel Sambuc #endif 112f4a2713aSLionel Sambuc #endif 113*0a6a1f1dSLionel Sambuc #undef __need_NULL 114*0a6a1f1dSLionel Sambuc #endif /* defined(__need_NULL) */ 115f4a2713aSLionel Sambuc 116*0a6a1f1dSLionel Sambuc #if defined(__need_STDDEF_H_misc) 11735a4831dSErik van der Kouwe #if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L 118*0a6a1f1dSLionel Sambuc #include "__stddef_max_align_t.h" 11935a4831dSErik van der Kouwe #endif 120f4a2713aSLionel Sambuc #define offsetof(t, d) __builtin_offsetof(t, d) 121*0a6a1f1dSLionel Sambuc #undef __need_STDDEF_H_misc 122*0a6a1f1dSLionel Sambuc #endif /* defined(__need_STDDEF_H_misc) */ 123f4a2713aSLionel Sambuc 124f4a2713aSLionel Sambuc /* Some C libraries expect to see a wint_t here. Others (notably MinGW) will use 125f4a2713aSLionel Sambuc __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */ 126f4a2713aSLionel Sambuc #if defined(__need_wint_t) 127f4a2713aSLionel Sambuc /* Always define wint_t when modules are available. */ 128f4a2713aSLionel Sambuc #if !defined(_WINT_T) || __has_feature(modules) 129f4a2713aSLionel Sambuc #if !__has_feature(modules) 130f4a2713aSLionel Sambuc #define _WINT_T 131f4a2713aSLionel Sambuc #endif 132f4a2713aSLionel Sambuc typedef __WINT_TYPE__ wint_t; 133f4a2713aSLionel Sambuc #endif 134f4a2713aSLionel Sambuc #undef __need_wint_t 135f4a2713aSLionel Sambuc #endif /* __need_wint_t */ 136*0a6a1f1dSLionel Sambuc 137*0a6a1f1dSLionel Sambuc #endif 138