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/libs/integer for 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 <boost/limits.hpp> // 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 # if defined(__crayx1)
165 // The Cray X1 has a 16-bit short, however it is not recommend
166 // for use in performance critical code.
167 typedef short int16_t;
168 typedef short int_least16_t;
169 typedef int int_fast16_t;
170 typedef unsigned short uint16_t;
171 typedef unsigned short uint_least16_t;
172 typedef unsigned int uint_fast16_t;
174 typedef short int16_t;
175 typedef short int_least16_t;
176 typedef short int_fast16_t;
177 typedef unsigned short uint16_t;
178 typedef unsigned short uint_least16_t;
179 typedef unsigned short uint_fast16_t;
181 # elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
182 // no 16-bit types on Cray:
183 typedef short int_least16_t;
184 typedef short int_fast16_t;
185 typedef unsigned short uint_least16_t;
186 typedef unsigned short uint_fast16_t;
188 # error defaults not correct; you must hand modify boost/cstdint.hpp
191 // 32-bit types -----------------------------------------------------------//
193 # if ULONG_MAX == 0xffffffff
194 typedef long int32_t;
195 typedef long int_least32_t;
196 typedef long int_fast32_t;
197 typedef unsigned long uint32_t;
198 typedef unsigned long uint_least32_t;
199 typedef unsigned long uint_fast32_t;
200 # elif UINT_MAX == 0xffffffff
202 typedef int int_least32_t;
203 typedef int int_fast32_t;
204 typedef unsigned int uint32_t;
205 typedef unsigned int uint_least32_t;
206 typedef unsigned int uint_fast32_t;
208 # error defaults not correct; you must hand modify boost/cstdint.hpp
211 // 64-bit types + intmax_t and uintmax_t ----------------------------------//
213 # if defined(BOOST_HAS_LONG_LONG) && \
214 !defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
215 (!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
216 (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
218 // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
219 # elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
222 # error defaults not correct; you must hand modify boost/cstdint.hpp
225 typedef long long intmax_t;
226 typedef unsigned long long uintmax_t;
227 typedef long long int64_t;
228 typedef long long int_least64_t;
229 typedef long long int_fast64_t;
230 typedef unsigned long long uint64_t;
231 typedef unsigned long long uint_least64_t;
232 typedef unsigned long long uint_fast64_t;
234 # elif ULONG_MAX != 0xffffffff
236 # if ULONG_MAX == 18446744073709551615 // 2**64 - 1
237 typedef long intmax_t;
238 typedef unsigned long uintmax_t;
239 typedef long int64_t;
240 typedef long int_least64_t;
241 typedef long int_fast64_t;
242 typedef unsigned long uint64_t;
243 typedef unsigned long uint_least64_t;
244 typedef unsigned long uint_fast64_t;
246 # error defaults not correct; you must hand modify boost/cstdint.hpp
248 # elif defined(__GNUC__) && defined(BOOST_HAS_LONG_LONG)
249 __extension__ typedef long long intmax_t;
250 __extension__ typedef unsigned long long uintmax_t;
251 __extension__ typedef long long int64_t;
252 __extension__ typedef long long int_least64_t;
253 __extension__ typedef long long int_fast64_t;
254 __extension__ typedef unsigned long long uint64_t;
255 __extension__ typedef unsigned long long uint_least64_t;
256 __extension__ typedef unsigned long long uint_fast64_t;
257 # elif defined(BOOST_HAS_MS_INT64)
259 // we have Borland/Intel/Microsoft __int64:
261 typedef __int64 intmax_t;
262 typedef unsigned __int64 uintmax_t;
263 typedef __int64 int64_t;
264 typedef __int64 int_least64_t;
265 typedef __int64 int_fast64_t;
266 typedef unsigned __int64 uint64_t;
267 typedef unsigned __int64 uint_least64_t;
268 typedef unsigned __int64 uint_fast64_t;
269 # else // assume no 64-bit integers
270 # define BOOST_NO_INT64_T
271 typedef int32_t intmax_t;
272 typedef uint32_t uintmax_t;
278 #endif // BOOST_HAS_STDINT_H
280 #endif // BOOST_CSTDINT_HPP
283 /****************************************************
285 Macro definition section:
287 Define various INTXX_C macros only if
288 __STDC_CONSTANT_MACROS is defined.
290 Undefine the macros if __STDC_CONSTANT_MACROS is
291 not defined and the macros are (cf <cassert>).
293 Added 23rd September 2000 (John Maddock).
294 Modified 11th September 2001 to be excluded when
295 BOOST_HAS_STDINT_H is defined (John Maddock).
297 ******************************************************/
299 #if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H)
300 # define BOOST__STDC_CONSTANT_MACROS_DEFINED
301 # if defined(BOOST_HAS_MS_INT64)
303 // Borland/Intel/Microsoft compilers have width specific suffixes:
305 # define INT8_C(value) value##i8
306 # define INT16_C(value) value##i16
307 # define INT32_C(value) value##i32
308 # define INT64_C(value) value##i64
310 // Borland bug: appending ui8 makes the type a signed char
311 # define UINT8_C(value) static_cast<unsigned char>(value##u)
313 # define UINT8_C(value) value##ui8
315 # define UINT16_C(value) value##ui16
316 # define UINT32_C(value) value##ui32
317 # define UINT64_C(value) value##ui64
318 # define INTMAX_C(value) value##i64
319 # define UINTMAX_C(value) value##ui64
322 // do it the old fashioned way:
324 // 8-bit types ------------------------------------------------------------//
326 # if UCHAR_MAX == 0xff
327 # define INT8_C(value) static_cast<boost::int8_t>(value)
328 # define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
331 // 16-bit types -----------------------------------------------------------//
333 # if USHRT_MAX == 0xffff
334 # define INT16_C(value) static_cast<boost::int16_t>(value)
335 # define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
338 // 32-bit types -----------------------------------------------------------//
340 # if UINT_MAX == 0xffffffff
341 # define INT32_C(value) value
342 # define UINT32_C(value) value##u
343 # elif ULONG_MAX == 0xffffffff
344 # define INT32_C(value) value##L
345 # define UINT32_C(value) value##uL
348 // 64-bit types + intmax_t and uintmax_t ----------------------------------//
350 # if defined(BOOST_HAS_LONG_LONG) && \
351 (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
354 // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
355 # elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
356 (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || \
357 (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
360 # error defaults not correct; you must hand modify boost/cstdint.hpp
362 # define INT64_C(value) value##LL
363 # define UINT64_C(value) value##uLL
364 # elif ULONG_MAX != 0xffffffff
366 # if ULONG_MAX == 18446744073709551615 // 2**64 - 1
367 # define INT64_C(value) value##L
368 # define UINT64_C(value) value##uL
370 # error defaults not correct; you must hand modify boost/cstdint.hpp
374 # ifdef BOOST_NO_INT64_T
375 # define INTMAX_C(value) INT32_C(value)
376 # define UINTMAX_C(value) UINT32_C(value)
378 # define INTMAX_C(value) INT64_C(value)
379 # define UINTMAX_C(value) UINT64_C(value)
382 # endif // Borland/Microsoft specific width suffixes
385 #elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS) && !defined(BOOST_HAS_STDINT_H)
387 // undef all the macros:
400 #endif // __STDC_CONSTANT_MACROS_DEFINED etc.