1 // boost cstdint.hpp header file ------------------------------------------//
3 // (C) Copyright Beman Dawes 1999.
4 // (C) Copyright Jens Mauer 2001
5 // (C) Copyright John Maddock 2001
6 // Distributed under the Boost
7 // Software License, Version 1.0. (See accompanying file
8 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 // See http://www.boost.org/libs/integer for documentation.
13 // 31 Oct 01 use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
14 // 16 Apr 01 check LONGLONG_MAX when looking for "long long" (Jens Maurer)
15 // 23 Jan 01 prefer "long" over "int" for int32_t and intmax_t (Jens Maurer)
16 // 12 Nov 00 Merged <boost/stdint.h> (Jens Maurer)
17 // 23 Sep 00 Added INTXX_C macro support (John Maddock).
18 // 22 Sep 00 Better 64-bit support (John Maddock)
19 // 29 Jun 00 Reimplement to avoid including stdint.h within namespace boost
20 // 8 Aug 99 Initial version (Beman Dawes)
23 #ifndef BOOST_CSTDINT_HPP
24 #define BOOST_CSTDINT_HPP
27 // Since we always define the INT#_C macros as per C++0x,
28 // define __STDC_CONSTANT_MACROS so that <stdint.h> does the right
29 // thing if possible, and so that the user knows that the macros
30 // are actually defined as per C99.
32 #ifndef __STDC_CONSTANT_MACROS
33 # define __STDC_CONSTANT_MACROS
36 #include <boost/config.hpp>
38 // For the following code we get several warnings along the lines of:
40 // boost/cstdint.hpp:428:35: error: use of C99 long long integer constant
42 // So we declare this a system header to suppress these warnings.
43 // See also https://github.com/boostorg/config/issues/190
45 #if defined(__GNUC__) && (__GNUC__ >= 4)
46 #pragma GCC system_header
50 // Note that GLIBC is a bit inconsistent about whether int64_t is defined or not
51 // depending upon what headers happen to have been included first...
52 // so we disable use of stdint.h when GLIBC does not define __GLIBC_HAVE_LONG_LONG.
53 // See https://svn.boost.org/trac/boost/ticket/3548 and http://sources.redhat.com/bugzilla/show_bug.cgi?id=10990
55 #if defined(BOOST_HAS_STDINT_H) \
56 && (!defined(__GLIBC__) \
57 || defined(__GLIBC_HAVE_LONG_LONG) \
58 || (defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 17)))))
60 // The following #include is an implementation artifact; not part of interface.
62 // HP-UX has a vaguely nice <stdint.h> in a non-standard location
63 # include <inttypes.h>
64 # ifdef __STDC_32_MODE__
65 // this is triggered with GCC, because it defines __cplusplus < 199707L
66 # define BOOST_NO_INT64_T
68 # elif defined(__FreeBSD__) || defined(__IBMCPP__) || defined(_AIX)
69 # include <inttypes.h>
73 // There is a bug in Cygwin two _C macros
74 # if defined(INTMAX_C) && defined(__CYGWIN__)
77 # define INTMAX_C(c) c##LL
78 # define UINTMAX_C(c) c##ULL
83 #if defined(__QNX__) && defined(__EXT_QNX)
85 // QNX (Dinkumware stdlib) defines these as non-standard names.
86 // Reflect to the standard names.
88 typedef ::intleast8_t int_least8_t;
89 typedef ::intfast8_t int_fast8_t;
90 typedef ::uintleast8_t uint_least8_t;
91 typedef ::uintfast8_t uint_fast8_t;
93 typedef ::intleast16_t int_least16_t;
94 typedef ::intfast16_t int_fast16_t;
95 typedef ::uintleast16_t uint_least16_t;
96 typedef ::uintfast16_t uint_fast16_t;
98 typedef ::intleast32_t int_least32_t;
99 typedef ::intfast32_t int_fast32_t;
100 typedef ::uintleast32_t uint_least32_t;
101 typedef ::uintfast32_t uint_fast32_t;
103 # ifndef BOOST_NO_INT64_T
105 typedef ::intleast64_t int_least64_t;
106 typedef ::intfast64_t int_fast64_t;
107 typedef ::uintleast64_t uint_least64_t;
108 typedef ::uintfast64_t uint_fast64_t;
118 using ::int_least8_t;
121 using ::uint_least8_t;
122 using ::uint_fast8_t;
125 using ::int_least16_t;
126 using ::int_fast16_t;
128 using ::uint_least16_t;
129 using ::uint_fast16_t;
132 using ::int_least32_t;
133 using ::int_fast32_t;
135 using ::uint_least32_t;
136 using ::uint_fast32_t;
138 # ifndef BOOST_NO_INT64_T
141 using ::int_least64_t;
142 using ::int_fast64_t;
144 using ::uint_least64_t;
145 using ::uint_fast64_t;
154 #elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__) || defined(__VMS) || defined(__SOLARIS9__) || defined(__NetBSD__)
155 // FreeBSD and Tru64 have an <inttypes.h> that contains much of what we need.
156 # include <inttypes.h>
161 typedef int8_t int_least8_t;
162 typedef int8_t int_fast8_t;
164 typedef uint8_t uint_least8_t;
165 typedef uint8_t uint_fast8_t;
168 typedef int16_t int_least16_t;
169 typedef int16_t int_fast16_t;
171 typedef uint16_t uint_least16_t;
172 typedef uint16_t uint_fast16_t;
175 typedef int32_t int_least32_t;
176 typedef int32_t int_fast32_t;
178 typedef uint32_t uint_least32_t;
179 typedef uint32_t uint_fast32_t;
181 # ifndef BOOST_NO_INT64_T
184 typedef int64_t int_least64_t;
185 typedef int64_t int_fast64_t;
187 typedef uint64_t uint_least64_t;
188 typedef uint64_t uint_fast64_t;
190 typedef int64_t intmax_t;
191 typedef uint64_t uintmax_t;
195 typedef int32_t intmax_t;
196 typedef uint32_t uintmax_t;
202 #else // BOOST_HAS_STDINT_H
204 # include <boost/limits.hpp> // implementation artifact; not part of interface
205 # include <limits.h> // needed for limits macros
211 // These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
212 // platforms. For other systems, they will have to be hand tailored.
214 // Because the fast types are assumed to be the same as the undecorated types,
215 // it may be possible to hand tailor a more efficient implementation. Such
216 // an optimization may be illusionary; on the Intel x86-family 386 on, for
217 // example, byte arithmetic and load/stores are as fast as "int" sized ones.
219 // 8-bit types ------------------------------------------------------------//
221 # if UCHAR_MAX == 0xff
222 typedef signed char int8_t;
223 typedef signed char int_least8_t;
224 typedef signed char int_fast8_t;
225 typedef unsigned char uint8_t;
226 typedef unsigned char uint_least8_t;
227 typedef unsigned char uint_fast8_t;
229 # error defaults not correct; you must hand modify boost/cstdint.hpp
232 // 16-bit types -----------------------------------------------------------//
234 # if USHRT_MAX == 0xffff
235 # if defined(__crayx1)
236 // The Cray X1 has a 16-bit short, however it is not recommend
237 // for use in performance critical code.
238 typedef short int16_t;
239 typedef short int_least16_t;
240 typedef int int_fast16_t;
241 typedef unsigned short uint16_t;
242 typedef unsigned short uint_least16_t;
243 typedef unsigned int uint_fast16_t;
245 typedef short int16_t;
246 typedef short int_least16_t;
247 typedef short int_fast16_t;
248 typedef unsigned short uint16_t;
249 typedef unsigned short uint_least16_t;
250 typedef unsigned short uint_fast16_t;
252 # elif (USHRT_MAX == 0xffffffff) && defined(__MTA__)
253 // On MTA / XMT short is 32 bits unless the -short16 compiler flag is specified
254 // MTA / XMT does support the following non-standard integer types
255 typedef __short16 int16_t;
256 typedef __short16 int_least16_t;
257 typedef __short16 int_fast16_t;
258 typedef unsigned __short16 uint16_t;
259 typedef unsigned __short16 uint_least16_t;
260 typedef unsigned __short16 uint_fast16_t;
261 # elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
262 // no 16-bit types on Cray:
263 typedef short int_least16_t;
264 typedef short int_fast16_t;
265 typedef unsigned short uint_least16_t;
266 typedef unsigned short uint_fast16_t;
268 # error defaults not correct; you must hand modify boost/cstdint.hpp
271 // 32-bit types -----------------------------------------------------------//
273 # if UINT_MAX == 0xffffffff
275 typedef int int_least32_t;
276 typedef int int_fast32_t;
277 typedef unsigned int uint32_t;
278 typedef unsigned int uint_least32_t;
279 typedef unsigned int uint_fast32_t;
280 # elif (USHRT_MAX == 0xffffffff)
281 typedef short int32_t;
282 typedef short int_least32_t;
283 typedef short int_fast32_t;
284 typedef unsigned short uint32_t;
285 typedef unsigned short uint_least32_t;
286 typedef unsigned short uint_fast32_t;
287 # elif ULONG_MAX == 0xffffffff
288 typedef long int32_t;
289 typedef long int_least32_t;
290 typedef long int_fast32_t;
291 typedef unsigned long uint32_t;
292 typedef unsigned long uint_least32_t;
293 typedef unsigned long uint_fast32_t;
294 # elif (UINT_MAX == 0xffffffffffffffff) && defined(__MTA__)
295 // Integers are 64 bits on the MTA / XMT
296 typedef __int32 int32_t;
297 typedef __int32 int_least32_t;
298 typedef __int32 int_fast32_t;
299 typedef unsigned __int32 uint32_t;
300 typedef unsigned __int32 uint_least32_t;
301 typedef unsigned __int32 uint_fast32_t;
303 # error defaults not correct; you must hand modify boost/cstdint.hpp
306 // 64-bit types + intmax_t and uintmax_t ----------------------------------//
308 # if defined(BOOST_HAS_LONG_LONG) && \
309 !defined(BOOST_MSVC) && !defined(BOOST_BORLANDC) && \
310 (!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
311 (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
313 // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
314 # elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
317 # error defaults not correct; you must hand modify boost/cstdint.hpp
320 typedef ::boost::long_long_type intmax_t;
321 typedef ::boost::ulong_long_type uintmax_t;
322 typedef ::boost::long_long_type int64_t;
323 typedef ::boost::long_long_type int_least64_t;
324 typedef ::boost::long_long_type int_fast64_t;
325 typedef ::boost::ulong_long_type uint64_t;
326 typedef ::boost::ulong_long_type uint_least64_t;
327 typedef ::boost::ulong_long_type uint_fast64_t;
329 # elif ULONG_MAX != 0xffffffff
331 # if ULONG_MAX == 18446744073709551615 // 2**64 - 1
332 typedef long intmax_t;
333 typedef unsigned long uintmax_t;
334 typedef long int64_t;
335 typedef long int_least64_t;
336 typedef long int_fast64_t;
337 typedef unsigned long uint64_t;
338 typedef unsigned long uint_least64_t;
339 typedef unsigned long uint_fast64_t;
341 # error defaults not correct; you must hand modify boost/cstdint.hpp
343 # elif defined(__GNUC__) && defined(BOOST_HAS_LONG_LONG)
344 __extension__ typedef long long intmax_t;
345 __extension__ typedef unsigned long long uintmax_t;
346 __extension__ typedef long long int64_t;
347 __extension__ typedef long long int_least64_t;
348 __extension__ typedef long long int_fast64_t;
349 __extension__ typedef unsigned long long uint64_t;
350 __extension__ typedef unsigned long long uint_least64_t;
351 __extension__ typedef unsigned long long uint_fast64_t;
352 # elif defined(BOOST_HAS_MS_INT64)
354 // we have Borland/Intel/Microsoft __int64:
356 typedef __int64 intmax_t;
357 typedef unsigned __int64 uintmax_t;
358 typedef __int64 int64_t;
359 typedef __int64 int_least64_t;
360 typedef __int64 int_fast64_t;
361 typedef unsigned __int64 uint64_t;
362 typedef unsigned __int64 uint_least64_t;
363 typedef unsigned __int64 uint_fast64_t;
364 # else // assume no 64-bit integers
365 # define BOOST_NO_INT64_T
366 typedef int32_t intmax_t;
367 typedef uint32_t uintmax_t;
373 #endif // BOOST_HAS_STDINT_H
375 // intptr_t/uintptr_t are defined separately because they are optional and not universally available
376 #if defined(BOOST_WINDOWS) && !defined(_WIN32_WCE) && !defined(BOOST_HAS_STDINT_H)
377 // Older MSVC don't have stdint.h and have intptr_t/uintptr_t defined in stddef.h
381 #if (defined(BOOST_WINDOWS) && !defined(_WIN32_WCE)) \
382 || (defined(_XOPEN_UNIX) && (_XOPEN_UNIX+0 > 0) && !defined(__UCLIBC__)) \
383 || defined(__CYGWIN__) || defined(__VXWORKS__) \
384 || defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) \
385 || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || (defined(sun) && !defined(BOOST_HAS_STDINT_H)) || defined(INTPTR_MAX)
391 #define BOOST_HAS_INTPTR_T
393 // Clang pretends to be GCC, so it'll match this condition
394 #elif defined(__GNUC__) && defined(__INTPTR_TYPE__) && defined(__UINTPTR_TYPE__)
397 typedef __INTPTR_TYPE__ intptr_t;
398 typedef __UINTPTR_TYPE__ uintptr_t;
400 #define BOOST_HAS_INTPTR_T
404 #endif // BOOST_CSTDINT_HPP
407 /****************************************************
409 Macro definition section:
411 Added 23rd September 2000 (John Maddock).
412 Modified 11th September 2001 to be excluded when
413 BOOST_HAS_STDINT_H is defined (John Maddock).
414 Modified 11th Dec 2009 to always define the
415 INT#_C macros if they're not already defined (John Maddock).
417 ******************************************************/
419 #if !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && \
420 (!defined(INT8_C) || !defined(INT16_C) || !defined(INT32_C) || !defined(INT64_C))
422 // Undef the macros as a precaution, since we may get here if <stdint.h> has failed
423 // to define them all, see https://svn.boost.org/trac/boost/ticket/12786
437 # define BOOST__STDC_CONSTANT_MACROS_DEFINED
438 # if defined(BOOST_HAS_MS_INT64)
440 // Borland/Intel/Microsoft compilers have width specific suffixes:
443 # define INT8_C(value) value##i8
446 # define INT16_C(value) value##i16
449 # define INT32_C(value) value##i32
452 # define INT64_C(value) value##i64
454 # ifdef BOOST_BORLANDC
455 // Borland bug: appending ui8 makes the type a signed char
456 # define UINT8_C(value) static_cast<unsigned char>(value##u)
458 # define UINT8_C(value) value##ui8
461 # define UINT16_C(value) value##ui16
464 # define UINT32_C(value) value##ui32
467 # define UINT64_C(value) value##ui64
470 # define INTMAX_C(value) value##i64
471 # define UINTMAX_C(value) value##ui64
475 // do it the old fashioned way:
477 // 8-bit types ------------------------------------------------------------//
479 # if (UCHAR_MAX == 0xff) && !defined(INT8_C)
480 # define INT8_C(value) static_cast<boost::int8_t>(value)
481 # define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
484 // 16-bit types -----------------------------------------------------------//
486 # if (USHRT_MAX == 0xffff) && !defined(INT16_C)
487 # define INT16_C(value) static_cast<boost::int16_t>(value)
488 # define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
491 // 32-bit types -----------------------------------------------------------//
493 # if (UINT_MAX == 0xffffffff)
494 # define INT32_C(value) value
495 # define UINT32_C(value) value##u
496 # elif ULONG_MAX == 0xffffffff
497 # define INT32_C(value) value##L
498 # define UINT32_C(value) value##uL
502 // 64-bit types + intmax_t and uintmax_t ----------------------------------//
504 # if defined(BOOST_HAS_LONG_LONG) && \
505 (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX) || defined(_ULLONG_MAX) || defined(_LLONG_MAX))
508 // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
509 # define INT64_C(value) value##LL
510 # define UINT64_C(value) value##uLL
511 # elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || \
512 (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || \
513 (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL) || \
514 (defined(_ULLONG_MAX) && _ULLONG_MAX == 18446744073709551615ULL) || \
515 (defined(_LLONG_MAX) && _LLONG_MAX == 9223372036854775807LL)
517 # define INT64_C(value) value##LL
518 # define UINT64_C(value) value##uLL
520 # error defaults not correct; you must hand modify boost/cstdint.hpp
522 # elif ULONG_MAX != 0xffffffff
524 # if ULONG_MAX == 18446744073709551615U // 2**64 - 1
525 # define INT64_C(value) value##L
526 # define UINT64_C(value) value##uL
528 # error defaults not correct; you must hand modify boost/cstdint.hpp
530 # elif defined(BOOST_HAS_LONG_LONG)
531 // Usual macros not defined, work things out for ourselves:
532 # if(~0uLL == 18446744073709551615ULL)
533 # define INT64_C(value) value##LL
534 # define UINT64_C(value) value##uLL
536 # error defaults not correct; you must hand modify boost/cstdint.hpp
539 # error defaults not correct; you must hand modify boost/cstdint.hpp
542 # ifdef BOOST_NO_INT64_T
543 # define INTMAX_C(value) INT32_C(value)
544 # define UINTMAX_C(value) UINT32_C(value)
546 # define INTMAX_C(value) INT64_C(value)
547 # define UINTMAX_C(value) UINT64_C(value)
550 # endif // Borland/Microsoft specific width suffixes
552 #endif // INT#_C macros.