stdint.h revision 199512
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# include_next <stdint.h>
34#else
35
36/* C99 7.18.1.1 Exact-width integer types.
37 * C99 7.18.1.2 Minimum-width integer types.
38 * C99 7.18.1.3 Fastest minimum-width integer types.
39 *
40 * The standard requires that exact-width type be defined for 8-, 16-, 32-, and
41 * 64-bit types if they are implemented. Other exact width types are optional.
42 * This implementation defines an exact-width types for every integer width
43 * that is represented in the standard integer types.
44 *
45 * The standard also requires minimum-width types be defined for 8-, 16-, 32-,
46 * and 64-bit widths regardless of whether there are corresponding exact-width
47 * types.
48 *
49 * To accomodate targets that are missing types that are exactly 8, 16, 32, or
50 * 64 bits wide, this implementation takes an approach of cascading
51 * redefintions, redefining __int_leastN_t to successively smaller exact-width
52 * types. It is therefore important that the types are defined in order of
53 * descending widths.
54 *
55 * We currently assume that the minimum-width types and the fastest
56 * minimum-width types are the same. This is allowed by the standard, but is
57 * suboptimal.
58 *
59 * In violation of the standard, some targets do not implement a type that is
60 * wide enough to represent all of the required widths (8-, 16-, 32-, 64-bit).
61 * To accomodate these targets, a required minimum-width type is only
62 * defined if there exists an exact-width type of equal or greater width.
63 */
64
65#ifdef __INT64_TYPE__
66# ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/
67typedef signed __INT64_TYPE__ int64_t;
68# endif /* __int8_t_defined */
69typedef unsigned __INT64_TYPE__ uint64_t;
70# define __int_least64_t int64_t
71# define __uint_least64_t uint64_t
72# define __int_least32_t int64_t
73# define __uint_least32_t uint64_t
74# define __int_least16_t int64_t
75# define __uint_least16_t uint64_t
76# define __int_least8_t int64_t
77# define __uint_least8_t uint64_t
78#endif /* __INT64_TYPE__ */
79
80#ifdef __int_least64_t
81typedef __int_least64_t int_least64_t;
82typedef __uint_least64_t uint_least64_t;
83typedef __int_least64_t int_fast64_t;
84typedef __uint_least64_t uint_fast64_t;
85#endif /* __int_least64_t */
86
87#ifdef __INT56_TYPE__
88typedef signed __INT56_TYPE__ int56_t;
89typedef unsigned __INT56_TYPE__ uint56_t;
90typedef int56_t int_least56_t;
91typedef uint56_t uint_least56_t;
92typedef int56_t int_fast56_t;
93typedef uint56_t uint_fast56_t;
94# define __int_least32_t int56_t
95# define __uint_least32_t uint56_t
96# define __int_least16_t int56_t
97# define __uint_least16_t uint56_t
98# define __int_least8_t int56_t
99# define __uint_least8_t uint56_t
100#endif /* __INT56_TYPE__ */
101
102
103#ifdef __INT48_TYPE__
104typedef signed __INT48_TYPE__ int48_t;
105typedef unsigned __INT48_TYPE__ uint48_t;
106typedef int48_t int_least48_t;
107typedef uint48_t uint_least48_t;
108typedef int48_t int_fast48_t;
109typedef uint48_t uint_fast48_t;
110# define __int_least32_t int48_t
111# define __uint_least32_t uint48_t
112# define __int_least16_t int48_t
113# define __uint_least16_t uint48_t
114# define __int_least8_t int48_t
115# define __uint_least8_t uint48_t
116#endif /* __INT48_TYPE__ */
117
118
119#ifdef __INT40_TYPE__
120typedef signed __INT40_TYPE__ int40_t;
121typedef unsigned __INT40_TYPE__ uint40_t;
122typedef int40_t int_least40_t;
123typedef uint40_t uint_least40_t;
124typedef int40_t int_fast40_t;
125typedef uint40_t uint_fast40_t;
126# define __int_least32_t int40_t
127# define __uint_least32_t uint40_t
128# define __int_least16_t int40_t
129# define __uint_least16_t uint40_t
130# define __int_least8_t int40_t
131# define __uint_least8_t uint40_t
132#endif /* __INT40_TYPE__ */
133
134
135#ifdef __INT32_TYPE__
136
137# ifndef __int8_t_defined /* glibc sys/types.h also defines int32_t*/
138typedef signed __INT32_TYPE__ int32_t;
139# endif /* __int8_t_defined */
140
141# ifndef __uint32_t_defined  /* more glibc compatibility */
142# define __uint32_t_defined
143typedef unsigned __INT32_TYPE__ uint32_t;
144# endif /* __uint32_t_defined */
145
146# define __int_least32_t int32_t
147# define __uint_least32_t uint32_t
148# define __int_least16_t int32_t
149# define __uint_least16_t uint32_t
150# define __int_least8_t int32_t
151# define __uint_least8_t uint32_t
152#endif /* __INT32_TYPE__ */
153
154#ifdef __int_least32_t
155typedef __int_least32_t int_least32_t;
156typedef __uint_least32_t uint_least32_t;
157typedef __int_least32_t int_fast32_t;
158typedef __uint_least32_t uint_fast32_t;
159#endif /* __int_least32_t */
160
161#ifdef __INT24_TYPE__
162typedef signed __INT24_TYPE__ int24_t;
163typedef unsigned __INT24_TYPE__ uint24_t;
164typedef int24_t int_least24_t;
165typedef uint24_t uint_least24_t;
166typedef int24_t int_fast24_t;
167typedef uint24_t uint_fast24_t;
168# define __int_least16_t int24_t
169# define __uint_least16_t uint24_t
170# define __int_least8_t int24_t
171# define __uint_least8_t uint24_t
172#endif /* __INT24_TYPE__ */
173
174#ifdef __INT16_TYPE__
175#ifndef __int8_t_defined /* glibc sys/types.h also defines int16_t*/
176typedef signed __INT16_TYPE__ int16_t;
177#endif /* __int8_t_defined */
178typedef unsigned __INT16_TYPE__ uint16_t;
179# define __int_least16_t int16_t
180# define __uint_least16_t uint16_t
181# define __int_least8_t int16_t
182# define __uint_least8_t uint16_t
183#endif /* __INT16_TYPE__ */
184
185#ifdef __int_least16_t
186typedef __int_least16_t int_least16_t;
187typedef __uint_least16_t uint_least16_t;
188typedef __int_least16_t int_fast16_t;
189typedef __uint_least16_t uint_fast16_t;
190#endif /* __int_least16_t */
191
192
193#ifdef __INT8_TYPE__
194#ifndef __int8_t_defined  /* glibc sys/types.h also defines int8_t*/
195typedef signed __INT8_TYPE__ int8_t;
196#endif /* __int8_t_defined */
197typedef unsigned __INT8_TYPE__ uint8_t;
198# define __int_least8_t int8_t
199# define __uint_least8_t uint8_t
200#endif /* __INT8_TYPE__ */
201
202#ifdef __int_least8_t
203typedef __int_least8_t int_least8_t;
204typedef __uint_least8_t uint_least8_t;
205typedef __int_least8_t int_fast8_t;
206typedef __uint_least8_t uint_fast8_t;
207#endif /* __int_least8_t */
208
209/* prevent glibc sys/types.h from defining conflicting types */
210#ifndef __int8_t_defined
211# define __int8_t_defined
212#endif /* __int8_t_defined */
213
214/* C99 7.18.1.4 Integer types capable of holding object pointers.
215 */
216#define __stdint_join3(a,b,c) a ## b ## c
217#define __stdint_exjoin3(a,b,c) __stdint_join3(a,b,c)
218
219#ifndef __intptr_t_defined
220typedef __stdint_exjoin3( int, __INTPTR_WIDTH__, _t) intptr_t;
221#define __intptr_t_defined
222#endif
223typedef __stdint_exjoin3(uint, __INTPTR_WIDTH__, _t) uintptr_t;
224
225/* C99 7.18.1.5 Greatest-width integer types.
226 */
227typedef __stdint_exjoin3( int, __INTMAX_WIDTH__, _t) intmax_t;
228typedef __stdint_exjoin3(uint, __INTMAX_WIDTH__, _t) uintmax_t;
229
230/* C99 7.18.4 Macros for minimum-width integer constants.
231 *
232 * The standard requires that integer constant macros be defined for all the
233 * minimum-width types defined above. As 8-, 16-, 32-, and 64-bit minimum-width
234 * types are required, the corresponding integer constant macros are defined
235 * here. This implementation also defines minimum-width types for every other
236 * integer width that the target implements, so corresponding macros are
237 * defined below, too.
238 *
239 * These macros are defined using the same successive-shrinking approach as
240 * the type definitions above. It is likewise important that macros are defined
241 * in order of decending width.
242 *
243 * Note that C++ should not check __STDC_CONSTANT_MACROS here, contrary to the
244 * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
245 */
246
247#define __int_c_join(a, b) a ## b
248#define __int_c(v, suffix) __int_c_join(v, suffix)
249#define __uint_c(v, suffix) __int_c_join(v##U, suffix)
250
251
252#ifdef __INT64_TYPE__
253# ifdef __INT64_C_SUFFIX__
254#  define __int64_c_suffix __INT64_C_SUFFIX__
255#  define __int32_c_suffix __INT64_C_SUFFIX__
256#  define __int16_c_suffix __INT64_C_SUFFIX__
257#  define  __int8_c_suffix __INT64_C_SUFFIX__
258# else
259#  undef __int64_c_suffix
260#  undef __int32_c_suffix
261#  undef __int16_c_suffix
262#  undef  __int8_c_suffix
263# endif /* __INT64_C_SUFFIX__ */
264#endif /* __INT64_TYPE__ */
265
266#ifdef __int_least64_t
267# ifdef __int64_c_suffix
268#  define INT64_C(v) __int_c(v, __int64_c_suffix)
269#  define UINT64_C(v) __uint_c(v, __int64_c_suffix)
270# else
271#  define INT64_C(v) v
272#  define UINT64_C(v) v ## U
273# endif /* __int64_c_suffix */
274#endif /* __int_least64_t */
275
276
277#ifdef __INT56_TYPE__
278# ifdef __INT56_C_SUFFIX__
279#  define INT56_C(v) __int_c(v, __INT56_C_SUFFIX__)
280#  define UINT56_C(v) __uint_c(v, __INT56_C_SUFFIX__)
281#  define __int32_c_suffix __INT56_C_SUFFIX__
282#  define __int16_c_suffix __INT56_C_SUFFIX__
283#  define __int8_c_suffix  __INT56_C_SUFFIX__
284# else
285#  define INT56_C(v) v
286#  define UINT56_C(v) v ## U
287#  undef __int32_c_suffix
288#  undef __int16_c_suffix
289#  undef  __int8_c_suffix
290# endif /* __INT56_C_SUFFIX__ */
291#endif /* __INT56_TYPE__ */
292
293
294#ifdef __INT48_TYPE__
295# ifdef __INT48_C_SUFFIX__
296#  define INT48_C(v) __int_c(v, __INT48_C_SUFFIX__)
297#  define UINT48_C(v) __uint_c(v, __INT48_C_SUFFIX__)
298#  define __int32_c_suffix __INT48_C_SUFFIX__
299#  define __int16_c_suffix __INT48_C_SUFFIX__
300#  define __int8_c_suffix  __INT48_C_SUFFIX__
301# else
302#  define INT48_C(v) v
303#  define UINT48_C(v) v ## U
304#  undef __int32_c_suffix
305#  undef __int16_c_suffix
306#  undef  __int8_c_suffix
307# endif /* __INT48_C_SUFFIX__ */
308#endif /* __INT48_TYPE__ */
309
310
311#ifdef __INT40_TYPE__
312# ifdef __INT40_C_SUFFIX__
313#  define INT40_C(v) __int_c(v, __INT40_C_SUFFIX__)
314#  define UINT40_C(v) __uint_c(v, __INT40_C_SUFFIX__)
315#  define __int32_c_suffix __INT40_C_SUFFIX__
316#  define __int16_c_suffix __INT40_C_SUFFIX__
317#  define __int8_c_suffix  __INT40_C_SUFFIX__
318# else
319#  define INT40_C(v) v
320#  define UINT40_C(v) v ## U
321#  undef __int32_c_suffix
322#  undef __int16_c_suffix
323#  undef  __int8_c_suffix
324# endif /* __INT40_C_SUFFIX__ */
325#endif /* __INT40_TYPE__ */
326
327
328#ifdef __INT32_TYPE__
329# ifdef __INT32_C_SUFFIX__
330#  define __int32_c_suffix __INT32_C_SUFFIX__
331#  define __int16_c_suffix __INT32_C_SUFFIX__
332#  define __int8_c_suffix  __INT32_C_SUFFIX__
333#else
334#  undef __int32_c_suffix
335#  undef __int16_c_suffix
336#  undef  __int8_c_suffix
337# endif /* __INT32_C_SUFFIX__ */
338#endif /* __INT32_TYPE__ */
339
340#ifdef __int_least32_t
341# ifdef __int32_c_suffix
342#  define INT32_C(v) __int_c(v, __int32_c_suffix)
343#  define UINT32_C(v) __uint_c(v, __int32_c_suffix)
344# else
345#  define INT32_C(v) v
346#  define UINT32_C(v) v ## U
347# endif /* __int32_c_suffix */
348#endif /* __int_least32_t */
349
350
351#ifdef __INT24_TYPE__
352# ifdef __INT24_C_SUFFIX__
353#  define INT24_C(v) __int_c(v, __INT24_C_SUFFIX__)
354#  define UINT24_C(v) __uint_c(v, __INT24_C_SUFFIX__)
355#  define __int16_c_suffix __INT24_C_SUFFIX__
356#  define __int8_c_suffix  __INT24_C_SUFFIX__
357# else
358#  define INT24_C(v) v
359#  define UINT24_C(v) v ## U
360#  undef __int16_c_suffix
361#  undef  __int8_c_suffix
362# endif /* __INT24_C_SUFFIX__ */
363#endif /* __INT24_TYPE__ */
364
365
366#ifdef __INT16_TYPE__
367# ifdef __INT16_C_SUFFIX__
368#  define __int16_c_suffix __INT16_C_SUFFIX__
369#  define __int8_c_suffix  __INT16_C_SUFFIX__
370#else
371#  undef __int16_c_suffix
372#  undef  __int8_c_suffix
373# endif /* __INT16_C_SUFFIX__ */
374#endif /* __INT16_TYPE__ */
375
376#ifdef __int_least16_t
377# ifdef __int16_c_suffix
378#  define INT16_C(v) __int_c(v, __int16_c_suffix)
379#  define UINT16_C(v) __uint_c(v, __int16_c_suffix)
380# else
381#  define INT16_C(v) v
382#  define UINT16_C(v) v ## U
383# endif /* __int16_c_suffix */
384#endif /* __int_least16_t */
385
386
387#ifdef __INT8_TYPE__
388# ifdef __INT8_C_SUFFIX__
389#  define __int8_c_suffix __INT8_C_SUFFIX__
390#else
391#  undef  __int8_c_suffix
392# endif /* __INT8_C_SUFFIX__ */
393#endif /* __INT8_TYPE__ */
394
395#ifdef __int_least8_t
396# ifdef __int8_c_suffix
397#  define INT8_C(v) __int_c(v, __int8_c_suffix)
398#  define UINT8_C(v) __uint_c(v, __int8_c_suffix)
399# else
400#  define INT8_C(v) v
401#  define UINT8_C(v) v ## U
402# endif /* __int8_c_suffix */
403#endif /* __int_least8_t */
404
405
406/* C99 7.18.2.1 Limits of exact-width integer types.
407 * C99 7.18.2.2 Limits of minimum-width integer types.
408 * C99 7.18.2.3 Limits of fastest minimum-width integer types.
409 *
410 * The presence of limit macros are completely optional in C99.  This
411 * implementation defines limits for all of the types (exact- and
412 * minimum-width) that it defines above, using the limits of the minimum-width
413 * type for any types that do not have exact-width representations.
414 *
415 * As in the type definitions, this section takes an approach of
416 * successive-shrinking to determine which limits to use for the standard (8,
417 * 16, 32, 64) bit widths when they don't have exact representations. It is
418 * therefore important that the defintions be kept in order of decending
419 * widths.
420 *
421 * Note that C++ should not check __STDC_LIMIT_MACROS here, contrary to the
422 * claims of the C standard (see C++ 18.3.1p2, [cstdint.syn]).
423 */
424
425#ifdef __INT64_TYPE__
426# define INT64_MAX           INT64_C( 9223372036854775807)
427# define INT64_MIN         (-INT64_C( 9223372036854775807)-1)
428# define UINT64_MAX         UINT64_C(18446744073709551615)
429# define __INT_LEAST64_MIN   INT64_MIN
430# define __INT_LEAST64_MAX   INT64_MAX
431# define __UINT_LEAST64_MAX UINT64_MAX
432# define __INT_LEAST32_MIN   INT64_MIN
433# define __INT_LEAST32_MAX   INT64_MAX
434# define __UINT_LEAST32_MAX UINT64_MAX
435# define __INT_LEAST16_MIN   INT64_MIN
436# define __INT_LEAST16_MAX   INT64_MAX
437# define __UINT_LEAST16_MAX UINT64_MAX
438# define __INT_LEAST8_MIN    INT64_MIN
439# define __INT_LEAST8_MAX    INT64_MAX
440# define __UINT_LEAST8_MAX  UINT64_MAX
441#endif /* __INT64_TYPE__ */
442
443#ifdef __INT_LEAST64_MIN
444# define INT_LEAST64_MIN   __INT_LEAST64_MIN
445# define INT_LEAST64_MAX   __INT_LEAST64_MAX
446# define UINT_LEAST64_MAX __UINT_LEAST64_MAX
447# define INT_FAST64_MIN    __INT_LEAST64_MIN
448# define INT_FAST64_MAX    __INT_LEAST64_MAX
449# define UINT_FAST64_MAX  __UINT_LEAST64_MAX
450#endif /* __INT_LEAST64_MIN */
451
452
453#ifdef __INT56_TYPE__
454# define INT56_MAX           INT56_C(36028797018963967)
455# define INT56_MIN         (-INT56_C(36028797018963967)-1)
456# define UINT56_MAX         UINT56_C(72057594037927935)
457# define INT_LEAST56_MIN     INT56_MIN
458# define INT_LEAST56_MAX     INT56_MAX
459# define UINT_LEAST56_MAX   UINT56_MAX
460# define INT_FAST56_MIN      INT56_MIN
461# define INT_FAST56_MAX      INT56_MAX
462# define UINT_FAST56_MAX    UINT56_MAX
463# define __INT_LEAST32_MIN   INT56_MIN
464# define __INT_LEAST32_MAX   INT56_MAX
465# define __UINT_LEAST32_MAX UINT56_MAX
466# define __INT_LEAST16_MIN   INT56_MIN
467# define __INT_LEAST16_MAX   INT56_MAX
468# define __UINT_LEAST16_MAX UINT56_MAX
469# define __INT_LEAST8_MIN    INT56_MIN
470# define __INT_LEAST8_MAX    INT56_MAX
471# define __UINT_LEAST8_MAX  UINT56_MAX
472#endif /* __INT56_TYPE__ */
473
474
475#ifdef __INT48_TYPE__
476# define INT48_MAX           INT48_C(140737488355327)
477# define INT48_MIN         (-INT48_C(140737488355327)-1)
478# define UINT48_MAX         UINT48_C(281474976710655)
479# define INT_LEAST48_MIN     INT48_MIN
480# define INT_LEAST48_MAX     INT48_MAX
481# define UINT_LEAST48_MAX   UINT48_MAX
482# define INT_FAST48_MIN      INT48_MIN
483# define INT_FAST48_MAX      INT48_MAX
484# define UINT_FAST48_MAX    UINT48_MAX
485# define __INT_LEAST32_MIN   INT48_MIN
486# define __INT_LEAST32_MAX   INT48_MAX
487# define __UINT_LEAST32_MAX UINT48_MAX
488# define __INT_LEAST16_MIN   INT48_MIN
489# define __INT_LEAST16_MAX   INT48_MAX
490# define __UINT_LEAST16_MAX UINT48_MAX
491# define __INT_LEAST8_MIN    INT48_MIN
492# define __INT_LEAST8_MAX    INT48_MAX
493# define __UINT_LEAST8_MAX  UINT48_MAX
494#endif /* __INT48_TYPE__ */
495
496
497#ifdef __INT40_TYPE__
498# define INT40_MAX           INT40_C(549755813887)
499# define INT40_MIN         (-INT40_C(549755813887)-1)
500# define UINT40_MAX         UINT40_C(1099511627775)
501# define INT_LEAST40_MIN     INT40_MIN
502# define INT_LEAST40_MAX     INT40_MAX
503# define UINT_LEAST40_MAX   UINT40_MAX
504# define INT_FAST40_MIN      INT40_MIN
505# define INT_FAST40_MAX      INT40_MAX
506# define UINT_FAST40_MAX    UINT40_MAX
507# define __INT_LEAST32_MIN   INT40_MIN
508# define __INT_LEAST32_MAX   INT40_MAX
509# define __UINT_LEAST32_MAX UINT40_MAX
510# define __INT_LEAST16_MIN   INT40_MIN
511# define __INT_LEAST16_MAX   INT40_MAX
512# define __UINT_LEAST16_MAX UINT40_MAX
513# define __INT_LEAST8_MIN    INT40_MIN
514# define __INT_LEAST8_MAX    INT40_MAX
515# define __UINT_LEAST8_MAX  UINT40_MAX
516#endif /* __INT40_TYPE__ */
517
518
519#ifdef __INT32_TYPE__
520# define INT32_MAX           INT32_C(2147483647)
521# define INT32_MIN         (-INT32_C(2147483647)-1)
522# define UINT32_MAX         UINT32_C(4294967295)
523# define __INT_LEAST32_MIN   INT32_MIN
524# define __INT_LEAST32_MAX   INT32_MAX
525# define __UINT_LEAST32_MAX UINT32_MAX
526# define __INT_LEAST16_MIN   INT32_MIN
527# define __INT_LEAST16_MAX   INT32_MAX
528# define __UINT_LEAST16_MAX UINT32_MAX
529# define __INT_LEAST8_MIN    INT32_MIN
530# define __INT_LEAST8_MAX    INT32_MAX
531# define __UINT_LEAST8_MAX  UINT32_MAX
532#endif /* __INT32_TYPE__ */
533
534#ifdef __INT_LEAST32_MIN
535# define INT_LEAST32_MIN   __INT_LEAST32_MIN
536# define INT_LEAST32_MAX   __INT_LEAST32_MAX
537# define UINT_LEAST32_MAX __UINT_LEAST32_MAX
538# define INT_FAST32_MIN    __INT_LEAST32_MIN
539# define INT_FAST32_MAX    __INT_LEAST32_MAX
540# define UINT_FAST32_MAX  __UINT_LEAST32_MAX
541#endif /* __INT_LEAST32_MIN */
542
543
544#ifdef __INT24_TYPE__
545# define INT24_MAX           INT24_C(8388607)
546# define INT24_MIN         (-INT24_C(8388607)-1)
547# define UINT24_MAX         UINT24_C(16777215)
548# define INT_LEAST24_MIN     INT24_MIN
549# define INT_LEAST24_MAX     INT24_MAX
550# define UINT_LEAST24_MAX   UINT24_MAX
551# define INT_FAST24_MIN      INT24_MIN
552# define INT_FAST24_MAX      INT24_MAX
553# define UINT_FAST24_MAX    UINT24_MAX
554# define __INT_LEAST16_MIN   INT24_MIN
555# define __INT_LEAST16_MAX   INT24_MAX
556# define __UINT_LEAST16_MAX UINT24_MAX
557# define __INT_LEAST8_MIN    INT24_MIN
558# define __INT_LEAST8_MAX    INT24_MAX
559# define __UINT_LEAST8_MAX  UINT24_MAX
560#endif /* __INT24_TYPE__ */
561
562
563#ifdef __INT16_TYPE__
564#define INT16_MAX            INT16_C(32767)
565#define INT16_MIN          (-INT16_C(32767)-1)
566#define UINT16_MAX          UINT16_C(65535)
567# define __INT_LEAST16_MIN   INT16_MIN
568# define __INT_LEAST16_MAX   INT16_MAX
569# define __UINT_LEAST16_MAX UINT16_MAX
570# define __INT_LEAST8_MIN    INT16_MIN
571# define __INT_LEAST8_MAX    INT16_MAX
572# define __UINT_LEAST8_MAX  UINT16_MAX
573#endif /* __INT16_TYPE__ */
574
575#ifdef __INT_LEAST16_MIN
576# define INT_LEAST16_MIN   __INT_LEAST16_MIN
577# define INT_LEAST16_MAX   __INT_LEAST16_MAX
578# define UINT_LEAST16_MAX __UINT_LEAST16_MAX
579# define INT_FAST16_MIN    __INT_LEAST16_MIN
580# define INT_FAST16_MAX    __INT_LEAST16_MAX
581# define UINT_FAST16_MAX  __UINT_LEAST16_MAX
582#endif /* __INT_LEAST16_MIN */
583
584
585#ifdef __INT8_TYPE__
586# define INT8_MAX            INT8_C(127)
587# define INT8_MIN          (-INT8_C(127)-1)
588# define UINT8_MAX          UINT8_C(255)
589# define __INT_LEAST8_MIN    INT8_MIN
590# define __INT_LEAST8_MAX    INT8_MAX
591# define __UINT_LEAST8_MAX  UINT8_MAX
592#endif /* __INT8_TYPE__ */
593
594#ifdef __INT_LEAST8_MIN
595# define INT_LEAST8_MIN   __INT_LEAST8_MIN
596# define INT_LEAST8_MAX   __INT_LEAST8_MAX
597# define UINT_LEAST8_MAX __UINT_LEAST8_MAX
598# define INT_FAST8_MIN    __INT_LEAST8_MIN
599# define INT_FAST8_MAX    __INT_LEAST8_MAX
600# define UINT_FAST8_MAX  __UINT_LEAST8_MAX
601#endif /* __INT_LEAST8_MIN */
602
603/* C99 7.18.2.4 Limits of integer types capable of holding object pointers. */
604/* C99 7.18.3 Limits of other integer types. */
605
606#define  INTPTR_MIN __stdint_exjoin3( INT, __INTPTR_WIDTH__, _MIN)
607#define  INTPTR_MAX __stdint_exjoin3( INT, __INTPTR_WIDTH__, _MAX)
608#define UINTPTR_MAX __stdint_exjoin3(UINT, __INTPTR_WIDTH__, _MAX)
609
610#if __POINTER_WIDTH__ == 64
611
612#define PTRDIFF_MIN  INT64_MIN
613#define PTRDIFF_MAX  INT64_MAX
614#define SIZE_MAX    UINT64_MAX
615
616#elif __POINTER_WIDTH__ == 32
617
618#define PTRDIFF_MIN  INT32_MIN
619#define PTRDIFF_MAX  INT32_MAX
620#define SIZE_MAX    UINT32_MAX
621
622#elif __POINTER_WIDTH__ == 16
623
624#define PTRDIFF_MIN  INT16_MIN
625#define PTRDIFF_MAX  INT16_MAX
626#define SIZE_MAX    UINT16_MAX
627
628#else
629#error "unknown or unset pointer width!"
630#endif
631
632/* C99 7.18.2.5 Limits of greatest-width integer types. */
633#define INTMAX_MIN  __stdint_exjoin3( INT, __INTMAX_WIDTH__, _MIN)
634#define INTMAX_MAX  __stdint_exjoin3( INT, __INTMAX_WIDTH__, _MAX)
635#define UINTMAX_MAX __stdint_exjoin3(UINT, __INTMAX_WIDTH__, _MAX)
636
637/* C99 7.18.3 Limits of other integer types. */
638#define SIG_ATOMIC_MIN INT32_MIN
639#define SIG_ATOMIC_MAX INT32_MAX
640#define WINT_MIN       INT32_MIN
641#define WINT_MAX       INT32_MAX
642
643/* FIXME: if we ever support a target with unsigned wchar_t, this should be
644 * 0 .. Max.
645 */
646#ifndef WCHAR_MAX
647#define WCHAR_MAX __WCHAR_MAX__
648#endif
649#ifndef WCHAR_MIN
650#define WCHAR_MIN (-__WCHAR_MAX__-1)
651#endif
652
653/* 7.18.4.2 Macros for greatest-width integer constants. */
654#define INTMAX_C(v)  __stdint_exjoin3( INT, __INTMAX_WIDTH__, _C(v))
655#define UINTMAX_C(v) __stdint_exjoin3(UINT, __INTMAX_WIDTH__, _C(v))
656
657#endif /* __STDC_HOSTED__ */
658#endif /* __CLANG_STDINT_H */
659