1 /* Copyright (C) 2001-2002, 2004-2007 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>
26 /* Get those types that are already defined in other system include
27 files, so that we can "#define int8_t signed char" below without
28 worrying about a later system include file containing a "typedef
29 signed char int8_t;" that will get messed up by our macro. Our
30 macros should all be consistent with the system versions, except
31 for the "fast" types and macros, which we recommend against using
32 in public interfaces due to compiler differences. */
35 # if defined __sgi && ! defined __c99
36 /* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users
37 with "This header file is to be used only for c99 mode compilations"
41 /* Other systems may have an incomplete or buggy <stdint.h>.
42 Include it before <inttypes.h>, since any "#include <stdint.h>"
43 in <inttypes.h> would reinclude us, skipping our contents because
44 _GL_STDINT_H is defined.
45 The include_next requires a split double-inclusion guard. */
46 # if @HAVE_INCLUDE_NEXT@
47 # include_next <stdint.h>
49 # include @ABSOLUTE_STDINT_H@
56 /* <sys/types.h> defines some of the stdint.h types as well, on glibc,
57 IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
58 AIX 5.2 <sys/types.h> isn't needed and causes troubles.
59 MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
60 relies on the system <stdint.h> definitions, so include
61 <sys/types.h> after @ABSOLUTE_STDINT_H@. */
62 #if @HAVE_SYS_TYPES_H@ && ! defined _AIX
63 # include <sys/types.h>
66 /* Get LONG_MIN, LONG_MAX, ULONG_MAX. */
70 /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
71 int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
72 <inttypes.h> also defines intptr_t and uintptr_t. */
73 # define _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
74 # include <inttypes.h>
75 # undef _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
76 #elif @HAVE_SYS_INTTYPES_H@
77 /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
78 the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
79 # include <sys/inttypes.h>
82 #if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__
83 /* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
84 int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is
85 included by <sys/types.h>. */
86 # include <sys/bitypes.h>
89 #if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
91 /* Get WCHAR_MIN, WCHAR_MAX. */
92 # if ! (defined WCHAR_MIN && defined WCHAR_MAX)
98 /* Minimum and maximum values for a integer type under the usual assumption.
99 Return an unspecified value if BITS == 0, adding a check to pacify
102 #define _STDINT_MIN(signed, bits, zero) \
103 ((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero))
105 #define _STDINT_MAX(signed, bits, zero) \
107 ? ~ _STDINT_MIN (signed, bits, zero) \
108 : ((((zero) + 1) << ((bits) ? (bits) - 1 : 0)) - 1) * 2 + 1)
110 /* 7.18.1.1. Exact-width integer types */
112 /* Here we assume a standard architecture where the hardware integer
113 types have 8, 16, 32, optionally 64 bits. */
117 #define int8_t signed char
118 #define uint8_t unsigned char
122 #define int16_t short int
123 #define uint16_t unsigned short int
128 #define uint32_t unsigned int
130 /* Do not undefine int64_t if gnulib is not being used with 64-bit
131 types, since otherwise it breaks platforms like Tandem/NSK. */
132 #if LONG_MAX >> 31 >> 31 == 1
134 # define int64_t long int
136 #elif defined _MSC_VER
138 # define int64_t __int64
140 #elif @HAVE_LONG_LONG_INT@
142 # define int64_t long long int
146 #if ULONG_MAX >> 31 >> 31 >> 1 == 1
148 # define uint64_t unsigned long int
150 #elif defined _MSC_VER
152 # define uint64_t unsigned __int64
154 #elif @HAVE_UNSIGNED_LONG_LONG_INT@
156 # define uint64_t unsigned long long int
160 /* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */
166 /* 7.18.1.2. Minimum-width integer types */
168 /* Here we assume a standard architecture where the hardware integer
169 types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
170 are the same as the corresponding N_t types. */
175 #undef uint_least16_t
177 #undef uint_least32_t
179 #undef uint_least64_t
180 #define int_least8_t int8_t
181 #define uint_least8_t uint8_t
182 #define int_least16_t int16_t
183 #define uint_least16_t uint16_t
184 #define int_least32_t int32_t
185 #define uint_least32_t uint32_t
187 # define int_least64_t int64_t
190 # define uint_least64_t uint64_t
193 /* 7.18.1.3. Fastest minimum-width integer types */
195 /* Note: Other <stdint.h> substitutes may define these types differently.
196 It is not recommended to use these types in public header files. */
198 /* Here we assume a standard architecture where the hardware integer
199 types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
200 are taken from the same list of types. Assume that 'long int'
201 is fast enough for all narrower integers. */
211 #define int_fast8_t long int
212 #define uint_fast8_t unsigned int_fast8_t
213 #define int_fast16_t long int
214 #define uint_fast16_t unsigned int_fast16_t
215 #define int_fast32_t long int
216 #define uint_fast32_t unsigned int_fast32_t
218 # define int_fast64_t int64_t
221 # define uint_fast64_t uint64_t
224 /* 7.18.1.4. Integer types capable of holding object pointers */
228 #define intptr_t long int
229 #define uintptr_t unsigned long int
231 /* 7.18.1.5. Greatest-width integer types */
233 /* Note: These types are compiler dependent. It may be unwise to use them in
234 public header files. */
237 #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
238 # define intmax_t long long int
239 #elif defined GL_INT64_T
240 # define intmax_t int64_t
242 # define intmax_t long int
246 #if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
247 # define uintmax_t unsigned long long int
248 #elif defined GL_UINT64_T
249 # define uintmax_t uint64_t
251 # define uintmax_t unsigned long int
254 /* 7.18.2. Limits of specified-width integer types */
256 #if ! defined __cplusplus || defined __STDC_LIMIT_MACROS
258 /* 7.18.2.1. Limits of exact-width integer types */
260 /* Here we assume a standard architecture where the hardware integer
261 types have 8, 16, 32, optionally 64 bits. */
266 #define INT8_MIN (~ INT8_MAX)
268 #define UINT8_MAX 255
273 #define INT16_MIN (~ INT16_MAX)
274 #define INT16_MAX 32767
275 #define UINT16_MAX 65535
280 #define INT32_MIN (~ INT32_MAX)
281 #define INT32_MAX 2147483647
282 #define UINT32_MAX 4294967295U
287 /* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0
288 evaluates the latter incorrectly in preprocessor expressions. */
289 # define INT64_MIN (- INTMAX_C (1) << 63)
290 # define INT64_MAX INTMAX_C (9223372036854775807)
295 # define UINT64_MAX UINTMAX_C (18446744073709551615)
298 /* 7.18.2.2. Limits of minimum-width integer types */
300 /* Here we assume a standard architecture where the hardware integer
301 types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
302 are the same as the corresponding N_t types. */
304 #undef INT_LEAST8_MIN
305 #undef INT_LEAST8_MAX
306 #undef UINT_LEAST8_MAX
307 #define INT_LEAST8_MIN INT8_MIN
308 #define INT_LEAST8_MAX INT8_MAX
309 #define UINT_LEAST8_MAX UINT8_MAX
311 #undef INT_LEAST16_MIN
312 #undef INT_LEAST16_MAX
313 #undef UINT_LEAST16_MAX
314 #define INT_LEAST16_MIN INT16_MIN
315 #define INT_LEAST16_MAX INT16_MAX
316 #define UINT_LEAST16_MAX UINT16_MAX
318 #undef INT_LEAST32_MIN
319 #undef INT_LEAST32_MAX
320 #undef UINT_LEAST32_MAX
321 #define INT_LEAST32_MIN INT32_MIN
322 #define INT_LEAST32_MAX INT32_MAX
323 #define UINT_LEAST32_MAX UINT32_MAX
325 #undef INT_LEAST64_MIN
326 #undef INT_LEAST64_MAX
328 # define INT_LEAST64_MIN INT64_MIN
329 # define INT_LEAST64_MAX INT64_MAX
332 #undef UINT_LEAST64_MAX
334 # define UINT_LEAST64_MAX UINT64_MAX
337 /* 7.18.2.3. Limits of fastest minimum-width integer types */
339 /* Here we assume a standard architecture where the hardware integer
340 types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
341 are taken from the same list of types. */
345 #undef UINT_FAST8_MAX
346 #define INT_FAST8_MIN LONG_MIN
347 #define INT_FAST8_MAX LONG_MAX
348 #define UINT_FAST8_MAX ULONG_MAX
350 #undef INT_FAST16_MIN
351 #undef INT_FAST16_MAX
352 #undef UINT_FAST16_MAX
353 #define INT_FAST16_MIN LONG_MIN
354 #define INT_FAST16_MAX LONG_MAX
355 #define UINT_FAST16_MAX ULONG_MAX
357 #undef INT_FAST32_MIN
358 #undef INT_FAST32_MAX
359 #undef UINT_FAST32_MAX
360 #define INT_FAST32_MIN LONG_MIN
361 #define INT_FAST32_MAX LONG_MAX
362 #define UINT_FAST32_MAX ULONG_MAX
364 #undef INT_FAST64_MIN
365 #undef INT_FAST64_MAX
367 # define INT_FAST64_MIN INT64_MIN
368 # define INT_FAST64_MAX INT64_MAX
371 #undef UINT_FAST64_MAX
373 # define UINT_FAST64_MAX UINT64_MAX
376 /* 7.18.2.4. Limits of integer types capable of holding object pointers */
381 #define INTPTR_MIN LONG_MIN
382 #define INTPTR_MAX LONG_MAX
383 #define UINTPTR_MAX ULONG_MAX
385 /* 7.18.2.5. Limits of greatest-width integer types */
390 # define INTMAX_MIN INT64_MIN
391 # define INTMAX_MAX INT64_MAX
393 # define INTMAX_MIN INT32_MIN
394 # define INTMAX_MAX INT32_MAX
399 # define UINTMAX_MAX UINT64_MAX
401 # define UINTMAX_MAX UINT32_MAX
404 /* 7.18.3. Limits of other integer types */
406 /* ptrdiff_t limits */
409 #define PTRDIFF_MIN \
410 _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
411 #define PTRDIFF_MAX \
412 _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
414 /* sig_atomic_t limits */
415 #undef SIG_ATOMIC_MIN
416 #undef SIG_ATOMIC_MAX
417 #define SIG_ATOMIC_MIN \
418 _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
419 0@SIG_ATOMIC_T_SUFFIX@)
420 #define SIG_ATOMIC_MAX \
421 _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
422 0@SIG_ATOMIC_T_SUFFIX@)
427 #define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@)
433 _STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
435 _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
441 _STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
443 _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
445 #endif /* !defined __cplusplus || defined __STDC_LIMIT_MACROS */
447 /* 7.18.4. Macros for integer constants */
449 #if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
451 /* 7.18.4.1. Macros for minimum-width integer constants */
452 /* According to ISO C 99 Technical Corrigendum 1 */
454 /* Here we assume a standard architecture where the hardware integer
455 types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */
465 #define UINT16_C(x) x
470 #define UINT32_C(x) x ## U
474 #if LONG_MAX >> 31 >> 31 == 1
475 # define INT64_C(x) x##L
476 #elif defined _MSC_VER
477 # define INT64_C(x) x##i64
478 #elif @HAVE_LONG_LONG_INT@
479 # define INT64_C(x) x##LL
481 #if ULONG_MAX >> 31 >> 31 >> 1 == 1
482 # define UINT64_C(x) x##UL
483 #elif defined _MSC_VER
484 # define UINT64_C(x) x##ui64
485 #elif @HAVE_UNSIGNED_LONG_LONG_INT@
486 # define UINT64_C(x) x##ULL
489 /* 7.18.4.2. Macros for greatest-width integer constants */
492 #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
493 # define INTMAX_C(x) x##LL
494 #elif defined GL_INT64_T
495 # define INTMAX_C(x) INT64_C(x)
497 # define INTMAX_C(x) x##L
501 #if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
502 # define UINTMAX_C(x) x##ULL
503 #elif defined GL_UINT64_T
504 # define UINTMAX_C(x) UINT64_C(x)
506 # define UINTMAX_C(x) x##UL
509 #endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */
511 #endif /* _GL_STDINT_H */
512 #endif /* _GL_STDINT_H */