1inttypes.h(0P) POSIX Programmer's Manual inttypes.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 inttypes.h — fixed size integer types
14
16 #include <inttypes.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 <inttypes.h> header shall include the <stdint.h> header.
26
27 The <inttypes.h> header shall define at least the following types:
28
29 imaxdiv_t Structure type that is the type of the value returned by
30 the imaxdiv() function.
31
32 wchar_t As described in <stddef.h>.
33
34 The <inttypes.h> header shall define the following macros. Each expands
35 to a character string literal containing a conversion specifier, possi‐
36 bly modified by a length modifier, suitable for use within the format
37 argument of a formatted input/output function when converting the cor‐
38 responding integer type. These macros have the general form of PRI
39 (character string literals for the fprintf() and fwprintf() family of
40 functions) or SCN (character string literals for the fscanf() and fws‐
41 canf() family of functions), followed by the conversion specifier, fol‐
42 lowed by a name corresponding to a similar type name in <stdint.h>. In
43 these names, N represents the width of the type as described in
44 <stdint.h>. For example, PRIdFAST32 can be used in a format string to
45 print the value of an integer of type int_fast32_t.
46
47 The fprintf() macros for signed integers are:
48
49
50 PRIdN PRIdLEASTN PRIdFASTN PRIdMAX PRIdPTR
51 PRIiN PRIiLEASTN PRIiFASTN PRIiMAX PRIiPTR
52
53 The fprintf() macros for unsigned integers are:
54
55
56 PRIoN PRIoLEASTN PRIoFASTN PRIoMAX PRIoPTR
57 PRIuN PRIuLEASTN PRIuFASTN PRIuMAX PRIuPTR
58 PRIxN PRIxLEASTN PRIxFASTN PRIxMAX PRIxPTR
59 PRIXN PRIXLEASTN PRIXFASTN PRIXMAX PRIXPTR
60
61 The fscanf() macros for signed integers are:
62
63
64 SCNdN SCNdLEASTN SCNdFASTN SCNdMAX SCNdPTR
65 SCNiN SCNiLEASTN SCNiFASTN SCNiMAX SCNiPTR
66
67 The fscanf() macros for unsigned integers are:
68
69
70 SCNoN SCNoLEASTN SCNoFASTN SCNoMAX SCNoPTR
71 SCNuN SCNuLEASTN SCNuFASTN SCNuMAX SCNuPTR
72 SCNxN SCNxLEASTN SCNxFASTN SCNxMAX SCNxPTR
73
74 For each type that the implementation provides in <stdint.h>, the cor‐
75 responding fprintf() and fwprintf() macros shall be defined and the
76 corresponding fscanf() and fwscanf() macros shall be defined unless the
77 implementation does not have a suitable modifier for the type.
78
79 The following shall be declared as functions and may also be defined as
80 macros. Function prototypes shall be provided.
81
82 intmax_t imaxabs(intmax_t);
83 imaxdiv_t imaxdiv(intmax_t, intmax_t);
84 intmax_t strtoimax(const char *restrict, char **restrict, int);
85 uintmax_t strtoumax(const char *restrict, char **restrict, int);
86 intmax_t wcstoimax(const wchar_t *restrict, wchar_t **restrict, int);
87 uintmax_t wcstoumax(const wchar_t *restrict, wchar_t **restrict, int);
88
89 The following sections are informative.
90
92 #include <inttypes.h>
93 #include <wchar.h>
94 int main(void)
95 {
96 uintmax_t i = UINTMAX_MAX; // This type always exists.
97 wprintf(L"The largest integer value is %020"
98 PRIxMAX "\n", i);
99 return 0;
100 }
101
103 The purpose of <inttypes.h> is to provide a set of integer types whose
104 definitions are consistent across machines and independent of operating
105 systems and other implementation idiosyncrasies. It defines, through
106 typedef, integer types of various sizes. Implementations are free to
107 typedef them as ISO C standard integer types or extensions that they
108 support. Consistent use of this header will greatly increase the porta‐
109 bility of applications across platforms.
110
112 The ISO/IEC 9899:1990 standard specified that the language should sup‐
113 port four signed and unsigned integer data types—char, short, int, and
114 long—but placed very little requirement on their size other than that
115 int and short be at least 16 bits and long be at least as long as int
116 and not smaller than 32 bits. For 16-bit systems, most implementations
117 assigned 8, 16, 16, and 32 bits to char, short, int, and long, respec‐
118 tively. For 32-bit systems, the common practice has been to assign 8,
119 16, 32, and 32 bits to these types. This difference in int size can
120 create some problems for users who migrate from one system to another
121 which assigns different sizes to integer types, because the ISO C stan‐
122 dard integer promotion rule can produce silent changes unexpectedly.
123 The need for defining an extended integer type increased with the
124 introduction of 64-bit systems.
125
127 Macro names beginning with PRI or SCN followed by any lowercase letter
128 or 'X' may be added to the macros defined in the <inttypes.h> header.
129
131 <stddef.h>
132
133 The System Interfaces volume of POSIX.1‐2008, Section 2.2, The Compila‐
134 tion Environment, imaxabs(), imaxdiv(), strtoimax(), wcstoimax()
135
137 Portions of this text are reprinted and reproduced in electronic form
138 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
139 -- Portable Operating System Interface (POSIX), The Open Group Base
140 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
141 cal and Electronics Engineers, Inc and The Open Group. (This is
142 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
143 event of any discrepancy between this version and the original IEEE and
144 The Open Group Standard, the original IEEE and The Open Group Standard
145 is the referee document. The original Standard can be obtained online
146 at http://www.unix.org/online.html .
147
148 Any typographical or formatting errors that appear in this page are
149 most likely to have been introduced during the conversion of the source
150 files to man page format. To report such errors, see https://www.ker‐
151 nel.org/doc/man-pages/reporting_bugs.html .
152
153
154
155IEEE/The Open Group 2013 inttypes.h(0P)