73d4f7df53c9544d66072ed8701425549beb8e63
[gnulib.git] / lib / stdint_.h
1 /* Copyright (C) 2001-2002, 2004-2006 Free Software Foundation, Inc.
2    Written by Bruno Haible, Sam Steingold, Peter Burwood.
3    This file is part of gnulib.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 #ifndef _STDINT_H
20 #define _STDINT_H
21
22 /*
23  * ISO C 99 <stdint.h> for platforms that lack it.
24  * <http://www.opengroup.org/susv3xbd/stdint.h.html>
25  */
26
27 /* Get wchar_t, WCHAR_MIN, WCHAR_MAX.  */
28 #include <stddef.h>
29 /* Get LONG_MIN, LONG_MAX, ULONG_MAX.  */
30 #include <limits.h>
31
32 /* Get those types that are already defined in other system include files.  */
33 #if defined(__FreeBSD__) && (__FreeBSD__ >= 3) && (__FreeBSD__ <= 4)
34 # include <sys/inttypes.h>
35 #endif
36 #if defined(__OpenBSD__) || defined(__bsdi__) || defined(__sgi)
37   /* In OpenBSD 3.8, <sys/types.h> includes <machine/types.h>, which defines
38      int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
39      <inttypes.h> includes <machine/types.h> and also defines intptr_t and
40      uintptr_t.  */
41   /* BSD/OS 4.2 is similar, but doesn't have <inttypes.h> */
42   /* IRIX 6.5 has <inttypes.h>, and <sys/types.h> defines some of these
43      types as well.  */
44 # include <sys/types.h>
45 # if @HAVE_INTTYPES_H@
46 #  include @FULL_PATH_INTTYPES_H@
47 # endif
48 #endif
49 #if defined(__linux__) && @HAVE_SYS_BITYPES_H@
50   /* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
51      int{8,16,32,64}_t and __BIT_TYPES_DEFINED__.  In libc5 >= 5.2.2 it is
52      included by <sys/types.h>.  */
53 # include <sys/bitypes.h>
54 #endif
55 #if defined(__sun) && @HAVE_SYS_INTTYPES_H@
56   /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
57      the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX.
58      But note that <sys/int_types.h> contains only the type definitions!  */
59 # include <sys/inttypes.h>
60 #endif
61 #if (defined(__hpux) || defined(_AIX)) && @HAVE_INTTYPES_H@
62   /* HP-UX 10 <inttypes.h> has nearly everything, except UINT_LEAST8_MAX,
63      UINT_FAST8_MAX, PTRDIFF_MIN, PTRDIFF_MAX.  */
64   /* AIX 4 <inttypes.h> has nearly everything, except INTPTR_MIN, INTPTR_MAX,
65      UINTPTR_MAX, PTRDIFF_MIN, PTRDIFF_MAX.  */
66 # include @FULL_PATH_INTTYPES_H@
67 #endif
68 #if @HAVE_STDINT_H@
69   /* Other systems may have an incomplete <stdint.h>.  */
70   /* On some versions of IRIX, the SGI C compiler comes with an <stdint.h>,
71      but
72        - in c99 mode, <inttypes.h> includes <stdint.h>,
73        - in c89 mode, <stdint.h> spews warnings. <inttypes.h> defines only
74          a subset of the types and macros that are defined in <stdint.h>.
75      So we rely only on <inttypes.h> (included above).  It means that in
76      c89 mode, we shadow the contents of warning-spewing <stdint.h>.  */
77 # if !(defined(__sgi) && @HAVE_INTTYPES_H@ && !defined(_c99))
78 #  include @FULL_PATH_STDINT_H@
79 # endif
80 #endif
81
82 /* 7.18.1.1. Exact-width integer types */
83
84 /* Here we assume a standard architecture where the hardware integer
85    types have 8, 16, 32, optionally 64 bits.  */
86
87 #if !@HAVE_INT8_T@
88 typedef signed char    int8_t;
89 #endif
90 #if !@HAVE_UINT8_T@
91 typedef unsigned char  uint8_t;
92 # define _UINT8_T /* avoid collision with Solaris 2.5.1 <pthread.h> */
93 #endif
94
95 #if !@HAVE_INT16_T@
96 typedef short          int16_t;
97 #endif
98 #if !@HAVE_UINT16_T@
99 typedef unsigned short uint16_t;
100 #endif
101
102 #if !@HAVE_INT32_T@
103 typedef int            int32_t;
104 #endif
105 #if !@HAVE_UINT32_T@
106 typedef unsigned int   uint32_t;
107 # define _UINT32_T /* avoid collision with Solaris 2.5.1 <pthread.h> */
108 #endif
109
110 #if @HAVE_INT64_T@
111 # define _STDINT_H_HAVE_INT64 1
112 #else
113 # if @HAVE_LONG_64BIT@
114 typedef long           int64_t;
115 #  define _STDINT_H_HAVE_INT64 1
116 # elif @HAVE_LONG_LONG_64BIT@
117 typedef long long      int64_t;
118 #  define _STDINT_H_HAVE_INT64 1
119 # elif defined _MSC_VER
120 typedef __int64        int64_t;
121 #  define _STDINT_H_HAVE_INT64 1
122 # endif
123 #endif
124 #if @HAVE_UINT64_T@
125 # define _STDINT_H_HAVE_UINT64 1
126 #else
127 # if @HAVE_LONG_64BIT@
128 typedef unsigned long      uint64_t;
129 #  define _STDINT_H_HAVE_UINT64 1
130 # elif @HAVE_LONG_LONG_64BIT@
131 typedef unsigned long long uint64_t;
132 #  define _UINT64_T /* avoid collision with Solaris 2.5.1 <pthread.h> */
133 #  define _STDINT_H_HAVE_UINT64 1
134 # elif defined _MSC_VER
135 typedef unsigned __int64   uint64_t;
136 #  define _STDINT_H_HAVE_UINT64 1
137 # endif
138 #endif
139
140 /* 7.18.1.2. Minimum-width integer types */
141
142 /* Here we assume a standard architecture where the hardware integer
143    types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
144    are the same as the corresponding N_t types.  */
145
146 #if !@HAVE_INT_LEAST8_T@
147 typedef int8_t   int_least8_t;
148 #endif
149 #if !@HAVE_UINT_LEAST8_T@
150 typedef uint8_t  uint_least8_t;
151 #endif
152
153 #if !@HAVE_INT_LEAST16_T@
154 typedef int16_t  int_least16_t;
155 #endif
156 #if !@HAVE_UINT_LEAST16_T@
157 typedef uint16_t uint_least16_t;
158 #endif
159
160 #if !@HAVE_INT_LEAST32_T@
161 typedef int32_t  int_least32_t;
162 #endif
163 #if !@HAVE_UINT_LEAST32_T@
164 typedef uint32_t uint_least32_t;
165 #endif
166
167 #if !@HAVE_INT_LEAST64_T@ && _STDINT_H_HAVE_INT64
168 typedef int64_t  int_least64_t;
169 #endif
170 #if !@HAVE_UINT_LEAST64_T@ && _STDINT_H_HAVE_UINT64
171 typedef uint64_t uint_least64_t;
172 #endif
173
174 /* 7.18.1.3. Fastest minimum-width integer types */
175
176 /* Note: Other <stdint.h> substitutes may define these types differently.
177    It is not recommended to use these types in public header files. */
178
179 /* Here we assume a standard architecture where the hardware integer
180    types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
181    are taken from the same list of types.  */
182
183 /* On alpha processors, int32_t variables are slower than int64_t variables,
184    due to the necessary zap instructions.  */
185 #if defined __alpha
186 # define _STDINT_H_INT64_FASTER_THAN_INT32 1
187 #endif
188
189 #if !@HAVE_INT_FAST8_T@
190 # if _STDINT_H_INT64_FASTER_THAN_INT32
191 typedef int64_t  int_fast8_t;
192 # else
193 typedef int32_t  int_fast8_t;
194 # endif
195 #endif
196 #if !@HAVE_UINT_FAST8_T@
197 # if _STDINT_H_INT64_FASTER_THAN_INT32
198 typedef uint64_t uint_fast8_t;
199 # else
200 typedef uint32_t uint_fast8_t;
201 # endif
202 #endif
203
204 #if !@HAVE_INT_FAST16_T@
205 # if _STDINT_H_INT64_FASTER_THAN_INT32
206 typedef int64_t  int_fast16_t;
207 # else
208 typedef int32_t  int_fast16_t;
209 # endif
210 #endif
211 #if !@HAVE_UINT_FAST16_T@
212 # if _STDINT_H_INT64_FASTER_THAN_INT32
213 typedef uint64_t uint_fast16_t;
214 # else
215 typedef uint32_t uint_fast16_t;
216 # endif
217 #endif
218
219 #if !@HAVE_INT_FAST32_T@
220 # if _STDINT_H_INT64_FASTER_THAN_INT32
221 typedef int64_t  int_fast32_t;
222 # else
223 typedef int32_t  int_fast32_t;
224 # endif
225 #endif
226 #if !@HAVE_UINT_FAST32_T@
227 # if _STDINT_H_INT64_FASTER_THAN_INT32
228 typedef uint64_t uint_fast32_t;
229 # else
230 typedef uint32_t uint_fast32_t;
231 # endif
232 #endif
233
234 #if !@HAVE_INT_FAST64_T@ && _STDINT_H_HAVE_INT64
235 typedef int64_t  int_fast64_t;
236 #endif
237 #if !@HAVE_UINT_FAST64_T@ && _STDINT_H_HAVE_UINT64
238 typedef uint64_t uint_fast64_t;
239 #endif
240
241 /* 7.18.1.4. Integer types capable of holding object pointers */
242
243 /* On some platforms (like IRIX6 MIPS with -n32) sizeof(void*) < sizeof(long),
244    but this doesn't matter here.  */
245 #if !@HAVE_INTPTR_T@
246 typedef long          intptr_t;
247 #endif
248 #if !@HAVE_UINTPTR_T@
249 typedef unsigned long uintptr_t;
250 #endif
251
252 /* 7.18.1.5. Greatest-width integer types */
253
254 /* Note: These types are compiler dependent. It may be unwise to use them in
255    public header files. */
256
257 #if !@HAVE_INTMAX_T@
258 # ifdef _STDINT_H_HAVE_INT64
259 typedef int64_t  intmax_t;
260 # else
261 typedef int32_t  intmax_t;
262 # endif
263 #endif
264 #if !@HAVE_UINTMAX_T@
265 # ifdef _STDINT_H_HAVE_UINT64
266 typedef uint64_t uintmax_t;
267 # else
268 typedef uint32_t uintmax_t;
269 # endif
270 #endif
271
272 /* 7.18.2. Limits of specified-width integer types */
273
274 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
275
276 /* 7.18.2.1. Limits of exact-width integer types */
277
278 /* Here we assume a standard architecture where the hardware integer
279    types have 8, 16, 32, optionally 64 bits.  */
280
281 #if @HAVE_INT8_T@
282 # ifndef INT8_MIN
283 #  define INT8_MIN  (-1 << (@BITSIZEOF_INT8_T@ - 1))
284 # endif
285 #else
286 # define INT8_MIN  -128
287 #endif
288 #if @HAVE_INT8_T@
289 # ifndef INT8_MAX
290 #  define INT8_MAX  (~ (-1 << (@BITSIZEOF_INT8_T@ - 1)))
291 # endif
292 #else
293 # define INT8_MAX  127
294 #endif
295 #if @HAVE_UINT8_T@
296 # ifndef UINT8_MAX
297 #  if @BITSIZEOF_UINT8_T@ < @BITSIZEOF_UNSIGNED_INT@
298 #   define UINT8_MAX  (((1 << (@BITSIZEOF_UINT8_T@ - 1)) - 1) * 2 + 1)
299 #  else
300 #   define UINT8_MAX  (((1U << (@BITSIZEOF_UINT8_T@ - 1)) - 1) * 2 + 1)
301 #  endif
302 # endif
303 #else
304 # define UINT8_MAX  255
305 #endif
306
307 #if @HAVE_INT16_T@
308 # ifndef INT16_MIN
309 #  define INT16_MIN  (-1 << (@BITSIZEOF_INT16_T@ - 1))
310 # endif
311 #else
312 # define INT16_MIN  -32768
313 #endif
314 #if @HAVE_INT16_T@
315 # ifndef INT16_MAX
316 #  define INT16_MAX  (~ (-1 << (@BITSIZEOF_INT16_T@ - 1)))
317 # endif
318 #else
319 # define INT16_MAX  32767
320 #endif
321 #if @HAVE_UINT16_T@
322 # ifndef UINT16_MAX
323 #  if @BITSIZEOF_UINT16_T@ < @BITSIZEOF_UNSIGNED_INT@
324 #   define UINT16_MAX  (((1 << (@BITSIZEOF_UINT16_T@ - 1)) - 1) * 2 + 1)
325 #  else
326 #   define UINT16_MAX  (((1U << (@BITSIZEOF_UINT16_T@ - 1)) - 1) * 2 + 1)
327 #  endif
328 # endif
329 #else
330 # define UINT16_MAX  65535
331 #endif
332
333 #if @HAVE_INT32_T@
334 # ifndef INT32_MIN
335 #  define INT32_MIN  (-1 << (@BITSIZEOF_INT32_T@ - 1))
336 # endif
337 #else
338 # define INT32_MIN  (~INT32_MAX)
339 #endif
340 #if @HAVE_INT32_T@
341 # ifndef INT32_MAX
342 #  define INT32_MAX  (~ (-1 << (@BITSIZEOF_INT32_T@ - 1)))
343 # endif
344 #else
345 # define INT32_MAX  2147483647
346 #endif
347 #if @HAVE_UINT32_T@
348 # ifndef UINT32_MAX
349 #  if @BITSIZEOF_UINT32_T@ < @BITSIZEOF_UNSIGNED_INT@
350 #   define UINT32_MAX  (((1 << (@BITSIZEOF_UINT32_T@ - 1)) - 1) * 2 + 1)
351 #  else
352 #   define UINT32_MAX  (((1U << (@BITSIZEOF_UINT32_T@ - 1)) - 1) * 2 + 1)
353 #  endif
354 # endif
355 #else
356 # define UINT32_MAX  4294967295U
357 #endif
358
359 #if @HAVE_INT64_T@
360 # ifndef INT64_MIN
361 #  if @HAVE_LONG_64BIT@
362 #   define INT64_MIN  (-1L << (@BITSIZEOF_INT64_T@ - 1))
363 #  elif @HAVE_LONG_LONG_64BIT@
364 #   define INT64_MIN  (-1LL << (@BITSIZEOF_INT64_T@ - 1))
365 #  elif defined _MSC_VER
366 #   define INT64_MIN  (-1i64 << (@BITSIZEOF_INT64_T@ - 1))
367 #  endif
368 # endif
369 #else
370 # ifdef _STDINT_H_HAVE_INT64
371 #  define INT64_MIN  (~INT64_MAX)
372 # endif
373 #endif
374 #if @HAVE_INT64_T@
375 # ifndef INT64_MAX
376 #  if @HAVE_LONG_64BIT@
377 #   define INT64_MAX  (~ (-1L << (@BITSIZEOF_INT64_T@ - 1)))
378 #  elif @HAVE_LONG_LONG_64BIT@
379 #   define INT64_MAX  (~ (-1LL << (@BITSIZEOF_INT64_T@ - 1)))
380 #  elif defined _MSC_VER
381 #   define INT64_MAX  (~ (-1i64 << (@BITSIZEOF_INT64_T@ - 1)))
382 #  endif
383 # endif
384 #else
385 # ifdef _STDINT_H_HAVE_INT64
386 #  if @HAVE_LONG_64BIT@
387 #   define INT64_MAX  9223372036854775807L
388 #  elif @HAVE_LONG_LONG_64BIT@
389 #   define INT64_MAX  9223372036854775807LL
390 #  elif defined _MSC_VER
391 #   define INT64_MAX  9223372036854775807i64
392 #  endif
393 # endif
394 #endif
395 #if @HAVE_UINT64_T@
396 # ifndef UINT64_MAX
397 #  if @HAVE_LONG_64BIT@
398 #   define UINT64_MAX  (((1UL << (@BITSIZEOF_UINT64_T@ - 1)) - 1) * 2 + 1)
399 #  elif @HAVE_LONG_LONG_64BIT@
400 #   define UINT64_MAX  (((1ULL << (@BITSIZEOF_UINT64_T@ - 1)) - 1) * 2 + 1)
401 #  elif defined _MSC_VER
402 #   define UINT64_MAX  (((1ui64 << (@BITSIZEOF_UINT64_T@ - 1)) - 1) * 2 + 1)
403 #  endif
404 # endif
405 #else
406 # ifdef _STDINT_H_HAVE_UINT64
407 #  if @HAVE_LONG_64BIT@
408 #   define UINT64_MAX 18446744073709551615UL
409 #  elif @HAVE_LONG_LONG_64BIT@
410 #   define UINT64_MAX 18446744073709551615ULL
411 #  elif defined _MSC_VER
412 #   define UINT64_MAX 18446744073709551615ui64
413 #  endif
414 # endif
415 #endif
416
417 /* 7.18.2.2. Limits of minimum-width integer types */
418
419 /* Here we assume a standard architecture where the hardware integer
420    types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
421    are the same as the corresponding N_t types.  */
422
423 #if @HAVE_INT_LEAST8_T@
424 # ifndef INT_LEAST8_MIN
425 #  define INT_LEAST8_MIN  (-1 << (@BITSIZEOF_INT_LEAST8_T@ - 1))
426 # endif
427 #else
428 # define INT_LEAST8_MIN  INT8_MIN
429 #endif
430 #if @HAVE_INT_LEAST8_T@
431 # ifndef INT_LEAST8_MAX
432 #  define INT_LEAST8_MAX  (~ (-1 << (@BITSIZEOF_INT_LEAST8_T@ - 1)))
433 # endif
434 #else
435 # define INT_LEAST8_MAX  INT8_MAX
436 #endif
437 #if @HAVE_UINT_LEAST8_T@
438 # ifndef UINT_LEAST8_MAX
439 #  if @BITSIZEOF_UINT_LEAST8_T@ < @BITSIZEOF_UNSIGNED_INT@
440 #   define UINT_LEAST8_MAX  (((1 << (@BITSIZEOF_UINT_LEAST8_T@ - 1)) - 1) * 2 + 1)
441 #  else
442 #   define UINT_LEAST8_MAX  (((1U << (@BITSIZEOF_UINT_LEAST8_T@ - 1)) - 1) * 2 + 1)
443 #  endif
444 # endif
445 #else
446 # define UINT_LEAST8_MAX  UINT8_MAX
447 #endif
448
449 #if @HAVE_INT_LEAST16_T@
450 # ifndef INT_LEAST16_MIN
451 #  define INT_LEAST16_MIN  (-1 << (@BITSIZEOF_INT_LEAST16_T@ - 1))
452 # endif
453 #else
454 # define INT_LEAST16_MIN  INT16_MIN
455 #endif
456 #if @HAVE_INT_LEAST16_T@
457 # ifndef INT_LEAST16_MAX
458 #  define INT_LEAST16_MAX  (~ (-1 << (@BITSIZEOF_INT_LEAST16_T@ - 1)))
459 # endif
460 #else
461 # define INT_LEAST16_MAX  INT16_MAX
462 #endif
463 #if @HAVE_UINT_LEAST16_T@
464 # ifndef UINT_LEAST16_MAX
465 #  if @BITSIZEOF_UINT_LEAST16_T@ < @BITSIZEOF_UNSIGNED_INT@
466 #   define UINT_LEAST16_MAX  (((1 << (@BITSIZEOF_UINT_LEAST16_T@ - 1)) - 1) * 2 + 1)
467 #  else
468 #   define UINT_LEAST16_MAX  (((1U << (@BITSIZEOF_UINT_LEAST16_T@ - 1)) - 1) * 2 + 1)
469 #  endif
470 # endif
471 #else
472 # define UINT_LEAST16_MAX  UINT16_MAX
473 #endif
474
475 #if @HAVE_INT_LEAST32_T@
476 # ifndef INT_LEAST32_MIN
477 #  define INT_LEAST32_MIN  (-1 << (@BITSIZEOF_INT_LEAST32_T@ - 1))
478 # endif
479 #else
480 # define INT_LEAST32_MIN  INT32_MIN
481 #endif
482 #if @HAVE_INT_LEAST32_T@
483 # ifndef INT_LEAST32_MAX
484 #  define INT_LEAST32_MAX  (~ (-1 << (@BITSIZEOF_INT_LEAST32_T@ - 1)))
485 # endif
486 #else
487 # define INT_LEAST32_MAX  INT32_MAX
488 #endif
489 #if @HAVE_UINT_LEAST32_T@
490 # ifndef UINT_LEAST32_MAX
491 #  if @BITSIZEOF_UINT_LEAST32_T@ < @BITSIZEOF_UNSIGNED_INT@
492 #   define UINT_LEAST32_MAX  (((1 << (@BITSIZEOF_UINT_LEAST32_T@ - 1)) - 1) * 2 + 1)
493 #  else
494 #   define UINT_LEAST32_MAX  (((1U << (@BITSIZEOF_UINT_LEAST32_T@ - 1)) - 1) * 2 + 1)
495 #  endif
496 # endif
497 #else
498 # define UINT_LEAST32_MAX  UINT32_MAX
499 #endif
500
501 #if @HAVE_INT_LEAST64_T@
502 # ifndef INT_LEAST64_MIN
503 #  if @HAVE_LONG_64BIT@
504 #   define INT_LEAST64_MIN  (-1L << (@BITSIZEOF_INT_LEAST64_T@ - 1))
505 #  elif @HAVE_LONG_LONG_64BIT@
506 #   define INT_LEAST64_MIN  (-1LL << (@BITSIZEOF_INT_LEAST64_T@ - 1))
507 #  elif defined _MSC_VER
508 #   define INT_LEAST64_MIN  (-1i64 << (@BITSIZEOF_INT_LEAST64_T@ - 1))
509 #  endif
510 # endif
511 #else
512 # ifdef _STDINT_H_HAVE_INT64
513 #  define INT_LEAST64_MIN  INT64_MIN
514 # endif
515 #endif
516 #if @HAVE_INT_LEAST64_T@
517 # ifndef INT_LEAST64_MAX
518 #  if @HAVE_LONG_64BIT@
519 #   define INT_LEAST64_MAX  (~ (-1L << (@BITSIZEOF_INT_LEAST64_T@ - 1)))
520 #  elif @HAVE_LONG_LONG_64BIT@
521 #   define INT_LEAST64_MAX  (~ (-1LL << (@BITSIZEOF_INT_LEAST64_T@ - 1)))
522 #  elif defined _MSC_VER
523 #   define INT_LEAST64_MAX  (~ (-1i64 << (@BITSIZEOF_INT_LEAST64_T@ - 1)))
524 #  endif
525 # endif
526 #else
527 # ifdef _STDINT_H_HAVE_INT64
528 #  define INT_LEAST64_MAX  INT64_MAX
529 # endif
530 #endif
531 #if @HAVE_UINT_LEAST64_T@
532 # ifndef UINT_LEAST64_MAX
533 #  if @HAVE_LONG_64BIT@
534 #   define UINT_LEAST64_MAX  (((1UL << (@BITSIZEOF_UINT_LEAST64_T@ - 1)) - 1) * 2 + 1)
535 #  elif @HAVE_LONG_LONG_64BIT@
536 #   define UINT_LEAST64_MAX  (((1ULL << (@BITSIZEOF_UINT_LEAST64_T@ - 1)) - 1) * 2 + 1)
537 #  elif defined _MSC_VER
538 #   define UINT_LEAST64_MAX  (((1ui64 << (@BITSIZEOF_UINT_LEAST64_T@ - 1)) - 1) * 2 + 1)
539 #  endif
540 # endif
541 #else
542 # ifdef _STDINT_H_HAVE_UINT64
543 #  define UINT_LEAST64_MAX  UINT64_MAX
544 # endif
545 #endif
546
547 /* 7.18.2.3. Limits of fastest minimum-width integer types */
548
549 /* Here we assume a standard architecture where the hardware integer
550    types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
551    are taken from the same list of types.  */
552
553 #if @HAVE_INT_FAST8_T@
554 # ifndef INT_FAST8_MIN
555 #  define INT_FAST8_MIN  (-1L << (@BITSIZEOF_INT_FAST8_T@ - 1))
556 # endif
557 #else
558 # if _STDINT_H_INT64_FASTER_THAN_INT32
559 #  define INT_FAST8_MIN  INT64_MIN
560 # else
561 #  define INT_FAST8_MIN  INT32_MIN
562 # endif
563 #endif
564 #if @HAVE_INT_FAST8_T@
565 # ifndef INT_FAST8_MAX
566 #  define INT_FAST8_MAX  (~ (-1L << (@BITSIZEOF_INT_FAST8_T@ - 1)))
567 # endif
568 #else
569 # if _STDINT_H_INT64_FASTER_THAN_INT32
570 #  define INT_FAST8_MAX  INT64_MAX
571 # else
572 #  define INT_FAST8_MAX  INT32_MAX
573 # endif
574 #endif
575 #if @HAVE_UINT_FAST8_T@
576 # ifndef UINT_FAST8_MAX
577 #  if @BITSIZEOF_UINT_FAST8_T@ < @BITSIZEOF_UNSIGNED_INT@
578 #   define UINT_FAST8_MAX  (((1 << (@BITSIZEOF_UINT_FAST8_T@ - 1)) - 1) * 2 + 1)
579 #  else
580 #   define UINT_FAST8_MAX  (((1UL << (@BITSIZEOF_UINT_FAST8_T@ - 1)) - 1) * 2 + 1)
581 #  endif
582 # endif
583 #else
584 # if _STDINT_H_INT64_FASTER_THAN_INT32
585 #  define UINT_FAST8_MAX  UINT64_MAX
586 # else
587 #  define UINT_FAST8_MAX  UINT32_MAX
588 # endif
589 #endif
590
591 #if @HAVE_INT_FAST16_T@
592 # ifndef INT_FAST16_MIN
593 #  define INT_FAST16_MIN  (-1L << (@BITSIZEOF_INT_FAST16_T@ - 1))
594 # endif
595 #else
596 # if _STDINT_H_INT64_FASTER_THAN_INT32
597 #  define INT_FAST16_MIN  INT64_MIN
598 # else
599 #  define INT_FAST16_MIN  INT32_MIN
600 # endif
601 #endif
602 #if @HAVE_INT_FAST16_T@
603 # ifndef INT_FAST16_MAX
604 #  define INT_FAST16_MAX  (~ (-1L << (@BITSIZEOF_INT_FAST16_T@ - 1)))
605 # endif
606 #else
607 # if _STDINT_H_INT64_FASTER_THAN_INT32
608 #  define INT_FAST16_MAX  INT64_MAX
609 # else
610 #  define INT_FAST16_MAX  INT32_MAX
611 # endif
612 #endif
613 #if @HAVE_UINT_FAST16_T@
614 # ifndef UINT_FAST16_MAX
615 #  if @BITSIZEOF_UINT_FAST16_T@ < @BITSIZEOF_UNSIGNED_INT@
616 #   define UINT_FAST16_MAX  (((1 << (@BITSIZEOF_UINT_FAST16_T@ - 1)) - 1) * 2 + 1)
617 #  else
618 #   define UINT_FAST16_MAX  (((1UL << (@BITSIZEOF_UINT_FAST16_T@ - 1)) - 1) * 2 + 1)
619 #  endif
620 # endif
621 #else
622 # if _STDINT_H_INT64_FASTER_THAN_INT32
623 #  define UINT_FAST16_MAX  UINT64_MAX
624 # else
625 #  define UINT_FAST16_MAX  UINT32_MAX
626 # endif
627 #endif
628
629 #if @HAVE_INT_FAST32_T@
630 # ifndef INT_FAST32_MIN
631 #  define INT_FAST32_MIN  (-1L << (@BITSIZEOF_INT_FAST32_T@ - 1))
632 # endif
633 #else
634 # if _STDINT_H_INT64_FASTER_THAN_INT32
635 #  define INT_FAST32_MIN  INT64_MIN
636 # else
637 #  define INT_FAST32_MIN  INT32_MIN
638 # endif
639 #endif
640 #if @HAVE_INT_FAST32_T@
641 # ifndef INT_FAST32_MAX
642 #  define INT_FAST32_MAX  (~ (-1L << (@BITSIZEOF_INT_FAST32_T@ - 1)))
643 # endif
644 #else
645 # if _STDINT_H_INT64_FASTER_THAN_INT32
646 #  define INT_FAST32_MAX  INT64_MAX
647 # else
648 #  define INT_FAST32_MAX  INT32_MAX
649 # endif
650 #endif
651 #if @HAVE_UINT_FAST32_T@
652 # ifndef UINT_FAST32_MAX
653 #  if @BITSIZEOF_UINT_FAST32_T@ < @BITSIZEOF_UNSIGNED_INT@
654 #   define UINT_FAST32_MAX  (((1 << (@BITSIZEOF_UINT_FAST32_T@ - 1)) - 1) * 2 + 1)
655 #  else
656 #   define UINT_FAST32_MAX  (((1UL << (@BITSIZEOF_UINT_FAST32_T@ - 1)) - 1) * 2 + 1)
657 #  endif
658 # endif
659 #else
660 # if _STDINT_H_INT64_FASTER_THAN_INT32
661 #  define UINT_FAST32_MAX  UINT64_MAX
662 # else
663 #  define UINT_FAST32_MAX  UINT32_MAX
664 # endif
665 #endif
666
667 #if @HAVE_INT_FAST64_T@
668 # ifndef INT_FAST64_MIN
669 #  if @HAVE_LONG_64BIT@
670 #   define INT_FAST64_MIN  (-1L << (@BITSIZEOF_INT_FAST64_T@ - 1))
671 #  elif @HAVE_LONG_LONG_64BIT@
672 #   define INT_FAST64_MIN  (-1LL << (@BITSIZEOF_INT_FAST64_T@ - 1))
673 #  elif defined _MSC_VER
674 #   define INT_FAST64_MIN  (-1i64 << (@BITSIZEOF_INT_FAST64_T@ - 1))
675 #  endif
676 # endif
677 #else
678 # ifdef _STDINT_H_HAVE_INT64
679 #  define INT_FAST64_MIN  INT64_MIN
680 # endif
681 #endif
682 #if @HAVE_INT_FAST64_T@
683 # ifndef INT_FAST64_MAX
684 #  if @HAVE_LONG_64BIT@
685 #   define INT_FAST64_MAX  (~ (-1L << (@BITSIZEOF_INT_FAST64_T@ - 1)))
686 #  elif @HAVE_LONG_LONG_64BIT@
687 #   define INT_FAST64_MAX  (~ (-1LL << (@BITSIZEOF_INT_FAST64_T@ - 1)))
688 #  elif defined _MSC_VER
689 #   define INT_FAST64_MAX  (~ (-1i64 << (@BITSIZEOF_INT_FAST64_T@ - 1)))
690 #  endif
691 # endif
692 #else
693 # ifdef _STDINT_H_HAVE_INT64
694 #  define INT_FAST64_MAX  INT64_MAX
695 # endif
696 #endif
697 #if @HAVE_UINT_FAST64_T@
698 # ifndef UINT_FAST64_MAX
699 #  if @HAVE_LONG_64BIT@
700 #   define UINT_FAST64_MAX  (((1UL << (@BITSIZEOF_UINT_FAST64_T@ - 1)) - 1) * 2 + 1)
701 #  elif @HAVE_LONG_LONG_64BIT@
702 #   define UINT_FAST64_MAX  (((1ULL << (@BITSIZEOF_UINT_FAST64_T@ - 1)) - 1) * 2 + 1)
703 #  elif defined _MSC_VER
704 #   define UINT_FAST64_MAX  (((1ui64 << (@BITSIZEOF_UINT_FAST64_T@ - 1)) - 1) * 2 + 1)
705 #  endif
706 # endif
707 #else
708 # ifdef _STDINT_H_HAVE_UINT64
709 #  define UINT_FAST64_MAX  UINT64_MAX
710 # endif
711 #endif
712
713 /* 7.18.2.4. Limits of integer types capable of holding object pointers */
714
715 #if @HAVE_INTPTR_T@
716 # ifndef INTPTR_MIN
717 #  if @BITSIZEOF_INTPTR_T@ > @BITSIZEOF_LONG@
718 #   define INTPTR_MIN  (-1LL << (@BITSIZEOF_INTPTR_T@ - 1))
719 #  else
720 #   define INTPTR_MIN  (-1L << (@BITSIZEOF_INTPTR_T@ - 1))
721 #  endif
722 # endif
723 #else
724 # define INTPTR_MIN  LONG_MIN
725 #endif
726 #if @HAVE_INTPTR_T@
727 # ifndef INTPTR_MAX
728 #  if @BITSIZEOF_INTPTR_T@ > @BITSIZEOF_LONG@
729 #   define INTPTR_MAX  (~ (-1LL << (@BITSIZEOF_INTPTR_T@ - 1)))
730 #  else
731 #   define INTPTR_MAX  (~ (-1L << (@BITSIZEOF_INTPTR_T@ - 1)))
732 #  endif
733 # endif
734 #else
735 # define INTPTR_MAX  LONG_MAX
736 #endif
737 #if @HAVE_UINTPTR_T@
738 # ifndef UINTPTR_MAX
739 #  if @BITSIZEOF_UINTPTR_T@ > @BITSIZEOF_UNSIGNED_LONG@
740 #   define UINTPTR_MAX  (((1ULL << (@BITSIZEOF_UINTPTR_T@ - 1)) - 1) * 2 + 1)
741 #  else
742 #   define UINTPTR_MAX  (((1UL << (@BITSIZEOF_UINTPTR_T@ - 1)) - 1) * 2 + 1)
743 #  endif
744 # endif
745 #else
746 # define UINTPTR_MAX  ULONG_MAX
747 #endif
748
749 /* 7.18.2.5. Limits of greatest-width integer types */
750
751 #if @HAVE_INTMAX_T@
752 # ifndef INTMAX_MIN
753 #  if @BITSIZEOF_INTMAX_T@ > @BITSIZEOF_LONG@
754 #   define INTMAX_MIN  (-1LL << (@BITSIZEOF_INTMAX_T@ - 1))
755 #  else
756 #   define INTMAX_MIN  (-1L << (@BITSIZEOF_INTMAX_T@ - 1))
757 #  endif
758 # endif
759 #else
760 # ifdef _STDINT_H_HAVE_INT64
761 #  define INTMAX_MIN  INT64_MIN
762 # else
763 #  define INTMAX_MIN  INT32_MIN
764 # endif
765 #endif
766 #if @HAVE_INTMAX_T@
767 # ifndef INTMAX_MAX
768 #  if @BITSIZEOF_INTMAX_T@ > @BITSIZEOF_LONG@
769 #   define INTMAX_MAX  (~ (-1LL << (@BITSIZEOF_INTMAX_T@ - 1)))
770 #  else
771 #   define INTMAX_MAX  (~ (-1L << (@BITSIZEOF_INTMAX_T@ - 1)))
772 #  endif
773 # endif
774 #else
775 # ifdef _STDINT_H_HAVE_INT64
776 #  define INTMAX_MAX  INT64_MAX
777 # else
778 #  define INTMAX_MAX  INT32_MAX
779 # endif
780 #endif
781 #if @HAVE_UINTMAX_T@
782 # ifndef UINTMAX_MAX
783 #  if @BITSIZEOF_UINTMAX_T@ > @BITSIZEOF_UNSIGNED_LONG@
784 #   define UINTMAX_MAX  (((1ULL << (@BITSIZEOF_UINTMAX_T@ - 1)) - 1) * 2 + 1)
785 #  else
786 #   define UINTMAX_MAX  (((1UL << (@BITSIZEOF_UINTMAX_T@ - 1)) - 1) * 2 + 1)
787 #  endif
788 # endif
789 #else
790 # ifdef _STDINT_H_HAVE_INT64
791 #  define UINTMAX_MAX  UINT64_MAX
792 # else
793 #  define UINTMAX_MAX  UINT32_MAX
794 # endif
795 #endif
796
797 /* 7.18.3. Limits of other integer types */
798
799 /* ptrdiff_t limits */
800 #ifndef PTRDIFF_MIN
801 # if @BITSIZEOF_PTRDIFF_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_PTRDIFF_T_LONG@
802 #  define PTRDIFF_MIN  (-1L << (@BITSIZEOF_PTRDIFF_T@ - 1))
803 # else
804 #  define PTRDIFF_MIN  (-1 << (@BITSIZEOF_PTRDIFF_T@ - 1))
805 # endif
806 #endif
807 #ifndef PTRDIFF_MAX
808 # if @BITSIZEOF_PTRDIFF_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_PTRDIFF_T_LONG@
809 #  define PTRDIFF_MAX  (~ (-1L << (@BITSIZEOF_PTRDIFF_T@ - 1)))
810 # else
811 #  define PTRDIFF_MAX  (~ (-1 << (@BITSIZEOF_PTRDIFF_T@ - 1)))
812 # endif
813 #endif
814
815 /* sig_atomic_t limits */
816 #ifndef SIG_ATOMIC_MIN
817 # if @HAVE_SIGNED_SIG_ATOMIC_T@
818 #  if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_LONG@
819 #   define SIG_ATOMIC_MIN  (-1L << (@BITSIZEOF_SIG_ATOMIC_T@ - 1))
820 #  else
821 #   define SIG_ATOMIC_MIN  (-1 << (@BITSIZEOF_SIG_ATOMIC_T@ - 1))
822 #  endif
823 # else
824 #  if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_UNSIGNED_LONG@
825 #   define SIG_ATOMIC_MIN  0UL
826 #  elif @BITSIZEOF_SIG_ATOMIC_T@ >= @BITSIZEOF_UNSIGNED_INT@
827 #   define SIG_ATOMIC_MIN  0U
828 #  else
829 #   define SIG_ATOMIC_MIN  0
830 #  endif
831 # endif
832 #endif
833 #ifndef SIG_ATOMIC_MAX
834 # if @HAVE_SIGNED_SIG_ATOMIC_T@
835 #  if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_LONG@
836 #   define SIG_ATOMIC_MAX  (~ (-1L << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)))
837 #  else
838 #   define SIG_ATOMIC_MAX  (~ (-1 << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)))
839 #  endif
840 # else
841 #  if @BITSIZEOF_SIG_ATOMIC_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_SIG_ATOMIC_T_UNSIGNED_LONG@
842 #   define SIG_ATOMIC_MAX  (((1UL << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)) - 1) * 2 + 1)
843 #  elif @BITSIZEOF_SIG_ATOMIC_T@ >= @BITSIZEOF_UNSIGNED_INT@
844 #   define SIG_ATOMIC_MAX  (((1U << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)) - 1) * 2 + 1)
845 #  else
846 #   define SIG_ATOMIC_MAX  (((1 << (@BITSIZEOF_SIG_ATOMIC_T@ - 1)) - 1) * 2 + 1)
847 #  endif
848 # endif
849 #endif
850
851 /* size_t limit */
852 #ifndef SIZE_MAX /* SIZE_MAX may also be defined in config.h. */
853 # if @BITSIZEOF_SIZE_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_SIZE_T_UNSIGNED_LONG@
854 #  define SIZE_MAX  (((1UL << (@BITSIZEOF_SIZE_T@ - 1)) - 1) * 2 + 1)
855 # else
856 #  define SIZE_MAX  (((1U << (@BITSIZEOF_SIZE_T@ - 1)) - 1) * 2 + 1)
857 # endif
858 #endif
859
860 /* wchar_t limits may already be defined in <stddef.h>.  */
861 #ifndef WCHAR_MIN
862 # if @HAVE_SIGNED_WCHAR_T@
863 #  if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WCHAR_T_LONG@
864 #   define WCHAR_MIN  (-1L << (@BITSIZEOF_WCHAR_T@ - 1))
865 #  else
866 #   define WCHAR_MIN  (-1 << (@BITSIZEOF_WCHAR_T@ - 1))
867 #  endif
868 # else
869 #  if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WCHAR_T_UNSIGNED_LONG@
870 #   define WCHAR_MIN  0UL
871 #  elif @BITSIZEOF_WCHAR_T@ >= @BITSIZEOF_UNSIGNED_INT@
872 #   define WCHAR_MIN  0U
873 #  else
874 #   define WCHAR_MIN  0
875 #  endif
876 # endif
877 #endif
878 #ifndef WCHAR_MAX
879 # if @HAVE_SIGNED_WCHAR_T@
880 #  if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WCHAR_T_LONG@
881 #   define WCHAR_MAX  (~ (-1L << (@BITSIZEOF_WCHAR_T@ - 1)))
882 #  else
883 #   define WCHAR_MAX  (~ (-1 << (@BITSIZEOF_WCHAR_T@ - 1)))
884 #  endif
885 # else
886 #  if @BITSIZEOF_WCHAR_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WCHAR_T_UNSIGNED_LONG@
887 #   define WCHAR_MAX  (((1UL << (@BITSIZEOF_WCHAR_T@ - 1)) - 1) * 2 + 1)
888 #  elif @BITSIZEOF_WCHAR_T@ >= @BITSIZEOF_UNSIGNED_INT@
889 #   define WCHAR_MAX  (((1U << (@BITSIZEOF_WCHAR_T@ - 1)) - 1) * 2 + 1)
890 #  else
891 #   define WCHAR_MAX  (((1 << (@BITSIZEOF_WCHAR_T@ - 1)) - 1) * 2 + 1)
892 #  endif
893 # endif
894 #endif
895
896 /* wint_t limits */
897 #ifndef WINT_MIN
898 # if @HAVE_SIGNED_WINT_T@
899 #  if @BITSIZEOF_WINT_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WINT_T_LONG@
900 #   define WINT_MIN  (-1L << (@BITSIZEOF_WINT_T@ - 1))
901 #  else
902 #   define WINT_MIN  (-1 << (@BITSIZEOF_WINT_T@ - 1))
903 #  endif
904 # else
905 #  if @BITSIZEOF_WINT_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WINT_T_UNSIGNED_LONG@
906 #   define WINT_MIN  0UL
907 #  elif @BITSIZEOF_WINT_T@ >= @BITSIZEOF_UNSIGNED_INT@
908 #   define WINT_MIN  0U
909 #  else
910 #   define WINT_MIN  0
911 #  endif
912 # endif
913 #endif
914 #ifndef WINT_MAX
915 # if @HAVE_SIGNED_WINT_T@
916 #  if @BITSIZEOF_WINT_T@ > @BITSIZEOF_LONG@ || @SAME_TYPE_WINT_T_LONG@
917 #   define WINT_MAX  (~ (-1L << (@BITSIZEOF_WINT_T@ - 1)))
918 #  else
919 #   define WINT_MAX  (~ (-1 << (@BITSIZEOF_WINT_T@ - 1)))
920 #  endif
921 # else
922 #  if @BITSIZEOF_WINT_T@ > @BITSIZEOF_UNSIGNED_LONG@ || @SAME_TYPE_WINT_T_UNSIGNED_LONG@
923 #   define WINT_MAX  (((1UL << (@BITSIZEOF_WINT_T@ - 1)) - 1) * 2 + 1)
924 #  elif @BITSIZEOF_WINT_T@ >= @BITSIZEOF_UNSIGNED_INT@
925 #   define WINT_MAX  (((1U << (@BITSIZEOF_WINT_T@ - 1)) - 1) * 2 + 1)
926 #  else
927 #   define WINT_MAX  (((1 << (@BITSIZEOF_WINT_T@ - 1)) - 1) * 2 + 1)
928 #  endif
929 # endif
930 #endif
931
932 #endif
933
934 /* 7.18.4. Macros for integer constants */
935
936 #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
937
938 /* 7.18.4.1. Macros for minimum-width integer constants */
939 /* According to ISO C 99 Technical Corrigendum 1 */
940
941 #undef INT8_C
942 #undef UINT8_C
943 #define INT8_C(x) x
944 #if @HAVE_UINT8_T@
945 # if @BITSIZEOF_UINT8_T@ < @BITSIZEOF_UNSIGNED_INT@
946 #  define UINT8_C(x) x
947 # else
948 #  define UINT8_C(x) x##U
949 # endif
950 #else
951 # define UINT8_C(x) x
952 #endif
953
954 #undef INT16_C
955 #undef UINT16_C
956 #define INT16_C(x) x
957 #if @HAVE_UINT16_T@
958 # if @BITSIZEOF_UINT16_T@ < @BITSIZEOF_UNSIGNED_INT@
959 #  define UINT16_C(x) x
960 # else
961 #  define UINT16_C(x) x##U
962 # endif
963 #else
964 # define UINT16_C(x) x
965 #endif
966
967 #undef INT32_C
968 #undef UINT32_C
969 #define INT32_C(x) x
970 #if @HAVE_UINT32_T@
971 # if @BITSIZEOF_UINT32_T@ < @BITSIZEOF_UNSIGNED_INT@
972 #  define UINT32_C(x) x
973 # else
974 #  define UINT32_C(x) x##U
975 # endif
976 #else
977 # define UINT32_C(x) x
978 #endif
979
980 #undef INT64_C
981 #undef UINT64_C
982 #if @HAVE_LONG_64BIT@
983 # define INT64_C(x) x##L
984 # define UINT64_C(x) x##UL
985 #elif @HAVE_LONG_LONG_64BIT@
986 # define INT64_C(x) x##LL
987 # define UINT64_C(x) x##ULL
988 #elif defined(_MSC_VER)
989 # define INT64_C(x) x##i64
990 # define UINT64_C(x) x##ui64
991 #endif
992
993 /* 7.18.4.2. Macros for greatest-width integer constants */
994
995 #undef INTMAX_C
996 #undef UINTMAX_C
997 #if @HAVE_LONG_64BIT@
998 # define INTMAX_C(x) x##L
999 # define UINTMAX_C(x) x##UL
1000 #elif @HAVE_LONG_LONG_64BIT@
1001 # define INTMAX_C(x) x##LL
1002 # define UINTMAX_C(x) x##ULL
1003 #elif defined(_MSC_VER)
1004 # define INTMAX_C(x) x##i64
1005 # define UINTMAX_C(x) x##ui64
1006 #else
1007 # define INTMAX_C(x) x
1008 # define UINTMAX_C(x) x##U
1009 #endif
1010
1011 #endif
1012
1013 #endif /* _STDINT_H */