1stdint.h(0P) POSIX Programmer's Manual stdint.h(0P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 stdint.h — integer types
14
16 #include <stdint.h>
17
19 Some of the functionality described on this reference page extends the
20 ISO C standard. Applications shall define the appropriate feature test
21 macro (see the System Interfaces volume of POSIX.1‐2008, Section 2.2,
22 The Compilation Environment) to enable the visibility of these symbols
23 in this header.
24
25 The <stdint.h> header shall declare sets of integer types having speci‐
26 fied widths, and shall define corresponding sets of macros. It shall
27 also define macros that specify limits of integer types corresponding
28 to types defined in other standard headers.
29
30 Note: The ``width'' of an integer type is the number of bits used
31 to store its value in a pure binary system; the actual type
32 may use more bits than that (for example, a 28-bit type could
33 be stored in 32 bits of actual storage). An N-bit signed type
34 has values in the range −2N−1 or 1−2N−1 to 2N−1−1, while an
35 N-bit unsigned type has values in the range 0 to 2N−1.
36
37 Types are defined in the following categories:
38
39 * Integer types having certain exact widths
40
41 * Integer types having at least certain specified widths
42
43 * Fastest integer types having at least certain specified widths
44
45 * Integer types wide enough to hold pointers to objects
46
47 * Integer types having greatest width
48
49 (Some of these types may denote the same type.)
50
51 Corresponding macros specify limits of the declared types and construct
52 suitable constants.
53
54 For each type described herein that the implementation provides, the
55 <stdint.h> header shall declare that typedef name and define the asso‐
56 ciated macros. Conversely, for each type described herein that the
57 implementation does not provide, the <stdint.h> header shall not
58 declare that typedef name, nor shall it define the associated macros.
59 An implementation shall provide those types described as required, but
60 need not provide any of the others (described as optional).
61
62 Integer Types
63 When typedef names differing only in the absence or presence of the
64 initial u are defined, they shall denote corresponding signed and
65 unsigned types as described in the ISO/IEC 9899:1999 standard, Section
66 6.2.5; an implementation providing one of these corresponding types
67 shall also provide the other.
68
69 In the following descriptions, the symbol N represents an unsigned dec‐
70 imal integer with no leading zeros (for example, 8 or 24, but not 04 or
71 048).
72
73 * Exact-width integer types
74
75 The typedef name intN_t designates a signed integer type with width
76 N, no padding bits, and a two's-complement representation. Thus,
77 int8_t denotes a signed integer type with a width of exactly 8
78 bits.
79
80 The typedef name uintN_t designates an unsigned integer type with
81 width N. Thus, uint24_t denotes an unsigned integer type with a
82 width of exactly 24 bits.
83
84 The following types are required:
85
86 int8_t
87 int16_t
88 int32_t
89 uint8_t
90 uint16_t
91 uint32_t
92
93 If an implementation provides integer types with width 64 that meet
94 these requirements, then the following types are required: int64_t
95 uint64_t
96
97 In particular, this will be the case if any of the following are
98 true:
99
100 -- The implementation supports the _POSIX_V7_ILP32_OFFBIG program‐
101 ming environment and the application is being built in the
102 _POSIX_V7_ILP32_OFFBIG programming environment (see the Shell
103 and Utilities volume of POSIX.1‐2008, c99, Programming Environ‐
104 ments).
105
106 -- The implementation supports the _POSIX_V7_LP64_OFF64 program‐
107 ming environment and the application is being built in the
108 _POSIX_V7_LP64_OFF64 programming environment.
109
110 -- The implementation supports the _POSIX_V7_LPBIG_OFFBIG program‐
111 ming environment and the application is being built in the
112 _POSIX_V7_LPBIG_OFFBIG programming environment.
113
114 All other types of this form are optional.
115
116 * Minimum-width integer types
117
118 The typedef name int_leastN_t designates a signed integer type with
119 a width of at least N, such that no signed integer type with lesser
120 size has at least the specified width. Thus, int_least32_t denotes
121 a signed integer type with a width of at least 32 bits.
122
123 The typedef name uint_leastN_t designates an unsigned integer type
124 with a width of at least N, such that no unsigned integer type with
125 lesser size has at least the specified width. Thus, uint_least16_t
126 denotes an unsigned integer type with a width of at least 16 bits.
127
128 The following types are required: int_least8_t int_least16_t
129 int_least32_t int_least64_t uint_least8_t uint_least16_t
130 uint_least32_t uint_least64_t
131
132 All other types of this form are optional.
133
134 * Fastest minimum-width integer types
135
136 Each of the following types designates an integer type that is usu‐
137 ally fastest to operate with among all integer types that have at
138 least the specified width.
139
140 The designated type is not guaranteed to be fastest for all pur‐
141 poses; if the implementation has no clear grounds for choosing one
142 type over another, it will simply pick some integer type satisfying
143 the signedness and width requirements.
144
145 The typedef name int_fastN_t designates the fastest signed integer
146 type with a width of at least N. The typedef name uint_fastN_t
147 designates the fastest unsigned integer type with a width of at
148 least N.
149
150 The following types are required: int_fast8_t int_fast16_t
151 int_fast32_t int_fast64_t uint_fast8_t uint_fast16_t uint_fast32_t
152 uint_fast64_t
153
154 All other types of this form are optional.
155
156 * Integer types capable of holding object pointers
157
158 The following type designates a signed integer type with the prop‐
159 erty that any valid pointer to void can be converted to this type,
160 then converted back to a pointer to void, and the result will com‐
161 pare equal to the original pointer: intptr_t
162
163 The following type designates an unsigned integer type with the
164 property that any valid pointer to void can be converted to this
165 type, then converted back to a pointer to void, and the result will
166 compare equal to the original pointer: uintptr_t
167
168 On XSI-conformant systems, the intptr_t and uintptr_t types are
169 required; otherwise, they are optional.
170
171 * Greatest-width integer types
172
173 The following type designates a signed integer type capable of rep‐
174 resenting any value of any signed integer type: intmax_t
175
176 The following type designates an unsigned integer type capable of
177 representing any value of any unsigned integer type: uintmax_t
178
179 These types are required.
180
181 Note: Applications can test for optional types by using the corre‐
182 sponding limit macro from Limits of Specified-Width Integer
183 Types.
184
185 Limits of Specified-Width Integer Types
186 The following macros specify the minimum and maximum limits of the
187 types declared in the <stdint.h> header. Each macro name corresponds to
188 a similar type name in Integer Types.
189
190 Each instance of any defined macro shall be replaced by a constant
191 expression suitable for use in #if preprocessing directives, and this
192 expression shall have the same type as would an expression that is an
193 object of the corresponding type converted according to the integer
194 promotions. Its implementation-defined value shall be equal to or
195 greater in magnitude (absolute value) than the corresponding value
196 given below, with the same sign, except where stated to be exactly the
197 given value.
198
199 * Limits of exact-width integer types
200
201 -- Minimum values of exact-width signed integer types:
202
203 {INTN_MIN} Exactly −(2^N−1)
204
205 -- Maximum values of exact-width signed integer types:
206
207 {INTN_MAX} Exactly 2^N−1 −1
208
209 -- Maximum values of exact-width unsigned integer types:
210
211 {UINTN_MAX} Exactly 2^N −1
212
213 * Limits of minimum-width integer types
214
215 -- Minimum values of minimum-width signed integer types:
216
217 {INT_LEASTN_MIN}
218 −(2^N−1 −1)
219
220 -- Maximum values of minimum-width signed integer types:
221
222 {INT_LEASTN_MAX}
223 2^N−1 −1
224
225 -- Maximum values of minimum-width unsigned integer types:
226
227 {UINT_LEASTN_MAX}
228 2^N −1
229
230 * Limits of fastest minimum-width integer types
231
232 -- Minimum values of fastest minimum-width signed integer types:
233
234 {INT_FASTN_MIN} −(2^N−1 −1)
235
236 -- Maximum values of fastest minimum-width signed integer types:
237
238 {INT_FASTN_MAX} 2^N−1 −1
239
240 -- Maximum values of fastest minimum-width unsigned integer types:
241
242 {UINT_FASTN_MAX}
243 2^N −1
244
245 * Limits of integer types capable of holding object pointers
246
247 -- Minimum value of pointer-holding signed integer type:
248
249 {INTPTR_MIN} −(2^15 −1)
250
251 -- Maximum value of pointer-holding signed integer type:
252
253 {INTPTR_MAX} 2^15 −1
254
255 -- Maximum value of pointer-holding unsigned integer type:
256
257 {UINTPTR_MAX} 2^16 −1
258
259 * Limits of greatest-width integer types
260
261 -- Minimum value of greatest-width signed integer type:
262
263 {INTMAX_MIN} −(2^63 −1)
264
265 -- Maximum value of greatest-width signed integer type:
266
267 {INTMAX_MAX} 2^63 −1
268
269 -- Maximum value of greatest-width unsigned integer type:
270
271 {UINTMAX_MAX} 2^64 −1
272
273 Limits of Other Integer Types
274 The following macros specify the minimum and maximum limits of integer
275 types corresponding to types defined in other standard headers.
276
277 Each instance of these macros shall be replaced by a constant expres‐
278 sion suitable for use in #if preprocessing directives, and this expres‐
279 sion shall have the same type as would an expression that is an object
280 of the corresponding type converted according to the integer promo‐
281 tions. Its implementation-defined value shall be equal to or greater in
282 magnitude (absolute value) than the corresponding value given below,
283 with the same sign.
284
285 * Limits of ptrdiff_t:
286
287 {PTRDIFF_MIN} −65535
288
289 {PTRDIFF_MAX} +65535
290
291 * Limits of sig_atomic_t:
292
293 {SIG_ATOMIC_MIN}
294 See below.
295
296 {SIG_ATOMIC_MAX}
297 See below.
298
299 * Limit of size_t:
300
301 {SIZE_MAX} 65535
302
303 * Limits of wchar_t:
304
305 {WCHAR_MIN} See below.
306
307 {WCHAR_MAX} See below.
308
309 * Limits of wint_t:
310
311 {WINT_MIN} See below.
312
313 {WINT_MAX} See below.
314
315 If sig_atomic_t (see the <signal.h> header) is defined as a signed
316 integer type, the value of {SIG_ATOMIC_MIN} shall be no greater than
317 −127 and the value of {SIG_ATOMIC_MAX} shall be no less than 127; oth‐
318 erwise, sig_atomic_t shall be defined as an unsigned integer type, and
319 the value of {SIG_ATOMIC_MIN} shall be 0 and the value of
320 {SIG_ATOMIC_MAX} shall be no less than 255.
321
322 If wchar_t (see the <stddef.h> header) is defined as a signed integer
323 type, the value of {WCHAR_MIN} shall be no greater than −127 and the
324 value of {WCHAR_MAX} shall be no less than 127; otherwise, wchar_t
325 shall be defined as an unsigned integer type, and the value of
326 {WCHAR_MIN} shall be 0 and the value of {WCHAR_MAX} shall be no less
327 than 255.
328
329 If wint_t (see the <wchar.h> header) is defined as a signed integer
330 type, the value of {WINT_MIN} shall be no greater than −32767 and the
331 value of {WINT_MAX} shall be no less than 32767; otherwise, wint_t
332 shall be defined as an unsigned integer type, and the value of
333 {WINT_MIN} shall be 0 and the value of {WINT_MAX} shall be no less than
334 65535.
335
336 Macros for Integer Constant Expressions
337 The following macros expand to integer constant expressions suitable
338 for initializing objects that have integer types corresponding to types
339 defined in the <stdint.h> header. Each macro name corresponds to a sim‐
340 ilar type name listed under Minimum-width integer types and Greatest-
341 width integer types.
342
343 Each invocation of one of these macros shall expand to an integer con‐
344 stant expression suitable for use in #if preprocessing directives. The
345 type of the expression shall have the same type as would an expression
346 that is an object of the corresponding type converted according to the
347 integer promotions. The value of the expression shall be that of the
348 argument.
349
350 The argument in any instance of these macros shall be an unsuffixed
351 integer constant with a value that does not exceed the limits for the
352 corresponding type.
353
354 * Macros for minimum-width integer constant expressions
355
356 The macro INTN_C(value) shall expand to an integer constant expres‐
357 sion corresponding to the type int_leastN_t. The macro
358 UINTN_C(value) shall expand to an integer constant expression cor‐
359 responding to the type uint_leastN_t. For example, if
360 uint_least64_t is a name for the type unsigned long long, then
361 UINT64_C(0x123) might expand to the integer constant 0x123ULL.
362
363 * Macros for greatest-width integer constant expressions
364
365 The following macro expands to an integer constant expression hav‐
366 ing the value specified by its argument and the type intmax_t: INT‐
367 MAX_C(value)
368
369 The following macro expands to an integer constant expression hav‐
370 ing the value specified by its argument and the type uintmax_t:
371 UINTMAX_C(value)
372
373 The following sections are informative.
374
376 None.
377
379 The <stdint.h> header is a subset of the <inttypes.h> header more suit‐
380 able for use in freestanding environments, which might not support the
381 formatted I/O functions. In some environments, if the formatted conver‐
382 sion support is not wanted, using this header instead of the <int‐
383 types.h> header avoids defining such a large number of macros.
384
385 As a consequence of adding int8_t, the following are true:
386
387 * A byte is exactly 8 bits.
388
389 * {CHAR_BIT} has the value 8, {SCHAR_MAX} has the value 127,
390 {SCHAR_MIN} has the value −128, and {UCHAR_MAX} has the value 255.
391
392 (The POSIX standard explicitly requires 8-bit char and two's-complement
393 arithmetic.)
394
396 typedef names beginning with int or uint and ending with _t may be
397 added to the types defined in the <stdint.h> header. Macro names begin‐
398 ning with INT or UINT and ending with _MAX, _MIN, or _C may be added to
399 the macros defined in the <stdint.h> header.
400
402 <inttypes.h>, <signal.h>, <stddef.h>, <wchar.h>
403
404 The System Interfaces volume of POSIX.1‐2008, Section 2.2, The Compila‐
405 tion Environment
406
408 Portions of this text are reprinted and reproduced in electronic form
409 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
410 -- Portable Operating System Interface (POSIX), The Open Group Base
411 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
412 cal and Electronics Engineers, Inc and The Open Group. (This is
413 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
414 event of any discrepancy between this version and the original IEEE and
415 The Open Group Standard, the original IEEE and The Open Group Standard
416 is the referee document. The original Standard can be obtained online
417 at http://www.unix.org/online.html .
418
419 Any typographical or formatting errors that appear in this page are
420 most likely to have been introduced during the conversion of the source
421 files to man page format. To report such errors, see https://www.ker‐
422 nel.org/doc/man-pages/reporting_bugs.html .
423
424
425
426IEEE/The Open Group 2013 stdint.h(0P)