1 /* Copyright (C) 1989-2015 Free Software Foundation, Inc. 2 3 This file is part of GCC. 4 5 GCC is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3, or (at your option) 8 any later version. 9 10 GCC is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 Under Section 7 of GPL version 3, you are granted additional 16 permissions described in the GCC Runtime Library Exception, version 17 3.1, as published by the Free Software Foundation. 18 19 You should have received a copy of the GNU General Public License and 20 a copy of the GCC Runtime Library Exception along with this program; 21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 22 <http://www.gnu.org/licenses/>. */ 23 24 /* 25 * ISO C Standard: 7.17 Common definitions <stddef.h> 26 */ 27 #if (!defined(_STDDEF_H) && !defined(_STDDEF_H_) && !defined(_ANSI_STDDEF_H) \ 28 && !defined(__STDDEF_H__)) \ 29 || defined(__need_wchar_t) || defined(__need_size_t) \ 30 || defined(__need_ptrdiff_t) || defined(__need_NULL) \ 31 || defined(__need_wint_t) 32 33 /* Any one of these symbols __need_* means that GNU libc 34 wants us just to define one data type. So don't define 35 the symbols that indicate this file's entire job has been done. */ 36 #if (!defined(__need_wchar_t) && !defined(__need_size_t) \ 37 && !defined(__need_ptrdiff_t) && !defined(__need_NULL) \ 38 && !defined(__need_wint_t)) 39 #define _STDDEF_H 40 #define _STDDEF_H_ 41 /* snaroff@next.com says the NeXT needs this. */ 42 #define _ANSI_STDDEF_H 43 #endif 44 45 #ifndef __sys_stdtypes_h 46 /* This avoids lossage on SunOS but only if stdtypes.h comes first. 47 There's no way to win with the other order! Sun lossage. */ 48 49 /* On 4.3bsd-net2, make sure ansi.h is included, so we have 50 one less case to deal with in the following. */ 51 #if defined (__BSD_NET2__) || defined (____386BSD____) || (defined (__FreeBSD__) && (__FreeBSD__ < 5)) || defined(__NetBSD__) 52 #ifndef inhibit_libc 53 #include <machine/ansi.h> 54 #endif 55 #endif 56 /* On FreeBSD 5, machine/ansi.h does not exist anymore... */ 57 #if defined (__FreeBSD__) && (__FreeBSD__ >= 5) 58 #include <sys/_types.h> 59 #endif 60 61 /* In 4.3bsd-net2, machine/ansi.h defines these symbols, which are 62 defined if the corresponding type is *not* defined. 63 FreeBSD-2.1 defines _MACHINE_ANSI_H_ instead of _ANSI_H_. 64 NetBSD defines _I386_ANSI_H_ and _X86_64_ANSI_H_ instead of _ANSI_H_ */ 65 #if defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_) 66 #if !defined(_SIZE_T_) && !defined(_BSD_SIZE_T_) 67 #define _SIZE_T 68 #endif 69 #if !defined(_PTRDIFF_T_) && !defined(_BSD_PTRDIFF_T_) 70 #define _PTRDIFF_T 71 #endif 72 /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_ 73 instead of _WCHAR_T_. */ 74 #if !defined(_WCHAR_T_) && !defined(_BSD_WCHAR_T_) 75 #ifndef _BSD_WCHAR_T_ 76 #define _WCHAR_T 77 #endif 78 #endif 79 /* Undef _FOO_T_ if we are supposed to define foo_t. */ 80 #if defined (__need_ptrdiff_t) || defined (_STDDEF_H_) 81 #undef _PTRDIFF_T_ 82 #undef _BSD_PTRDIFF_T_ 83 #endif 84 #if defined (__need_size_t) || defined (_STDDEF_H_) 85 #undef _SIZE_T_ 86 #undef _BSD_SIZE_T_ 87 #endif 88 #if defined (__need_wchar_t) || defined (_STDDEF_H_) 89 #undef _WCHAR_T_ 90 #undef _BSD_WCHAR_T_ 91 #endif 92 #endif /* defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_) */ 93 94 /* Sequent's header files use _PTRDIFF_T_ in some conflicting way. 95 Just ignore it. */ 96 #if defined (__sequent__) && defined (_PTRDIFF_T_) 97 #undef _PTRDIFF_T_ 98 #endif 99 100 /* On VxWorks, <type/vxTypesBase.h> may have defined macros like 101 _TYPE_size_t which will typedef size_t. fixincludes patched the 102 vxTypesBase.h so that this macro is only defined if _GCC_SIZE_T is 103 not defined, and so that defining this macro defines _GCC_SIZE_T. 104 If we find that the macros are still defined at this point, we must 105 invoke them so that the type is defined as expected. */ 106 #if defined (_TYPE_ptrdiff_t) && (defined (__need_ptrdiff_t) || defined (_STDDEF_H_)) 107 _TYPE_ptrdiff_t; 108 #undef _TYPE_ptrdiff_t 109 #endif 110 #if defined (_TYPE_size_t) && (defined (__need_size_t) || defined (_STDDEF_H_)) 111 _TYPE_size_t; 112 #undef _TYPE_size_t 113 #endif 114 #if defined (_TYPE_wchar_t) && (defined (__need_wchar_t) || defined (_STDDEF_H_)) 115 _TYPE_wchar_t; 116 #undef _TYPE_wchar_t 117 #endif 118 119 /* In case nobody has defined these types, but we aren't running under 120 GCC 2.00, make sure that __PTRDIFF_TYPE__, __SIZE_TYPE__, and 121 __WCHAR_TYPE__ have reasonable values. This can happen if the 122 parts of GCC is compiled by an older compiler, that actually 123 include gstddef.h, such as collect2. */ 124 125 /* Signed type of difference of two pointers. */ 126 127 /* Define this type if we are doing the whole job, 128 or if we want this type in particular. */ 129 #if defined (_STDDEF_H) || defined (__need_ptrdiff_t) 130 #ifndef _PTRDIFF_T /* in case <sys/types.h> has defined it. */ 131 #ifndef _T_PTRDIFF_ 132 #ifndef _T_PTRDIFF 133 #ifndef __PTRDIFF_T 134 #ifndef _PTRDIFF_T_ 135 #ifndef _BSD_PTRDIFF_T_ 136 #ifndef ___int_ptrdiff_t_h 137 #ifndef _GCC_PTRDIFF_T 138 #ifndef _PTRDIFF_T_DECLARED /* DragonFly */ 139 #define _PTRDIFF_T 140 #define _T_PTRDIFF_ 141 #define _T_PTRDIFF 142 #define __PTRDIFF_T 143 #define _PTRDIFF_T_ 144 #define _BSD_PTRDIFF_T_ 145 #define ___int_ptrdiff_t_h 146 #define _GCC_PTRDIFF_T 147 #define _PTRDIFF_T_DECLARED 148 #ifndef __PTRDIFF_TYPE__ 149 #define __PTRDIFF_TYPE__ long int 150 #endif 151 typedef __PTRDIFF_TYPE__ ptrdiff_t; 152 #endif /* _PTRDIFF_T_DECLARED */ 153 #endif /* _GCC_PTRDIFF_T */ 154 #endif /* ___int_ptrdiff_t_h */ 155 #endif /* _BSD_PTRDIFF_T_ */ 156 #endif /* _PTRDIFF_T_ */ 157 #endif /* __PTRDIFF_T */ 158 #endif /* _T_PTRDIFF */ 159 #endif /* _T_PTRDIFF_ */ 160 #endif /* _PTRDIFF_T */ 161 162 /* If this symbol has done its job, get rid of it. */ 163 #undef __need_ptrdiff_t 164 165 #endif /* _STDDEF_H or __need_ptrdiff_t. */ 166 167 /* Unsigned type of `sizeof' something. */ 168 169 /* Define this type if we are doing the whole job, 170 or if we want this type in particular. */ 171 #if defined (_STDDEF_H) || defined (__need_size_t) 172 #ifndef __size_t__ /* BeOS */ 173 #ifndef __SIZE_T__ /* Cray Unicos/Mk */ 174 #ifndef _SIZE_T /* in case <sys/types.h> has defined it. */ 175 #ifndef _SYS_SIZE_T_H 176 #ifndef _T_SIZE_ 177 #ifndef _T_SIZE 178 #ifndef __SIZE_T 179 #ifndef _SIZE_T_ 180 #ifndef _BSD_SIZE_T_ 181 #ifndef _SIZE_T_DEFINED_ 182 #ifndef _SIZE_T_DEFINED 183 #ifndef _BSD_SIZE_T_DEFINED_ /* Darwin */ 184 #ifndef _SIZE_T_DECLARED /* FreeBSD 5 */ 185 #ifndef ___int_size_t_h 186 #ifndef _GCC_SIZE_T 187 #ifndef _SIZET_ 188 #ifndef __size_t 189 #define __size_t__ /* BeOS */ 190 #define __SIZE_T__ /* Cray Unicos/Mk */ 191 #define _SIZE_T 192 #define _SYS_SIZE_T_H 193 #define _T_SIZE_ 194 #define _T_SIZE 195 #define __SIZE_T 196 #define _SIZE_T_ 197 #define _BSD_SIZE_T_ 198 #define _SIZE_T_DEFINED_ 199 #define _SIZE_T_DEFINED 200 #define _BSD_SIZE_T_DEFINED_ /* Darwin */ 201 #define _SIZE_T_DECLARED /* FreeBSD 5 */ 202 #define ___int_size_t_h 203 #define _GCC_SIZE_T 204 #define _SIZET_ 205 #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \ 206 || defined(__DragonFly__) \ 207 || defined(__FreeBSD_kernel__) 208 /* __size_t is a typedef on FreeBSD 5, must not trash it. */ 209 #elif defined (__VMS__) 210 /* __size_t is also a typedef on VMS. */ 211 #else 212 #define __size_t 213 #endif 214 #ifndef __SIZE_TYPE__ 215 #define __SIZE_TYPE__ long unsigned int 216 #endif 217 #if !(defined (__GNUG__) && defined (size_t)) 218 typedef __SIZE_TYPE__ size_t; 219 #ifdef __BEOS__ 220 typedef long ssize_t; 221 #endif /* __BEOS__ */ 222 #endif /* !(defined (__GNUG__) && defined (size_t)) */ 223 #endif /* __size_t */ 224 #endif /* _SIZET_ */ 225 #endif /* _GCC_SIZE_T */ 226 #endif /* ___int_size_t_h */ 227 #endif /* _SIZE_T_DECLARED */ 228 #endif /* _BSD_SIZE_T_DEFINED_ */ 229 #endif /* _SIZE_T_DEFINED */ 230 #endif /* _SIZE_T_DEFINED_ */ 231 #endif /* _BSD_SIZE_T_ */ 232 #endif /* _SIZE_T_ */ 233 #endif /* __SIZE_T */ 234 #endif /* _T_SIZE */ 235 #endif /* _T_SIZE_ */ 236 #endif /* _SYS_SIZE_T_H */ 237 #endif /* _SIZE_T */ 238 #endif /* __SIZE_T__ */ 239 #endif /* __size_t__ */ 240 #undef __need_size_t 241 #endif /* _STDDEF_H or __need_size_t. */ 242 243 244 /* Wide character type. 245 Locale-writers should change this as necessary to 246 be big enough to hold unique values not between 0 and 127, 247 and not (wchar_t) -1, for each defined multibyte character. */ 248 249 /* Define this type if we are doing the whole job, 250 or if we want this type in particular. */ 251 #if defined (_STDDEF_H) || defined (__need_wchar_t) 252 #ifndef __wchar_t__ /* BeOS */ 253 #ifndef __WCHAR_T__ /* Cray Unicos/Mk */ 254 #ifndef _WCHAR_T 255 #ifndef _T_WCHAR_ 256 #ifndef _T_WCHAR 257 #ifndef __WCHAR_T 258 #ifndef _WCHAR_T_ 259 #ifndef _BSD_WCHAR_T_ 260 #ifndef _BSD_WCHAR_T_DEFINED_ /* Darwin */ 261 #ifndef _BSD_RUNE_T_DEFINED_ /* Darwin */ 262 #ifndef _WCHAR_T_DECLARED /* FreeBSD 5 */ 263 #ifndef _WCHAR_T_DEFINED_ 264 #ifndef _WCHAR_T_DEFINED 265 #ifndef _WCHAR_T_H 266 #ifndef ___int_wchar_t_h 267 #ifndef __INT_WCHAR_T_H 268 #ifndef _GCC_WCHAR_T 269 #define __wchar_t__ /* BeOS */ 270 #define __WCHAR_T__ /* Cray Unicos/Mk */ 271 #define _WCHAR_T 272 #define _T_WCHAR_ 273 #define _T_WCHAR 274 #define __WCHAR_T 275 #define _WCHAR_T_ 276 #define _BSD_WCHAR_T_ 277 #define _WCHAR_T_DEFINED_ 278 #define _WCHAR_T_DEFINED 279 #define _WCHAR_T_H 280 #define ___int_wchar_t_h 281 #define __INT_WCHAR_T_H 282 #define _GCC_WCHAR_T 283 #define _WCHAR_T_DECLARED 284 285 /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_ 286 instead of _WCHAR_T_, and _BSD_RUNE_T_ (which, unlike the other 287 symbols in the _FOO_T_ family, stays defined even after its 288 corresponding type is defined). If we define wchar_t, then we 289 must undef _WCHAR_T_; for BSD/386 1.1 (and perhaps others), if 290 we undef _WCHAR_T_, then we must also define rune_t, since 291 headers like runetype.h assume that if machine/ansi.h is included, 292 and _BSD_WCHAR_T_ is not defined, then rune_t is available. 293 machine/ansi.h says, "Note that _WCHAR_T_ and _RUNE_T_ must be of 294 the same type." */ 295 #ifdef _BSD_WCHAR_T_ 296 #undef _BSD_WCHAR_T_ 297 #ifdef _BSD_RUNE_T_ 298 #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE) 299 typedef _BSD_RUNE_T_ rune_t; 300 #define _BSD_WCHAR_T_DEFINED_ 301 #define _BSD_RUNE_T_DEFINED_ /* Darwin */ 302 #if defined (__FreeBSD__) && (__FreeBSD__ < 5) 303 /* Why is this file so hard to maintain properly? In contrast to 304 the comment above regarding BSD/386 1.1, on FreeBSD for as long 305 as the symbol has existed, _BSD_RUNE_T_ must not stay defined or 306 redundant typedefs will occur when stdlib.h is included after this file. */ 307 #undef _BSD_RUNE_T_ 308 #endif 309 #endif 310 #endif 311 #endif 312 /* FreeBSD 5 can't be handled well using "traditional" logic above 313 since it no longer defines _BSD_RUNE_T_ yet still desires to export 314 rune_t in some cases... */ 315 #if defined (__FreeBSD__) && (__FreeBSD__ >= 5) 316 #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE) 317 #if __BSD_VISIBLE 318 #ifndef _RUNE_T_DECLARED 319 typedef __rune_t rune_t; 320 #define _RUNE_T_DECLARED 321 #endif 322 #endif 323 #endif 324 #endif 325 326 #ifndef __WCHAR_TYPE__ 327 #define __WCHAR_TYPE__ int 328 #endif 329 #ifndef __cplusplus 330 typedef __WCHAR_TYPE__ wchar_t; 331 #endif 332 #endif 333 #endif 334 #endif 335 #endif 336 #endif 337 #endif 338 #endif /* _WCHAR_T_DECLARED */ 339 #endif /* _BSD_RUNE_T_DEFINED_ */ 340 #endif 341 #endif 342 #endif 343 #endif 344 #endif 345 #endif 346 #endif 347 #endif /* __WCHAR_T__ */ 348 #endif /* __wchar_t__ */ 349 #undef __need_wchar_t 350 #endif /* _STDDEF_H or __need_wchar_t. */ 351 352 #if defined (__need_wint_t) 353 #ifndef _WINT_T 354 #define _WINT_T 355 356 #ifndef __WINT_TYPE__ 357 #define __WINT_TYPE__ unsigned int 358 #endif 359 typedef __WINT_TYPE__ wint_t; 360 #endif 361 #undef __need_wint_t 362 #endif 363 364 /* In 4.3bsd-net2, leave these undefined to indicate that size_t, etc. 365 are already defined. */ 366 /* BSD/OS 3.1 and FreeBSD [23].x require the MACHINE_ANSI_H check here. */ 367 /* NetBSD 5 requires the I386_ANSI_H and X86_64_ANSI_H checks here. */ 368 #if defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_) 369 /* The references to _GCC_PTRDIFF_T_, _GCC_SIZE_T_, and _GCC_WCHAR_T_ 370 are probably typos and should be removed before 2.8 is released. */ 371 #ifdef _GCC_PTRDIFF_T_ 372 #undef _PTRDIFF_T_ 373 #undef _BSD_PTRDIFF_T_ 374 #endif 375 #ifdef _GCC_SIZE_T_ 376 #undef _SIZE_T_ 377 #undef _BSD_SIZE_T_ 378 #endif 379 #ifdef _GCC_WCHAR_T_ 380 #undef _WCHAR_T_ 381 #undef _BSD_WCHAR_T_ 382 #endif 383 /* The following ones are the real ones. */ 384 #ifdef _GCC_PTRDIFF_T 385 #undef _PTRDIFF_T_ 386 #undef _BSD_PTRDIFF_T_ 387 #endif 388 #ifdef _GCC_SIZE_T 389 #undef _SIZE_T_ 390 #undef _BSD_SIZE_T_ 391 #endif 392 #ifdef _GCC_WCHAR_T 393 #undef _WCHAR_T_ 394 #undef _BSD_WCHAR_T_ 395 #endif 396 #endif /* _ANSI_H_ || _MACHINE_ANSI_H_ || _X86_64_ANSI_H_ || _I386_ANSI_H_ */ 397 398 #endif /* __sys_stdtypes_h */ 399 400 /* A null pointer constant. */ 401 402 #if defined (_STDDEF_H) || defined (__need_NULL) 403 #undef NULL /* in case <stdio.h> has defined it. */ 404 #ifdef __GNUG__ 405 #define NULL __null 406 #else /* G++ */ 407 #ifndef __cplusplus 408 #define NULL ((void *)0) 409 #else /* C++ */ 410 #define NULL 0 411 #endif /* C++ */ 412 #endif /* G++ */ 413 #endif /* NULL not defined and <stddef.h> or need NULL. */ 414 #undef __need_NULL 415 416 #ifdef _STDDEF_H 417 418 /* Offset of member MEMBER in a struct of type TYPE. */ 419 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) 420 421 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \ 422 || (defined(__cplusplus) && __cplusplus >= 201103L) 423 #ifndef _GCC_MAX_ALIGN_T 424 #define _GCC_MAX_ALIGN_T 425 /* Type whose alignment is supported in every context and is at least 426 as great as that of any standard type not using alignment 427 specifiers. */ 428 typedef struct { 429 long long __max_align_ll __attribute__((__aligned__(__alignof__(long long)))); 430 long double __max_align_ld __attribute__((__aligned__(__alignof__(long double)))); 431 } max_align_t; 432 #endif 433 #endif /* C11 or C++11. */ 434 435 #if defined(__cplusplus) && __cplusplus >= 201103L 436 #ifndef _GXX_NULLPTR_T 437 #define _GXX_NULLPTR_T 438 typedef decltype(nullptr) nullptr_t; 439 #endif 440 #endif /* C++11. */ 441 442 #endif /* _STDDEF_H was defined this time */ 443 444 #endif /* !_STDDEF_H && !_STDDEF_H_ && !_ANSI_STDDEF_H && !__STDDEF_H__ 445 || __need_XXX was not defined before */ 446