cstdint.hpp 14 KB

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