Debian Codegraph @

gcc/ginclude/stddef.h

raw
1 /* Copyright (C) 1989-2025 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 /* [email protected] 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 #if defined(__NetBSD__)
50 #include <machine/ansi.h>
51 #endif
52
53 #if defined (__FreeBSD__)
54 #include <sys/_types.h>
55 #endif
56
57 #if defined(__NetBSD__)
58 #if !defined(_SIZE_T_) && !defined(_BSD_SIZE_T_)
59 #define _SIZE_T
60 #endif
61 #if !defined(_PTRDIFF_T_) && !defined(_BSD_PTRDIFF_T_)
62 #define _PTRDIFF_T
63 #endif
64 /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_
65 instead of _WCHAR_T_. */
66 #if !defined(_WCHAR_T_) && !defined(_BSD_WCHAR_T_)
67 #ifndef _BSD_WCHAR_T_
68 #define _WCHAR_T
69 #endif
70 #endif
71 /* Undef _FOO_T_ if we are supposed to define foo_t. */
72 #if defined (__need_ptrdiff_t) || defined (_STDDEF_H_)
73 #undef _PTRDIFF_T_
74 #undef _BSD_PTRDIFF_T_
75 #endif
76 #if defined (__need_size_t) || defined (_STDDEF_H_)
77 #undef _SIZE_T_
78 #undef _BSD_SIZE_T_
79 #endif
80 #if defined (__need_wchar_t) || defined (_STDDEF_H_)
81 #undef _WCHAR_T_
82 #undef _BSD_WCHAR_T_
83 #endif
84 #endif /* defined(__NetBSD__) */
85
86 /* Sequent's header files use _PTRDIFF_T_ in some conflicting way.
87 Just ignore it. */
88 #if defined (__sequent__) && defined (_PTRDIFF_T_)
89 #undef _PTRDIFF_T_
90 #endif
91
92 /* When modular code is enabled with macOS SDKs from version 15, the
93 include guards are set in the includers of this code, rather than as
94 part of it. This means the we must unset them or the intended code
95 here will be bypassed (resulting in undefined values). */
96 #if defined (__APPLE__)
97 # if defined(__has_feature) && __has_feature(modules)
98 # if defined (__need_ptrdiff_t)
99 # undef __PTRDIFF_T
100 # endif
101 # if defined (__need_size_t)
102 # undef __SIZE_T
103 # endif
104 # endif
105 #endif
106
107 /* On VxWorks, <type/vxTypesBase.h> may have defined macros like
108 _TYPE_size_t which will typedef size_t. fixincludes patched the
109 vxTypesBase.h so that this macro is only defined if _GCC_SIZE_T is
110 not defined, and so that defining this macro defines _GCC_SIZE_T.
111 If we find that the macros are still defined at this point, we must
112 invoke them so that the type is defined as expected. */
113 #if defined (_TYPE_ptrdiff_t) && (defined (__need_ptrdiff_t) || defined (_STDDEF_H_))
114 _TYPE_ptrdiff_t;
115 #undef _TYPE_ptrdiff_t
116 #endif
117 #if defined (_TYPE_size_t) && (defined (__need_size_t) || defined (_STDDEF_H_))
118 _TYPE_size_t;
119 #undef _TYPE_size_t
120 #endif
121 #if defined (_TYPE_wchar_t) && (defined (__need_wchar_t) || defined (_STDDEF_H_))
122 _TYPE_wchar_t;
123 #undef _TYPE_wchar_t
124 #endif
125
126 /* In case nobody has defined these types, but we aren't running under
127 GCC 2.00, make sure that __PTRDIFF_TYPE__, __SIZE_TYPE__, and
128 __WCHAR_TYPE__ have reasonable values. This can happen if the
129 parts of GCC is compiled by an older compiler, that actually
130 include gstddef.h, such as collect2. */
131
132 /* Signed type of difference of two pointers. */
133
134 /* Define this type if we are doing the whole job,
135 or if we want this type in particular. */
136 #if defined (_STDDEF_H) || defined (__need_ptrdiff_t)
137 #ifndef _PTRDIFF_T /* in case <sys/types.h> has defined it. */
138 #ifndef _T_PTRDIFF_
139 #ifndef _T_PTRDIFF
140 #ifndef __PTRDIFF_T
141 #ifndef _PTRDIFF_T_
142 #ifndef _BSD_PTRDIFF_T_
143 #ifndef ___int_ptrdiff_t_h
144 #ifndef _GCC_PTRDIFF_T
145 #ifndef _PTRDIFF_T_DECLARED /* DragonFly */
146 #ifndef __DEFINED_ptrdiff_t /* musl libc */
147 #define _PTRDIFF_T
148 #define _T_PTRDIFF_
149 #define _T_PTRDIFF
150 #define __PTRDIFF_T
151 #define _PTRDIFF_T_
152 #define _BSD_PTRDIFF_T_
153 #define ___int_ptrdiff_t_h
154 #define _GCC_PTRDIFF_T
155 #define _PTRDIFF_T_DECLARED
156 #define __DEFINED_ptrdiff_t
157 #ifndef __PTRDIFF_TYPE__
158 #define __PTRDIFF_TYPE__ long int
159 #endif
160 typedef __PTRDIFF_TYPE__ ptrdiff_t;
161 #endif /* __DEFINED_ptrdiff_t */
162 #endif /* _PTRDIFF_T_DECLARED */
163 #endif /* _GCC_PTRDIFF_T */
164 #endif /* ___int_ptrdiff_t_h */
165 #endif /* _BSD_PTRDIFF_T_ */
166 #endif /* _PTRDIFF_T_ */
167 #endif /* __PTRDIFF_T */
168 #endif /* _T_PTRDIFF */
169 #endif /* _T_PTRDIFF_ */
170 #endif /* _PTRDIFF_T */
171
172 /* If this symbol has done its job, get rid of it. */
173 #undef __need_ptrdiff_t
174
175 #endif /* _STDDEF_H or __need_ptrdiff_t. */
176
177 /* Unsigned type of `sizeof' something. */
178
179 /* Define this type if we are doing the whole job,
180 or if we want this type in particular. */
181 #if defined (_STDDEF_H) || defined (__need_size_t)
182 #ifndef __size_t__ /* BeOS */
183 #ifndef __SIZE_T__ /* Cray Unicos/Mk */
184 #ifndef _SIZE_T /* in case <sys/types.h> has defined it. */
185 #ifndef _SYS_SIZE_T_H
186 #ifndef _T_SIZE_
187 #ifndef _T_SIZE
188 #ifndef __SIZE_T
189 #ifndef _SIZE_T_
190 #ifndef _BSD_SIZE_T_
191 #ifndef _SIZE_T_DEFINED_
192 #ifndef _SIZE_T_DEFINED
193 #ifndef _BSD_SIZE_T_DEFINED_ /* Darwin */
194 #ifndef _SIZE_T_DECLARED /* FreeBSD 5 */
195 #ifndef __DEFINED_size_t /* musl libc */
196 #ifndef ___int_size_t_h
197 #ifndef _GCC_SIZE_T
198 #ifndef _SIZET_
199 #ifndef __size_t
200 #define __size_t__ /* BeOS */
201 #define __SIZE_T__ /* Cray Unicos/Mk */
202 #define _SIZE_T
203 #define _SYS_SIZE_T_H
204 #define _T_SIZE_
205 #define _T_SIZE
206 #define __SIZE_T
207 #define _SIZE_T_
208 #define _BSD_SIZE_T_
209 #define _SIZE_T_DEFINED_
210 #define _SIZE_T_DEFINED
211 #define _BSD_SIZE_T_DEFINED_ /* Darwin */
212 #define _SIZE_T_DECLARED /* FreeBSD 5 */
213 #define __DEFINED_size_t /* musl libc */
214 #define ___int_size_t_h
215 #define _GCC_SIZE_T
216 #define _SIZET_
217 #if defined (__FreeBSD__) \
218 || defined(__DragonFly__) \
219 || defined(__FreeBSD_kernel__) \
220 || defined(__VMS__)
221 /* __size_t is a typedef, must not trash it. */
222 #else
223 #define __size_t
224 #endif
225 #ifndef __SIZE_TYPE__
226 #define __SIZE_TYPE__ long unsigned int
227 #endif
228 #if !(defined (__GNUG__) && defined (size_t))
229 typedef __SIZE_TYPE__ size_t;
230 #ifdef __BEOS__
231 typedef long ssize_t;
232 #endif /* __BEOS__ */
233 #endif /* !(defined (__GNUG__) && defined (size_t)) */
234 #endif /* __size_t */
235 #endif /* _SIZET_ */
236 #endif /* _GCC_SIZE_T */
237 #endif /* ___int_size_t_h */
238 #endif /* __DEFINED_size_t */
239 #endif /* _SIZE_T_DECLARED */
240 #endif /* _BSD_SIZE_T_DEFINED_ */
241 #endif /* _SIZE_T_DEFINED */
242 #endif /* _SIZE_T_DEFINED_ */
243 #endif /* _BSD_SIZE_T_ */
244 #endif /* _SIZE_T_ */
245 #endif /* __SIZE_T */
246 #endif /* _T_SIZE */
247 #endif /* _T_SIZE_ */
248 #endif /* _SYS_SIZE_T_H */
249 #endif /* _SIZE_T */
250 #endif /* __SIZE_T__ */
251 #endif /* __size_t__ */
252 #undef __need_size_t
253 #endif /* _STDDEF_H or __need_size_t. */
254
255
256 /* Wide character type.
257 Locale-writers should change this as necessary to
258 be big enough to hold unique values not between 0 and 127,
259 and not (wchar_t) -1, for each defined multibyte character. */
260
261 /* Define this type if we are doing the whole job,
262 or if we want this type in particular. */
263 #if defined (_STDDEF_H) || defined (__need_wchar_t)
264 #ifndef __wchar_t__ /* BeOS */
265 #ifndef __WCHAR_T__ /* Cray Unicos/Mk */
266 #ifndef _WCHAR_T
267 #ifndef _T_WCHAR_
268 #ifndef _T_WCHAR
269 #ifndef __WCHAR_T
270 #ifndef _WCHAR_T_
271 #ifndef _BSD_WCHAR_T_
272 #ifndef _BSD_WCHAR_T_DEFINED_ /* Darwin */
273 #ifndef _BSD_RUNE_T_DEFINED_ /* Darwin */
274 #ifndef _WCHAR_T_DECLARED /* FreeBSD 5 */
275 #ifndef __DEFINED_wchar_t /* musl libc */
276 #ifndef _WCHAR_T_DEFINED_
277 #ifndef _WCHAR_T_DEFINED
278 #ifndef _WCHAR_T_H
279 #ifndef ___int_wchar_t_h
280 #ifndef __INT_WCHAR_T_H
281 #ifndef _GCC_WCHAR_T
282 #define __wchar_t__ /* BeOS */
283 #define __WCHAR_T__ /* Cray Unicos/Mk */
284 #define _WCHAR_T
285 #define _T_WCHAR_
286 #define _T_WCHAR
287 #define __WCHAR_T
288 #define _WCHAR_T_
289 #define _BSD_WCHAR_T_
290 #define _WCHAR_T_DEFINED_
291 #define _WCHAR_T_DEFINED
292 #define _WCHAR_T_H
293 #define ___int_wchar_t_h
294 #define __INT_WCHAR_T_H
295 #define _GCC_WCHAR_T
296 #define _WCHAR_T_DECLARED
297 #define __DEFINED_wchar_t
298
299 /* On BSD/386 1.1, at least, machine/ansi.h defines _BSD_WCHAR_T_
300 instead of _WCHAR_T_, and _BSD_RUNE_T_ (which, unlike the other
301 symbols in the _FOO_T_ family, stays defined even after its
302 corresponding type is defined). If we define wchar_t, then we
303 must undef _WCHAR_T_; for BSD/386 1.1 (and perhaps others), if
304 we undef _WCHAR_T_, then we must also define rune_t, since
305 headers like runetype.h assume that if machine/ansi.h is included,
306 and _BSD_WCHAR_T_ is not defined, then rune_t is available.
307 machine/ansi.h says, "Note that _WCHAR_T_ and _RUNE_T_ must be of
308 the same type." */
309 #ifdef _BSD_WCHAR_T_
310 #undef _BSD_WCHAR_T_
311 #ifdef _BSD_RUNE_T_
312 #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
313 typedef _BSD_RUNE_T_ rune_t;
314 #define _BSD_WCHAR_T_DEFINED_
315 #define _BSD_RUNE_T_DEFINED_ /* Darwin */
316 #if defined (__FreeBSD__) && (__FreeBSD__ < 5)
317 /* Why is this file so hard to maintain properly? In contrast to
318 the comment above regarding BSD/386 1.1, on FreeBSD for as long
319 as the symbol has existed, _BSD_RUNE_T_ must not stay defined or
320 redundant typedefs will occur when stdlib.h is included after this file. */
321 #undef _BSD_RUNE_T_
322 #endif
323 #endif
324 #endif
325 #endif
326 /* FreeBSD 5 can't be handled well using "traditional" logic above
327 since it no longer defines _BSD_RUNE_T_ yet still desires to export
328 rune_t in some cases... */
329 #if defined (__FreeBSD__) && (__FreeBSD__ >= 5)
330 #if !defined (_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
331 #if __BSD_VISIBLE
332 #ifndef _RUNE_T_DECLARED
333 typedef __rune_t rune_t;
334 #define _RUNE_T_DECLARED
335 #endif
336 #endif
337 #endif
338 #endif
339
340 #ifndef __WCHAR_TYPE__
341 #define __WCHAR_TYPE__ int
342 #endif
343 #ifndef __cplusplus
344 typedef __WCHAR_TYPE__ wchar_t;
345 #endif
346 #endif
347 #endif
348 #endif
349 #endif
350 #endif
351 #endif
352 #endif /* __DEFINED_wchar_t */
353 #endif /* _WCHAR_T_DECLARED */
354 #endif /* _BSD_RUNE_T_DEFINED_ */
355 #endif
356 #endif
357 #endif
358 #endif
359 #endif
360 #endif
361 #endif
362 #endif /* __WCHAR_T__ */
363 #endif /* __wchar_t__ */
364 #undef __need_wchar_t
365 #endif /* _STDDEF_H or __need_wchar_t. */
366
367 #if defined (__need_wint_t)
368 #ifndef _WINT_T
369 #define _WINT_T
370
371 #ifndef __WINT_TYPE__
372 #define __WINT_TYPE__ unsigned int
373 #endif
374 typedef __WINT_TYPE__ wint_t;
375 #endif
376 #undef __need_wint_t
377 #endif
378
379 #if defined(__NetBSD__)
380 /* The references to _GCC_PTRDIFF_T_, _GCC_SIZE_T_, and _GCC_WCHAR_T_
381 are probably typos and should be removed before 2.8 is released. */
382 #ifdef _GCC_PTRDIFF_T_
383 #undef _PTRDIFF_T_
384 #undef _BSD_PTRDIFF_T_
385 #endif
386 #ifdef _GCC_SIZE_T_
387 #undef _SIZE_T_
388 #undef _BSD_SIZE_T_
389 #endif
390 #ifdef _GCC_WCHAR_T_
391 #undef _WCHAR_T_
392 #undef _BSD_WCHAR_T_
393 #endif
394 /* The following ones are the real ones. */
395 #ifdef _GCC_PTRDIFF_T
396 #undef _PTRDIFF_T_
397 #undef _BSD_PTRDIFF_T_
398 #endif
399 #ifdef _GCC_SIZE_T
400 #undef _SIZE_T_
401 #undef _BSD_SIZE_T_
402 #endif
403 #ifdef _GCC_WCHAR_T
404 #undef _WCHAR_T_
405 #undef _BSD_WCHAR_T_
406 #endif
407 #endif /* __NetBSD__ */
408
409 #endif /* __sys_stdtypes_h */
410
411 /* A null pointer constant. */
412
413 #if defined (_STDDEF_H) || defined (__need_NULL)
414 #undef NULL /* in case <stdio.h> has defined it. */
415 #ifdef __GNUG__
416 #define NULL __null
417 #else /* G++ */
418 #ifndef __cplusplus
419 #define NULL ((void *)0)
420 #else /* C++ */
421 #define NULL 0
422 #endif /* C++ */
423 #endif /* G++ */
424 #endif /* NULL not defined and <stddef.h> or need NULL. */
425 #undef __need_NULL
426
427 #ifdef _STDDEF_H
428
429 /* Offset of member MEMBER in a struct of type TYPE. */
430 #undef offsetof /* in case a system header has defined it. */
431 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
432
433 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
434 || (defined(__cplusplus) && __cplusplus >= 201103L)
435 #ifndef _GCC_MAX_ALIGN_T
436 #define _GCC_MAX_ALIGN_T
437 /* Type whose alignment is supported in every context and is at least
438 as great as that of any standard type not using alignment
439 specifiers. */
440 typedef struct {
441 long long __max_align_ll __attribute__((__aligned__(__alignof__(long long))));
442 long double __max_align_ld __attribute__((__aligned__(__alignof__(long double))));
443 /* _Float128 is defined as a basic type, so max_align_t must be
444 sufficiently aligned for it. This code must work in C++, so we
445 use __float128 here; that is only available on some
446 architectures, but only on i386 is extra alignment needed for
447 __float128. */
448 #ifdef __i386__
449 __float128 __max_align_f128 __attribute__((__aligned__(__alignof(__float128))));
450 #endif
451 } max_align_t;
452 #endif
453 #endif /* C11 or C++11. */
454
455 #if defined(__cplusplus) && __cplusplus >= 201103L
456 #ifndef _GXX_NULLPTR_T
457 #define _GXX_NULLPTR_T
458 typedef decltype(nullptr) nullptr_t;
459 #endif
460 #endif /* C++11. */
461
462 #if defined (__STDC_VERSION__) && __STDC_VERSION__ > 201710L
463 #ifndef _GCC_NULLPTR_T
464 #define _GCC_NULLPTR_T
465 typedef __typeof__(nullptr) nullptr_t;
466 #endif
467 #ifndef __STDC_VERSION_STDDEF_H__
468 #define unreachable() (__builtin_unreachable ())
469 #define __STDC_VERSION_STDDEF_H__ 202311L
470 #endif
471 #endif /* C23. */
472
473 #endif /* _STDDEF_H was defined this time */
474
475 #endif /* !_STDDEF_H && !_STDDEF_H_ && !_ANSI_STDDEF_H && !__STDDEF_H__
476 || __need_XXX was not defined before */