gnulib: update to 776af40e0
[deliverable/binutils-gdb.git] / gnulib / import / stddef.in.h
1 /* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues.
2
3 Copyright (C) 2009-2021 Free Software Foundation, Inc.
4
5 This program 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 This program 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 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <https://www.gnu.org/licenses/>. */
17
18 /* Written by Eric Blake. */
19
20 /*
21 * POSIX 2008 <stddef.h> for platforms that have issues.
22 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html>
23 */
24
25 #if __GNUC__ >= 3
26 @PRAGMA_SYSTEM_HEADER@
27 #endif
28 @PRAGMA_COLUMNS@
29
30 #if defined __need_wchar_t || defined __need_size_t \
31 || defined __need_ptrdiff_t || defined __need_NULL \
32 || defined __need_wint_t
33 /* Special invocation convention inside gcc header files. In
34 particular, gcc provides a version of <stddef.h> that blindly
35 redefines NULL even when __need_wint_t was defined, even though
36 wint_t is not normally provided by <stddef.h>. Hence, we must
37 remember if special invocation has ever been used to obtain wint_t,
38 in which case we need to clean up NULL yet again. */
39
40 # if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T)
41 # ifdef __need_wint_t
42 # define _GL_STDDEF_WINT_T
43 # endif
44 # @INCLUDE_NEXT@ @NEXT_STDDEF_H@
45 # endif
46
47 #else
48 /* Normal invocation convention. */
49
50 # ifndef _@GUARD_PREFIX@_STDDEF_H
51
52 /* On AIX 7.2, with xlc in 64-bit mode, <stddef.h> defines max_align_t to a
53 type with alignment 4, but 'long' has alignment 8. */
54 # if defined _AIX && defined _ARCH_PPC64
55 # if !GNULIB_defined_max_align_t
56 # ifdef _MAX_ALIGN_T
57 /* /usr/include/stddef.h has already defined max_align_t. Override it. */
58 typedef long rpl_max_align_t;
59 # define max_align_t rpl_max_align_t
60 # else
61 /* Prevent /usr/include/stddef.h from defining max_align_t. */
62 typedef long max_align_t;
63 # define _MAX_ALIGN_T
64 # endif
65 # define GNULIB_defined_max_align_t 1
66 # endif
67 # endif
68
69 /* The include_next requires a split double-inclusion guard. */
70
71 # @INCLUDE_NEXT@ @NEXT_STDDEF_H@
72
73 /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */
74 # if (@REPLACE_NULL@ \
75 && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _GL_STDDEF_WINT_T))
76 # undef NULL
77 # ifdef __cplusplus
78 /* ISO C++ says that the macro NULL must expand to an integer constant
79 expression, hence '((void *) 0)' is not allowed in C++. */
80 # if __GNUG__ >= 3
81 /* GNU C++ has a __null macro that behaves like an integer ('int' or
82 'long') but has the same size as a pointer. Use that, to avoid
83 warnings. */
84 # define NULL __null
85 # else
86 # define NULL 0L
87 # endif
88 # else
89 # define NULL ((void *) 0)
90 # endif
91 # endif
92
93 # ifndef _@GUARD_PREFIX@_STDDEF_H
94 # define _@GUARD_PREFIX@_STDDEF_H
95
96 /* Some platforms lack wchar_t. */
97 #if !@HAVE_WCHAR_T@
98 # define wchar_t int
99 #endif
100
101 /* Some platforms lack max_align_t. The check for _GCC_MAX_ALIGN_T is
102 a hack in case the configure-time test was done with g++ even though
103 we are currently compiling with gcc.
104 On MSVC, max_align_t is defined only in C++ mode, after <cstddef> was
105 included. Its definition is good since it has an alignment of 8 (on x86
106 and x86_64). */
107 #if defined _MSC_VER && defined __cplusplus
108 # include <cstddef>
109 #else
110 # if ! (@HAVE_MAX_ALIGN_T@ || defined _GCC_MAX_ALIGN_T)
111 # if !GNULIB_defined_max_align_t
112 /* On the x86, the maximum storage alignment of double, long, etc. is 4,
113 but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8,
114 and the C11 standard allows this. Work around this problem by
115 using __alignof__ (which returns 8 for double) rather than _Alignof
116 (which returns 4), and align each union member accordingly. */
117 # if defined __GNUC__ || (__clang_major__ >= 4)
118 # define _GL_STDDEF_ALIGNAS(type) \
119 __attribute__ ((__aligned__ (__alignof__ (type))))
120 # else
121 # define _GL_STDDEF_ALIGNAS(type) /* */
122 # endif
123 typedef union
124 {
125 char *__p _GL_STDDEF_ALIGNAS (char *);
126 double __d _GL_STDDEF_ALIGNAS (double);
127 long double __ld _GL_STDDEF_ALIGNAS (long double);
128 long int __i _GL_STDDEF_ALIGNAS (long int);
129 } rpl_max_align_t;
130 # define max_align_t rpl_max_align_t
131 # define GNULIB_defined_max_align_t 1
132 # endif
133 # endif
134 #endif
135
136 # endif /* _@GUARD_PREFIX@_STDDEF_H */
137 # endif /* _@GUARD_PREFIX@_STDDEF_H */
138 #endif /* __need_XXX */
This page took 0.031588 seconds and 4 git commands to generate.