1<inttypes.h>(0P) POSIX Programmer's Manual <inttypes.h>(0P)
2
3
4
6 inttypes.h - fixed size integer types
7
9 #include <inttypes.h>
10
12 Some of the functionality described on this reference page extends the
13 ISO C standard. Applications shall define the appropriate feature test
14 macro (see the System Interfaces volume of IEEE Std 1003.1-2001, Sec‐
15 tion 2.2, The Compilation Environment) to enable the visibility of
16 these symbols in this header.
17
18 The <inttypes.h> header shall include the <stdint.h> header.
19
20 The <inttypes.h> header shall include a definition of at least the fol‐
21 lowing type:
22
23 imaxdiv_t
24 Structure type that is the type of the value returned by the
25 imaxdiv() function.
26
27
28 The following macros shall be defined. Each expands to a character
29 string literal containing a conversion specifier, possibly modified by
30 a length modifier, suitable for use within the format argument of a
31 formatted input/output function when converting the corresponding inte‐
32 ger type. These macros have the general form of PRI (character string
33 literals for the fprintf() and fwprintf() family of functions) or SCN
34 (character string literals for the fscanf() and fwscanf() family of
35 functions), followed by the conversion specifier, followed by a name
36 corresponding to a similar type name in <stdint.h>. In these names, N
37 represents the width of the type as described in <stdint.h>. For exam‐
38 ple, PRIdFAST32 can be used in a format string to print the value of an
39 integer of type int_fast32_t.
40
41 The fprintf() macros for signed integers are:
42
43 PRIdN PRIdLEASTN PRIdFASTN PRIdMAX PRIdPTR
44 PRIiN PRIiLEASTN PRIiFASTN PRIiMAX PRIiPTR
45
46 The fprintf() macros for unsigned integers are:
47
48 PRIoN PRIoLEASTN PRIoFASTN PRIoMAX PRIoPTR
49 PRIuN PRIuLEASTN PRIuFASTN PRIuMAX PRIuPTR
50 PRIxN PRIxLEASTN PRIxFASTN PRIxMAX PRIxPTR
51 PRIXN PRIXLEASTN PRIXFASTN PRIXMAX PRIXPTR
52
53 The fscanf() macros for signed integers are:
54
55 SCNdN SCNdLEASTN SCNdFASTN SCNdMAX SCNdPTR
56 SCNiN SCNiLEASTN SCNiFASTN SCNiMAX SCNiPTR
57
58 The fscanf() macros for unsigned integers are:
59
60 SCNoN SCNoLEASTN SCNoFASTN SCNoMAX SCNoPTR
61 SCNuN SCNuLEASTN SCNuFASTN SCNuMAX SCNuPTR
62 SCNxN SCNxLEASTN SCNxFASTN SCNxMAX SCNxPTR
63
64 For each type that the implementation provides in <stdint.h>, the cor‐
65 responding fprintf() and fwprintf() macros shall be defined and the
66 corresponding fscanf() and fwscanf() macros shall be defined unless the
67 implementation does not have a suitable modifier for the type.
68
69 The following shall be declared as functions and may also be defined as
70 macros. Function prototypes shall be provided.
71
72
73 intmax_t imaxabs(intmax_t);
74 imaxdiv_t imaxdiv(intmax_t, intmax_t);
75 intmax_t strtoimax(const char *restrict, char **restrict, int);
76 uintmax_t strtoumax(const char *restrict, char **restrict, int);
77 intmax_t wcstoimax(const wchar_t *restrict, wchar_t **restrict, int);
78 uintmax_t wcstoumax(const wchar_t *restrict, wchar_t **restrict, int);
79
81 #include <inttypes.h>
82 #include <wchar.h>
83 int main(void)
84 {
85 uintmax_t i = UINTMAX_MAX; // This type always exists.
86 wprintf(L"The largest integer value is %020"
87 PRIxMAX "\n", i);
88 return 0;
89 }
90
91 The following sections are informative.
92
94 The purpose of <inttypes.h> is to provide a set of integer types whose
95 definitions are consistent across machines and independent of operating
96 systems and other implementation idiosyncrasies. It defines, via type‐
97 def, integer types of various sizes. Implementations are free to type‐
98 def them as ISO C standard integer types or extensions that they sup‐
99 port. Consistent use of this header will greatly increase the portabil‐
100 ity of applications across platforms.
101
103 The ISO/IEC 9899:1990 standard specified that the language should sup‐
104 port four signed and unsigned integer data types- char, short, int, and
105 long- but placed very little requirement on their size other than that
106 int and short be at least 16 bits and long be at least as long as int
107 and not smaller than 32 bits. For 16-bit systems, most implementations
108 assigned 8, 16, 16, and 32 bits to char, short, int, and long, respec‐
109 tively. For 32-bit systems, the common practice has been to assign 8,
110 16, 32, and 32 bits to these types. This difference in int size can
111 create some problems for users who migrate from one system to another
112 which assigns different sizes to integer types, because the ISO C stan‐
113 dard integer promotion rule can produce silent changes unexpectedly.
114 The need for defining an extended integer type increased with the
115 introduction of 64-bit systems.
116
118 Macro names beginning with PRI or SCN followed by any lowercase letter
119 or 'X' may be added to the macros defined in the <inttypes.h> header.
120
122 The System Interfaces volume of IEEE Std 1003.1-2001, imaxdiv()
123
125 Portions of this text are reprinted and reproduced in electronic form
126 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
127 -- Portable Operating System Interface (POSIX), The Open Group Base
128 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
129 Electrical and Electronics Engineers, Inc and The Open Group. In the
130 event of any discrepancy between this version and the original IEEE and
131 The Open Group Standard, the original IEEE and The Open Group Standard
132 is the referee document. The original Standard can be obtained online
133 at http://www.opengroup.org/unix/online.html .
134
135
136
137IEEE/The Open Group 2003 <inttypes.h>(0P)