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