1 /* Copyright (C) 1989, 1997, 1998, 1999, 2000, 2002, 2004, 2009, 2011, 2012
2 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
26 * ISO C Standard: 7.17 Common definitions <stddef.h>
28 #if (!defined(_STDDEF_H) && !defined(_STDDEF_H_) && !defined(_ANSI_STDDEF_H) \
29 && !defined(__STDDEF_H__)) \
30 || defined(__need_wchar_t) || defined(__need_size_t) \
31 || defined(__need_ptrdiff_t) || defined(__need_NULL) \
32 || defined(__need_wint_t)
34 /* Any one of these symbols __need_* means that GNU libc
35 wants us just to define one data type. So don't define
36 the symbols that indicate this file's entire job has been done. */
37 #if (!defined(__need_wchar_t) && !defined(__need_size_t) \
38 && !defined(__need_ptrdiff_t) && !defined(__need_NULL) \
39 && !defined(__need_wint_t))
42 /* snaroff@next.com says the NeXT needs this. */
43 #define _ANSI_STDDEF_H
46 #ifndef __sys_stdtypes_h
47 /* This avoids lossage on SunOS but only if stdtypes.h comes first.
48 There's no way to win with the other order! Sun lossage. */
50 /* On 4.3bsd-net2, make sure ansi.h is included, so we have
51 one less case to deal with in the following. */
52 #if defined (__BSD_NET2__) || defined (____386BSD____) || (defined (__FreeBSD__) && (__FreeBSD__ < 5)) || defined(__NetBSD__)
53 #include <machine/ansi.h>
55 /* On FreeBSD 5, machine/ansi.h does not exist anymore... */
56 #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
57 #include <sys/_types.h>
60 /* In 4.3bsd-net2, machine/ansi.h defines these symbols, which are
61 defined if the corresponding type is *not* defined.
62 FreeBSD-2.1 defines _MACHINE_ANSI_H_ instead of _ANSI_H_.
63 NetBSD defines _I386_ANSI_H_ and _X86_64_ANSI_H_ instead of _ANSI_H_ */
64 #if defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_)
65 #if !defined(_SIZE_T_) && !defined(_BSD_SIZE_T_)
68 #if !defined(_PTRDIFF_T_) && !defined(_BSD_PTRDIFF_T_)
71 /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_
72 instead of _WCHAR_T_. */
73 #if !defined(_WCHAR_T_) && !defined(_BSD_WCHAR_T_)
78 /* Undef _FOO_T_ if we are supposed to define foo_t. */
79 #if defined (__need_ptrdiff_t) || defined (_STDDEF_H_)
81 #undef _BSD_PTRDIFF_T_
83 #if defined (__need_size_t) || defined (_STDDEF_H_)
87 #if defined (__need_wchar_t) || defined (_STDDEF_H_)
91 #endif /* defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_) */
93 /* Sequent's header files use _PTRDIFF_T_ in some conflicting way.
95 #if defined (__sequent__) && defined (_PTRDIFF_T_)
99 /* On VxWorks, <type/vxTypesBase.h> may have defined macros like
100 _TYPE_size_t which will typedef size_t. fixincludes patched the
101 vxTypesBase.h so that this macro is only defined if _GCC_SIZE_T is
102 not defined, and so that defining this macro defines _GCC_SIZE_T.
103 If we find that the macros are still defined at this point, we must
104 invoke them so that the type is defined as expected. */
105 #if defined (_TYPE_ptrdiff_t) && (defined (__need_ptrdiff_t) || defined (_STDDEF_H_))
107 #undef _TYPE_ptrdiff_t
109 #if defined (_TYPE_size_t) && (defined (__need_size_t) || defined (_STDDEF_H_))
113 #if defined (_TYPE_wchar_t) && (defined (__need_wchar_t) || defined (_STDDEF_H_))
118 /* In case nobody has defined these types, but we aren't running under
119 GCC 2.00, make sure that __PTRDIFF_TYPE__, __SIZE_TYPE__, and
120 __WCHAR_TYPE__ have reasonable values. This can happen if the
121 parts of GCC is compiled by an older compiler, that actually
122 include gstddef.h, such as collect2. */
124 /* Signed type of difference of two pointers. */
126 /* Define this type if we are doing the whole job,
127 or if we want this type in particular. */
128 #if defined (_STDDEF_H) || defined (__need_ptrdiff_t)
129 #ifndef _PTRDIFF_T /* in case <sys/types.h> has defined it. */
134 #ifndef _BSD_PTRDIFF_T_
135 #ifndef ___int_ptrdiff_t_h
136 #ifndef _GCC_PTRDIFF_T
142 #define _BSD_PTRDIFF_T_
143 #define ___int_ptrdiff_t_h
144 #define _GCC_PTRDIFF_T
145 #ifndef __PTRDIFF_TYPE__
146 #define __PTRDIFF_TYPE__ long int
148 typedef __PTRDIFF_TYPE__
ptrdiff_t;
149 #endif /* _GCC_PTRDIFF_T */
150 #endif /* ___int_ptrdiff_t_h */
151 #endif /* _BSD_PTRDIFF_T_ */
152 #endif /* _PTRDIFF_T_ */
153 #endif /* __PTRDIFF_T */
154 #endif /* _T_PTRDIFF */
155 #endif /* _T_PTRDIFF_ */
156 #endif /* _PTRDIFF_T */
158 /* If this symbol has done its job, get rid of it. */
159 #undef __need_ptrdiff_t
161 #endif /* _STDDEF_H or __need_ptrdiff_t. */
163 /* Unsigned type of `sizeof' something. */
165 /* Define this type if we are doing the whole job,
166 or if we want this type in particular. */
167 #if defined (_STDDEF_H) || defined (__need_size_t)
168 #ifndef __size_t__ /* BeOS */
169 #ifndef __SIZE_T__ /* Cray Unicos/Mk */
170 #ifndef _SIZE_T /* in case <sys/types.h> has defined it. */
171 #ifndef _SYS_SIZE_T_H
177 #ifndef _SIZE_T_DEFINED_
178 #ifndef _SIZE_T_DEFINED
179 #ifndef _BSD_SIZE_T_DEFINED_ /* Darwin */
180 #ifndef _SIZE_T_DECLARED /* FreeBSD 5 */
181 #ifndef ___int_size_t_h
185 #define __size_t__ /* BeOS */
186 #define __SIZE_T__ /* Cray Unicos/Mk */
188 #define _SYS_SIZE_T_H
194 #define _SIZE_T_DEFINED_
195 #define _SIZE_T_DEFINED
196 #define _BSD_SIZE_T_DEFINED_ /* Darwin */
197 #define _SIZE_T_DECLARED /* FreeBSD 5 */
198 #define ___int_size_t_h
201 #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
202 || defined(__FreeBSD_kernel__)
203 /* __size_t is a typedef on FreeBSD 5, must not trash it. */
204 #elif defined (__VMS__)
205 /* __size_t is also a typedef on VMS. */
209 #ifndef __SIZE_TYPE__
210 #define __SIZE_TYPE__ long unsigned int
212 #if !(defined (__GNUG__) && defined (size_t))
213 typedef __SIZE_TYPE__
size_t;
215 typedef long ssize_t
;
216 #endif /* __BEOS__ */
217 #endif /* !(defined (__GNUG__) && defined (size_t)) */
218 #endif /* __size_t */
220 #endif /* _GCC_SIZE_T */
221 #endif /* ___int_size_t_h */
222 #endif /* _SIZE_T_DECLARED */
223 #endif /* _BSD_SIZE_T_DEFINED_ */
224 #endif /* _SIZE_T_DEFINED */
225 #endif /* _SIZE_T_DEFINED_ */
226 #endif /* _BSD_SIZE_T_ */
227 #endif /* _SIZE_T_ */
228 #endif /* __SIZE_T */
230 #endif /* _T_SIZE_ */
231 #endif /* _SYS_SIZE_T_H */
233 #endif /* __SIZE_T__ */
234 #endif /* __size_t__ */
236 #endif /* _STDDEF_H or __need_size_t. */
239 /* Wide character type.
240 Locale-writers should change this as necessary to
241 be big enough to hold unique values not between 0 and 127,
242 and not (wchar_t) -1, for each defined multibyte character. */
244 /* Define this type if we are doing the whole job,
245 or if we want this type in particular. */
246 #if defined (_STDDEF_H) || defined (__need_wchar_t)
247 #ifndef __wchar_t__ /* BeOS */
248 #ifndef __WCHAR_T__ /* Cray Unicos/Mk */
254 #ifndef _BSD_WCHAR_T_
255 #ifndef _BSD_WCHAR_T_DEFINED_ /* Darwin */
256 #ifndef _BSD_RUNE_T_DEFINED_ /* Darwin */
257 #ifndef _WCHAR_T_DECLARED /* FreeBSD 5 */
258 #ifndef _WCHAR_T_DEFINED_
259 #ifndef _WCHAR_T_DEFINED
261 #ifndef ___int_wchar_t_h
262 #ifndef __INT_WCHAR_T_H
264 #define __wchar_t__ /* BeOS */
265 #define __WCHAR_T__ /* Cray Unicos/Mk */
271 #define _BSD_WCHAR_T_
272 #define _WCHAR_T_DEFINED_
273 #define _WCHAR_T_DEFINED
275 #define ___int_wchar_t_h
276 #define __INT_WCHAR_T_H
278 #define _WCHAR_T_DECLARED
280 /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_
281 instead of _WCHAR_T_, and _BSD_RUNE_T_ (which, unlike the other
282 symbols in the _FOO_T_ family, stays defined even after its
283 corresponding type is defined). If we define wchar_t, then we
284 must undef _WCHAR_T_; for BSD/386 1.1 (and perhaps others), if
285 we undef _WCHAR_T_, then we must also define rune_t, since
286 headers like runetype.h assume that if machine/ansi.h is included,
287 and _BSD_WCHAR_T_ is not defined, then rune_t is available.
288 machine/ansi.h says, "Note that _WCHAR_T_ and _RUNE_T_ must be of
293 #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
294 typedef _BSD_RUNE_T_ rune_t
;
295 #define _BSD_WCHAR_T_DEFINED_
296 #define _BSD_RUNE_T_DEFINED_ /* Darwin */
297 #if defined (__FreeBSD__) && (__FreeBSD__ < 5)
298 /* Why is this file so hard to maintain properly? In contrast to
299 the comment above regarding BSD/386 1.1, on FreeBSD for as long
300 as the symbol has existed, _BSD_RUNE_T_ must not stay defined or
301 redundant typedefs will occur when stdlib.h is included after this file. */
307 /* FreeBSD 5 can't be handled well using "traditional" logic above
308 since it no longer defines _BSD_RUNE_T_ yet still desires to export
309 rune_t in some cases... */
310 #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
311 #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
313 #ifndef _RUNE_T_DECLARED
314 typedef __rune_t rune_t
;
315 #define _RUNE_T_DECLARED
321 #ifndef __WCHAR_TYPE__
322 #define __WCHAR_TYPE__ int
325 typedef __WCHAR_TYPE__
wchar_t;
333 #endif /* _WCHAR_T_DECLARED */
334 #endif /* _BSD_RUNE_T_DEFINED_ */
342 #endif /* __WCHAR_T__ */
343 #endif /* __wchar_t__ */
344 #undef __need_wchar_t
345 #endif /* _STDDEF_H or __need_wchar_t. */
347 #if defined (__need_wint_t)
351 #ifndef __WINT_TYPE__
352 #define __WINT_TYPE__ unsigned int
354 typedef __WINT_TYPE__
wint_t;
359 /* In 4.3bsd-net2, leave these undefined to indicate that size_t, etc.
360 are already defined. */
361 /* BSD/OS 3.1 and FreeBSD [23].x require the MACHINE_ANSI_H check here. */
362 /* NetBSD 5 requires the I386_ANSI_H and X86_64_ANSI_H checks here. */
363 #if defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_) || defined(_X86_64_ANSI_H_) || defined(_I386_ANSI_H_)
364 /* The references to _GCC_PTRDIFF_T_, _GCC_SIZE_T_, and _GCC_WCHAR_T_
365 are probably typos and should be removed before 2.8 is released. */
366 #ifdef _GCC_PTRDIFF_T_
368 #undef _BSD_PTRDIFF_T_
378 /* The following ones are the real ones. */
379 #ifdef _GCC_PTRDIFF_T
381 #undef _BSD_PTRDIFF_T_
391 #endif /* _ANSI_H_ || _MACHINE_ANSI_H_ || _X86_64_ANSI_H_ || _I386_ANSI_H_ */
393 #endif /* __sys_stdtypes_h */
395 /* A null pointer constant. */
397 #if defined (_STDDEF_H) || defined (__need_NULL)
398 #undef NULL /* in case <stdio.h> has defined it. */
403 #define NULL ((void *)0)
408 #endif /* NULL not defined and <stddef.h> or need NULL. */
413 /* Offset of member MEMBER in a struct of type TYPE. */
414 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
416 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
417 || (defined(__cplusplus) && __cplusplus >= 201103L)
418 #ifndef _GCC_MAX_ALIGN_T
419 #define _GCC_MAX_ALIGN_T
420 /* Type whose alignment is supported in every context and is at least
421 as great as that of any standard type not using alignment
424 long long __max_align_ll
__attribute__((__aligned__(__alignof__(long long))));
425 long double __max_align_ld
__attribute__((__aligned__(__alignof__(long double))));
428 #endif /* C11 or C++11. */
430 #if defined(__cplusplus) && __cplusplus >= 201103L
431 #ifndef _GXX_NULLPTR_T
432 #define _GXX_NULLPTR_T
433 typedef decltype(nullptr) nullptr_t
;
437 #endif /* _STDDEF_H was defined this time */
439 #endif /* !_STDDEF_H && !_STDDEF_H_ && !_ANSI_STDDEF_H && !__STDDEF_H__
440 || __need_XXX was not defined before */