cstdint.hpp 18 KB

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