xref: /freebsd/contrib/llvm-project/clang/lib/Headers/stdint.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 /*===---- stdint.h - Standard header for sized integer types --------------===*\
2  *
3  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4  * See https://llvm.org/LICENSE.txt for license information.
5  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6  *
7 \*===----------------------------------------------------------------------===*/
8 
9 #ifndef __CLANG_STDINT_H
10 // AIX system headers need stdint.h to be re-enterable while _STD_TYPES_T
11 // is defined until an inclusion of it without _STD_TYPES_T occurs, in which
12 // case the header guard macro is defined.
13 #if !defined(_AIX) || !defined(_STD_TYPES_T) || !defined(__STDC_HOSTED__)
14 #define __CLANG_STDINT_H
15 #endif
16 
17 #if defined(__MVS__) && __has_include_next(<stdint.h>)
18 #include_next <stdint.h>
19 #else
20 
21 /* If we're hosted, fall back to the system's stdint.h, which might have
22  * additional definitions.
23  */
24 #if __STDC_HOSTED__ && __has_include_next(<stdint.h>)
25 
26 // C99 7.18.3 Limits of other integer types
27 //
28 //  Footnote 219, 220: C++ implementations should define these macros only when
29 //  __STDC_LIMIT_MACROS is defined before <stdint.h> is included.
30 //
31 //  Footnote 222: C++ implementations should define these macros only when
32 //  __STDC_CONSTANT_MACROS is defined before <stdint.h> is included.
33 //
34 // C++11 [cstdint.syn]p2:
35 //
36 //  The macros defined by <cstdint> are provided unconditionally. In particular,
37 //  the symbols __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS (mentioned in
38 //  footnotes 219, 220, and 222 in the C standard) play no role in C++.
39 //
40 // C11 removed the problematic footnotes.
41 //
42 // Work around this inconsistency by always defining those macros in C++ mode,
43 // so that a C library implementation which follows the C99 standard can be
44 // used in C++.
45 # ifdef __cplusplus
46 #  if !defined(__STDC_LIMIT_MACROS)
47 #   define __STDC_LIMIT_MACROS
48 #   define __STDC_LIMIT_MACROS_DEFINED_BY_CLANG
49 #  endif
50 #  if !defined(__STDC_CONSTANT_MACROS)
51 #   define __STDC_CONSTANT_MACROS
52 #   define __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG
53 #  endif
54 # endif
55 
56 # include_next <stdint.h>
57 
58 # ifdef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG
59 #  undef __STDC_LIMIT_MACROS
60 #  undef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG
61 # endif
62 # ifdef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG
63 #  undef __STDC_CONSTANT_MACROS
64 #  undef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG
65 # endif
66 
67 #else
68 
69 /* C99 7.18.1.1 Exact-width integer types.
70  * C99 7.18.1.2 Minimum-width integer types.
71  * C99 7.18.1.3 Fastest minimum-width integer types.
72  *
73  * The standard requires that exact-width type be defined for 8-, 16-, 32-, and
74  * 64-bit types if they are implemented. Other exact width types are optional.
75  * This implementation defines an exact-width types for every integer width
76  * that is represented in the standard integer types.
77  *
78  * The standard also requires minimum-width types be defined for 8-, 16-, 32-,
79  * and 64-bit widths regardless of whether there are corresponding exact-width
80  * types.
81  *
82  * To accommodate targets that are missing types that are exactly 8, 16, 32, or
83  * 64 bits wide, this implementation takes an approach of cascading
84  * redefinitions, redefining __int_leastN_t to successively smaller exact-width
85  * types. It is therefore important that the types are defined in order of
86  * descending widths.
87  *
88  * We currently assume that the minimum-width types and the fastest
89  * minimum-width types are the same. This is allowed by the standard, but is
90  * suboptimal.
91  *
92  * In violation of the standard, some targets do not implement a type that is
93  * wide enough to represent all of the required widths (8-, 16-, 32-, 64-bit).
94  * To accommodate these targets, a required minimum-width type is only
95  * defined if there exists an exact-width type of equal or greater width.
96  */
97 
98 #ifdef __INT64_TYPE__
99 # ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/
100 typedef __INT64_TYPE__ int64_t;
101 # endif /* __int8_t_defined */
102 typedef __UINT64_TYPE__ uint64_t;
103 # undef __int_least64_t
104 # define __int_least64_t int64_t
105 # undef __uint_least64_t
106 # define __uint_least64_t uint64_t
107 # undef __int_least32_t
108 # define __int_least32_t int64_t
109 # undef __uint_least32_t
110 # define __uint_least32_t uint64_t
111 # undef __int_least16_t
112 # define __int_least16_t int64_t
113 # undef __uint_least16_t
114 # define __uint_least16_t uint64_t
115 # undef __int_least8_t
116 # define __int_least8_t int64_t
117 # undef __uint_least8_t
118 # define __uint_least8_t uint64_t
119 #endif /* __INT64_TYPE__ */
120 
121 #ifdef __int_least64_t
122 typedef __int_least64_t int_least64_t;
123 typedef __uint_least64_t uint_least64_t;
124 typedef __int_least64_t int_fast64_t;
125 typedef __uint_least64_t uint_fast64_t;
126 #endif /* __int_least64_t */
127 
128 #ifdef __INT56_TYPE__
129 typedef __INT56_TYPE__ int56_t;
130 typedef __UINT56_TYPE__ uint56_t;
131 typedef int56_t int_least56_t;
132 typedef uint56_t uint_least56_t;
133 typedef int56_t int_fast56_t;
134 typedef uint56_t uint_fast56_t;
135 # undef __int_least32_t
136 # define __int_least32_t int56_t
137 # undef __uint_least32_t
138 # define __uint_least32_t uint56_t
139 # undef __int_least16_t
140 # define __int_least16_t int56_t
141 # undef __uint_least16_t
142 # define __uint_least16_t uint56_t
143 # undef __int_least8_t
144 # define __int_least8_t int56_t
145 # undef __uint_least8_t
146 # define __uint_least8_t uint56_t
147 #endif /* __INT56_TYPE__ */
148 
149 
150 #ifdef __INT48_TYPE__
151 typedef __INT48_TYPE__ int48_t;
152 typedef __UINT48_TYPE__ uint48_t;
153 typedef int48_t int_least48_t;
154 typedef uint48_t uint_least48_t;
155 typedef int48_t int_fast48_t;
156 typedef uint48_t uint_fast48_t;
157 # undef __int_least32_t
158 # define __int_least32_t int48_t
159 # undef __uint_least32_t
160 # define __uint_least32_t uint48_t
161 # undef __int_least16_t
162 # define __int_least16_t int48_t
163 # undef __uint_least16_t
164 # define __uint_least16_t uint48_t
165 # undef __int_least8_t
166 # define __int_least8_t int48_t
167 # undef __uint_least8_t
168 # define __uint_least8_t uint48_t
169 #endif /* __INT48_TYPE__ */
170 
171 
172 #ifdef __INT40_TYPE__
173 typedef __INT40_TYPE__ int40_t;
174 typedef __UINT40_TYPE__ uint40_t;
175 typedef int40_t int_least40_t;
176 typedef uint40_t uint_least40_t;
177 typedef int40_t int_fast40_t;
178 typedef uint40_t uint_fast40_t;
179 # undef __int_least32_t
180 # define __int_least32_t int40_t
181 # undef __uint_least32_t
182 # define __uint_least32_t uint40_t
183 # undef __int_least16_t
184 # define __int_least16_t int40_t
185 # undef __uint_least16_t
186 # define __uint_least16_t uint40_t
187 # undef __int_least8_t
188 # define __int_least8_t int40_t
189 # undef __uint_least8_t
190 # define __uint_least8_t uint40_t
191 #endif /* __INT40_TYPE__ */
192 
193 
194 #ifdef __INT32_TYPE__
195 
196 # ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/
197 typedef __INT32_TYPE__ int32_t;
198 # endif /* __int8_t_defined */
199 
200 # ifndef __uint32_t_defined  /* more glibc compatibility */
201 # define __uint32_t_defined
202 typedef __UINT32_TYPE__ uint32_t;
203 # endif /* __uint32_t_defined */
204 
205 # undef __int_least32_t
206 # define __int_least32_t int32_t
207 # undef __uint_least32_t
208 # define __uint_least32_t uint32_t
209 # undef __int_least16_t
210 # define __int_least16_t int32_t
211 # undef __uint_least16_t
212 # define __uint_least16_t uint32_t
213 # undef __int_least8_t
214 # define __int_least8_t int32_t
215 # undef __uint_least8_t
216 # define __uint_least8_t uint32_t
217 #endif /* __INT32_TYPE__ */
218 
219 #ifdef __int_least32_t
220 typedef __int_least32_t int_least32_t;
221 typedef __uint_least32_t uint_least32_t;
222 typedef __int_least32_t int_fast32_t;
223 typedef __uint_least32_t uint_fast32_t;
224 #endif /* __int_least32_t */
225 
226 #ifdef __INT24_TYPE__
227 typedef __INT24_TYPE__ int24_t;
228 typedef __UINT24_TYPE__ uint24_t;
229 typedef int24_t int_least24_t;
230 typedef uint24_t uint_least24_t;
231 typedef int24_t int_fast24_t;
232 typedef uint24_t uint_fast24_t;
233 # undef __int_least16_t
234 # define __int_least16_t int24_t
235 # undef __uint_least16_t
236 # define __uint_least16_t uint24_t
237 # undef __int_least8_t
238 # define __int_least8_t int24_t
239 # undef __uint_least8_t
240 # define __uint_least8_t uint24_t
241 #endif /* __INT24_TYPE__ */
242 
243 #ifdef __INT16_TYPE__
244 #ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/
245 typedef __INT16_TYPE__ int16_t;
246 #endif /* __int8_t_defined */
247 typedef __UINT16_TYPE__ uint16_t;
248 # undef __int_least16_t
249 # define __int_least16_t int16_t
250 # undef __uint_least16_t
251 # define __uint_least16_t uint16_t
252 # undef __int_least8_t
253 # define __int_least8_t int16_t
254 # undef __uint_least8_t
255 # define __uint_least8_t uint16_t
256 #endif /* __INT16_TYPE__ */
257 
258 #ifdef __int_least16_t
259 typedef __int_least16_t int_least16_t;
260 typedef __uint_least16_t uint_least16_t;
261 typedef __int_least16_t int_fast16_t;
262 typedef __uint_least16_t uint_fast16_t;
263 #endif /* __int_least16_t */
264 
265 
266 #ifdef __INT8_TYPE__
267 #ifndef __int8_t_defined  /* glibc sys/types.h also defines int8_t*/
268 typedef __INT8_TYPE__ int8_t;
269 #endif /* __int8_t_defined */
270 typedef __UINT8_TYPE__ uint8_t;
271 # undef __int_least8_t
272 # define __int_least8_t int8_t
273 # undef __uint_least8_t
274 # define __uint_least8_t uint8_t
275 #endif /* __INT8_TYPE__ */
276 
277 #ifdef __int_least8_t
278 typedef __int_least8_t int_least8_t;
279 typedef __uint_least8_t uint_least8_t;
280 typedef __int_least8_t int_fast8_t;
281 typedef __uint_least8_t uint_fast8_t;
282 #endif /* __int_least8_t */
283 
284 /* prevent glibc sys/types.h from defining conflicting types */
285 #ifndef __int8_t_defined
286 # define __int8_t_defined
287 #endif /* __int8_t_defined */
288 
289 /* C99 7.18.1.4 Integer types capable of holding object pointers.
290  */
291 #define __stdint_join3(a,b,c) a ## b ## c
292 
293 #ifndef _INTPTR_T
294 #ifndef __intptr_t_defined
295 typedef __INTPTR_TYPE__ intptr_t;
296 #define __intptr_t_defined
297 #define _INTPTR_T
298 #endif
299 #endif
300 
301 #ifndef _UINTPTR_T
302 typedef __UINTPTR_TYPE__ uintptr_t;
303 #define _UINTPTR_T
304 #endif
305 
306 /* C99 7.18.1.5 Greatest-width integer types.
307  */
308 typedef __INTMAX_TYPE__  intmax_t;
309 typedef __UINTMAX_TYPE__ uintmax_t;
310 
311 /* C99 7.18.4 Macros for minimum-width integer constants.
312  *
313  * The standard requires that integer constant macros be defined for all the
314  * minimum-width types defined above. As 8-, 16-, 32-, and 64-bit minimum-width
315  * types are required, the corresponding integer constant macros are defined
316  * here. This implementation also defines minimum-width types for every other
317  * integer width that the target implements, so corresponding macros are
318  * defined below, too.
319  *
320  * These macros are defined using the same successive-shrinking approach as
321  * the type definitions above. It is likewise important that macros are defined
322  * in order of decending width.
323  *
324  * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the
325  * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
326  */
327 
328 #define __int_c_join(a, b) a ## b
329 #define __int_c(v, suffix) __int_c_join(v, suffix)
330 #define __uint_c(v, suffix) __int_c_join(v##U, suffix)
331 
332 
333 #ifdef __INT64_TYPE__
334 # undef __int64_c_suffix
335 # undef __int32_c_suffix
336 # undef __int16_c_suffix
337 # undef  __int8_c_suffix
338 # ifdef __INT64_C_SUFFIX__
339 #  define __int64_c_suffix __INT64_C_SUFFIX__
340 #  define __int32_c_suffix __INT64_C_SUFFIX__
341 #  define __int16_c_suffix __INT64_C_SUFFIX__
342 #  define  __int8_c_suffix __INT64_C_SUFFIX__
343 # endif /* __INT64_C_SUFFIX__ */
344 #endif /* __INT64_TYPE__ */
345 
346 #ifdef __int_least64_t
347 # ifdef __int64_c_suffix
348 #  define INT64_C(v) __int_c(v, __int64_c_suffix)
349 #  define UINT64_C(v) __uint_c(v, __int64_c_suffix)
350 # else
351 #  define INT64_C(v) v
352 #  define UINT64_C(v) v ## U
353 # endif /* __int64_c_suffix */
354 #endif /* __int_least64_t */
355 
356 
357 #ifdef __INT56_TYPE__
358 # undef __int32_c_suffix
359 # undef __int16_c_suffix
360 # undef  __int8_c_suffix
361 # ifdef __INT56_C_SUFFIX__
362 #  define INT56_C(v) __int_c(v, __INT56_C_SUFFIX__)
363 #  define UINT56_C(v) __uint_c(v, __INT56_C_SUFFIX__)
364 #  define __int32_c_suffix __INT56_C_SUFFIX__
365 #  define __int16_c_suffix __INT56_C_SUFFIX__
366 #  define __int8_c_suffix  __INT56_C_SUFFIX__
367 # else
368 #  define INT56_C(v) v
369 #  define UINT56_C(v) v ## U
370 # endif /* __INT56_C_SUFFIX__ */
371 #endif /* __INT56_TYPE__ */
372 
373 
374 #ifdef __INT48_TYPE__
375 # undef __int32_c_suffix
376 # undef __int16_c_suffix
377 # undef  __int8_c_suffix
378 # ifdef __INT48_C_SUFFIX__
379 #  define INT48_C(v) __int_c(v, __INT48_C_SUFFIX__)
380 #  define UINT48_C(v) __uint_c(v, __INT48_C_SUFFIX__)
381 #  define __int32_c_suffix __INT48_C_SUFFIX__
382 #  define __int16_c_suffix __INT48_C_SUFFIX__
383 #  define __int8_c_suffix  __INT48_C_SUFFIX__
384 # else
385 #  define INT48_C(v) v
386 #  define UINT48_C(v) v ## U
387 # endif /* __INT48_C_SUFFIX__ */
388 #endif /* __INT48_TYPE__ */
389 
390 
391 #ifdef __INT40_TYPE__
392 # undef __int32_c_suffix
393 # undef __int16_c_suffix
394 # undef  __int8_c_suffix
395 # ifdef __INT40_C_SUFFIX__
396 #  define INT40_C(v) __int_c(v, __INT40_C_SUFFIX__)
397 #  define UINT40_C(v) __uint_c(v, __INT40_C_SUFFIX__)
398 #  define __int32_c_suffix __INT40_C_SUFFIX__
399 #  define __int16_c_suffix __INT40_C_SUFFIX__
400 #  define __int8_c_suffix  __INT40_C_SUFFIX__
401 # else
402 #  define INT40_C(v) v
403 #  define UINT40_C(v) v ## U
404 # endif /* __INT40_C_SUFFIX__ */
405 #endif /* __INT40_TYPE__ */
406 
407 
408 #ifdef __INT32_TYPE__
409 # undef __int32_c_suffix
410 # undef __int16_c_suffix
411 # undef  __int8_c_suffix
412 # ifdef __INT32_C_SUFFIX__
413 #  define __int32_c_suffix __INT32_C_SUFFIX__
414 #  define __int16_c_suffix __INT32_C_SUFFIX__
415 #  define __int8_c_suffix  __INT32_C_SUFFIX__
416 # endif /* __INT32_C_SUFFIX__ */
417 #endif /* __INT32_TYPE__ */
418 
419 #ifdef __int_least32_t
420 # ifdef __int32_c_suffix
421 #  define INT32_C(v) __int_c(v, __int32_c_suffix)
422 #  define UINT32_C(v) __uint_c(v, __int32_c_suffix)
423 # else
424 #  define INT32_C(v) v
425 #  define UINT32_C(v) v ## U
426 # endif /* __int32_c_suffix */
427 #endif /* __int_least32_t */
428 
429 
430 #ifdef __INT24_TYPE__
431 # undef __int16_c_suffix
432 # undef  __int8_c_suffix
433 # ifdef __INT24_C_SUFFIX__
434 #  define INT24_C(v) __int_c(v, __INT24_C_SUFFIX__)
435 #  define UINT24_C(v) __uint_c(v, __INT24_C_SUFFIX__)
436 #  define __int16_c_suffix __INT24_C_SUFFIX__
437 #  define __int8_c_suffix  __INT24_C_SUFFIX__
438 # else
439 #  define INT24_C(v) v
440 #  define UINT24_C(v) v ## U
441 # endif /* __INT24_C_SUFFIX__ */
442 #endif /* __INT24_TYPE__ */
443 
444 
445 #ifdef __INT16_TYPE__
446 # undef __int16_c_suffix
447 # undef  __int8_c_suffix
448 # ifdef __INT16_C_SUFFIX__
449 #  define __int16_c_suffix __INT16_C_SUFFIX__
450 #  define __int8_c_suffix  __INT16_C_SUFFIX__
451 # endif /* __INT16_C_SUFFIX__ */
452 #endif /* __INT16_TYPE__ */
453 
454 #ifdef __int_least16_t
455 # ifdef __int16_c_suffix
456 #  define INT16_C(v) __int_c(v, __int16_c_suffix)
457 #  define UINT16_C(v) __uint_c(v, __int16_c_suffix)
458 # else
459 #  define INT16_C(v) v
460 #  define UINT16_C(v) v ## U
461 # endif /* __int16_c_suffix */
462 #endif /* __int_least16_t */
463 
464 
465 #ifdef __INT8_TYPE__
466 # undef  __int8_c_suffix
467 # ifdef __INT8_C_SUFFIX__
468 #  define __int8_c_suffix __INT8_C_SUFFIX__
469 # endif /* __INT8_C_SUFFIX__ */
470 #endif /* __INT8_TYPE__ */
471 
472 #ifdef __int_least8_t
473 # ifdef __int8_c_suffix
474 #  define INT8_C(v) __int_c(v, __int8_c_suffix)
475 #  define UINT8_C(v) __uint_c(v, __int8_c_suffix)
476 # else
477 #  define INT8_C(v) v
478 #  define UINT8_C(v) v ## U
479 # endif /* __int8_c_suffix */
480 #endif /* __int_least8_t */
481 
482 
483 /* C99 7.18.2.1 Limits of exact-width integer types.
484  * C99 7.18.2.2 Limits of minimum-width integer types.
485  * C99 7.18.2.3 Limits of fastest minimum-width integer types.
486  *
487  * The presence of limit macros are completely optional in C99.  This
488  * implementation defines limits for all of the types (exact- and
489  * minimum-width) that it defines above, using the limits of the minimum-width
490  * type for any types that do not have exact-width representations.
491  *
492  * As in the type definitions, this section takes an approach of
493  * successive-shrinking to determine which limits to use for the standard (8,
494  * 16, 32, 64) bit widths when they don't have exact representations. It is
495  * therefore important that the definitions be kept in order of decending
496  * widths.
497  *
498  * Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the
499  * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
500  */
501 
502 #ifdef __INT64_TYPE__
503 # define INT64_MAX           INT64_C( 9223372036854775807)
504 # define INT64_MIN         (-INT64_C( 9223372036854775807)-1)
505 # define UINT64_MAX         UINT64_C(18446744073709551615)
506 
507 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
508 # define UINT64_WIDTH         64
509 # define INT64_WIDTH          UINT64_WIDTH
510 
511 # define __UINT_LEAST64_WIDTH UINT64_WIDTH
512 # undef __UINT_LEAST32_WIDTH
513 # define __UINT_LEAST32_WIDTH UINT64_WIDTH
514 # undef __UINT_LEAST16_WIDTH
515 # define __UINT_LEAST16_WIDTH UINT64_WIDTH
516 # undef __UINT_LEAST8_MAX
517 # define __UINT_LEAST8_MAX UINT64_MAX
518 #endif /* __STDC_VERSION__ */
519 
520 # define __INT_LEAST64_MIN   INT64_MIN
521 # define __INT_LEAST64_MAX   INT64_MAX
522 # define __UINT_LEAST64_MAX UINT64_MAX
523 # undef __INT_LEAST32_MIN
524 # define __INT_LEAST32_MIN   INT64_MIN
525 # undef __INT_LEAST32_MAX
526 # define __INT_LEAST32_MAX   INT64_MAX
527 # undef __UINT_LEAST32_MAX
528 # define __UINT_LEAST32_MAX UINT64_MAX
529 # undef __INT_LEAST16_MIN
530 # define __INT_LEAST16_MIN   INT64_MIN
531 # undef __INT_LEAST16_MAX
532 # define __INT_LEAST16_MAX   INT64_MAX
533 # undef __UINT_LEAST16_MAX
534 # define __UINT_LEAST16_MAX UINT64_MAX
535 # undef __INT_LEAST8_MIN
536 # define __INT_LEAST8_MIN    INT64_MIN
537 # undef __INT_LEAST8_MAX
538 # define __INT_LEAST8_MAX    INT64_MAX
539 # undef __UINT_LEAST8_MAX
540 # define __UINT_LEAST8_MAX  UINT64_MAX
541 #endif /* __INT64_TYPE__ */
542 
543 #ifdef __INT_LEAST64_MIN
544 # define INT_LEAST64_MIN   __INT_LEAST64_MIN
545 # define INT_LEAST64_MAX   __INT_LEAST64_MAX
546 # define UINT_LEAST64_MAX __UINT_LEAST64_MAX
547 # define INT_FAST64_MIN    __INT_LEAST64_MIN
548 # define INT_FAST64_MAX    __INT_LEAST64_MAX
549 # define UINT_FAST64_MAX  __UINT_LEAST64_MAX
550 
551 #if defined(__STDC_VERSION__) &&  __STDC_VERSION__ >= 202311L
552 # define UINT_LEAST64_WIDTH __UINT_LEAST64_WIDTH
553 # define INT_LEAST64_WIDTH  UINT_LEAST64_WIDTH
554 # define UINT_FAST64_WIDTH  __UINT_LEAST64_WIDTH
555 # define INT_FAST64_WIDTH   UINT_FAST64_WIDTH
556 #endif /* __STDC_VERSION__ */
557 #endif /* __INT_LEAST64_MIN */
558 
559 
560 #ifdef __INT56_TYPE__
561 # define INT56_MAX           INT56_C(36028797018963967)
562 # define INT56_MIN         (-INT56_C(36028797018963967)-1)
563 # define UINT56_MAX         UINT56_C(72057594037927935)
564 # define INT_LEAST56_MIN     INT56_MIN
565 # define INT_LEAST56_MAX     INT56_MAX
566 # define UINT_LEAST56_MAX   UINT56_MAX
567 # define INT_FAST56_MIN      INT56_MIN
568 # define INT_FAST56_MAX      INT56_MAX
569 # define UINT_FAST56_MAX    UINT56_MAX
570 
571 # undef __INT_LEAST32_MIN
572 # define __INT_LEAST32_MIN   INT56_MIN
573 # undef __INT_LEAST32_MAX
574 # define __INT_LEAST32_MAX   INT56_MAX
575 # undef __UINT_LEAST32_MAX
576 # define __UINT_LEAST32_MAX UINT56_MAX
577 # undef __INT_LEAST16_MIN
578 # define __INT_LEAST16_MIN   INT56_MIN
579 # undef __INT_LEAST16_MAX
580 # define __INT_LEAST16_MAX   INT56_MAX
581 # undef __UINT_LEAST16_MAX
582 # define __UINT_LEAST16_MAX UINT56_MAX
583 # undef __INT_LEAST8_MIN
584 # define __INT_LEAST8_MIN    INT56_MIN
585 # undef __INT_LEAST8_MAX
586 # define __INT_LEAST8_MAX    INT56_MAX
587 # undef __UINT_LEAST8_MAX
588 # define __UINT_LEAST8_MAX  UINT56_MAX
589 
590 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
591 # define UINT56_WIDTH         56
592 # define INT56_WIDTH          UINT56_WIDTH
593 # define UINT_LEAST56_WIDTH   UINT56_WIDTH
594 # define INT_LEAST56_WIDTH    UINT_LEAST56_WIDTH
595 # define UINT_FAST56_WIDTH    UINT56_WIDTH
596 # define INT_FAST56_WIDTH     UINT_FAST56_WIDTH
597 # undef __UINT_LEAST32_WIDTH
598 # define __UINT_LEAST32_WIDTH UINT56_WIDTH
599 # undef __UINT_LEAST16_WIDTH
600 # define __UINT_LEAST16_WIDTH UINT56_WIDTH
601 # undef __UINT_LEAST8_WIDTH
602 # define __UINT_LEAST8_WIDTH  UINT56_WIDTH
603 #endif /* __STDC_VERSION__ */
604 #endif /* __INT56_TYPE__ */
605 
606 
607 #ifdef __INT48_TYPE__
608 # define INT48_MAX           INT48_C(140737488355327)
609 # define INT48_MIN         (-INT48_C(140737488355327)-1)
610 # define UINT48_MAX         UINT48_C(281474976710655)
611 # define INT_LEAST48_MIN     INT48_MIN
612 # define INT_LEAST48_MAX     INT48_MAX
613 # define UINT_LEAST48_MAX   UINT48_MAX
614 # define INT_FAST48_MIN      INT48_MIN
615 # define INT_FAST48_MAX      INT48_MAX
616 # define UINT_FAST48_MAX    UINT48_MAX
617 
618 # undef __INT_LEAST32_MIN
619 # define __INT_LEAST32_MIN   INT48_MIN
620 # undef __INT_LEAST32_MAX
621 # define __INT_LEAST32_MAX   INT48_MAX
622 # undef __UINT_LEAST32_MAX
623 # define __UINT_LEAST32_MAX UINT48_MAX
624 # undef __INT_LEAST16_MIN
625 # define __INT_LEAST16_MIN   INT48_MIN
626 # undef __INT_LEAST16_MAX
627 # define __INT_LEAST16_MAX   INT48_MAX
628 # undef __UINT_LEAST16_MAX
629 # define __UINT_LEAST16_MAX UINT48_MAX
630 # undef __INT_LEAST8_MIN
631 # define __INT_LEAST8_MIN    INT48_MIN
632 # undef __INT_LEAST8_MAX
633 # define __INT_LEAST8_MAX    INT48_MAX
634 # undef __UINT_LEAST8_MAX
635 # define __UINT_LEAST8_MAX  UINT48_MAX
636 
637 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
638 #define UINT48_WIDTH         48
639 #define INT48_WIDTH          UINT48_WIDTH
640 #define UINT_LEAST48_WIDTH   UINT48_WIDTH
641 #define INT_LEAST48_WIDTH    UINT_LEAST48_WIDTH
642 #define UINT_FAST48_WIDTH    UINT48_WIDTH
643 #define INT_FAST48_WIDTH     UINT_FAST48_WIDTH
644 #undef __UINT_LEAST32_WIDTH
645 #define __UINT_LEAST32_WIDTH UINT48_WIDTH
646 # undef __UINT_LEAST16_WIDTH
647 #define __UINT_LEAST16_WIDTH UINT48_WIDTH
648 # undef __UINT_LEAST8_WIDTH
649 #define __UINT_LEAST8_WIDTH  UINT48_WIDTH
650 #endif /* __STDC_VERSION__ */
651 #endif /* __INT48_TYPE__ */
652 
653 
654 #ifdef __INT40_TYPE__
655 # define INT40_MAX           INT40_C(549755813887)
656 # define INT40_MIN         (-INT40_C(549755813887)-1)
657 # define UINT40_MAX         UINT40_C(1099511627775)
658 # define INT_LEAST40_MIN     INT40_MIN
659 # define INT_LEAST40_MAX     INT40_MAX
660 # define UINT_LEAST40_MAX   UINT40_MAX
661 # define INT_FAST40_MIN      INT40_MIN
662 # define INT_FAST40_MAX      INT40_MAX
663 # define UINT_FAST40_MAX    UINT40_MAX
664 
665 # undef __INT_LEAST32_MIN
666 # define __INT_LEAST32_MIN   INT40_MIN
667 # undef __INT_LEAST32_MAX
668 # define __INT_LEAST32_MAX   INT40_MAX
669 # undef __UINT_LEAST32_MAX
670 # define __UINT_LEAST32_MAX UINT40_MAX
671 # undef __INT_LEAST16_MIN
672 # define __INT_LEAST16_MIN   INT40_MIN
673 # undef __INT_LEAST16_MAX
674 # define __INT_LEAST16_MAX   INT40_MAX
675 # undef __UINT_LEAST16_MAX
676 # define __UINT_LEAST16_MAX UINT40_MAX
677 # undef __INT_LEAST8_MIN
678 # define __INT_LEAST8_MIN    INT40_MIN
679 # undef __INT_LEAST8_MAX
680 # define __INT_LEAST8_MAX    INT40_MAX
681 # undef __UINT_LEAST8_MAX
682 # define __UINT_LEAST8_MAX  UINT40_MAX
683 
684 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
685 # define UINT40_WIDTH         40
686 # define INT40_WIDTH          UINT40_WIDTH
687 # define UINT_LEAST40_WIDTH   UINT40_WIDTH
688 # define INT_LEAST40_WIDTH    UINT_LEAST40_WIDTH
689 # define UINT_FAST40_WIDTH    UINT40_WIDTH
690 # define INT_FAST40_WIDTH     UINT_FAST40_WIDTH
691 # undef __UINT_LEAST32_WIDTH
692 # define __UINT_LEAST32_WIDTH UINT40_WIDTH
693 # undef __UINT_LEAST16_WIDTH
694 # define __UINT_LEAST16_WIDTH UINT40_WIDTH
695 # undef __UINT_LEAST8_WIDTH
696 # define __UINT_LEAST8_WIDTH  UINT40_WIDTH
697 #endif /* __STDC_VERSION__ */
698 #endif /* __INT40_TYPE__ */
699 
700 
701 #ifdef __INT32_TYPE__
702 # define INT32_MAX           INT32_C(2147483647)
703 # define INT32_MIN         (-INT32_C(2147483647)-1)
704 # define UINT32_MAX         UINT32_C(4294967295)
705 
706 # undef __INT_LEAST32_MIN
707 # define __INT_LEAST32_MIN   INT32_MIN
708 # undef __INT_LEAST32_MAX
709 # define __INT_LEAST32_MAX   INT32_MAX
710 # undef __UINT_LEAST32_MAX
711 # define __UINT_LEAST32_MAX UINT32_MAX
712 # undef __INT_LEAST16_MIN
713 # define __INT_LEAST16_MIN   INT32_MIN
714 # undef __INT_LEAST16_MAX
715 # define __INT_LEAST16_MAX   INT32_MAX
716 # undef __UINT_LEAST16_MAX
717 # define __UINT_LEAST16_MAX UINT32_MAX
718 # undef __INT_LEAST8_MIN
719 # define __INT_LEAST8_MIN    INT32_MIN
720 # undef __INT_LEAST8_MAX
721 # define __INT_LEAST8_MAX    INT32_MAX
722 # undef __UINT_LEAST8_MAX
723 # define __UINT_LEAST8_MAX  UINT32_MAX
724 
725 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
726 # define UINT32_WIDTH         32
727 # define INT32_WIDTH          UINT32_WIDTH
728 # undef __UINT_LEAST32_WIDTH
729 # define __UINT_LEAST32_WIDTH UINT32_WIDTH
730 # undef __UINT_LEAST16_WIDTH
731 # define __UINT_LEAST16_WIDTH UINT32_WIDTH
732 # undef __UINT_LEAST8_WIDTH
733 # define __UINT_LEAST8_WIDTH  UINT32_WIDTH
734 #endif /* __STDC_VERSION__ */
735 #endif /* __INT32_TYPE__ */
736 
737 #ifdef __INT_LEAST32_MIN
738 # define INT_LEAST32_MIN   __INT_LEAST32_MIN
739 # define INT_LEAST32_MAX   __INT_LEAST32_MAX
740 # define UINT_LEAST32_MAX __UINT_LEAST32_MAX
741 # define INT_FAST32_MIN    __INT_LEAST32_MIN
742 # define INT_FAST32_MAX    __INT_LEAST32_MAX
743 # define UINT_FAST32_MAX  __UINT_LEAST32_MAX
744 
745 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
746 # define UINT_LEAST32_WIDTH __UINT_LEAST32_WIDTH
747 # define INT_LEAST32_WIDTH  UINT_LEAST32_WIDTH
748 # define UINT_FAST32_WIDTH  __UINT_LEAST32_WIDTH
749 # define INT_FAST32_WIDTH   UINT_FAST32_WIDTH
750 #endif /* __STDC_VERSION__ */
751 #endif /* __INT_LEAST32_MIN */
752 
753 
754 #ifdef __INT24_TYPE__
755 # define INT24_MAX           INT24_C(8388607)
756 # define INT24_MIN         (-INT24_C(8388607)-1)
757 # define UINT24_MAX         UINT24_C(16777215)
758 # define INT_LEAST24_MIN     INT24_MIN
759 # define INT_LEAST24_MAX     INT24_MAX
760 # define UINT_LEAST24_MAX   UINT24_MAX
761 # define INT_FAST24_MIN      INT24_MIN
762 # define INT_FAST24_MAX      INT24_MAX
763 # define UINT_FAST24_MAX    UINT24_MAX
764 
765 # undef __INT_LEAST16_MIN
766 # define __INT_LEAST16_MIN   INT24_MIN
767 # undef __INT_LEAST16_MAX
768 # define __INT_LEAST16_MAX   INT24_MAX
769 # undef __UINT_LEAST16_MAX
770 # define __UINT_LEAST16_MAX UINT24_MAX
771 # undef __INT_LEAST8_MIN
772 # define __INT_LEAST8_MIN    INT24_MIN
773 # undef __INT_LEAST8_MAX
774 # define __INT_LEAST8_MAX    INT24_MAX
775 # undef __UINT_LEAST8_MAX
776 # define __UINT_LEAST8_MAX  UINT24_MAX
777 
778 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
779 # define UINT24_WIDTH         24
780 # define INT24_WIDTH          UINT24_WIDTH
781 # define UINT_LEAST24_WIDTH   UINT24_WIDTH
782 # define INT_LEAST24_WIDTH    UINT_LEAST24_WIDTH
783 # define UINT_FAST24_WIDTH    UINT24_WIDTH
784 # define INT_FAST24_WIDTH     UINT_FAST24_WIDTH
785 # undef __UINT_LEAST16_WIDTH
786 # define __UINT_LEAST16_WIDTH UINT24_WIDTH
787 # undef __UINT_LEAST8_WIDTH
788 # define __UINT_LEAST8_WIDTH  UINT24_WIDTH
789 #endif /* __STDC_VERSION__ */
790 #endif /* __INT24_TYPE__ */
791 
792 
793 #ifdef __INT16_TYPE__
794 #define INT16_MAX            INT16_C(32767)
795 #define INT16_MIN          (-INT16_C(32767)-1)
796 #define UINT16_MAX          UINT16_C(65535)
797 
798 # undef __INT_LEAST16_MIN
799 # define __INT_LEAST16_MIN   INT16_MIN
800 # undef __INT_LEAST16_MAX
801 # define __INT_LEAST16_MAX   INT16_MAX
802 # undef __UINT_LEAST16_MAX
803 # define __UINT_LEAST16_MAX UINT16_MAX
804 # undef __INT_LEAST8_MIN
805 # define __INT_LEAST8_MIN    INT16_MIN
806 # undef __INT_LEAST8_MAX
807 # define __INT_LEAST8_MAX    INT16_MAX
808 # undef __UINT_LEAST8_MAX
809 # define __UINT_LEAST8_MAX  UINT16_MAX
810 
811 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
812 # define UINT16_WIDTH         16
813 # define INT16_WIDTH          UINT16_WIDTH
814 # undef __UINT_LEAST16_WIDTH
815 # define __UINT_LEAST16_WIDTH UINT16_WIDTH
816 # undef __UINT_LEAST8_WIDTH
817 # define __UINT_LEAST8_WIDTH  UINT16_WIDTH
818 #endif /* __STDC_VERSION__ */
819 #endif /* __INT16_TYPE__ */
820 
821 #ifdef __INT_LEAST16_MIN
822 # define INT_LEAST16_MIN   __INT_LEAST16_MIN
823 # define INT_LEAST16_MAX   __INT_LEAST16_MAX
824 # define UINT_LEAST16_MAX __UINT_LEAST16_MAX
825 # define INT_FAST16_MIN    __INT_LEAST16_MIN
826 # define INT_FAST16_MAX    __INT_LEAST16_MAX
827 # define UINT_FAST16_MAX  __UINT_LEAST16_MAX
828 
829 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
830 # define UINT_LEAST16_WIDTH __UINT_LEAST16_WIDTH
831 # define INT_LEAST16_WIDTH  UINT_LEAST16_WIDTH
832 # define UINT_FAST16_WIDTH  __UINT_LEAST16_WIDTH
833 # define INT_FAST16_WIDTH   UINT_FAST16_WIDTH
834 #endif /* __STDC_VERSION__ */
835 #endif /* __INT_LEAST16_MIN */
836 
837 
838 #ifdef __INT8_TYPE__
839 # define INT8_MAX            INT8_C(127)
840 # define INT8_MIN          (-INT8_C(127)-1)
841 # define UINT8_MAX          UINT8_C(255)
842 
843 # undef __INT_LEAST8_MIN
844 # define __INT_LEAST8_MIN    INT8_MIN
845 # undef __INT_LEAST8_MAX
846 # define __INT_LEAST8_MAX    INT8_MAX
847 # undef __UINT_LEAST8_MAX
848 # define __UINT_LEAST8_MAX  UINT8_MAX
849 
850 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
851 # define UINT8_WIDTH         8
852 # define INT8_WIDTH          UINT8_WIDTH
853 # undef __UINT_LEAST8_WIDTH
854 # define __UINT_LEAST8_WIDTH UINT8_WIDTH
855 #endif /* __STDC_VERSION__ */
856 #endif /* __INT8_TYPE__ */
857 
858 #ifdef __INT_LEAST8_MIN
859 # define INT_LEAST8_MIN   __INT_LEAST8_MIN
860 # define INT_LEAST8_MAX   __INT_LEAST8_MAX
861 # define UINT_LEAST8_MAX __UINT_LEAST8_MAX
862 # define INT_FAST8_MIN    __INT_LEAST8_MIN
863 # define INT_FAST8_MAX    __INT_LEAST8_MAX
864 # define UINT_FAST8_MAX  __UINT_LEAST8_MAX
865 
866 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
867 # define UINT_LEAST8_WIDTH __UINT_LEAST8_WIDTH
868 # define INT_LEAST8_WIDTH  UINT_LEAST8_WIDTH
869 # define UINT_FAST8_WIDTH  __UINT_LEAST8_WIDTH
870 # define INT_FAST8_WIDTH   UINT_FAST8_WIDTH
871 #endif /* __STDC_VERSION__ */
872 #endif /* __INT_LEAST8_MIN */
873 
874 /* Some utility macros */
875 #define  __INTN_MIN(n)  __stdint_join3( INT, n, _MIN)
876 #define  __INTN_MAX(n)  __stdint_join3( INT, n, _MAX)
877 #define __UINTN_MAX(n)  __stdint_join3(UINT, n, _MAX)
878 #define  __INTN_C(n, v) __stdint_join3( INT, n, _C(v))
879 #define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v))
880 
881 /* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */
882 /* C99 7.18.3 Limits of other integer types. */
883 
884 #define  INTPTR_MIN  (-__INTPTR_MAX__-1)
885 #define  INTPTR_MAX    __INTPTR_MAX__
886 #define UINTPTR_MAX   __UINTPTR_MAX__
887 #define PTRDIFF_MIN (-__PTRDIFF_MAX__-1)
888 #define PTRDIFF_MAX   __PTRDIFF_MAX__
889 #define    SIZE_MAX      __SIZE_MAX__
890 
891 /* C23 7.22.2.4 Width of integer types capable of holding object pointers. */
892 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
893 /* NB: The C standard requires that these be the same value, but the compiler
894    exposes separate internal width macros. */
895 #define INTPTR_WIDTH  __INTPTR_WIDTH__
896 #define UINTPTR_WIDTH __UINTPTR_WIDTH__
897 #endif
898 
899 /* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__
900  * is enabled. */
901 #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
902 #define   RSIZE_MAX            (SIZE_MAX >> 1)
903 #endif
904 
905 /* C99 7.18.2.5 Limits of greatest-width integer types. */
906 #define  INTMAX_MIN (-__INTMAX_MAX__-1)
907 #define  INTMAX_MAX   __INTMAX_MAX__
908 #define UINTMAX_MAX  __UINTMAX_MAX__
909 
910 /* C23 7.22.2.5 Width of greatest-width integer types. */
911 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
912 /* NB: The C standard requires that these be the same value, but the compiler
913    exposes separate internal width macros. */
914 #define INTMAX_WIDTH __INTMAX_WIDTH__
915 #define UINTMAX_WIDTH __UINTMAX_WIDTH__
916 #endif
917 
918 /* C99 7.18.3 Limits of other integer types. */
919 #define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__)
920 #define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__)
921 #ifdef __WINT_UNSIGNED__
922 # define WINT_MIN       __UINTN_C(__WINT_WIDTH__, 0)
923 # define WINT_MAX       __UINTN_MAX(__WINT_WIDTH__)
924 #else
925 # define WINT_MIN       __INTN_MIN(__WINT_WIDTH__)
926 # define WINT_MAX       __INTN_MAX(__WINT_WIDTH__)
927 #endif
928 
929 #ifndef WCHAR_MAX
930 # define WCHAR_MAX __WCHAR_MAX__
931 #endif
932 #ifndef WCHAR_MIN
933 # if __WCHAR_MAX__ == __INTN_MAX(__WCHAR_WIDTH__)
934 #  define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__)
935 # else
936 #  define WCHAR_MIN __UINTN_C(__WCHAR_WIDTH__, 0)
937 # endif
938 #endif
939 
940 /* 7.18.4.2 Macros for greatest-width integer constants. */
941 #define  INTMAX_C(v) __int_c(v,  __INTMAX_C_SUFFIX__)
942 #define UINTMAX_C(v) __int_c(v, __UINTMAX_C_SUFFIX__)
943 
944 /* C23 7.22.3.x Width of other integer types. */
945 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
946 #define PTRDIFF_WIDTH    __PTRDIFF_WIDTH__
947 #define SIG_ATOMIC_WIDTH __SIG_ATOMIC_WIDTH__
948 #define SIZE_WIDTH       __SIZE_WIDTH__
949 #define WCHAR_WIDTH      __WCHAR_WIDTH__
950 #define WINT_WIDTH       __WINT_WIDTH__
951 #endif
952 
953 #endif /* __STDC_HOSTED__ */
954 #endif /* __MVS__ */
955 #endif /* __CLANG_STDINT_H */
956