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