1 // boost cstdint.hpp header file ------------------------------------------//
3 // (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
4 // and distribute this software is granted provided this copyright
5 // notice appears in all copies. This software is provided "as is" without
6 // express or implied warranty, and with no claim as to its suitability for
9 // See http://www.boost.org for most recent version including documentation.
12 // 31 Oct 01 use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
13 // 16 Apr 01 check LONGLONG_MAX when looking for "long long" (Jens Maurer)
14 // 23 Jan 01 prefer "long" over "int" for int32_t and intmax_t (Jens Maurer)
15 // 12 Nov 00 Merged <boost/stdint.h> (Jens Maurer)
16 // 23 Sep 00 Added INTXX_C macro support (John Maddock).
17 // 22 Sep 00 Better 64-bit support (John Maddock)
18 // 29 Jun 00 Reimplement to avoid including stdint.h within namespace boost
19 // 8 Aug 99 Initial version (Beman Dawes)
22 #ifndef BOOST_CSTDINT_HPP
23 #define BOOST_CSTDINT_HPP
25 #include <boost/config.hpp>
28 #ifdef BOOST_HAS_STDINT_H
30 // The following #include is an implementation artifact; not part of interface.
32 // HP-UX has a vaguely nice <stdint.h> in a non-standard location
33 # include <inttypes.h>
34 # ifdef __STDC_32_MODE__
35 // this is triggered with GCC, because it defines __cplusplus < 199707L
36 # define BOOST_NO_INT64_T
38 # elif defined(__FreeBSD__) || defined(__IBMCPP__)
39 # include <inttypes.h>
51 using ::uint_least8_t;
55 using ::int_least16_t;
58 using ::uint_least16_t;
59 using ::uint_fast16_t;
62 using ::int_least32_t;
65 using ::uint_least32_t;
66 using ::uint_fast32_t;
68 # ifndef BOOST_NO_INT64_T
71 using ::int_least64_t;
74 using ::uint_least64_t;
75 using ::uint_fast64_t;
84 #elif defined(__FreeBSD__) && (__FreeBSD__ <= 4)
85 // FreeBSD has an <inttypes.h> that contains much of what we need
86 # include <inttypes.h>
91 typedef int8_t int_least8_t;
92 typedef int8_t int_fast8_t;
94 typedef uint8_t uint_least8_t;
95 typedef uint8_t uint_fast8_t;
98 typedef int16_t int_least16_t;
99 typedef int16_t int_fast16_t;
101 typedef uint16_t uint_least16_t;
102 typedef uint16_t uint_fast16_t;
105 typedef int32_t int_least32_t;
106 typedef int32_t int_fast32_t;
108 typedef uint32_t uint_least32_t;
109 typedef uint32_t uint_fast32_t;
111 # ifndef BOOST_NO_INT64_T
114 typedef int64_t int_least64_t;
115 typedef int64_t int_fast64_t;
117 typedef uint64_t uint_least64_t;
118 typedef uint64_t uint_fast64_t;
120 typedef int64_t intmax_t;
121 typedef uint64_t uintmax_t;
125 typedef int32_t intmax_t;
126 typedef uint32_t uintmax_t;
132 #else // BOOST_HAS_STDINT_H
134 # include <limits.h> // implementation artifact; not part of interface
140 // These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
141 // platforms. For other systems, they will have to be hand tailored.
143 // Because the fast types are assumed to be the same as the undecorated types,
144 // it may be possible to hand tailor a more efficient implementation. Such
145 // an optimization may be illusionary; on the Intel x86-family 386 on, for
146 // example, byte arithmetic and load/stores are as fast as "int" sized ones.
148 // 8-bit types ------------------------------------------------------------//
150 # if UCHAR_MAX == 0xff
151 typedef signed char int8_t;
152 typedef signed char int_least8_t;
153 typedef signed char int_fast8_t;
154 typedef unsigned char uint8_t;
155 typedef unsigned char uint_least8_t;
156 typedef unsigned char uint_fast8_t;
158 # error defaults not correct; you must hand modify boost/cstdint.hpp
161 // 16-bit types -----------------------------------------------------------//
163 # if USHRT_MAX == 0xffff
164 typedef short int16_t;
165 typedef short int_least16_t;
166 typedef short int_fast16_t;
167 typedef unsigned short uint16_t;
168 typedef unsigned short uint_least16_t;
169 typedef unsigned short uint_fast16_t;
171 # error defaults not correct; you must hand modify boost/cstdint.hpp
174 // 32-bit types -----------------------------------------------------------//
176 # if ULONG_MAX == 0xffffffff
177 typedef long int32_t;
178 typedef long int_least32_t;
179 typedef long int_fast32_t;
180 typedef unsigned long uint32_t;
181 typedef unsigned long uint_least32_t;
182 typedef unsigned long uint_fast32_t;
183 # elif UINT_MAX == 0xffffffff
185 typedef int int_least32_t;
186 typedef int int_fast32_t;
187 typedef unsigned int uint32_t;
188 typedef unsigned int uint_least32_t;
189 typedef unsigned int uint_fast32_t;
191 # error defaults not correct; you must hand modify boost/cstdint.hpp
194 // 64-bit types + intmax_t and uintmax_t ----------------------------------//
196 # if defined(BOOST_HAS_LONG_LONG) && \
197 !defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
198 (!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
199 (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
201 // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
202 # elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
205 # error defaults not correct; you must hand modify boost/cstdint.hpp
208 typedef long long intmax_t;
209 typedef unsigned long long uintmax_t;
210 typedef long long int64_t;
211 typedef long long int_least64_t;
212 typedef long long int_fast64_t;
213 typedef unsigned long long uint64_t;
214 typedef unsigned long long uint_least64_t;
215 typedef unsigned long long uint_fast64_t;
217 # elif ULONG_MAX != 0xffffffff
219 # if ULONG_MAX == 18446744073709551615 // 2**64 - 1
220 typedef long intmax_t;
221 typedef unsigned long uintmax_t;
222 typedef long int64_t;
223 typedef long int_least64_t;
224 typedef long int_fast64_t;
225 typedef unsigned long uint64_t;
226 typedef unsigned long uint_least64_t;
227 typedef unsigned long uint_fast64_t;
229 # error defaults not correct; you must hand modify boost/cstdint.hpp
231 # elif defined(BOOST_HAS_MS_INT64)
233 // we have Borland/Intel/Microsoft __int64:
235 typedef __int64 intmax_t;
236 typedef unsigned __int64 uintmax_t;
237 typedef __int64 int64_t;
238 typedef __int64 int_least64_t;
239 typedef __int64 int_fast64_t;
240 typedef unsigned __int64 uint64_t;
241 typedef unsigned __int64 uint_least64_t;
242 typedef unsigned __int64 uint_fast64_t;
243 # else // assume no 64-bit integers
244 # define BOOST_NO_INT64_T
245 typedef int32_t intmax_t;
246 typedef uint32_t uintmax_t;
252 #endif // BOOST_HAS_STDINT_H
254 #endif // BOOST_CSTDINT_HPP
257 /****************************************************
259 Macro definition section:
261 Define various INTXX_C macros only if
262 __STDC_CONSTANT_MACROS is defined.
264 Undefine the macros if __STDC_CONSTANT_MACROS is
265 not defined and the macros are (cf <cassert>).
267 Added 23rd September 2000 (John Maddock).
268 Modified 11th September 2001 to be excluded when
269 BOOST_HAS_STDINT_H is defined (John Maddock).
271 ******************************************************/
273 #if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H)
274 # define BOOST__STDC_CONSTANT_MACROS_DEFINED
275 # if defined(BOOST_HAS_MS_INT64)
277 // Borland/Intel/Microsoft compilers have width specific suffixes:
279 # define INT8_C(value) value##i8
280 # define INT16_C(value) value##i16
281 # define INT32_C(value) value##i32
282 # define INT64_C(value) value##i64
284 // Borland bug: appending ui8 makes the type a signed char
285 # define UINT8_C(value) static_cast<unsigned char>(value##u)
287 # define UINT8_C(value) value##ui8
289 # define UINT16_C(value) value##ui16
290 # define UINT32_C(value) value##ui32
291 # define UINT64_C(value) value##ui64
292 # define INTMAX_C(value) value##i64
293 # define UINTMAX_C(value) value##ui64
296 // do it the old fashioned way:
298 // 8-bit types ------------------------------------------------------------//
300 # if UCHAR_MAX == 0xff
301 # define INT8_C(value) static_cast<boost::int8_t>(value)
302 # define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
305 // 16-bit types -----------------------------------------------------------//
307 # if USHRT_MAX == 0xffff
308 # define INT16_C(value) static_cast<boost::int16_t>(value)
309 # define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
312 // 32-bit types -----------------------------------------------------------//
314 # if UINT_MAX == 0xffffffff
315 # define INT32_C(value) value
316 # define UINT32_C(value) value##u
317 # elif ULONG_MAX == 0xffffffff
318 # define INT32_C(value) value##L
319 # define UINT32_C(value) value##uL
322 // 64-bit types + intmax_t and uintmax_t ----------------------------------//
324 # if defined(BOOST_HAS_LONG_LONG) && \
325 (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
328 // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
329 # elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
330 (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || \
331 (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
334 # error defaults not correct; you must hand modify boost/cstdint.hpp
336 # define INT64_C(value) value##LL
337 # define UINT64_C(value) value##uLL
338 # elif ULONG_MAX != 0xffffffff
340 # if ULONG_MAX == 18446744073709551615 // 2**64 - 1
341 # define INT64_C(value) value##L
342 # define UINT64_C(value) value##uL
344 # error defaults not correct; you must hand modify boost/cstdint.hpp
348 # ifdef BOOST_NO_INT64_T
349 # define INTMAX_C(value) INT32_C(value)
350 # define UINTMAX_C(value) UINT32_C(value)
352 # define INTMAX_C(value) INT64_C(value)
353 # define UINTMAX_C(value) UINT64_C(value)
356 # endif // Borland/Microsoft specific width suffixes
359 #elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS) && !defined(BOOST_HAS_STDINT_H)
361 // undef all the macros:
374 #endif // __STDC_CONSTANT_MACROS_DEFINED etc.