1 /*===---- stdint.h - Standard header for sized integer types --------------===*\
2  *
3  * Copyright (c) 2009 Chris Lattner
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE.
22  *
23 \*===----------------------------------------------------------------------===*/
24 
25 #ifndef __CLANG_STDINT_H
26 #define __CLANG_STDINT_H
27 
28 /* If we're hosted, fall back to the system's stdint.h, which might have
29  * additional definitions.
30  */
31 #if __STDC_HOSTED__ && \
32     defined(__has_include_next) && __has_include_next(<stdint.h>)
33 
34 // C99 7.18.3 Limits of other integer types
35 //
36 //  Footnote 219, 220: C++ implementations should define these macros only when
37 //  __STDC_LIMIT_MACROS is defined before <stdint.h> is included.
38 //
39 //  Footnote 222: C++ implementations should define these macros only when
40 //  __STDC_CONSTANT_MACROS is defined before <stdint.h> is included.
41 //
42 // C++11 [cstdint.syn]p2:
43 //
44 //  The macros defined by <cstdint> are provided unconditionally. In particular,
45 //  the symbols __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS (mentioned in
46 //  footnotes 219, 220, and 222 in the C standard) play no role in C++.
47 //
48 // C11 removed the problematic footnotes.
49 //
50 // Work around this inconsistency by always defining those macros in C++ mode,
51 // so that a C library implementation which follows the C99 standard can be
52 // used in C++.
53 # ifdef __cplusplus
54 #  if !defined(__STDC_LIMIT_MACROS)
55 #   define __STDC_LIMIT_MACROS
56 #   define __STDC_LIMIT_MACROS_DEFINED_BY_CLANG
57 #  endif
58 #  if !defined(__STDC_CONSTANT_MACROS)
59 #   define __STDC_CONSTANT_MACROS
60 #   define __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG
61 #  endif
62 # endif
63 
64 # include_next <stdint.h>
65 
66 # ifdef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG
67 #  undef __STDC_LIMIT_MACROS
68 #  undef __STDC_LIMIT_MACROS_DEFINED_BY_CLANG
69 # endif
70 # ifdef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG
71 #  undef __STDC_CONSTANT_MACROS
72 #  undef __STDC_CONSTANT_MACROS_DEFINED_BY_CLANG
73 # endif
74 
75 #else
76 
77 /* C99 7.18.1.1 Exact-width integer types.
78  * C99 7.18.1.2 Minimum-width integer types.
79  * C99 7.18.1.3 Fastest minimum-width integer types.
80  *
81  * The standard requires that exact-width type be defined for 8-, 16-, 32-, and
82  * 64-bit types if they are implemented. Other exact width types are optional.
83  * This implementation defines an exact-width types for every integer width
84  * that is represented in the standard integer types.
85  *
86  * The standard also requires minimum-width types be defined for 8-, 16-, 32-,
87  * and 64-bit widths regardless of whether there are corresponding exact-width
88  * types.
89  *
90  * To accommodate targets that are missing types that are exactly 8, 16, 32, or
91  * 64 bits wide, this implementation takes an approach of cascading
92  * redefintions, redefining __int_leastN_t to successively smaller exact-width
93  * types. It is therefore important that the types are defined in order of
94  * descending widths.
95  *
96  * We currently assume that the minimum-width types and the fastest
97  * minimum-width types are the same. This is allowed by the standard, but is
98  * suboptimal.
99  *
100  * In violation of the standard, some targets do not implement a type that is
101  * wide enough to represent all of the required widths (8-, 16-, 32-, 64-bit).
102  * To accommodate these targets, a required minimum-width type is only
103  * defined if there exists an exact-width type of equal or greater width.
104  */
105 
106 #ifdef __INT64_TYPE__
107 # ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/
108 typedef signed __INT64_TYPE__ int64_t;
109 # endif /* __int8_t_defined */
110 typedef unsigned __INT64_TYPE__ uint64_t;
111 # define __int_least64_t int64_t
112 # define __uint_least64_t uint64_t
113 # define __int_least32_t int64_t
114 # define __uint_least32_t uint64_t
115 # define __int_least16_t int64_t
116 # define __uint_least16_t uint64_t
117 # define __int_least8_t int64_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 signed __INT56_TYPE__ int56_t;
130 typedef unsigned __INT56_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 # define __int_least32_t int56_t
136 # define __uint_least32_t uint56_t
137 # define __int_least16_t int56_t
138 # define __uint_least16_t uint56_t
139 # define __int_least8_t int56_t
140 # define __uint_least8_t uint56_t
141 #endif /* __INT56_TYPE__ */
142 
143 
144 #ifdef __INT48_TYPE__
145 typedef signed __INT48_TYPE__ int48_t;
146 typedef unsigned __INT48_TYPE__ uint48_t;
147 typedef int48_t int_least48_t;
148 typedef uint48_t uint_least48_t;
149 typedef int48_t int_fast48_t;
150 typedef uint48_t uint_fast48_t;
151 # define __int_least32_t int48_t
152 # define __uint_least32_t uint48_t
153 # define __int_least16_t int48_t
154 # define __uint_least16_t uint48_t
155 # define __int_least8_t int48_t
156 # define __uint_least8_t uint48_t
157 #endif /* __INT48_TYPE__ */
158 
159 
160 #ifdef __INT40_TYPE__
161 typedef signed __INT40_TYPE__ int40_t;
162 typedef unsigned __INT40_TYPE__ uint40_t;
163 typedef int40_t int_least40_t;
164 typedef uint40_t uint_least40_t;
165 typedef int40_t int_fast40_t;
166 typedef uint40_t uint_fast40_t;
167 # define __int_least32_t int40_t
168 # define __uint_least32_t uint40_t
169 # define __int_least16_t int40_t
170 # define __uint_least16_t uint40_t
171 # define __int_least8_t int40_t
172 # define __uint_least8_t uint40_t
173 #endif /* __INT40_TYPE__ */
174 
175 
176 #ifdef __INT32_TYPE__
177 
178 # ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/
179 typedef signed __INT32_TYPE__ int32_t;
180 # endif /* __int8_t_defined */
181 
182 # ifndef __uint32_t_defined  /* more glibc compatibility */
183 # define __uint32_t_defined
184 typedef unsigned __INT32_TYPE__ uint32_t;
185 # endif /* __uint32_t_defined */
186 
187 # define __int_least32_t int32_t
188 # define __uint_least32_t uint32_t
189 # define __int_least16_t int32_t
190 # define __uint_least16_t uint32_t
191 # define __int_least8_t int32_t
192 # define __uint_least8_t uint32_t
193 #endif /* __INT32_TYPE__ */
194 
195 #ifdef __int_least32_t
196 typedef __int_least32_t int_least32_t;
197 typedef __uint_least32_t uint_least32_t;
198 typedef __int_least32_t int_fast32_t;
199 typedef __uint_least32_t uint_fast32_t;
200 #endif /* __int_least32_t */
201 
202 #ifdef __INT24_TYPE__
203 typedef signed __INT24_TYPE__ int24_t;
204 typedef unsigned __INT24_TYPE__ uint24_t;
205 typedef int24_t int_least24_t;
206 typedef uint24_t uint_least24_t;
207 typedef int24_t int_fast24_t;
208 typedef uint24_t uint_fast24_t;
209 # define __int_least16_t int24_t
210 # define __uint_least16_t uint24_t
211 # define __int_least8_t int24_t
212 # define __uint_least8_t uint24_t
213 #endif /* __INT24_TYPE__ */
214 
215 #ifdef __INT16_TYPE__
216 #ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/
217 typedef signed __INT16_TYPE__ int16_t;
218 #endif /* __int8_t_defined */
219 typedef unsigned __INT16_TYPE__ uint16_t;
220 # define __int_least16_t int16_t
221 # define __uint_least16_t uint16_t
222 # define __int_least8_t int16_t
223 # define __uint_least8_t uint16_t
224 #endif /* __INT16_TYPE__ */
225 
226 #ifdef __int_least16_t
227 typedef __int_least16_t int_least16_t;
228 typedef __uint_least16_t uint_least16_t;
229 typedef __int_least16_t int_fast16_t;
230 typedef __uint_least16_t uint_fast16_t;
231 #endif /* __int_least16_t */
232 
233 
234 #ifdef __INT8_TYPE__
235 #ifndef __int8_t_defined  /* glibc sys/types.h also defines int8_t*/
236 typedef signed __INT8_TYPE__ int8_t;
237 #endif /* __int8_t_defined */
238 typedef unsigned __INT8_TYPE__ uint8_t;
239 # define __int_least8_t int8_t
240 # define __uint_least8_t uint8_t
241 #endif /* __INT8_TYPE__ */
242 
243 #ifdef __int_least8_t
244 typedef __int_least8_t int_least8_t;
245 typedef __uint_least8_t uint_least8_t;
246 typedef __int_least8_t int_fast8_t;
247 typedef __uint_least8_t uint_fast8_t;
248 #endif /* __int_least8_t */
249 
250 /* prevent glibc sys/types.h from defining conflicting types */
251 #ifndef __int8_t_defined
252 # define __int8_t_defined
253 #endif /* __int8_t_defined */
254 
255 /* C99 7.18.1.4 Integer types capable of holding object pointers.
256  */
257 #define __stdint_join3(a,b,c) a ## b ## c
258 
259 #define  __intn_t(n) __stdint_join3( int, n, _t)
260 #define __uintn_t(n) __stdint_join3(uint, n, _t)
261 
262 #ifndef _INTPTR_T
263 #ifndef __intptr_t_defined
264 typedef  __intn_t(__INTPTR_WIDTH__)  intptr_t;
265 #define __intptr_t_defined
266 #define _INTPTR_T
267 #endif
268 #endif
269 
270 #ifndef _UINTPTR_T
271 typedef __uintn_t(__INTPTR_WIDTH__) uintptr_t;
272 #define _UINTPTR_T
273 #endif
274 
275 /* C99 7.18.1.5 Greatest-width integer types.
276  */
277 typedef __INTMAX_TYPE__  intmax_t;
278 typedef __UINTMAX_TYPE__ uintmax_t;
279 
280 /* C99 7.18.4 Macros for minimum-width integer constants.
281  *
282  * The standard requires that integer constant macros be defined for all the
283  * minimum-width types defined above. As 8-, 16-, 32-, and 64-bit minimum-width
284  * types are required, the corresponding integer constant macros are defined
285  * here. This implementation also defines minimum-width types for every other
286  * integer width that the target implements, so corresponding macros are
287  * defined below, too.
288  *
289  * These macros are defined using the same successive-shrinking approach as
290  * the type definitions above. It is likewise important that macros are defined
291  * in order of decending width.
292  *
293  * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the
294  * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
295  */
296 
297 #define __int_c_join(a, b) a ## b
298 #define __int_c(v, suffix) __int_c_join(v, suffix)
299 #define __uint_c(v, suffix) __int_c_join(v##U, suffix)
300 
301 
302 #ifdef __INT64_TYPE__
303 # ifdef __INT64_C_SUFFIX__
304 #  define __int64_c_suffix __INT64_C_SUFFIX__
305 #  define __int32_c_suffix __INT64_C_SUFFIX__
306 #  define __int16_c_suffix __INT64_C_SUFFIX__
307 #  define  __int8_c_suffix __INT64_C_SUFFIX__
308 # else
309 #  undef __int64_c_suffix
310 #  undef __int32_c_suffix
311 #  undef __int16_c_suffix
312 #  undef  __int8_c_suffix
313 # endif /* __INT64_C_SUFFIX__ */
314 #endif /* __INT64_TYPE__ */
315 
316 #ifdef __int_least64_t
317 # ifdef __int64_c_suffix
318 #  define INT64_C(v) __int_c(v, __int64_c_suffix)
319 #  define UINT64_C(v) __uint_c(v, __int64_c_suffix)
320 # else
321 #  define INT64_C(v) v
322 #  define UINT64_C(v) v ## U
323 # endif /* __int64_c_suffix */
324 #endif /* __int_least64_t */
325 
326 
327 #ifdef __INT56_TYPE__
328 # ifdef __INT56_C_SUFFIX__
329 #  define INT56_C(v) __int_c(v, __INT56_C_SUFFIX__)
330 #  define UINT56_C(v) __uint_c(v, __INT56_C_SUFFIX__)
331 #  define __int32_c_suffix __INT56_C_SUFFIX__
332 #  define __int16_c_suffix __INT56_C_SUFFIX__
333 #  define __int8_c_suffix  __INT56_C_SUFFIX__
334 # else
335 #  define INT56_C(v) v
336 #  define UINT56_C(v) v ## U
337 #  undef __int32_c_suffix
338 #  undef __int16_c_suffix
339 #  undef  __int8_c_suffix
340 # endif /* __INT56_C_SUFFIX__ */
341 #endif /* __INT56_TYPE__ */
342 
343 
344 #ifdef __INT48_TYPE__
345 # ifdef __INT48_C_SUFFIX__
346 #  define INT48_C(v) __int_c(v, __INT48_C_SUFFIX__)
347 #  define UINT48_C(v) __uint_c(v, __INT48_C_SUFFIX__)
348 #  define __int32_c_suffix __INT48_C_SUFFIX__
349 #  define __int16_c_suffix __INT48_C_SUFFIX__
350 #  define __int8_c_suffix  __INT48_C_SUFFIX__
351 # else
352 #  define INT48_C(v) v
353 #  define UINT48_C(v) v ## U
354 #  undef __int32_c_suffix
355 #  undef __int16_c_suffix
356 #  undef  __int8_c_suffix
357 # endif /* __INT48_C_SUFFIX__ */
358 #endif /* __INT48_TYPE__ */
359 
360 
361 #ifdef __INT40_TYPE__
362 # ifdef __INT40_C_SUFFIX__
363 #  define INT40_C(v) __int_c(v, __INT40_C_SUFFIX__)
364 #  define UINT40_C(v) __uint_c(v, __INT40_C_SUFFIX__)
365 #  define __int32_c_suffix __INT40_C_SUFFIX__
366 #  define __int16_c_suffix __INT40_C_SUFFIX__
367 #  define __int8_c_suffix  __INT40_C_SUFFIX__
368 # else
369 #  define INT40_C(v) v
370 #  define UINT40_C(v) v ## U
371 #  undef __int32_c_suffix
372 #  undef __int16_c_suffix
373 #  undef  __int8_c_suffix
374 # endif /* __INT40_C_SUFFIX__ */
375 #endif /* __INT40_TYPE__ */
376 
377 
378 #ifdef __INT32_TYPE__
379 # ifdef __INT32_C_SUFFIX__
380 #  define __int32_c_suffix __INT32_C_SUFFIX__
381 #  define __int16_c_suffix __INT32_C_SUFFIX__
382 #  define __int8_c_suffix  __INT32_C_SUFFIX__
383 #else
384 #  undef __int32_c_suffix
385 #  undef __int16_c_suffix
386 #  undef  __int8_c_suffix
387 # endif /* __INT32_C_SUFFIX__ */
388 #endif /* __INT32_TYPE__ */
389 
390 #ifdef __int_least32_t
391 # ifdef __int32_c_suffix
392 #  define INT32_C(v) __int_c(v, __int32_c_suffix)
393 #  define UINT32_C(v) __uint_c(v, __int32_c_suffix)
394 # else
395 #  define INT32_C(v) v
396 #  define UINT32_C(v) v ## U
397 # endif /* __int32_c_suffix */
398 #endif /* __int_least32_t */
399 
400 
401 #ifdef __INT24_TYPE__
402 # ifdef __INT24_C_SUFFIX__
403 #  define INT24_C(v) __int_c(v, __INT24_C_SUFFIX__)
404 #  define UINT24_C(v) __uint_c(v, __INT24_C_SUFFIX__)
405 #  define __int16_c_suffix __INT24_C_SUFFIX__
406 #  define __int8_c_suffix  __INT24_C_SUFFIX__
407 # else
408 #  define INT24_C(v) v
409 #  define UINT24_C(v) v ## U
410 #  undef __int16_c_suffix
411 #  undef  __int8_c_suffix
412 # endif /* __INT24_C_SUFFIX__ */
413 #endif /* __INT24_TYPE__ */
414 
415 
416 #ifdef __INT16_TYPE__
417 # ifdef __INT16_C_SUFFIX__
418 #  define __int16_c_suffix __INT16_C_SUFFIX__
419 #  define __int8_c_suffix  __INT16_C_SUFFIX__
420 #else
421 #  undef __int16_c_suffix
422 #  undef  __int8_c_suffix
423 # endif /* __INT16_C_SUFFIX__ */
424 #endif /* __INT16_TYPE__ */
425 
426 #ifdef __int_least16_t
427 # ifdef __int16_c_suffix
428 #  define INT16_C(v) __int_c(v, __int16_c_suffix)
429 #  define UINT16_C(v) __uint_c(v, __int16_c_suffix)
430 # else
431 #  define INT16_C(v) v
432 #  define UINT16_C(v) v ## U
433 # endif /* __int16_c_suffix */
434 #endif /* __int_least16_t */
435 
436 
437 #ifdef __INT8_TYPE__
438 # ifdef __INT8_C_SUFFIX__
439 #  define __int8_c_suffix __INT8_C_SUFFIX__
440 #else
441 #  undef  __int8_c_suffix
442 # endif /* __INT8_C_SUFFIX__ */
443 #endif /* __INT8_TYPE__ */
444 
445 #ifdef __int_least8_t
446 # ifdef __int8_c_suffix
447 #  define INT8_C(v) __int_c(v, __int8_c_suffix)
448 #  define UINT8_C(v) __uint_c(v, __int8_c_suffix)
449 # else
450 #  define INT8_C(v) v
451 #  define UINT8_C(v) v ## U
452 # endif /* __int8_c_suffix */
453 #endif /* __int_least8_t */
454 
455 
456 /* C99 7.18.2.1 Limits of exact-width integer types.
457  * C99 7.18.2.2 Limits of minimum-width integer types.
458  * C99 7.18.2.3 Limits of fastest minimum-width integer types.
459  *
460  * The presence of limit macros are completely optional in C99.  This
461  * implementation defines limits for all of the types (exact- and
462  * minimum-width) that it defines above, using the limits of the minimum-width
463  * type for any types that do not have exact-width representations.
464  *
465  * As in the type definitions, this section takes an approach of
466  * successive-shrinking to determine which limits to use for the standard (8,
467  * 16, 32, 64) bit widths when they don't have exact representations. It is
468  * therefore important that the defintions be kept in order of decending
469  * widths.
470  *
471  * Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the
472  * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
473  */
474 
475 #ifdef __INT64_TYPE__
476 # define INT64_MAX           INT64_C( 9223372036854775807)
477 # define INT64_MIN         (-INT64_C( 9223372036854775807)-1)
478 # define UINT64_MAX         UINT64_C(18446744073709551615)
479 # define __INT_LEAST64_MIN   INT64_MIN
480 # define __INT_LEAST64_MAX   INT64_MAX
481 # define __UINT_LEAST64_MAX UINT64_MAX
482 # define __INT_LEAST32_MIN   INT64_MIN
483 # define __INT_LEAST32_MAX   INT64_MAX
484 # define __UINT_LEAST32_MAX UINT64_MAX
485 # define __INT_LEAST16_MIN   INT64_MIN
486 # define __INT_LEAST16_MAX   INT64_MAX
487 # define __UINT_LEAST16_MAX UINT64_MAX
488 # define __INT_LEAST8_MIN    INT64_MIN
489 # define __INT_LEAST8_MAX    INT64_MAX
490 # define __UINT_LEAST8_MAX  UINT64_MAX
491 #endif /* __INT64_TYPE__ */
492 
493 #ifdef __INT_LEAST64_MIN
494 # define INT_LEAST64_MIN   __INT_LEAST64_MIN
495 # define INT_LEAST64_MAX   __INT_LEAST64_MAX
496 # define UINT_LEAST64_MAX __UINT_LEAST64_MAX
497 # define INT_FAST64_MIN    __INT_LEAST64_MIN
498 # define INT_FAST64_MAX    __INT_LEAST64_MAX
499 # define UINT_FAST64_MAX  __UINT_LEAST64_MAX
500 #endif /* __INT_LEAST64_MIN */
501 
502 
503 #ifdef __INT56_TYPE__
504 # define INT56_MAX           INT56_C(36028797018963967)
505 # define INT56_MIN         (-INT56_C(36028797018963967)-1)
506 # define UINT56_MAX         UINT56_C(72057594037927935)
507 # define INT_LEAST56_MIN     INT56_MIN
508 # define INT_LEAST56_MAX     INT56_MAX
509 # define UINT_LEAST56_MAX   UINT56_MAX
510 # define INT_FAST56_MIN      INT56_MIN
511 # define INT_FAST56_MAX      INT56_MAX
512 # define UINT_FAST56_MAX    UINT56_MAX
513 # define __INT_LEAST32_MIN   INT56_MIN
514 # define __INT_LEAST32_MAX   INT56_MAX
515 # define __UINT_LEAST32_MAX UINT56_MAX
516 # define __INT_LEAST16_MIN   INT56_MIN
517 # define __INT_LEAST16_MAX   INT56_MAX
518 # define __UINT_LEAST16_MAX UINT56_MAX
519 # define __INT_LEAST8_MIN    INT56_MIN
520 # define __INT_LEAST8_MAX    INT56_MAX
521 # define __UINT_LEAST8_MAX  UINT56_MAX
522 #endif /* __INT56_TYPE__ */
523 
524 
525 #ifdef __INT48_TYPE__
526 # define INT48_MAX           INT48_C(140737488355327)
527 # define INT48_MIN         (-INT48_C(140737488355327)-1)
528 # define UINT48_MAX         UINT48_C(281474976710655)
529 # define INT_LEAST48_MIN     INT48_MIN
530 # define INT_LEAST48_MAX     INT48_MAX
531 # define UINT_LEAST48_MAX   UINT48_MAX
532 # define INT_FAST48_MIN      INT48_MIN
533 # define INT_FAST48_MAX      INT48_MAX
534 # define UINT_FAST48_MAX    UINT48_MAX
535 # define __INT_LEAST32_MIN   INT48_MIN
536 # define __INT_LEAST32_MAX   INT48_MAX
537 # define __UINT_LEAST32_MAX UINT48_MAX
538 # define __INT_LEAST16_MIN   INT48_MIN
539 # define __INT_LEAST16_MAX   INT48_MAX
540 # define __UINT_LEAST16_MAX UINT48_MAX
541 # define __INT_LEAST8_MIN    INT48_MIN
542 # define __INT_LEAST8_MAX    INT48_MAX
543 # define __UINT_LEAST8_MAX  UINT48_MAX
544 #endif /* __INT48_TYPE__ */
545 
546 
547 #ifdef __INT40_TYPE__
548 # define INT40_MAX           INT40_C(549755813887)
549 # define INT40_MIN         (-INT40_C(549755813887)-1)
550 # define UINT40_MAX         UINT40_C(1099511627775)
551 # define INT_LEAST40_MIN     INT40_MIN
552 # define INT_LEAST40_MAX     INT40_MAX
553 # define UINT_LEAST40_MAX   UINT40_MAX
554 # define INT_FAST40_MIN      INT40_MIN
555 # define INT_FAST40_MAX      INT40_MAX
556 # define UINT_FAST40_MAX    UINT40_MAX
557 # define __INT_LEAST32_MIN   INT40_MIN
558 # define __INT_LEAST32_MAX   INT40_MAX
559 # define __UINT_LEAST32_MAX UINT40_MAX
560 # define __INT_LEAST16_MIN   INT40_MIN
561 # define __INT_LEAST16_MAX   INT40_MAX
562 # define __UINT_LEAST16_MAX UINT40_MAX
563 # define __INT_LEAST8_MIN    INT40_MIN
564 # define __INT_LEAST8_MAX    INT40_MAX
565 # define __UINT_LEAST8_MAX  UINT40_MAX
566 #endif /* __INT40_TYPE__ */
567 
568 
569 #ifdef __INT32_TYPE__
570 # define INT32_MAX           INT32_C(2147483647)
571 # define INT32_MIN         (-INT32_C(2147483647)-1)
572 # define UINT32_MAX         UINT32_C(4294967295)
573 # define __INT_LEAST32_MIN   INT32_MIN
574 # define __INT_LEAST32_MAX   INT32_MAX
575 # define __UINT_LEAST32_MAX UINT32_MAX
576 # define __INT_LEAST16_MIN   INT32_MIN
577 # define __INT_LEAST16_MAX   INT32_MAX
578 # define __UINT_LEAST16_MAX UINT32_MAX
579 # define __INT_LEAST8_MIN    INT32_MIN
580 # define __INT_LEAST8_MAX    INT32_MAX
581 # define __UINT_LEAST8_MAX  UINT32_MAX
582 #endif /* __INT32_TYPE__ */
583 
584 #ifdef __INT_LEAST32_MIN
585 # define INT_LEAST32_MIN   __INT_LEAST32_MIN
586 # define INT_LEAST32_MAX   __INT_LEAST32_MAX
587 # define UINT_LEAST32_MAX __UINT_LEAST32_MAX
588 # define INT_FAST32_MIN    __INT_LEAST32_MIN
589 # define INT_FAST32_MAX    __INT_LEAST32_MAX
590 # define UINT_FAST32_MAX  __UINT_LEAST32_MAX
591 #endif /* __INT_LEAST32_MIN */
592 
593 
594 #ifdef __INT24_TYPE__
595 # define INT24_MAX           INT24_C(8388607)
596 # define INT24_MIN         (-INT24_C(8388607)-1)
597 # define UINT24_MAX         UINT24_C(16777215)
598 # define INT_LEAST24_MIN     INT24_MIN
599 # define INT_LEAST24_MAX     INT24_MAX
600 # define UINT_LEAST24_MAX   UINT24_MAX
601 # define INT_FAST24_MIN      INT24_MIN
602 # define INT_FAST24_MAX      INT24_MAX
603 # define UINT_FAST24_MAX    UINT24_MAX
604 # define __INT_LEAST16_MIN   INT24_MIN
605 # define __INT_LEAST16_MAX   INT24_MAX
606 # define __UINT_LEAST16_MAX UINT24_MAX
607 # define __INT_LEAST8_MIN    INT24_MIN
608 # define __INT_LEAST8_MAX    INT24_MAX
609 # define __UINT_LEAST8_MAX  UINT24_MAX
610 #endif /* __INT24_TYPE__ */
611 
612 
613 #ifdef __INT16_TYPE__
614 #define INT16_MAX            INT16_C(32767)
615 #define INT16_MIN          (-INT16_C(32767)-1)
616 #define UINT16_MAX          UINT16_C(65535)
617 # define __INT_LEAST16_MIN   INT16_MIN
618 # define __INT_LEAST16_MAX   INT16_MAX
619 # define __UINT_LEAST16_MAX UINT16_MAX
620 # define __INT_LEAST8_MIN    INT16_MIN
621 # define __INT_LEAST8_MAX    INT16_MAX
622 # define __UINT_LEAST8_MAX  UINT16_MAX
623 #endif /* __INT16_TYPE__ */
624 
625 #ifdef __INT_LEAST16_MIN
626 # define INT_LEAST16_MIN   __INT_LEAST16_MIN
627 # define INT_LEAST16_MAX   __INT_LEAST16_MAX
628 # define UINT_LEAST16_MAX __UINT_LEAST16_MAX
629 # define INT_FAST16_MIN    __INT_LEAST16_MIN
630 # define INT_FAST16_MAX    __INT_LEAST16_MAX
631 # define UINT_FAST16_MAX  __UINT_LEAST16_MAX
632 #endif /* __INT_LEAST16_MIN */
633 
634 
635 #ifdef __INT8_TYPE__
636 # define INT8_MAX            INT8_C(127)
637 # define INT8_MIN          (-INT8_C(127)-1)
638 # define UINT8_MAX          UINT8_C(255)
639 # define __INT_LEAST8_MIN    INT8_MIN
640 # define __INT_LEAST8_MAX    INT8_MAX
641 # define __UINT_LEAST8_MAX  UINT8_MAX
642 #endif /* __INT8_TYPE__ */
643 
644 #ifdef __INT_LEAST8_MIN
645 # define INT_LEAST8_MIN   __INT_LEAST8_MIN
646 # define INT_LEAST8_MAX   __INT_LEAST8_MAX
647 # define UINT_LEAST8_MAX __UINT_LEAST8_MAX
648 # define INT_FAST8_MIN    __INT_LEAST8_MIN
649 # define INT_FAST8_MAX    __INT_LEAST8_MAX
650 # define UINT_FAST8_MAX  __UINT_LEAST8_MAX
651 #endif /* __INT_LEAST8_MIN */
652 
653 /* Some utility macros */
654 #define  __INTN_MIN(n)  __stdint_join3( INT, n, _MIN)
655 #define  __INTN_MAX(n)  __stdint_join3( INT, n, _MAX)
656 #define __UINTN_MAX(n)  __stdint_join3(UINT, n, _MAX)
657 #define  __INTN_C(n, v) __stdint_join3( INT, n, _C(v))
658 #define __UINTN_C(n, v) __stdint_join3(UINT, n, _C(v))
659 
660 /* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */
661 /* C99 7.18.3 Limits of other integer types. */
662 
663 #define  INTPTR_MIN  __INTN_MIN(__INTPTR_WIDTH__)
664 #define  INTPTR_MAX  __INTN_MAX(__INTPTR_WIDTH__)
665 #define UINTPTR_MAX __UINTN_MAX(__INTPTR_WIDTH__)
666 #define PTRDIFF_MIN  __INTN_MIN(__PTRDIFF_WIDTH__)
667 #define PTRDIFF_MAX  __INTN_MAX(__PTRDIFF_WIDTH__)
668 #define    SIZE_MAX __UINTN_MAX(__SIZE_WIDTH__)
669 
670 /* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__
671  * is enabled. */
672 #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
673 #define   RSIZE_MAX            (SIZE_MAX >> 1)
674 #endif
675 
676 /* C99 7.18.2.5 Limits of greatest-width integer types. */
677 #define INTMAX_MIN   __INTN_MIN(__INTMAX_WIDTH__)
678 #define INTMAX_MAX   __INTN_MAX(__INTMAX_WIDTH__)
679 #define UINTMAX_MAX __UINTN_MAX(__INTMAX_WIDTH__)
680 
681 /* C99 7.18.3 Limits of other integer types. */
682 #define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__)
683 #define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__)
684 #ifdef __WINT_UNSIGNED__
685 # define WINT_MIN       __UINTN_C(__WINT_WIDTH__, 0)
686 # define WINT_MAX       __UINTN_MAX(__WINT_WIDTH__)
687 #else
688 # define WINT_MIN       __INTN_MIN(__WINT_WIDTH__)
689 # define WINT_MAX       __INTN_MAX(__WINT_WIDTH__)
690 #endif
691 
692 #ifndef WCHAR_MAX
693 # define WCHAR_MAX __WCHAR_MAX__
694 #endif
695 #ifndef WCHAR_MIN
696 # if __WCHAR_MAX__ == __INTN_MAX(__WCHAR_WIDTH__)
697 #  define WCHAR_MIN __INTN_MIN(__WCHAR_WIDTH__)
698 # else
699 #  define WCHAR_MIN __UINTN_C(__WCHAR_WIDTH__, 0)
700 # endif
701 #endif
702 
703 /* 7.18.4.2 Macros for greatest-width integer constants. */
704 #define INTMAX_C(v)   __INTN_C(__INTMAX_WIDTH__, v)
705 #define UINTMAX_C(v) __UINTN_C(__INTMAX_WIDTH__, v)
706 
707 #endif /* __STDC_HOSTED__ */
708 #endif /* __CLANG_STDINT_H */
709