diff options
Diffstat (limited to 'devdocs/c/types%2Finteger.html')
| -rw-r--r-- | devdocs/c/types%2Finteger.html | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/devdocs/c/types%2Finteger.html b/devdocs/c/types%2Finteger.html new file mode 100644 index 00000000..2815d35d --- /dev/null +++ b/devdocs/c/types%2Finteger.html @@ -0,0 +1,140 @@ + <h1 id="firstHeading" class="firstHeading">Fixed width integer types <span class="t-mark-rev t-since-c99">(since C99)</span> +</h1> <h3 id="Types"> Types</h3> <table class="t-dsc-begin"> <tr class="t-dsc-header"> <th colspan="2"> Defined in header <code><stdint.h></code> </th> +</tr> <tr class="t-dsc"> <td> <code>int8_t</code><br><code>int16_t</code><br><code>int32_t</code><br><code>int64_t</code> </td> <td> signed integer type with width of<br> exactly 8, 16, 32 and 64 bits respectively<br>with no padding bits and using 2's complement for negative values<br>(provided only if the implementation directly supports the type) </td> +</tr> <tr class="t-dsc"> <td> <code>int_fast8_t</code><br><code>int_fast16_t</code><br><code>int_fast32_t</code><br><code>int_fast64_t</code> </td> <td> fastest signed integer type with width of<br> at least 8, 16, 32 and 64 bits respectively </td> +</tr> <tr class="t-dsc"> <td> <code>int_least8_t</code><br><code>int_least16_t</code><br><code>int_least32_t</code><br><code>int_least64_t</code> </td> <td> smallest signed integer type with width of<br> at least 8, 16, 32 and 64 bits respectively </td> +</tr> <tr class="t-dsc"> <td> <code>intmax_t</code> </td> <td> maximum width integer type </td> +</tr> <tr class="t-dsc"> <td> <code>intptr_t</code> </td> <td> integer type capable of holding a pointer </td> +</tr> <tr class="t-dsc"> <td> <code>uint8_t</code><br><code>uint16_t</code><br><code>uint32_t</code><br><code>uint64_t</code> </td> <td> unsigned integer type with width of<br> exactly 8, 16, 32 and 64 bits respectively <br>(provided only if the implementation directly supports the type) </td> +</tr> <tr class="t-dsc"> <td> <code>uint_fast8_t</code><br><code>uint_fast16_t</code><br><code>uint_fast32_t</code><br><code>uint_fast64_t</code> </td> <td> fastest unsigned integer type with width of<br> at least 8, 16, 32 and 64 bits respectively </td> +</tr> <tr class="t-dsc"> <td> <code>uint_least8_t</code><br><code>uint_least16_t</code><br><code>uint_least32_t</code><br><code>uint_least64_t</code> </td> <td> smallest unsigned integer type with width of<br> at least 8, 16, 32 and 64 bits respectively </td> +</tr> <tr class="t-dsc"> <td> <code>uintmax_t</code> </td> <td> maximum width unsigned integer type </td> +</tr> <tr class="t-dsc"> <td> <code>uintptr_t</code> </td> <td> unsigned integer type capable of holding a pointer </td> +</tr> </table> <p>The implementation may define typedef names <code>int<i>N</i>_t</code>, <code>int_fast<i>N</i>_t</code>, <code>int_least<i>N</i>_t</code>, <code>uint<i>N</i>_t</code>, <code>uint_fast<i>N</i>_t</code>, and <code>uint_least<i>N</i>_t</code> when <i>N</i> is not 8, 16, 32 or 64. Typedef names of the form <code>int<i>N</i>_t</code> may only be defined if the implementation supports an integer type of that width with no padding. Thus, uint24_t denotes an unsigned integer type with a width of exactly 24 bits.</p> +<p>Each of the macros listed in below is defined if and only if the implementation defines the corresponding typedef name. The macros <code>INT<i>N</i>_C</code> and <code>UINT<i>N</i>_C</code> correspond to the typedef names <code>int_least<i>N</i>_t</code> and <code>uint_least<i>N</i>_t</code>, respectively.</p> +<h3 id="Macro_constants"> Macro constants</h3> <table class="t-dsc-begin"> <tr class="t-dsc-header"> <th colspan="2"> Defined in header <code><stdint.h></code> </th> +</tr> <tr> <td colspan="2"> <h5 id="Signed_integers_:_width"> Signed integers : width </h5> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INT8_WIDTH</span><span>INT16_WIDTH</span><span>INT32_WIDTH</span><span>INT64_WIDTH</span></span></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span><span class="t-mark">(optional)</span></span></span></div> </td> <td> bit width of an object of type int8_t, int16_t, int32_t, int64_t (exactly 8, 16, 32, 64) <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INT_FAST8_WIDTH</span><span>INT_FAST16_WIDTH</span><span>INT_FAST32_WIDTH</span><span>INT_FAST64_WIDTH</span></span></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span></span></span></div> </td> <td> bit width of an object of type int_fast8_t, int_fast16_t, int_fast32_t, int_fast64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INT_LEAST8_WIDTH</span><span>INT_LEAST16_WIDTH</span><span>INT_LEAST32_WIDTH</span><span>INT_LEAST64_WIDTH</span></span></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span></span></span></div> </td> <td> bit width of an object of type int_least8_t, int_least16_t, int_least32_t, int_least64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INTPTR_WIDTH</span></span></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span><span class="t-mark">(optional)</span></span></span></div> </td> <td> bit width of an object of type intptr_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INTMAX_WIDTH</span></span></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span></span></span></div> </td> <td> bit width of an object of type intmax_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr> <td colspan="2"> <h5 id="Signed_integers_:_minimum_value"> Signed integers : minimum value </h5> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INT8_MIN</span><span>INT16_MIN</span><span>INT32_MIN</span><span>INT64_MIN</span></span></div> </td> <td> minimum value of an object of type int8_t, int16_t, int32_t, int64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INT_FAST8_MIN</span><span>INT_FAST16_MIN</span><span>INT_FAST32_MIN</span><span>INT_FAST64_MIN</span></span></div> </td> <td> minimum value of an object of type int_fast8_t, int_fast16_t, int_fast32_t, int_fast64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INT_LEAST8_MIN</span><span>INT_LEAST16_MIN</span><span>INT_LEAST32_MIN</span><span>INT_LEAST64_MIN</span></span></div> </td> <td> minimum value of an object of type int_least8_t, int_least16_t, int_least32_t, int_least64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INTPTR_MIN</span></span></div> </td> <td> minimum value of an object of type intptr_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INTMAX_MIN</span></span></div> </td> <td> minimum value of an object of type intmax_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr> <td colspan="2"> <h5 id="Signed_integers_:_maximum_value"> Signed integers : maximum value </h5> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INT8_MAX</span><span>INT16_MAX</span><span>INT32_MAX</span><span>INT64_MAX</span></span></div> </td> <td> maximum value of an object of type int8_t, int16_t, int32_t, int64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INT_FAST8_MAX</span><span>INT_FAST16_MAX</span><span>INT_FAST32_MAX</span><span>INT_FAST64_MAX</span></span></div> </td> <td> maximum value of an object of type int_fast8_t, int_fast16_t, int_fast32_t, int_fast64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INT_LEAST8_MAX</span><span>INT_LEAST16_MAX</span><span>INT_LEAST32_MAX</span><span>INT_LEAST64_MAX</span></span></div> </td> <td> maximum value of an object of type int_least8_t, int_least16_t, int_least32_t, int_least64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INTPTR_MAX</span></span></div> </td> <td> maximum value of an object of type intptr_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INTMAX_MAX</span></span></div> </td> <td> maximum value of an object of type intmax_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr> <td colspan="2"> <h5 id="Unsigned_integers_:_width"> Unsigned integers : width </h5> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINT8_WIDTH</span><span>UINT16_WIDTH</span><span>UINT32_WIDTH</span><span>UINT64_WIDTH</span></span></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span><span class="t-mark">(optional)</span></span></span></div> </td> <td> bit width of an object of type uint8_t, uint16_t, uint32_t, uint64_t (exactly 8, 16, 32, 64) <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINT_FAST8_WIDTH</span><span>UINT_FAST16_WIDTH</span><span>UINT_FAST32_WIDTH</span><span>UINT_FAST64_WIDTH</span></span></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span></span></span></div> </td> <td> bit width of an object of type uint_fast8_t, uint_fast16_t, uint_fast32_t, uint_fast64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINT_LEAST8_WIDTH</span><span>UINT_LEAST16_WIDTH</span><span>UINT_LEAST32_WIDTH</span><span>UINT_LEAST64_WIDTH</span></span></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span></span></span></div> </td> <td> bit width of an object of type uint_least8_t, uint_least16_t, uint_least32_t, uint_least64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINTPTR_WIDTH</span></span></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span><span class="t-mark">(optional)</span></span></span></div> </td> <td> bit width of an object of type uintptr_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINTMAX_WIDTH</span></span></div> +<div><span class="t-lines"><span><span class="t-mark-rev t-since-c23">(C23)</span></span></span></div> </td> <td> bit width of an object of type uintmax_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr> <td colspan="2"> <h5 id="Unsigned_integers_:_maximum_value"> Unsigned integers : maximum value </h5> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINT8_MAX</span><span>UINT16_MAX</span><span>UINT32_MAX</span><span>UINT64_MAX</span></span></div> </td> <td> maximum value of an object of type uint8_t, uint16_t, uint32_t, uint64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINT_FAST8_MAX</span><span>UINT_FAST16_MAX</span><span>UINT_FAST32_MAX</span><span>UINT_FAST64_MAX</span></span></div> </td> <td> maximum value of an object of type uint_fast8_t, uint_fast16_t, uint_fast32_t, uint_fast64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINT_LEAST8_MAX</span><span>UINT_LEAST16_MAX</span><span>UINT_LEAST32_MAX</span><span>UINT_LEAST64_MAX</span></span></div> </td> <td> maximum value of an object of type uint_least8_t, uint_least16_t, uint_least32_t, uint_least64_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINTPTR_MAX</span></span></div> </td> <td> maximum value of an object of type uintptr_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINTMAX_MAX</span></span></div> </td> <td> maximum value of an object of type uintmax_t <br> <span class="t-mark">(macro constant)</span> </td> +</tr> </table> <h3 id="Function_macros_for_minimum-width_integer_constants"> Function macros for minimum-width integer constants</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INT8_C</span><span>INT16_C</span><span>INT32_C</span><span>INT64_C</span></span></div> </td> <td> expands to an integer constant expression having the value specified by its argument and the type int_least8_t, int_least16_t, int_least32_t, int_least64_t respectively <br> <span class="t-mark">(function macro)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>INTMAX_C</span></span></div> </td> <td> expands to an integer constant expression having the value specified by its argument and the type intmax_t <br> <span class="t-mark">(function macro)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINT8_C</span><span>UINT16_C</span><span>UINT32_C</span><span>UINT64_C</span></span></div> </td> <td> expands to an integer constant expression having the value specified by its argument and the type uint_least8_t, uint_least16_t, uint_least32_t, uint_least64_t respectively <br> <span class="t-mark">(function macro)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><span class="t-lines"><span>UINTMAX_C</span></span></div> </td> <td> expands to an integer constant expression having the value specified by its argument and the type uintmax_t <br> <span class="t-mark">(function macro)</span> </td> +</tr> </table> <div class="c source-c"><pre data-language="c">#include <stdint.h> +UINT64_C(0x123) // might expand to 0x123ULL or 0x123UL</pre></div> <h3 id="Format_macro_constants"> Format macro constants</h3> <table class="t-dsc-begin"> <tr class="t-dsc-header"> <th colspan="2"> Defined in header <code><inttypes.h></code> </th> +</tr> </table> <h4 id="Format_constants_for_the_fprintf_family_of_functions"> Format constants for the <code><a href="../io/fprintf" title="c/io/fprintf">fprintf</a></code> family of functions</h4> <p>Each of the <code>PRI</code> macros listed here is defined if and only if the implementation defines the corresponding typedef name.</p> +<table class="wikitable"> <tr> <th rowspan="2">Equivalent<br>for <span class="kw4">int</span> or<br><span class="kw4">unsigned</span> <span class="kw4">int</span> </th> <th rowspan="2">Description </th> <th colspan="5">Macros for data types </th> +</tr> <tr> <td> +<br><br><br><br><div><code>[u]intx_t</code></div> +<br><br><br><br> </td> <td> +<div><code>[u]int_leastx_t</code></div> </td> <td> +<div><code>[u]int_fastx_t</code></div> </td> <td> +<div><code>[u]intmax_t</code></div> </td> <td> +<div><code>[u]intptr_t</code></div> </td> +</tr> <tr> <th> <code>d</code> </th> <td rowspan="2">output of a signed decimal integer value </td> <td>PRId<b>x</b> </td> <td>PRIdLEAST<b>x</b> </td> <td>PRIdFAST<b>x</b> </td> <td>PRIdMAX </td> <td>PRIdPTR </td> +</tr> <tr> <th> <code>i</code> </th> <td>PRIi<b>x</b> </td> <td>PRIiLEAST<b>x</b> </td> <td>PRIiFAST<b>x</b> </td> <td>PRIiMAX </td> <td>PRIiPTR </td> +</tr> <tr> <th> <code>u</code> </th> <td>output of an unsigned decimal integer value </td> <td>PRIu<b>x</b> </td> <td>PRIuLEAST<b>x</b> </td> <td>PRIuFAST<b>x</b> </td> <td>PRIuMAX </td> <td>PRIuPTR </td> +</tr> <tr> <th> <code>o</code> </th> <td>output of an unsigned octal integer value </td> <td>PRIo<b>x</b> </td> <td>PRIoLEAST<b>x</b> </td> <td>PRIoFAST<b>x</b> </td> <td>PRIoMAX </td> <td>PRIoPTR </td> +</tr> <tr> <th> <code>x</code> </th> <td>output of an unsigned lowercase hexadecimal integer value </td> <td>PRIx<b>x</b> </td> <td>PRIxLEAST<b>x</b> </td> <td>PRIxFAST<b>x</b> </td> <td>PRIxMAX </td> <td>PRIxPTR </td> +</tr> <tr> <th> <code>X</code> </th> <td>output of an unsigned uppercase hexadecimal integer value </td> <td>PRIX<b>x</b> </td> <td>PRIXLEAST<b>x</b> </td> <td>PRIXFAST<b>x</b> </td> <td>PRIXMAX </td> <td>PRIXPTR </td> +</tr> +</table> <h4 id="Format_constants_for_the_fscanf_family_of_functions"> Format constants for the <code><a href="../io/fscanf" title="c/io/fscanf">fscanf</a></code> family of functions</h4> <p>Each of the <code>SCN</code> macros listed in here is defined if and only if the implementation defines the corresponding typedef name and has a suitable <code><a href="../io/fscanf" title="c/io/fscanf">fscanf</a></code> length modifier for the type.</p> +<table class="wikitable"> <tr> <th rowspan="2">Equivalent<br>for <span class="kw4">int</span> or<br><span class="kw4">unsigned</span> <span class="kw4">int</span> </th> <th rowspan="2">Description </th> <th colspan="5">Macros for data types </th> +</tr> <tr> <td> +<br><br><br><br><div><code>[u]intx_t</code></div> +<br><br><br><br> </td> <td> +<div><code>[u]int_leastx_t</code></div> </td> <td> +<div><code>[u]int_fastx_t</code></div> </td> <td> +<div><code>[u]intmax_t</code></div> </td> <td> +<div><code>[u]intptr_t</code></div> </td> +</tr> <tr> <th> <code>d</code> </th> <td>input of a signed decimal integer value </td> <td>SCNd<b>x</b> </td> <td>SCNdLEAST<b>x</b> </td> <td>SCNdFAST<b>x</b> </td> <td>SCNdMAX </td> <td>SCNdPTR </td> +</tr> <tr> <th> <code>i</code> </th> <td>input of a signed integer value (base is determined by the first characters parsed) </td> <td>SCNi<b>x</b> </td> <td>SCNiLEAST<b>x</b> </td> <td>SCNiFAST<b>x</b> </td> <td>SCNiMAX </td> <td>SCNiPTR </td> +</tr> <tr> <th> <code>u</code> </th> <td>input of an unsigned decimal integer value </td> <td>SCNu<b>x</b> </td> <td>SCNuLEAST<b>x</b> </td> <td>SCNuFAST<b>x</b> </td> <td>SCNuMAX </td> <td>SCNuPTR </td> +</tr> <tr> <th> <code>o</code> </th> <td>input of an unsigned octal integer value </td> <td>SCNo<b>x</b> </td> <td>SCNoLEAST<b>x</b> </td> <td>SCNoFAST<b>x</b> </td> <td>SCNoMAX </td> <td>SCNoPTR </td> +</tr> <tr> <th> <code>x</code> </th> <td>input of an unsigned hexadecimal integer value </td> <td>SCNx<b>x</b> </td> <td>SCNxLEAST<b>x</b> </td> <td>SCNxFAST<b>x</b> </td> <td>SCNxMAX </td> <td>SCNxPTR </td> +</tr> +</table> <h3 id="Example"> Example</h3> <div class="t-example"> +<p>See also <a href="https://en.cppreference.com/w/cpp/language/user_literal#Notes" title="cpp/language/user literal">C++ compatibility note</a> regarding spaces before <a href="#Format_macro_constants">format macros</a> used in this example.</p> +<div class="c source-c"><pre data-language="c">#include <inttypes.h> +#include <stdio.h> + +int main(void) +{ + printf("%zu\n", sizeof(int64_t)); + printf("%s\n", PRId64); + printf("%+" PRId64 "\n", INT64_MIN); + printf("%+" PRId64 "\n", INT64_MAX); + + int64_t n = 7; + printf("%+" PRId64 "\n", n); +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">8 +lld +-9223372036854775808 ++9223372036854775807 ++7</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C23 standard (ISO/IEC 9899:2023): </li> +<ul> +<li> 7.8.1 Macros for format specifiers (p: TBD) </li> +<li> 7.18 Integer types <stdint.h> (p: TBD) </li> +</ul> +<li> C17 standard (ISO/IEC 9899:2018): </li> +<ul> +<li> 7.8.1 Macros for format specifiers (p: 158-159) </li> +<li> 7.18 Integer types <stdint.h> (p: 212-216) </li> +</ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul> +<li> 7.8.1 Macros for format specifiers (p: 217-218) </li> +<li> 7.18 Integer types <stdint.h> (p: 289-295) </li> +</ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul> +<li> 7.8.1 Macros for format specifiers (p: 198-199) </li> +<li> 7.18 Integer types <stdint.h> (p: 255-261) </li> +</ul> +</ul> <h3 id="See_also"> See also</h3> <ul><li> <a href="../language/arithmetic_types" title="c/language/arithmetic types">Arithmetic types</a> </li></ul> <table class="t-dsc-begin"> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/types/integer" title="cpp/types/integer">C++ documentation</a></span> for <span class=""><span>Fixed width integer types</span></span> </td> +</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/language/user_literal" title="cpp/language/user literal">C++ documentation</a></span> for <span class=""><span>User-defined literals (<a href="https://en.cppreference.com/w/cpp/language/user_literal#Notes" title="cpp/language/user literal">formatting macros note</a>)</span></span> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/types/integer" class="_attribution-link">https://en.cppreference.com/w/c/types/integer</a> + </p> +</div> |
