1 // boost cstdint.hpp header file ------------------------------------------//
\r
3 // (C) Copyright Beman Dawes 1999.
\r
4 // (C) Copyright Jens Mauer 2001
\r
5 // (C) Copyright John Maddock 2001
\r
6 // Distributed under the Boost
\r
7 // Software License, Version 1.0. (See accompanying file
\r
8 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
\r
10 // See http://www.boost.org/libs/integer for documentation.
\r
13 // 31 Oct 01 use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
\r
14 // 16 Apr 01 check LONGLONG_MAX when looking for "long long" (Jens Maurer)
\r
15 // 23 Jan 01 prefer "long" over "int" for int32_t and intmax_t (Jens Maurer)
\r
16 // 12 Nov 00 Merged <boost/stdint.h> (Jens Maurer)
\r
17 // 23 Sep 00 Added INTXX_C macro support (John Maddock).
\r
18 // 22 Sep 00 Better 64-bit support (John Maddock)
\r
19 // 29 Jun 00 Reimplement to avoid including stdint.h within namespace boost
\r
20 // 8 Aug 99 Initial version (Beman Dawes)
\r
23 #ifndef BOOST_CSTDINT_HPP
\r
24 #define BOOST_CSTDINT_HPP
\r
27 // Since we always define the INT#_C macros as per C++0x,
\r
28 // define __STDC_CONSTANT_MACROS so that <stdint.h> does the right
\r
29 // thing if possible, and so that the user knows that the macros
\r
30 // are actually defined as per C99.
\r
32 #ifndef __STDC_CONSTANT_MACROS
\r
33 # define __STDC_CONSTANT_MACROS
\r
36 #include <boost/config.hpp>
\r
39 // Note that GLIBC is a bit inconsistent about whether int64_t is defined or not
\r
40 // depending upon what headers happen to have been included first...
\r
41 // so we disable use of stdint.h when GLIBC does not define __GLIBC_HAVE_LONG_LONG.
\r
42 // See https://svn.boost.org/trac/boost/ticket/3548 and http://sources.redhat.com/bugzilla/show_bug.cgi?id=10990
\r
44 #if defined(BOOST_HAS_STDINT_H) && (!defined(__GLIBC__) || defined(__GLIBC_HAVE_LONG_LONG))
\r
46 // The following #include is an implementation artifact; not part of interface.
\r
48 // HP-UX has a vaguely nice <stdint.h> in a non-standard location
\r
49 # include <inttypes.h>
\r
50 # ifdef __STDC_32_MODE__
\r
51 // this is triggered with GCC, because it defines __cplusplus < 199707L
\r
52 # define BOOST_NO_INT64_T
\r
54 # elif defined(__FreeBSD__) || defined(__IBMCPP__) || defined(_AIX)
\r
55 # include <inttypes.h>
\r
57 # include <stdint.h>
\r
59 // There is a bug in Cygwin two _C macros
\r
60 # if defined(__STDC_CONSTANT_MACROS) && defined(__CYGWIN__)
\r
63 # define INTMAX_C(c) c##LL
\r
64 # define UINTMAX_C(c) c##ULL
\r
71 // QNX (Dinkumware stdlib) defines these as non-standard names.
\r
72 // Reflect to the standard names.
\r
74 typedef ::intleast8_t int_least8_t;
\r
75 typedef ::intfast8_t int_fast8_t;
\r
76 typedef ::uintleast8_t uint_least8_t;
\r
77 typedef ::uintfast8_t uint_fast8_t;
\r
79 typedef ::intleast16_t int_least16_t;
\r
80 typedef ::intfast16_t int_fast16_t;
\r
81 typedef ::uintleast16_t uint_least16_t;
\r
82 typedef ::uintfast16_t uint_fast16_t;
\r
84 typedef ::intleast32_t int_least32_t;
\r
85 typedef ::intfast32_t int_fast32_t;
\r
86 typedef ::uintleast32_t uint_least32_t;
\r
87 typedef ::uintfast32_t uint_fast32_t;
\r
89 # ifndef BOOST_NO_INT64_T
\r
91 typedef ::intleast64_t int_least64_t;
\r
92 typedef ::intfast64_t int_fast64_t;
\r
93 typedef ::uintleast64_t uint_least64_t;
\r
94 typedef ::uintfast64_t uint_fast64_t;
\r
104 using ::int_least8_t;
\r
105 using ::int_fast8_t;
\r
107 using ::uint_least8_t;
\r
108 using ::uint_fast8_t;
\r
111 using ::int_least16_t;
\r
112 using ::int_fast16_t;
\r
114 using ::uint_least16_t;
\r
115 using ::uint_fast16_t;
\r
118 using ::int_least32_t;
\r
119 using ::int_fast32_t;
\r
121 using ::uint_least32_t;
\r
122 using ::uint_fast32_t;
\r
124 # ifndef BOOST_NO_INT64_T
\r
127 using ::int_least64_t;
\r
128 using ::int_fast64_t;
\r
130 using ::uint_least64_t;
\r
131 using ::uint_fast64_t;
\r
136 using ::uintmax_t;
\r
138 } // namespace boost
\r
140 #elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__)
\r
141 // FreeBSD and Tru64 have an <inttypes.h> that contains much of what we need.
\r
142 # include <inttypes.h>
\r
147 typedef int8_t int_least8_t;
\r
148 typedef int8_t int_fast8_t;
\r
150 typedef uint8_t uint_least8_t;
\r
151 typedef uint8_t uint_fast8_t;
\r
154 typedef int16_t int_least16_t;
\r
155 typedef int16_t int_fast16_t;
\r
157 typedef uint16_t uint_least16_t;
\r
158 typedef uint16_t uint_fast16_t;
\r
161 typedef int32_t int_least32_t;
\r
162 typedef int32_t int_fast32_t;
\r
164 typedef uint32_t uint_least32_t;
\r
165 typedef uint32_t uint_fast32_t;
\r
167 # ifndef BOOST_NO_INT64_T
\r
170 typedef int64_t int_least64_t;
\r
171 typedef int64_t int_fast64_t;
\r
173 typedef uint64_t uint_least64_t;
\r
174 typedef uint64_t uint_fast64_t;
\r
176 typedef int64_t intmax_t;
\r
177 typedef uint64_t uintmax_t;
\r
181 typedef int32_t intmax_t;
\r
182 typedef uint32_t uintmax_t;
\r
186 } // namespace boost
\r
188 #else // BOOST_HAS_STDINT_H
\r
190 # include <boost/limits.hpp> // implementation artifact; not part of interface
\r
191 # include <limits.h> // needed for limits macros
\r
197 // These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
\r
198 // platforms. For other systems, they will have to be hand tailored.
\r
200 // Because the fast types are assumed to be the same as the undecorated types,
\r
201 // it may be possible to hand tailor a more efficient implementation. Such
\r
202 // an optimization may be illusionary; on the Intel x86-family 386 on, for
\r
203 // example, byte arithmetic and load/stores are as fast as "int" sized ones.
\r
205 // 8-bit types ------------------------------------------------------------//
\r
207 # if UCHAR_MAX == 0xff
\r
208 typedef signed char int8_t;
\r
209 typedef signed char int_least8_t;
\r
210 typedef signed char int_fast8_t;
\r
211 typedef unsigned char uint8_t;
\r
212 typedef unsigned char uint_least8_t;
\r
213 typedef unsigned char uint_fast8_t;
\r
215 # error defaults not correct; you must hand modify boost/cstdint.hpp
\r
218 // 16-bit types -----------------------------------------------------------//
\r
220 # if USHRT_MAX == 0xffff
\r
221 # if defined(__crayx1)
\r
222 // The Cray X1 has a 16-bit short, however it is not recommend
\r
223 // for use in performance critical code.
\r
224 typedef short int16_t;
\r
225 typedef short int_least16_t;
\r
226 typedef int int_fast16_t;
\r
227 typedef unsigned short uint16_t;
\r
228 typedef unsigned short uint_least16_t;
\r
229 typedef unsigned int uint_fast16_t;
\r
231 typedef short int16_t;
\r
232 typedef short int_least16_t;
\r
233 typedef short int_fast16_t;
\r
234 typedef unsigned short uint16_t;
\r
235 typedef unsigned short uint_least16_t;
\r
236 typedef unsigned short uint_fast16_t;
\r
238 # elif (USHRT_MAX == 0xffffffff) && defined(__MTA__)
\r
239 // On MTA / XMT short is 32 bits unless the -short16 compiler flag is specified
\r
240 // MTA / XMT does support the following non-standard integer types
\r
241 typedef __short16 int16_t;
\r
242 typedef __short16 int_least16_t;
\r
243 typedef __short16 int_fast16_t;
\r
244 typedef unsigned __short16 uint16_t;
\r
245 typedef unsigned __short16 uint_least16_t;
\r
246 typedef unsigned __short16 uint_fast16_t;
\r
247 # elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
\r
248 // no 16-bit types on Cray:
\r
249 typedef short int_least16_t;
\r
250 typedef short int_fast16_t;
\r
251 typedef unsigned short uint_least16_t;
\r
252 typedef unsigned short uint_fast16_t;
\r
254 # error defaults not correct; you must hand modify boost/cstdint.hpp
\r
257 // 32-bit types -----------------------------------------------------------//
\r
259 # if ULONG_MAX == 0xffffffff
\r
260 typedef long int32_t;
\r
261 typedef long int_least32_t;
\r
262 typedef long int_fast32_t;
\r
263 typedef unsigned long uint32_t;
\r
264 typedef unsigned long uint_least32_t;
\r
265 typedef unsigned long uint_fast32_t;
\r
266 # elif UINT_MAX == 0xffffffff
\r
267 typedef int int32_t;
\r
268 typedef int int_least32_t;
\r
269 typedef int int_fast32_t;
\r
270 typedef unsigned int uint32_t;
\r
271 typedef unsigned int uint_least32_t;
\r
272 typedef unsigned int uint_fast32_t;
\r
273 # elif (UINT_MAX == 0xffffffffffffffff) && defined(__MTA__)
\r
274 // Integers are 64 bits on the MTA / XMT
\r
275 typedef __int32 int32_t;
\r
276 typedef __int32 int_least32_t;
\r
277 typedef __int32 int_fast32_t;
\r
278 typedef unsigned __int32 uint32_t;
\r
279 typedef unsigned __int32 uint_least32_t;
\r
280 typedef unsigned __int32 uint_fast32_t;
\r
282 # error defaults not correct; you must hand modify boost/cstdint.hpp
\r
285 // 64-bit types + intmax_t and uintmax_t ----------------------------------//
\r
287 # if defined(BOOST_HAS_LONG_LONG) && \
\r
288 !defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
\r
289 (!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
\r
290 (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
\r
291 # if defined(__hpux)
\r
292 // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
\r
293 # elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
\r
296 # error defaults not correct; you must hand modify boost/cstdint.hpp
\r
299 typedef ::boost::long_long_type intmax_t;
\r
300 typedef ::boost::ulong_long_type uintmax_t;
\r
301 typedef ::boost::long_long_type int64_t;
\r
302 typedef ::boost::long_long_type int_least64_t;
\r
303 typedef ::boost::long_long_type int_fast64_t;
\r
304 typedef ::boost::ulong_long_type uint64_t;
\r
305 typedef ::boost::ulong_long_type uint_least64_t;
\r
306 typedef ::boost::ulong_long_type uint_fast64_t;
\r
308 # elif ULONG_MAX != 0xffffffff
\r
310 # if ULONG_MAX == 18446744073709551615 // 2**64 - 1
\r
311 typedef long intmax_t;
\r
312 typedef unsigned long uintmax_t;
\r
313 typedef long int64_t;
\r
314 typedef long int_least64_t;
\r
315 typedef long int_fast64_t;
\r
316 typedef unsigned long uint64_t;
\r
317 typedef unsigned long uint_least64_t;
\r
318 typedef unsigned long uint_fast64_t;
\r
320 # error defaults not correct; you must hand modify boost/cstdint.hpp
\r
322 # elif defined(__GNUC__) && defined(BOOST_HAS_LONG_LONG)
\r
323 __extension__ typedef long long intmax_t;
\r
324 __extension__ typedef unsigned long long uintmax_t;
\r
325 __extension__ typedef long long int64_t;
\r
326 __extension__ typedef long long int_least64_t;
\r
327 __extension__ typedef long long int_fast64_t;
\r
328 __extension__ typedef unsigned long long uint64_t;
\r
329 __extension__ typedef unsigned long long uint_least64_t;
\r
330 __extension__ typedef unsigned long long uint_fast64_t;
\r
331 # elif defined(BOOST_HAS_MS_INT64)
\r
333 // we have Borland/Intel/Microsoft __int64:
\r
335 typedef __int64 intmax_t;
\r
336 typedef unsigned __int64 uintmax_t;
\r
337 typedef __int64 int64_t;
\r
338 typedef __int64 int_least64_t;
\r
339 typedef __int64 int_fast64_t;
\r
340 typedef unsigned __int64 uint64_t;
\r
341 typedef unsigned __int64 uint_least64_t;
\r
342 typedef unsigned __int64 uint_fast64_t;
\r
343 # else // assume no 64-bit integers
\r
344 # define BOOST_NO_INT64_T
\r
345 typedef int32_t intmax_t;
\r
346 typedef uint32_t uintmax_t;
\r
349 } // namespace boost
\r
352 #endif // BOOST_HAS_STDINT_H
\r
354 #endif // BOOST_CSTDINT_HPP
\r
357 /****************************************************
\r
359 Macro definition section:
\r
361 Added 23rd September 2000 (John Maddock).
\r
362 Modified 11th September 2001 to be excluded when
\r
363 BOOST_HAS_STDINT_H is defined (John Maddock).
\r
364 Modified 11th Dec 2009 to always define the
\r
365 INT#_C macros if they're not already defined (John Maddock).
\r
367 ******************************************************/
\r
369 #if !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(INT8_C)
\r
370 #include <limits.h>
\r
371 # define BOOST__STDC_CONSTANT_MACROS_DEFINED
\r
372 # if defined(BOOST_HAS_MS_INT64)
\r
374 // Borland/Intel/Microsoft compilers have width specific suffixes:
\r
376 # define INT8_C(value) value##i8
\r
377 # define INT16_C(value) value##i16
\r
378 # define INT32_C(value) value##i32
\r
379 # define INT64_C(value) value##i64
\r
380 # ifdef __BORLANDC__
\r
381 // Borland bug: appending ui8 makes the type a signed char
\r
382 # define UINT8_C(value) static_cast<unsigned char>(value##u)
\r
384 # define UINT8_C(value) value##ui8
\r
386 # define UINT16_C(value) value##ui16
\r
387 # define UINT32_C(value) value##ui32
\r
388 # define UINT64_C(value) value##ui64
\r
389 # define INTMAX_C(value) value##i64
\r
390 # define UINTMAX_C(value) value##ui64
\r
393 // do it the old fashioned way:
\r
395 // 8-bit types ------------------------------------------------------------//
\r
397 # if UCHAR_MAX == 0xff
\r
398 # define INT8_C(value) static_cast<boost::int8_t>(value)
\r
399 # define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
\r
402 // 16-bit types -----------------------------------------------------------//
\r
404 # if USHRT_MAX == 0xffff
\r
405 # define INT16_C(value) static_cast<boost::int16_t>(value)
\r
406 # define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
\r
409 // 32-bit types -----------------------------------------------------------//
\r
411 # if UINT_MAX == 0xffffffff
\r
412 # define INT32_C(value) value
\r
413 # define UINT32_C(value) value##u
\r
414 # elif ULONG_MAX == 0xffffffff
\r
415 # define INT32_C(value) value##L
\r
416 # define UINT32_C(value) value##uL
\r
419 // 64-bit types + intmax_t and uintmax_t ----------------------------------//
\r
421 # if defined(BOOST_HAS_LONG_LONG) && \
\r
422 (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX) || defined(_LLONG_MAX))
\r
424 # if defined(__hpux)
\r
425 // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
\r
426 # define INT64_C(value) value##LL
\r
427 # define UINT64_C(value) value##uLL
\r
428 # elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || \
\r
429 (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || \
\r
430 (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL) || \
\r
431 (defined(_LLONG_MAX) && _LLONG_MAX == 18446744073709551615ULL)
\r
433 # define INT64_C(value) value##LL
\r
434 # define UINT64_C(value) value##uLL
\r
436 # error defaults not correct; you must hand modify boost/cstdint.hpp
\r
438 # elif ULONG_MAX != 0xffffffff
\r
440 # if ULONG_MAX == 18446744073709551615U // 2**64 - 1
\r
441 # define INT64_C(value) value##L
\r
442 # define UINT64_C(value) value##uL
\r
444 # error defaults not correct; you must hand modify boost/cstdint.hpp
\r
446 # elif defined(BOOST_HAS_LONG_LONG)
\r
447 // Usual macros not defined, work things out for ourselves:
\r
448 # if(~0uLL == 18446744073709551615ULL)
\r
449 # define INT64_C(value) value##LL
\r
450 # define UINT64_C(value) value##uLL
\r
452 # error defaults not correct; you must hand modify boost/cstdint.hpp
\r
455 # error defaults not correct; you must hand modify boost/cstdint.hpp
\r
458 # ifdef BOOST_NO_INT64_T
\r
459 # define INTMAX_C(value) INT32_C(value)
\r
460 # define UINTMAX_C(value) UINT32_C(value)
\r
462 # define INTMAX_C(value) INT64_C(value)
\r
463 # define UINTMAX_C(value) UINT64_C(value)
\r
466 # endif // Borland/Microsoft specific width suffixes
\r
468 #endif // INT#_C macros.
\r