sh: Fix static build with --enable-fortify
[glibc.git] / stdlib / stdint.h
blob01a9abc9e5c153e10894592f457ae78277d87008
1 /* Copyright (C) 1997-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
19 * ISO C99: 7.18 Integer types <stdint.h>
22 #ifndef _STDINT_H
23 #define _STDINT_H 1
25 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
26 #include <bits/libc-header-start.h>
27 #include <bits/types.h>
28 #include <bits/wchar.h>
29 #include <bits/wordsize.h>
31 /* Exact integral types. */
33 /* Signed. */
34 #include <bits/stdint-intn.h>
36 /* Unsigned. */
37 #include <bits/stdint-uintn.h>
40 /* Small types. */
41 #include <bits/stdint-least.h>
44 /* Fast types. */
46 /* Signed. */
47 typedef signed char int_fast8_t;
48 #if __WORDSIZE == 64
49 typedef long int int_fast16_t;
50 typedef long int int_fast32_t;
51 typedef long int int_fast64_t;
52 #else
53 typedef int int_fast16_t;
54 typedef int int_fast32_t;
55 __extension__
56 typedef long long int int_fast64_t;
57 #endif
59 /* Unsigned. */
60 typedef unsigned char uint_fast8_t;
61 #if __WORDSIZE == 64
62 typedef unsigned long int uint_fast16_t;
63 typedef unsigned long int uint_fast32_t;
64 typedef unsigned long int uint_fast64_t;
65 #else
66 typedef unsigned int uint_fast16_t;
67 typedef unsigned int uint_fast32_t;
68 __extension__
69 typedef unsigned long long int uint_fast64_t;
70 #endif
73 /* Types for `void *' pointers. */
74 #if __WORDSIZE == 64
75 # ifndef __intptr_t_defined
76 typedef long int intptr_t;
77 # define __intptr_t_defined
78 # endif
79 typedef unsigned long int uintptr_t;
80 #else
81 # ifndef __intptr_t_defined
82 typedef int intptr_t;
83 # define __intptr_t_defined
84 # endif
85 typedef unsigned int uintptr_t;
86 #endif
89 /* Largest integral types. */
90 typedef __intmax_t intmax_t;
91 typedef __uintmax_t uintmax_t;
94 # if __WORDSIZE == 64
95 # define __INT64_C(c) c ## L
96 # define __UINT64_C(c) c ## UL
97 # else
98 # define __INT64_C(c) c ## LL
99 # define __UINT64_C(c) c ## ULL
100 # endif
102 /* Limits of integral types. */
104 /* Minimum of signed integral types. */
105 # define INT8_MIN (-128)
106 # define INT16_MIN (-32767-1)
107 # define INT32_MIN (-2147483647-1)
108 # define INT64_MIN (-__INT64_C(9223372036854775807)-1)
109 /* Maximum of signed integral types. */
110 # define INT8_MAX (127)
111 # define INT16_MAX (32767)
112 # define INT32_MAX (2147483647)
113 # define INT64_MAX (__INT64_C(9223372036854775807))
115 /* Maximum of unsigned integral types. */
116 # define UINT8_MAX (255)
117 # define UINT16_MAX (65535)
118 # define UINT32_MAX (4294967295U)
119 # define UINT64_MAX (__UINT64_C(18446744073709551615))
122 /* Minimum of signed integral types having a minimum size. */
123 # define INT_LEAST8_MIN (-128)
124 # define INT_LEAST16_MIN (-32767-1)
125 # define INT_LEAST32_MIN (-2147483647-1)
126 # define INT_LEAST64_MIN (-__INT64_C(9223372036854775807)-1)
127 /* Maximum of signed integral types having a minimum size. */
128 # define INT_LEAST8_MAX (127)
129 # define INT_LEAST16_MAX (32767)
130 # define INT_LEAST32_MAX (2147483647)
131 # define INT_LEAST64_MAX (__INT64_C(9223372036854775807))
133 /* Maximum of unsigned integral types having a minimum size. */
134 # define UINT_LEAST8_MAX (255)
135 # define UINT_LEAST16_MAX (65535)
136 # define UINT_LEAST32_MAX (4294967295U)
137 # define UINT_LEAST64_MAX (__UINT64_C(18446744073709551615))
140 /* Minimum of fast signed integral types having a minimum size. */
141 # define INT_FAST8_MIN (-128)
142 # if __WORDSIZE == 64
143 # define INT_FAST16_MIN (-9223372036854775807L-1)
144 # define INT_FAST32_MIN (-9223372036854775807L-1)
145 # else
146 # define INT_FAST16_MIN (-2147483647-1)
147 # define INT_FAST32_MIN (-2147483647-1)
148 # endif
149 # define INT_FAST64_MIN (-__INT64_C(9223372036854775807)-1)
150 /* Maximum of fast signed integral types having a minimum size. */
151 # define INT_FAST8_MAX (127)
152 # if __WORDSIZE == 64
153 # define INT_FAST16_MAX (9223372036854775807L)
154 # define INT_FAST32_MAX (9223372036854775807L)
155 # else
156 # define INT_FAST16_MAX (2147483647)
157 # define INT_FAST32_MAX (2147483647)
158 # endif
159 # define INT_FAST64_MAX (__INT64_C(9223372036854775807))
161 /* Maximum of fast unsigned integral types having a minimum size. */
162 # define UINT_FAST8_MAX (255)
163 # if __WORDSIZE == 64
164 # define UINT_FAST16_MAX (18446744073709551615UL)
165 # define UINT_FAST32_MAX (18446744073709551615UL)
166 # else
167 # define UINT_FAST16_MAX (4294967295U)
168 # define UINT_FAST32_MAX (4294967295U)
169 # endif
170 # define UINT_FAST64_MAX (__UINT64_C(18446744073709551615))
173 /* Values to test for integral types holding `void *' pointer. */
174 # if __WORDSIZE == 64
175 # define INTPTR_MIN (-9223372036854775807L-1)
176 # define INTPTR_MAX (9223372036854775807L)
177 # define UINTPTR_MAX (18446744073709551615UL)
178 # else
179 # define INTPTR_MIN (-2147483647-1)
180 # define INTPTR_MAX (2147483647)
181 # define UINTPTR_MAX (4294967295U)
182 # endif
185 /* Minimum for largest signed integral type. */
186 # define INTMAX_MIN (-__INT64_C(9223372036854775807)-1)
187 /* Maximum for largest signed integral type. */
188 # define INTMAX_MAX (__INT64_C(9223372036854775807))
190 /* Maximum for largest unsigned integral type. */
191 # define UINTMAX_MAX (__UINT64_C(18446744073709551615))
194 /* Limits of other integer types. */
196 /* Limits of `ptrdiff_t' type. */
197 # if __WORDSIZE == 64
198 # define PTRDIFF_MIN (-9223372036854775807L-1)
199 # define PTRDIFF_MAX (9223372036854775807L)
200 # else
201 # if __WORDSIZE32_PTRDIFF_LONG
202 # define PTRDIFF_MIN (-2147483647L-1)
203 # define PTRDIFF_MAX (2147483647L)
204 # else
205 # define PTRDIFF_MIN (-2147483647-1)
206 # define PTRDIFF_MAX (2147483647)
207 # endif
208 # endif
210 /* Limits of `sig_atomic_t'. */
211 # define SIG_ATOMIC_MIN (-2147483647-1)
212 # define SIG_ATOMIC_MAX (2147483647)
214 /* Limit of `size_t' type. */
215 # if __WORDSIZE == 64
216 # define SIZE_MAX (18446744073709551615UL)
217 # else
218 # if __WORDSIZE32_SIZE_ULONG
219 # define SIZE_MAX (4294967295UL)
220 # else
221 # define SIZE_MAX (4294967295U)
222 # endif
223 # endif
225 /* Limits of `wchar_t'. */
226 # ifndef WCHAR_MIN
227 /* These constants might also be defined in <wchar.h>. */
228 # define WCHAR_MIN __WCHAR_MIN
229 # define WCHAR_MAX __WCHAR_MAX
230 # endif
232 /* Limits of `wint_t'. */
233 # define WINT_MIN (0u)
234 # define WINT_MAX (4294967295u)
236 /* Signed. */
237 # define INT8_C(c) c
238 # define INT16_C(c) c
239 # define INT32_C(c) c
240 # if __WORDSIZE == 64
241 # define INT64_C(c) c ## L
242 # else
243 # define INT64_C(c) c ## LL
244 # endif
246 /* Unsigned. */
247 # define UINT8_C(c) c
248 # define UINT16_C(c) c
249 # define UINT32_C(c) c ## U
250 # if __WORDSIZE == 64
251 # define UINT64_C(c) c ## UL
252 # else
253 # define UINT64_C(c) c ## ULL
254 # endif
256 /* Maximal type. */
257 # if __WORDSIZE == 64
258 # define INTMAX_C(c) c ## L
259 # define UINTMAX_C(c) c ## UL
260 # else
261 # define INTMAX_C(c) c ## LL
262 # define UINTMAX_C(c) c ## ULL
263 # endif
265 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
267 # define INT8_WIDTH 8
268 # define UINT8_WIDTH 8
269 # define INT16_WIDTH 16
270 # define UINT16_WIDTH 16
271 # define INT32_WIDTH 32
272 # define UINT32_WIDTH 32
273 # define INT64_WIDTH 64
274 # define UINT64_WIDTH 64
276 # define INT_LEAST8_WIDTH 8
277 # define UINT_LEAST8_WIDTH 8
278 # define INT_LEAST16_WIDTH 16
279 # define UINT_LEAST16_WIDTH 16
280 # define INT_LEAST32_WIDTH 32
281 # define UINT_LEAST32_WIDTH 32
282 # define INT_LEAST64_WIDTH 64
283 # define UINT_LEAST64_WIDTH 64
285 # define INT_FAST8_WIDTH 8
286 # define UINT_FAST8_WIDTH 8
287 # define INT_FAST16_WIDTH __WORDSIZE
288 # define UINT_FAST16_WIDTH __WORDSIZE
289 # define INT_FAST32_WIDTH __WORDSIZE
290 # define UINT_FAST32_WIDTH __WORDSIZE
291 # define INT_FAST64_WIDTH 64
292 # define UINT_FAST64_WIDTH 64
294 # define INTPTR_WIDTH __WORDSIZE
295 # define UINTPTR_WIDTH __WORDSIZE
297 # define INTMAX_WIDTH 64
298 # define UINTMAX_WIDTH 64
300 # define PTRDIFF_WIDTH __WORDSIZE
301 # define SIG_ATOMIC_WIDTH 32
302 # define SIZE_WIDTH __WORDSIZE
303 # define WCHAR_WIDTH 32
304 # define WINT_WIDTH 32
306 #endif
308 #endif /* stdint.h */