1 | // boost cstdint.hpp header file ------------------------------------------// |
---|
2 | |
---|
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) |
---|
9 | |
---|
10 | // See http://www.boost.org/libs/integer for documentation. |
---|
11 | |
---|
12 | // Revision History |
---|
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) |
---|
21 | |
---|
22 | |
---|
23 | #ifndef BOOST_CSTDINT_HPP |
---|
24 | #define BOOST_CSTDINT_HPP |
---|
25 | |
---|
26 | #include <boost/config.hpp> |
---|
27 | |
---|
28 | |
---|
29 | #ifdef BOOST_HAS_STDINT_H |
---|
30 | |
---|
31 | // The following #include is an implementation artifact; not part of interface. |
---|
32 | # ifdef __hpux |
---|
33 | // HP-UX has a vaguely nice <stdint.h> in a non-standard location |
---|
34 | # include <inttypes.h> |
---|
35 | # ifdef __STDC_32_MODE__ |
---|
36 | // this is triggered with GCC, because it defines __cplusplus < 199707L |
---|
37 | # define BOOST_NO_INT64_T |
---|
38 | # endif |
---|
39 | # elif defined(__FreeBSD__) || defined(__IBMCPP__) |
---|
40 | # include <inttypes.h> |
---|
41 | # else |
---|
42 | # include <stdint.h> |
---|
43 | |
---|
44 | // There is a bug in Cygwin two _C macros |
---|
45 | # if defined(__STDC_CONSTANT_MACROS) && defined(__CYGWIN__) |
---|
46 | # undef INTMAX_C |
---|
47 | # undef UINTMAX_C |
---|
48 | # define INTMAX_C(c) c##LL |
---|
49 | # define UINTMAX_C(c) c##ULL |
---|
50 | # endif |
---|
51 | |
---|
52 | # endif |
---|
53 | |
---|
54 | #ifdef __QNX__ |
---|
55 | |
---|
56 | // QNX (Dinkumware stdlib) defines these as non-standard names. |
---|
57 | // Reflect to the standard names. |
---|
58 | |
---|
59 | typedef ::intleast8_t int_least8_t; |
---|
60 | typedef ::intfast8_t int_fast8_t; |
---|
61 | typedef ::uintleast8_t uint_least8_t; |
---|
62 | typedef ::uintfast8_t uint_fast8_t; |
---|
63 | |
---|
64 | typedef ::intleast16_t int_least16_t; |
---|
65 | typedef ::intfast16_t int_fast16_t; |
---|
66 | typedef ::uintleast16_t uint_least16_t; |
---|
67 | typedef ::uintfast16_t uint_fast16_t; |
---|
68 | |
---|
69 | typedef ::intleast32_t int_least32_t; |
---|
70 | typedef ::intfast32_t int_fast32_t; |
---|
71 | typedef ::uintleast32_t uint_least32_t; |
---|
72 | typedef ::uintfast32_t uint_fast32_t; |
---|
73 | |
---|
74 | # ifndef BOOST_NO_INT64_T |
---|
75 | |
---|
76 | typedef ::intleast64_t int_least64_t; |
---|
77 | typedef ::intfast64_t int_fast64_t; |
---|
78 | typedef ::uintleast64_t uint_least64_t; |
---|
79 | typedef ::uintfast64_t uint_fast64_t; |
---|
80 | |
---|
81 | # endif |
---|
82 | |
---|
83 | #endif |
---|
84 | |
---|
85 | namespace boost |
---|
86 | { |
---|
87 | |
---|
88 | using ::int8_t; |
---|
89 | using ::int_least8_t; |
---|
90 | using ::int_fast8_t; |
---|
91 | using ::uint8_t; |
---|
92 | using ::uint_least8_t; |
---|
93 | using ::uint_fast8_t; |
---|
94 | |
---|
95 | using ::int16_t; |
---|
96 | using ::int_least16_t; |
---|
97 | using ::int_fast16_t; |
---|
98 | using ::uint16_t; |
---|
99 | using ::uint_least16_t; |
---|
100 | using ::uint_fast16_t; |
---|
101 | |
---|
102 | using ::int32_t; |
---|
103 | using ::int_least32_t; |
---|
104 | using ::int_fast32_t; |
---|
105 | using ::uint32_t; |
---|
106 | using ::uint_least32_t; |
---|
107 | using ::uint_fast32_t; |
---|
108 | |
---|
109 | # ifndef BOOST_NO_INT64_T |
---|
110 | |
---|
111 | using ::int64_t; |
---|
112 | using ::int_least64_t; |
---|
113 | using ::int_fast64_t; |
---|
114 | using ::uint64_t; |
---|
115 | using ::uint_least64_t; |
---|
116 | using ::uint_fast64_t; |
---|
117 | |
---|
118 | # endif |
---|
119 | |
---|
120 | using ::intmax_t; |
---|
121 | using ::uintmax_t; |
---|
122 | |
---|
123 | } // namespace boost |
---|
124 | |
---|
125 | #elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__) |
---|
126 | // FreeBSD and Tru64 have an <inttypes.h> that contains much of what we need. |
---|
127 | # include <inttypes.h> |
---|
128 | |
---|
129 | namespace boost { |
---|
130 | |
---|
131 | using ::int8_t; |
---|
132 | typedef int8_t int_least8_t; |
---|
133 | typedef int8_t int_fast8_t; |
---|
134 | using ::uint8_t; |
---|
135 | typedef uint8_t uint_least8_t; |
---|
136 | typedef uint8_t uint_fast8_t; |
---|
137 | |
---|
138 | using ::int16_t; |
---|
139 | typedef int16_t int_least16_t; |
---|
140 | typedef int16_t int_fast16_t; |
---|
141 | using ::uint16_t; |
---|
142 | typedef uint16_t uint_least16_t; |
---|
143 | typedef uint16_t uint_fast16_t; |
---|
144 | |
---|
145 | using ::int32_t; |
---|
146 | typedef int32_t int_least32_t; |
---|
147 | typedef int32_t int_fast32_t; |
---|
148 | using ::uint32_t; |
---|
149 | typedef uint32_t uint_least32_t; |
---|
150 | typedef uint32_t uint_fast32_t; |
---|
151 | |
---|
152 | # ifndef BOOST_NO_INT64_T |
---|
153 | |
---|
154 | using ::int64_t; |
---|
155 | typedef int64_t int_least64_t; |
---|
156 | typedef int64_t int_fast64_t; |
---|
157 | using ::uint64_t; |
---|
158 | typedef uint64_t uint_least64_t; |
---|
159 | typedef uint64_t uint_fast64_t; |
---|
160 | |
---|
161 | typedef int64_t intmax_t; |
---|
162 | typedef uint64_t uintmax_t; |
---|
163 | |
---|
164 | # else |
---|
165 | |
---|
166 | typedef int32_t intmax_t; |
---|
167 | typedef uint32_t uintmax_t; |
---|
168 | |
---|
169 | # endif |
---|
170 | |
---|
171 | } // namespace boost |
---|
172 | |
---|
173 | #else // BOOST_HAS_STDINT_H |
---|
174 | |
---|
175 | # include <boost/limits.hpp> // implementation artifact; not part of interface |
---|
176 | # include <limits.h> // needed for limits macros |
---|
177 | |
---|
178 | |
---|
179 | namespace boost |
---|
180 | { |
---|
181 | |
---|
182 | // These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit |
---|
183 | // platforms. For other systems, they will have to be hand tailored. |
---|
184 | // |
---|
185 | // Because the fast types are assumed to be the same as the undecorated types, |
---|
186 | // it may be possible to hand tailor a more efficient implementation. Such |
---|
187 | // an optimization may be illusionary; on the Intel x86-family 386 on, for |
---|
188 | // example, byte arithmetic and load/stores are as fast as "int" sized ones. |
---|
189 | |
---|
190 | // 8-bit types ------------------------------------------------------------// |
---|
191 | |
---|
192 | # if UCHAR_MAX == 0xff |
---|
193 | typedef signed char int8_t; |
---|
194 | typedef signed char int_least8_t; |
---|
195 | typedef signed char int_fast8_t; |
---|
196 | typedef unsigned char uint8_t; |
---|
197 | typedef unsigned char uint_least8_t; |
---|
198 | typedef unsigned char uint_fast8_t; |
---|
199 | # else |
---|
200 | # error defaults not correct; you must hand modify boost/cstdint.hpp |
---|
201 | # endif |
---|
202 | |
---|
203 | // 16-bit types -----------------------------------------------------------// |
---|
204 | |
---|
205 | # if USHRT_MAX == 0xffff |
---|
206 | # if defined(__crayx1) |
---|
207 | // The Cray X1 has a 16-bit short, however it is not recommend |
---|
208 | // for use in performance critical code. |
---|
209 | typedef short int16_t; |
---|
210 | typedef short int_least16_t; |
---|
211 | typedef int int_fast16_t; |
---|
212 | typedef unsigned short uint16_t; |
---|
213 | typedef unsigned short uint_least16_t; |
---|
214 | typedef unsigned int uint_fast16_t; |
---|
215 | # else |
---|
216 | typedef short int16_t; |
---|
217 | typedef short int_least16_t; |
---|
218 | typedef short int_fast16_t; |
---|
219 | typedef unsigned short uint16_t; |
---|
220 | typedef unsigned short uint_least16_t; |
---|
221 | typedef unsigned short uint_fast16_t; |
---|
222 | # endif |
---|
223 | # elif (USHRT_MAX == 0xffffffff) && defined(CRAY) |
---|
224 | // no 16-bit types on Cray: |
---|
225 | typedef short int_least16_t; |
---|
226 | typedef short int_fast16_t; |
---|
227 | typedef unsigned short uint_least16_t; |
---|
228 | typedef unsigned short uint_fast16_t; |
---|
229 | # else |
---|
230 | # error defaults not correct; you must hand modify boost/cstdint.hpp |
---|
231 | # endif |
---|
232 | |
---|
233 | // 32-bit types -----------------------------------------------------------// |
---|
234 | |
---|
235 | # if ULONG_MAX == 0xffffffff |
---|
236 | typedef long int32_t; |
---|
237 | typedef long int_least32_t; |
---|
238 | typedef long int_fast32_t; |
---|
239 | typedef unsigned long uint32_t; |
---|
240 | typedef unsigned long uint_least32_t; |
---|
241 | typedef unsigned long uint_fast32_t; |
---|
242 | # elif UINT_MAX == 0xffffffff |
---|
243 | typedef int int32_t; |
---|
244 | typedef int int_least32_t; |
---|
245 | typedef int int_fast32_t; |
---|
246 | typedef unsigned int uint32_t; |
---|
247 | typedef unsigned int uint_least32_t; |
---|
248 | typedef unsigned int uint_fast32_t; |
---|
249 | # else |
---|
250 | # error defaults not correct; you must hand modify boost/cstdint.hpp |
---|
251 | # endif |
---|
252 | |
---|
253 | // 64-bit types + intmax_t and uintmax_t ----------------------------------// |
---|
254 | |
---|
255 | # if defined(BOOST_HAS_LONG_LONG) && \ |
---|
256 | !defined(BOOST_MSVC) && !defined(__BORLANDC__) && \ |
---|
257 | (!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \ |
---|
258 | (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX)) |
---|
259 | # if defined(__hpux) |
---|
260 | // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions |
---|
261 | # elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL) |
---|
262 | // 2**64 - 1 |
---|
263 | # else |
---|
264 | # error defaults not correct; you must hand modify boost/cstdint.hpp |
---|
265 | # endif |
---|
266 | |
---|
267 | typedef ::boost::long_long_type intmax_t; |
---|
268 | typedef ::boost::ulong_long_type uintmax_t; |
---|
269 | typedef ::boost::long_long_type int64_t; |
---|
270 | typedef ::boost::long_long_type int_least64_t; |
---|
271 | typedef ::boost::long_long_type int_fast64_t; |
---|
272 | typedef ::boost::ulong_long_type uint64_t; |
---|
273 | typedef ::boost::ulong_long_type uint_least64_t; |
---|
274 | typedef ::boost::ulong_long_type uint_fast64_t; |
---|
275 | |
---|
276 | # elif ULONG_MAX != 0xffffffff |
---|
277 | |
---|
278 | # if ULONG_MAX == 18446744073709551615 // 2**64 - 1 |
---|
279 | typedef long intmax_t; |
---|
280 | typedef unsigned long uintmax_t; |
---|
281 | typedef long int64_t; |
---|
282 | typedef long int_least64_t; |
---|
283 | typedef long int_fast64_t; |
---|
284 | typedef unsigned long uint64_t; |
---|
285 | typedef unsigned long uint_least64_t; |
---|
286 | typedef unsigned long uint_fast64_t; |
---|
287 | # else |
---|
288 | # error defaults not correct; you must hand modify boost/cstdint.hpp |
---|
289 | # endif |
---|
290 | # elif defined(__GNUC__) && defined(BOOST_HAS_LONG_LONG) |
---|
291 | __extension__ typedef long long intmax_t; |
---|
292 | __extension__ typedef unsigned long long uintmax_t; |
---|
293 | __extension__ typedef long long int64_t; |
---|
294 | __extension__ typedef long long int_least64_t; |
---|
295 | __extension__ typedef long long int_fast64_t; |
---|
296 | __extension__ typedef unsigned long long uint64_t; |
---|
297 | __extension__ typedef unsigned long long uint_least64_t; |
---|
298 | __extension__ typedef unsigned long long uint_fast64_t; |
---|
299 | # elif defined(BOOST_HAS_MS_INT64) |
---|
300 | // |
---|
301 | // we have Borland/Intel/Microsoft __int64: |
---|
302 | // |
---|
303 | typedef __int64 intmax_t; |
---|
304 | typedef unsigned __int64 uintmax_t; |
---|
305 | typedef __int64 int64_t; |
---|
306 | typedef __int64 int_least64_t; |
---|
307 | typedef __int64 int_fast64_t; |
---|
308 | typedef unsigned __int64 uint64_t; |
---|
309 | typedef unsigned __int64 uint_least64_t; |
---|
310 | typedef unsigned __int64 uint_fast64_t; |
---|
311 | # else // assume no 64-bit integers |
---|
312 | # define BOOST_NO_INT64_T |
---|
313 | typedef int32_t intmax_t; |
---|
314 | typedef uint32_t uintmax_t; |
---|
315 | # endif |
---|
316 | |
---|
317 | } // namespace boost |
---|
318 | |
---|
319 | |
---|
320 | #endif // BOOST_HAS_STDINT_H |
---|
321 | |
---|
322 | #endif // BOOST_CSTDINT_HPP |
---|
323 | |
---|
324 | |
---|
325 | /**************************************************** |
---|
326 | |
---|
327 | Macro definition section: |
---|
328 | |
---|
329 | Define various INTXX_C macros only if |
---|
330 | __STDC_CONSTANT_MACROS is defined. |
---|
331 | |
---|
332 | Undefine the macros if __STDC_CONSTANT_MACROS is |
---|
333 | not defined and the macros are (cf <cassert>). |
---|
334 | |
---|
335 | Added 23rd September 2000 (John Maddock). |
---|
336 | Modified 11th September 2001 to be excluded when |
---|
337 | BOOST_HAS_STDINT_H is defined (John Maddock). |
---|
338 | |
---|
339 | ******************************************************/ |
---|
340 | |
---|
341 | #if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H) |
---|
342 | # define BOOST__STDC_CONSTANT_MACROS_DEFINED |
---|
343 | # if defined(BOOST_HAS_MS_INT64) |
---|
344 | // |
---|
345 | // Borland/Intel/Microsoft compilers have width specific suffixes: |
---|
346 | // |
---|
347 | # define INT8_C(value) value##i8 |
---|
348 | # define INT16_C(value) value##i16 |
---|
349 | # define INT32_C(value) value##i32 |
---|
350 | # define INT64_C(value) value##i64 |
---|
351 | # ifdef __BORLANDC__ |
---|
352 | // Borland bug: appending ui8 makes the type a signed char |
---|
353 | # define UINT8_C(value) static_cast<unsigned char>(value##u) |
---|
354 | # else |
---|
355 | # define UINT8_C(value) value##ui8 |
---|
356 | # endif |
---|
357 | # define UINT16_C(value) value##ui16 |
---|
358 | # define UINT32_C(value) value##ui32 |
---|
359 | # define UINT64_C(value) value##ui64 |
---|
360 | # define INTMAX_C(value) value##i64 |
---|
361 | # define UINTMAX_C(value) value##ui64 |
---|
362 | |
---|
363 | # else |
---|
364 | // do it the old fashioned way: |
---|
365 | |
---|
366 | // 8-bit types ------------------------------------------------------------// |
---|
367 | |
---|
368 | # if UCHAR_MAX == 0xff |
---|
369 | # define INT8_C(value) static_cast<boost::int8_t>(value) |
---|
370 | # define UINT8_C(value) static_cast<boost::uint8_t>(value##u) |
---|
371 | # endif |
---|
372 | |
---|
373 | // 16-bit types -----------------------------------------------------------// |
---|
374 | |
---|
375 | # if USHRT_MAX == 0xffff |
---|
376 | # define INT16_C(value) static_cast<boost::int16_t>(value) |
---|
377 | # define UINT16_C(value) static_cast<boost::uint16_t>(value##u) |
---|
378 | # endif |
---|
379 | |
---|
380 | // 32-bit types -----------------------------------------------------------// |
---|
381 | |
---|
382 | # if UINT_MAX == 0xffffffff |
---|
383 | # define INT32_C(value) value |
---|
384 | # define UINT32_C(value) value##u |
---|
385 | # elif ULONG_MAX == 0xffffffff |
---|
386 | # define INT32_C(value) value##L |
---|
387 | # define UINT32_C(value) value##uL |
---|
388 | # endif |
---|
389 | |
---|
390 | // 64-bit types + intmax_t and uintmax_t ----------------------------------// |
---|
391 | |
---|
392 | # if defined(BOOST_HAS_LONG_LONG) && \ |
---|
393 | (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX)) |
---|
394 | |
---|
395 | # if defined(__hpux) |
---|
396 | // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions |
---|
397 | # elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \ |
---|
398 | (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || \ |
---|
399 | (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U) |
---|
400 | |
---|
401 | # else |
---|
402 | # error defaults not correct; you must hand modify boost/cstdint.hpp |
---|
403 | # endif |
---|
404 | # define INT64_C(value) value##LL |
---|
405 | # define UINT64_C(value) value##uLL |
---|
406 | # elif ULONG_MAX != 0xffffffff |
---|
407 | |
---|
408 | # if ULONG_MAX == 18446744073709551615 // 2**64 - 1 |
---|
409 | # define INT64_C(value) value##L |
---|
410 | # define UINT64_C(value) value##uL |
---|
411 | # else |
---|
412 | # error defaults not correct; you must hand modify boost/cstdint.hpp |
---|
413 | # endif |
---|
414 | # endif |
---|
415 | |
---|
416 | # ifdef BOOST_NO_INT64_T |
---|
417 | # define INTMAX_C(value) INT32_C(value) |
---|
418 | # define UINTMAX_C(value) UINT32_C(value) |
---|
419 | # else |
---|
420 | # define INTMAX_C(value) INT64_C(value) |
---|
421 | # define UINTMAX_C(value) UINT64_C(value) |
---|
422 | # endif |
---|
423 | |
---|
424 | # endif // Borland/Microsoft specific width suffixes |
---|
425 | |
---|
426 | |
---|
427 | #elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS) && !defined(BOOST_HAS_STDINT_H) |
---|
428 | // |
---|
429 | // undef all the macros: |
---|
430 | // |
---|
431 | # undef INT8_C |
---|
432 | # undef INT16_C |
---|
433 | # undef INT32_C |
---|
434 | # undef INT64_C |
---|
435 | # undef UINT8_C |
---|
436 | # undef UINT16_C |
---|
437 | # undef UINT32_C |
---|
438 | # undef UINT64_C |
---|
439 | # undef INTMAX_C |
---|
440 | # undef UINTMAX_C |
---|
441 | |
---|
442 | #endif // __STDC_CONSTANT_MACROS_DEFINED etc. |
---|
443 | |
---|
444 | |
---|
445 | |
---|
446 | |
---|