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