OSDN Git Service

2010-04-29 Jon Grant <04@jguk.org>
[pf3gnuchains/gcc-fork.git] / gcc / ginclude / stddef.h
1 /* Copyright (C) 1989, 1997, 1998, 1999, 2000, 2002, 2004, 2009
2    Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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)
9 any later version.
10
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.
15
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.
19
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/>.  */
24
25 /*
26  * ISO C Standard:  7.17  Common definitions  <stddef.h>
27  */
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)
33
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))
40 #define _STDDEF_H
41 #define _STDDEF_H_
42 /* snaroff@next.com says the NeXT needs this.  */
43 #define _ANSI_STDDEF_H
44 /* Irix 5.1 needs this.  */
45 #define __STDDEF_H__
46 #endif
47
48 #ifndef __sys_stdtypes_h
49 /* This avoids lossage on SunOS but only if stdtypes.h comes first.
50    There's no way to win with the other order!  Sun lossage.  */
51
52 /* On 4.3bsd-net2, make sure ansi.h is included, so we have
53    one less case to deal with in the following.  */
54 #if defined (__BSD_NET2__) || defined (____386BSD____) || (defined (__FreeBSD__) && (__FreeBSD__ < 5)) || defined(__NetBSD__)
55 #include <machine/ansi.h>
56 #endif
57 /* On FreeBSD 5, machine/ansi.h does not exist anymore... */
58 #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
59 #include <sys/_types.h>
60 #endif
61
62 /* In 4.3bsd-net2, machine/ansi.h defines these symbols, which are
63    defined if the corresponding type is *not* defined.
64    FreeBSD-2.1 defines _MACHINE_ANSI_H_ instead of _ANSI_H_ */
65 #if defined(_ANSI_H_) || defined(_MACHINE_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_) */
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 #define _PTRDIFF_T
139 #define _T_PTRDIFF_
140 #define _T_PTRDIFF
141 #define __PTRDIFF_T
142 #define _PTRDIFF_T_
143 #define _BSD_PTRDIFF_T_
144 #define ___int_ptrdiff_t_h
145 #define _GCC_PTRDIFF_T
146 #ifndef __PTRDIFF_TYPE__
147 #define __PTRDIFF_TYPE__ long int
148 #endif
149 typedef __PTRDIFF_TYPE__ ptrdiff_t;
150 #endif /* _GCC_PTRDIFF_T */
151 #endif /* ___int_ptrdiff_t_h */
152 #endif /* _BSD_PTRDIFF_T_ */
153 #endif /* _PTRDIFF_T_ */
154 #endif /* __PTRDIFF_T */
155 #endif /* _T_PTRDIFF */
156 #endif /* _T_PTRDIFF_ */
157 #endif /* _PTRDIFF_T */
158
159 /* If this symbol has done its job, get rid of it.  */
160 #undef  __need_ptrdiff_t
161
162 #endif /* _STDDEF_H or __need_ptrdiff_t.  */
163
164 /* Unsigned type of `sizeof' something.  */
165
166 /* Define this type if we are doing the whole job,
167    or if we want this type in particular.  */
168 #if defined (_STDDEF_H) || defined (__need_size_t)
169 #ifndef __size_t__      /* BeOS */
170 #ifndef __SIZE_T__      /* Cray Unicos/Mk */
171 #ifndef _SIZE_T /* in case <sys/types.h> has defined it. */
172 #ifndef _SYS_SIZE_T_H
173 #ifndef _T_SIZE_
174 #ifndef _T_SIZE
175 #ifndef __SIZE_T
176 #ifndef _SIZE_T_
177 #ifndef _BSD_SIZE_T_
178 #ifndef _SIZE_T_DEFINED_
179 #ifndef _SIZE_T_DEFINED
180 #ifndef _BSD_SIZE_T_DEFINED_    /* Darwin */
181 #ifndef _SIZE_T_DECLARED        /* FreeBSD 5 */
182 #ifndef ___int_size_t_h
183 #ifndef _GCC_SIZE_T
184 #ifndef _SIZET_
185 #ifndef __size_t
186 #define __size_t__      /* BeOS */
187 #define __SIZE_T__      /* Cray Unicos/Mk */
188 #define _SIZE_T
189 #define _SYS_SIZE_T_H
190 #define _T_SIZE_
191 #define _T_SIZE
192 #define __SIZE_T
193 #define _SIZE_T_
194 #define _BSD_SIZE_T_
195 #define _SIZE_T_DEFINED_
196 #define _SIZE_T_DEFINED
197 #define _BSD_SIZE_T_DEFINED_    /* Darwin */
198 #define _SIZE_T_DECLARED        /* FreeBSD 5 */
199 #define ___int_size_t_h
200 #define _GCC_SIZE_T
201 #define _SIZET_
202 #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
203 /* __size_t is a typedef on FreeBSD 5!, must not trash it. */
204 #else
205 #define __size_t
206 #endif
207 #ifndef __SIZE_TYPE__
208 #define __SIZE_TYPE__ long unsigned int
209 #endif
210 #if !(defined (__GNUG__) && defined (size_t))
211 typedef __SIZE_TYPE__ size_t;
212 #ifdef __BEOS__
213 typedef long ssize_t;
214 #endif /* __BEOS__ */
215 #endif /* !(defined (__GNUG__) && defined (size_t)) */
216 #endif /* __size_t */
217 #endif /* _SIZET_ */
218 #endif /* _GCC_SIZE_T */
219 #endif /* ___int_size_t_h */
220 #endif /* _SIZE_T_DECLARED */
221 #endif /* _BSD_SIZE_T_DEFINED_ */
222 #endif /* _SIZE_T_DEFINED */
223 #endif /* _SIZE_T_DEFINED_ */
224 #endif /* _BSD_SIZE_T_ */
225 #endif /* _SIZE_T_ */
226 #endif /* __SIZE_T */
227 #endif /* _T_SIZE */
228 #endif /* _T_SIZE_ */
229 #endif /* _SYS_SIZE_T_H */
230 #endif /* _SIZE_T */
231 #endif /* __SIZE_T__ */
232 #endif /* __size_t__ */
233 #undef  __need_size_t
234 #endif /* _STDDEF_H or __need_size_t.  */
235
236
237 /* Wide character type.
238    Locale-writers should change this as necessary to
239    be big enough to hold unique values not between 0 and 127,
240    and not (wchar_t) -1, for each defined multibyte character.  */
241
242 /* Define this type if we are doing the whole job,
243    or if we want this type in particular.  */
244 #if defined (_STDDEF_H) || defined (__need_wchar_t)
245 #ifndef __wchar_t__     /* BeOS */
246 #ifndef __WCHAR_T__     /* Cray Unicos/Mk */
247 #ifndef _WCHAR_T
248 #ifndef _T_WCHAR_
249 #ifndef _T_WCHAR
250 #ifndef __WCHAR_T
251 #ifndef _WCHAR_T_
252 #ifndef _BSD_WCHAR_T_
253 #ifndef _BSD_WCHAR_T_DEFINED_    /* Darwin */
254 #ifndef _BSD_RUNE_T_DEFINED_    /* Darwin */
255 #ifndef _WCHAR_T_DECLARED /* FreeBSD 5 */
256 #ifndef _WCHAR_T_DEFINED_
257 #ifndef _WCHAR_T_DEFINED
258 #ifndef _WCHAR_T_H
259 #ifndef ___int_wchar_t_h
260 #ifndef __INT_WCHAR_T_H
261 #ifndef _GCC_WCHAR_T
262 #define __wchar_t__     /* BeOS */
263 #define __WCHAR_T__     /* Cray Unicos/Mk */
264 #define _WCHAR_T
265 #define _T_WCHAR_
266 #define _T_WCHAR
267 #define __WCHAR_T
268 #define _WCHAR_T_
269 #define _BSD_WCHAR_T_
270 #define _WCHAR_T_DEFINED_
271 #define _WCHAR_T_DEFINED
272 #define _WCHAR_T_H
273 #define ___int_wchar_t_h
274 #define __INT_WCHAR_T_H
275 #define _GCC_WCHAR_T
276 #define _WCHAR_T_DECLARED
277
278 /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_
279    instead of _WCHAR_T_, and _BSD_RUNE_T_ (which, unlike the other
280    symbols in the _FOO_T_ family, stays defined even after its
281    corresponding type is defined).  If we define wchar_t, then we
282    must undef _WCHAR_T_; for BSD/386 1.1 (and perhaps others), if
283    we undef _WCHAR_T_, then we must also define rune_t, since 
284    headers like runetype.h assume that if machine/ansi.h is included,
285    and _BSD_WCHAR_T_ is not defined, then rune_t is available.
286    machine/ansi.h says, "Note that _WCHAR_T_ and _RUNE_T_ must be of
287    the same type." */
288 #ifdef _BSD_WCHAR_T_
289 #undef _BSD_WCHAR_T_
290 #ifdef _BSD_RUNE_T_
291 #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
292 typedef _BSD_RUNE_T_ rune_t;
293 #define _BSD_WCHAR_T_DEFINED_
294 #define _BSD_RUNE_T_DEFINED_    /* Darwin */
295 #if defined (__FreeBSD__) && (__FreeBSD__ < 5)
296 /* Why is this file so hard to maintain properly?  In contrast to
297    the comment above regarding BSD/386 1.1, on FreeBSD for as long
298    as the symbol has existed, _BSD_RUNE_T_ must not stay defined or
299    redundant typedefs will occur when stdlib.h is included after this file. */
300 #undef _BSD_RUNE_T_
301 #endif
302 #endif
303 #endif
304 #endif
305 /* FreeBSD 5 can't be handled well using "traditional" logic above
306    since it no longer defines _BSD_RUNE_T_ yet still desires to export
307    rune_t in some cases... */
308 #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
309 #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
310 #if __BSD_VISIBLE
311 #ifndef _RUNE_T_DECLARED
312 typedef __rune_t        rune_t;
313 #define _RUNE_T_DECLARED
314 #endif
315 #endif
316 #endif
317 #endif
318
319 #ifndef __WCHAR_TYPE__
320 #define __WCHAR_TYPE__ int
321 #endif
322 #ifndef __cplusplus
323 typedef __WCHAR_TYPE__ wchar_t;
324 #endif
325 #endif
326 #endif
327 #endif
328 #endif
329 #endif
330 #endif
331 #endif /* _WCHAR_T_DECLARED */
332 #endif /* _BSD_RUNE_T_DEFINED_ */
333 #endif
334 #endif
335 #endif
336 #endif
337 #endif
338 #endif
339 #endif
340 #endif /* __WCHAR_T__ */
341 #endif /* __wchar_t__ */
342 #undef  __need_wchar_t
343 #endif /* _STDDEF_H or __need_wchar_t.  */
344
345 #if defined (__need_wint_t)
346 #ifndef _WINT_T
347 #define _WINT_T
348
349 #ifndef __WINT_TYPE__
350 #define __WINT_TYPE__ unsigned int
351 #endif
352 typedef __WINT_TYPE__ wint_t;
353 #endif
354 #undef __need_wint_t
355 #endif
356
357 /*  In 4.3bsd-net2, leave these undefined to indicate that size_t, etc.
358     are already defined.  */
359 /*  BSD/OS 3.1 and FreeBSD [23].x require the MACHINE_ANSI_H check here.  */
360 #if defined(_ANSI_H_) || defined(_MACHINE_ANSI_H_)
361 /*  The references to _GCC_PTRDIFF_T_, _GCC_SIZE_T_, and _GCC_WCHAR_T_
362     are probably typos and should be removed before 2.8 is released.  */
363 #ifdef _GCC_PTRDIFF_T_
364 #undef _PTRDIFF_T_
365 #undef _BSD_PTRDIFF_T_
366 #endif
367 #ifdef _GCC_SIZE_T_
368 #undef _SIZE_T_
369 #undef _BSD_SIZE_T_
370 #endif
371 #ifdef _GCC_WCHAR_T_
372 #undef _WCHAR_T_
373 #undef _BSD_WCHAR_T_
374 #endif
375 /*  The following ones are the real ones.  */
376 #ifdef _GCC_PTRDIFF_T
377 #undef _PTRDIFF_T_
378 #undef _BSD_PTRDIFF_T_
379 #endif
380 #ifdef _GCC_SIZE_T
381 #undef _SIZE_T_
382 #undef _BSD_SIZE_T_
383 #endif
384 #ifdef _GCC_WCHAR_T
385 #undef _WCHAR_T_
386 #undef _BSD_WCHAR_T_
387 #endif
388 #endif /* _ANSI_H_ || _MACHINE_ANSI_H_ */
389
390 #endif /* __sys_stdtypes_h */
391
392 /* A null pointer constant.  */
393
394 #if defined (_STDDEF_H) || defined (__need_NULL)
395 #undef NULL             /* in case <stdio.h> has defined it. */
396 #ifdef __GNUG__
397 #define NULL __null
398 #else   /* G++ */
399 #ifndef __cplusplus
400 #define NULL ((void *)0)
401 #else   /* C++ */
402 #define NULL 0
403 #endif  /* C++ */
404 #endif  /* G++ */
405 #endif  /* NULL not defined and <stddef.h> or need NULL.  */
406 #undef  __need_NULL
407
408 #ifdef _STDDEF_H
409
410 /* Offset of member MEMBER in a struct of type TYPE. */
411 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
412
413 #endif /* _STDDEF_H was defined this time */
414
415 #endif /* !_STDDEF_H && !_STDDEF_H_ && !_ANSI_STDDEF_H && !__STDDEF_H__
416           || __need_XXX was not defined before */