cstdint.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Standard Integer Types</title>
  5. <link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
  7. <link rel="home" href="../index.html" title="Boost.Config">
  8. <link rel="up" href="../index.html" title="Boost.Config">
  9. <link rel="prev" href="build_config.html" title="Build Time Configuration">
  10. <link rel="next" href="guidelines_for_boost_authors.html" title="Guidelines for Boost Authors">
  11. </head>
  12. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  13. <table cellpadding="2" width="100%"><tr>
  14. <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
  15. <td align="center"><a href="../../../../../index.html">Home</a></td>
  16. <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
  17. <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
  18. <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
  19. <td align="center"><a href="../../../../../more/index.htm">More</a></td>
  20. </tr></table>
  21. <hr>
  22. <div class="spirit-nav">
  23. <a accesskey="p" href="build_config.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="guidelines_for_boost_authors.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  27. <a name="boost_config.cstdint"></a><a class="link" href="cstdint.html" title="Standard Integer Types">Standard Integer Types</a>
  28. </h2></div></div></div>
  29. <div class="toc"><dl class="toc">
  30. <dt><span class="section"><a href="cstdint.html#boost_config.cstdint.overview">Overview</a></span></dt>
  31. <dt><span class="section"><a href="cstdint.html#boost_config.cstdint.rationale">Rationale</a></span></dt>
  32. <dt><span class="section"><a href="cstdint.html#boost_config.cstdint.ce"><span class="emphasis"><em>Caveat emptor</em></span></a></span></dt>
  33. <dt><span class="section"><a href="cstdint.html#boost_config.cstdint.exact_width_integer_types">Exact-width
  34. integer types</a></span></dt>
  35. <dt><span class="section"><a href="cstdint.html#boost_config.cstdint.minimum_width_integer_types">Minimum-width
  36. integer types</a></span></dt>
  37. <dt><span class="section"><a href="cstdint.html#boost_config.cstdint.fastest_minimum_width_integer_types">Fastest
  38. minimum-width integer types</a></span></dt>
  39. <dt><span class="section"><a href="cstdint.html#boost_config.cstdint.greatest_width_integer_types">Greatest-width
  40. integer types</a></span></dt>
  41. <dt><span class="section"><a href="cstdint.html#boost_config.cstdint.integer_constant_macros">Integer
  42. Constant Macros</a></span></dt>
  43. <dt><span class="section"><a href="cstdint.html#boost_config.cstdint.intptr">Integers for Storing Pointers</a></span></dt>
  44. </dl></div>
  45. <div class="section">
  46. <div class="titlepage"><div><div><h3 class="title">
  47. <a name="boost_config.cstdint.overview"></a><a class="link" href="cstdint.html#boost_config.cstdint.overview" title="Overview">Overview</a>
  48. </h3></div></div></div>
  49. <p>
  50. The header <code class="literal"><a href="../../../../../boost/cstdint.hpp" target="_top">&lt;boost/cstdint.hpp&gt;</a></code>
  51. provides the typedef's useful for writing portable code that requires certain
  52. integer widths. All typedef's are in namespace boost.
  53. </p>
  54. <p>
  55. The specifications for these types are based on the ISO/IEC 9899:1999 C Language
  56. standard header &lt;stdint.h&gt;. The 64-bit types required by the C standard
  57. are <span class="emphasis"><em>not required</em></span> in the boost header, and may not be
  58. supplied for all platforms/compilers, because <code class="literal">long long</code>
  59. is not [yet] included in the C++ standard.
  60. </p>
  61. <p>
  62. See <a href="../../../test/cstdint_test.cpp" target="_top">cstdint_test.cpp</a> for
  63. a test program.
  64. </p>
  65. </div>
  66. <div class="section">
  67. <div class="titlepage"><div><div><h3 class="title">
  68. <a name="boost_config.cstdint.rationale"></a><a class="link" href="cstdint.html#boost_config.cstdint.rationale" title="Rationale">Rationale</a>
  69. </h3></div></div></div>
  70. <p>
  71. The organization of the Boost.Integer headers and classes is designed to
  72. take advantage of &lt;stdint.h&gt; types from the 1999 C standard without
  73. causing undefined behavior in terms of the 1998 C++ standard. The header
  74. &lt;boost/cstdint.hpp&gt; makes the standard integer types safely available
  75. in namespace <code class="literal">boost</code> without placing any names in namespace
  76. <code class="literal">std</code>. The intension is to complement rather than compete
  77. with the C++ Standard Library. Should some future C++ standard include &lt;stdint.h&gt;
  78. and &lt;cstdint&gt;, then &lt;boost/cstdint.hpp&gt; will continue to function,
  79. but will become redundant and may be safely deprecated.
  80. </p>
  81. <p>
  82. Because these are boost headers, their names conform to boost header naming
  83. conventions rather than C++ Standard Library header naming conventions.
  84. </p>
  85. </div>
  86. <div class="section">
  87. <div class="titlepage"><div><div><h3 class="title">
  88. <a name="boost_config.cstdint.ce"></a><a class="link" href="cstdint.html#boost_config.cstdint.ce" title="Caveat emptor"><span class="emphasis"><em>Caveat emptor</em></span></a>
  89. </h3></div></div></div>
  90. <p>
  91. As an implementation artifact, certain C &lt;limits.h&gt; macro names may
  92. possibly be visible to users of &lt;boost/cstdint.hpp&gt;. Don't use these
  93. macros; they are not part of any Boost-specified interface. Use <code class="literal">boost::integer_traits&lt;&gt;</code>
  94. or <code class="literal">std::numeric_limits&lt;&gt;</code> instead.
  95. </p>
  96. <p>
  97. As another implementation artifact, certain C &lt;stdint.h&gt; typedef names
  98. may possibly be visible in the global namespace to users of &lt;boost/cstdint.hpp&gt;.
  99. Don't use these names, they are not part of any Boost-specified interface.
  100. Use the respective names in namespace <code class="literal">boost</code> instead.
  101. </p>
  102. </div>
  103. <div class="section">
  104. <div class="titlepage"><div><div><h3 class="title">
  105. <a name="boost_config.cstdint.exact_width_integer_types"></a><a class="link" href="cstdint.html#boost_config.cstdint.exact_width_integer_types" title="Exact-width integer types">Exact-width
  106. integer types</a>
  107. </h3></div></div></div>
  108. <p>
  109. The typedef <code class="literal">int#_t</code>, with # replaced by the width, designates
  110. a signed integer type of exactly # bits; for example <code class="literal">int8_t</code>
  111. denotes an 8-bit signed integer type. Similarly, the typedef <code class="literal">uint#_t</code>
  112. designates an unsigned integer type of exactly # bits.
  113. </p>
  114. <p>
  115. These types are optional. However, if a platform supports integer types with
  116. widths of 8, 16, 32, 64, or any combination thereof, then &lt;boost/cstdint.hpp&gt;
  117. does provide the corresponding typedefs.
  118. </p>
  119. <p>
  120. The absence of int64_t and uint64_t is indicated by the macro <code class="computeroutput"><span class="identifier">BOOST_NO_INT64_T</span></code>.
  121. </p>
  122. </div>
  123. <div class="section">
  124. <div class="titlepage"><div><div><h3 class="title">
  125. <a name="boost_config.cstdint.minimum_width_integer_types"></a><a class="link" href="cstdint.html#boost_config.cstdint.minimum_width_integer_types" title="Minimum-width integer types">Minimum-width
  126. integer types</a>
  127. </h3></div></div></div>
  128. <p>
  129. The typedef <code class="literal">int_least#_t</code>, with # replaced by the width,
  130. designates a signed integer type with a width of at least # bits, such that
  131. no signed integer type with lesser size has at least the specified width.
  132. Thus, <code class="literal">int_least32_t</code> denotes the smallest signed integer
  133. type with a width of at least 32 bits. Similarly, the typedef name <code class="literal">uint_least#_t</code>
  134. designates an unsigned integer type with a width of at least # bits, such
  135. that no unsigned integer type with lesser size has at least the specified
  136. width.
  137. </p>
  138. <p>
  139. The following minimum-width integer types are provided for all platforms:
  140. </p>
  141. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  142. <li class="listitem">
  143. <code class="literal">int_least8_t</code>
  144. </li>
  145. <li class="listitem">
  146. <code class="literal">int_least16_t</code>
  147. </li>
  148. <li class="listitem">
  149. <code class="literal">int_least32_t</code>
  150. </li>
  151. <li class="listitem">
  152. <code class="literal">uint_least8_t</code>
  153. </li>
  154. <li class="listitem">
  155. <code class="literal">uint_least16_t</code>
  156. </li>
  157. <li class="listitem">
  158. <code class="literal">uint_least32_t</code>
  159. </li>
  160. </ul></div>
  161. <p>
  162. The following types are available only if, after including &lt;boost/cstdint.hpp&gt;,
  163. the macro BOOST_NO_INT64_T is not defined:
  164. </p>
  165. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  166. <li class="listitem">
  167. <code class="literal">int_least64_t</code>
  168. </li>
  169. <li class="listitem">
  170. <code class="literal">uint_least64_t</code>
  171. </li>
  172. </ul></div>
  173. <p>
  174. All other minimum-width integer types are optional.
  175. </p>
  176. </div>
  177. <div class="section">
  178. <div class="titlepage"><div><div><h3 class="title">
  179. <a name="boost_config.cstdint.fastest_minimum_width_integer_types"></a><a class="link" href="cstdint.html#boost_config.cstdint.fastest_minimum_width_integer_types" title="Fastest minimum-width integer types">Fastest
  180. minimum-width integer types</a>
  181. </h3></div></div></div>
  182. <p>
  183. The typedef <code class="literal">int_fast#_t</code>, with # replaced by the width,
  184. designates the fastest signed integer type with a width of at least # bits.
  185. Similarly, the typedef name <code class="literal">uint_fast#_t</code> designates the
  186. fastest unsigned integer type with a width of at least # bits.
  187. </p>
  188. <p>
  189. There is no guarantee that these types are fastest for all purposes. In any
  190. case, however, they satisfy the signedness and width requirements.
  191. </p>
  192. <p>
  193. The following fastest minimum-width integer types are provided for all platforms:
  194. </p>
  195. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  196. <li class="listitem">
  197. <code class="literal">int_fast8_t</code>
  198. </li>
  199. <li class="listitem">
  200. <code class="literal">int_fast16_t</code>
  201. </li>
  202. <li class="listitem">
  203. <code class="literal">int_fast32_t</code>
  204. </li>
  205. <li class="listitem">
  206. <code class="literal">uint_fast8_t</code>
  207. </li>
  208. <li class="listitem">
  209. <code class="literal">uint_fast16_t</code>
  210. </li>
  211. <li class="listitem">
  212. <code class="literal">uint_fast32_t</code>
  213. </li>
  214. </ul></div>
  215. <p>
  216. The following types are available only if, after including &lt;boost/cstdint.hpp&gt;,
  217. the macro BOOST_NO_INT64_T is not defined:
  218. </p>
  219. <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
  220. <li class="listitem">
  221. <code class="literal">int_fast64_t</code>
  222. </li>
  223. <li class="listitem">
  224. <code class="literal">uint_fast64_t</code>
  225. </li>
  226. </ul></div>
  227. <p>
  228. All other fastest minimum-width integer types are optional.
  229. </p>
  230. </div>
  231. <div class="section">
  232. <div class="titlepage"><div><div><h3 class="title">
  233. <a name="boost_config.cstdint.greatest_width_integer_types"></a><a class="link" href="cstdint.html#boost_config.cstdint.greatest_width_integer_types" title="Greatest-width integer types">Greatest-width
  234. integer types</a>
  235. </h3></div></div></div>
  236. <p>
  237. The typedef <code class="literal">intmax_t </code>designates a signed integer type
  238. capable of representing any value of any signed integer type.
  239. </p>
  240. <p>
  241. The typedef <code class="literal">uintmax_t</code> designates an unsigned integer type
  242. capable of representing any value of any unsigned integer type.
  243. </p>
  244. <p>
  245. These types are provided for all platforms.
  246. </p>
  247. </div>
  248. <div class="section">
  249. <div class="titlepage"><div><div><h3 class="title">
  250. <a name="boost_config.cstdint.integer_constant_macros"></a><a class="link" href="cstdint.html#boost_config.cstdint.integer_constant_macros" title="Integer Constant Macros">Integer
  251. Constant Macros</a>
  252. </h3></div></div></div>
  253. <p>
  254. The following macros are always defined after inclusion of this header, these
  255. allow integer constants of at least the specified width to be declared: INT8_C,
  256. UINT8_C, INT16_C, UINT16_C, INT32_C, UINT32_C, INTMAX_C, UINTMAX_C.
  257. </p>
  258. <p>
  259. The macros INT64_C and UINT64_C are also defined if the the macro BOOST_NO_INT64_T
  260. is not defined.
  261. </p>
  262. <p>
  263. The C99 macro __STDC_CONSTANT_MACROS is also defined as an artifact of the
  264. implementation.
  265. </p>
  266. <p>
  267. For example:
  268. </p>
  269. <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdint</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
  270. <span class="comment">// Here the constant 0x1FFFFFFFF has the correct suffix applied:</span>
  271. <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint64_t</span> <span class="identifier">c</span> <span class="special">=</span> <span class="identifier">INT64_C</span><span class="special">(</span><span class="number">0</span><span class="identifier">x1FFFFFFFF</span><span class="special">);</span>
  272. </pre>
  273. </div>
  274. <div class="section">
  275. <div class="titlepage"><div><div><h3 class="title">
  276. <a name="boost_config.cstdint.intptr"></a><a class="link" href="cstdint.html#boost_config.cstdint.intptr" title="Integers for Storing Pointers">Integers for Storing Pointers</a>
  277. </h3></div></div></div>
  278. <p>
  279. The typedefs <code class="literal">intptr_t</code> and <code class="literal">uintptr_t</code>
  280. defined signed and unsigned integers respectively each capable of storing
  281. a pointer. The macro <code class="literal">BOOST_HAS_INTPTR_T</code> is set when these
  282. types are available.
  283. </p>
  284. </div>
  285. </div>
  286. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  287. <td align="left"></td>
  288. <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2007 Beman Dawes, Vesa Karvonen, John
  289. Maddock<p>
  290. Distributed under the Boost Software License, Version 1.0. (See accompanying
  291. file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
  292. </p>
  293. </div></td>
  294. </tr></table>
  295. <hr>
  296. <div class="spirit-nav">
  297. <a accesskey="p" href="build_config.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="guidelines_for_boost_authors.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  298. </div>
  299. </body>
  300. </html>