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 <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
# 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(BOOST_HAS_MS_INT64)
250
// we have Borland/Intel/Microsoft __int64:
252
typedef __int64 intmax_t;
253
typedef unsigned __int64 uintmax_t;
254
typedef __int64 int64_t;
255
typedef __int64 int_least64_t;
256
typedef __int64 int_fast64_t;
257
typedef unsigned __int64 uint64_t;
258
typedef unsigned __int64 uint_least64_t;
259
typedef unsigned __int64 uint_fast64_t;
260
# else // assume no 64-bit integers
261
# define BOOST_NO_INT64_T
262
typedef int32_t intmax_t;
263
typedef uint32_t uintmax_t;
269
#endif // BOOST_HAS_STDINT_H
271
#endif // BOOST_CSTDINT_HPP
274
/****************************************************
276
Macro definition section:
278
Define various INTXX_C macros only if
279
__STDC_CONSTANT_MACROS is defined.
281
Undefine the macros if __STDC_CONSTANT_MACROS is
282
not defined and the macros are (cf <cassert>).
284
Added 23rd September 2000 (John Maddock).
285
Modified 11th September 2001 to be excluded when
286
BOOST_HAS_STDINT_H is defined (John Maddock).
288
******************************************************/
290
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H)
291
# define BOOST__STDC_CONSTANT_MACROS_DEFINED
292
# if defined(BOOST_HAS_MS_INT64)
294
// Borland/Intel/Microsoft compilers have width specific suffixes:
296
# define INT8_C(value) value##i8
297
# define INT16_C(value) value##i16
298
# define INT32_C(value) value##i32
299
# define INT64_C(value) value##i64
301
// Borland bug: appending ui8 makes the type a signed char
302
# define UINT8_C(value) static_cast<unsigned char>(value##u)
304
# define UINT8_C(value) value##ui8
306
# define UINT16_C(value) value##ui16
307
# define UINT32_C(value) value##ui32
308
# define UINT64_C(value) value##ui64
309
# define INTMAX_C(value) value##i64
310
# define UINTMAX_C(value) value##ui64
313
// do it the old fashioned way:
315
// 8-bit types ------------------------------------------------------------//
317
# if UCHAR_MAX == 0xff
318
# define INT8_C(value) static_cast<boost::int8_t>(value)
319
# define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
322
// 16-bit types -----------------------------------------------------------//
324
# if USHRT_MAX == 0xffff
325
# define INT16_C(value) static_cast<boost::int16_t>(value)
326
# define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
329
// 32-bit types -----------------------------------------------------------//
331
# if UINT_MAX == 0xffffffff
332
# define INT32_C(value) value
333
# define UINT32_C(value) value##u
334
# elif ULONG_MAX == 0xffffffff
335
# define INT32_C(value) value##L
336
# define UINT32_C(value) value##uL
339
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
341
# if defined(BOOST_HAS_LONG_LONG) && \
342
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
345
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
346
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
347
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || \
348
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
351
# error defaults not correct; you must hand modify boost/cstdint.hpp
353
# define INT64_C(value) value##LL
354
# define UINT64_C(value) value##uLL
355
# elif ULONG_MAX != 0xffffffff
357
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
358
# define INT64_C(value) value##L
359
# define UINT64_C(value) value##uL
361
# error defaults not correct; you must hand modify boost/cstdint.hpp
365
# ifdef BOOST_NO_INT64_T
366
# define INTMAX_C(value) INT32_C(value)
367
# define UINTMAX_C(value) UINT32_C(value)
369
# define INTMAX_C(value) INT64_C(value)
370
# define UINTMAX_C(value) UINT64_C(value)
373
# endif // Borland/Microsoft specific width suffixes
376
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS) && !defined(BOOST_HAS_STDINT_H)
378
// undef all the macros:
391
#endif // __STDC_CONSTANT_MACROS_DEFINED etc.