1 /* Copyright (C) 2001-2002, 2004-2011 Free Software Foundation, Inc.
2 Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood.
3 This file is part of gnulib.
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)
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.
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. */
20 * ISO C 99 <stdint.h> for platforms that lack it.
21 * <http://www.opengroup.org/susv3xbd/stdint.h.html>
24 #ifndef _@GUARD_PREFIX@_STDINT_H
27 @PRAGMA_SYSTEM_HEADER@
31 /* When including a system file that in turn includes <inttypes.h>,
32 use the system <inttypes.h>, not our substitute. This avoids
33 problems with (for example) VMS, whose <sys/bitypes.h> includes
35 #define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
37 /* Get those types that are already defined in other system include
38 files, so that we can "#define int8_t signed char" below without
39 worrying about a later system include file containing a "typedef
40 signed char int8_t;" that will get messed up by our macro. Our
41 macros should all be consistent with the system versions, except
42 for the "fast" types and macros, which we recommend against using
43 in public interfaces due to compiler differences. */
46 # if defined __sgi && ! defined __c99
47 /* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users
48 with "This header file is to be used only for c99 mode compilations"
53 /* Some pre-C++11 <stdint.h> implementations need this. */
55 # ifndef __STDC_CONSTANT_MACROS
56 # define __STDC_CONSTANT_MACROS 1
58 # ifndef __STDC_LIMIT_MACROS
59 # define __STDC_LIMIT_MACROS 1
63 /* Other systems may have an incomplete or buggy <stdint.h>.
64 Include it before <inttypes.h>, since any "#include <stdint.h>"
65 in <inttypes.h> would reinclude us, skipping our contents because
66 _@GUARD_PREFIX@_STDINT_H is defined.
67 The include_next requires a split double-inclusion guard. */
68 # @INCLUDE_NEXT@ @NEXT_STDINT_H@
71 #if ! defined _@GUARD_PREFIX@_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
72 #define _@GUARD_PREFIX@_STDINT_H
74 /* <sys/types.h> defines some of the stdint.h types as well, on glibc,
75 IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
76 AIX 5.2 <sys/types.h> isn't needed and causes troubles.
77 MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
78 relies on the system <stdint.h> definitions, so include
79 <sys/types.h> after @NEXT_STDINT_H@. */
80 #if @HAVE_SYS_TYPES_H@ && ! defined _AIX
81 # include <sys/types.h>
84 /* Get LONG_MIN, LONG_MAX, ULONG_MAX. */
88 /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
89 int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
90 <inttypes.h> also defines intptr_t and uintptr_t. */
91 # include <inttypes.h>
92 #elif @HAVE_SYS_INTTYPES_H@
93 /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
94 the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
95 # include <sys/inttypes.h>
98 #if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__
99 /* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
100 int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is
101 included by <sys/types.h>. */
102 # include <sys/bitypes.h>
105 #undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
107 /* Minimum and maximum values for an integer type under the usual assumption.
108 Return an unspecified value if BITS == 0, adding a check to pacify
111 #define _STDINT_MIN(signed, bits, zero) \
112 ((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero))
114 #define _STDINT_MAX(signed, bits, zero) \
116 ? ~ _STDINT_MIN (signed, bits, zero) \
117 : /* The expression for the unsigned case. The subtraction of (signed) \
118 is a nop in the unsigned case and avoids "signed integer overflow" \
119 warnings in the signed case. */ \
120 ((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
122 #if !GNULIB_defined_stdint_types
124 /* 7.18.1.1. Exact-width integer types */
126 /* Here we assume a standard architecture where the hardware integer
127 types have 8, 16, 32, optionally 64 bits. */
131 typedef signed char gl_int8_t;
132 typedef unsigned char gl_uint8_t;
133 #define int8_t gl_int8_t
134 #define uint8_t gl_uint8_t
138 typedef short int gl_int16_t;
139 typedef unsigned short int gl_uint16_t;
140 #define int16_t gl_int16_t
141 #define uint16_t gl_uint16_t
145 typedef int gl_int32_t;
146 typedef unsigned int gl_uint32_t;
147 #define int32_t gl_int32_t
148 #define uint32_t gl_uint32_t
150 /* If the system defines INT64_MAX, assume int64_t works. That way,
151 if the underlying platform defines int64_t to be a 64-bit long long
152 int, the code below won't mistakenly define it to be a 64-bit long
153 int, which would mess up C++ name mangling. We must use #ifdef
154 rather than #if, to avoid an error with HP-UX 10.20 cc. */
159 /* Do not undefine int64_t if gnulib is not being used with 64-bit
160 types, since otherwise it breaks platforms like Tandem/NSK. */
161 # if LONG_MAX >> 31 >> 31 == 1
163 typedef long int gl_int64_t;
164 # define int64_t gl_int64_t
166 # elif defined _MSC_VER
168 typedef __int64 gl_int64_t;
169 # define int64_t gl_int64_t
171 # elif @HAVE_LONG_LONG_INT@
173 typedef long long int gl_int64_t;
174 # define int64_t gl_int64_t
182 # if ULONG_MAX >> 31 >> 31 >> 1 == 1
184 typedef unsigned long int gl_uint64_t;
185 # define uint64_t gl_uint64_t
187 # elif defined _MSC_VER
189 typedef unsigned __int64 gl_uint64_t;
190 # define uint64_t gl_uint64_t
192 # elif @HAVE_UNSIGNED_LONG_LONG_INT@
194 typedef unsigned long long int gl_uint64_t;
195 # define uint64_t gl_uint64_t
200 /* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */
206 /* 7.18.1.2. Minimum-width integer types */
208 /* Here we assume a standard architecture where the hardware integer
209 types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
210 are the same as the corresponding N_t types. */
215 #undef uint_least16_t
217 #undef uint_least32_t
219 #undef uint_least64_t
220 #define int_least8_t int8_t
221 #define uint_least8_t uint8_t
222 #define int_least16_t int16_t
223 #define uint_least16_t uint16_t
224 #define int_least32_t int32_t
225 #define uint_least32_t uint32_t
227 # define int_least64_t int64_t
230 # define uint_least64_t uint64_t
233 /* 7.18.1.3. Fastest minimum-width integer types */
235 /* Note: Other <stdint.h> substitutes may define these types differently.
236 It is not recommended to use these types in public header files. */
238 /* Here we assume a standard architecture where the hardware integer
239 types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
240 are taken from the same list of types. Assume that 'long int'
241 is fast enough for all narrower integers. */
251 typedef long int gl_int_fast8_t;
252 typedef unsigned long int gl_uint_fast8_t;
253 typedef long int gl_int_fast16_t;
254 typedef unsigned long int gl_uint_fast16_t;
255 typedef long int gl_int_fast32_t;
256 typedef unsigned long int gl_uint_fast32_t;
257 #define int_fast8_t gl_int_fast8_t
258 #define uint_fast8_t gl_uint_fast8_t
259 #define int_fast16_t gl_int_fast16_t
260 #define uint_fast16_t gl_uint_fast16_t
261 #define int_fast32_t gl_int_fast32_t
262 #define uint_fast32_t gl_uint_fast32_t
264 # define int_fast64_t int64_t
267 # define uint_fast64_t uint64_t
270 /* 7.18.1.4. Integer types capable of holding object pointers */
274 typedef long int gl_intptr_t;
275 typedef unsigned long int gl_uintptr_t;
276 #define intptr_t gl_intptr_t
277 #define uintptr_t gl_uintptr_t
279 /* 7.18.1.5. Greatest-width integer types */
281 /* Note: These types are compiler dependent. It may be unwise to use them in
282 public header files. */
284 /* If the system defines INTMAX_MAX, assume that intmax_t works, and
285 similarly for UINTMAX_MAX and uintmax_t. This avoids problems with
286 assuming one type where another is used by the system. */
291 # if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
292 typedef long long int gl_intmax_t;
293 # define intmax_t gl_intmax_t
294 # elif defined GL_INT64_T
295 # define intmax_t int64_t
297 typedef long int gl_intmax_t;
298 # define intmax_t gl_intmax_t
305 # if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
306 typedef unsigned long long int gl_uintmax_t;
307 # define uintmax_t gl_uintmax_t
308 # elif defined GL_UINT64_T
309 # define uintmax_t uint64_t
311 typedef unsigned long int gl_uintmax_t;
312 # define uintmax_t gl_uintmax_t
316 /* Verify that intmax_t and uintmax_t have the same size. Too much code
317 breaks if this is not the case. If this check fails, the reason is likely
318 to be found in the autoconf macros. */
319 typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
322 #define GNULIB_defined_stdint_types 1
323 #endif /* !GNULIB_defined_stdint_types */
325 /* 7.18.2. Limits of specified-width integer types */
327 /* 7.18.2.1. Limits of exact-width integer types */
329 /* Here we assume a standard architecture where the hardware integer
330 types have 8, 16, 32, optionally 64 bits. */
335 #define INT8_MIN (~ INT8_MAX)
337 #define UINT8_MAX 255
342 #define INT16_MIN (~ INT16_MAX)
343 #define INT16_MAX 32767
344 #define UINT16_MAX 65535
349 #define INT32_MIN (~ INT32_MAX)
350 #define INT32_MAX 2147483647
351 #define UINT32_MAX 4294967295U
353 #if defined GL_INT64_T && ! defined INT64_MAX
354 /* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0
355 evaluates the latter incorrectly in preprocessor expressions. */
356 # define INT64_MIN (- INTMAX_C (1) << 63)
357 # define INT64_MAX INTMAX_C (9223372036854775807)
360 #if defined GL_UINT64_T && ! defined UINT64_MAX
361 # define UINT64_MAX UINTMAX_C (18446744073709551615)
364 /* 7.18.2.2. Limits of minimum-width integer types */
366 /* Here we assume a standard architecture where the hardware integer
367 types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
368 are the same as the corresponding N_t types. */
370 #undef INT_LEAST8_MIN
371 #undef INT_LEAST8_MAX
372 #undef UINT_LEAST8_MAX
373 #define INT_LEAST8_MIN INT8_MIN
374 #define INT_LEAST8_MAX INT8_MAX
375 #define UINT_LEAST8_MAX UINT8_MAX
377 #undef INT_LEAST16_MIN
378 #undef INT_LEAST16_MAX
379 #undef UINT_LEAST16_MAX
380 #define INT_LEAST16_MIN INT16_MIN
381 #define INT_LEAST16_MAX INT16_MAX
382 #define UINT_LEAST16_MAX UINT16_MAX
384 #undef INT_LEAST32_MIN
385 #undef INT_LEAST32_MAX
386 #undef UINT_LEAST32_MAX
387 #define INT_LEAST32_MIN INT32_MIN
388 #define INT_LEAST32_MAX INT32_MAX
389 #define UINT_LEAST32_MAX UINT32_MAX
391 #undef INT_LEAST64_MIN
392 #undef INT_LEAST64_MAX
394 # define INT_LEAST64_MIN INT64_MIN
395 # define INT_LEAST64_MAX INT64_MAX
398 #undef UINT_LEAST64_MAX
400 # define UINT_LEAST64_MAX UINT64_MAX
403 /* 7.18.2.3. Limits of fastest minimum-width integer types */
405 /* Here we assume a standard architecture where the hardware integer
406 types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
407 are taken from the same list of types. */
411 #undef UINT_FAST8_MAX
412 #define INT_FAST8_MIN LONG_MIN
413 #define INT_FAST8_MAX LONG_MAX
414 #define UINT_FAST8_MAX ULONG_MAX
416 #undef INT_FAST16_MIN
417 #undef INT_FAST16_MAX
418 #undef UINT_FAST16_MAX
419 #define INT_FAST16_MIN LONG_MIN
420 #define INT_FAST16_MAX LONG_MAX
421 #define UINT_FAST16_MAX ULONG_MAX
423 #undef INT_FAST32_MIN
424 #undef INT_FAST32_MAX
425 #undef UINT_FAST32_MAX
426 #define INT_FAST32_MIN LONG_MIN
427 #define INT_FAST32_MAX LONG_MAX
428 #define UINT_FAST32_MAX ULONG_MAX
430 #undef INT_FAST64_MIN
431 #undef INT_FAST64_MAX
433 # define INT_FAST64_MIN INT64_MIN
434 # define INT_FAST64_MAX INT64_MAX
437 #undef UINT_FAST64_MAX
439 # define UINT_FAST64_MAX UINT64_MAX
442 /* 7.18.2.4. Limits of integer types capable of holding object pointers */
447 #define INTPTR_MIN LONG_MIN
448 #define INTPTR_MAX LONG_MAX
449 #define UINTPTR_MAX ULONG_MAX
451 /* 7.18.2.5. Limits of greatest-width integer types */
456 # define INTMAX_MIN INT64_MIN
457 # define INTMAX_MAX INT64_MAX
459 # define INTMAX_MIN INT32_MIN
460 # define INTMAX_MAX INT32_MAX
466 # define UINTMAX_MAX UINT64_MAX
468 # define UINTMAX_MAX UINT32_MAX
472 /* 7.18.3. Limits of other integer types */
474 /* ptrdiff_t limits */
477 #if @APPLE_UNIVERSAL_BUILD@
479 # define PTRDIFF_MIN _STDINT_MIN (1, 64, 0l)
480 # define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l)
482 # define PTRDIFF_MIN _STDINT_MIN (1, 32, 0)
483 # define PTRDIFF_MAX _STDINT_MAX (1, 32, 0)
486 # define PTRDIFF_MIN \
487 _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
488 # define PTRDIFF_MAX \
489 _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
492 /* sig_atomic_t limits */
493 #undef SIG_ATOMIC_MIN
494 #undef SIG_ATOMIC_MAX
495 #define SIG_ATOMIC_MIN \
496 _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
497 0@SIG_ATOMIC_T_SUFFIX@)
498 #define SIG_ATOMIC_MAX \
499 _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
500 0@SIG_ATOMIC_T_SUFFIX@)
505 #if @APPLE_UNIVERSAL_BUILD@
507 # define SIZE_MAX _STDINT_MAX (0, 64, 0ul)
509 # define SIZE_MAX _STDINT_MAX (0, 32, 0ul)
512 # define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@)
516 /* Get WCHAR_MIN, WCHAR_MAX.
517 This include is not on the top, above, because on OSF/1 4.0 we have a
518 sequence of nested includes
519 <wchar.h> -> <stdio.h> -> <getopt.h> -> <stdlib.h>, and the latter includes
520 <stdint.h> and assumes its types are already defined. */
521 #if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX)
522 /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
523 included before <wchar.h>. */
527 # define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
529 # undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
534 _STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
536 _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
542 _STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
544 _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
546 /* 7.18.4. Macros for integer constants */
548 /* 7.18.4.1. Macros for minimum-width integer constants */
549 /* According to ISO C 99 Technical Corrigendum 1 */
551 /* Here we assume a standard architecture where the hardware integer
552 types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */
562 #define UINT16_C(x) x
567 #define UINT32_C(x) x ## U
571 #if LONG_MAX >> 31 >> 31 == 1
572 # define INT64_C(x) x##L
573 #elif defined _MSC_VER
574 # define INT64_C(x) x##i64
575 #elif @HAVE_LONG_LONG_INT@
576 # define INT64_C(x) x##LL
578 #if ULONG_MAX >> 31 >> 31 >> 1 == 1
579 # define UINT64_C(x) x##UL
580 #elif defined _MSC_VER
581 # define UINT64_C(x) x##ui64
582 #elif @HAVE_UNSIGNED_LONG_LONG_INT@
583 # define UINT64_C(x) x##ULL
586 /* 7.18.4.2. Macros for greatest-width integer constants */
589 # if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
590 # define INTMAX_C(x) x##LL
591 # elif defined GL_INT64_T
592 # define INTMAX_C(x) INT64_C(x)
594 # define INTMAX_C(x) x##L
599 # if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
600 # define UINTMAX_C(x) x##ULL
601 # elif defined GL_UINT64_T
602 # define UINTMAX_C(x) UINT64_C(x)
604 # define UINTMAX_C(x) x##UL
608 #endif /* _@GUARD_PREFIX@_STDINT_H */
609 #endif /* !defined _@GUARD_PREFIX@_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */