1 WG14/N1256 Committee Draft -- Septermber 7, 2007 ISO/IEC 9899:TC3
5 Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
6 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv
7 1. Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
8 2. Normative references . . . . . . . . . . . . . . . . . . . . . . . 2
9 3. Terms, definitions, and symbols . . . . . . . . . . . . . . . . . . . 3
10 4. Conformance . . . . . . . . . . . . . . . . . . . . . . . . . . 7
11 5. Environment . . . . . . . . . . . . . . . . . . . . . . . . . . 9
12 5.1 Conceptual models . . . . . . . . . . . . . . . . . . . . . 9
13 5.1.1 Translation environment . . . . . . . . . . . . . . . . 9
14 5.1.2 Execution environments . . . . . . . . . . . . . . . . 11
15 5.2 Environmental considerations . . . . . . . . . . . . . . . . . 17
16 5.2.1 Character sets . . . . . . . . . . . . . . . . . . . . 17
17 5.2.2 Character display semantics . . . . . . . . . . . . . . 19
18 5.2.3 Signals and interrupts . . . . . . . . . . . . . . . . . 20
19 5.2.4 Environmental limits . . . . . . . . . . . . . . . . . 20
20 6. Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
21 6.1 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . 29
22 6.2 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 29
23 6.2.1 Scopes of identifiers . . . . . . . . . . . . . . . . . 29
24 6.2.2 Linkages of identifiers . . . . . . . . . . . . . . . . . 30
25 6.2.3 Name spaces of identifiers . . . . . . . . . . . . . . . 31
26 6.2.4 Storage durations of objects . . . . . . . . . . . . . . 32
27 6.2.5 Types . . . . . . . . . . . . . . . . . . . . . . . 33
28 6.2.6 Representations of types . . . . . . . . . . . . . . . . 37
29 6.2.7 Compatible type and composite type . . . . . . . . . . . 40
30 6.3 Conversions . . . . . . . . . . . . . . . . . . . . . . . . 42
31 6.3.1 Arithmetic operands . . . . . . . . . . . . . . . . . 42
32 6.3.2 Other operands . . . . . . . . . . . . . . . . . . . 46
33 6.4 Lexical elements . . . . . . . . . . . . . . . . . . . . . . 49
34 6.4.1 Keywords . . . . . . . . . . . . . . . . . . . . . . 50
35 6.4.2 Identifiers . . . . . . . . . . . . . . . . . . . . . . 51
36 6.4.3 Universal character names . . . . . . . . . . . . . . . 53
37 6.4.4 Constants . . . . . . . . . . . . . . . . . . . . . . 54
38 6.4.5 String literals . . . . . . . . . . . . . . . . . . . . 62
39 6.4.6 Punctuators . . . . . . . . . . . . . . . . . . . . . 63
40 6.4.7 Header names . . . . . . . . . . . . . . . . . . . . 64
41 6.4.8 Preprocessing numbers . . . . . . . . . . . . . . . . 65
42 6.4.9 Comments . . . . . . . . . . . . . . . . . . . . . 66
43 6.5 Expressions . . . . . . . . . . . . . . . . . . . . . . . . 67
47 6.5.1 Primary expressions . . . . . . . . . . . . . . . . . 69
48 6.5.2 Postfix operators . . . . . . . . . . . . . . . . . . . 69
49 6.5.3 Unary operators . . . . . . . . . . . . . . . . . . . 78
50 6.5.4 Cast operators . . . . . . . . . . . . . . . . . . . . 81
51 6.5.5 Multiplicative operators . . . . . . . . . . . . . . . . 82
52 6.5.6 Additive operators . . . . . . . . . . . . . . . . . . 82
53 6.5.7 Bitwise shift operators . . . . . . . . . . . . . . . . . 84
54 6.5.8 Relational operators . . . . . . . . . . . . . . . . . . 85
55 6.5.9 Equality operators . . . . . . . . . . . . . . . . . . 86
56 6.5.10 Bitwise AND operator . . . . . . . . . . . . . . . . . 87
57 6.5.11 Bitwise exclusive OR operator . . . . . . . . . . . . . 88
58 6.5.12 Bitwise inclusive OR operator . . . . . . . . . . . . . . 88
59 6.5.13 Logical AND operator . . . . . . . . . . . . . . . . . 89
60 6.5.14 Logical OR operator . . . . . . . . . . . . . . . . . 89
61 6.5.15 Conditional operator . . . . . . . . . . . . . . . . . 90
62 6.5.16 Assignment operators . . . . . . . . . . . . . . . . . 91
63 6.5.17 Comma operator . . . . . . . . . . . . . . . . . . . 94
64 6.6 Constant expressions . . . . . . . . . . . . . . . . . . . . . 95
65 6.7 Declarations . . . . . . . . . . . . . . . . . . . . . . . . 97
66 6.7.1 Storage-class specifiers . . . . . . . . . . . . . . . . 98
67 6.7.2 Type specifiers . . . . . . . . . . . . . . . . . . . . 99
68 6.7.3 Type qualifiers . . . . . . . . . . . . . . . . . . . . 108
69 6.7.4 Function specifiers . . . . . . . . . . . . . . . . . . 112
70 6.7.5 Declarators . . . . . . . . . . . . . . . . . . . . . 114
71 6.7.6 Type names . . . . . . . . . . . . . . . . . . . . . 122
72 6.7.7 Type definitions . . . . . . . . . . . . . . . . . . . 123
73 6.7.8 Initialization . . . . . . . . . . . . . . . . . . . . 125
74 6.8 Statements and blocks . . . . . . . . . . . . . . . . . . . . 131
75 6.8.1 Labeled statements . . . . . . . . . . . . . . . . . . 131
76 6.8.2 Compound statement . . . . . . . . . . . . . . . . . 132
77 6.8.3 Expression and null statements . . . . . . . . . . . . . 132
78 6.8.4 Selection statements . . . . . . . . . . . . . . . . . 133
79 6.8.5 Iteration statements . . . . . . . . . . . . . . . . . . 135
80 6.8.6 Jump statements . . . . . . . . . . . . . . . . . . . 136
81 6.9 External definitions . . . . . . . . . . . . . . . . . . . . . 140
82 6.9.1 Function definitions . . . . . . . . . . . . . . . . . . 141
83 6.9.2 External object definitions . . . . . . . . . . . . . . . 143
84 6.10 Preprocessing directives . . . . . . . . . . . . . . . . . . . 145
85 6.10.1 Conditional inclusion . . . . . . . . . . . . . . . . . 147
86 6.10.2 Source file inclusion . . . . . . . . . . . . . . . . . 149
87 6.10.3 Macro replacement . . . . . . . . . . . . . . . . . . 151
88 6.10.4 Line control . . . . . . . . . . . . . . . . . . . . . 158
89 6.10.5 Error directive . . . . . . . . . . . . . . . . . . . . 159
90 6.10.6 Pragma directive . . . . . . . . . . . . . . . . . . . 159
94 6.10.7 Null directive . . . . . . . . . . . . . . . . . . . . 160
95 6.10.8 Predefined macro names . . . . . . . . . . . . . . . . 160
96 6.10.9 Pragma operator . . . . . . . . . . . . . . . . . . . 161
97 6.11 Future language directions . . . . . . . . . . . . . . . . . . 163
98 6.11.1 Floating types . . . . . . . . . . . . . . . . . . . . 163
99 6.11.2 Linkages of identifiers . . . . . . . . . . . . . . . . . 163
100 6.11.3 External names . . . . . . . . . . . . . . . . . . . 163
101 6.11.4 Character escape sequences . . . . . . . . . . . . . . 163
102 6.11.5 Storage-class specifiers . . . . . . . . . . . . . . . . 163
103 6.11.6 Function declarators . . . . . . . . . . . . . . . . . 163
104 6.11.7 Function definitions . . . . . . . . . . . . . . . . . . 163
105 6.11.8 Pragma directives . . . . . . . . . . . . . . . . . . 163
106 6.11.9 Predefined macro names . . . . . . . . . . . . . . . . 163
107 7. Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
108 7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 164
109 7.1.1 Definitions of terms . . . . . . . . . . . . . . . . . . 164
110 7.1.2 Standard headers . . . . . . . . . . . . . . . . . . . 165
111 7.1.3 Reserved identifiers . . . . . . . . . . . . . . . . . . 166
112 7.1.4 Use of library functions . . . . . . . . . . . . . . . . 166
113 7.2 Diagnostics <assert.h> . . . . . . . . . . . . . . . . . . 169
114 7.2.1 Program diagnostics . . . . . . . . . . . . . . . . . 169
115 7.3 Complex arithmetic <complex.h> . . . . . . . . . . . . . . 170
116 7.3.1 Introduction . . . . . . . . . . . . . . . . . . . . . 170
117 7.3.2 Conventions . . . . . . . . . . . . . . . . . . . . . 171
118 7.3.3 Branch cuts . . . . . . . . . . . . . . . . . . . . . 171
119 7.3.4 The CX_LIMITED_RANGE pragma . . . . . . . . . . . 171
120 7.3.5 Trigonometric functions . . . . . . . . . . . . . . . . 172
121 7.3.6 Hyperbolic functions . . . . . . . . . . . . . . . . . 174
122 7.3.7 Exponential and logarithmic functions . . . . . . . . . . 176
123 7.3.8 Power and absolute-value functions . . . . . . . . . . . 177
124 7.3.9 Manipulation functions . . . . . . . . . . . . . . . . 178
125 7.4 Character handling <ctype.h> . . . . . . . . . . . . . . . . 181
126 7.4.1 Character classification functions . . . . . . . . . . . . 181
127 7.4.2 Character case mapping functions . . . . . . . . . . . . 184
128 7.5 Errors <errno.h> . . . . . . . . . . . . . . . . . . . . . 186
129 7.6 Floating-point environment <fenv.h> . . . . . . . . . . . . . 187
130 7.6.1 The FENV_ACCESS pragma . . . . . . . . . . . . . . 189
131 7.6.2 Floating-point exceptions . . . . . . . . . . . . . . . 190
132 7.6.3 Rounding . . . . . . . . . . . . . . . . . . . . . . 193
133 7.6.4 Environment . . . . . . . . . . . . . . . . . . . . 194
134 7.7 Characteristics of floating types <float.h> . . . . . . . . . . . 197
135 7.8 Format conversion of integer types <inttypes.h> . . . . . . . . 198
136 7.8.1 Macros for format specifiers . . . . . . . . . . . . . . 198
137 7.8.2 Functions for greatest-width integer types . . . . . . . . . 199
141 7.9 Alternative spellings <iso646.h> . . . . . . . . . . . . . . . 202
142 7.10 Sizes of integer types <limits.h> . . . . . . . . . . . . . . 203
143 7.11 Localization <locale.h> . . . . . . . . . . . . . . . . . . 204
144 7.11.1 Locale control . . . . . . . . . . . . . . . . . . . . 205
145 7.11.2 Numeric formatting convention inquiry . . . . . . . . . . 206
146 7.12 Mathematics <math.h> . . . . . . . . . . . . . . . . . . . 212
147 7.12.1 Treatment of error conditions . . . . . . . . . . . . . . 214
148 7.12.2 The FP_CONTRACT pragma . . . . . . . . . . . . . . 215
149 7.12.3 Classification macros . . . . . . . . . . . . . . . . . 216
150 7.12.4 Trigonometric functions . . . . . . . . . . . . . . . . 218
151 7.12.5 Hyperbolic functions . . . . . . . . . . . . . . . . . 221
152 7.12.6 Exponential and logarithmic functions . . . . . . . . . . 223
153 7.12.7 Power and absolute-value functions . . . . . . . . . . . 228
154 7.12.8 Error and gamma functions . . . . . . . . . . . . . . . 230
155 7.12.9 Nearest integer functions . . . . . . . . . . . . . . . . 231
156 7.12.10 Remainder functions . . . . . . . . . . . . . . . . . 235
157 7.12.11 Manipulation functions . . . . . . . . . . . . . . . . 236
158 7.12.12 Maximum, minimum, and positive difference functions . . . 238
159 7.12.13 Floating multiply-add . . . . . . . . . . . . . . . . . 239
160 7.12.14 Comparison macros . . . . . . . . . . . . . . . . . . 240
161 7.13 Nonlocal jumps <setjmp.h> . . . . . . . . . . . . . . . . 243
162 7.13.1 Save calling environment . . . . . . . . . . . . . . . 243
163 7.13.2 Restore calling environment . . . . . . . . . . . . . . 244
164 7.14 Signal handling <signal.h> . . . . . . . . . . . . . . . . . 246
165 7.14.1 Specify signal handling . . . . . . . . . . . . . . . . 247
166 7.14.2 Send signal . . . . . . . . . . . . . . . . . . . . . 248
167 7.15 Variable arguments <stdarg.h> . . . . . . . . . . . . . . . 249
168 7.15.1 Variable argument list access macros . . . . . . . . . . . 249
169 7.16 Boolean type and values <stdbool.h> . . . . . . . . . . . . 253
170 7.17 Common definitions <stddef.h> . . . . . . . . . . . . . . . 254
171 7.18 Integer types <stdint.h> . . . . . . . . . . . . . . . . . . 255
172 7.18.1 Integer types . . . . . . . . . . . . . . . . . . . . 255
173 7.18.2 Limits of specified-width integer types . . . . . . . . . . 257
174 7.18.3 Limits of other integer types . . . . . . . . . . . . . . 259
175 7.18.4 Macros for integer constants . . . . . . . . . . . . . . 260
176 7.19 Input/output <stdio.h> . . . . . . . . . . . . . . . . . . 262
177 7.19.1 Introduction . . . . . . . . . . . . . . . . . . . . . 262
178 7.19.2 Streams . . . . . . . . . . . . . . . . . . . . . . 264
179 7.19.3 Files . . . . . . . . . . . . . . . . . . . . . . . . 266
180 7.19.4 Operations on files . . . . . . . . . . . . . . . . . . 268
181 7.19.5 File access functions . . . . . . . . . . . . . . . . . 270
182 7.19.6 Formatted input/output functions . . . . . . . . . . . . 274
183 7.19.7 Character input/output functions . . . . . . . . . . . . . 296
184 7.19.8 Direct input/output functions . . . . . . . . . . . . . . 301
188 7.19.9 File positioning functions . . . . . . . . . . . . . . . 302
189 7.19.10 Error-handling functions . . . . . . . . . . . . . . . . 304
190 7.20 General utilities <stdlib.h> . . . . . . . . . . . . . . . . 306
191 7.20.1 Numeric conversion functions . . . . . . . . . . . . . . 307
192 7.20.2 Pseudo-random sequence generation functions . . . . . . . 312
193 7.20.3 Memory management functions . . . . . . . . . . . . . 313
194 7.20.4 Communication with the environment . . . . . . . . . . 315
195 7.20.5 Searching and sorting utilities . . . . . . . . . . . . . . 318
196 7.20.6 Integer arithmetic functions . . . . . . . . . . . . . . 320
197 7.20.7 Multibyte/wide character conversion functions . . . . . . . 321
198 7.20.8 Multibyte/wide string conversion functions . . . . . . . . 323
199 7.21 String handling <string.h> . . . . . . . . . . . . . . . . . 325
200 7.21.1 String function conventions . . . . . . . . . . . . . . . 325
201 7.21.2 Copying functions . . . . . . . . . . . . . . . . . . 325
202 7.21.3 Concatenation functions . . . . . . . . . . . . . . . . 327
203 7.21.4 Comparison functions . . . . . . . . . . . . . . . . . 328
204 7.21.5 Search functions . . . . . . . . . . . . . . . . . . . 330
205 7.21.6 Miscellaneous functions . . . . . . . . . . . . . . . . 333
206 7.22 Type-generic math <tgmath.h> . . . . . . . . . . . . . . . 335
207 7.23 Date and time <time.h> . . . . . . . . . . . . . . . . . . 338
208 7.23.1 Components of time . . . . . . . . . . . . . . . . . 338
209 7.23.2 Time manipulation functions . . . . . . . . . . . . . . 339
210 7.23.3 Time conversion functions . . . . . . . . . . . . . . . 341
211 7.24 Extended multibyte and wide character utilities <wchar.h> . . . . . 348
212 7.24.1 Introduction . . . . . . . . . . . . . . . . . . . . . 348
213 7.24.2 Formatted wide character input/output functions . . . . . . 349
214 7.24.3 Wide character input/output functions . . . . . . . . . . 367
215 7.24.4 General wide string utilities . . . . . . . . . . . . . . 371
216 7.24.5 Wide character time conversion functions . . . . . . . . . 385
217 7.24.6 Extended multibyte/wide character conversion utilities . . . . 386
218 7.25 Wide character classification and mapping utilities <wctype.h> . . . 393
219 7.25.1 Introduction . . . . . . . . . . . . . . . . . . . . . 393
220 7.25.2 Wide character classification utilities . . . . . . . . . . . 394
221 7.25.3 Wide character case mapping utilities . . . . . . . . . . . 399
222 7.26 Future library directions . . . . . . . . . . . . . . . . . . . 401
223 7.26.1 Complex arithmetic <complex.h> . . . . . . . . . . . 401
224 7.26.2 Character handling <ctype.h> . . . . . . . . . . . . 401
225 7.26.3 Errors <errno.h> . . . . . . . . . . . . . . . . . 401
226 7.26.4 Format conversion of integer types <inttypes.h> . . . . 401
227 7.26.5 Localization <locale.h> . . . . . . . . . . . . . . 401
228 7.26.6 Signal handling <signal.h> . . . . . . . . . . . . . 401
229 7.26.7 Boolean type and values <stdbool.h> . . . . . . . . . 401
230 7.26.8 Integer types <stdint.h> . . . . . . . . . . . . . . 401
231 7.26.9 Input/output <stdio.h> . . . . . . . . . . . . . . . 402
235 7.26.10 General utilities <stdlib.h> . . . . . . . . . . . . . 402
236 7.26.11 String handling <string.h> . . . . . . . . . . . . . 402
237 7.26.12 Extended multibyte and wide character utilities
238 <wchar.h> . . . . . . . . . . . . . . . . . . . . 402
239 7.26.13 Wide character classification and mapping utilities
240 <wctype.h> . . . . . . . . . . . . . . . . . . . . 402
241 Annex A (informative) Language syntax summary . . . . . . . . . . . . 403
242 A.1 Lexical grammar . . . . . . . . . . . . . . . . . . . . . . 403
243 A.2 Phrase structure grammar . . . . . . . . . . . . . . . . . . . 409
244 A.3 Preprocessing directives . . . . . . . . . . . . . . . . . . . 416
245 Annex B (informative) Library summary . . . . . . . . . . . . . . . . 419
246 B.1 Diagnostics <assert.h> . . . . . . . . . . . . . . . . . . 419
247 B.2 Complex <complex.h> . . . . . . . . . . . . . . . . . . . 419
248 B.3 Character handling <ctype.h> . . . . . . . . . . . . . . . . 421
249 B.4 Errors <errno.h> . . . . . . . . . . . . . . . . . . . . . 421
250 B.5 Floating-point environment <fenv.h> . . . . . . . . . . . . . 421
251 B.6 Characteristics of floating types <float.h> . . . . . . . . . . . 422
252 B.7 Format conversion of integer types <inttypes.h> . . . . . . . . 422
253 B.8 Alternative spellings <iso646.h> . . . . . . . . . . . . . . . 423
254 B.9 Sizes of integer types <limits.h> . . . . . . . . . . . . . . 423
255 B.10 Localization <locale.h> . . . . . . . . . . . . . . . . . . 423
256 B.11 Mathematics <math.h> . . . . . . . . . . . . . . . . . . . 423
257 B.12 Nonlocal jumps <setjmp.h> . . . . . . . . . . . . . . . . 428
258 B.13 Signal handling <signal.h> . . . . . . . . . . . . . . . . . 428
259 B.14 Variable arguments <stdarg.h> . . . . . . . . . . . . . . . 428
260 B.15 Boolean type and values <stdbool.h> . . . . . . . . . . . . 428
261 B.16 Common definitions <stddef.h> . . . . . . . . . . . . . . . 429
262 B.17 Integer types <stdint.h> . . . . . . . . . . . . . . . . . . 429
263 B.18 Input/output <stdio.h> . . . . . . . . . . . . . . . . . . 429
264 B.19 General utilities <stdlib.h> . . . . . . . . . . . . . . . . 431
265 B.20 String handling <string.h> . . . . . . . . . . . . . . . . . 433
266 B.21 Type-generic math <tgmath.h> . . . . . . . . . . . . . . . 434
267 B.22 Date and time <time.h> . . . . . . . . . . . . . . . . . . 434
268 B.23 Extended multibyte/wide character utilities <wchar.h> . . . . . . 435
269 B.24 Wide character classification and mapping utilities <wctype.h> . . . 437
270 Annex C (informative) Sequence points . . . . . . . . . . . . . . . . . 439
271 Annex D (normative) Universal character names for identifiers . . . . . . . 440
272 Annex E (informative) Implementation limits . . . . . . . . . . . . . . 442
273 Annex F (normative) IEC 60559 floating-point arithmetic . . . . . . . . . . 444
274 F.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 444
275 F.2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
276 F.3 Operators and functions . . . . . . . . . . . . . . . . . . . 445
280 F.4 Floating to integer conversion . . . . . . . . . . . . . . . . . 447
281 F.5 Binary-decimal conversion . . . . . . . . . . . . . . . . . . 447
282 F.6 Contracted expressions . . . . . . . . . . . . . . . . . . . . 448
283 F.7 Floating-point environment . . . . . . . . . . . . . . . . . . 448
284 F.8 Optimization . . . . . . . . . . . . . . . . . . . . . . . . 451
285 F.9 Mathematics <math.h> . . . . . . . . . . . . . . . . . . . 454
286 Annex G (informative) IEC 60559-compatible complex arithmetic . . . . . . 467
287 G.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 467
288 G.2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
289 G.3 Conventions . . . . . . . . . . . . . . . . . . . . . . . . 467
290 G.4 Conversions . . . . . . . . . . . . . . . . . . . . . . . . 468
291 G.5 Binary operators . . . . . . . . . . . . . . . . . . . . . . 468
292 G.6 Complex arithmetic <complex.h> . . . . . . . . . . . . . . 472
293 G.7 Type-generic math <tgmath.h> . . . . . . . . . . . . . . . 480
294 Annex H (informative) Language independent arithmetic . . . . . . . . . . 481
295 H.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 481
296 H.2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
297 H.3 Notification . . . . . . . . . . . . . . . . . . . . . . . . 485
298 Annex I (informative) Common warnings . . . . . . . . . . . . . . . . 487
299 Annex J (informative) Portability issues . . . . . . . . . . . . . . . . . 489
300 J.1 Unspecified behavior . . . . . . . . . . . . . . . . . . . . . 489
301 J.2 Undefined behavior . . . . . . . . . . . . . . . . . . . . . 492
302 J.3 Implementation-defined behavior . . . . . . . . . . . . . . . . 505
303 J.4 Locale-specific behavior . . . . . . . . . . . . . . . . . . . 512
304 J.5 Common extensions . . . . . . . . . . . . . . . . . . . . . 513
305 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
306 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
314 1 ISO (the International Organization for Standardization) and IEC (the International
315 Electrotechnical Commission) form the specialized system for worldwide
316 standardization. National bodies that are member of ISO or IEC participate in the
317 development of International Standards through technical committees established by the
318 respective organization to deal with particular fields of technical activity. ISO and IEC
319 technical committees collaborate in fields of mutual interest. Other international
320 organizations, governmental and non-governmental, in liaison with ISO and IEC, also
321 take part in the work.
322 2 International Standards are drafted in accordance with the rules given in the ISO/IEC
324 3 In the field of information technology, ISO and IEC have established a joint technical
325 committee, ISO/IEC JTC 1. Draft International Standards adopted by the joint technical
326 committee are circulated to national bodies for voting. Publication as an International
327 Standard requires approval by at least 75% of the national bodies casting a vote.
328 4 International Standard ISO/IEC 9899 was prepared by Joint Technical Committee
329 ISO/IEC JTC 1, Information technology, Subcommittee SC 22, Programming languages,
330 their environments and system software interfaces. The Working Group responsible for
331 this standard (WG 14) maintains a site on the World Wide Web at
332 http://www.open-std.org/JTC1/SC22/WG14/ containing additional
333 information relevant to this standard such as a Rationale for many of the decisions made
334 during its preparation and a log of Defect Reports and Responses.
335 5 This second edition cancels and replaces the first edition, ISO/IEC 9899:1990, as
336 amended and corrected by ISO/IEC 9899/COR1:1994, ISO/IEC 9899/AMD1:1995, and
337 ISO/IEC 9899/COR2:1996. Major changes from the previous edition include:
338 -- restricted character set support via digraphs and <iso646.h> (originally specified
340 -- wide character library support in <wchar.h> and <wctype.h> (originally
342 -- more precise aliasing rules via effective type
343 -- restricted pointers
344 -- variable length arrays
345 -- flexible array members
346 -- static and type qualifiers in parameter array declarators
347 -- complex (and imaginary) support in <complex.h>
348 -- type-generic math macros in <tgmath.h>
349 -- the long long int type and library functions
353 -- increased minimum translation limits
354 -- additional floating-point characteristics in <float.h>
355 -- remove implicit int
356 -- reliable integer division
357 -- universal character names (\u and \U)
358 -- extended identifiers
359 -- hexadecimal floating-point constants and %a and %A printf/scanf conversion
362 -- designated initializers
364 -- extended integer types and library functions in <inttypes.h> and <stdint.h>
365 -- remove implicit function declaration
366 -- preprocessor arithmetic done in intmax_t/uintmax_t
367 -- mixed declarations and code
368 -- new block scopes for selection and iteration statements
369 -- integer constant type rules
370 -- integer promotion rules
371 -- macros with a variable number of arguments
372 -- the vscanf family of functions in <stdio.h> and <wchar.h>
373 -- additional math library functions in <math.h>
374 -- treatment of error conditions by math library functions (math_errhandling)
375 -- floating-point environment access in <fenv.h>
376 -- IEC 60559 (also known as IEC 559 or IEEE arithmetic) support
377 -- trailing comma allowed in enum declaration
378 -- %lf conversion specifier allowed in printf
380 -- the snprintf family of functions in <stdio.h>
381 -- boolean type in <stdbool.h>
382 -- idempotent type qualifiers
383 -- empty macro arguments
387 -- new structure type compatibility rules (tag compatibility)
388 -- additional predefined macro names
389 -- _Pragma preprocessing operator
391 -- __func__ predefined identifier
393 -- additional strftime conversion specifiers
394 -- LIA compatibility annex
395 -- deprecate ungetc at the beginning of a binary file
396 -- remove deprecation of aliased array parameters
397 -- conversion of array to pointer not limited to lvalues
398 -- relaxed constraints on aggregate and union initialization
399 -- relaxed restrictions on portable header names
400 -- return without expression not permitted in function that returns a value (and vice
402 6 Annexes D and F form a normative part of this standard; annexes A, B, C, E, G, H, I, J,
403 the bibliography, and the index are for information only. In accordance with Part 3 of the
404 ISO/IEC Directives, this foreword, the introduction, notes, footnotes, and examples are
405 also for information only.
410 1 With the introduction of new devices and extended character sets, new features may be
411 added to this International Standard. Subclauses in the language and library clauses warn
412 implementors and programmers of usages which, though valid in themselves, may
413 conflict with future additions.
414 2 Certain features are obsolescent, which means that they may be considered for
415 withdrawal in future revisions of this International Standard. They are retained because
416 of their widespread use, but their use in new implementations (for implementation
417 features) or new programs (for language [6.11] or library features [7.26]) is discouraged.
418 3 This International Standard is divided into four major subdivisions:
419 -- preliminary elements (clauses 1-4);
420 -- the characteristics of environments that translate and execute C programs (clause 5);
421 -- the language syntax, constraints, and semantics (clause 6);
422 -- the library facilities (clause 7).
423 4 Examples are provided to illustrate possible forms of the constructions described.
424 Footnotes are provided to emphasize consequences of the rules described in that
425 subclause or elsewhere in this International Standard. References are used to refer to
426 other related subclauses. Recommendations are provided to give advice or guidance to
427 implementors. Annexes provide additional information and summarize the information
428 contained in this International Standard. A bibliography lists documents that were
429 referred to during the preparation of the standard.
430 5 The language clause (clause 6) is derived from ''The C Reference Manual''.
431 6 The library clause (clause 7) is based on the 1984 /usr/group Standard.
437 Programming languages -- C
443 1 This International Standard specifies the form and establishes the interpretation of
444 programs written in the C programming language.1) It specifies
445 -- the representation of C programs;
446 -- the syntax and constraints of the C language;
447 -- the semantic rules for interpreting C programs;
448 -- the representation of input data to be processed by C programs;
449 -- the representation of output data produced by C programs;
450 -- the restrictions and limits imposed by a conforming implementation of C.
451 2 This International Standard does not specify
452 -- the mechanism by which C programs are transformed for use by a data-processing
454 -- the mechanism by which C programs are invoked for use by a data-processing
456 -- the mechanism by which input data are transformed for use by a C program;
457 -- the mechanism by which output data are transformed after being produced by a C
459 -- the size or complexity of a program and its data that will exceed the capacity of any
460 specific data-processing system or the capacity of a particular processor;
463 1) This International Standard is designed to promote the portability of C programs among a variety of
464 data-processing systems. It is intended for use by implementors and programmers.
468 -- all minimal requirements of a data-processing system that is capable of supporting a
469 conforming implementation.
471 2. Normative references
472 1 The following normative documents contain provisions which, through reference in this
473 text, constitute provisions of this International Standard. For dated references,
474 subsequent amendments to, or revisions of, any of these publications do not apply.
475 However, parties to agreements based on this International Standard are encouraged to
476 investigate the possibility of applying the most recent editions of the normative
477 documents indicated below. For undated references, the latest edition of the normative
478 document referred to applies. Members of ISO and IEC maintain registers of currently
479 valid International Standards.
480 2 ISO 31-11:1992, Quantities and units -- Part 11: Mathematical signs and symbols for
481 use in the physical sciences and technology.
482 3 ISO/IEC 646, Information technology -- ISO 7-bit coded character set for information
484 4 ISO/IEC 2382-1:1993, Information technology -- Vocabulary -- Part 1: Fundamental
486 5 ISO 4217, Codes for the representation of currencies and funds.
487 6 ISO 8601, Data elements and interchange formats -- Information interchange --
488 Representation of dates and times.
489 7 ISO/IEC 10646 (all parts), Information technology -- Universal Multiple-Octet Coded
491 8 IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems (previously
492 designated IEC 559:1989).
497 3. Terms, definitions, and symbols
498 1 For the purposes of this International Standard, the following definitions apply. Other
499 terms are defined where they appear in italic type or on the left side of a syntax rule.
500 Terms explicitly defined in this International Standard are not to be presumed to refer
501 implicitly to similar terms defined elsewhere. Terms not defined in this International
502 Standard are to be interpreted according to ISO/IEC 2382-1. Mathematical symbols not
503 defined in this International Standard are to be interpreted according to ISO 31-11.
506 <execution-time action> to read or modify the value of an object
507 2 NOTE 1 Where only one of these two actions is meant, ''read'' or ''modify'' is used.
509 3 NOTE 2 "Modify'' includes the case where the new value being stored is the same as the previous value.
511 4 NOTE 3 Expressions that are not evaluated do not access objects.
515 requirement that objects of a particular type be located on storage boundaries with
516 addresses that are particular multiples of a byte address
520 actual parameter (deprecated)
521 expression in the comma-separated list bounded by the parentheses in a function call
522 expression, or a sequence of preprocessing tokens in the comma-separated list bounded
523 by the parentheses in a function-like macro invocation
526 external appearance or action
528 1 implementation-defined behavior
529 unspecified behavior where each implementation documents how the choice is made
530 2 EXAMPLE An example of implementation-defined behavior is the propagation of the high-order bit
531 when a signed integer is shifted right.
534 1 locale-specific behavior
535 behavior that depends on local conventions of nationality, culture, and language that each
536 implementation documents
540 2 EXAMPLE An example of locale-specific behavior is whether the islower function returns true for
541 characters other than the 26 lowercase Latin letters.
545 behavior, upon use of a nonportable or erroneous program construct or of erroneous data,
546 for which this International Standard imposes no requirements
547 2 NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable
548 results, to behaving during translation or program execution in a documented manner characteristic of the
549 environment (with or without the issuance of a diagnostic message), to terminating a translation or
550 execution (with the issuance of a diagnostic message).
552 3 EXAMPLE An example of undefined behavior is the behavior on integer overflow.
555 1 unspecified behavior
556 use of an unspecified value, or other behavior where this International Standard provides
557 two or more possibilities and imposes no further requirements on which is chosen in any
559 2 EXAMPLE An example of unspecified behavior is the order in which the arguments to a function are
564 unit of data storage in the execution environment large enough to hold an object that may
565 have one of two values
566 2 NOTE It need not be possible to express the address of each individual bit of an object.
570 addressable unit of data storage large enough to hold any member of the basic character
571 set of the execution environment
572 2 NOTE 1 It is possible to express the address of each individual byte of an object uniquely.
574 3 NOTE 2 A byte is composed of a contiguous sequence of bits, the number of which is implementation-
575 defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order
580 <abstract> member of a set of elements used for the organization, control, or
581 representation of data
584 single-byte character
585 <C> bit representation that fits in a byte
590 1 multibyte character
591 sequence of one or more bytes representing a member of the extended character set of
592 either the source or the execution environment
593 2 NOTE The extended character set is a superset of the basic character set.
597 bit representation that fits in an object of type wchar_t, capable of representing any
598 character in the current locale
601 restriction, either syntactic or semantic, by which the exposition of language elements is
604 1 correctly rounded result
605 representation in the result format that is nearest in value, subject to the current rounding
606 mode, to what the result would be given unlimited range and precision
609 message belonging to an implementation-defined subset of the implementation's message
613 reference to a later subclause of this International Standard that contains additional
614 information relevant to this subclause
617 particular set of software, running in a particular translation environment under particular
618 control options, that performs translation of programs for, and supports execution of
619 functions in, a particular execution environment
621 1 implementation limit
622 restriction imposed upon programs by the implementation
625 region of data storage in the execution environment, the contents of which can represent
630 2 NOTE When referenced, an object may be interpreted as having a particular type; see 6.3.2.1.
635 formal argument (deprecated)
636 object declared as part of a function declaration or definition that acquires a value on
637 entry to the function, or an identifier from the comma-separated list bounded by the
638 parentheses immediately following the macro name in a function-like macro definition
640 1 recommended practice
641 specification that is strongly recommended as being in keeping with the intent of the
642 standard, but that may be impractical for some implementations
645 precise meaning of the contents of an object when interpreted as having a specific type
647 1 implementation-defined value
648 unspecified value where each implementation documents how the choice is made
650 1 indeterminate value
651 either an unspecified value or a trap representation
654 valid value of the relevant type where this International Standard imposes no
655 requirements on which value is chosen in any instance
656 2 NOTE An unspecified value cannot be a trap representation.
660 ceiling of x: the least integer greater than or equal to x
661 2 EXAMPLE ???2.4??? is 3, ???-2.4??? is -2.
665 floor of x: the greatest integer less than or equal to x
666 2 EXAMPLE ???2.4??? is 2, ???-2.4??? is -3.
672 1 In this International Standard, ''shall'' is to be interpreted as a requirement on an
673 implementation or on a program; conversely, ''shall not'' is to be interpreted as a
675 2 If a ''shall'' or ''shall not'' requirement that appears outside of a constraint is violated, the
676 behavior is undefined. Undefined behavior is otherwise indicated in this International
677 Standard by the words ''undefined behavior'' or by the omission of any explicit definition
678 of behavior. There is no difference in emphasis among these three; they all describe
679 ''behavior that is undefined''.
680 3 A program that is correct in all other aspects, operating on correct data, containing
681 unspecified behavior shall be a correct program and act in accordance with 5.1.2.3.
682 4 The implementation shall not successfully translate a preprocessing translation unit
683 containing a #error preprocessing directive unless it is part of a group skipped by
684 conditional inclusion.
685 5 A strictly conforming program shall use only those features of the language and library
686 specified in this International Standard.2) It shall not produce output dependent on any
687 unspecified, undefined, or implementation-defined behavior, and shall not exceed any
688 minimum implementation limit.
689 6 The two forms of conforming implementation are hosted and freestanding. A conforming
690 hosted implementation shall accept any strictly conforming program. A conforming
691 freestanding implementation shall accept any strictly conforming program that does not
692 use complex types and in which the use of the features specified in the library clause
693 (clause 7) is confined to the contents of the standard headers <float.h>,
694 <iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and
695 <stdint.h>. A conforming implementation may have extensions (including additional
696 library functions), provided they do not alter the behavior of any strictly conforming
701 2) A strictly conforming program can use conditional features (such as those in annex F) provided the
702 use is guarded by a #ifdef directive with the appropriate macro. For example:
703 #ifdef __STDC_IEC_559__ /* FE_UPWARD defined */
705 fesetround(FE_UPWARD);
709 3) This implies that a conforming implementation reserves no identifiers other than those explicitly
710 reserved in this International Standard.
714 7 A conforming program is one that is acceptable to a conforming implementation.4)
715 8 An implementation shall be accompanied by a document that defines all implementation-
716 defined and locale-specific characteristics and all extensions.
717 Forward references: conditional inclusion (6.10.1), error directive (6.10.5),
718 characteristics of floating types <float.h> (7.7), alternative spellings <iso646.h>
719 (7.9), sizes of integer types <limits.h> (7.10), variable arguments <stdarg.h>
720 (7.15), boolean type and values <stdbool.h> (7.16), common definitions
721 <stddef.h> (7.17), integer types <stdint.h> (7.18).
726 4) Strictly conforming programs are intended to be maximally portable among conforming
727 implementations. Conforming programs may depend upon nonportable features of a conforming
734 1 An implementation translates C source files and executes C programs in two data-
735 processing-system environments, which will be called the translation environment and
736 the execution environment in this International Standard. Their characteristics define and
737 constrain the results of executing conforming C programs constructed according to the
738 syntactic and semantic rules for conforming implementations.
739 Forward references: In this clause, only a few of many possible forward references
741 5.1 Conceptual models
742 5.1.1 Translation environment
743 5.1.1.1 Program structure
744 1 A C program need not all be translated at the same time. The text of the program is kept
745 in units called source files, (or preprocessing files) in this International Standard. A
746 source file together with all the headers and source files included via the preprocessing
747 directive #include is known as a preprocessing translation unit. After preprocessing, a
748 preprocessing translation unit is called a translation unit. Previously translated translation
749 units may be preserved individually or in libraries. The separate translation units of a
750 program communicate by (for example) calls to functions whose identifiers have external
751 linkage, manipulation of objects whose identifiers have external linkage, or manipulation
752 of data files. Translation units may be separately translated and then later linked to
753 produce an executable program.
754 Forward references: linkages of identifiers (6.2.2), external definitions (6.9),
755 preprocessing directives (6.10).
756 5.1.1.2 Translation phases
757 1 The precedence among the syntax rules of translation is specified by the following
759 1. Physical source file multibyte characters are mapped, in an implementation-
760 defined manner, to the source character set (introducing new-line characters for
761 end-of-line indicators) if necessary. Trigraph sequences are replaced by
762 corresponding single-character internal representations.
766 5) Implementations shall behave as if these separate phases occur, even though many are typically folded
767 together in practice. Source files, translation units, and translated translation units need not
768 necessarily be stored as files, nor need there be any one-to-one correspondence between these entities
769 and any external representation. The description is conceptual only, and does not specify any
770 particular implementation.
774 2. Each instance of a backslash character (\) immediately followed by a new-line
775 character is deleted, splicing physical source lines to form logical source lines.
776 Only the last backslash on any physical source line shall be eligible for being part
777 of such a splice. A source file that is not empty shall end in a new-line character,
778 which shall not be immediately preceded by a backslash character before any such
779 splicing takes place.
780 3. The source file is decomposed into preprocessing tokens6) and sequences of
781 white-space characters (including comments). A source file shall not end in a
782 partial preprocessing token or in a partial comment. Each comment is replaced by
783 one space character. New-line characters are retained. Whether each nonempty
784 sequence of white-space characters other than new-line is retained or replaced by
785 one space character is implementation-defined.
786 4. Preprocessing directives are executed, macro invocations are expanded, and
787 _Pragma unary operator expressions are executed. If a character sequence that
788 matches the syntax of a universal character name is produced by token
789 concatenation (6.10.3.3), the behavior is undefined. A #include preprocessing
790 directive causes the named header or source file to be processed from phase 1
791 through phase 4, recursively. All preprocessing directives are then deleted.
792 5. Each source character set member and escape sequence in character constants and
793 string literals is converted to the corresponding member of the execution character
794 set; if there is no corresponding member, it is converted to an implementation-
795 defined member other than the null (wide) character.7)
796 6. Adjacent string literal tokens are concatenated.
797 7. White-space characters separating tokens are no longer significant. Each
798 preprocessing token is converted into a token. The resulting tokens are
799 syntactically and semantically analyzed and translated as a translation unit.
800 8. All external object and function references are resolved. Library components are
801 linked to satisfy external references to functions and objects not defined in the
802 current translation. All such translator output is collected into a program image
803 which contains information needed for execution in its execution environment.
804 Forward references: universal character names (6.4.3), lexical elements (6.4),
805 preprocessing directives (6.10), trigraph sequences (5.2.1.1), external definitions (6.9).
809 6) As described in 6.4, the process of dividing a source file's characters into preprocessing tokens is
810 context-dependent. For example, see the handling of < within a #include preprocessing directive.
811 7) An implementation need not convert all non-corresponding source characters to the same execution
817 1 A conforming implementation shall produce at least one diagnostic message (identified in
818 an implementation-defined manner) if a preprocessing translation unit or translation unit
819 contains a violation of any syntax rule or constraint, even if the behavior is also explicitly
820 specified as undefined or implementation-defined. Diagnostic messages need not be
821 produced in other circumstances.8)
822 2 EXAMPLE An implementation shall issue a diagnostic for the translation unit:
825 because in those cases where wording in this International Standard describes the behavior for a construct
826 as being both a constraint error and resulting in undefined behavior, the constraint error shall be diagnosed.
828 5.1.2 Execution environments
829 1 Two execution environments are defined: freestanding and hosted. In both cases,
830 program startup occurs when a designated C function is called by the execution
831 environment. All objects with static storage duration shall be initialized (set to their
832 initial values) before program startup. The manner and timing of such initialization are
833 otherwise unspecified. Program termination returns control to the execution
835 Forward references: storage durations of objects (6.2.4), initialization (6.7.8).
836 5.1.2.1 Freestanding environment
837 1 In a freestanding environment (in which C program execution may take place without any
838 benefit of an operating system), the name and type of the function called at program
839 startup are implementation-defined. Any library facilities available to a freestanding
840 program, other than the minimal set required by clause 4, are implementation-defined.
841 2 The effect of program termination in a freestanding environment is implementation-
843 5.1.2.2 Hosted environment
844 1 A hosted environment need not be provided, but shall conform to the following
845 specifications if present.
850 8) The intent is that an implementation should identify the nature of, and where possible localize, each
851 violation. Of course, an implementation is free to produce any number of diagnostics as long as a
852 valid program is still correctly translated. It may also successfully translate an invalid program.
856 5.1.2.2.1 Program startup
857 1 The function called at program startup is named main. The implementation declares no
858 prototype for this function. It shall be defined with a return type of int and with no
860 int main(void) { /* ... */ }
861 or with two parameters (referred to here as argc and argv, though any names may be
862 used, as they are local to the function in which they are declared):
863 int main(int argc, char *argv[]) { /* ... */ }
864 or equivalent;9) or in some other implementation-defined manner.
865 2 If they are declared, the parameters to the main function shall obey the following
867 -- The value of argc shall be nonnegative.
868 -- argv[argc] shall be a null pointer.
869 -- If the value of argc is greater than zero, the array members argv[0] through
870 argv[argc-1] inclusive shall contain pointers to strings, which are given
871 implementation-defined values by the host environment prior to program startup. The
872 intent is to supply to the program information determined prior to program startup
873 from elsewhere in the hosted environment. If the host environment is not capable of
874 supplying strings with letters in both uppercase and lowercase, the implementation
875 shall ensure that the strings are received in lowercase.
876 -- If the value of argc is greater than zero, the string pointed to by argv[0]
877 represents the program name; argv[0][0] shall be the null character if the
878 program name is not available from the host environment. If the value of argc is
879 greater than one, the strings pointed to by argv[1] through argv[argc-1]
880 represent the program parameters.
881 -- The parameters argc and argv and the strings pointed to by the argv array shall
882 be modifiable by the program, and retain their last-stored values between program
883 startup and program termination.
884 5.1.2.2.2 Program execution
885 1 In a hosted environment, a program may use all the functions, macros, type definitions,
886 and objects described in the library clause (clause 7).
890 9) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as
891 char ** argv, and so on.
895 5.1.2.2.3 Program termination
896 1 If the return type of the main function is a type compatible with int, a return from the
897 initial call to the main function is equivalent to calling the exit function with the value
898 returned by the main function as its argument;10) reaching the } that terminates the
899 main function returns a value of 0. If the return type is not compatible with int, the
900 termination status returned to the host environment is unspecified.
901 Forward references: definition of terms (7.1.1), the exit function (7.20.4.3).
902 5.1.2.3 Program execution
903 1 The semantic descriptions in this International Standard describe the behavior of an
904 abstract machine in which issues of optimization are irrelevant.
905 2 Accessing a volatile object, modifying an object, modifying a file, or calling a function
906 that does any of those operations are all side effects,11) which are changes in the state of
907 the execution environment. Evaluation of an expression may produce side effects. At
908 certain specified points in the execution sequence called sequence points, all side effects
909 of previous evaluations shall be complete and no side effects of subsequent evaluations
910 shall have taken place. (A summary of the sequence points is given in annex C.)
911 3 In the abstract machine, all expressions are evaluated as specified by the semantics. An
912 actual implementation need not evaluate part of an expression if it can deduce that its
913 value is not used and that no needed side effects are produced (including any caused by
914 calling a function or accessing a volatile object).
915 4 When the processing of the abstract machine is interrupted by receipt of a signal, only the
916 values of objects as of the previous sequence point may be relied on. Objects that may be
917 modified between the previous sequence point and the next sequence point need not have
918 received their correct values yet.
919 5 The least requirements on a conforming implementation are:
920 -- At sequence points, volatile objects are stable in the sense that previous accesses are
921 complete and subsequent accesses have not yet occurred.
926 10) In accordance with 6.2.4, the lifetimes of objects with automatic storage duration declared in main
927 will have ended in the former case, even where they would not have in the latter.
928 11) The IEC 60559 standard for binary floating-point arithmetic requires certain user-accessible status
929 flags and control modes. Floating-point operations implicitly set the status flags; modes affect result
930 values of floating-point operations. Implementations that support such floating-point state are
931 required to regard changes to it as side effects -- see annex F for details. The floating-point
932 environment library <fenv.h> provides a programming facility for indicating when these side
933 effects matter, freeing the implementations in other cases.
937 -- At program termination, all data written into files shall be identical to the result that
938 execution of the program according to the abstract semantics would have produced.
939 -- The input and output dynamics of interactive devices shall take place as specified in
940 7.19.3. The intent of these requirements is that unbuffered or line-buffered output
941 appear as soon as possible, to ensure that prompting messages actually appear prior to
942 a program waiting for input.
943 6 What constitutes an interactive device is implementation-defined.
944 7 More stringent correspondences between abstract and actual semantics may be defined by
946 8 EXAMPLE 1 An implementation might define a one-to-one correspondence between abstract and actual
947 semantics: at every sequence point, the values of the actual objects would agree with those specified by the
948 abstract semantics. The keyword volatile would then be redundant.
949 9 Alternatively, an implementation might perform various optimizations within each translation unit, such
950 that the actual semantics would agree with the abstract semantics only when making function calls across
951 translation unit boundaries. In such an implementation, at the time of each function entry and function
952 return where the calling function and the called function are in different translation units, the values of all
953 externally linked objects and of all objects accessible via pointers therein would agree with the abstract
954 semantics. Furthermore, at the time of each such function entry the values of the parameters of the called
955 function and of all objects accessible via pointers therein would agree with the abstract semantics. In this
956 type of implementation, objects referred to by interrupt service routines activated by the signal function
957 would require explicit specification of volatile storage, as well as other implementation-defined
960 10 EXAMPLE 2 In executing the fragment
964 the ''integer promotions'' require that the abstract machine promote the value of each variable to int size
965 and then add the two ints and truncate the sum. Provided the addition of two chars can be done without
966 overflow, or with overflow wrapping silently to produce the correct result, the actual execution need only
967 produce the same result, possibly omitting the promotions.
969 11 EXAMPLE 3 Similarly, in the fragment
974 the multiplication may be executed using single-precision arithmetic if the implementation can ascertain
975 that the result would be the same as if it were executed using double-precision arithmetic (for example, if d
976 were replaced by the constant 2.0, which has type double).
980 12 EXAMPLE 4 Implementations employing wide registers have to take care to honor appropriate
981 semantics. Values are independent of whether they are represented in a register or in memory. For
982 example, an implicit spilling of a register is not permitted to alter the value. Also, an explicit store and load
983 is required to round to the precision of the storage type. In particular, casts and assignments are required to
984 perform their specified conversion. For the fragment
988 d2 = (float) expression;
989 the values assigned to d1 and d2 are required to have been converted to float.
991 13 EXAMPLE 5 Rearrangement for floating-point expressions is often restricted because of limitations in
992 precision as well as range. The implementation cannot generally apply the mathematical associative rules
993 for addition or multiplication, nor the distributive rule, because of roundoff error, even in the absence of
994 overflow and underflow. Likewise, implementations cannot generally replace decimal constants in order to
995 rearrange expressions. In the following fragment, rearrangements suggested by mathematical rules for real
996 numbers are often not valid (see F.8).
999 x = (x * y) * z; // not equivalent to x *= y * z;
1000 z = (x - y) + y ; // not equivalent to z = x;
1001 z = x + x * y; // not equivalent to z = x * (1.0 + y);
1002 y = x / 5.0; // not equivalent to y = x * 0.2;
1004 14 EXAMPLE 6 To illustrate the grouping behavior of expressions, in the following fragment
1007 a = a + 32760 + b + 5;
1008 the expression statement behaves exactly the same as
1009 a = (((a + 32760) + b) + 5);
1010 due to the associativity and precedence of these operators. Thus, the result of the sum (a + 32760) is
1011 next added to b, and that result is then added to 5 which results in the value assigned to a. On a machine in
1012 which overflows produce an explicit trap and in which the range of values representable by an int is
1013 [-32768, +32767], the implementation cannot rewrite this expression as
1014 a = ((a + b) + 32765);
1015 since if the values for a and b were, respectively, -32754 and -15, the sum a + b would produce a trap
1016 while the original expression would not; nor can the expression be rewritten either as
1017 a = ((a + 32765) + b);
1019 a = (a + (b + 32765));
1020 since the values for a and b might have been, respectively, 4 and -8 or -17 and 12. However, on a machine
1021 in which overflow silently generates some value and where positive and negative overflows cancel, the
1022 above expression statement can be rewritten by the implementation in any of the above ways because the
1023 same result will occur.
1027 15 EXAMPLE 7 The grouping of an expression does not completely determine its evaluation. In the
1033 sum = sum * 10 - '0' + (*p++ = getchar());
1034 the expression statement is grouped as if it were written as
1035 sum = (((sum * 10) - '0') + ((*(p++)) = (getchar())));
1036 but the actual increment of p can occur at any time between the previous sequence point and the next
1037 sequence point (the ;), and the call to getchar can occur at any point prior to the need of its returned
1040 Forward references: expressions (6.5), type qualifiers (6.7.3), statements (6.8), the
1041 signal function (7.14), files (7.19.3).
1045 5.2 Environmental considerations
1046 5.2.1 Character sets
1047 1 Two sets of characters and their associated collating sequences shall be defined: the set in
1048 which source files are written (the source character set), and the set interpreted in the
1049 execution environment (the execution character set). Each set is further divided into a
1050 basic character set, whose contents are given by this subclause, and a set of zero or more
1051 locale-specific members (which are not members of the basic character set) called
1052 extended characters. The combined set is also called the extended character set. The
1053 values of the members of the execution character set are implementation-defined.
1054 2 In a character constant or string literal, members of the execution character set shall be
1055 represented by corresponding members of the source character set or by escape
1056 sequences consisting of the backslash \ followed by one or more characters. A byte with
1057 all bits set to 0, called the null character, shall exist in the basic execution character set; it
1058 is used to terminate a character string.
1059 3 Both the basic source and basic execution character sets shall have the following
1060 members: the 26 uppercase letters of the Latin alphabet
1061 A B C D E F G H I J K L M
1062 N O P Q R S T U V W X Y Z
1063 the 26 lowercase letters of the Latin alphabet
1064 a b c d e f g h i j k l m
1065 n o p q r s t u v w x y z
1066 the 10 decimal digits
1068 the following 29 graphic characters
1069 ! " # % & ' ( ) * + , - . / :
1070 ; < = > ? [ \ ] ^ _ { | } ~
1071 the space character, and control characters representing horizontal tab, vertical tab, and
1072 form feed. The representation of each member of the source and execution basic
1073 character sets shall fit in a byte. In both the source and execution basic character sets, the
1074 value of each character after 0 in the above list of decimal digits shall be one greater than
1075 the value of the previous. In source files, there shall be some way of indicating the end of
1076 each line of text; this International Standard treats such an end-of-line indicator as if it
1077 were a single new-line character. In the basic execution character set, there shall be
1078 control characters representing alert, backspace, carriage return, and new line. If any
1079 other characters are encountered in a source file (except in an identifier, a character
1080 constant, a string literal, a header name, a comment, or a preprocessing token that is never
1084 converted to a token), the behavior is undefined.
1085 4 A letter is an uppercase letter or a lowercase letter as defined above; in this International
1086 Standard the term does not include other characters that are letters in other alphabets.
1087 5 The universal character name construct provides a way to name other characters.
1088 Forward references: universal character names (6.4.3), character constants (6.4.4.4),
1089 preprocessing directives (6.10), string literals (6.4.5), comments (6.4.9), string (7.1.1).
1090 5.2.1.1 Trigraph sequences
1091 1 Before any other processing takes place, each occurrence of one of the following
1092 sequences of three characters (called trigraph sequences12)) is replaced with the
1093 corresponding single character.
1097 No other trigraph sequences exist. Each ? that does not begin one of the trigraphs listed
1098 above is not changed.
1100 ??=define arraycheck(a, b) a??(b??) ??!??! b??(a??)
1102 #define arraycheck(a, b) a[b] || b[a]
1104 3 EXAMPLE 2 The following source line
1106 becomes (after replacement of the trigraph sequence ??/)
1109 5.2.1.2 Multibyte characters
1110 1 The source character set may contain multibyte characters, used to represent members of
1111 the extended character set. The execution character set may also contain multibyte
1112 characters, which need not have the same encoding as for the source character set. For
1113 both character sets, the following shall hold:
1114 -- The basic character set shall be present and each character shall be encoded as a
1116 -- The presence, meaning, and representation of any additional members is locale-
1119 12) The trigraph sequences enable the input of characters that are not defined in the Invariant Code Set as
1120 described in ISO/IEC 646, which is a subset of the seven-bit US ASCII code set.
1124 -- A multibyte character set may have a state-dependent encoding, wherein each
1125 sequence of multibyte characters begins in an initial shift state and enters other
1126 locale-specific shift states when specific multibyte characters are encountered in the
1127 sequence. While in the initial shift state, all single-byte characters retain their usual
1128 interpretation and do not alter the shift state. The interpretation for subsequent bytes
1129 in the sequence is a function of the current shift state.
1130 -- A byte with all bits zero shall be interpreted as a null character independent of shift
1131 state. Such a byte shall not occur as part of any other multibyte character.
1132 2 For source files, the following shall hold:
1133 -- An identifier, comment, string literal, character constant, or header name shall begin
1134 and end in the initial shift state.
1135 -- An identifier, comment, string literal, character constant, or header name shall consist
1136 of a sequence of valid multibyte characters.
1137 5.2.2 Character display semantics
1138 1 The active position is that location on a display device where the next character output by
1139 the fputc function would appear. The intent of writing a printing character (as defined
1140 by the isprint function) to a display device is to display a graphic representation of
1141 that character at the active position and then advance the active position to the next
1142 position on the current line. The direction of writing is locale-specific. If the active
1143 position is at the final position of a line (if there is one), the behavior of the display device
1145 2 Alphabetic escape sequences representing nongraphic characters in the execution
1146 character set are intended to produce actions on display devices as follows:
1147 \a (alert) Produces an audible or visible alert without changing the active position.
1148 \b (backspace) Moves the active position to the previous position on the current line. If
1149 the active position is at the initial position of a line, the behavior of the display
1150 device is unspecified.
1151 \f ( form feed) Moves the active position to the initial position at the start of the next
1153 \n (new line) Moves the active position to the initial position of the next line.
1154 \r (carriage return) Moves the active position to the initial position of the current line.
1155 \t (horizontal tab) Moves the active position to the next horizontal tabulation position
1156 on the current line. If the active position is at or past the last defined horizontal
1157 tabulation position, the behavior of the display device is unspecified.
1158 \v (vertical tab) Moves the active position to the initial position of the next vertical
1159 tabulation position. If the active position is at or past the last defined vertical
1163 tabulation position, the behavior of the display device is unspecified.
1164 3 Each of these escape sequences shall produce a unique implementation-defined value
1165 which can be stored in a single char object. The external representations in a text file
1166 need not be identical to the internal representations, and are outside the scope of this
1167 International Standard.
1168 Forward references: the isprint function (7.4.1.8), the fputc function (7.19.7.3).
1169 5.2.3 Signals and interrupts
1170 1 Functions shall be implemented such that they may be interrupted at any time by a signal,
1171 or may be called by a signal handler, or both, with no alteration to earlier, but still active,
1172 invocations' control flow (after the interruption), function return values, or objects with
1173 automatic storage duration. All such objects shall be maintained outside the function
1174 image (the instructions that compose the executable representation of a function) on a
1175 per-invocation basis.
1176 5.2.4 Environmental limits
1177 1 Both the translation and execution environments constrain the implementation of
1178 language translators and libraries. The following summarizes the language-related
1179 environmental limits on a conforming implementation; the library-related limits are
1180 discussed in clause 7.
1181 5.2.4.1 Translation limits
1182 1 The implementation shall be able to translate and execute at least one program that
1183 contains at least one instance of every one of the following limits:13)
1184 -- 127 nesting levels of blocks
1185 -- 63 nesting levels of conditional inclusion
1186 -- 12 pointer, array, and function declarators (in any combinations) modifying an
1187 arithmetic, structure, union, or incomplete type in a declaration
1188 -- 63 nesting levels of parenthesized declarators within a full declarator
1189 -- 63 nesting levels of parenthesized expressions within a full expression
1190 -- 63 significant initial characters in an internal identifier or a macro name (each
1191 universal character name or extended source character is considered a single
1193 -- 31 significant initial characters in an external identifier (each universal character name
1194 specifying a short identifier of 0000FFFF or less is considered 6 characters, each
1197 13) Implementations should avoid imposing fixed translation limits whenever possible.
1201 universal character name specifying a short identifier of 00010000 or more is
1202 considered 10 characters, and each extended source character is considered the same
1203 number of characters as the corresponding universal character name, if any)14)
1204 -- 4095 external identifiers in one translation unit
1205 -- 511 identifiers with block scope declared in one block
1206 -- 4095 macro identifiers simultaneously defined in one preprocessing translation unit
1207 -- 127 parameters in one function definition
1208 -- 127 arguments in one function call
1209 -- 127 parameters in one macro definition
1210 -- 127 arguments in one macro invocation
1211 -- 4095 characters in a logical source line
1212 -- 4095 characters in a character string literal or wide string literal (after concatenation)
1213 -- 65535 bytes in an object (in a hosted environment only)
1214 -- 15 nesting levels for #included files
1215 -- 1023 case labels for a switch statement (excluding those for any nested switch
1217 -- 1023 members in a single structure or union
1218 -- 1023 enumeration constants in a single enumeration
1219 -- 63 levels of nested structure or union definitions in a single struct-declaration-list
1220 5.2.4.2 Numerical limits
1221 1 An implementation is required to document all the limits specified in this subclause,
1222 which are specified in the headers <limits.h> and <float.h>. Additional limits are
1223 specified in <stdint.h>.
1224 Forward references: integer types <stdint.h> (7.18).
1225 5.2.4.2.1 Sizes of integer types <limits.h>
1226 1 The values given below shall be replaced by constant expressions suitable for use in #if
1227 preprocessing directives. Moreover, except for CHAR_BIT and MB_LEN_MAX, the
1228 following shall be replaced by expressions that have the same type as would an
1229 expression that is an object of the corresponding type converted according to the integer
1230 promotions. Their implementation-defined values shall be equal or greater in magnitude
1233 14) See ''future language directions'' (6.11.3).
1237 (absolute value) to those shown, with the same sign.
1238 -- number of bits for smallest object that is not a bit-field (byte)
1240 -- minimum value for an object of type signed char
1241 SCHAR_MIN -127 // -(27 - 1)
1242 -- maximum value for an object of type signed char
1243 SCHAR_MAX +127 // 27 - 1
1244 -- maximum value for an object of type unsigned char
1245 UCHAR_MAX 255 // 28 - 1
1246 -- minimum value for an object of type char
1248 -- maximum value for an object of type char
1250 -- maximum number of bytes in a multibyte character, for any supported locale
1252 -- minimum value for an object of type short int
1253 SHRT_MIN -32767 // -(215 - 1)
1254 -- maximum value for an object of type short int
1255 SHRT_MAX +32767 // 215 - 1
1256 -- maximum value for an object of type unsigned short int
1257 USHRT_MAX 65535 // 216 - 1
1258 -- minimum value for an object of type int
1259 INT_MIN -32767 // -(215 - 1)
1260 -- maximum value for an object of type int
1261 INT_MAX +32767 // 215 - 1
1262 -- maximum value for an object of type unsigned int
1263 UINT_MAX 65535 // 216 - 1
1264 -- minimum value for an object of type long int
1265 LONG_MIN -2147483647 // -(231 - 1)
1266 -- maximum value for an object of type long int
1267 LONG_MAX +2147483647 // 231 - 1
1268 -- maximum value for an object of type unsigned long int
1269 ULONG_MAX 4294967295 // 232 - 1
1273 -- minimum value for an object of type long long int
1274 LLONG_MIN -9223372036854775807 // -(263 - 1)
1275 -- maximum value for an object of type long long int
1276 LLONG_MAX +9223372036854775807 // 263 - 1
1277 -- maximum value for an object of type unsigned long long int
1278 ULLONG_MAX 18446744073709551615 // 264 - 1
1279 2 If the value of an object of type char is treated as a signed integer when used in an
1280 expression, the value of CHAR_MIN shall be the same as that of SCHAR_MIN and the
1281 value of CHAR_MAX shall be the same as that of SCHAR_MAX. Otherwise, the value of
1282 CHAR_MIN shall be 0 and the value of CHAR_MAX shall be the same as that of
1283 UCHAR_MAX.15) The value UCHAR_MAX shall equal 2CHAR_BIT - 1.
1284 Forward references: representations of types (6.2.6), conditional inclusion (6.10.1).
1285 5.2.4.2.2 Characteristics of floating types <float.h>
1286 1 The characteristics of floating types are defined in terms of a model that describes a
1287 representation of floating-point numbers and values that provide information about an
1288 implementation's floating-point arithmetic.16) The following parameters are used to
1289 define the model for each floating-point type:
1291 b base or radix of exponent representation (an integer > 1)
1292 e exponent (an integer between a minimum emin and a maximum emax )
1293 p precision (the number of base-b digits in the significand)
1294 fk nonnegative integers less than b (the significand digits)
1295 2 A floating-point number (x) is defined by the following model:
1297 x = sb e (Sum) f k b-k ,
1301 3 In addition to normalized floating-point numbers ( f 1 > 0 if x != 0), floating types may be
1302 able to contain other kinds of floating-point numbers, such as subnormal floating-point
1303 numbers (x != 0, e = emin , f 1 = 0) and unnormalized floating-point numbers (x != 0,
1304 e > emin , f 1 = 0), and values that are not floating-point numbers, such as infinities and
1305 NaNs. A NaN is an encoding signifying Not-a-Number. A quiet NaN propagates
1306 through almost every arithmetic operation without raising a floating-point exception; a
1307 signaling NaN generally raises a floating-point exception when occurring as an
1311 16) The floating-point model is intended to clarify the description of each floating-point characteristic and
1312 does not require the floating-point arithmetic of the implementation to be identical.
1316 arithmetic operand.17)
1317 4 An implementation may give zero and non-numeric values (such as infinities and NaNs) a
1318 sign or may leave them unsigned. Wherever such values are unsigned, any requirement
1319 in this International Standard to retrieve the sign shall produce an unspecified sign, and
1320 any requirement to set the sign shall be ignored.
1321 5 The accuracy of the floating-point operations (+, -, *, /) and of the library functions in
1322 <math.h> and <complex.h> that return floating-point results is implementation-
1323 defined, as is the accuracy of the conversion between floating-point internal
1324 representations and string representations performed by the library functions in
1325 <stdio.h>, <stdlib.h>, and <wchar.h>. The implementation may state that the
1326 accuracy is unknown.
1327 6 All integer values in the <float.h> header, except FLT_ROUNDS, shall be constant
1328 expressions suitable for use in #if preprocessing directives; all floating values shall be
1329 constant expressions. All except DECIMAL_DIG, FLT_EVAL_METHOD, FLT_RADIX,
1330 and FLT_ROUNDS have separate names for all three floating-point types. The floating-
1331 point model representation is provided for all values except FLT_EVAL_METHOD and
1333 7 The rounding mode for floating-point addition is characterized by the implementation-
1334 defined value of FLT_ROUNDS:18)
1338 2 toward positive infinity
1339 3 toward negative infinity
1340 All other values for FLT_ROUNDS characterize implementation-defined rounding
1342 8 Except for assignment and cast (which remove all extra range and precision), the values
1343 of operations with floating operands and values subject to the usual arithmetic
1344 conversions and of floating constants are evaluated to a format whose range and precision
1345 may be greater than required by the type. The use of evaluation formats is characterized
1346 by the implementation-defined value of FLT_EVAL_METHOD:19)
1350 17) IEC 60559:1989 specifies quiet and signaling NaNs. For implementations that do not support
1351 IEC 60559:1989, the terms quiet NaN and signaling NaN are intended to apply to encodings with
1353 18) Evaluation of FLT_ROUNDS correctly reflects any execution-time change of rounding mode through
1354 the function fesetround in <fenv.h>.
1359 0 evaluate all operations and constants just to the range and precision of the
1361 1 evaluate operations and constants of type float and double to the
1362 range and precision of the double type, evaluate long double
1363 operations and constants to the range and precision of the long double
1365 2 evaluate all operations and constants to the range and precision of the
1367 All other negative values for FLT_EVAL_METHOD characterize implementation-defined
1369 9 The values given in the following list shall be replaced by constant expressions with
1370 implementation-defined values that are greater or equal in magnitude (absolute value) to
1371 those shown, with the same sign:
1372 -- radix of exponent representation, b
1374 -- number of base-FLT_RADIX digits in the floating-point significand, p
1378 -- number of decimal digits, n, such that any floating-point number in the widest
1379 supported floating type with pmax radix b digits can be rounded to a floating-point
1380 number with n decimal digits and back again without change to the value,
1381 ??? pmax log10 b if b is a power of 10
1383 ??? ???1 + pmax log10 b??? otherwise
1385 -- number of decimal digits, q, such that any floating-point number with q decimal digits
1386 can be rounded into a floating-point number with p radix b digits and back again
1387 without change to the q decimal digits,
1392 19) The evaluation method determines evaluation formats of expressions involving all floating types, not
1393 just real types. For example, if FLT_EVAL_METHOD is 1, then the product of two float
1394 _Complex operands is represented in the double _Complex format, and its parts are evaluated to
1399 ??? p log10 b if b is a power of 10
1401 ??? ???( p - 1) log10 b??? otherwise
1405 -- minimum negative integer such that FLT_RADIX raised to one less than that power is
1406 a normalized floating-point number, emin
1410 -- minimum negative integer such that 10 raised to that power is in the range of
1411 normalized floating-point numbers, ???log10 b emin -1 ???
1416 -- maximum integer such that FLT_RADIX raised to one less than that power is a
1417 representable finite floating-point number, emax
1421 -- maximum integer such that 10 raised to that power is in the range of representable
1422 finite floating-point numbers, ???log10 ((1 - b- p )b emax )???
1426 10 The values given in the following list shall be replaced by constant expressions with
1427 implementation-defined values that are greater than or equal to those shown:
1428 -- maximum representable finite floating-point number, (1 - b- p )b emax
1432 11 The values given in the following list shall be replaced by constant expressions with
1433 implementation-defined (positive) values that are less than or equal to those shown:
1434 -- the difference between 1 and the least value greater than 1 that is representable in the
1435 given floating point type, b1- p
1442 -- minimum normalized positive floating-point number, b emin -1
1446 Recommended practice
1447 12 Conversion from (at least) double to decimal with DECIMAL_DIG digits and back
1448 should be the identity function.
1449 13 EXAMPLE 1 The following describes an artificial floating-point representation that meets the minimum
1450 requirements of this International Standard, and the appropriate values in a <float.h> header for type
1453 x = s16e (Sum) f k 16-k ,
1459 FLT_EPSILON 9.53674316E-07F
1462 FLT_MIN 2.93873588E-39F
1465 FLT_MAX 3.40282347E+38F
1468 14 EXAMPLE 2 The following describes floating-point representations that also meet the requirements for
1469 single-precision and double-precision normalized numbers in IEC 60559,20) and the appropriate values in a
1470 <float.h> header for types float and double:
1472 x f = s2e (Sum) f k 2-k ,
1477 x d = s2e (Sum) f k 2-k ,
1484 FLT_EPSILON 1.19209290E-07F // decimal constant
1485 FLT_EPSILON 0X1P-23F // hex constant
1488 20) The floating-point model in that standard sums powers of b from zero, so the values of the exponent
1489 limits are one less than shown here.
1495 FLT_MIN 1.17549435E-38F // decimal constant
1496 FLT_MIN 0X1P-126F // hex constant
1499 FLT_MAX 3.40282347E+38F // decimal constant
1500 FLT_MAX 0X1.fffffeP127F // hex constant
1503 DBL_EPSILON 2.2204460492503131E-16 // decimal constant
1504 DBL_EPSILON 0X1P-52 // hex constant
1507 DBL_MIN 2.2250738585072014E-308 // decimal constant
1508 DBL_MIN 0X1P-1022 // hex constant
1511 DBL_MAX 1.7976931348623157E+308 // decimal constant
1512 DBL_MAX 0X1.fffffffffffffP1023 // hex constant
1514 If a type wider than double were supported, then DECIMAL_DIG would be greater than 17. For
1515 example, if the widest type were to use the minimal-width IEC 60559 double-extended format (64 bits of
1516 precision), then DECIMAL_DIG would be 21.
1518 Forward references: conditional inclusion (6.10.1), complex arithmetic
1519 <complex.h> (7.3), extended multibyte and wide character utilities <wchar.h>
1520 (7.24), floating-point environment <fenv.h> (7.6), general utilities <stdlib.h>
1521 (7.20), input/output <stdio.h> (7.19), mathematics <math.h> (7.12).
1528 1 In the syntax notation used in this clause, syntactic categories (nonterminals) are
1529 indicated by italic type, and literal words and character set members (terminals) by bold
1530 type. A colon (:) following a nonterminal introduces its definition. Alternative
1531 definitions are listed on separate lines, except when prefaced by the words ''one of''. An
1532 optional symbol is indicated by the subscript ''opt'', so that
1534 indicates an optional expression enclosed in braces.
1535 2 When syntactic categories are referred to in the main text, they are not italicized and
1536 words are separated by spaces instead of hyphens.
1537 3 A summary of the language syntax is given in annex A.
1539 6.2.1 Scopes of identifiers
1540 1 An identifier can denote an object; a function; a tag or a member of a structure, union, or
1541 enumeration; a typedef name; a label name; a macro name; or a macro parameter. The
1542 same identifier can denote different entities at different points in the program. A member
1543 of an enumeration is called an enumeration constant. Macro names and macro
1544 parameters are not considered further here, because prior to the semantic phase of
1545 program translation any occurrences of macro names in the source file are replaced by the
1546 preprocessing token sequences that constitute their macro definitions.
1547 2 For each different entity that an identifier designates, the identifier is visible (i.e., can be
1548 used) only within a region of program text called its scope. Different entities designated
1549 by the same identifier either have different scopes, or are in different name spaces. There
1550 are four kinds of scopes: function, file, block, and function prototype. (A function
1551 prototype is a declaration of a function that declares the types of its parameters.)
1552 3 A label name is the only kind of identifier that has function scope. It can be used (in a
1553 goto statement) anywhere in the function in which it appears, and is declared implicitly
1554 by its syntactic appearance (followed by a : and a statement).
1555 4 Every other identifier has scope determined by the placement of its declaration (in a
1556 declarator or type specifier). If the declarator or type specifier that declares the identifier
1557 appears outside of any block or list of parameters, the identifier has file scope, which
1558 terminates at the end of the translation unit. If the declarator or type specifier that
1559 declares the identifier appears inside a block or within the list of parameter declarations in
1560 a function definition, the identifier has block scope, which terminates at the end of the
1561 associated block. If the declarator or type specifier that declares the identifier appears
1565 within the list of parameter declarations in a function prototype (not part of a function
1566 definition), the identifier has function prototype scope, which terminates at the end of the
1567 function declarator. If an identifier designates two different entities in the same name
1568 space, the scopes might overlap. If so, the scope of one entity (the inner scope) will be a
1569 strict subset of the scope of the other entity (the outer scope). Within the inner scope, the
1570 identifier designates the entity declared in the inner scope; the entity declared in the outer
1571 scope is hidden (and not visible) within the inner scope.
1572 5 Unless explicitly stated otherwise, where this International Standard uses the term
1573 ''identifier'' to refer to some entity (as opposed to the syntactic construct), it refers to the
1574 entity in the relevant name space whose declaration is visible at the point the identifier
1576 6 Two identifiers have the same scope if and only if their scopes terminate at the same
1578 7 Structure, union, and enumeration tags have scope that begins just after the appearance of
1579 the tag in a type specifier that declares the tag. Each enumeration constant has scope that
1580 begins just after the appearance of its defining enumerator in an enumerator list. Any
1581 other identifier has scope that begins just after the completion of its declarator.
1582 Forward references: declarations (6.7), function calls (6.5.2.2), function definitions
1583 (6.9.1), identifiers (6.4.2), name spaces of identifiers (6.2.3), macro replacement (6.10.3),
1584 source file inclusion (6.10.2), statements (6.8).
1585 6.2.2 Linkages of identifiers
1586 1 An identifier declared in different scopes or in the same scope more than once can be
1587 made to refer to the same object or function by a process called linkage.21) There are
1588 three kinds of linkage: external, internal, and none.
1589 2 In the set of translation units and libraries that constitutes an entire program, each
1590 declaration of a particular identifier with external linkage denotes the same object or
1591 function. Within one translation unit, each declaration of an identifier with internal
1592 linkage denotes the same object or function. Each declaration of an identifier with no
1593 linkage denotes a unique entity.
1594 3 If the declaration of a file scope identifier for an object or a function contains the storage-
1595 class specifier static, the identifier has internal linkage.22)
1596 4 For an identifier declared with the storage-class specifier extern in a scope in which a
1600 21) There is no linkage between different identifiers.
1601 22) A function declaration can contain the storage-class specifier static only if it is at file scope; see
1606 prior declaration of that identifier is visible,23) if the prior declaration specifies internal or
1607 external linkage, the linkage of the identifier at the later declaration is the same as the
1608 linkage specified at the prior declaration. If no prior declaration is visible, or if the prior
1609 declaration specifies no linkage, then the identifier has external linkage.
1610 5 If the declaration of an identifier for a function has no storage-class specifier, its linkage
1611 is determined exactly as if it were declared with the storage-class specifier extern. If
1612 the declaration of an identifier for an object has file scope and no storage-class specifier,
1613 its linkage is external.
1614 6 The following identifiers have no linkage: an identifier declared to be anything other than
1615 an object or a function; an identifier declared to be a function parameter; a block scope
1616 identifier for an object declared without the storage-class specifier extern.
1617 7 If, within a translation unit, the same identifier appears with both internal and external
1618 linkage, the behavior is undefined.
1619 Forward references: declarations (6.7), expressions (6.5), external definitions (6.9),
1621 6.2.3 Name spaces of identifiers
1622 1 If more than one declaration of a particular identifier is visible at any point in a
1623 translation unit, the syntactic context disambiguates uses that refer to different entities.
1624 Thus, there are separate name spaces for various categories of identifiers, as follows:
1625 -- label names (disambiguated by the syntax of the label declaration and use);
1626 -- the tags of structures, unions, and enumerations (disambiguated by following any24)
1627 of the keywords struct, union, or enum);
1628 -- the members of structures or unions; each structure or union has a separate name
1629 space for its members (disambiguated by the type of the expression used to access the
1630 member via the . or -> operator);
1631 -- all other identifiers, called ordinary identifiers (declared in ordinary declarators or as
1632 enumeration constants).
1633 Forward references: enumeration specifiers (6.7.2.2), labeled statements (6.8.1),
1634 structure and union specifiers (6.7.2.1), structure and union members (6.5.2.3), tags
1635 (6.7.2.3), the goto statement (6.8.6.1).
1640 23) As specified in 6.2.1, the later declaration might hide the prior declaration.
1641 24) There is only one name space for tags even though three are possible.
1645 6.2.4 Storage durations of objects
1646 1 An object has a storage duration that determines its lifetime. There are three storage
1647 durations: static, automatic, and allocated. Allocated storage is described in 7.20.3.
1648 2 The lifetime of an object is the portion of program execution during which storage is
1649 guaranteed to be reserved for it. An object exists, has a constant address,25) and retains
1650 its last-stored value throughout its lifetime.26) If an object is referred to outside of its
1651 lifetime, the behavior is undefined. The value of a pointer becomes indeterminate when
1652 the object it points to reaches the end of its lifetime.
1653 3 An object whose identifier is declared with external or internal linkage, or with the
1654 storage-class specifier static has static storage duration. Its lifetime is the entire
1655 execution of the program and its stored value is initialized only once, prior to program
1657 4 An object whose identifier is declared with no linkage and without the storage-class
1658 specifier static has automatic storage duration.
1659 5 For such an object that does not have a variable length array type, its lifetime extends
1660 from entry into the block with which it is associated until execution of that block ends in
1661 any way. (Entering an enclosed block or calling a function suspends, but does not end,
1662 execution of the current block.) If the block is entered recursively, a new instance of the
1663 object is created each time. The initial value of the object is indeterminate. If an
1664 initialization is specified for the object, it is performed each time the declaration is
1665 reached in the execution of the block; otherwise, the value becomes indeterminate each
1666 time the declaration is reached.
1667 6 For such an object that does have a variable length array type, its lifetime extends from
1668 the declaration of the object until execution of the program leaves the scope of the
1669 declaration.27) If the scope is entered recursively, a new instance of the object is created
1670 each time. The initial value of the object is indeterminate.
1671 Forward references: statements (6.8), function calls (6.5.2.2), declarators (6.7.5), array
1672 declarators (6.7.5.2), initialization (6.7.8).
1677 25) The term ''constant address'' means that two pointers to the object constructed at possibly different
1678 times will compare equal. The address may be different during two different executions of the same
1680 26) In the case of a volatile object, the last store need not be explicit in the program.
1681 27) Leaving the innermost block containing the declaration, or jumping to a point in that block or an
1682 embedded block prior to the declaration, leaves the scope of the declaration.
1687 1 The meaning of a value stored in an object or returned by a function is determined by the
1688 type of the expression used to access it. (An identifier declared to be an object is the
1689 simplest such expression; the type is specified in the declaration of the identifier.) Types
1690 are partitioned into object types (types that fully describe objects), function types (types
1691 that describe functions), and incomplete types (types that describe objects but lack
1692 information needed to determine their sizes).
1693 2 An object declared as type _Bool is large enough to store the values 0 and 1.
1694 3 An object declared as type char is large enough to store any member of the basic
1695 execution character set. If a member of the basic execution character set is stored in a
1696 char object, its value is guaranteed to be nonnegative. If any other character is stored in
1697 a char object, the resulting value is implementation-defined but shall be within the range
1698 of values that can be represented in that type.
1699 4 There are five standard signed integer types, designated as signed char, short
1700 int, int, long int, and long long int. (These and other types may be
1701 designated in several additional ways, as described in 6.7.2.) There may also be
1702 implementation-defined extended signed integer types.28) The standard and extended
1703 signed integer types are collectively called signed integer types.29)
1704 5 An object declared as type signed char occupies the same amount of storage as a
1705 ''plain'' char object. A ''plain'' int object has the natural size suggested by the
1706 architecture of the execution environment (large enough to contain any value in the range
1707 INT_MIN to INT_MAX as defined in the header <limits.h>).
1708 6 For each of the signed integer types, there is a corresponding (but different) unsigned
1709 integer type (designated with the keyword unsigned) that uses the same amount of
1710 storage (including sign information) and has the same alignment requirements. The type
1711 _Bool and the unsigned integer types that correspond to the standard signed integer
1712 types are the standard unsigned integer types. The unsigned integer types that
1713 correspond to the extended signed integer types are the extended unsigned integer types.
1714 The standard and extended unsigned integer types are collectively called unsigned integer
1719 28) Implementation-defined keywords shall have the form of an identifier reserved for any use as
1721 29) Therefore, any statement in this Standard about signed integer types also applies to the extended
1722 signed integer types.
1723 30) Therefore, any statement in this Standard about unsigned integer types also applies to the extended
1724 unsigned integer types.
1728 7 The standard signed integer types and standard unsigned integer types are collectively
1729 called the standard integer types, the extended signed integer types and extended
1730 unsigned integer types are collectively called the extended integer types.
1731 8 For any two integer types with the same signedness and different integer conversion rank
1732 (see 6.3.1.1), the range of values of the type with smaller integer conversion rank is a
1733 subrange of the values of the other type.
1734 9 The range of nonnegative values of a signed integer type is a subrange of the
1735 corresponding unsigned integer type, and the representation of the same value in each
1736 type is the same.31) A computation involving unsigned operands can never overflow,
1737 because a result that cannot be represented by the resulting unsigned integer type is
1738 reduced modulo the number that is one greater than the largest value that can be
1739 represented by the resulting type.
1740 10 There are three real floating types, designated as float, double, and long
1741 double.32) The set of values of the type float is a subset of the set of values of the
1742 type double; the set of values of the type double is a subset of the set of values of the
1744 11 There are three complex types, designated as float _Complex, double
1745 _Complex, and long double _Complex.33) The real floating and complex types
1746 are collectively called the floating types.
1747 12 For each floating type there is a corresponding real type, which is always a real floating
1748 type. For real floating types, it is the same type. For complex types, it is the type given
1749 by deleting the keyword _Complex from the type name.
1750 13 Each complex type has the same representation and alignment requirements as an array
1751 type containing exactly two elements of the corresponding real type; the first element is
1752 equal to the real part, and the second element to the imaginary part, of the complex
1754 14 The type char, the signed and unsigned integer types, and the floating types are
1755 collectively called the basic types. Even if the implementation defines two or more basic
1756 types to have the same representation, they are nevertheless different types.34)
1758 31) The same representation and alignment requirements are meant to imply interchangeability as
1759 arguments to functions, return values from functions, and members of unions.
1760 32) See ''future language directions'' (6.11.1).
1761 33) A specification for imaginary types is in informative annex G.
1762 34) An implementation may define new keywords that provide alternative ways to designate a basic (or
1763 any other) type; this does not violate the requirement that all basic types be different.
1764 Implementation-defined keywords shall have the form of an identifier reserved for any use as
1769 15 The three types char, signed char, and unsigned char are collectively called
1770 the character types. The implementation shall define char to have the same range,
1771 representation, and behavior as either signed char or unsigned char.35)
1772 16 An enumeration comprises a set of named integer constant values. Each distinct
1773 enumeration constitutes a different enumerated type.
1774 17 The type char, the signed and unsigned integer types, and the enumerated types are
1775 collectively called integer types. The integer and real floating types are collectively called
1777 18 Integer and floating types are collectively called arithmetic types. Each arithmetic type
1778 belongs to one type domain: the real type domain comprises the real types, the complex
1779 type domain comprises the complex types.
1780 19 The void type comprises an empty set of values; it is an incomplete type that cannot be
1782 20 Any number of derived types can be constructed from the object, function, and
1783 incomplete types, as follows:
1784 -- An array type describes a contiguously allocated nonempty set of objects with a
1785 particular member object type, called the element type.36) Array types are
1786 characterized by their element type and by the number of elements in the array. An
1787 array type is said to be derived from its element type, and if its element type is T , the
1788 array type is sometimes called ''array of T ''. The construction of an array type from
1789 an element type is called ''array type derivation''.
1790 -- A structure type describes a sequentially allocated nonempty set of member objects
1791 (and, in certain circumstances, an incomplete array), each of which has an optionally
1792 specified name and possibly distinct type.
1793 -- A union type describes an overlapping nonempty set of member objects, each of
1794 which has an optionally specified name and possibly distinct type.
1795 -- A function type describes a function with specified return type. A function type is
1796 characterized by its return type and the number and types of its parameters. A
1797 function type is said to be derived from its return type, and if its return type is T , the
1798 function type is sometimes called ''function returning T ''. The construction of a
1799 function type from a return type is called ''function type derivation''.
1803 35) CHAR_MIN, defined in <limits.h>, will have one of the values 0 or SCHAR_MIN, and this can be
1804 used to distinguish the two options. Irrespective of the choice made, char is a separate type from the
1805 other two and is not compatible with either.
1806 36) Since object types do not include incomplete types, an array of incomplete type cannot be constructed.
1810 -- A pointer type may be derived from a function type, an object type, or an incomplete
1811 type, called the referenced type. A pointer type describes an object whose value
1812 provides a reference to an entity of the referenced type. A pointer type derived from
1813 the referenced type T is sometimes called ''pointer to T ''. The construction of a
1814 pointer type from a referenced type is called ''pointer type derivation''.
1815 These methods of constructing derived types can be applied recursively.
1816 21 Arithmetic types and pointer types are collectively called scalar types. Array and
1817 structure types are collectively called aggregate types.37)
1818 22 An array type of unknown size is an incomplete type. It is completed, for an identifier of
1819 that type, by specifying the size in a later declaration (with internal or external linkage).
1820 A structure or union type of unknown content (as described in 6.7.2.3) is an incomplete
1821 type. It is completed, for all declarations of that type, by declaring the same structure or
1822 union tag with its defining content later in the same scope.
1823 23 A type has known constant size if the type is not incomplete and is not a variable length
1825 24 Array, function, and pointer types are collectively called derived declarator types. A
1826 declarator type derivation from a type T is the construction of a derived declarator type
1827 from T by the application of an array-type, a function-type, or a pointer-type derivation to
1829 25 A type is characterized by its type category, which is either the outermost derivation of a
1830 derived type (as noted above in the construction of derived types), or the type itself if the
1831 type consists of no derived types.
1832 26 Any type so far mentioned is an unqualified type. Each unqualified type has several
1833 qualified versions of its type,38) corresponding to the combinations of one, two, or all
1834 three of the const, volatile, and restrict qualifiers. The qualified or unqualified
1835 versions of a type are distinct types that belong to the same type category and have the
1836 same representation and alignment requirements.39) A derived type is not qualified by the
1837 qualifiers (if any) of the type from which it is derived.
1838 27 A pointer to void shall have the same representation and alignment requirements as a
1839 pointer to a character type.39) Similarly, pointers to qualified or unqualified versions of
1840 compatible types shall have the same representation and alignment requirements. All
1843 37) Note that aggregate type does not include union type because an object with union type can only
1844 contain one member at a time.
1845 38) See 6.7.3 regarding qualified array and function types.
1846 39) The same representation and alignment requirements are meant to imply interchangeability as
1847 arguments to functions, return values from functions, and members of unions.
1851 pointers to structure types shall have the same representation and alignment requirements
1852 as each other. All pointers to union types shall have the same representation and
1853 alignment requirements as each other. Pointers to other types need not have the same
1854 representation or alignment requirements.
1855 28 EXAMPLE 1 The type designated as ''float *'' has type ''pointer to float''. Its type category is
1856 pointer, not a floating type. The const-qualified version of this type is designated as ''float * const''
1857 whereas the type designated as ''const float *'' is not a qualified type -- its type is ''pointer to const-
1858 qualified float'' and is a pointer to a qualified type.
1860 29 EXAMPLE 2 The type designated as ''struct tag (*[5])(float)'' has type ''array of pointer to
1861 function returning struct tag''. The array has length five and the function has a single parameter of type
1862 float. Its type category is array.
1864 Forward references: compatible type and composite type (6.2.7), declarations (6.7).
1865 6.2.6 Representations of types
1867 1 The representations of all types are unspecified except as stated in this subclause.
1868 2 Except for bit-fields, objects are composed of contiguous sequences of one or more bytes,
1869 the number, order, and encoding of which are either explicitly specified or
1870 implementation-defined.
1871 3 Values stored in unsigned bit-fields and objects of type unsigned char shall be
1872 represented using a pure binary notation.40)
1873 4 Values stored in non-bit-field objects of any other object type consist of n x CHAR_BIT
1874 bits, where n is the size of an object of that type, in bytes. The value may be copied into
1875 an object of type unsigned char [n] (e.g., by memcpy); the resulting set of bytes is
1876 called the object representation of the value. Values stored in bit-fields consist of m bits,
1877 where m is the size specified for the bit-field. The object representation is the set of m
1878 bits the bit-field comprises in the addressable storage unit holding it. Two values (other
1879 than NaNs) with the same object representation compare equal, but values that compare
1880 equal may have different object representations.
1881 5 Certain object representations need not represent a value of the object type. If the stored
1882 value of an object has such a representation and is read by an lvalue expression that does
1883 not have character type, the behavior is undefined. If such a representation is produced
1884 by a side effect that modifies all or any part of the object by an lvalue expression that
1885 does not have character type, the behavior is undefined.41) Such a representation is called
1887 40) A positional representation for integers that uses the binary digits 0 and 1, in which the values
1888 represented by successive bits are additive, begin with 1, and are multiplied by successive integral
1889 powers of 2, except perhaps the bit with the highest position. (Adapted from the American National
1890 Dictionary for Information Processing Systems.) A byte contains CHAR_BIT bits, and the values of
1891 type unsigned char range from 0 to 2
1897 a trap representation.
1898 6 When a value is stored in an object of structure or union type, including in a member
1899 object, the bytes of the object representation that correspond to any padding bytes take
1900 unspecified values.42) The value of a structure or union object is never a trap
1901 representation, even though the value of a member of the structure or union object may be
1902 a trap representation.
1903 7 When a value is stored in a member of an object of union type, the bytes of the object
1904 representation that do not correspond to that member but do correspond to other members
1905 take unspecified values.
1906 8 Where an operator is applied to a value that has more than one object representation,
1907 which object representation is used shall not affect the value of the result.43) Where a
1908 value is stored in an object using a type that has more than one object representation for
1909 that value, it is unspecified which representation is used, but a trap representation shall
1911 Forward references: declarations (6.7), expressions (6.5), lvalues, arrays, and function
1912 designators (6.3.2.1).
1913 6.2.6.2 Integer types
1914 1 For unsigned integer types other than unsigned char, the bits of the object
1915 representation shall be divided into two groups: value bits and padding bits (there need
1916 not be any of the latter). If there are N value bits, each bit shall represent a different
1917 power of 2 between 1 and 2 N -1 , so that objects of that type shall be capable of
1918 representing values from 0 to 2 N - 1 using a pure binary representation; this shall be
1919 known as the value representation. The values of any padding bits are unspecified.44)
1920 2 For signed integer types, the bits of the object representation shall be divided into three
1921 groups: value bits, padding bits, and the sign bit. There need not be any padding bits;
1923 41) Thus, an automatic variable can be initialized to a trap representation without causing undefined
1924 behavior, but the value of the variable cannot be used until a proper value is stored in it.
1925 42) Thus, for example, structure assignment need not copy any padding bits.
1926 43) It is possible for objects x and y with the same effective type T to have the same value when they are
1927 accessed as objects of type T, but to have different values in other contexts. In particular, if == is
1928 defined for type T, then x == y does not imply that memcmp(&x, &y, sizeof (T)) == 0.
1929 Furthermore, x == y does not necessarily imply that x and y have the same value; other operations
1930 on values of type T may distinguish between them.
1931 44) Some combinations of padding bits might generate trap representations, for example, if one padding
1932 bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap
1933 representation other than as part of an exceptional condition such as an overflow, and this cannot occur
1934 with unsigned types. All other combinations of padding bits are alternative object representations of
1935 the value specified by the value bits.
1939 there shall be exactly one sign bit. Each bit that is a value bit shall have the same value as
1940 the same bit in the object representation of the corresponding unsigned type (if there are
1941 M value bits in the signed type and N in the unsigned type, then M <= N ). If the sign bit
1942 is zero, it shall not affect the resulting value. If the sign bit is one, the value shall be
1943 modified in one of the following ways:
1944 -- the corresponding value with sign bit 0 is negated (sign and magnitude);
1945 -- the sign bit has the value -(2 N ) (two's complement);
1946 -- the sign bit has the value -(2 N - 1) (ones' complement ).
1947 Which of these applies is implementation-defined, as is whether the value with sign bit 1
1948 and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones'
1949 complement), is a trap representation or a normal value. In the case of sign and
1950 magnitude and ones' complement, if this representation is a normal value it is called a
1952 3 If the implementation supports negative zeros, they shall be generated only by:
1953 -- the &, |, ^, ~, <<, and >> operators with arguments that produce such a value;
1954 -- the +, -, *, /, and % operators where one argument is a negative zero and the result is
1956 -- compound assignment operators based on the above cases.
1957 It is unspecified whether these cases actually generate a negative zero or a normal zero,
1958 and whether a negative zero becomes a normal zero when stored in an object.
1959 4 If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<,
1960 and >> operators with arguments that would produce such a value is undefined.
1961 5 The values of any padding bits are unspecified.45) A valid (non-trap) object representation
1962 of a signed integer type where the sign bit is zero is a valid object representation of the
1963 corresponding unsigned type, and shall represent the same value. For any integer type,
1964 the object representation where all the bits are zero shall be a representation of the value
1966 6 The precision of an integer type is the number of bits it uses to represent values,
1967 excluding any sign and padding bits. The width of an integer type is the same but
1968 including any sign bit; thus for unsigned integer types the two values are the same, while
1971 45) Some combinations of padding bits might generate trap representations, for example, if one padding
1972 bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap
1973 representation other than as part of an exceptional condition such as an overflow. All other
1974 combinations of padding bits are alternative object representations of the value specified by the value
1979 for signed integer types the width is one greater than the precision.
1980 6.2.7 Compatible type and composite type
1981 1 Two types have compatible type if their types are the same. Additional rules for
1982 determining whether two types are compatible are described in 6.7.2 for type specifiers,
1983 in 6.7.3 for type qualifiers, and in 6.7.5 for declarators.46) Moreover, two structure,
1984 union, or enumerated types declared in separate translation units are compatible if their
1985 tags and members satisfy the following requirements: If one is declared with a tag, the
1986 other shall be declared with the same tag. If both are complete types, then the following
1987 additional requirements apply: there shall be a one-to-one correspondence between their
1988 members such that each pair of corresponding members are declared with compatible
1989 types, and such that if one member of a corresponding pair is declared with a name, the
1990 other member is declared with the same name. For two structures, corresponding
1991 members shall be declared in the same order. For two structures or unions, corresponding
1992 bit-fields shall have the same widths. For two enumerations, corresponding members
1993 shall have the same values.
1994 2 All declarations that refer to the same object or function shall have compatible type;
1995 otherwise, the behavior is undefined.
1996 3 A composite type can be constructed from two types that are compatible; it is a type that
1997 is compatible with both of the two types and satisfies the following conditions:
1998 -- If one type is an array of known constant size, the composite type is an array of that
1999 size; otherwise, if one type is a variable length array, the composite type is that type.
2000 -- If only one type is a function type with a parameter type list (a function prototype),
2001 the composite type is a function prototype with the parameter type list.
2002 -- If both types are function types with parameter type lists, the type of each parameter
2003 in the composite parameter type list is the composite type of the corresponding
2005 These rules apply recursively to the types from which the two types are derived.
2006 4 For an identifier with internal or external linkage declared in a scope in which a prior
2007 declaration of that identifier is visible,47) if the prior declaration specifies internal or
2008 external linkage, the type of the identifier at the later declaration becomes the composite
2014 46) Two types need not be identical to be compatible.
2015 47) As specified in 6.2.1, the later declaration might hide the prior declaration.
2019 5 EXAMPLE Given the following two file scope declarations:
2020 int f(int (*)(), double (*)[3]);
2021 int f(int (*)(char *), double (*)[]);
2022 The resulting composite type for the function is:
2023 int f(int (*)(char *), double (*)[3]);
2028 1 Several operators convert operand values from one type to another automatically. This
2029 subclause specifies the result required from such an implicit conversion, as well as those
2030 that result from a cast operation (an explicit conversion). The list in 6.3.1.8 summarizes
2031 the conversions performed by most ordinary operators; it is supplemented as required by
2032 the discussion of each operator in 6.5.
2033 2 Conversion of an operand value to a compatible type causes no change to the value or the
2035 Forward references: cast operators (6.5.4).
2036 6.3.1 Arithmetic operands
2037 6.3.1.1 Boolean, characters, and integers
2038 1 Every integer type has an integer conversion rank defined as follows:
2039 -- No two signed integer types shall have the same rank, even if they have the same
2041 -- The rank of a signed integer type shall be greater than the rank of any signed integer
2042 type with less precision.
2043 -- The rank of long long int shall be greater than the rank of long int, which
2044 shall be greater than the rank of int, which shall be greater than the rank of short
2045 int, which shall be greater than the rank of signed char.
2046 -- The rank of any unsigned integer type shall equal the rank of the corresponding
2047 signed integer type, if any.
2048 -- The rank of any standard integer type shall be greater than the rank of any extended
2049 integer type with the same width.
2050 -- The rank of char shall equal the rank of signed char and unsigned char.
2051 -- The rank of _Bool shall be less than the rank of all other standard integer types.
2052 -- The rank of any enumerated type shall equal the rank of the compatible integer type
2054 -- The rank of any extended signed integer type relative to another extended signed
2055 integer type with the same precision is implementation-defined, but still subject to the
2056 other rules for determining the integer conversion rank.
2057 -- For all integer types T1, T2, and T3, if T1 has greater rank than T2 and T2 has
2058 greater rank than T3, then T1 has greater rank than T3.
2059 2 The following may be used in an expression wherever an int or unsigned int may
2064 -- An object or expression with an integer type whose integer conversion rank is less
2065 than or equal to the rank of int and unsigned int.
2066 -- A bit-field of type _Bool, int, signed int, or unsigned int.
2067 If an int can represent all values of the original type, the value is converted to an int;
2068 otherwise, it is converted to an unsigned int. These are called the integer
2069 promotions.48) All other types are unchanged by the integer promotions.
2070 3 The integer promotions preserve value including sign. As discussed earlier, whether a
2071 ''plain'' char is treated as signed is implementation-defined.
2072 Forward references: enumeration specifiers (6.7.2.2), structure and union specifiers
2074 6.3.1.2 Boolean type
2075 1 When any scalar value is converted to _Bool, the result is 0 if the value compares equal
2076 to 0; otherwise, the result is 1.
2077 6.3.1.3 Signed and unsigned integers
2078 1 When a value with integer type is converted to another integer type other than _Bool, if
2079 the value can be represented by the new type, it is unchanged.
2080 2 Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or
2081 subtracting one more than the maximum value that can be represented in the new type
2082 until the value is in the range of the new type.49)
2083 3 Otherwise, the new type is signed and the value cannot be represented in it; either the
2084 result is implementation-defined or an implementation-defined signal is raised.
2085 6.3.1.4 Real floating and integer
2086 1 When a finite value of real floating type is converted to an integer type other than _Bool,
2087 the fractional part is discarded (i.e., the value is truncated toward zero). If the value of
2088 the integral part cannot be represented by the integer type, the behavior is undefined.50)
2089 2 When a value of integer type is converted to a real floating type, if the value being
2090 converted can be represented exactly in the new type, it is unchanged. If the value being
2091 converted is in the range of values that can be represented but cannot be represented
2093 48) The integer promotions are applied only: as part of the usual arithmetic conversions, to certain
2094 argument expressions, to the operands of the unary +, -, and ~ operators, and to both operands of the
2095 shift operators, as specified by their respective subclauses.
2096 49) The rules describe arithmetic on the mathematical value, not the value of a given type of expression.
2097 50) The remaindering operation performed when a value of integer type is converted to unsigned type
2098 need not be performed when a value of real floating type is converted to unsigned type. Thus, the
2099 range of portable real floating values is (-1, Utype_MAX+1).
2103 exactly, the result is either the nearest higher or nearest lower representable value, chosen
2104 in an implementation-defined manner. If the value being converted is outside the range of
2105 values that can be represented, the behavior is undefined.
2106 6.3.1.5 Real floating types
2107 1 When a float is promoted to double or long double, or a double is promoted
2108 to long double, its value is unchanged (if the source value is represented in the
2109 precision and range of its type).
2110 2 When a double is demoted to float, a long double is demoted to double or
2111 float, or a value being represented in greater precision and range than required by its
2112 semantic type (see 6.3.1.8) is explicitly converted (including to its own type), if the value
2113 being converted can be represented exactly in the new type, it is unchanged. If the value
2114 being converted is in the range of values that can be represented but cannot be
2115 represented exactly, the result is either the nearest higher or nearest lower representable
2116 value, chosen in an implementation-defined manner. If the value being converted is
2117 outside the range of values that can be represented, the behavior is undefined.
2118 6.3.1.6 Complex types
2119 1 When a value of complex type is converted to another complex type, both the real and
2120 imaginary parts follow the conversion rules for the corresponding real types.
2121 6.3.1.7 Real and complex
2122 1 When a value of real type is converted to a complex type, the real part of the complex
2123 result value is determined by the rules of conversion to the corresponding real type and
2124 the imaginary part of the complex result value is a positive zero or an unsigned zero.
2125 2 When a value of complex type is converted to a real type, the imaginary part of the
2126 complex value is discarded and the value of the real part is converted according to the
2127 conversion rules for the corresponding real type.
2128 6.3.1.8 Usual arithmetic conversions
2129 1 Many operators that expect operands of arithmetic type cause conversions and yield result
2130 types in a similar way. The purpose is to determine a common real type for the operands
2131 and result. For the specified operands, each operand is converted, without change of type
2132 domain, to a type whose corresponding real type is the common real type. Unless
2133 explicitly stated otherwise, the common real type is also the corresponding real type of
2134 the result, whose type domain is the type domain of the operands if they are the same,
2135 and complex otherwise. This pattern is called the usual arithmetic conversions:
2136 First, if the corresponding real type of either operand is long double, the other
2137 operand is converted, without change of type domain, to a type whose
2138 corresponding real type is long double.
2142 Otherwise, if the corresponding real type of either operand is double, the other
2143 operand is converted, without change of type domain, to a type whose
2144 corresponding real type is double.
2145 Otherwise, if the corresponding real type of either operand is float, the other
2146 operand is converted, without change of type domain, to a type whose
2147 corresponding real type is float.51)
2148 Otherwise, the integer promotions are performed on both operands. Then the
2149 following rules are applied to the promoted operands:
2150 If both operands have the same type, then no further conversion is needed.
2151 Otherwise, if both operands have signed integer types or both have unsigned
2152 integer types, the operand with the type of lesser integer conversion rank is
2153 converted to the type of the operand with greater rank.
2154 Otherwise, if the operand that has unsigned integer type has rank greater or
2155 equal to the rank of the type of the other operand, then the operand with
2156 signed integer type is converted to the type of the operand with unsigned
2158 Otherwise, if the type of the operand with signed integer type can represent
2159 all of the values of the type of the operand with unsigned integer type, then
2160 the operand with unsigned integer type is converted to the type of the
2161 operand with signed integer type.
2162 Otherwise, both operands are converted to the unsigned integer type
2163 corresponding to the type of the operand with signed integer type.
2164 2 The values of floating operands and of the results of floating expressions may be
2165 represented in greater precision and range than that required by the type; the types are not
2171 51) For example, addition of a double _Complex and a float entails just the conversion of the
2172 float operand to double (and yields a double _Complex result).
2173 52) The cast and assignment operators are still required to perform their specified conversions as
2174 described in 6.3.1.4 and 6.3.1.5.
2178 6.3.2 Other operands
2179 6.3.2.1 Lvalues, arrays, and function designators
2180 1 An lvalue is an expression with an object type or an incomplete type other than void;53)
2181 if an lvalue does not designate an object when it is evaluated, the behavior is undefined.
2182 When an object is said to have a particular type, the type is specified by the lvalue used to
2183 designate the object. A modifiable lvalue is an lvalue that does not have array type, does
2184 not have an incomplete type, does not have a const-qualified type, and if it is a structure
2185 or union, does not have any member (including, recursively, any member or element of
2186 all contained aggregates or unions) with a const-qualified type.
2187 2 Except when it is the operand of the sizeof operator, the unary & operator, the ++
2188 operator, the -- operator, or the left operand of the . operator or an assignment operator,
2189 an lvalue that does not have array type is converted to the value stored in the designated
2190 object (and is no longer an lvalue). If the lvalue has qualified type, the value has the
2191 unqualified version of the type of the lvalue; otherwise, the value has the type of the
2192 lvalue. If the lvalue has an incomplete type and does not have array type, the behavior is
2194 3 Except when it is the operand of the sizeof operator or the unary & operator, or is a
2195 string literal used to initialize an array, an expression that has type ''array of type'' is
2196 converted to an expression with type ''pointer to type'' that points to the initial element of
2197 the array object and is not an lvalue. If the array object has register storage class, the
2198 behavior is undefined.
2199 4 A function designator is an expression that has function type. Except when it is the
2200 operand of the sizeof operator54) or the unary & operator, a function designator with
2201 type ''function returning type'' is converted to an expression that has type ''pointer to
2202 function returning type''.
2203 Forward references: address and indirection operators (6.5.3.2), assignment operators
2204 (6.5.16), common definitions <stddef.h> (7.17), initialization (6.7.8), postfix
2205 increment and decrement operators (6.5.2.4), prefix increment and decrement operators
2206 (6.5.3.1), the sizeof operator (6.5.3.4), structure and union members (6.5.2.3).
2209 53) The name ''lvalue'' comes originally from the assignment expression E1 = E2, in which the left
2210 operand E1 is required to be a (modifiable) lvalue. It is perhaps better considered as representing an
2211 object ''locator value''. What is sometimes called ''rvalue'' is in this International Standard described
2212 as the ''value of an expression''.
2213 An obvious example of an lvalue is an identifier of an object. As a further example, if E is a unary
2214 expression that is a pointer to an object, *E is an lvalue that designates the object to which E points.
2215 54) Because this conversion does not occur, the operand of the sizeof operator remains a function
2216 designator and violates the constraint in 6.5.3.4.
2221 1 The (nonexistent) value of a void expression (an expression that has type void) shall not
2222 be used in any way, and implicit or explicit conversions (except to void) shall not be
2223 applied to such an expression. If an expression of any other type is evaluated as a void
2224 expression, its value or designator is discarded. (A void expression is evaluated for its
2227 1 A pointer to void may be converted to or from a pointer to any incomplete or object
2228 type. A pointer to any incomplete or object type may be converted to a pointer to void
2229 and back again; the result shall compare equal to the original pointer.
2230 2 For any qualifier q, a pointer to a non-q-qualified type may be converted to a pointer to
2231 the q-qualified version of the type; the values stored in the original and converted pointers
2232 shall compare equal.
2233 3 An integer constant expression with the value 0, or such an expression cast to type
2234 void *, is called a null pointer constant.55) If a null pointer constant is converted to a
2235 pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal
2236 to a pointer to any object or function.
2237 4 Conversion of a null pointer to another pointer type yields a null pointer of that type.
2238 Any two null pointers shall compare equal.
2239 5 An integer may be converted to any pointer type. Except as previously specified, the
2240 result is implementation-defined, might not be correctly aligned, might not point to an
2241 entity of the referenced type, and might be a trap representation.56)
2242 6 Any pointer type may be converted to an integer type. Except as previously specified, the
2243 result is implementation-defined. If the result cannot be represented in the integer type,
2244 the behavior is undefined. The result need not be in the range of values of any integer
2246 7 A pointer to an object or incomplete type may be converted to a pointer to a different
2247 object or incomplete type. If the resulting pointer is not correctly aligned57) for the
2248 pointed-to type, the behavior is undefined. Otherwise, when converted back again, the
2249 result shall compare equal to the original pointer. When a pointer to an object is
2252 55) The macro NULL is defined in <stddef.h> (and other headers) as a null pointer constant; see 7.17.
2253 56) The mapping functions for converting a pointer to an integer or an integer to a pointer are intended to
2254 be consistent with the addressing structure of the execution environment.
2255 57) In general, the concept ''correctly aligned'' is transitive: if a pointer to type A is correctly aligned for a
2256 pointer to type B, which in turn is correctly aligned for a pointer to type C, then a pointer to type A is
2257 correctly aligned for a pointer to type C.
2261 converted to a pointer to a character type, the result points to the lowest addressed byte of
2262 the object. Successive increments of the result, up to the size of the object, yield pointers
2263 to the remaining bytes of the object.
2264 8 A pointer to a function of one type may be converted to a pointer to a function of another
2265 type and back again; the result shall compare equal to the original pointer. If a converted
2266 pointer is used to call a function whose type is not compatible with the pointed-to type,
2267 the behavior is undefined.
2268 Forward references: cast operators (6.5.4), equality operators (6.5.9), integer types
2269 capable of holding object pointers (7.18.1.4), simple assignment (6.5.16.1).
2273 6.4 Lexical elements
2281 preprocessing-token:
2288 each non-white-space character that cannot be one of the above
2290 2 Each preprocessing token that is converted to a token shall have the lexical form of a
2291 keyword, an identifier, a constant, a string literal, or a punctuator.
2293 3 A token is the minimal lexical element of the language in translation phases 7 and 8. The
2294 categories of tokens are: keywords, identifiers, constants, string literals, and punctuators.
2295 A preprocessing token is the minimal lexical element of the language in translation
2296 phases 3 through 6. The categories of preprocessing tokens are: header names,
2297 identifiers, preprocessing numbers, character constants, string literals, punctuators, and
2298 single non-white-space characters that do not lexically match the other preprocessing
2299 token categories.58) If a ' or a " character matches the last category, the behavior is
2300 undefined. Preprocessing tokens can be separated by white space; this consists of
2301 comments (described later), or white-space characters (space, horizontal tab, new-line,
2302 vertical tab, and form-feed), or both. As described in 6.10, in certain circumstances
2303 during translation phase 4, white space (or the absence thereof) serves as more than
2304 preprocessing token separation. White space may appear within a preprocessing token
2305 only as part of a header name or between the quotation characters in a character constant
2310 58) An additional category, placemarkers, is used internally in translation phase 4 (see 6.10.3.3); it cannot
2311 occur in source files.
2315 4 If the input stream has been parsed into preprocessing tokens up to a given character, the
2316 next preprocessing token is the longest sequence of characters that could constitute a
2317 preprocessing token. There is one exception to this rule: header name preprocessing
2318 tokens are recognized only within #include preprocessing directives and in
2319 implementation-defined locations within #pragma directives. In such contexts, a
2320 sequence of characters that could be either a header name or a string literal is recognized
2322 5 EXAMPLE 1 The program fragment 1Ex is parsed as a preprocessing number token (one that is not a
2323 valid floating or integer constant token), even though a parse as the pair of preprocessing tokens 1 and Ex
2324 might produce a valid expression (for example, if Ex were a macro defined as +1). Similarly, the program
2325 fragment 1E1 is parsed as a preprocessing number (one that is a valid floating constant token), whether or
2326 not E is a macro name.
2328 6 EXAMPLE 2 The program fragment x+++++y is parsed as x ++ ++ + y, which violates a constraint on
2329 increment operators, even though the parse x ++ + ++ y might yield a correct expression.
2331 Forward references: character constants (6.4.4.4), comments (6.4.9), expressions (6.5),
2332 floating constants (6.4.4.2), header names (6.4.7), macro replacement (6.10.3), postfix
2333 increment and decrement operators (6.5.2.4), prefix increment and decrement operators
2334 (6.5.3.1), preprocessing directives (6.10), preprocessing numbers (6.4.8), string literals
2339 auto enum restrict unsigned
2340 break extern return void
2341 case float short volatile
2342 char for signed while
2343 const goto sizeof _Bool
2344 continue if static _Complex
2345 default inline struct _Imaginary
2350 2 The above tokens (case sensitive) are reserved (in translation phases 7 and 8) for use as
2351 keywords, and shall not be used otherwise. The keyword _Imaginary is reserved for
2352 specifying imaginary types.59)
2356 59) One possible specification for imaginary types appears in annex G.
2365 identifier identifier-nondigit
2367 identifier-nondigit:
2369 universal-character-name
2370 other implementation-defined characters
2372 _ a b c d e f g h i j k l m
2373 n o p q r s t u v w x y z
2374 A B C D E F G H I J K L M
2375 N O P Q R S T U V W X Y Z
2379 2 An identifier is a sequence of nondigit characters (including the underscore _, the
2380 lowercase and uppercase Latin letters, and other characters) and digits, which designates
2381 one or more entities as described in 6.2.1. Lowercase and uppercase letters are distinct.
2382 There is no specific limit on the maximum length of an identifier.
2383 3 Each universal character name in an identifier shall designate a character whose encoding
2384 in ISO/IEC 10646 falls into one of the ranges specified in annex D.60) The initial
2385 character shall not be a universal character name designating a digit. An implementation
2386 may allow multibyte characters that are not part of the basic source character set to
2387 appear in identifiers; which characters and their correspondence to universal character
2388 names is implementation-defined.
2389 4 When preprocessing tokens are converted to tokens during translation phase 7, if a
2390 preprocessing token could be converted to either a keyword or an identifier, it is converted
2394 60) On systems in which linkers cannot accept extended characters, an encoding of the universal character
2395 name may be used in forming valid external identifiers. For example, some otherwise unused
2396 character or sequence of characters may be used to encode the \u in a universal character name.
2397 Extended characters may produce a long external identifier.
2401 Implementation limits
2402 5 As discussed in 5.2.4.1, an implementation may limit the number of significant initial
2403 characters in an identifier; the limit for an external name (an identifier that has external
2404 linkage) may be more restrictive than that for an internal name (a macro name or an
2405 identifier that does not have external linkage). The number of significant characters in an
2406 identifier is implementation-defined.
2407 6 Any identifiers that differ in a significant character are different identifiers. If two
2408 identifiers differ only in nonsignificant characters, the behavior is undefined.
2409 Forward references: universal character names (6.4.3), macro replacement (6.10.3).
2410 6.4.2.2 Predefined identifiers
2412 1 The identifier __func__ shall be implicitly declared by the translator as if,
2413 immediately following the opening brace of each function definition, the declaration
2414 static const char __func__[] = "function-name";
2415 appeared, where function-name is the name of the lexically-enclosing function.61)
2416 2 This name is encoded as if the implicit declaration had been written in the source
2417 character set and then translated into the execution character set as indicated in translation
2419 3 EXAMPLE Consider the code fragment:
2423 printf("%s\n", __func__);
2426 Each time the function is called, it will print to the standard output stream:
2429 Forward references: function definitions (6.9.1).
2434 61) Since the name __func__ is reserved for any use by the implementation (7.1.3), if any other
2435 identifier is explicitly declared using the name __func__, the behavior is undefined.
2439 6.4.3 Universal character names
2441 1 universal-character-name:
2443 \U hex-quad hex-quad
2445 hexadecimal-digit hexadecimal-digit
2446 hexadecimal-digit hexadecimal-digit
2448 2 A universal character name shall not specify a character whose short identifier is less than
2449 00A0 other than 0024 ($), 0040 (@), or 0060 ('), nor one in the range D800 through
2452 3 Universal character names may be used in identifiers, character constants, and string
2453 literals to designate characters that are not in the basic character set.
2455 4 The universal character name \Unnnnnnnn designates the character whose eight-digit
2456 short identifier (as specified by ISO/IEC 10646) is nnnnnnnn.63) Similarly, the universal
2457 character name \unnnn designates the character whose four-digit short identifier is nnnn
2458 (and whose eight-digit short identifier is 0000nnnn).
2463 62) The disallowed characters are the characters in the basic character set and the code positions reserved
2464 by ISO/IEC 10646 for control characters, the character DELETE, and the S-zone (reserved for use by
2466 63) Short identifiers for characters were first specified in ISO/IEC 10646-1/AMD9:1997.
2475 enumeration-constant
2478 2 Each constant shall have a type and the value of a constant shall be in the range of
2479 representable values for its type.
2481 3 Each constant has a type, determined by its form and value, as detailed later.
2482 6.4.4.1 Integer constants
2485 decimal-constant integer-suffixopt
2486 octal-constant integer-suffixopt
2487 hexadecimal-constant integer-suffixopt
2490 decimal-constant digit
2493 octal-constant octal-digit
2494 hexadecimal-constant:
2495 hexadecimal-prefix hexadecimal-digit
2496 hexadecimal-constant hexadecimal-digit
2497 hexadecimal-prefix: one of
2499 nonzero-digit: one of
2506 hexadecimal-digit: one of
2511 unsigned-suffix long-suffixopt
2512 unsigned-suffix long-long-suffix
2513 long-suffix unsigned-suffixopt
2514 long-long-suffix unsigned-suffixopt
2515 unsigned-suffix: one of
2519 long-long-suffix: one of
2522 2 An integer constant begins with a digit, but has no period or exponent part. It may have a
2523 prefix that specifies its base and a suffix that specifies its type.
2524 3 A decimal constant begins with a nonzero digit and consists of a sequence of decimal
2525 digits. An octal constant consists of the prefix 0 optionally followed by a sequence of the
2526 digits 0 through 7 only. A hexadecimal constant consists of the prefix 0x or 0X followed
2527 by a sequence of the decimal digits and the letters a (or A) through f (or F) with values
2528 10 through 15 respectively.
2530 4 The value of a decimal constant is computed base 10; that of an octal constant, base 8;
2531 that of a hexadecimal constant, base 16. The lexically first digit is the most significant.
2532 5 The type of an integer constant is the first of the corresponding list in which its value can
2537 Octal or Hexadecimal
2538 Suffix Decimal Constant Constant
2541 long int unsigned int
2542 long long int long int
2545 unsigned long long int
2547 u or U unsigned int unsigned int
2548 unsigned long int unsigned long int
2549 unsigned long long int unsigned long long int
2551 l or L long int long int
2552 long long int unsigned long int
2554 unsigned long long int
2556 Both u or U unsigned long int unsigned long int
2557 and l or L unsigned long long int unsigned long long int
2559 ll or LL long long int long long int
2560 unsigned long long int
2562 Both u or U unsigned long long int unsigned long long int
2564 6 If an integer constant cannot be represented by any type in its list, it may have an
2565 extended integer type, if the extended integer type can represent its value. If all of the
2566 types in the list for the constant are signed, the extended integer type shall be signed. If
2567 all of the types in the list for the constant are unsigned, the extended integer type shall be
2568 unsigned. If the list contains both signed and unsigned types, the extended integer type
2569 may be signed or unsigned. If an integer constant cannot be represented by any type in
2570 its list and has no extended integer type, then the integer constant has no type.
2574 6.4.4.2 Floating constants
2576 1 floating-constant:
2577 decimal-floating-constant
2578 hexadecimal-floating-constant
2579 decimal-floating-constant:
2580 fractional-constant exponent-partopt floating-suffixopt
2581 digit-sequence exponent-part floating-suffixopt
2582 hexadecimal-floating-constant:
2583 hexadecimal-prefix hexadecimal-fractional-constant
2584 binary-exponent-part floating-suffixopt
2585 hexadecimal-prefix hexadecimal-digit-sequence
2586 binary-exponent-part floating-suffixopt
2587 fractional-constant:
2588 digit-sequenceopt . digit-sequence
2591 e signopt digit-sequence
2592 E signopt digit-sequence
2597 digit-sequence digit
2598 hexadecimal-fractional-constant:
2599 hexadecimal-digit-sequenceopt .
2600 hexadecimal-digit-sequence
2601 hexadecimal-digit-sequence .
2602 binary-exponent-part:
2603 p signopt digit-sequence
2604 P signopt digit-sequence
2605 hexadecimal-digit-sequence:
2607 hexadecimal-digit-sequence hexadecimal-digit
2608 floating-suffix: one of
2614 2 A floating constant has a significand part that may be followed by an exponent part and a
2615 suffix that specifies its type. The components of the significand part may include a digit
2616 sequence representing the whole-number part, followed by a period (.), followed by a
2617 digit sequence representing the fraction part. The components of the exponent part are an
2618 e, E, p, or P followed by an exponent consisting of an optionally signed digit sequence.
2619 Either the whole-number part or the fraction part has to be present; for decimal floating
2620 constants, either the period or the exponent part has to be present.
2622 3 The significand part is interpreted as a (decimal or hexadecimal) rational number; the
2623 digit sequence in the exponent part is interpreted as a decimal integer. For decimal
2624 floating constants, the exponent indicates the power of 10 by which the significand part is
2625 to be scaled. For hexadecimal floating constants, the exponent indicates the power of 2
2626 by which the significand part is to be scaled. For decimal floating constants, and also for
2627 hexadecimal floating constants when FLT_RADIX is not a power of 2, the result is either
2628 the nearest representable value, or the larger or smaller representable value immediately
2629 adjacent to the nearest representable value, chosen in an implementation-defined manner.
2630 For hexadecimal floating constants when FLT_RADIX is a power of 2, the result is
2632 4 An unsuffixed floating constant has type double. If suffixed by the letter f or F, it has
2633 type float. If suffixed by the letter l or L, it has type long double.
2634 5 Floating constants are converted to internal format as if at translation-time. The
2635 conversion of a floating constant shall not raise an exceptional condition or a floating-
2636 point exception at execution time.
2637 Recommended practice
2638 6 The implementation should produce a diagnostic message if a hexadecimal constant
2639 cannot be represented exactly in its evaluation format; the implementation should then
2640 proceed with the translation of the program.
2641 7 The translation-time conversion of floating constants should match the execution-time
2642 conversion of character strings by library functions, such as strtod, given matching
2643 inputs suitable for both conversions, the same result format, and default execution-time
2649 64) The specification for the library functions recommends more accurate conversion than required for
2650 floating constants (see 7.20.1.3).
2654 6.4.4.3 Enumeration constants
2656 1 enumeration-constant:
2659 2 An identifier declared as an enumeration constant has type int.
2660 Forward references: enumeration specifiers (6.7.2.2).
2661 6.4.4.4 Character constants
2663 1 character-constant:
2665 L' c-char-sequence '
2668 c-char-sequence c-char
2670 any member of the source character set except
2671 the single-quote ', backslash \, or new-line character
2674 simple-escape-sequence
2675 octal-escape-sequence
2676 hexadecimal-escape-sequence
2677 universal-character-name
2678 simple-escape-sequence: one of
2680 \a \b \f \n \r \t \v
2681 octal-escape-sequence:
2683 \ octal-digit octal-digit
2684 \ octal-digit octal-digit octal-digit
2685 hexadecimal-escape-sequence:
2686 \x hexadecimal-digit
2687 hexadecimal-escape-sequence hexadecimal-digit
2692 2 An integer character constant is a sequence of one or more multibyte characters enclosed
2693 in single-quotes, as in 'x'. A wide character constant is the same, except prefixed by the
2694 letter L. With a few exceptions detailed later, the elements of the sequence are any
2695 members of the source character set; they are mapped in an implementation-defined
2696 manner to members of the execution character set.
2697 3 The single-quote ', the double-quote ", the question-mark ?, the backslash \, and
2698 arbitrary integer values are representable according to the following table of escape
2704 octal character \octal digits
2705 hexadecimal character \x hexadecimal digits
2706 4 The double-quote " and question-mark ? are representable either by themselves or by the
2707 escape sequences \" and \?, respectively, but the single-quote ' and the backslash \
2708 shall be represented, respectively, by the escape sequences \' and \\.
2709 5 The octal digits that follow the backslash in an octal escape sequence are taken to be part
2710 of the construction of a single character for an integer character constant or of a single
2711 wide character for a wide character constant. The numerical value of the octal integer so
2712 formed specifies the value of the desired character or wide character.
2713 6 The hexadecimal digits that follow the backslash and the letter x in a hexadecimal escape
2714 sequence are taken to be part of the construction of a single character for an integer
2715 character constant or of a single wide character for a wide character constant. The
2716 numerical value of the hexadecimal integer so formed specifies the value of the desired
2717 character or wide character.
2718 7 Each octal or hexadecimal escape sequence is the longest sequence of characters that can
2719 constitute the escape sequence.
2720 8 In addition, characters not in the basic character set are representable by universal
2721 character names and certain nongraphic characters are representable by escape sequences
2722 consisting of the backslash \ followed by a lowercase letter: \a, \b, \f, \n, \r, \t,
2728 65) The semantics of these characters were discussed in 5.2.2. If any other character follows a backslash,
2729 the result is not a token and a diagnostic is required. See ''future language directions'' (6.11.4).
2734 9 The value of an octal or hexadecimal escape sequence shall be in the range of
2735 representable values for the type unsigned char for an integer character constant, or
2736 the unsigned type corresponding to wchar_t for a wide character constant.
2738 10 An integer character constant has type int. The value of an integer character constant
2739 containing a single character that maps to a single-byte execution character is the
2740 numerical value of the representation of the mapped character interpreted as an integer.
2741 The value of an integer character constant containing more than one character (e.g.,
2742 'ab'), or containing a character or escape sequence that does not map to a single-byte
2743 execution character, is implementation-defined. If an integer character constant contains
2744 a single character or escape sequence, its value is the one that results when an object with
2745 type char whose value is that of the single character or escape sequence is converted to
2747 11 A wide character constant has type wchar_t, an integer type defined in the
2748 <stddef.h> header. The value of a wide character constant containing a single
2749 multibyte character that maps to a member of the extended execution character set is the
2750 wide character corresponding to that multibyte character, as defined by the mbtowc
2751 function, with an implementation-defined current locale. The value of a wide character
2752 constant containing more than one multibyte character, or containing a multibyte
2753 character or escape sequence not represented in the extended execution character set, is
2754 implementation-defined.
2755 12 EXAMPLE 1 The construction '\0' is commonly used to represent the null character.
2757 13 EXAMPLE 2 Consider implementations that use two's-complement representation for integers and eight
2758 bits for objects that have type char. In an implementation in which type char has the same range of
2759 values as signed char, the integer character constant '\xFF' has the value -1; if type char has the
2760 same range of values as unsigned char, the character constant '\xFF' has the value +255.
2762 14 EXAMPLE 3 Even if eight bits are used for objects that have type char, the construction '\x123'
2763 specifies an integer character constant containing only one character, since a hexadecimal escape sequence
2764 is terminated only by a non-hexadecimal character. To specify an integer character constant containing the
2765 two characters whose values are '\x12' and '3', the construction '\0223' may be used, since an octal
2766 escape sequence is terminated after three octal digits. (The value of this two-character integer character
2767 constant is implementation-defined.)
2769 15 EXAMPLE 4 Even if 12 or more bits are used for objects that have type wchar_t, the construction
2770 L'\1234' specifies the implementation-defined value that results from the combination of the values
2773 Forward references: common definitions <stddef.h> (7.17), the mbtowc function
2778 6.4.5 String literals
2781 " s-char-sequenceopt "
2782 L" s-char-sequenceopt "
2785 s-char-sequence s-char
2787 any member of the source character set except
2788 the double-quote ", backslash \, or new-line character
2791 2 A character string literal is a sequence of zero or more multibyte characters enclosed in
2792 double-quotes, as in "xyz". A wide string literal is the same, except prefixed by the
2794 3 The same considerations apply to each element of the sequence in a character string
2795 literal or a wide string literal as if it were in an integer character constant or a wide
2796 character constant, except that the single-quote ' is representable either by itself or by the
2797 escape sequence \', but the double-quote " shall be represented by the escape sequence
2800 4 In translation phase 6, the multibyte character sequences specified by any sequence of
2801 adjacent character and wide string literal tokens are concatenated into a single multibyte
2802 character sequence. If any of the tokens are wide string literal tokens, the resulting
2803 multibyte character sequence is treated as a wide string literal; otherwise, it is treated as a
2804 character string literal.
2805 5 In translation phase 7, a byte or code of value zero is appended to each multibyte
2806 character sequence that results from a string literal or literals.66) The multibyte character
2807 sequence is then used to initialize an array of static storage duration and length just
2808 sufficient to contain the sequence. For character string literals, the array elements have
2809 type char, and are initialized with the individual bytes of the multibyte character
2810 sequence; for wide string literals, the array elements have type wchar_t, and are
2811 initialized with the sequence of wide characters corresponding to the multibyte character
2813 66) A character string literal need not be a string (see 7.1.1), because a null character may be embedded in
2814 it by a \0 escape sequence.
2818 sequence, as defined by the mbstowcs function with an implementation-defined current
2819 locale. The value of a string literal containing a multibyte character or escape sequence
2820 not represented in the execution character set is implementation-defined.
2821 6 It is unspecified whether these arrays are distinct provided their elements have the
2822 appropriate values. If the program attempts to modify such an array, the behavior is
2824 7 EXAMPLE This pair of adjacent character string literals
2826 produces a single character string literal containing the two characters whose values are '\x12' and '3',
2827 because escape sequences are converted into single members of the execution character set just prior to
2828 adjacent string literal concatenation.
2830 Forward references: common definitions <stddef.h> (7.17), the mbstowcs
2831 function (7.20.8.1).
2834 1 punctuator: one of
2837 / % << >> < > <= >= == != ^ | && ||
2839 = *= /= %= += -= <<= >>= &= ^= |=
2843 2 A punctuator is a symbol that has independent syntactic and semantic significance.
2844 Depending on context, it may specify an operation to be performed (which in turn may
2845 yield a value or a function designator, produce a side effect, or some combination thereof)
2846 in which case it is known as an operator (other forms of operator also exist in some
2847 contexts). An operand is an entity on which an operator acts.
2851 3 In all aspects of the language, the six tokens67)
2853 behave, respectively, the same as the six tokens
2855 except for their spelling.68)
2856 Forward references: expressions (6.5), declarations (6.7), preprocessing directives
2857 (6.10), statements (6.8).
2865 h-char-sequence h-char
2867 any member of the source character set except
2868 the new-line character and >
2871 q-char-sequence q-char
2873 any member of the source character set except
2874 the new-line character and "
2876 2 The sequences in both forms of header names are mapped in an implementation-defined
2877 manner to headers or external source file names as specified in 6.10.2.
2878 3 If the characters ', \, ", //, or /* occur in the sequence between the < and > delimiters,
2879 the behavior is undefined. Similarly, if the characters ', \, //, or /* occur in the
2884 67) These tokens are sometimes called ''digraphs''.
2885 68) Thus [ and <: behave differently when ''stringized'' (see 6.10.3.2), but can otherwise be freely
2890 sequence between the " delimiters, the behavior is undefined.69) Header name
2891 preprocessing tokens are recognized only within #include preprocessing directives and
2892 in implementation-defined locations within #pragma directives.70)
2893 4 EXAMPLE The following sequence of characters:
2896 #define const.member@$
2897 forms the following sequence of preprocessing tokens (with each individual preprocessing token delimited
2898 by a { on the left and a } on the right).
2899 {0x3}{<}{1}{/}{a}{.}{h}{>}{1e2}
2900 {#}{include} {<1/a.h>}
2901 {#}{define} {const}{.}{member}{@}{$}
2903 Forward references: source file inclusion (6.10.2).
2904 6.4.8 Preprocessing numbers
2910 pp-number identifier-nondigit
2917 2 A preprocessing number begins with a digit optionally preceded by a period (.) and may
2918 be followed by valid identifier characters and the character sequences e+, e-, E+, E-,
2920 3 Preprocessing number tokens lexically include all floating and integer constant tokens.
2922 4 A preprocessing number does not have type or a value; it acquires both after a successful
2923 conversion (as part of translation phase 7) to a floating constant token or an integer
2927 69) Thus, sequences of characters that resemble escape sequences cause undefined behavior.
2928 70) For an example of a header name preprocessing token used in a #pragma directive, see 6.10.9.
2933 1 Except within a character constant, a string literal, or a comment, the characters /*
2934 introduce a comment. The contents of such a comment are examined only to identify
2935 multibyte characters and to find the characters */ that terminate it.71)
2936 2 Except within a character constant, a string literal, or a comment, the characters //
2937 introduce a comment that includes all multibyte characters up to, but not including, the
2938 next new-line character. The contents of such a comment are examined only to identify
2939 multibyte characters and to find the terminating new-line character.
2941 "a//b" // four-character string literal
2942 #include "//e" // undefined behavior
2943 // */ // comment, not syntax error
2944 f = g/**//h; // equivalent to f = g / h;
2946 i(); // part of a two-line comment
2948 / j(); // part of a two-line comment
2949 #define glue(x,y) x##y
2950 glue(/,/) k(); // syntax error, not comment
2951 /*//*/ l(); // equivalent to l();
2953 + p; // equivalent to m = n + p;
2958 71) Thus, /* ... */ comments do not nest.
2963 1 An expression is a sequence of operators and operands that specifies computation of a
2964 value, or that designates an object or a function, or that generates side effects, or that
2965 performs a combination thereof.
2966 2 Between the previous and next sequence point an object shall have its stored value
2967 modified at most once by the evaluation of an expression.72) Furthermore, the prior value
2968 shall be read only to determine the value to be stored.73)
2969 3 The grouping of operators and operands is indicated by the syntax.74) Except as specified
2970 later (for the function-call (), &&, ||, ?:, and comma operators), the order of evaluation
2971 of subexpressions and the order in which side effects take place are both unspecified.
2972 4 Some operators (the unary operator ~, and the binary operators <<, >>, &, ^, and |,
2973 collectively described as bitwise operators) are required to have operands that have
2974 integer type. These operators yield values that depend on the internal representations of
2975 integers, and have implementation-defined and undefined aspects for signed types.
2976 5 If an exceptional condition occurs during the evaluation of an expression (that is, if the
2977 result is not mathematically defined or not in the range of representable values for its
2978 type), the behavior is undefined.
2979 6 The effective type of an object for an access to its stored value is the declared type of the
2980 object, if any.75) If a value is stored into an object having no declared type through an
2981 lvalue having a type that is not a character type, then the type of the lvalue becomes the
2984 72) A floating-point status flag is not an object and can be set more than once within an expression.
2985 73) This paragraph renders undefined statement expressions such as
2992 74) The syntax specifies the precedence of operators in the evaluation of an expression, which is the same
2993 as the order of the major subclauses of this subclause, highest precedence first. Thus, for example, the
2994 expressions allowed as the operands of the binary + operator (6.5.6) are those expressions defined in
2995 6.5.1 through 6.5.6. The exceptions are cast expressions (6.5.4) as operands of unary operators
2996 (6.5.3), and an operand contained between any of the following pairs of operators: grouping
2997 parentheses () (6.5.1), subscripting brackets [] (6.5.2.1), function-call parentheses () (6.5.2.2), and
2998 the conditional operator ?: (6.5.15).
2999 Within each major subclause, the operators have the same precedence. Left- or right-associativity is
3000 indicated in each subclause by the syntax for the expressions discussed therein.
3001 75) Allocated objects have no declared type.
3005 effective type of the object for that access and for subsequent accesses that do not modify
3006 the stored value. If a value is copied into an object having no declared type using
3007 memcpy or memmove, or is copied as an array of character type, then the effective type
3008 of the modified object for that access and for subsequent accesses that do not modify the
3009 value is the effective type of the object from which the value is copied, if it has one. For
3010 all other accesses to an object having no declared type, the effective type of the object is
3011 simply the type of the lvalue used for the access.
3012 7 An object shall have its stored value accessed only by an lvalue expression that has one of
3013 the following types:76)
3014 -- a type compatible with the effective type of the object,
3015 -- a qualified version of a type compatible with the effective type of the object,
3016 -- a type that is the signed or unsigned type corresponding to the effective type of the
3018 -- a type that is the signed or unsigned type corresponding to a qualified version of the
3019 effective type of the object,
3020 -- an aggregate or union type that includes one of the aforementioned types among its
3021 members (including, recursively, a member of a subaggregate or contained union), or
3022 -- a character type.
3023 8 A floating expression may be contracted, that is, evaluated as though it were an atomic
3024 operation, thereby omitting rounding errors implied by the source code and the
3025 expression evaluation method.77) The FP_CONTRACT pragma in <math.h> provides a
3026 way to disallow contracted expressions. Otherwise, whether and how expressions are
3027 contracted is implementation-defined.78)
3028 Forward references: the FP_CONTRACT pragma (7.12.2), copying functions (7.21.2).
3033 76) The intent of this list is to specify those circumstances in which an object may or may not be aliased.
3034 77) A contracted expression might also omit the raising of floating-point exceptions.
3035 78) This license is specifically intended to allow implementations to exploit fast machine instructions that
3036 combine multiple C operators. As contractions potentially undermine predictability, and can even
3037 decrease accuracy for containing expressions, their use needs to be well-defined and clearly
3042 6.5.1 Primary expressions
3044 1 primary-expression:
3050 2 An identifier is a primary expression, provided it has been declared as designating an
3051 object (in which case it is an lvalue) or a function (in which case it is a function
3053 3 A constant is a primary expression. Its type depends on its form and value, as detailed in
3055 4 A string literal is a primary expression. It is an lvalue with type as detailed in 6.4.5.
3056 5 A parenthesized expression is a primary expression. Its type and value are identical to
3057 those of the unparenthesized expression. It is an lvalue, a function designator, or a void
3058 expression if the unparenthesized expression is, respectively, an lvalue, a function
3059 designator, or a void expression.
3060 Forward references: declarations (6.7).
3061 6.5.2 Postfix operators
3063 1 postfix-expression:
3065 postfix-expression [ expression ]
3066 postfix-expression ( argument-expression-listopt )
3067 postfix-expression . identifier
3068 postfix-expression -> identifier
3069 postfix-expression ++
3070 postfix-expression --
3071 ( type-name ) { initializer-list }
3072 ( type-name ) { initializer-list , }
3077 79) Thus, an undeclared identifier is a violation of the syntax.
3081 argument-expression-list:
3082 assignment-expression
3083 argument-expression-list , assignment-expression
3084 6.5.2.1 Array subscripting
3086 1 One of the expressions shall have type ''pointer to object type'', the other expression shall
3087 have integer type, and the result has type ''type''.
3089 2 A postfix expression followed by an expression in square brackets [] is a subscripted
3090 designation of an element of an array object. The definition of the subscript operator []
3091 is that E1[E2] is identical to (*((E1)+(E2))). Because of the conversion rules that
3092 apply to the binary + operator, if E1 is an array object (equivalently, a pointer to the
3093 initial element of an array object) and E2 is an integer, E1[E2] designates the E2-th
3094 element of E1 (counting from zero).
3095 3 Successive subscript operators designate an element of a multidimensional array object.
3096 If E is an n-dimensional array (n >= 2) with dimensions i x j x . . . x k, then E (used as
3097 other than an lvalue) is converted to a pointer to an (n - 1)-dimensional array with
3098 dimensions j x . . . x k. If the unary * operator is applied to this pointer explicitly, or
3099 implicitly as a result of subscripting, the result is the pointed-to (n - 1)-dimensional array,
3100 which itself is converted into a pointer if used as other than an lvalue. It follows from this
3101 that arrays are stored in row-major order (last subscript varies fastest).
3102 4 EXAMPLE Consider the array object defined by the declaration
3104 Here x is a 3 x 5 array of ints; more precisely, x is an array of three element objects, each of which is an
3105 array of five ints. In the expression x[i], which is equivalent to (*((x)+(i))), x is first converted to
3106 a pointer to the initial array of five ints. Then i is adjusted according to the type of x, which conceptually
3107 entails multiplying i by the size of the object to which the pointer points, namely an array of five int
3108 objects. The results are added and indirection is applied to yield an array of five ints. When used in the
3109 expression x[i][j], that array is in turn converted to a pointer to the first of the ints, so x[i][j]
3112 Forward references: additive operators (6.5.6), address and indirection operators
3113 (6.5.3.2), array declarators (6.7.5.2).
3117 6.5.2.2 Function calls
3119 1 The expression that denotes the called function80) shall have type pointer to function
3120 returning void or returning an object type other than an array type.
3121 2 If the expression that denotes the called function has a type that includes a prototype, the
3122 number of arguments shall agree with the number of parameters. Each argument shall
3123 have a type such that its value may be assigned to an object with the unqualified version
3124 of the type of its corresponding parameter.
3126 3 A postfix expression followed by parentheses () containing a possibly empty, comma-
3127 separated list of expressions is a function call. The postfix expression denotes the called
3128 function. The list of expressions specifies the arguments to the function.
3129 4 An argument may be an expression of any object type. In preparing for the call to a
3130 function, the arguments are evaluated, and each parameter is assigned the value of the
3131 corresponding argument.81)
3132 5 If the expression that denotes the called function has type pointer to function returning an
3133 object type, the function call expression has the same type as that object type, and has the
3134 value determined as specified in 6.8.6.4. Otherwise, the function call has type void. If
3135 an attempt is made to modify the result of a function call or to access it after the next
3136 sequence point, the behavior is undefined.
3137 6 If the expression that denotes the called function has a type that does not include a
3138 prototype, the integer promotions are performed on each argument, and arguments that
3139 have type float are promoted to double. These are called the default argument
3140 promotions. If the number of arguments does not equal the number of parameters, the
3141 behavior is undefined. If the function is defined with a type that includes a prototype, and
3142 either the prototype ends with an ellipsis (, ...) or the types of the arguments after
3143 promotion are not compatible with the types of the parameters, the behavior is undefined.
3144 If the function is defined with a type that does not include a prototype, and the types of
3145 the arguments after promotion are not compatible with those of the parameters after
3146 promotion, the behavior is undefined, except for the following cases:
3151 80) Most often, this is the result of converting an identifier that is a function designator.
3152 81) A function may change the values of its parameters, but these changes cannot affect the values of the
3153 arguments. On the other hand, it is possible to pass a pointer to an object, and the function may
3154 change the value of the object pointed to. A parameter declared to have array or function type is
3155 adjusted to have a pointer type as described in 6.9.1.
3159 -- one promoted type is a signed integer type, the other promoted type is the
3160 corresponding unsigned integer type, and the value is representable in both types;
3161 -- both types are pointers to qualified or unqualified versions of a character type or
3163 7 If the expression that denotes the called function has a type that does include a prototype,
3164 the arguments are implicitly converted, as if by assignment, to the types of the
3165 corresponding parameters, taking the type of each parameter to be the unqualified version
3166 of its declared type. The ellipsis notation in a function prototype declarator causes
3167 argument type conversion to stop after the last declared parameter. The default argument
3168 promotions are performed on trailing arguments.
3169 8 No other conversions are performed implicitly; in particular, the number and types of
3170 arguments are not compared with those of the parameters in a function definition that
3171 does not include a function prototype declarator.
3172 9 If the function is defined with a type that is not compatible with the type (of the
3173 expression) pointed to by the expression that denotes the called function, the behavior is
3175 10 The order of evaluation of the function designator, the actual arguments, and
3176 subexpressions within the actual arguments is unspecified, but there is a sequence point
3177 before the actual call.
3178 11 Recursive function calls shall be permitted, both directly and indirectly through any chain
3180 12 EXAMPLE In the function call
3181 (*pf[f1()]) (f2(), f3() + f4())
3182 the functions f1, f2, f3, and f4 may be called in any order. All side effects have to be completed before
3183 the function pointed to by pf[f1()] is called.
3185 Forward references: function declarators (including prototypes) (6.7.5.3), function
3186 definitions (6.9.1), the return statement (6.8.6.4), simple assignment (6.5.16.1).
3187 6.5.2.3 Structure and union members
3189 1 The first operand of the . operator shall have a qualified or unqualified structure or union
3190 type, and the second operand shall name a member of that type.
3191 2 The first operand of the -> operator shall have type ''pointer to qualified or unqualified
3192 structure'' or ''pointer to qualified or unqualified union'', and the second operand shall
3193 name a member of the type pointed to.
3198 3 A postfix expression followed by the . operator and an identifier designates a member of
3199 a structure or union object. The value is that of the named member,82) and is an lvalue if
3200 the first expression is an lvalue. If the first expression has qualified type, the result has
3201 the so-qualified version of the type of the designated member.
3202 4 A postfix expression followed by the -> operator and an identifier designates a member
3203 of a structure or union object. The value is that of the named member of the object to
3204 which the first expression points, and is an lvalue.83) If the first expression is a pointer to
3205 a qualified type, the result has the so-qualified version of the type of the designated
3207 5 One special guarantee is made in order to simplify the use of unions: if a union contains
3208 several structures that share a common initial sequence (see below), and if the union
3209 object currently contains one of these structures, it is permitted to inspect the common
3210 initial part of any of them anywhere that a declaration of the complete type of the union is
3211 visible. Two structures share a common initial sequence if corresponding members have
3212 compatible types (and, for bit-fields, the same widths) for a sequence of one or more
3214 6 EXAMPLE 1 If f is a function returning a structure or union, and x is a member of that structure or
3215 union, f().x is a valid postfix expression but is not an lvalue.
3218 struct s { int i; const int ci; };
3221 volatile struct s vs;
3222 the various members have the types:
3228 vs.ci volatile const int
3233 82) If the member used to access the contents of a union object is not the same as the member last used to
3234 store a value in the object, the appropriate part of the object representation of the value is reinterpreted
3235 as an object representation in the new type as described in 6.2.6 (a process sometimes called "type
3236 punning"). This might be a trap representation.
3237 83) If &E is a valid pointer expression (where & is the ''address-of '' operator, which generates a pointer to
3238 its operand), the expression (&E)->MOS is the same as E.MOS.
3242 8 EXAMPLE 3 The following is a valid fragment:
3257 u.nf.doublenode = 3.14;
3259 if (u.n.alltypes == 1)
3260 if (sin(u.nf.doublenode) == 0.0)
3262 The following is not a valid fragment (because the union type is not visible within function f):
3263 struct t1 { int m; };
3264 struct t2 { int m; };
3265 int f(struct t1 *p1, struct t2 *p2)
3278 return f(&u.s1, &u.s2);
3281 Forward references: address and indirection operators (6.5.3.2), structure and union
3282 specifiers (6.7.2.1).
3286 6.5.2.4 Postfix increment and decrement operators
3288 1 The operand of the postfix increment or decrement operator shall have qualified or
3289 unqualified real or pointer type and shall be a modifiable lvalue.
3291 2 The result of the postfix ++ operator is the value of the operand. After the result is
3292 obtained, the value of the operand is incremented. (That is, the value 1 of the appropriate
3293 type is added to it.) See the discussions of additive operators and compound assignment
3294 for information on constraints, types, and conversions and the effects of operations on
3295 pointers. The side effect of updating the stored value of the operand shall occur between
3296 the previous and the next sequence point.
3297 3 The postfix -- operator is analogous to the postfix ++ operator, except that the value of
3298 the operand is decremented (that is, the value 1 of the appropriate type is subtracted from
3300 Forward references: additive operators (6.5.6), compound assignment (6.5.16.2).
3301 6.5.2.5 Compound literals
3303 1 The type name shall specify an object type or an array of unknown size, but not a variable
3305 2 No initializer shall attempt to provide a value for an object not contained within the entire
3306 unnamed object specified by the compound literal.
3307 3 If the compound literal occurs outside the body of a function, the initializer list shall
3308 consist of constant expressions.
3310 4 A postfix expression that consists of a parenthesized type name followed by a brace-
3311 enclosed list of initializers is a compound literal. It provides an unnamed object whose
3312 value is given by the initializer list.84)
3313 5 If the type name specifies an array of unknown size, the size is determined by the
3314 initializer list as specified in 6.7.8, and the type of the compound literal is that of the
3315 completed array type. Otherwise (when the type name specifies an object type), the type
3316 of the compound literal is that specified by the type name. In either case, the result is an
3320 84) Note that this differs from a cast expression. For example, a cast specifies a conversion to scalar types
3321 or void only, and the result of a cast expression is not an lvalue.
3325 6 The value of the compound literal is that of an unnamed object initialized by the
3326 initializer list. If the compound literal occurs outside the body of a function, the object
3327 has static storage duration; otherwise, it has automatic storage duration associated with
3328 the enclosing block.
3329 7 All the semantic rules and constraints for initializer lists in 6.7.8 are applicable to
3330 compound literals.85)
3331 8 String literals, and compound literals with const-qualified types, need not designate
3332 distinct objects.86)
3333 9 EXAMPLE 1 The file scope definition
3334 int *p = (int []){2, 4};
3335 initializes p to point to the first element of an array of two ints, the first having the value two and the
3336 second, four. The expressions in this compound literal are required to be constant. The unnamed object
3337 has static storage duration.
3339 10 EXAMPLE 2 In contrast, in
3347 p is assigned the address of the first element of an array of two ints, the first having the value previously
3348 pointed to by p and the second, zero. The expressions in this compound literal need not be constant. The
3349 unnamed object has automatic storage duration.
3351 11 EXAMPLE 3 Initializers with designations can be combined with compound literals. Structure objects
3352 created using compound literals can be passed to functions without depending on member order:
3353 drawline((struct point){.x=1, .y=1},
3354 (struct point){.x=3, .y=4});
3355 Or, if drawline instead expected pointers to struct point:
3356 drawline(&(struct point){.x=1, .y=1},
3357 &(struct point){.x=3, .y=4});
3359 12 EXAMPLE 4 A read-only compound literal can be specified through constructions like:
3360 (const float []){1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6}
3365 85) For example, subobjects without explicit initializers are initialized to zero.
3366 86) This allows implementations to share storage for string literals and constant compound literals with
3367 the same or overlapping representations.
3371 13 EXAMPLE 5 The following three expressions have different meanings:
3373 (char []){"/tmp/fileXXXXXX"}
3374 (const char []){"/tmp/fileXXXXXX"}
3375 The first always has static storage duration and has type array of char, but need not be modifiable; the last
3376 two have automatic storage duration when they occur within the body of a function, and the first of these
3379 14 EXAMPLE 6 Like string literals, const-qualified compound literals can be placed into read-only memory
3380 and can even be shared. For example,
3381 (const char []){"abc"} == "abc"
3382 might yield 1 if the literals' storage is shared.
3384 15 EXAMPLE 7 Since compound literals are unnamed, a single compound literal cannot specify a circularly
3385 linked object. For example, there is no way to write a self-referential compound literal that could be used
3386 as the function argument in place of the named object endless_zeros below:
3387 struct int_list { int car; struct int_list *cdr; };
3388 struct int_list endless_zeros = {0, &endless_zeros};
3389 eval(endless_zeros);
3391 16 EXAMPLE 8 Each compound literal creates only a single object in a given scope:
3392 struct s { int i; };
3395 struct s *p = 0, *q;
3398 q = p, p = &((struct s){ j++ });
3399 if (j < 2) goto again;
3400 return p == q && q->i == 1;
3402 The function f() always returns the value 1.
3403 17 Note that if an iteration statement were used instead of an explicit goto and a labeled statement, the
3404 lifetime of the unnamed object would be the body of the loop only, and on entry next time around p would
3405 have an indeterminate value, which would result in undefined behavior.
3407 Forward references: type names (6.7.6), initialization (6.7.8).
3411 6.5.3 Unary operators
3417 unary-operator cast-expression
3418 sizeof unary-expression
3419 sizeof ( type-name )
3420 unary-operator: one of
3422 6.5.3.1 Prefix increment and decrement operators
3424 1 The operand of the prefix increment or decrement operator shall have qualified or
3425 unqualified real or pointer type and shall be a modifiable lvalue.
3427 2 The value of the operand of the prefix ++ operator is incremented. The result is the new
3428 value of the operand after incrementation. The expression ++E is equivalent to (E+=1).
3429 See the discussions of additive operators and compound assignment for information on
3430 constraints, types, side effects, and conversions and the effects of operations on pointers.
3431 3 The prefix -- operator is analogous to the prefix ++ operator, except that the value of the
3432 operand is decremented.
3433 Forward references: additive operators (6.5.6), compound assignment (6.5.16.2).
3434 6.5.3.2 Address and indirection operators
3436 1 The operand of the unary & operator shall be either a function designator, the result of a
3437 [] or unary * operator, or an lvalue that designates an object that is not a bit-field and is
3438 not declared with the register storage-class specifier.
3439 2 The operand of the unary * operator shall have pointer type.
3441 3 The unary & operator yields the address of its operand. If the operand has type ''type'',
3442 the result has type ''pointer to type''. If the operand is the result of a unary * operator,
3443 neither that operator nor the & operator is evaluated and the result is as if both were
3444 omitted, except that the constraints on the operators still apply and the result is not an
3445 lvalue. Similarly, if the operand is the result of a [] operator, neither the & operator nor
3449 the unary * that is implied by the [] is evaluated and the result is as if the & operator
3450 were removed and the [] operator were changed to a + operator. Otherwise, the result is
3451 a pointer to the object or function designated by its operand.
3452 4 The unary * operator denotes indirection. If the operand points to a function, the result is
3453 a function designator; if it points to an object, the result is an lvalue designating the
3454 object. If the operand has type ''pointer to type'', the result has type ''type''. If an
3455 invalid value has been assigned to the pointer, the behavior of the unary * operator is
3457 Forward references: storage-class specifiers (6.7.1), structure and union specifiers
3459 6.5.3.3 Unary arithmetic operators
3461 1 The operand of the unary + or - operator shall have arithmetic type; of the ~ operator,
3462 integer type; of the ! operator, scalar type.
3464 2 The result of the unary + operator is the value of its (promoted) operand. The integer
3465 promotions are performed on the operand, and the result has the promoted type.
3466 3 The result of the unary - operator is the negative of its (promoted) operand. The integer
3467 promotions are performed on the operand, and the result has the promoted type.
3468 4 The result of the ~ operator is the bitwise complement of its (promoted) operand (that is,
3469 each bit in the result is set if and only if the corresponding bit in the converted operand is
3470 not set). The integer promotions are performed on the operand, and the result has the
3471 promoted type. If the promoted type is an unsigned type, the expression ~E is equivalent
3472 to the maximum value representable in that type minus E.
3473 5 The result of the logical negation operator ! is 0 if the value of its operand compares
3474 unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int.
3475 The expression !E is equivalent to (0==E).
3480 87) Thus, &*E is equivalent to E (even if E is a null pointer), and &(E1[E2]) to ((E1)+(E2)). It is
3481 always true that if E is a function designator or an lvalue that is a valid operand of the unary &
3482 operator, *&E is a function designator or an lvalue equal to E. If *P is an lvalue and T is the name of
3483 an object pointer type, *(T)P is an lvalue that has a type compatible with that to which T points.
3484 Among the invalid values for dereferencing a pointer by the unary * operator are a null pointer, an
3485 address inappropriately aligned for the type of object pointed to, and the address of an object after the
3486 end of its lifetime.
3490 6.5.3.4 The sizeof operator
3492 1 The sizeof operator shall not be applied to an expression that has function type or an
3493 incomplete type, to the parenthesized name of such a type, or to an expression that
3494 designates a bit-field member.
3496 2 The sizeof operator yields the size (in bytes) of its operand, which may be an
3497 expression or the parenthesized name of a type. The size is determined from the type of
3498 the operand. The result is an integer. If the type of the operand is a variable length array
3499 type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an
3501 3 When applied to an operand that has type char, unsigned char, or signed char,
3502 (or a qualified version thereof) the result is 1. When applied to an operand that has array
3503 type, the result is the total number of bytes in the array.88) When applied to an operand
3504 that has structure or union type, the result is the total number of bytes in such an object,
3505 including internal and trailing padding.
3506 4 The value of the result is implementation-defined, and its type (an unsigned integer type)
3507 is size_t, defined in <stddef.h> (and other headers).
3508 5 EXAMPLE 1 A principal use of the sizeof operator is in communication with routines such as storage
3509 allocators and I/O systems. A storage-allocation function might accept a size (in bytes) of an object to
3510 allocate and return a pointer to void. For example:
3511 extern void *alloc(size_t);
3512 double *dp = alloc(sizeof *dp);
3513 The implementation of the alloc function should ensure that its return value is aligned suitably for
3514 conversion to a pointer to double.
3516 6 EXAMPLE 2 Another use of the sizeof operator is to compute the number of elements in an array:
3517 sizeof array / sizeof array[0]
3519 7 EXAMPLE 3 In this example, the size of a variable length array is computed and returned from a
3522 size_t fsize3(int n)
3524 char b[n+3]; // variable length array
3525 return sizeof b; // execution time sizeof
3530 88) When applied to a parameter declared to have array or function type, the sizeof operator yields the
3531 size of the adjusted (pointer) type (see 6.9.1).
3538 size = fsize3(10); // fsize3 returns 13
3542 Forward references: common definitions <stddef.h> (7.17), declarations (6.7),
3543 structure and union specifiers (6.7.2.1), type names (6.7.6), array declarators (6.7.5.2).
3544 6.5.4 Cast operators
3548 ( type-name ) cast-expression
3550 2 Unless the type name specifies a void type, the type name shall specify qualified or
3551 unqualified scalar type and the operand shall have scalar type.
3552 3 Conversions that involve pointers, other than where permitted by the constraints of
3553 6.5.16.1, shall be specified by means of an explicit cast.
3555 4 Preceding an expression by a parenthesized type name converts the value of the
3556 expression to the named type. This construction is called a cast.89) A cast that specifies
3557 no conversion has no effect on the type or value of an expression.
3558 5 If the value of the expression is represented with greater precision or range than required
3559 by the type named by the cast (6.3.1.8), then the cast specifies a conversion even if the
3560 type of the expression is the same as the named type.
3561 Forward references: equality operators (6.5.9), function declarators (including
3562 prototypes) (6.7.5.3), simple assignment (6.5.16.1), type names (6.7.6).
3567 89) A cast does not yield an lvalue. Thus, a cast to a qualified type has the same effect as a cast to the
3568 unqualified version of the type.
3572 6.5.5 Multiplicative operators
3574 1 multiplicative-expression:
3576 multiplicative-expression * cast-expression
3577 multiplicative-expression / cast-expression
3578 multiplicative-expression % cast-expression
3580 2 Each of the operands shall have arithmetic type. The operands of the % operator shall
3583 3 The usual arithmetic conversions are performed on the operands.
3584 4 The result of the binary * operator is the product of the operands.
3585 5 The result of the / operator is the quotient from the division of the first operand by the
3586 second; the result of the % operator is the remainder. In both operations, if the value of
3587 the second operand is zero, the behavior is undefined.
3588 6 When integers are divided, the result of the / operator is the algebraic quotient with any
3589 fractional part discarded.90) If the quotient a/b is representable, the expression
3590 (a/b)*b + a%b shall equal a.
3591 6.5.6 Additive operators
3593 1 additive-expression:
3594 multiplicative-expression
3595 additive-expression + multiplicative-expression
3596 additive-expression - multiplicative-expression
3598 2 For addition, either both operands shall have arithmetic type, or one operand shall be a
3599 pointer to an object type and the other shall have integer type. (Incrementing is
3600 equivalent to adding 1.)
3601 3 For subtraction, one of the following shall hold:
3602 -- both operands have arithmetic type;
3606 90) This is often called ''truncation toward zero''.
3610 -- both operands are pointers to qualified or unqualified versions of compatible object
3612 -- the left operand is a pointer to an object type and the right operand has integer type.
3613 (Decrementing is equivalent to subtracting 1.)
3615 4 If both operands have arithmetic type, the usual arithmetic conversions are performed on
3617 5 The result of the binary + operator is the sum of the operands.
3618 6 The result of the binary - operator is the difference resulting from the subtraction of the
3619 second operand from the first.
3620 7 For the purposes of these operators, a pointer to an object that is not an element of an
3621 array behaves the same as a pointer to the first element of an array of length one with the
3622 type of the object as its element type.
3623 8 When an expression that has integer type is added to or subtracted from a pointer, the
3624 result has the type of the pointer operand. If the pointer operand points to an element of
3625 an array object, and the array is large enough, the result points to an element offset from
3626 the original element such that the difference of the subscripts of the resulting and original
3627 array elements equals the integer expression. In other words, if the expression P points to
3628 the i-th element of an array object, the expressions (P)+N (equivalently, N+(P)) and
3629 (P)-N (where N has the value n) point to, respectively, the i+n-th and i-n-th elements of
3630 the array object, provided they exist. Moreover, if the expression P points to the last
3631 element of an array object, the expression (P)+1 points one past the last element of the
3632 array object, and if the expression Q points one past the last element of an array object,
3633 the expression (Q)-1 points to the last element of the array object. If both the pointer
3634 operand and the result point to elements of the same array object, or one past the last
3635 element of the array object, the evaluation shall not produce an overflow; otherwise, the
3636 behavior is undefined. If the result points one past the last element of the array object, it
3637 shall not be used as the operand of a unary * operator that is evaluated.
3638 9 When two pointers are subtracted, both shall point to elements of the same array object,
3639 or one past the last element of the array object; the result is the difference of the
3640 subscripts of the two array elements. The size of the result is implementation-defined,
3641 and its type (a signed integer type) is ptrdiff_t defined in the <stddef.h> header.
3642 If the result is not representable in an object of that type, the behavior is undefined. In
3643 other words, if the expressions P and Q point to, respectively, the i-th and j-th elements of
3644 an array object, the expression (P)-(Q) has the value i-j provided the value fits in an
3645 object of type ptrdiff_t. Moreover, if the expression P points either to an element of
3646 an array object or one past the last element of an array object, and the expression Q points
3647 to the last element of the same array object, the expression ((Q)+1)-(P) has the same
3651 value as ((Q)-(P))+1 and as -((P)-((Q)+1)), and has the value zero if the
3652 expression P points one past the last element of the array object, even though the
3653 expression (Q)+1 does not point to an element of the array object.91)
3654 10 EXAMPLE Pointer arithmetic is well defined with pointers to variable length array types.
3658 int (*p)[m] = a; // p == &a[0]
3659 p += 1; // p == &a[1]
3660 (*p)[2] = 99; // a[1][2] == 99
3661 n = p - a; // n == 1
3663 11 If array a in the above example were declared to be an array of known constant size, and pointer p were
3664 declared to be a pointer to an array of the same known constant size (pointing to a), the results would be
3667 Forward references: array declarators (6.7.5.2), common definitions <stddef.h>
3669 6.5.7 Bitwise shift operators
3673 shift-expression << additive-expression
3674 shift-expression >> additive-expression
3676 2 Each of the operands shall have integer type.
3678 3 The integer promotions are performed on each of the operands. The type of the result is
3679 that of the promoted left operand. If the value of the right operand is negative or is
3680 greater than or equal to the width of the promoted left operand, the behavior is undefined.
3685 91) Another way to approach pointer arithmetic is first to convert the pointer(s) to character pointer(s): In
3686 this scheme the integer expression added to or subtracted from the converted pointer is first multiplied
3687 by the size of the object originally pointed to, and the resulting pointer is converted back to the
3688 original type. For pointer subtraction, the result of the difference between the character pointers is
3689 similarly divided by the size of the object originally pointed to.
3690 When viewed in this way, an implementation need only provide one extra byte (which may overlap
3691 another object in the program) just after the end of the object in order to satisfy the ''one past the last
3692 element'' requirements.
3696 4 The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with
3697 zeros. If E1 has an unsigned type, the value of the result is E1 x 2E2 , reduced modulo
3698 one more than the maximum value representable in the result type. If E1 has a signed
3699 type and nonnegative value, and E1 x 2E2 is representable in the result type, then that is
3700 the resulting value; otherwise, the behavior is undefined.
3701 5 The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type
3702 or if E1 has a signed type and a nonnegative value, the value of the result is the integral
3703 part of the quotient of E1 / 2E2 . If E1 has a signed type and a negative value, the
3704 resulting value is implementation-defined.
3705 6.5.8 Relational operators
3707 1 relational-expression:
3709 relational-expression < shift-expression
3710 relational-expression > shift-expression
3711 relational-expression <= shift-expression
3712 relational-expression >= shift-expression
3714 2 One of the following shall hold:
3715 -- both operands have real type;
3716 -- both operands are pointers to qualified or unqualified versions of compatible object
3718 -- both operands are pointers to qualified or unqualified versions of compatible
3721 3 If both of the operands have arithmetic type, the usual arithmetic conversions are
3723 4 For the purposes of these operators, a pointer to an object that is not an element of an
3724 array behaves the same as a pointer to the first element of an array of length one with the
3725 type of the object as its element type.
3726 5 When two pointers are compared, the result depends on the relative locations in the
3727 address space of the objects pointed to. If two pointers to object or incomplete types both
3728 point to the same object, or both point one past the last element of the same array object,
3729 they compare equal. If the objects pointed to are members of the same aggregate object,
3730 pointers to structure members declared later compare greater than pointers to members
3731 declared earlier in the structure, and pointers to array elements with larger subscript
3735 values compare greater than pointers to elements of the same array with lower subscript
3736 values. All pointers to members of the same union object compare equal. If the
3737 expression P points to an element of an array object and the expression Q points to the
3738 last element of the same array object, the pointer expression Q+1 compares greater than
3739 P. In all other cases, the behavior is undefined.
3740 6 Each of the operators < (less than), > (greater than), <= (less than or equal to), and >=
3741 (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false.92)
3742 The result has type int.
3743 6.5.9 Equality operators
3745 1 equality-expression:
3746 relational-expression
3747 equality-expression == relational-expression
3748 equality-expression != relational-expression
3750 2 One of the following shall hold:
3751 -- both operands have arithmetic type;
3752 -- both operands are pointers to qualified or unqualified versions of compatible types;
3753 -- one operand is a pointer to an object or incomplete type and the other is a pointer to a
3754 qualified or unqualified version of void; or
3755 -- one operand is a pointer and the other is a null pointer constant.
3757 3 The == (equal to) and != (not equal to) operators are analogous to the relational
3758 operators except for their lower precedence.93) Each of the operators yields 1 if the
3759 specified relation is true and 0 if it is false. The result has type int. For any pair of
3760 operands, exactly one of the relations is true.
3761 4 If both of the operands have arithmetic type, the usual arithmetic conversions are
3762 performed. Values of complex types are equal if and only if both their real parts are equal
3763 and also their imaginary parts are equal. Any two values of arithmetic types from
3764 different type domains are equal if and only if the results of their conversions to the
3765 (complex) result type determined by the usual arithmetic conversions are equal.
3768 92) The expression a<b<c is not interpreted as in ordinary mathematics. As the syntax indicates, it
3769 means (a<b)<c; in other words, ''if a is less than b, compare 1 to c; otherwise, compare 0 to c''.
3770 93) Because of the precedences, a<b == c<d is 1 whenever a<b and c<d have the same truth-value.
3774 5 Otherwise, at least one operand is a pointer. If one operand is a pointer and the other is a
3775 null pointer constant, the null pointer constant is converted to the type of the pointer. If
3776 one operand is a pointer to an object or incomplete type and the other is a pointer to a
3777 qualified or unqualified version of void, the former is converted to the type of the latter.
3778 6 Two pointers compare equal if and only if both are null pointers, both are pointers to the
3779 same object (including a pointer to an object and a subobject at its beginning) or function,
3780 both are pointers to one past the last element of the same array object, or one is a pointer
3781 to one past the end of one array object and the other is a pointer to the start of a different
3782 array object that happens to immediately follow the first array object in the address
3784 7 For the purposes of these operators, a pointer to an object that is not an element of an
3785 array behaves the same as a pointer to the first element of an array of length one with the
3786 type of the object as its element type.
3787 6.5.10 Bitwise AND operator
3791 AND-expression & equality-expression
3793 2 Each of the operands shall have integer type.
3795 3 The usual arithmetic conversions are performed on the operands.
3796 4 The result of the binary & operator is the bitwise AND of the operands (that is, each bit in
3797 the result is set if and only if each of the corresponding bits in the converted operands is
3803 94) Two objects may be adjacent in memory because they are adjacent elements of a larger array or
3804 adjacent members of a structure with no padding between them, or because the implementation chose
3805 to place them so, even though they are unrelated. If prior invalid pointer operations (such as accesses
3806 outside array bounds) produced undefined behavior, subsequent comparisons also produce undefined
3811 6.5.11 Bitwise exclusive OR operator
3813 1 exclusive-OR-expression:
3815 exclusive-OR-expression ^ AND-expression
3817 2 Each of the operands shall have integer type.
3819 3 The usual arithmetic conversions are performed on the operands.
3820 4 The result of the ^ operator is the bitwise exclusive OR of the operands (that is, each bit
3821 in the result is set if and only if exactly one of the corresponding bits in the converted
3823 6.5.12 Bitwise inclusive OR operator
3825 1 inclusive-OR-expression:
3826 exclusive-OR-expression
3827 inclusive-OR-expression | exclusive-OR-expression
3829 2 Each of the operands shall have integer type.
3831 3 The usual arithmetic conversions are performed on the operands.
3832 4 The result of the | operator is the bitwise inclusive OR of the operands (that is, each bit in
3833 the result is set if and only if at least one of the corresponding bits in the converted
3838 6.5.13 Logical AND operator
3840 1 logical-AND-expression:
3841 inclusive-OR-expression
3842 logical-AND-expression && inclusive-OR-expression
3844 2 Each of the operands shall have scalar type.
3846 3 The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it
3847 yields 0. The result has type int.
3848 4 Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation;
3849 there is a sequence point after the evaluation of the first operand. If the first operand
3850 compares equal to 0, the second operand is not evaluated.
3851 6.5.14 Logical OR operator
3853 1 logical-OR-expression:
3854 logical-AND-expression
3855 logical-OR-expression || logical-AND-expression
3857 2 Each of the operands shall have scalar type.
3859 3 The || operator shall yield 1 if either of its operands compare unequal to 0; otherwise, it
3860 yields 0. The result has type int.
3861 4 Unlike the bitwise | operator, the || operator guarantees left-to-right evaluation; there is
3862 a sequence point after the evaluation of the first operand. If the first operand compares
3863 unequal to 0, the second operand is not evaluated.
3867 6.5.15 Conditional operator
3869 1 conditional-expression:
3870 logical-OR-expression
3871 logical-OR-expression ? expression : conditional-expression
3873 2 The first operand shall have scalar type.
3874 3 One of the following shall hold for the second and third operands:
3875 -- both operands have arithmetic type;
3876 -- both operands have the same structure or union type;
3877 -- both operands have void type;
3878 -- both operands are pointers to qualified or unqualified versions of compatible types;
3879 -- one operand is a pointer and the other is a null pointer constant; or
3880 -- one operand is a pointer to an object or incomplete type and the other is a pointer to a
3881 qualified or unqualified version of void.
3883 4 The first operand is evaluated; there is a sequence point after its evaluation. The second
3884 operand is evaluated only if the first compares unequal to 0; the third operand is evaluated
3885 only if the first compares equal to 0; the result is the value of the second or third operand
3886 (whichever is evaluated), converted to the type described below.95) If an attempt is made
3887 to modify the result of a conditional operator or to access it after the next sequence point,
3888 the behavior is undefined.
3889 5 If both the second and third operands have arithmetic type, the result type that would be
3890 determined by the usual arithmetic conversions, were they applied to those two operands,
3891 is the type of the result. If both the operands have structure or union type, the result has
3892 that type. If both operands have void type, the result has void type.
3893 6 If both the second and third operands are pointers or one is a null pointer constant and the
3894 other is a pointer, the result type is a pointer to a type qualified with all the type qualifiers
3895 of the types pointed-to by both operands. Furthermore, if both operands are pointers to
3896 compatible types or to differently qualified versions of compatible types, the result type is
3897 a pointer to an appropriately qualified version of the composite type; if one operand is a
3898 null pointer constant, the result has the type of the other operand; otherwise, one operand
3899 is a pointer to void or a qualified version of void, in which case the result type is a
3901 95) A conditional expression does not yield an lvalue.
3905 pointer to an appropriately qualified version of void.
3906 7 EXAMPLE The common type that results when the second and third operands are pointers is determined
3907 in two independent stages. The appropriate qualifiers, for example, do not depend on whether the two
3908 pointers have compatible types.
3909 8 Given the declarations
3916 the third column in the following table is the common type that is the result of a conditional expression in
3917 which the first two columns are the second and third operands (in either order):
3918 c_vp c_ip const void *
3919 v_ip 0 volatile int *
3920 c_ip v_ip const volatile int *
3921 vp c_cp const void *
3925 6.5.16 Assignment operators
3927 1 assignment-expression:
3928 conditional-expression
3929 unary-expression assignment-operator assignment-expression
3930 assignment-operator: one of
3931 = *= /= %= += -= <<= >>= &= ^= |=
3933 2 An assignment operator shall have a modifiable lvalue as its left operand.
3935 3 An assignment operator stores a value in the object designated by the left operand. An
3936 assignment expression has the value of the left operand after the assignment, but is not an
3937 lvalue. The type of an assignment expression is the type of the left operand unless the
3938 left operand has qualified type, in which case it is the unqualified version of the type of
3939 the left operand. The side effect of updating the stored value of the left operand shall
3940 occur between the previous and the next sequence point.
3941 4 The order of evaluation of the operands is unspecified. If an attempt is made to modify
3942 the result of an assignment operator or to access it after the next sequence point, the
3943 behavior is undefined.
3947 6.5.16.1 Simple assignment
3949 1 One of the following shall hold:96)
3950 -- the left operand has qualified or unqualified arithmetic type and the right has
3952 -- the left operand has a qualified or unqualified version of a structure or union type
3953 compatible with the type of the right;
3954 -- both operands are pointers to qualified or unqualified versions of compatible types,
3955 and the type pointed to by the left has all the qualifiers of the type pointed to by the
3957 -- one operand is a pointer to an object or incomplete type and the other is a pointer to a
3958 qualified or unqualified version of void, and the type pointed to by the left has all
3959 the qualifiers of the type pointed to by the right;
3960 -- the left operand is a pointer and the right is a null pointer constant; or
3961 -- the left operand has type _Bool and the right is a pointer.
3963 2 In simple assignment (=), the value of the right operand is converted to the type of the
3964 assignment expression and replaces the value stored in the object designated by the left
3966 3 If the value being stored in an object is read from another object that overlaps in any way
3967 the storage of the first object, then the overlap shall be exact and the two objects shall
3968 have qualified or unqualified versions of a compatible type; otherwise, the behavior is
3970 4 EXAMPLE 1 In the program fragment
3974 if ((c = f()) == -1)
3976 the int value returned by the function may be truncated when stored in the char, and then converted back
3977 to int width prior to the comparison. In an implementation in which ''plain'' char has the same range of
3978 values as unsigned char (and char is narrower than int), the result of the conversion cannot be
3982 96) The asymmetric appearance of these constraints with respect to type qualifiers is due to the conversion
3983 (specified in 6.3.2.1) that changes lvalues to ''the value of the expression'' and thus removes any type
3984 qualifiers that were applied to the type category of the expression (for example, it removes const but
3985 not volatile from the type int volatile * const).
3989 negative, so the operands of the comparison can never compare equal. Therefore, for full portability, the
3990 variable c should be declared as int.
3992 5 EXAMPLE 2 In the fragment:
3997 the value of i is converted to the type of the assignment expression c = i, that is, char type. The value
3998 of the expression enclosed in parentheses is then converted to the type of the outer assignment expression,
3999 that is, long int type.
4001 6 EXAMPLE 3 Consider the fragment:
4005 cpp = &p; // constraint violation
4008 The first assignment is unsafe because it would allow the following valid code to attempt to change the
4009 value of the const object c.
4011 6.5.16.2 Compound assignment
4013 1 For the operators += and -= only, either the left operand shall be a pointer to an object
4014 type and the right shall have integer type, or the left operand shall have qualified or
4015 unqualified arithmetic type and the right shall have arithmetic type.
4016 2 For the other operators, each operand shall have arithmetic type consistent with those
4017 allowed by the corresponding binary operator.
4019 3 A compound assignment of the form E1 op = E2 differs from the simple assignment
4020 expression E1 = E1 op (E2) only in that the lvalue E1 is evaluated only once.
4024 6.5.17 Comma operator
4027 assignment-expression
4028 expression , assignment-expression
4030 2 The left operand of a comma operator is evaluated as a void expression; there is a
4031 sequence point after its evaluation. Then the right operand is evaluated; the result has its
4032 type and value.97) If an attempt is made to modify the result of a comma operator or to
4033 access it after the next sequence point, the behavior is undefined.
4034 3 EXAMPLE As indicated by the syntax, the comma operator (as described in this subclause) cannot
4035 appear in contexts where a comma is used to separate items in a list (such as arguments to functions or lists
4036 of initializers). On the other hand, it can be used within a parenthesized expression or within the second
4037 expression of a conditional operator in such contexts. In the function call
4039 the function has three arguments, the second of which has the value 5.
4041 Forward references: initialization (6.7.8).
4046 97) A comma operator does not yield an lvalue.
4050 6.6 Constant expressions
4052 1 constant-expression:
4053 conditional-expression
4055 2 A constant expression can be evaluated during translation rather than runtime, and
4056 accordingly may be used in any place that a constant may be.
4058 3 Constant expressions shall not contain assignment, increment, decrement, function-call,
4059 or comma operators, except when they are contained within a subexpression that is not
4061 4 Each constant expression shall evaluate to a constant that is in the range of representable
4062 values for its type.
4064 5 An expression that evaluates to a constant is required in several contexts. If a floating
4065 expression is evaluated in the translation environment, the arithmetic precision and range
4066 shall be at least as great as if the expression were being evaluated in the execution
4068 6 An integer constant expression99) shall have integer type and shall only have operands
4069 that are integer constants, enumeration constants, character constants, sizeof
4070 expressions whose results are integer constants, and floating constants that are the
4071 immediate operands of casts. Cast operators in an integer constant expression shall only
4072 convert arithmetic types to integer types, except as part of an operand to the sizeof
4074 7 More latitude is permitted for constant expressions in initializers. Such a constant
4075 expression shall be, or evaluate to, one of the following:
4076 -- an arithmetic constant expression,
4077 -- a null pointer constant,
4082 98) The operand of a sizeof operator is usually not evaluated (6.5.3.4).
4083 99) An integer constant expression is used to specify the size of a bit-field member of a structure, the
4084 value of an enumeration constant, the size of an array, or the value of a case constant. Further
4085 constraints that apply to the integer constant expressions used in conditional-inclusion preprocessing
4086 directives are discussed in 6.10.1.
4090 -- an address constant, or
4091 -- an address constant for an object type plus or minus an integer constant expression.
4092 8 An arithmetic constant expression shall have arithmetic type and shall only have
4093 operands that are integer constants, floating constants, enumeration constants, character
4094 constants, and sizeof expressions. Cast operators in an arithmetic constant expression
4095 shall only convert arithmetic types to arithmetic types, except as part of an operand to a
4096 sizeof operator whose result is an integer constant.
4097 9 An address constant is a null pointer, a pointer to an lvalue designating an object of static
4098 storage duration, or a pointer to a function designator; it shall be created explicitly using
4099 the unary & operator or an integer constant cast to pointer type, or implicitly by the use of
4100 an expression of array or function type. The array-subscript [] and member-access .
4101 and -> operators, the address & and indirection * unary operators, and pointer casts may
4102 be used in the creation of an address constant, but the value of an object shall not be
4103 accessed by use of these operators.
4104 10 An implementation may accept other forms of constant expressions.
4105 11 The semantic rules for the evaluation of a constant expression are the same as for
4106 nonconstant expressions.100)
4107 Forward references: array declarators (6.7.5.2), initialization (6.7.8).
4112 100) Thus, in the following initialization,
4113 static int i = 2 || 1 / 0;
4114 the expression is a valid integer constant expression with value one.
4121 declaration-specifiers init-declarator-listopt ;
4122 declaration-specifiers:
4123 storage-class-specifier declaration-specifiersopt
4124 type-specifier declaration-specifiersopt
4125 type-qualifier declaration-specifiersopt
4126 function-specifier declaration-specifiersopt
4127 init-declarator-list:
4129 init-declarator-list , init-declarator
4132 declarator = initializer
4134 2 A declaration shall declare at least a declarator (other than the parameters of a function or
4135 the members of a structure or union), a tag, or the members of an enumeration.
4136 3 If an identifier has no linkage, there shall be no more than one declaration of the identifier
4137 (in a declarator or type specifier) with the same scope and in the same name space, except
4138 for tags as specified in 6.7.2.3.
4139 4 All declarations in the same scope that refer to the same object or function shall specify
4142 5 A declaration specifies the interpretation and attributes of a set of identifiers. A definition
4143 of an identifier is a declaration for that identifier that:
4144 -- for an object, causes storage to be reserved for that object;
4145 -- for a function, includes the function body;101)
4146 -- for an enumeration constant or typedef name, is the (only) declaration of the
4148 6 The declaration specifiers consist of a sequence of specifiers that indicate the linkage,
4149 storage duration, and part of the type of the entities that the declarators denote. The init-
4150 declarator-list is a comma-separated sequence of declarators, each of which may have
4152 101) Function definitions have a different syntax, described in 6.9.1.
4156 additional type information, or an initializer, or both. The declarators contain the
4157 identifiers (if any) being declared.
4158 7 If an identifier for an object is declared with no linkage, the type for the object shall be
4159 complete by the end of its declarator, or by the end of its init-declarator if it has an
4160 initializer; in the case of function parameters (including in prototypes), it is the adjusted
4161 type (see 6.7.5.3) that is required to be complete.
4162 Forward references: declarators (6.7.5), enumeration specifiers (6.7.2.2), initialization
4164 6.7.1 Storage-class specifiers
4166 1 storage-class-specifier:
4173 2 At most, one storage-class specifier may be given in the declaration specifiers in a
4176 3 The typedef specifier is called a ''storage-class specifier'' for syntactic convenience
4177 only; it is discussed in 6.7.7. The meanings of the various linkages and storage durations
4178 were discussed in 6.2.2 and 6.2.4.
4179 4 A declaration of an identifier for an object with storage-class specifier register
4180 suggests that access to the object be as fast as possible. The extent to which such
4181 suggestions are effective is implementation-defined.103)
4182 5 The declaration of an identifier for a function that has block scope shall have no explicit
4183 storage-class specifier other than extern.
4187 102) See ''future language directions'' (6.11.5).
4188 103) The implementation may treat any register declaration simply as an auto declaration. However,
4189 whether or not addressable storage is actually used, the address of any part of an object declared with
4190 storage-class specifier register cannot be computed, either explicitly (by use of the unary &
4191 operator as discussed in 6.5.3.2) or implicitly (by converting an array name to a pointer as discussed in
4192 6.3.2.1). Thus, the only operator that can be applied to an array declared with storage-class specifier
4197 6 If an aggregate or union object is declared with a storage-class specifier other than
4198 typedef, the properties resulting from the storage-class specifier, except with respect to
4199 linkage, also apply to the members of the object, and so on recursively for any aggregate
4200 or union member objects.
4201 Forward references: type definitions (6.7.7).
4202 6.7.2 Type specifiers
4216 struct-or-union-specifier *
4220 2 At least one type specifier shall be given in the declaration specifiers in each declaration,
4221 and in the specifier-qualifier list in each struct declaration and type name. Each list of
4222 type specifiers shall be one of the following sets (delimited by commas, when there is
4223 more than one set on a line); the type specifiers may occur in any order, possibly
4224 intermixed with the other declaration specifiers.
4229 -- short, signed short, short int, or signed short int
4230 -- unsigned short, or unsigned short int
4231 -- int, signed, or signed int
4235 -- unsigned, or unsigned int
4236 -- long, signed long, long int, or signed long int
4237 -- unsigned long, or unsigned long int
4238 -- long long, signed long long, long long int, or
4239 signed long long int
4240 -- unsigned long long, or unsigned long long int
4247 -- long double _Complex
4248 -- struct or union specifier *
4251 3 The type specifier _Complex shall not be used if the implementation does not provide
4254 4 Specifiers for structures, unions, and enumerations are discussed in 6.7.2.1 through
4255 6.7.2.3. Declarations of typedef names are discussed in 6.7.7. The characteristics of the
4256 other types are discussed in 6.2.5.
4257 5 Each of the comma-separated sets designates the same type, except that for bit-fields, it is
4258 implementation-defined whether the specifier int designates the same type as signed
4259 int or the same type as unsigned int.
4260 Forward references: enumeration specifiers (6.7.2.2), structure and union specifiers
4261 (6.7.2.1), tags (6.7.2.3), type definitions (6.7.7).
4266 104) Freestanding implementations are not required to provide complex types. *
4270 6.7.2.1 Structure and union specifiers
4272 1 struct-or-union-specifier:
4273 struct-or-union identifieropt { struct-declaration-list }
4274 struct-or-union identifier
4278 struct-declaration-list:
4280 struct-declaration-list struct-declaration
4282 specifier-qualifier-list struct-declarator-list ;
4283 specifier-qualifier-list:
4284 type-specifier specifier-qualifier-listopt
4285 type-qualifier specifier-qualifier-listopt
4286 struct-declarator-list:
4288 struct-declarator-list , struct-declarator
4291 declaratoropt : constant-expression
4293 2 A structure or union shall not contain a member with incomplete or function type (hence,
4294 a structure shall not contain an instance of itself, but may contain a pointer to an instance
4295 of itself), except that the last member of a structure with more than one named member
4296 may have incomplete array type; such a structure (and any union containing, possibly
4297 recursively, a member that is such a structure) shall not be a member of a structure or an
4298 element of an array.
4299 3 The expression that specifies the width of a bit-field shall be an integer constant
4300 expression with a nonnegative value that does not exceed the width of an object of the
4301 type that would be specified were the colon and expression omitted. If the value is zero,
4302 the declaration shall have no declarator.
4303 4 A bit-field shall have a type that is a qualified or unqualified version of _Bool, signed
4304 int, unsigned int, or some other implementation-defined type.
4309 5 As discussed in 6.2.5, a structure is a type consisting of a sequence of members, whose
4310 storage is allocated in an ordered sequence, and a union is a type consisting of a sequence
4311 of members whose storage overlap.
4312 6 Structure and union specifiers have the same form. The keywords struct and union
4313 indicate that the type being specified is, respectively, a structure type or a union type.
4314 7 The presence of a struct-declaration-list in a struct-or-union-specifier declares a new type,
4315 within a translation unit. The struct-declaration-list is a sequence of declarations for the
4316 members of the structure or union. If the struct-declaration-list contains no named
4317 members, the behavior is undefined. The type is incomplete until after the } that
4318 terminates the list.
4319 8 A member of a structure or union may have any object type other than a variably
4320 modified type.105) In addition, a member may be declared to consist of a specified
4321 number of bits (including a sign bit, if any). Such a member is called a bit-field;106) its
4322 width is preceded by a colon.
4323 9 A bit-field is interpreted as a signed or unsigned integer type consisting of the specified
4324 number of bits.107) If the value 0 or 1 is stored into a nonzero-width bit-field of type
4325 _Bool, the value of the bit-field shall compare equal to the value stored.
4326 10 An implementation may allocate any addressable storage unit large enough to hold a bit-
4327 field. If enough space remains, a bit-field that immediately follows another bit-field in a
4328 structure shall be packed into adjacent bits of the same unit. If insufficient space remains,
4329 whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is
4330 implementation-defined. The order of allocation of bit-fields within a unit (high-order to
4331 low-order or low-order to high-order) is implementation-defined. The alignment of the
4332 addressable storage unit is unspecified.
4333 11 A bit-field declaration with no declarator, but only a colon and a width, indicates an
4334 unnamed bit-field.108) As a special case, a bit-field structure member with a width of 0
4335 indicates that no further bit-field is to be packed into the unit in which the previous bit-
4336 field, if any, was placed.
4339 105) A structure or union can not contain a member with a variably modified type because member names
4340 are not ordinary identifiers as defined in 6.2.3.
4341 106) The unary & (address-of) operator cannot be applied to a bit-field object; thus, there are no pointers to
4342 or arrays of bit-field objects.
4343 107) As specified in 6.7.2 above, if the actual type specifier used is int or a typedef-name defined as int,
4344 then it is implementation-defined whether the bit-field is signed or unsigned.
4345 108) An unnamed bit-field structure member is useful for padding to conform to externally imposed
4350 12 Each non-bit-field member of a structure or union object is aligned in an implementation-
4351 defined manner appropriate to its type.
4352 13 Within a structure object, the non-bit-field members and the units in which bit-fields
4353 reside have addresses that increase in the order in which they are declared. A pointer to a
4354 structure object, suitably converted, points to its initial member (or if that member is a
4355 bit-field, then to the unit in which it resides), and vice versa. There may be unnamed
4356 padding within a structure object, but not at its beginning.
4357 14 The size of a union is sufficient to contain the largest of its members. The value of at
4358 most one of the members can be stored in a union object at any time. A pointer to a
4359 union object, suitably converted, points to each of its members (or if a member is a bit-
4360 field, then to the unit in which it resides), and vice versa.
4361 15 There may be unnamed padding at the end of a structure or union.
4362 16 As a special case, the last element of a structure with more than one named member may
4363 have an incomplete array type; this is called a flexible array member. In most situations,
4364 the flexible array member is ignored. In particular, the size of the structure is as if the
4365 flexible array member were omitted except that it may have more trailing padding than
4366 the omission would imply. However, when a . (or ->) operator has a left operand that is
4367 (a pointer to) a structure with a flexible array member and the right operand names that
4368 member, it behaves as if that member were replaced with the longest array (with the same
4369 element type) that would not make the structure larger than the object being accessed; the
4370 offset of the array shall remain that of the flexible array member, even if this would differ
4371 from that of the replacement array. If this array would have no elements, it behaves as if
4372 it had one element but the behavior is undefined if any attempt is made to access that
4373 element or to generate a pointer one past it.
4374 17 EXAMPLE After the declaration:
4375 struct s { int n; double d[]; };
4376 the structure struct s has a flexible array member d. A typical way to use this is:
4377 int m = /* some value */;
4378 struct s *p = malloc(sizeof (struct s) + sizeof (double [m]));
4379 and assuming that the call to malloc succeeds, the object pointed to by p behaves, for most purposes, as if
4380 p had been declared as:
4381 struct { int n; double d[m]; } *p;
4382 (there are circumstances in which this equivalence is broken; in particular, the offsets of member d might
4384 18 Following the above declaration:
4388 struct s t1 = { 0 }; // valid
4389 struct s t2 = { 1, { 4.2 }}; // invalid
4391 t1.d[0] = 4.2; // might be undefined behavior
4392 The initialization of t2 is invalid (and violates a constraint) because struct s is treated as if it did not
4393 contain member d. The assignment to t1.d[0] is probably undefined behavior, but it is possible that
4394 sizeof (struct s) >= offsetof(struct s, d) + sizeof (double)
4395 in which case the assignment would be legitimate. Nevertheless, it cannot appear in strictly conforming
4397 19 After the further declaration:
4398 struct ss { int n; };
4400 sizeof (struct s) >= sizeof (struct ss)
4401 sizeof (struct s) >= offsetof(struct s, d)
4402 are always equal to 1.
4403 20 If sizeof (double) is 8, then after the following code is executed:
4406 s1 = malloc(sizeof (struct s) + 64);
4407 s2 = malloc(sizeof (struct s) + 46);
4408 and assuming that the calls to malloc succeed, the objects pointed to by s1 and s2 behave, for most
4409 purposes, as if the identifiers had been declared as:
4410 struct { int n; double d[8]; } *s1;
4411 struct { int n; double d[5]; } *s2;
4412 21 Following the further successful assignments:
4413 s1 = malloc(sizeof (struct s) + 10);
4414 s2 = malloc(sizeof (struct s) + 6);
4415 they then behave as if the declarations were:
4416 struct { int n; double d[1]; } *s1, *s2;
4419 dp = &(s1->d[0]); // valid
4421 dp = &(s2->d[0]); // valid
4422 *dp = 42; // undefined behavior
4425 only copies the member n; if any of the array elements are within the first sizeof (struct s) bytes
4426 of the structure, they might be copied or simply overwritten with indeterminate values.
4428 Forward references: tags (6.7.2.3).
4432 6.7.2.2 Enumeration specifiers
4435 enum identifieropt { enumerator-list }
4436 enum identifieropt { enumerator-list , }
4440 enumerator-list , enumerator
4442 enumeration-constant
4443 enumeration-constant = constant-expression
4445 2 The expression that defines the value of an enumeration constant shall be an integer
4446 constant expression that has a value representable as an int.
4448 3 The identifiers in an enumerator list are declared as constants that have type int and
4449 may appear wherever such are permitted.109) An enumerator with = defines its
4450 enumeration constant as the value of the constant expression. If the first enumerator has
4451 no =, the value of its enumeration constant is 0. Each subsequent enumerator with no =
4452 defines its enumeration constant as the value of the constant expression obtained by
4453 adding 1 to the value of the previous enumeration constant. (The use of enumerators with
4454 = may produce enumeration constants with values that duplicate other values in the same
4455 enumeration.) The enumerators of an enumeration are also known as its members.
4456 4 Each enumerated type shall be compatible with char, a signed integer type, or an
4457 unsigned integer type. The choice of type is implementation-defined,110) but shall be
4458 capable of representing the values of all the members of the enumeration. The
4459 enumerated type is incomplete until after the } that terminates the list of enumerator
4465 109) Thus, the identifiers of enumeration constants declared in the same scope shall all be distinct from
4466 each other and from other identifiers declared in ordinary declarators.
4467 110) An implementation may delay the choice of which integer type until all enumeration constants have
4472 5 EXAMPLE The following fragment:
4473 enum hue { chartreuse, burgundy, claret=20, winedark };
4477 if (*cp != burgundy)
4479 makes hue the tag of an enumeration, and then declares col as an object that has that type and cp as a
4480 pointer to an object that has that type. The enumerated values are in the set { 0, 1, 20, 21 }.
4482 Forward references: tags (6.7.2.3).
4485 1 A specific type shall have its content defined at most once.
4486 2 Where two declarations that use the same tag declare the same type, they shall both use
4487 the same choice of struct, union, or enum.
4488 3 A type specifier of the form
4490 without an enumerator list shall only appear after the type it specifies is complete.
4492 4 All declarations of structure, union, or enumerated types that have the same scope and
4493 use the same tag declare the same type. The type is incomplete111) until the closing brace
4494 of the list defining the content, and complete thereafter.
4495 5 Two declarations of structure, union, or enumerated types which are in different scopes or
4496 use different tags declare distinct types. Each declaration of a structure, union, or
4497 enumerated type which does not include a tag declares a distinct type.
4498 6 A type specifier of the form
4499 struct-or-union identifieropt { struct-declaration-list }
4501 enum identifier { enumerator-list }
4503 enum identifier { enumerator-list , }
4504 declares a structure, union, or enumerated type. The list defines the structure content,
4506 111) An incomplete type may only by used when the size of an object of that type is not needed. It is not
4507 needed, for example, when a typedef name is declared to be a specifier for a structure or union, or
4508 when a pointer to or a function returning a structure or union is being declared. (See incomplete types
4509 in 6.2.5.) The specification has to be complete before such a function is called or defined.
4513 union content, or enumeration content. If an identifier is provided,112) the type specifier
4514 also declares the identifier to be the tag of that type.
4515 7 A declaration of the form
4516 struct-or-union identifier ;
4517 specifies a structure or union type and declares the identifier as a tag of that type.113)
4518 8 If a type specifier of the form
4519 struct-or-union identifier
4520 occurs other than as part of one of the above forms, and no other declaration of the
4521 identifier as a tag is visible, then it declares an incomplete structure or union type, and
4522 declares the identifier as the tag of that type.113)
4523 9 If a type specifier of the form
4524 struct-or-union identifier
4527 occurs other than as part of one of the above forms, and a declaration of the identifier as a
4528 tag is visible, then it specifies the same type as that other declaration, and does not
4530 10 EXAMPLE 1 This mechanism allows declaration of a self-referential structure.
4533 struct tnode *left, *right;
4535 specifies a structure that contains an integer and two pointers to objects of the same type. Once this
4536 declaration has been given, the declaration
4537 struct tnode s, *sp;
4538 declares s to be an object of the given type and sp to be a pointer to an object of the given type. With
4539 these declarations, the expression sp->left refers to the left struct tnode pointer of the object to
4540 which sp points; the expression s.right->count designates the count member of the right struct
4541 tnode pointed to from s.
4542 11 The following alternative formulation uses the typedef mechanism:
4547 112) If there is no identifier, the type can, within the translation unit, only be referred to by the declaration
4548 of which it is a part. Of course, when the declaration is of a typedef name, subsequent declarations
4549 can make use of that typedef name to declare objects having the specified structure, union, or
4551 113) A similar construction with enum does not exist.
4555 typedef struct tnode TNODE;
4558 TNODE *left, *right;
4562 12 EXAMPLE 2 To illustrate the use of prior declaration of a tag to specify a pair of mutually referential
4563 structures, the declarations
4564 struct s1 { struct s2 *s2p; /* ... */ }; // D1
4565 struct s2 { struct s1 *s1p; /* ... */ }; // D2
4566 specify a pair of structures that contain pointers to each other. Note, however, that if s2 were already
4567 declared as a tag in an enclosing scope, the declaration D1 would refer to it, not to the tag s2 declared in
4568 D2. To eliminate this context sensitivity, the declaration
4570 may be inserted ahead of D1. This declares a new tag s2 in the inner scope; the declaration D2 then
4571 completes the specification of the new type.
4573 Forward references: declarators (6.7.5), array declarators (6.7.5.2), type definitions
4575 6.7.3 Type qualifiers
4582 2 Types other than pointer types derived from object or incomplete types shall not be
4585 3 The properties associated with qualified types are meaningful only for expressions that
4587 4 If the same qualifier appears more than once in the same specifier-qualifier-list, either
4588 directly or via one or more typedefs, the behavior is the same as if it appeared only
4594 114) The implementation may place a const object that is not volatile in a read-only region of
4595 storage. Moreover, the implementation need not allocate storage for such an object if its address is
4600 5 If an attempt is made to modify an object defined with a const-qualified type through use
4601 of an lvalue with non-const-qualified type, the behavior is undefined. If an attempt is
4602 made to refer to an object defined with a volatile-qualified type through use of an lvalue
4603 with non-volatile-qualified type, the behavior is undefined.115)
4604 6 An object that has volatile-qualified type may be modified in ways unknown to the
4605 implementation or have other unknown side effects. Therefore any expression referring
4606 to such an object shall be evaluated strictly according to the rules of the abstract machine,
4607 as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the
4608 object shall agree with that prescribed by the abstract machine, except as modified by the
4609 unknown factors mentioned previously.116) What constitutes an access to an object that
4610 has volatile-qualified type is implementation-defined.
4611 7 An object that is accessed through a restrict-qualified pointer has a special association
4612 with that pointer. This association, defined in 6.7.3.1 below, requires that all accesses to
4613 that object use, directly or indirectly, the value of that particular pointer.117) The intended
4614 use of the restrict qualifier (like the register storage class) is to promote
4615 optimization, and deleting all instances of the qualifier from all preprocessing translation
4616 units composing a conforming program does not change its meaning (i.e., observable
4618 8 If the specification of an array type includes any type qualifiers, the element type is so-
4619 qualified, not the array type. If the specification of a function type includes any type
4620 qualifiers, the behavior is undefined.118)
4621 9 For two qualified types to be compatible, both shall have the identically qualified version
4622 of a compatible type; the order of type qualifiers within a list of specifiers or qualifiers
4623 does not affect the specified type.
4624 10 EXAMPLE 1 An object declared
4625 extern const volatile int real_time_clock;
4626 may be modifiable by hardware, but cannot be assigned to, incremented, or decremented.
4631 115) This applies to those objects that behave as if they were defined with qualified types, even if they are
4632 never actually defined as objects in the program (such as an object at a memory-mapped input/output
4634 116) A volatile declaration may be used to describe an object corresponding to a memory-mapped
4635 input/output port or an object accessed by an asynchronously interrupting function. Actions on
4636 objects so declared shall not be ''optimized out'' by an implementation or reordered except as
4637 permitted by the rules for evaluating expressions.
4638 117) For example, a statement that assigns a value returned by malloc to a single pointer establishes this
4639 association between the allocated object and the pointer.
4640 118) Both of these can occur through the use of typedefs.
4644 11 EXAMPLE 2 The following declarations and expressions illustrate the behavior when type qualifiers
4645 modify an aggregate type:
4646 const struct s { int mem; } cs = { 1 };
4647 struct s ncs; // the object ncs is modifiable
4648 typedef int A[2][3];
4649 const A a = {{4, 5, 6}, {7, 8, 9}}; // array of array of const int
4653 cs = ncs; // violates modifiable lvalue constraint for =
4654 pi = &ncs.mem; // valid
4655 pi = &cs.mem; // violates type constraints for =
4656 pci = &cs.mem; // valid
4657 pi = a[0]; // invalid: a[0] has type ''const int *''
4659 6.7.3.1 Formal definition of restrict
4660 1 Let D be a declaration of an ordinary identifier that provides a means of designating an
4661 object P as a restrict-qualified pointer to type T.
4662 2 If D appears inside a block and does not have storage class extern, let B denote the
4663 block. If D appears in the list of parameter declarations of a function definition, let B
4664 denote the associated block. Otherwise, let B denote the block of main (or the block of
4665 whatever function is called at program startup in a freestanding environment).
4666 3 In what follows, a pointer expression E is said to be based on object P if (at some
4667 sequence point in the execution of B prior to the evaluation of E) modifying P to point to
4668 a copy of the array object into which it formerly pointed would change the value of E.119)
4669 Note that ''based'' is defined only for expressions with pointer types.
4670 4 During each execution of B, let L be any lvalue that has &L based on P. If L is used to
4671 access the value of the object X that it designates, and X is also modified (by any means),
4672 then the following requirements apply: T shall not be const-qualified. Every other lvalue
4673 used to access the value of X shall also have its address based on P. Every access that
4674 modifies X shall be considered also to modify P, for the purposes of this subclause. If P
4675 is assigned the value of a pointer expression E that is based on another restricted pointer
4676 object P2, associated with block B2, then either the execution of B2 shall begin before
4677 the execution of B, or the execution of B2 shall end prior to the assignment. If these
4678 requirements are not met, then the behavior is undefined.
4679 5 Here an execution of B means that portion of the execution of the program that would
4680 correspond to the lifetime of an object with scalar type and automatic storage duration
4682 119) In other words, E depends on the value of P itself rather than on the value of an object referenced
4683 indirectly through P. For example, if identifier p has type (int **restrict), then the pointer
4684 expressions p and p+1 are based on the restricted pointer object designated by p, but the pointer
4685 expressions *p and p[1] are not.
4690 6 A translator is free to ignore any or all aliasing implications of uses of restrict.
4691 7 EXAMPLE 1 The file scope declarations
4695 assert that if an object is accessed using one of a, b, or c, and that object is modified anywhere in the
4696 program, then it is never accessed using either of the other two.
4698 8 EXAMPLE 2 The function parameter declarations in the following example
4699 void f(int n, int * restrict p, int * restrict q)
4704 assert that, during each execution of the function, if an object is accessed through one of the pointer
4705 parameters, then it is not also accessed through the other.
4706 9 The benefit of the restrict qualifiers is that they enable a translator to make an effective dependence
4707 analysis of function f without examining any of the calls of f in the program. The cost is that the
4708 programmer has to examine all of those calls to ensure that none give undefined behavior. For example, the
4709 second call of f in g has undefined behavior because each of d[1] through d[49] is accessed through
4714 f(50, d + 50, d); // valid
4715 f(50, d + 1, d); // undefined behavior
4718 10 EXAMPLE 3 The function parameter declarations
4719 void h(int n, int * restrict p, int * restrict q, int * restrict r)
4722 for (i = 0; i < n; i++)
4725 illustrate how an unmodified object can be aliased through two restricted pointers. In particular, if a and b
4726 are disjoint arrays, a call of the form h(100, a, b, b) has defined behavior, because array b is not
4727 modified within function h.
4729 11 EXAMPLE 4 The rule limiting assignments between restricted pointers does not distinguish between a
4730 function call and an equivalent nested block. With one exception, only ''outer-to-inner'' assignments
4731 between restricted pointers declared in nested blocks have defined behavior.
4738 p1 = q1; // undefined behavior
4740 int * restrict p2 = p1; // valid
4741 int * restrict q2 = q1; // valid
4742 p1 = q2; // undefined behavior
4743 p2 = q2; // undefined behavior
4746 12 The one exception allows the value of a restricted pointer to be carried out of the block in which it (or, more
4747 precisely, the ordinary identifier used to designate it) is declared when that block finishes execution. For
4748 example, this permits new_vector to return a vector.
4749 typedef struct { int n; float * restrict v; } vector;
4750 vector new_vector(int n)
4754 t.v = malloc(n * sizeof (float));
4758 6.7.4 Function specifiers
4760 1 function-specifier:
4763 2 Function specifiers shall be used only in the declaration of an identifier for a function.
4764 3 An inline definition of a function with external linkage shall not contain a definition of a
4765 modifiable object with static storage duration, and shall not contain a reference to an
4766 identifier with internal linkage.
4767 4 In a hosted environment, the inline function specifier shall not appear in a declaration
4770 5 A function declared with an inline function specifier is an inline function. The
4771 function specifier may appear more than once; the behavior is the same as if it appeared
4772 only once. Making a function an inline function suggests that calls to the function be as
4773 fast as possible.120) The extent to which such suggestions are effective is
4774 implementation-defined.121)
4775 6 Any function with internal linkage can be an inline function. For a function with external
4776 linkage, the following restrictions apply: If a function is declared with an inline
4780 function specifier, then it shall also be defined in the same translation unit. If all of the
4781 file scope declarations for a function in a translation unit include the inline function
4782 specifier without extern, then the definition in that translation unit is an inline
4783 definition. An inline definition does not provide an external definition for the function,
4784 and does not forbid an external definition in another translation unit. An inline definition
4785 provides an alternative to an external definition, which a translator may use to implement
4786 any call to the function in the same translation unit. It is unspecified whether a call to the
4787 function uses the inline definition or the external definition.122)
4788 7 EXAMPLE The declaration of an inline function with external linkage can result in either an external
4789 definition, or a definition available for use only within the translation unit. A file scope declaration with
4790 extern creates an external definition. The following example shows an entire translation unit.
4791 inline double fahr(double t)
4793 return (9.0 * t) / 5.0 + 32.0;
4795 inline double cels(double t)
4797 return (5.0 * (t - 32.0)) / 9.0;
4799 extern double fahr(double); // creates an external definition
4800 double convert(int is_fahr, double temp)
4802 /* A translator may perform inline substitutions */
4803 return is_fahr ? cels(temp) : fahr(temp);
4805 8 Note that the definition of fahr is an external definition because fahr is also declared with extern, but
4806 the definition of cels is an inline definition. Because cels has external linkage and is referenced, an
4807 external definition has to appear in another translation unit (see 6.9); the inline definition and the external
4808 definition are distinct and either may be used for the call.
4810 Forward references: function definitions (6.9.1).
4813 120) By using, for example, an alternative to the usual function call mechanism, such as ''inline
4814 substitution''. Inline substitution is not textual substitution, nor does it create a new function.
4815 Therefore, for example, the expansion of a macro used within the body of the function uses the
4816 definition it had at the point the function body appears, and not where the function is called; and
4817 identifiers refer to the declarations in scope where the body occurs. Likewise, the function has a
4818 single address, regardless of the number of inline definitions that occur in addition to the external
4820 121) For example, an implementation might never perform inline substitution, or might only perform inline
4821 substitutions to calls in the scope of an inline declaration.
4822 122) Since an inline definition is distinct from the corresponding external definition and from any other
4823 corresponding inline definitions in other translation units, all corresponding objects with static storage
4824 duration are also distinct in each of the definitions.
4831 pointeropt direct-declarator
4835 direct-declarator [ type-qualifier-listopt assignment-expressionopt ]
4836 direct-declarator [ static type-qualifier-listopt assignment-expression ]
4837 direct-declarator [ type-qualifier-list static assignment-expression ]
4838 direct-declarator [ type-qualifier-listopt * ]
4839 direct-declarator ( parameter-type-list )
4840 direct-declarator ( identifier-listopt )
4842 * type-qualifier-listopt
4843 * type-qualifier-listopt pointer
4844 type-qualifier-list:
4846 type-qualifier-list type-qualifier
4847 parameter-type-list:
4849 parameter-list , ...
4851 parameter-declaration
4852 parameter-list , parameter-declaration
4853 parameter-declaration:
4854 declaration-specifiers declarator
4855 declaration-specifiers abstract-declaratoropt
4858 identifier-list , identifier
4860 2 Each declarator declares one identifier, and asserts that when an operand of the same
4861 form as the declarator appears in an expression, it designates a function or object with the
4862 scope, storage duration, and type indicated by the declaration specifiers.
4863 3 A full declarator is a declarator that is not part of another declarator. The end of a full
4864 declarator is a sequence point. If, in the nested sequence of declarators in a full
4868 declarator, there is a declarator specifying a variable length array type, the type specified
4869 by the full declarator is said to be variably modified. Furthermore, any type derived by
4870 declarator type derivation from a variably modified type is itself variably modified.
4871 4 In the following subclauses, consider a declaration
4873 where T contains the declaration specifiers that specify a type T (such as int) and D1 is
4874 a declarator that contains an identifier ident. The type specified for the identifier ident in
4875 the various forms of declarator is described inductively using this notation.
4876 5 If, in the declaration ''T D1'', D1 has the form
4878 then the type specified for ident is T .
4879 6 If, in the declaration ''T D1'', D1 has the form
4881 then ident has the type specified by the declaration ''T D''. Thus, a declarator in
4882 parentheses is identical to the unparenthesized declarator, but the binding of complicated
4883 declarators may be altered by parentheses.
4884 Implementation limits
4885 7 As discussed in 5.2.4.1, an implementation may limit the number of pointer, array, and
4886 function declarators that modify an arithmetic, structure, union, or incomplete type, either
4887 directly or via one or more typedefs.
4888 Forward references: array declarators (6.7.5.2), type definitions (6.7.7).
4889 6.7.5.1 Pointer declarators
4891 1 If, in the declaration ''T D1'', D1 has the form
4892 * type-qualifier-listopt D
4893 and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
4894 T '', then the type specified for ident is ''derived-declarator-type-list type-qualifier-list
4895 pointer to T ''. For each type qualifier in the list, ident is a so-qualified pointer.
4896 2 For two pointer types to be compatible, both shall be identically qualified and both shall
4897 be pointers to compatible types.
4898 3 EXAMPLE The following pair of declarations demonstrates the difference between a ''variable pointer
4899 to a constant value'' and a ''constant pointer to a variable value''.
4903 const int *ptr_to_constant;
4904 int *const constant_ptr;
4905 The contents of any object pointed to by ptr_to_constant shall not be modified through that pointer,
4906 but ptr_to_constant itself may be changed to point to another object. Similarly, the contents of the
4907 int pointed to by constant_ptr may be modified, but constant_ptr itself shall always point to the
4909 4 The declaration of the constant pointer constant_ptr may be clarified by including a definition for the
4910 type ''pointer to int''.
4911 typedef int *int_ptr;
4912 const int_ptr constant_ptr;
4913 declares constant_ptr as an object that has type ''const-qualified pointer to int''.
4915 6.7.5.2 Array declarators
4917 1 In addition to optional type qualifiers and the keyword static, the [ and ] may delimit
4918 an expression or *. If they delimit an expression (which specifies the size of an array), the
4919 expression shall have an integer type. If the expression is a constant expression, it shall
4920 have a value greater than zero. The element type shall not be an incomplete or function
4921 type. The optional type qualifiers and the keyword static shall appear only in a
4922 declaration of a function parameter with an array type, and then only in the outermost
4923 array type derivation.
4924 2 An ordinary identifier (as defined in 6.2.3) that has a variably modified type shall have
4925 either block scope and no linkage or function prototype scope. If an identifier is declared
4926 to be an object with static storage duration, it shall not have a variable length array type.
4928 3 If, in the declaration ''T D1'', D1 has one of the forms:
4929 D[ type-qualifier-listopt assignment-expressionopt ]
4930 D[ static type-qualifier-listopt assignment-expression ]
4931 D[ type-qualifier-list static assignment-expression ]
4932 D[ type-qualifier-listopt * ]
4933 and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
4934 T '', then the type specified for ident is ''derived-declarator-type-list array of T ''.123)
4935 (See 6.7.5.3 for the meaning of the optional type qualifiers and the keyword static.)
4936 4 If the size is not present, the array type is an incomplete type. If the size is * instead of
4937 being an expression, the array type is a variable length array type of unspecified size,
4938 which can only be used in declarations with function prototype scope;124) such arrays are
4939 nonetheless complete types. If the size is an integer constant expression and the element
4941 123) When several ''array of'' specifications are adjacent, a multidimensional array is declared.
4945 type has a known constant size, the array type is not a variable length array type;
4946 otherwise, the array type is a variable length array type.
4947 5 If the size is an expression that is not an integer constant expression: if it occurs in a
4948 declaration at function prototype scope, it is treated as if it were replaced by *; otherwise,
4949 each time it is evaluated it shall have a value greater than zero. The size of each instance
4950 of a variable length array type does not change during its lifetime. Where a size
4951 expression is part of the operand of a sizeof operator and changing the value of the
4952 size expression would not affect the result of the operator, it is unspecified whether or not
4953 the size expression is evaluated.
4954 6 For two array types to be compatible, both shall have compatible element types, and if
4955 both size specifiers are present, and are integer constant expressions, then both size
4956 specifiers shall have the same constant value. If the two array types are used in a context
4957 which requires them to be compatible, it is undefined behavior if the two size specifiers
4958 evaluate to unequal values.
4960 float fa[11], *afp[17];
4961 declares an array of float numbers and an array of pointers to float numbers.
4963 8 EXAMPLE 2 Note the distinction between the declarations
4966 The first declares x to be a pointer to int; the second declares y to be an array of int of unspecified size
4967 (an incomplete type), the storage for which is defined elsewhere.
4969 9 EXAMPLE 3 The following declarations demonstrate the compatibility rules for variably modified types.
4977 int (*r)[n][n][n+1];
4978 p = a; // invalid: not compatible because 4 != 6
4979 r = c; // compatible, but defined behavior only if
4980 // n == 6 and m == n+1
4986 124) Thus, * can be used only in function declarations that are not definitions (see 6.7.5.3).
4990 10 EXAMPLE 4 All declarations of variably modified (VM) types have to be at either block scope or
4991 function prototype scope. Array objects declared with the static or extern storage-class specifier
4992 cannot have a variable length array (VLA) type. However, an object declared with the static storage-
4993 class specifier can have a VM type (that is, a pointer to a VLA type). Finally, all identifiers declared with a
4994 VM type have to be ordinary identifiers and cannot, therefore, be members of structures or unions.
4996 int A[n]; // invalid: file scope VLA
4997 extern int (*p2)[n]; // invalid: file scope VM
4998 int B[100]; // valid: file scope but not VM
4999 void fvla(int m, int C[m][m]); // valid: VLA with prototype scope
5000 void fvla(int m, int C[m][m]) // valid: adjusted to auto pointer to VLA
5002 typedef int VLA[m][m]; // valid: block scope typedef VLA
5004 int (*y)[n]; // invalid: y not ordinary identifier
5005 int z[n]; // invalid: z not ordinary identifier
5007 int D[m]; // valid: auto VLA
5008 static int E[m]; // invalid: static block scope VLA
5009 extern int F[m]; // invalid: F has linkage and is VLA
5010 int (*s)[m]; // valid: auto pointer to VLA
5011 extern int (*r)[m]; // invalid: r has linkage and points to VLA
5012 static int (*q)[m] = &B; // valid: q is a static block pointer to VLA
5015 Forward references: function declarators (6.7.5.3), function definitions (6.9.1),
5016 initialization (6.7.8).
5017 6.7.5.3 Function declarators (including prototypes)
5019 1 A function declarator shall not specify a return type that is a function type or an array
5021 2 The only storage-class specifier that shall occur in a parameter declaration is register.
5022 3 An identifier list in a function declarator that is not part of a definition of that function
5024 4 After adjustment, the parameters in a parameter type list in a function declarator that is
5025 part of a definition of that function shall not have incomplete type.
5027 5 If, in the declaration ''T D1'', D1 has the form
5028 D( parameter-type-list )
5030 D( identifier-listopt )
5034 and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
5035 T '', then the type specified for ident is ''derived-declarator-type-list function returning
5037 6 A parameter type list specifies the types of, and may declare identifiers for, the
5038 parameters of the function.
5039 7 A declaration of a parameter as ''array of type'' shall be adjusted to ''qualified pointer to
5040 type'', where the type qualifiers (if any) are those specified within the [ and ] of the
5041 array type derivation. If the keyword static also appears within the [ and ] of the
5042 array type derivation, then for each call to the function, the value of the corresponding
5043 actual argument shall provide access to the first element of an array with at least as many
5044 elements as specified by the size expression.
5045 8 A declaration of a parameter as ''function returning type'' shall be adjusted to ''pointer to
5046 function returning type'', as in 6.3.2.1.
5047 9 If the list terminates with an ellipsis (, ...), no information about the number or types
5048 of the parameters after the comma is supplied.125)
5049 10 The special case of an unnamed parameter of type void as the only item in the list
5050 specifies that the function has no parameters.
5051 11 If, in a parameter declaration, an identifier can be treated either as a typedef name or as a
5052 parameter name, it shall be taken as a typedef name.
5053 12 If the function declarator is not part of a definition of that function, parameters may have
5054 incomplete type and may use the [*] notation in their sequences of declarator specifiers
5055 to specify variable length array types.
5056 13 The storage-class specifier in the declaration specifiers for a parameter declaration, if
5057 present, is ignored unless the declared parameter is one of the members of the parameter
5058 type list for a function definition.
5059 14 An identifier list declares only the identifiers of the parameters of the function. An empty
5060 list in a function declarator that is part of a definition of that function specifies that the
5061 function has no parameters. The empty list in a function declarator that is not part of a
5062 definition of that function specifies that no information about the number or types of the
5063 parameters is supplied.126)
5064 15 For two function types to be compatible, both shall specify compatible return types.127)
5067 125) The macros defined in the <stdarg.h> header (7.15) may be used to access arguments that
5068 correspond to the ellipsis.
5069 126) See ''future language directions'' (6.11.6).
5070 127) If both function types are ''old style'', parameter types are not compared.
5074 Moreover, the parameter type lists, if both are present, shall agree in the number of
5075 parameters and in use of the ellipsis terminator; corresponding parameters shall have
5076 compatible types. If one type has a parameter type list and the other type is specified by a
5077 function declarator that is not part of a function definition and that contains an empty
5078 identifier list, the parameter list shall not have an ellipsis terminator and the type of each
5079 parameter shall be compatible with the type that results from the application of the
5080 default argument promotions. If one type has a parameter type list and the other type is
5081 specified by a function definition that contains a (possibly empty) identifier list, both shall
5082 agree in the number of parameters, and the type of each prototype parameter shall be
5083 compatible with the type that results from the application of the default argument
5084 promotions to the type of the corresponding identifier. (In the determination of type
5085 compatibility and of a composite type, each parameter declared with function or array
5086 type is taken as having the adjusted type and each parameter declared with qualified type
5087 is taken as having the unqualified version of its declared type.)
5088 16 EXAMPLE 1 The declaration
5089 int f(void), *fip(), (*pfi)();
5090 declares a function f with no parameters returning an int, a function fip with no parameter specification
5091 returning a pointer to an int, and a pointer pfi to a function with no parameter specification returning an
5092 int. It is especially useful to compare the last two. The binding of *fip() is *(fip()), so that the
5093 declaration suggests, and the same construction in an expression requires, the calling of a function fip,
5094 and then using indirection through the pointer result to yield an int. In the declarator (*pfi)(), the
5095 extra parentheses are necessary to indicate that indirection through a pointer to a function yields a function
5096 designator, which is then used to call the function; it returns an int.
5097 17 If the declaration occurs outside of any function, the identifiers have file scope and external linkage. If the
5098 declaration occurs inside a function, the identifiers of the functions f and fip have block scope and either
5099 internal or external linkage (depending on what file scope declarations for these identifiers are visible), and
5100 the identifier of the pointer pfi has block scope and no linkage.
5102 18 EXAMPLE 2 The declaration
5103 int (*apfi[3])(int *x, int *y);
5104 declares an array apfi of three pointers to functions returning int. Each of these functions has two
5105 parameters that are pointers to int. The identifiers x and y are declared for descriptive purposes only and
5106 go out of scope at the end of the declaration of apfi.
5108 19 EXAMPLE 3 The declaration
5109 int (*fpfi(int (*)(long), int))(int, ...);
5110 declares a function fpfi that returns a pointer to a function returning an int. The function fpfi has two
5111 parameters: a pointer to a function returning an int (with one parameter of type long int), and an int.
5112 The pointer returned by fpfi points to a function that has one int parameter and accepts zero or more
5113 additional arguments of any type.
5117 20 EXAMPLE 4 The following prototype has a variably modified parameter.
5118 void addscalar(int n, int m,
5119 double a[n][n*m+300], double x);
5123 addscalar(4, 2, b, 2.17);
5126 void addscalar(int n, int m,
5127 double a[n][n*m+300], double x)
5129 for (int i = 0; i < n; i++)
5130 for (int j = 0, k = n*m+300; j < k; j++)
5131 // a is a pointer to a VLA with n*m+300 elements
5135 21 EXAMPLE 5 The following are all compatible function prototype declarators.
5136 double maximum(int n, int m, double a[n][m]);
5137 double maximum(int n, int m, double a[*][*]);
5138 double maximum(int n, int m, double a[ ][*]);
5139 double maximum(int n, int m, double a[ ][m]);
5141 void f(double (* restrict a)[5]);
5142 void f(double a[restrict][5]);
5143 void f(double a[restrict 3][5]);
5144 void f(double a[restrict static 3][5]);
5145 (Note that the last declaration also specifies that the argument corresponding to a in any call to f must be a
5146 non-null pointer to the first of at least three arrays of 5 doubles, which the others do not.)
5148 Forward references: function definitions (6.9.1), type names (6.7.6).
5155 specifier-qualifier-list abstract-declaratoropt
5156 abstract-declarator:
5158 pointeropt direct-abstract-declarator
5159 direct-abstract-declarator:
5160 ( abstract-declarator )
5161 direct-abstract-declaratoropt [ type-qualifier-listopt
5162 assignment-expressionopt ]
5163 direct-abstract-declaratoropt [ static type-qualifier-listopt
5164 assignment-expression ]
5165 direct-abstract-declaratoropt [ type-qualifier-list static
5166 assignment-expression ]
5167 direct-abstract-declaratoropt [ * ]
5168 direct-abstract-declaratoropt ( parameter-type-listopt )
5170 2 In several contexts, it is necessary to specify a type. This is accomplished using a type
5171 name, which is syntactically a declaration for a function or an object of that type that
5172 omits the identifier.128)
5173 3 EXAMPLE The constructions
5181 (h) int (*const [])(unsigned int, ...)
5182 name respectively the types (a) int, (b) pointer to int, (c) array of three pointers to int, (d) pointer to an
5183 array of three ints, (e) pointer to a variable length array of an unspecified number of ints, (f) function
5184 with no parameter specification returning a pointer to int, (g) pointer to function with no parameters
5185 returning an int, and (h) array of an unspecified number of constant pointers to functions, each with one
5186 parameter that has type unsigned int and an unspecified number of other parameters, returning an
5192 128) As indicated by the syntax, empty parentheses in a type name are interpreted as ''function with no
5193 parameter specification'', rather than redundant parentheses around the omitted identifier.
5197 6.7.7 Type definitions
5202 2 If a typedef name specifies a variably modified type then it shall have block scope.
5204 3 In a declaration whose storage-class specifier is typedef, each declarator defines an
5205 identifier to be a typedef name that denotes the type specified for the identifier in the way
5206 described in 6.7.5. Any array size expressions associated with variable length array
5207 declarators are evaluated each time the declaration of the typedef name is reached in the
5208 order of execution. A typedef declaration does not introduce a new type, only a
5209 synonym for the type so specified. That is, in the following declarations:
5210 typedef T type_ident;
5212 type_ident is defined as a typedef name with the type specified by the declaration
5213 specifiers in T (known as T ), and the identifier in D has the type ''derived-declarator-
5214 type-list T '' where the derived-declarator-type-list is specified by the declarators of D. A
5215 typedef name shares the same name space as other identifiers declared in ordinary
5218 typedef int MILES, KLICKSP();
5219 typedef struct { double hi, lo; } range;
5222 extern KLICKSP *metricp;
5225 are all valid declarations. The type of distance is int, that of metricp is ''pointer to function with no
5226 parameter specification returning int'', and that of x and z is the specified structure; zp is a pointer to
5227 such a structure. The object distance has a type compatible with any other int object.
5229 5 EXAMPLE 2 After the declarations
5230 typedef struct s1 { int x; } t1, *tp1;
5231 typedef struct s2 { int x; } t2, *tp2;
5232 type t1 and the type pointed to by tp1 are compatible. Type t1 is also compatible with type struct
5233 s1, but not compatible with the types struct s2, t2, the type pointed to by tp2, or int.
5237 6 EXAMPLE 3 The following obscure constructions
5238 typedef signed int t;
5245 declare a typedef name t with type signed int, a typedef name plain with type int, and a structure
5246 with three bit-field members, one named t that contains values in the range [0, 15], an unnamed const-
5247 qualified bit-field which (if it could be accessed) would contain values in either the range [-15, +15] or
5248 [-16, +15], and one named r that contains values in one of the ranges [0, 31], [-15, +15], or [-16, +15].
5249 (The choice of range is implementation-defined.) The first two bit-field declarations differ in that
5250 unsigned is a type specifier (which forces t to be the name of a structure member), while const is a
5251 type qualifier (which modifies t which is still visible as a typedef name). If these declarations are followed
5252 in an inner scope by
5255 then a function f is declared with type ''function returning signed int with one unnamed parameter
5256 with type pointer to function returning signed int with one unnamed parameter with type signed
5257 int'', and an identifier t with type long int.
5259 7 EXAMPLE 4 On the other hand, typedef names can be used to improve code readability. All three of the
5260 following declarations of the signal function specify exactly the same type, the first without making use
5261 of any typedef names.
5262 typedef void fv(int), (*pfv)(int);
5263 void (*signal(int, void (*)(int)))(int);
5264 fv *signal(int, fv *);
5265 pfv signal(int, pfv);
5267 8 EXAMPLE 5 If a typedef name denotes a variable length array type, the length of the array is fixed at the
5268 time the typedef name is defined, not each time it is used:
5271 typedef int B[n]; // B is n ints, n evaluated now
5273 B a; // a is n ints, n without += 1
5274 int b[n]; // a and b are different sizes
5275 for (int i = 1; i < n; i++)
5281 6.7.8 Initialization
5284 assignment-expression
5285 { initializer-list }
5286 { initializer-list , }
5288 designationopt initializer
5289 initializer-list , designationopt initializer
5294 designator-list designator
5296 [ constant-expression ]
5299 2 No initializer shall attempt to provide a value for an object not contained within the entity
5301 3 The type of the entity to be initialized shall be an array of unknown size or an object type
5302 that is not a variable length array type.
5303 4 All the expressions in an initializer for an object that has static storage duration shall be
5304 constant expressions or string literals.
5305 5 If the declaration of an identifier has block scope, and the identifier has external or
5306 internal linkage, the declaration shall have no initializer for the identifier.
5307 6 If a designator has the form
5308 [ constant-expression ]
5309 then the current object (defined below) shall have array type and the expression shall be
5310 an integer constant expression. If the array is of unknown size, any nonnegative value is
5312 7 If a designator has the form
5314 then the current object (defined below) shall have structure or union type and the
5315 identifier shall be the name of a member of that type.
5320 8 An initializer specifies the initial value stored in an object.
5321 9 Except where explicitly stated otherwise, for the purposes of this subclause unnamed
5322 members of objects of structure and union type do not participate in initialization.
5323 Unnamed members of structure objects have indeterminate value even after initialization.
5324 10 If an object that has automatic storage duration is not initialized explicitly, its value is
5325 indeterminate. If an object that has static storage duration is not initialized explicitly,
5327 -- if it has pointer type, it is initialized to a null pointer;
5328 -- if it has arithmetic type, it is initialized to (positive or unsigned) zero;
5329 -- if it is an aggregate, every member is initialized (recursively) according to these rules;
5330 -- if it is a union, the first named member is initialized (recursively) according to these
5332 11 The initializer for a scalar shall be a single expression, optionally enclosed in braces. The
5333 initial value of the object is that of the expression (after conversion); the same type
5334 constraints and conversions as for simple assignment apply, taking the type of the scalar
5335 to be the unqualified version of its declared type.
5336 12 The rest of this subclause deals with initializers for objects that have aggregate or union
5338 13 The initializer for a structure or union object that has automatic storage duration shall be
5339 either an initializer list as described below, or a single expression that has compatible
5340 structure or union type. In the latter case, the initial value of the object, including
5341 unnamed members, is that of the expression.
5342 14 An array of character type may be initialized by a character string literal, optionally
5343 enclosed in braces. Successive characters of the character string literal (including the
5344 terminating null character if there is room or if the array is of unknown size) initialize the
5345 elements of the array.
5346 15 An array with element type compatible with wchar_t may be initialized by a wide
5347 string literal, optionally enclosed in braces. Successive wide characters of the wide string
5348 literal (including the terminating null wide character if there is room or if the array is of
5349 unknown size) initialize the elements of the array.
5350 16 Otherwise, the initializer for an object that has aggregate or union type shall be a brace-
5351 enclosed list of initializers for the elements or named members.
5352 17 Each brace-enclosed initializer list has an associated current object. When no
5353 designations are present, subobjects of the current object are initialized in order according
5354 to the type of the current object: array elements in increasing subscript order, structure
5358 members in declaration order, and the first named member of a union.129) In contrast, a
5359 designation causes the following initializer to begin initialization of the subobject
5360 described by the designator. Initialization then continues forward in order, beginning
5361 with the next subobject after that described by the designator.130)
5362 18 Each designator list begins its description with the current object associated with the
5363 closest surrounding brace pair. Each item in the designator list (in order) specifies a
5364 particular member of its current object and changes the current object for the next
5365 designator (if any) to be that member.131) The current object that results at the end of the
5366 designator list is the subobject to be initialized by the following initializer.
5367 19 The initialization shall occur in initializer list order, each initializer provided for a
5368 particular subobject overriding any previously listed initializer for the same subobject;132)
5369 all subobjects that are not initialized explicitly shall be initialized implicitly the same as
5370 objects that have static storage duration.
5371 20 If the aggregate or union contains elements or members that are aggregates or unions,
5372 these rules apply recursively to the subaggregates or contained unions. If the initializer of
5373 a subaggregate or contained union begins with a left brace, the initializers enclosed by
5374 that brace and its matching right brace initialize the elements or members of the
5375 subaggregate or the contained union. Otherwise, only enough initializers from the list are
5376 taken to account for the elements or members of the subaggregate or the first member of
5377 the contained union; any remaining initializers are left to initialize the next element or
5378 member of the aggregate of which the current subaggregate or contained union is a part.
5379 21 If there are fewer initializers in a brace-enclosed list than there are elements or members
5380 of an aggregate, or fewer characters in a string literal used to initialize an array of known
5381 size than there are elements in the array, the remainder of the aggregate shall be
5382 initialized implicitly the same as objects that have static storage duration.
5383 22 If an array of unknown size is initialized, its size is determined by the largest indexed
5384 element with an explicit initializer. At the end of its initializer list, the array no longer
5385 has incomplete type.
5389 129) If the initializer list for a subaggregate or contained union does not begin with a left brace, its
5390 subobjects are initialized as usual, but the subaggregate or contained union does not become the
5391 current object: current objects are associated only with brace-enclosed initializer lists.
5392 130) After a union member is initialized, the next object is not the next member of the union; instead, it is
5393 the next subobject of an object containing the union.
5394 131) Thus, a designator can only specify a strict subobject of the aggregate or union that is associated with
5395 the surrounding brace pair. Note, too, that each separate designator list is independent.
5396 132) Any initializer for the subobject which is overridden and so not used to initialize that subobject might
5397 not be evaluated at all.
5401 23 The order in which any side effects occur among the initialization list expressions is
5403 24 EXAMPLE 1 Provided that <complex.h> has been #included, the declarations
5405 double complex c = 5 + 3 * I;
5406 define and initialize i with the value 3 and c with the value 5.0 + i3.0.
5408 25 EXAMPLE 2 The declaration
5409 int x[] = { 1, 3, 5 };
5410 defines and initializes x as a one-dimensional array object that has three elements, as no size was specified
5411 and there are three initializers.
5413 26 EXAMPLE 3 The declaration
5419 is a definition with a fully bracketed initialization: 1, 3, and 5 initialize the first row of y (the array object
5420 y[0]), namely y[0][0], y[0][1], and y[0][2]. Likewise the next two lines initialize y[1] and
5421 y[2]. The initializer ends early, so y[3] is initialized with zeros. Precisely the same effect could have
5424 1, 3, 5, 2, 4, 6, 3, 5, 7
5426 The initializer for y[0] does not begin with a left brace, so three items from the list are used. Likewise the
5427 next three are taken successively for y[1] and y[2].
5429 27 EXAMPLE 4 The declaration
5431 { 1 }, { 2 }, { 3 }, { 4 }
5433 initializes the first column of z as specified and initializes the rest with zeros.
5435 28 EXAMPLE 5 The declaration
5436 struct { int a[3], b; } w[] = { { 1 }, 2 };
5437 is a definition with an inconsistently bracketed initialization. It defines an array with two element
5438 structures: w[0].a[0] is 1 and w[1].a[0] is 2; all the other elements are zero.
5443 133) In particular, the evaluation order need not be the same as the order of subobject initialization.
5447 29 EXAMPLE 6 The declaration
5448 short q[4][3][2] = {
5453 contains an incompletely but consistently bracketed initialization. It defines a three-dimensional array
5454 object: q[0][0][0] is 1, q[1][0][0] is 2, q[1][0][1] is 3, and 4, 5, and 6 initialize
5455 q[2][0][0], q[2][0][1], and q[2][1][0], respectively; all the rest are zero. The initializer for
5456 q[0][0] does not begin with a left brace, so up to six items from the current list may be used. There is
5457 only one, so the values for the remaining five elements are initialized with zero. Likewise, the initializers
5458 for q[1][0] and q[2][0] do not begin with a left brace, so each uses up to six items, initializing their
5459 respective two-dimensional subaggregates. If there had been more than six items in any of the lists, a
5460 diagnostic message would have been issued. The same initialization result could have been achieved by:
5461 short q[4][3][2] = {
5467 short q[4][3][2] = {
5479 in a fully bracketed form.
5480 30 Note that the fully bracketed and minimally bracketed forms of initialization are, in general, less likely to
5483 31 EXAMPLE 7 One form of initialization that completes array types involves typedef names. Given the
5485 typedef int A[]; // OK - declared with block scope
5487 A a = { 1, 2 }, b = { 3, 4, 5 };
5489 int a[] = { 1, 2 }, b[] = { 3, 4, 5 };
5490 due to the rules for incomplete types.
5494 32 EXAMPLE 8 The declaration
5495 char s[] = "abc", t[3] = "abc";
5496 defines ''plain'' char array objects s and t whose elements are initialized with character string literals.
5497 This declaration is identical to
5498 char s[] = { 'a', 'b', 'c', '\0' },
5499 t[] = { 'a', 'b', 'c' };
5500 The contents of the arrays are modifiable. On the other hand, the declaration
5502 defines p with type ''pointer to char'' and initializes it to point to an object with type ''array of char''
5503 with length 4 whose elements are initialized with a character string literal. If an attempt is made to use p to
5504 modify the contents of the array, the behavior is undefined.
5506 33 EXAMPLE 9 Arrays can be initialized to correspond to the elements of an enumeration by using
5508 enum { member_one, member_two };
5509 const char *nm[] = {
5510 [member_two] = "member two",
5511 [member_one] = "member one",
5514 34 EXAMPLE 10 Structure members can be initialized to nonzero values without depending on their order:
5515 div_t answer = { .quot = 2, .rem = -1 };
5517 35 EXAMPLE 11 Designators can be used to provide explicit initialization when unadorned initializer lists
5518 might be misunderstood:
5519 struct { int a[3], b; } w[] =
5520 { [0].a = {1}, [1].a[0] = 2 };
5522 36 EXAMPLE 12 Space can be ''allocated'' from both ends of an array by using a single designator:
5524 1, 3, 5, 7, 9, [MAX-5] = 8, 6, 4, 2, 0
5526 37 In the above, if MAX is greater than ten, there will be some zero-valued elements in the middle; if it is less
5527 than ten, some of the values provided by the first five initializers will be overridden by the second five.
5529 38 EXAMPLE 13 Any member of a union can be initialized:
5530 union { /* ... */ } u = { .any_member = 42 };
5532 Forward references: common definitions <stddef.h> (7.17).
5536 6.8 Statements and blocks
5541 expression-statement
5546 2 A statement specifies an action to be performed. Except as indicated, statements are
5547 executed in sequence.
5548 3 A block allows a set of declarations and statements to be grouped into one syntactic unit.
5549 The initializers of objects that have automatic storage duration, and the variable length
5550 array declarators of ordinary identifiers with block scope, are evaluated and the values are
5551 stored in the objects (including storing an indeterminate value in objects without an
5552 initializer) each time the declaration is reached in the order of execution, as if it were a
5553 statement, and within each declaration in the order that declarators appear.
5554 4 A full expression is an expression that is not part of another expression or of a declarator.
5555 Each of the following is a full expression: an initializer; the expression in an expression
5556 statement; the controlling expression of a selection statement (if or switch); the
5557 controlling expression of a while or do statement; each of the (optional) expressions of
5558 a for statement; the (optional) expression in a return statement. The end of a full
5559 expression is a sequence point.
5560 Forward references: expression and null statements (6.8.3), selection statements
5561 (6.8.4), iteration statements (6.8.5), the return statement (6.8.6.4).
5562 6.8.1 Labeled statements
5564 1 labeled-statement:
5565 identifier : statement
5566 case constant-expression : statement
5569 2 A case or default label shall appear only in a switch statement. Further
5570 constraints on such labels are discussed under the switch statement.
5574 3 Label names shall be unique within a function.
5576 4 Any statement may be preceded by a prefix that declares an identifier as a label name.
5577 Labels in themselves do not alter the flow of control, which continues unimpeded across
5579 Forward references: the goto statement (6.8.6.1), the switch statement (6.8.4.2).
5580 6.8.2 Compound statement
5582 1 compound-statement:
5583 { block-item-listopt }
5586 block-item-list block-item
5591 2 A compound statement is a block.
5592 6.8.3 Expression and null statements
5594 1 expression-statement:
5597 2 The expression in an expression statement is evaluated as a void expression for its side
5599 3 A null statement (consisting of just a semicolon) performs no operations.
5600 4 EXAMPLE 1 If a function call is evaluated as an expression statement for its side effects only, the
5601 discarding of its value may be made explicit by converting the expression to a void expression by means of
5609 134) Such as assignments, and function calls which have side effects.
5613 5 EXAMPLE 2 In the program fragment
5616 while (*s++ != '\0')
5618 a null statement is used to supply an empty loop body to the iteration statement.
5620 6 EXAMPLE 3 A null statement may also be used to carry a label just before the closing } of a compound
5634 Forward references: iteration statements (6.8.5).
5635 6.8.4 Selection statements
5637 1 selection-statement:
5638 if ( expression ) statement
5639 if ( expression ) statement else statement
5640 switch ( expression ) statement
5642 2 A selection statement selects among a set of statements depending on the value of a
5643 controlling expression.
5644 3 A selection statement is a block whose scope is a strict subset of the scope of its
5645 enclosing block. Each associated substatement is also a block whose scope is a strict
5646 subset of the scope of the selection statement.
5647 6.8.4.1 The if statement
5649 1 The controlling expression of an if statement shall have scalar type.
5651 2 In both forms, the first substatement is executed if the expression compares unequal to 0.
5652 In the else form, the second substatement is executed if the expression compares equal
5656 to 0. If the first substatement is reached via a label, the second substatement is not
5658 3 An else is associated with the lexically nearest preceding if that is allowed by the
5660 6.8.4.2 The switch statement
5662 1 The controlling expression of a switch statement shall have integer type.
5663 2 If a switch statement has an associated case or default label within the scope of an
5664 identifier with a variably modified type, the entire switch statement shall be within the
5665 scope of that identifier.135)
5666 3 The expression of each case label shall be an integer constant expression and no two of
5667 the case constant expressions in the same switch statement shall have the same value
5668 after conversion. There may be at most one default label in a switch statement.
5669 (Any enclosed switch statement may have a default label or case constant
5670 expressions with values that duplicate case constant expressions in the enclosing
5673 4 A switch statement causes control to jump to, into, or past the statement that is the
5674 switch body, depending on the value of a controlling expression, and on the presence of a
5675 default label and the values of any case labels on or in the switch body. A case or
5676 default label is accessible only within the closest enclosing switch statement.
5677 5 The integer promotions are performed on the controlling expression. The constant
5678 expression in each case label is converted to the promoted type of the controlling
5679 expression. If a converted value matches that of the promoted controlling expression,
5680 control jumps to the statement following the matched case label. Otherwise, if there is
5681 a default label, control jumps to the labeled statement. If no converted case constant
5682 expression matches and there is no default label, no part of the switch body is
5684 Implementation limits
5685 6 As discussed in 5.2.4.1, the implementation may limit the number of case values in a
5691 135) That is, the declaration either precedes the switch statement, or it follows the last case or
5692 default label associated with the switch that is in the block containing the declaration.
5696 7 EXAMPLE In the artificial program fragment
5703 /* falls through into default code */
5707 the object whose identifier is i exists with automatic storage duration (within the block) but is never
5708 initialized, and thus if the controlling expression has a nonzero value, the call to the printf function will
5709 access an indeterminate value. Similarly, the call to the function f cannot be reached.
5711 6.8.5 Iteration statements
5713 1 iteration-statement:
5714 while ( expression ) statement
5715 do statement while ( expression ) ;
5716 for ( expressionopt ; expressionopt ; expressionopt ) statement
5717 for ( declaration expressionopt ; expressionopt ) statement
5719 2 The controlling expression of an iteration statement shall have scalar type.
5720 3 The declaration part of a for statement shall only declare identifiers for objects having
5721 storage class auto or register.
5723 4 An iteration statement causes a statement called the loop body to be executed repeatedly
5724 until the controlling expression compares equal to 0. The repetition occurs regardless of
5725 whether the loop body is entered from the iteration statement or by a jump.136)
5726 5 An iteration statement is a block whose scope is a strict subset of the scope of its
5727 enclosing block. The loop body is also a block whose scope is a strict subset of the scope
5728 of the iteration statement.
5733 136) Code jumped over is not executed. In particular, the controlling expression of a for or while
5734 statement is not evaluated before entering the loop body, nor is clause-1 of a for statement.
5738 6.8.5.1 The while statement
5739 1 The evaluation of the controlling expression takes place before each execution of the loop
5741 6.8.5.2 The do statement
5742 1 The evaluation of the controlling expression takes place after each execution of the loop
5744 6.8.5.3 The for statement
5746 for ( clause-1 ; expression-2 ; expression-3 ) statement
5747 behaves as follows: The expression expression-2 is the controlling expression that is
5748 evaluated before each execution of the loop body. The expression expression-3 is
5749 evaluated as a void expression after each execution of the loop body. If clause-1 is a
5750 declaration, the scope of any identifiers it declares is the remainder of the declaration and
5751 the entire loop, including the other two expressions; it is reached in the order of execution
5752 before the first evaluation of the controlling expression. If clause-1 is an expression, it is
5753 evaluated as a void expression before the first evaluation of the controlling expression.137)
5754 2 Both clause-1 and expression-3 can be omitted. An omitted expression-2 is replaced by a
5756 6.8.6 Jump statements
5762 return expressionopt ;
5764 2 A jump statement causes an unconditional jump to another place.
5769 137) Thus, clause-1 specifies initialization for the loop, possibly declaring one or more variables for use in
5770 the loop; the controlling expression, expression-2, specifies an evaluation made before each iteration,
5771 such that execution of the loop continues until the expression compares equal to 0; and expression-3
5772 specifies an operation (such as incrementing) that is performed after each iteration.
5776 6.8.6.1 The goto statement
5778 1 The identifier in a goto statement shall name a label located somewhere in the enclosing
5779 function. A goto statement shall not jump from outside the scope of an identifier having
5780 a variably modified type to inside the scope of that identifier.
5782 2 A goto statement causes an unconditional jump to the statement prefixed by the named
5783 label in the enclosing function.
5784 3 EXAMPLE 1 It is sometimes convenient to jump into the middle of a complicated set of statements. The
5785 following outline presents one possible approach to a problem based on these three assumptions:
5786 1. The general initialization code accesses objects only visible to the current function.
5787 2. The general initialization code is too large to warrant duplication.
5788 3. The code to determine the next operation is at the head of the loop. (To allow it to be reached by
5789 continue statements, for example.)
5793 // determine next operation
5795 if (need to reinitialize) {
5796 // reinitialize-only code
5799 // general initialization code
5803 // handle other operations
5809 4 EXAMPLE 2 A goto statement is not allowed to jump past any declarations of objects with variably
5810 modified types. A jump within the scope, however, is permitted.
5811 goto lab3; // invalid: going INTO scope of VLA.
5817 goto lab4; // valid: going WITHIN scope of VLA.
5822 goto lab4; // invalid: going INTO scope of VLA.
5824 6.8.6.2 The continue statement
5826 1 A continue statement shall appear only in or as a loop body.
5828 2 A continue statement causes a jump to the loop-continuation portion of the smallest
5829 enclosing iteration statement; that is, to the end of the loop body. More precisely, in each
5831 while (/* ... */) { do { for (/* ... */) {
5832 /* ... */ /* ... */ /* ... */
5833 continue; continue; continue;
5834 /* ... */ /* ... */ /* ... */
5835 contin: ; contin: ; contin: ;
5836 } } while (/* ... */); }
5837 unless the continue statement shown is in an enclosed iteration statement (in which
5838 case it is interpreted within that statement), it is equivalent to goto contin;.138)
5839 6.8.6.3 The break statement
5841 1 A break statement shall appear only in or as a switch body or loop body.
5843 2 A break statement terminates execution of the smallest enclosing switch or iteration
5848 138) Following the contin: label is a null statement.
5852 6.8.6.4 The return statement
5854 1 A return statement with an expression shall not appear in a function whose return type
5855 is void. A return statement without an expression shall only appear in a function
5856 whose return type is void.
5858 2 A return statement terminates execution of the current function and returns control to
5859 its caller. A function may have any number of return statements.
5860 3 If a return statement with an expression is executed, the value of the expression is
5861 returned to the caller as the value of the function call expression. If the expression has a
5862 type different from the return type of the function in which it appears, the value is
5863 converted as if by assignment to an object having the return type of the function.139)
5865 struct s { double i; } f(void);
5882 there is no undefined behavior, although there would be if the assignment were done directly (without using
5883 a function call to fetch the value).
5888 139) The return statement is not an assignment. The overlap restriction of subclause 6.5.16.1 does not
5889 apply to the case of function return. The representation of floating-point values may have wider range
5890 or precision and is determined by FLT_EVAL_METHOD. A cast may be used to remove this extra
5891 range and precision.
5895 6.9 External definitions
5898 external-declaration
5899 translation-unit external-declaration
5900 external-declaration:
5904 2 The storage-class specifiers auto and register shall not appear in the declaration
5905 specifiers in an external declaration.
5906 3 There shall be no more than one external definition for each identifier declared with
5907 internal linkage in a translation unit. Moreover, if an identifier declared with internal
5908 linkage is used in an expression (other than as a part of the operand of a sizeof
5909 operator whose result is an integer constant), there shall be exactly one external definition
5910 for the identifier in the translation unit.
5912 4 As discussed in 5.1.1.1, the unit of program text after preprocessing is a translation unit,
5913 which consists of a sequence of external declarations. These are described as ''external''
5914 because they appear outside any function (and hence have file scope). As discussed in
5915 6.7, a declaration that also causes storage to be reserved for an object or a function named
5916 by the identifier is a definition.
5917 5 An external definition is an external declaration that is also a definition of a function
5918 (other than an inline definition) or an object. If an identifier declared with external
5919 linkage is used in an expression (other than as part of the operand of a sizeof operator
5920 whose result is an integer constant), somewhere in the entire program there shall be
5921 exactly one external definition for the identifier; otherwise, there shall be no more than
5927 140) Thus, if an identifier declared with external linkage is not used in an expression, there need be no
5928 external definition for it.
5932 6.9.1 Function definitions
5934 1 function-definition:
5935 declaration-specifiers declarator declaration-listopt compound-statement
5938 declaration-list declaration
5940 2 The identifier declared in a function definition (which is the name of the function) shall
5941 have a function type, as specified by the declarator portion of the function definition.141)
5942 3 The return type of a function shall be void or an object type other than array type.
5943 4 The storage-class specifier, if any, in the declaration specifiers shall be either extern or
5945 5 If the declarator includes a parameter type list, the declaration of each parameter shall
5946 include an identifier, except for the special case of a parameter list consisting of a single
5947 parameter of type void, in which case there shall not be an identifier. No declaration list
5949 6 If the declarator includes an identifier list, each declaration in the declaration list shall
5950 have at least one declarator, those declarators shall declare only identifiers from the
5951 identifier list, and every identifier in the identifier list shall be declared. An identifier
5952 declared as a typedef name shall not be redeclared as a parameter. The declarations in the
5953 declaration list shall contain no storage-class specifier other than register and no
5959 141) The intent is that the type category in a function definition cannot be inherited from a typedef:
5960 typedef int F(void); // type F is ''function with no parameters
5962 F f, g; // f and g both have type compatible with F
5963 F f { /* ... */ } // WRONG: syntax/constraint error
5964 F g() { /* ... */ } // WRONG: declares that g returns a function
5965 int f(void) { /* ... */ } // RIGHT: f has type compatible with F
5966 int g() { /* ... */ } // RIGHT: g has type compatible with F
5967 F *e(void) { /* ... */ } // e returns a pointer to a function
5968 F *((e))(void) { /* ... */ } // same: parentheses irrelevant
5969 int (*fp)(void); // fp points to a function that has type F
5970 F *Fp; // Fp points to a function that has type F
5975 7 The declarator in a function definition specifies the name of the function being defined
5976 and the identifiers of its parameters. If the declarator includes a parameter type list, the
5977 list also specifies the types of all the parameters; such a declarator also serves as a
5978 function prototype for later calls to the same function in the same translation unit. If the
5979 declarator includes an identifier list,142) the types of the parameters shall be declared in a
5980 following declaration list. In either case, the type of each parameter is adjusted as
5981 described in 6.7.5.3 for a parameter type list; the resulting type shall be an object type.
5982 8 If a function that accepts a variable number of arguments is defined without a parameter
5983 type list that ends with the ellipsis notation, the behavior is undefined.
5984 9 Each parameter has automatic storage duration. Its identifier is an lvalue, which is in
5985 effect declared at the head of the compound statement that constitutes the function body
5986 (and therefore cannot be redeclared in the function body except in an enclosed block).
5987 The layout of the storage for parameters is unspecified.
5988 10 On entry to the function, the size expressions of each variably modified parameter are
5989 evaluated and the value of each argument expression is converted to the type of the
5990 corresponding parameter as if by assignment. (Array expressions and function
5991 designators as arguments were converted to pointers before the call.)
5992 11 After all parameters have been assigned, the compound statement that constitutes the
5993 body of the function definition is executed.
5994 12 If the } that terminates a function is reached, and the value of the function call is used by
5995 the caller, the behavior is undefined.
5996 13 EXAMPLE 1 In the following:
5997 extern int max(int a, int b)
5999 return a > b ? a : b;
6001 extern is the storage-class specifier and int is the type specifier; max(int a, int b) is the
6002 function declarator; and
6003 { return a > b ? a : b; }
6004 is the function body. The following similar definition uses the identifier-list form for the parameter
6010 142) See ''future language directions'' (6.11.7).
6014 extern int max(a, b)
6017 return a > b ? a : b;
6019 Here int a, b; is the declaration list for the parameters. The difference between these two definitions is
6020 that the first form acts as a prototype declaration that forces conversion of the arguments of subsequent calls
6021 to the function, whereas the second form does not.
6023 14 EXAMPLE 2 To pass one function to another, one might say
6027 Then the definition of g might read
6028 void g(int (*funcp)(void))
6031 (*funcp)(); /* or funcp(); ... */
6034 void g(int func(void))
6037 func(); /* or (*func)(); ... */
6040 6.9.2 External object definitions
6042 1 If the declaration of an identifier for an object has file scope and an initializer, the
6043 declaration is an external definition for the identifier.
6044 2 A declaration of an identifier for an object that has file scope without an initializer, and
6045 without a storage-class specifier or with the storage-class specifier static, constitutes a
6046 tentative definition. If a translation unit contains one or more tentative definitions for an
6047 identifier, and the translation unit contains no external definition for that identifier, then
6048 the behavior is exactly as if the translation unit contains a file scope declaration of that
6049 identifier, with the composite type as of the end of the translation unit, with an initializer
6051 3 If the declaration of an identifier for an object is a tentative definition and has internal
6052 linkage, the declared type shall not be an incomplete type.
6057 int i1 = 1; // definition, external linkage
6058 static int i2 = 2; // definition, internal linkage
6059 extern int i3 = 3; // definition, external linkage
6060 int i4; // tentative definition, external linkage
6061 static int i5; // tentative definition, internal linkage
6062 int i1; // valid tentative definition, refers to previous
6063 int i2; // 6.2.2 renders undefined, linkage disagreement
6064 int i3; // valid tentative definition, refers to previous
6065 int i4; // valid tentative definition, refers to previous
6066 int i5; // 6.2.2 renders undefined, linkage disagreement
6067 extern int i1; // refers to previous, whose linkage is external
6068 extern int i2; // refers to previous, whose linkage is internal
6069 extern int i3; // refers to previous, whose linkage is external
6070 extern int i4; // refers to previous, whose linkage is external
6071 extern int i5; // refers to previous, whose linkage is internal
6073 5 EXAMPLE 2 If at the end of the translation unit containing
6075 the array i still has incomplete type, the implicit initializer causes it to have one element, which is set to
6076 zero on program startup.
6080 6.10 Preprocessing directives
6082 1 preprocessing-file:
6093 if-group elif-groupsopt else-groupopt endif-line
6095 # if constant-expression new-line groupopt
6096 # ifdef identifier new-line groupopt
6097 # ifndef identifier new-line groupopt
6100 elif-groups elif-group
6102 # elif constant-expression new-line groupopt
6104 # else new-line groupopt
6111 # include pp-tokens new-line
6112 # define identifier replacement-list new-line
6113 # define identifier lparen identifier-listopt )
6114 replacement-list new-line
6115 # define identifier lparen ... ) replacement-list new-line
6116 # define identifier lparen identifier-list , ... )
6117 replacement-list new-line
6118 # undef identifier new-line
6119 # line pp-tokens new-line
6120 # error pp-tokensopt new-line
6121 # pragma pp-tokensopt new-line
6124 pp-tokensopt new-line
6128 a ( character not immediately preceded by white-space
6133 pp-tokens preprocessing-token
6135 the new-line character
6137 2 A preprocessing directive consists of a sequence of preprocessing tokens that satisfies the
6138 following constraints: The first token in the sequence is a # preprocessing token that (at
6139 the start of translation phase 4) is either the first character in the source file (optionally
6140 after white space containing no new-line characters) or that follows white space
6141 containing at least one new-line character. The last token in the sequence is the first new-
6142 line character that follows the first token in the sequence.143) A new-line character ends
6143 the preprocessing directive even if it occurs within what would otherwise be an
6145 143) Thus, preprocessing directives are commonly called ''lines''. These ''lines'' have no other syntactic
6146 significance, as all white space is equivalent except in certain situations during preprocessing (see the
6147 # character string literal creation operator in 6.10.3.2, for example).
6151 invocation of a function-like macro.
6152 3 A text line shall not begin with a # preprocessing token. A non-directive shall not begin
6153 with any of the directive names appearing in the syntax.
6154 4 When in a group that is skipped (6.10.1), the directive syntax is relaxed to allow any
6155 sequence of preprocessing tokens to occur between the directive name and the following
6158 5 The only white-space characters that shall appear between preprocessing tokens within a
6159 preprocessing directive (from just after the introducing # preprocessing token through
6160 just before the terminating new-line character) are space and horizontal-tab (including
6161 spaces that have replaced comments or possibly other white-space characters in
6162 translation phase 3).
6164 6 The implementation can process and skip sections of source files conditionally, include
6165 other source files, and replace macros. These capabilities are called preprocessing,
6166 because conceptually they occur before translation of the resulting translation unit.
6167 7 The preprocessing tokens within a preprocessing directive are not subject to macro
6168 expansion unless otherwise stated.
6171 EMPTY # include <file.h>
6172 the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not
6173 begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been
6176 6.10.1 Conditional inclusion
6178 1 The expression that controls conditional inclusion shall be an integer constant expression
6179 except that: it shall not contain a cast; identifiers (including those lexically identical to
6180 keywords) are interpreted as described below;144) and it may contain unary operator
6181 expressions of the form
6186 144) Because the controlling constant expression is evaluated during translation phase 4, all identifiers
6187 either are or are not macro names -- there simply are no keywords, enumeration constants, etc.
6193 defined ( identifier )
6194 which evaluate to 1 if the identifier is currently defined as a macro name (that is, if it is
6195 predefined or if it has been the subject of a #define preprocessing directive without an
6196 intervening #undef directive with the same subject identifier), 0 if it is not.
6197 2 Each preprocessing token that remains (in the list of preprocessing tokens that will
6198 become the controlling expression) after all macro replacements have occurred shall be in
6199 the lexical form of a token (6.4).
6201 3 Preprocessing directives of the forms
6202 # if constant-expression new-line groupopt
6203 # elif constant-expression new-line groupopt
6204 check whether the controlling constant expression evaluates to nonzero.
6205 4 Prior to evaluation, macro invocations in the list of preprocessing tokens that will become
6206 the controlling constant expression are replaced (except for those macro names modified
6207 by the defined unary operator), just as in normal text. If the token defined is
6208 generated as a result of this replacement process or use of the defined unary operator
6209 does not match one of the two specified forms prior to macro replacement, the behavior is
6210 undefined. After all replacements due to macro expansion and the defined unary
6211 operator have been performed, all remaining identifiers (including those lexically
6212 identical to keywords) are replaced with the pp-number 0, and then each preprocessing
6213 token is converted into a token. The resulting tokens compose the controlling constant
6214 expression which is evaluated according to the rules of 6.6. For the purposes of this
6215 token conversion and evaluation, all signed integer types and all unsigned integer types
6216 act as if they have the same representation as, respectively, the types intmax_t and
6217 uintmax_t defined in the header <stdint.h>.145) This includes interpreting
6218 character constants, which may involve converting escape sequences into execution
6219 character set members. Whether the numeric value for these character constants matches
6220 the value obtained when an identical character constant occurs in an expression (other
6221 than within a #if or #elif directive) is implementation-defined.146) Also, whether a
6222 single-character character constant may have a negative value is implementation-defined.
6223 5 Preprocessing directives of the forms
6227 145) Thus, on an implementation where INT_MAX is 0x7FFF and UINT_MAX is 0xFFFF, the constant
6228 0x8000 is signed and positive within a #if expression even though it would be unsigned in
6229 translation phase 7.
6233 # ifdef identifier new-line groupopt
6234 # ifndef identifier new-line groupopt
6235 check whether the identifier is or is not currently defined as a macro name. Their
6236 conditions are equivalent to #if defined identifier and #if !defined identifier
6238 6 Each directive's condition is checked in order. If it evaluates to false (zero), the group
6239 that it controls is skipped: directives are processed only through the name that determines
6240 the directive in order to keep track of the level of nested conditionals; the rest of the
6241 directives' preprocessing tokens are ignored, as are the other preprocessing tokens in the
6242 group. Only the first group whose control condition evaluates to true (nonzero) is
6243 processed. If none of the conditions evaluates to true, and there is a #else directive, the
6244 group controlled by the #else is processed; lacking a #else directive, all the groups
6245 until the #endif are skipped.147)
6246 Forward references: macro replacement (6.10.3), source file inclusion (6.10.2), largest
6247 integer types (7.18.1.5).
6248 6.10.2 Source file inclusion
6250 1 A #include directive shall identify a header or source file that can be processed by the
6253 2 A preprocessing directive of the form
6254 # include <h-char-sequence> new-line
6255 searches a sequence of implementation-defined places for a header identified uniquely by
6256 the specified sequence between the < and > delimiters, and causes the replacement of that
6257 directive by the entire contents of the header. How the places are specified or the header
6258 identified is implementation-defined.
6259 3 A preprocessing directive of the form
6263 146) Thus, the constant expression in the following #if directive and if statement is not guaranteed to
6264 evaluate to the same value in these two contexts.
6266 if ('z' - 'a' == 25)
6268 147) As indicated by the syntax, a preprocessing token shall not follow a #else or #endif directive
6269 before the terminating new-line character. However, comments may appear anywhere in a source file,
6270 including within a preprocessing directive.
6274 # include "q-char-sequence" new-line
6275 causes the replacement of that directive by the entire contents of the source file identified
6276 by the specified sequence between the " delimiters. The named source file is searched
6277 for in an implementation-defined manner. If this search is not supported, or if the search
6278 fails, the directive is reprocessed as if it read
6279 # include <h-char-sequence> new-line
6280 with the identical contained sequence (including > characters, if any) from the original
6282 4 A preprocessing directive of the form
6283 # include pp-tokens new-line
6284 (that does not match one of the two previous forms) is permitted. The preprocessing
6285 tokens after include in the directive are processed just as in normal text. (Each
6286 identifier currently defined as a macro name is replaced by its replacement list of
6287 preprocessing tokens.) The directive resulting after all replacements shall match one of
6288 the two previous forms.148) The method by which a sequence of preprocessing tokens
6289 between a < and a > preprocessing token pair or a pair of " characters is combined into a
6290 single header name preprocessing token is implementation-defined.
6291 5 The implementation shall provide unique mappings for sequences consisting of one or
6292 more nondigits or digits (6.4.2.1) followed by a period (.) and a single nondigit. The
6293 first character shall not be a digit. The implementation may ignore distinctions of
6294 alphabetical case and restrict the mapping to eight significant characters before the
6296 6 A #include preprocessing directive may appear in a source file that has been read
6297 because of a #include directive in another file, up to an implementation-defined
6298 nesting limit (see 5.2.4.1).
6299 7 EXAMPLE 1 The most common uses of #include preprocessing directives are as in the following:
6303 8 EXAMPLE 2 This illustrates macro-replaced #include directives:
6308 148) Note that adjacent string literals are not concatenated into a single string literal (see the translation
6309 phases in 5.1.1.2); thus, an expansion that results in two string literals is an invalid directive.
6314 #define INCFILE "vers1.h"
6316 #define INCFILE "vers2.h" // and so on
6318 #define INCFILE "versN.h"
6322 Forward references: macro replacement (6.10.3).
6323 6.10.3 Macro replacement
6325 1 Two replacement lists are identical if and only if the preprocessing tokens in both have
6326 the same number, ordering, spelling, and white-space separation, where all white-space
6327 separations are considered identical.
6328 2 An identifier currently defined as an object-like macro shall not be redefined by another
6329 #define preprocessing directive unless the second definition is an object-like macro
6330 definition and the two replacement lists are identical. Likewise, an identifier currently
6331 defined as a function-like macro shall not be redefined by another #define
6332 preprocessing directive unless the second definition is a function-like macro definition
6333 that has the same number and spelling of parameters, and the two replacement lists are
6335 3 There shall be white-space between the identifier and the replacement list in the definition
6336 of an object-like macro.
6337 4 If the identifier-list in the macro definition does not end with an ellipsis, the number of
6338 arguments (including those arguments consisting of no preprocessing tokens) in an
6339 invocation of a function-like macro shall equal the number of parameters in the macro
6340 definition. Otherwise, there shall be more arguments in the invocation than there are
6341 parameters in the macro definition (excluding the ...). There shall exist a )
6342 preprocessing token that terminates the invocation.
6343 5 The identifier __VA_ARGS__ shall occur only in the replacement-list of a function-like
6344 macro that uses the ellipsis notation in the parameters.
6345 6 A parameter identifier in a function-like macro shall be uniquely declared within its
6348 7 The identifier immediately following the define is called the macro name. There is one
6349 name space for macro names. Any white-space characters preceding or following the
6350 replacement list of preprocessing tokens are not considered part of the replacement list
6351 for either form of macro.
6355 8 If a # preprocessing token, followed by an identifier, occurs lexically at the point at which
6356 a preprocessing directive could begin, the identifier is not subject to macro replacement.
6357 9 A preprocessing directive of the form
6358 # define identifier replacement-list new-line
6359 defines an object-like macro that causes each subsequent instance of the macro name149)
6360 to be replaced by the replacement list of preprocessing tokens that constitute the
6361 remainder of the directive. The replacement list is then rescanned for more macro names
6363 10 A preprocessing directive of the form
6364 # define identifier lparen identifier-listopt ) replacement-list new-line
6365 # define identifier lparen ... ) replacement-list new-line
6366 # define identifier lparen identifier-list , ... ) replacement-list new-line
6367 defines a function-like macro with parameters, whose use is similar syntactically to a
6368 function call. The parameters are specified by the optional list of identifiers, whose scope
6369 extends from their declaration in the identifier list until the new-line character that
6370 terminates the #define preprocessing directive. Each subsequent instance of the
6371 function-like macro name followed by a ( as the next preprocessing token introduces the
6372 sequence of preprocessing tokens that is replaced by the replacement list in the definition
6373 (an invocation of the macro). The replaced sequence of preprocessing tokens is
6374 terminated by the matching ) preprocessing token, skipping intervening matched pairs of
6375 left and right parenthesis preprocessing tokens. Within the sequence of preprocessing
6376 tokens making up an invocation of a function-like macro, new-line is considered a normal
6377 white-space character.
6378 11 The sequence of preprocessing tokens bounded by the outside-most matching parentheses
6379 forms the list of arguments for the function-like macro. The individual arguments within
6380 the list are separated by comma preprocessing tokens, but comma preprocessing tokens
6381 between matching inner parentheses do not separate arguments. If there are sequences of
6382 preprocessing tokens within the list of arguments that would otherwise act as
6383 preprocessing directives,150) the behavior is undefined.
6384 12 If there is a ... in the identifier-list in the macro definition, then the trailing arguments,
6385 including any separating comma preprocessing tokens, are merged to form a single item:
6386 the variable arguments. The number of arguments so combined is such that, following
6389 149) Since, by macro-replacement time, all character constants and string literals are preprocessing tokens,
6390 not sequences possibly containing identifier-like subsequences (see 5.1.1.2, translation phases), they
6391 are never scanned for macro names or parameters.
6392 150) Despite the name, a non-directive is a preprocessing directive.
6396 merger, the number of arguments is one more than the number of parameters in the macro
6397 definition (excluding the ...).
6398 6.10.3.1 Argument substitution
6399 1 After the arguments for the invocation of a function-like macro have been identified,
6400 argument substitution takes place. A parameter in the replacement list, unless preceded
6401 by a # or ## preprocessing token or followed by a ## preprocessing token (see below), is
6402 replaced by the corresponding argument after all macros contained therein have been
6403 expanded. Before being substituted, each argument's preprocessing tokens are
6404 completely macro replaced as if they formed the rest of the preprocessing file; no other
6405 preprocessing tokens are available.
6406 2 An identifier __VA_ARGS__ that occurs in the replacement list shall be treated as if it
6407 were a parameter, and the variable arguments shall form the preprocessing tokens used to
6409 6.10.3.2 The # operator
6411 1 Each # preprocessing token in the replacement list for a function-like macro shall be
6412 followed by a parameter as the next preprocessing token in the replacement list.
6414 2 If, in the replacement list, a parameter is immediately preceded by a # preprocessing
6415 token, both are replaced by a single character string literal preprocessing token that
6416 contains the spelling of the preprocessing token sequence for the corresponding
6417 argument. Each occurrence of white space between the argument's preprocessing tokens
6418 becomes a single space character in the character string literal. White space before the
6419 first preprocessing token and after the last preprocessing token composing the argument
6420 is deleted. Otherwise, the original spelling of each preprocessing token in the argument
6421 is retained in the character string literal, except for special handling for producing the
6422 spelling of string literals and character constants: a \ character is inserted before each "
6423 and \ character of a character constant or string literal (including the delimiting "
6424 characters), except that it is implementation-defined whether a \ character is inserted
6425 before the \ character beginning a universal character name. If the replacement that
6426 results is not a valid character string literal, the behavior is undefined. The character
6427 string literal corresponding to an empty argument is "". The order of evaluation of # and
6428 ## operators is unspecified.
6432 6.10.3.3 The ## operator
6434 1 A ## preprocessing token shall not occur at the beginning or at the end of a replacement
6435 list for either form of macro definition.
6437 2 If, in the replacement list of a function-like macro, a parameter is immediately preceded
6438 or followed by a ## preprocessing token, the parameter is replaced by the corresponding
6439 argument's preprocessing token sequence; however, if an argument consists of no
6440 preprocessing tokens, the parameter is replaced by a placemarker preprocessing token
6442 3 For both object-like and function-like macro invocations, before the replacement list is
6443 reexamined for more macro names to replace, each instance of a ## preprocessing token
6444 in the replacement list (not from an argument) is deleted and the preceding preprocessing
6445 token is concatenated with the following preprocessing token. Placemarker
6446 preprocessing tokens are handled specially: concatenation of two placemarkers results in
6447 a single placemarker preprocessing token, and concatenation of a placemarker with a
6448 non-placemarker preprocessing token results in the non-placemarker preprocessing token.
6449 If the result is not a valid preprocessing token, the behavior is undefined. The resulting
6450 token is available for further macro replacement. The order of evaluation of ## operators
6452 4 EXAMPLE In the following fragment:
6453 #define hash_hash # ## #
6454 #define mkstr(a) # a
6455 #define in_between(a) mkstr(a)
6456 #define join(c, d) in_between(c hash_hash d)
6457 char p[] = join(x, y); // equivalent to
6458 // char p[] = "x ## y";
6459 The expansion produces, at various stages:
6461 in_between(x hash_hash y)
6465 In other words, expanding hash_hash produces a new token, consisting of two adjacent sharp signs, but
6466 this new token is not the ## operator.
6469 151) Placemarker preprocessing tokens do not appear in the syntax because they are temporary entities that
6470 exist only within translation phase 4.
6474 6.10.3.4 Rescanning and further replacement
6475 1 After all parameters in the replacement list have been substituted and # and ##
6476 processing has taken place, all placemarker preprocessing tokens are removed. Then, the
6477 resulting preprocessing token sequence is rescanned, along with all subsequent
6478 preprocessing tokens of the source file, for more macro names to replace.
6479 2 If the name of the macro being replaced is found during this scan of the replacement list
6480 (not including the rest of the source file's preprocessing tokens), it is not replaced.
6481 Furthermore, if any nested replacements encounter the name of the macro being replaced,
6482 it is not replaced. These nonreplaced macro name preprocessing tokens are no longer
6483 available for further replacement even if they are later (re)examined in contexts in which
6484 that macro name preprocessing token would otherwise have been replaced.
6485 3 The resulting completely macro-replaced preprocessing token sequence is not processed
6486 as a preprocessing directive even if it resembles one, but all pragma unary operator
6487 expressions within it are then processed as specified in 6.10.9 below.
6488 6.10.3.5 Scope of macro definitions
6489 1 A macro definition lasts (independent of block structure) until a corresponding #undef
6490 directive is encountered or (if none is encountered) until the end of the preprocessing
6491 translation unit. Macro definitions have no significance after translation phase 4.
6492 2 A preprocessing directive of the form
6493 # undef identifier new-line
6494 causes the specified identifier no longer to be defined as a macro name. It is ignored if
6495 the specified identifier is not currently defined as a macro name.
6496 3 EXAMPLE 1 The simplest use of this facility is to define a ''manifest constant'', as in
6500 4 EXAMPLE 2 The following defines a function-like macro whose value is the maximum of its arguments.
6501 It has the advantages of working for any compatible types of the arguments and of generating in-line code
6502 without the overhead of function calling. It has the disadvantages of evaluating one or the other of its
6503 arguments a second time (including side effects) and generating more code than a function if invoked
6504 several times. It also cannot have its address taken, as it has none.
6505 #define max(a, b) ((a) > (b) ? (a) : (b))
6506 The parentheses ensure that the arguments and the resulting expression are bound properly.
6510 5 EXAMPLE 3 To illustrate the rules for redefinition and reexamination, the sequence
6512 #define f(a) f(x * (a))
6523 #define r(x,y) x ## y
6525 f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
6526 g(x+(3,4)-w) | h 5) & m
6528 p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
6529 char c[2][6] = { str(hello), str() };
6531 f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
6532 f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
6533 int i[] = { 1, 23, 4, 5, };
6534 char c[2][6] = { "hello", "" };
6536 6 EXAMPLE 4 To illustrate the rules for creating character string literals and concatenating tokens, the
6539 #define xstr(s) str(s)
6540 #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \
6542 #define INCFILE(n) vers ## n
6543 #define glue(a, b) a ## b
6544 #define xglue(a, b) glue(a, b)
6545 #define HIGHLOW "hello"
6546 #define LOW LOW ", world"
6548 fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away
6549 == 0) str(: @\n), s);
6550 #include xstr(INCFILE(2).h)
6557 printf("x" "1" "= %d, x" "2" "= %s", x1, x2);
6559 "strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n",
6561 #include "vers2.h" (after macro replacement, before file access)
6564 or, after concatenation of the character string literals,
6565 printf("x1= %d, x2= %s", x1, x2);
6567 "strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: @\n",
6569 #include "vers2.h" (after macro replacement, before file access)
6572 Space around the # and ## tokens in the macro definition is optional.
6574 7 EXAMPLE 5 To illustrate the rules for placemarker preprocessing tokens, the sequence
6575 #define t(x,y,z) x ## y ## z
6576 int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
6577 t(10,,), t(,11,), t(,,12), t(,,) };
6579 int j[] = { 123, 45, 67, 89,
6582 8 EXAMPLE 6 To demonstrate the redefinition rules, the following sequence is valid.
6583 #define OBJ_LIKE (1-1)
6584 #define OBJ_LIKE /* white space */ (1-1) /* other */
6585 #define FUNC_LIKE(a) ( a )
6586 #define FUNC_LIKE( a )( /* note the white space */ \
6587 a /* other stuff on this line
6589 But the following redefinitions are invalid:
6590 #define OBJ_LIKE (0) // different token sequence
6591 #define OBJ_LIKE (1 - 1) // different white space
6592 #define FUNC_LIKE(b) ( a ) // different parameter usage
6593 #define FUNC_LIKE(b) ( b ) // different parameter spelling
6595 9 EXAMPLE 7 Finally, to show the variable argument list macro facilities:
6596 #define debug(...) fprintf(stderr, __VA_ARGS__)
6597 #define showlist(...) puts(#__VA_ARGS__)
6598 #define report(test, ...) ((test)?puts(#test):\
6599 printf(__VA_ARGS__))
6601 debug("X = %d\n", x);
6602 showlist(The first, second, and third items.);
6603 report(x>y, "x is %d but y is %d", x, y);
6608 fprintf(stderr, "Flag" );
6609 fprintf(stderr, "X = %d\n", x );
6610 puts( "The first, second, and third items." );
6612 printf("x is %d but y is %d", x, y));
6616 1 The string literal of a #line directive, if present, shall be a character string literal.
6618 2 The line number of the current source line is one greater than the number of new-line
6619 characters read or introduced in translation phase 1 (5.1.1.2) while processing the source
6620 file to the current token.
6621 3 A preprocessing directive of the form
6622 # line digit-sequence new-line
6623 causes the implementation to behave as if the following sequence of source lines begins
6624 with a source line that has a line number as specified by the digit sequence (interpreted as
6625 a decimal integer). The digit sequence shall not specify zero, nor a number greater than
6627 4 A preprocessing directive of the form
6628 # line digit-sequence "s-char-sequenceopt" new-line
6629 sets the presumed line number similarly and changes the presumed name of the source
6630 file to be the contents of the character string literal.
6631 5 A preprocessing directive of the form
6632 # line pp-tokens new-line
6633 (that does not match one of the two previous forms) is permitted. The preprocessing
6634 tokens after line on the directive are processed just as in normal text (each identifier
6635 currently defined as a macro name is replaced by its replacement list of preprocessing
6636 tokens). The directive resulting after all replacements shall match one of the two
6637 previous forms and is then processed as appropriate.
6641 6.10.5 Error directive
6643 1 A preprocessing directive of the form
6644 # error pp-tokensopt new-line
6645 causes the implementation to produce a diagnostic message that includes the specified
6646 sequence of preprocessing tokens.
6647 6.10.6 Pragma directive
6649 1 A preprocessing directive of the form
6650 # pragma pp-tokensopt new-line
6651 where the preprocessing token STDC does not immediately follow pragma in the
6652 directive (prior to any macro replacement)152) causes the implementation to behave in an
6653 implementation-defined manner. The behavior might cause translation to fail or cause the
6654 translator or the resulting program to behave in a non-conforming manner. Any such
6655 pragma that is not recognized by the implementation is ignored.
6656 2 If the preprocessing token STDC does immediately follow pragma in the directive (prior
6657 to any macro replacement), then no macro replacement is performed on the directive, and
6658 the directive shall have one of the following forms153) whose meanings are described
6660 #pragma STDC FP_CONTRACT on-off-switch
6661 #pragma STDC FENV_ACCESS on-off-switch
6662 #pragma STDC CX_LIMITED_RANGE on-off-switch
6663 on-off-switch: one of
6665 Forward references: the FP_CONTRACT pragma (7.12.2), the FENV_ACCESS pragma
6666 (7.6.1), the CX_LIMITED_RANGE pragma (7.3.4).
6671 152) An implementation is not required to perform macro replacement in pragmas, but it is permitted
6672 except for in standard pragmas (where STDC immediately follows pragma). If the result of macro
6673 replacement in a non-standard pragma has the same form as a standard pragma, the behavior is still
6674 implementation-defined; an implementation is permitted to behave as if it were the standard pragma,
6675 but is not required to.
6676 153) See ''future language directions'' (6.11.8).
6680 6.10.7 Null directive
6682 1 A preprocessing directive of the form
6685 6.10.8 Predefined macro names
6686 1 The following macro names154) shall be defined by the implementation:
6687 __DATE__ The date of translation of the preprocessing translation unit: a character
6688 string literal of the form "Mmm dd yyyy", where the names of the
6689 months are the same as those generated by the asctime function, and the
6690 first character of dd is a space character if the value is less than 10. If the
6691 date of translation is not available, an implementation-defined valid date
6693 __FILE__ The presumed name of the current source file (a character string literal).155)
6694 __LINE__ The presumed line number (within the current source file) of the current
6695 source line (an integer constant).155)
6696 __STDC__ The integer constant 1, intended to indicate a conforming implementation.
6697 __STDC_HOSTED__ The integer constant 1 if the implementation is a hosted
6698 implementation or the integer constant 0 if it is not.
6699 __STDC_MB_MIGHT_NEQ_WC__ The integer constant 1, intended to indicate that, in
6700 the encoding for wchar_t, a member of the basic character set need not
6701 have a code value equal to its value when used as the lone character in an
6702 integer character constant.
6703 __STDC_VERSION__ The integer constant 199901L.156)
6704 __TIME__ The time of translation of the preprocessing translation unit: a character
6705 string literal of the form "hh:mm:ss" as in the time generated by the
6706 asctime function. If the time of translation is not available, an
6707 implementation-defined valid time shall be supplied.
6711 154) See ''future language directions'' (6.11.9).
6712 155) The presumed source file name and line number can be changed by the #line directive.
6713 156) This macro was not specified in ISO/IEC 9899:1990 and was specified as 199409L in
6714 ISO/IEC 9899/AMD1:1995. The intention is that this will remain an integer constant of type long
6715 int that is increased with each revision of this International Standard.
6719 2 The following macro names are conditionally defined by the implementation:
6720 __STDC_IEC_559__ The integer constant 1, intended to indicate conformance to the
6721 specifications in annex F (IEC 60559 floating-point arithmetic).
6722 __STDC_IEC_559_COMPLEX__ The integer constant 1, intended to indicate
6723 adherence to the specifications in informative annex G (IEC 60559
6724 compatible complex arithmetic).
6725 __STDC_ISO_10646__ An integer constant of the form yyyymmL (for example,
6726 199712L). If this symbol is defined, then every character in the Unicode
6727 required set, when stored in an object of type wchar_t, has the same
6728 value as the short identifier of that character. The Unicode required set
6729 consists of all the characters that are defined by ISO/IEC 10646, along with
6730 all amendments and technical corrigenda, as of the specified year and
6732 3 The values of the predefined macros (except for __FILE__ and __LINE__) remain
6733 constant throughout the translation unit.
6734 4 None of these macro names, nor the identifier defined, shall be the subject of a
6735 #define or a #undef preprocessing directive. Any other predefined macro names
6736 shall begin with a leading underscore followed by an uppercase letter or a second
6738 5 The implementation shall not predefine the macro __cplusplus, nor shall it define it
6739 in any standard header.
6740 Forward references: the asctime function (7.23.3.1), standard headers (7.1.2).
6741 6.10.9 Pragma operator
6743 1 A unary operator expression of the form:
6744 _Pragma ( string-literal )
6745 is processed as follows: The string literal is destringized by deleting the L prefix, if
6746 present, deleting the leading and trailing double-quotes, replacing each escape sequence
6747 \" by a double-quote, and replacing each escape sequence \\ by a single backslash. The
6748 resulting sequence of characters is processed through translation phase 3 to produce
6749 preprocessing tokens that are executed as if they were the pp-tokens in a pragma
6750 directive. The original four preprocessing tokens in the unary operator expression are
6752 2 EXAMPLE A directive of the form:
6753 #pragma listing on "..\listing.dir"
6754 can also be expressed as:
6758 _Pragma ( "listing on \"..\\listing.dir\"" )
6759 The latter form is processed in the same way whether it appears literally as shown, or results from macro
6761 #define LISTING(x) PRAGMA(listing on #x)
6762 #define PRAGMA(x) _Pragma(#x)
6763 LISTING ( ..\listing.dir )
6767 6.11 Future language directions
6768 6.11.1 Floating types
6769 1 Future standardization may include additional floating-point types, including those with
6770 greater range, precision, or both than long double.
6771 6.11.2 Linkages of identifiers
6772 1 Declaring an identifier with internal linkage at file scope without the static storage-
6773 class specifier is an obsolescent feature.
6774 6.11.3 External names
6775 1 Restriction of the significance of an external name to fewer than 255 characters
6776 (considering each universal character name or extended source character as a single
6777 character) is an obsolescent feature that is a concession to existing implementations.
6778 6.11.4 Character escape sequences
6779 1 Lowercase letters as escape sequences are reserved for future standardization. Other
6780 characters may be used in extensions.
6781 6.11.5 Storage-class specifiers
6782 1 The placement of a storage-class specifier other than at the beginning of the declaration
6783 specifiers in a declaration is an obsolescent feature.
6784 6.11.6 Function declarators
6785 1 The use of function declarators with empty parentheses (not prototype-format parameter
6786 type declarators) is an obsolescent feature.
6787 6.11.7 Function definitions
6788 1 The use of function definitions with separate parameter identifier and declaration lists
6789 (not prototype-format parameter type and identifier declarators) is an obsolescent feature.
6790 6.11.8 Pragma directives
6791 1 Pragmas whose first preprocessing token is STDC are reserved for future standardization.
6792 6.11.9 Predefined macro names
6793 1 Macro names beginning with __STDC_ are reserved for future standardization.
6801 7.1.1 Definitions of terms
6802 1 A string is a contiguous sequence of characters terminated by and including the first null
6803 character. The term multibyte string is sometimes used instead to emphasize special
6804 processing given to multibyte characters contained in the string or to avoid confusion
6805 with a wide string. A pointer to a string is a pointer to its initial (lowest addressed)
6806 character. The length of a string is the number of bytes preceding the null character and
6807 the value of a string is the sequence of the values of the contained characters, in order.
6808 2 The decimal-point character is the character used by functions that convert floating-point
6809 numbers to or from character sequences to denote the beginning of the fractional part of
6810 such character sequences.157) It is represented in the text and examples by a period, but
6811 may be changed by the setlocale function.
6812 3 A null wide character is a wide character with code value zero.
6813 4 A wide string is a contiguous sequence of wide characters terminated by and including
6814 the first null wide character. A pointer to a wide string is a pointer to its initial (lowest
6815 addressed) wide character. The length of a wide string is the number of wide characters
6816 preceding the null wide character and the value of a wide string is the sequence of code
6817 values of the contained wide characters, in order.
6818 5 A shift sequence is a contiguous sequence of bytes within a multibyte string that
6819 (potentially) causes a change in shift state (see 5.2.1.2). A shift sequence shall not have a
6820 corresponding wide character; it is instead taken to be an adjunct to an adjacent multibyte
6822 Forward references: character handling (7.4), the setlocale function (7.11.1.1).
6827 157) The functions that make use of the decimal-point character are the numeric conversion functions
6828 (7.20.1, 7.24.4.1) and the formatted input/output functions (7.19.6, 7.24.2).
6829 158) For state-dependent encodings, the values for MB_CUR_MAX and MB_LEN_MAX shall thus be large
6830 enough to count all the bytes in any complete multibyte character plus at least one adjacent shift
6831 sequence of maximum length. Whether these counts provide for more than one shift sequence is the
6832 implementation's choice.
6836 7.1.2 Standard headers
6837 1 Each library function is declared, with a type that includes a prototype, in a header,159)
6838 whose contents are made available by the #include preprocessing directive. The
6839 header declares a set of related functions, plus any necessary types and additional macros
6840 needed to facilitate their use. Declarations of types described in this clause shall not
6841 include type qualifiers, unless explicitly stated otherwise.
6842 2 The standard headers are
6843 <assert.h> <inttypes.h> <signal.h> <stdlib.h>
6844 <complex.h> <iso646.h> <stdarg.h> <string.h>
6845 <ctype.h> <limits.h> <stdbool.h> <tgmath.h>
6846 <errno.h> <locale.h> <stddef.h> <time.h>
6847 <fenv.h> <math.h> <stdint.h> <wchar.h>
6848 <float.h> <setjmp.h> <stdio.h> <wctype.h>
6849 3 If a file with the same name as one of the above < and > delimited sequences, not
6850 provided as part of the implementation, is placed in any of the standard places that are
6851 searched for included source files, the behavior is undefined.
6852 4 Standard headers may be included in any order; each may be included more than once in
6853 a given scope, with no effect different from being included only once, except that the
6854 effect of including <assert.h> depends on the definition of NDEBUG (see 7.2). If
6855 used, a header shall be included outside of any external declaration or definition, and it
6856 shall first be included before the first reference to any of the functions or objects it
6857 declares, or to any of the types or macros it defines. However, if an identifier is declared
6858 or defined in more than one header, the second and subsequent associated headers may be
6859 included after the initial reference to the identifier. The program shall not have any
6860 macros with names lexically identical to keywords currently defined prior to the
6862 5 Any definition of an object-like macro described in this clause shall expand to code that is
6863 fully protected by parentheses where necessary, so that it groups in an arbitrary
6864 expression as if it were a single identifier.
6865 6 Any declaration of a library function shall have external linkage.
6866 7 A summary of the contents of the standard headers is given in annex B.
6867 Forward references: diagnostics (7.2).
6872 159) A header is not necessarily a source file, nor are the < and > delimited sequences in header names
6873 necessarily valid source file names.
6877 7.1.3 Reserved identifiers
6878 1 Each header declares or defines all identifiers listed in its associated subclause, and
6879 optionally declares or defines identifiers listed in its associated future library directions
6880 subclause and identifiers which are always reserved either for any use or for use as file
6882 -- All identifiers that begin with an underscore and either an uppercase letter or another
6883 underscore are always reserved for any use.
6884 -- All identifiers that begin with an underscore are always reserved for use as identifiers
6885 with file scope in both the ordinary and tag name spaces.
6886 -- Each macro name in any of the following subclauses (including the future library
6887 directions) is reserved for use as specified if any of its associated headers is included;
6888 unless explicitly stated otherwise (see 7.1.4).
6889 -- All identifiers with external linkage in any of the following subclauses (including the
6890 future library directions) are always reserved for use as identifiers with external
6892 -- Each identifier with file scope listed in any of the following subclauses (including the
6893 future library directions) is reserved for use as a macro name and as an identifier with
6894 file scope in the same name space if any of its associated headers is included.
6895 2 No other identifiers are reserved. If the program declares or defines an identifier in a
6896 context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved
6897 identifier as a macro name, the behavior is undefined.
6898 3 If the program removes (with #undef) any macro definition of an identifier in the first
6899 group listed above, the behavior is undefined.
6900 7.1.4 Use of library functions
6901 1 Each of the following statements applies unless explicitly stated otherwise in the detailed
6902 descriptions that follow: If an argument to a function has an invalid value (such as a value
6903 outside the domain of the function, or a pointer outside the address space of the program,
6904 or a null pointer, or a pointer to non-modifiable storage when the corresponding
6905 parameter is not const-qualified) or a type (after promotion) not expected by a function
6906 with variable number of arguments, the behavior is undefined. If a function argument is
6907 described as being an array, the pointer actually passed to the function shall have a value
6908 such that all address computations and accesses to objects (that would be valid if the
6909 pointer did point to the first element of such an array) are in fact valid. Any function
6910 declared in a header may be additionally implemented as a function-like macro defined in
6912 160) The list of reserved identifiers with external linkage includes errno, math_errhandling,
6917 the header, so if a library function is declared explicitly when its header is included, one
6918 of the techniques shown below can be used to ensure the declaration is not affected by
6919 such a macro. Any macro definition of a function can be suppressed locally by enclosing
6920 the name of the function in parentheses, because the name is then not followed by the left
6921 parenthesis that indicates expansion of a macro function name. For the same syntactic
6922 reason, it is permitted to take the address of a library function even if it is also defined as
6923 a macro.161) The use of #undef to remove any macro definition will also ensure that an
6924 actual function is referred to. Any invocation of a library function that is implemented as
6925 a macro shall expand to code that evaluates each of its arguments exactly once, fully
6926 protected by parentheses where necessary, so it is generally safe to use arbitrary
6927 expressions as arguments.162) Likewise, those function-like macros described in the
6928 following subclauses may be invoked in an expression anywhere a function with a
6929 compatible return type could be called.163) All object-like macros listed as expanding to
6930 integer constant expressions shall additionally be suitable for use in #if preprocessing
6932 2 Provided that a library function can be declared without reference to any type defined in a
6933 header, it is also permissible to declare the function and use it without including its
6935 3 There is a sequence point immediately before a library function returns.
6936 4 The functions in the standard library are not guaranteed to be reentrant and may modify
6937 objects with static storage duration.164)
6941 161) This means that an implementation shall provide an actual function for each library function, even if it
6942 also provides a macro for that function.
6943 162) Such macros might not contain the sequence points that the corresponding function calls do.
6944 163) Because external identifiers and some macro names beginning with an underscore are reserved,
6945 implementations may provide special semantics for such names. For example, the identifier
6946 _BUILTIN_abs could be used to indicate generation of in-line code for the abs function. Thus, the
6947 appropriate header could specify
6948 #define abs(x) _BUILTIN_abs(x)
6949 for a compiler whose code generator will accept it.
6950 In this manner, a user desiring to guarantee that a given library function such as abs will be a genuine
6953 whether the implementation's header provides a macro implementation of abs or a built-in
6954 implementation. The prototype for the function, which precedes and is hidden by any macro
6955 definition, is thereby revealed also.
6956 164) Thus, a signal handler cannot, in general, call standard library functions.
6960 5 EXAMPLE The function atoi may be used in any of several ways:
6961 -- by use of its associated header (possibly generating a macro expansion)
6966 -- by use of its associated header (assuredly generating a true function reference)
6977 -- by explicit declaration
6978 extern int atoi(const char *);
6985 7.2 Diagnostics <assert.h>
6986 1 The header <assert.h> defines the assert macro and refers to another macro,
6988 which is not defined by <assert.h>. If NDEBUG is defined as a macro name at the
6989 point in the source file where <assert.h> is included, the assert macro is defined
6991 #define assert(ignore) ((void)0)
6992 The assert macro is redefined according to the current state of NDEBUG each time that
6993 <assert.h> is included.
6994 2 The assert macro shall be implemented as a macro, not as an actual function. If the
6995 macro definition is suppressed in order to access an actual function, the behavior is
6997 7.2.1 Program diagnostics
6998 7.2.1.1 The assert macro
7000 1 #include <assert.h>
7001 void assert(scalar expression);
7003 2 The assert macro puts diagnostic tests into programs; it expands to a void expression.
7004 When it is executed, if expression (which shall have a scalar type) is false (that is,
7005 compares equal to 0), the assert macro writes information about the particular call that
7006 failed (including the text of the argument, the name of the source file, the source line
7007 number, and the name of the enclosing function -- the latter are respectively the values of
7008 the preprocessing macros __FILE__ and __LINE__ and of the identifier
7009 __func__) on the standard error stream in an implementation-defined format.165) It
7010 then calls the abort function.
7012 3 The assert macro returns no value.
7013 Forward references: the abort function (7.20.4.1).
7018 165) The message written might be of the form:
7019 Assertion failed: expression, function abc, file xyz, line nnn.
7023 7.3 Complex arithmetic <complex.h>
7025 1 The header <complex.h> defines macros and declares functions that support complex
7026 arithmetic.166) Each synopsis specifies a family of functions consisting of a principal
7027 function with one or more double complex parameters and a double complex or
7028 double return value; and other functions with the same name but with f and l suffixes
7029 which are corresponding functions with float and long double parameters and
7033 expands to _Complex; the macro
7035 expands to a constant expression of type const float _Complex, with the value of
7036 the imaginary unit.167)
7041 are defined if and only if the implementation supports imaginary types;168) if defined,
7042 they expand to _Imaginary and a constant expression of type const float
7043 _Imaginary with the value of the imaginary unit.
7046 expands to either _Imaginary_I or _Complex_I. If _Imaginary_I is not
7047 defined, I shall expand to _Complex_I.
7048 5 Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then
7049 redefine the macros complex, imaginary, and I.
7050 Forward references: IEC 60559-compatible complex arithmetic (annex G).
7054 166) See ''future library directions'' (7.26.1).
7055 167) The imaginary unit is a number i such that i 2 = -1.
7056 168) A specification for imaginary types is in informative annex G.
7061 1 Values are interpreted as radians, not degrees. An implementation may set errno but is
7064 1 Some of the functions below have branch cuts, across which the function is
7065 discontinuous. For implementations with a signed zero (including all IEC 60559
7066 implementations) that follow the specifications of annex G, the sign of zero distinguishes
7067 one side of a cut from another so the function is continuous (except for format
7068 limitations) as the cut is approached from either side. For example, for the square root
7069 function, which has a branch cut along the negative real axis, the top of the cut, with
7070 imaginary part +0, maps to the positive imaginary axis, and the bottom of the cut, with
7071 imaginary part -0, maps to the negative imaginary axis.
7072 2 Implementations that do not support a signed zero (see annex F) cannot distinguish the
7073 sides of branch cuts. These implementations shall map a cut so the function is continuous
7074 as the cut is approached coming around the finite endpoint of the cut in a counter
7075 clockwise direction. (Branch cuts for the functions specified here have just one finite
7076 endpoint.) For example, for the square root function, coming counter clockwise around
7077 the finite endpoint of the cut along the negative real axis approaches the cut from above,
7078 so the cut maps to the positive imaginary axis.
7079 7.3.4 The CX_LIMITED_RANGE pragma
7081 1 #include <complex.h>
7082 #pragma STDC CX_LIMITED_RANGE on-off-switch
7084 2 The usual mathematical formulas for complex multiply, divide, and absolute value are
7085 problematic because of their treatment of infinities and because of undue overflow and
7086 underflow. The CX_LIMITED_RANGE pragma can be used to inform the
7087 implementation that (where the state is ''on'') the usual mathematical formulas are
7088 acceptable.169) The pragma can occur either outside external declarations or preceding all
7089 explicit declarations and statements inside a compound statement. When outside external
7091 169) The purpose of the pragma is to allow the implementation to use the formulas:
7092 (x + iy) x (u + iv) = (xu - yv) + i(yu + xv)
7093 (x + iy) / (u + iv) = [(xu + yv) + i(yu - xv)]/(u2 + v 2 )
7094 | x + iy | = (sqrt) x 2 + y 2
7096 where the programmer can determine they are safe.
7100 declarations, the pragma takes effect from its occurrence until another
7101 CX_LIMITED_RANGE pragma is encountered, or until the end of the translation unit.
7102 When inside a compound statement, the pragma takes effect from its occurrence until
7103 another CX_LIMITED_RANGE pragma is encountered (including within a nested
7104 compound statement), or until the end of the compound statement; at the end of a
7105 compound statement the state for the pragma is restored to its condition just before the
7106 compound statement. If this pragma is used in any other context, the behavior is
7107 undefined. The default state for the pragma is ''off''.
7108 7.3.5 Trigonometric functions
7109 7.3.5.1 The cacos functions
7111 1 #include <complex.h>
7112 double complex cacos(double complex z);
7113 float complex cacosf(float complex z);
7114 long double complex cacosl(long double complex z);
7116 2 The cacos functions compute the complex arc cosine of z, with branch cuts outside the
7117 interval [-1, +1] along the real axis.
7119 3 The cacos functions return the complex arc cosine value, in the range of a strip
7120 mathematically unbounded along the imaginary axis and in the interval [0, pi ] along the
7122 7.3.5.2 The casin functions
7124 1 #include <complex.h>
7125 double complex casin(double complex z);
7126 float complex casinf(float complex z);
7127 long double complex casinl(long double complex z);
7129 2 The casin functions compute the complex arc sine of z, with branch cuts outside the
7130 interval [-1, +1] along the real axis.
7132 3 The casin functions return the complex arc sine value, in the range of a strip
7133 mathematically unbounded along the imaginary axis and in the interval [-pi /2, +pi /2]
7134 along the real axis.
7138 7.3.5.3 The catan functions
7140 1 #include <complex.h>
7141 double complex catan(double complex z);
7142 float complex catanf(float complex z);
7143 long double complex catanl(long double complex z);
7145 2 The catan functions compute the complex arc tangent of z, with branch cuts outside the
7146 interval [-i, +i] along the imaginary axis.
7148 3 The catan functions return the complex arc tangent value, in the range of a strip
7149 mathematically unbounded along the imaginary axis and in the interval [-pi /2, +pi /2]
7150 along the real axis.
7151 7.3.5.4 The ccos functions
7153 1 #include <complex.h>
7154 double complex ccos(double complex z);
7155 float complex ccosf(float complex z);
7156 long double complex ccosl(long double complex z);
7158 2 The ccos functions compute the complex cosine of z.
7160 3 The ccos functions return the complex cosine value.
7161 7.3.5.5 The csin functions
7163 1 #include <complex.h>
7164 double complex csin(double complex z);
7165 float complex csinf(float complex z);
7166 long double complex csinl(long double complex z);
7168 2 The csin functions compute the complex sine of z.
7170 3 The csin functions return the complex sine value.
7174 7.3.5.6 The ctan functions
7176 1 #include <complex.h>
7177 double complex ctan(double complex z);
7178 float complex ctanf(float complex z);
7179 long double complex ctanl(long double complex z);
7181 2 The ctan functions compute the complex tangent of z.
7183 3 The ctan functions return the complex tangent value.
7184 7.3.6 Hyperbolic functions
7185 7.3.6.1 The cacosh functions
7187 1 #include <complex.h>
7188 double complex cacosh(double complex z);
7189 float complex cacoshf(float complex z);
7190 long double complex cacoshl(long double complex z);
7192 2 The cacosh functions compute the complex arc hyperbolic cosine of z, with a branch
7193 cut at values less than 1 along the real axis.
7195 3 The cacosh functions return the complex arc hyperbolic cosine value, in the range of a
7196 half-strip of non-negative values along the real axis and in the interval [-ipi , +ipi ] along
7198 7.3.6.2 The casinh functions
7200 1 #include <complex.h>
7201 double complex casinh(double complex z);
7202 float complex casinhf(float complex z);
7203 long double complex casinhl(long double complex z);
7205 2 The casinh functions compute the complex arc hyperbolic sine of z, with branch cuts
7206 outside the interval [-i, +i] along the imaginary axis.
7211 3 The casinh functions return the complex arc hyperbolic sine value, in the range of a
7212 strip mathematically unbounded along the real axis and in the interval [-ipi /2, +ipi /2]
7213 along the imaginary axis.
7214 7.3.6.3 The catanh functions
7216 1 #include <complex.h>
7217 double complex catanh(double complex z);
7218 float complex catanhf(float complex z);
7219 long double complex catanhl(long double complex z);
7221 2 The catanh functions compute the complex arc hyperbolic tangent of z, with branch
7222 cuts outside the interval [-1, +1] along the real axis.
7224 3 The catanh functions return the complex arc hyperbolic tangent value, in the range of a
7225 strip mathematically unbounded along the real axis and in the interval [-ipi /2, +ipi /2]
7226 along the imaginary axis.
7227 7.3.6.4 The ccosh functions
7229 1 #include <complex.h>
7230 double complex ccosh(double complex z);
7231 float complex ccoshf(float complex z);
7232 long double complex ccoshl(long double complex z);
7234 2 The ccosh functions compute the complex hyperbolic cosine of z.
7236 3 The ccosh functions return the complex hyperbolic cosine value.
7237 7.3.6.5 The csinh functions
7239 1 #include <complex.h>
7240 double complex csinh(double complex z);
7241 float complex csinhf(float complex z);
7242 long double complex csinhl(long double complex z);
7247 2 The csinh functions compute the complex hyperbolic sine of z.
7249 3 The csinh functions return the complex hyperbolic sine value.
7250 7.3.6.6 The ctanh functions
7252 1 #include <complex.h>
7253 double complex ctanh(double complex z);
7254 float complex ctanhf(float complex z);
7255 long double complex ctanhl(long double complex z);
7257 2 The ctanh functions compute the complex hyperbolic tangent of z.
7259 3 The ctanh functions return the complex hyperbolic tangent value.
7260 7.3.7 Exponential and logarithmic functions
7261 7.3.7.1 The cexp functions
7263 1 #include <complex.h>
7264 double complex cexp(double complex z);
7265 float complex cexpf(float complex z);
7266 long double complex cexpl(long double complex z);
7268 2 The cexp functions compute the complex base-e exponential of z.
7270 3 The cexp functions return the complex base-e exponential value.
7271 7.3.7.2 The clog functions
7273 1 #include <complex.h>
7274 double complex clog(double complex z);
7275 float complex clogf(float complex z);
7276 long double complex clogl(long double complex z);
7281 2 The clog functions compute the complex natural (base-e) logarithm of z, with a branch
7282 cut along the negative real axis.
7284 3 The clog functions return the complex natural logarithm value, in the range of a strip
7285 mathematically unbounded along the real axis and in the interval [-ipi , +ipi ] along the
7287 7.3.8 Power and absolute-value functions
7288 7.3.8.1 The cabs functions
7290 1 #include <complex.h>
7291 double cabs(double complex z);
7292 float cabsf(float complex z);
7293 long double cabsl(long double complex z);
7295 2 The cabs functions compute the complex absolute value (also called norm, modulus, or
7298 3 The cabs functions return the complex absolute value.
7299 7.3.8.2 The cpow functions
7301 1 #include <complex.h>
7302 double complex cpow(double complex x, double complex y);
7303 float complex cpowf(float complex x, float complex y);
7304 long double complex cpowl(long double complex x,
7305 long double complex y);
7307 2 The cpow functions compute the complex power function xy , with a branch cut for the
7308 first parameter along the negative real axis.
7310 3 The cpow functions return the complex power function value.
7314 7.3.8.3 The csqrt functions
7316 1 #include <complex.h>
7317 double complex csqrt(double complex z);
7318 float complex csqrtf(float complex z);
7319 long double complex csqrtl(long double complex z);
7321 2 The csqrt functions compute the complex square root of z, with a branch cut along the
7324 3 The csqrt functions return the complex square root value, in the range of the right half-
7325 plane (including the imaginary axis).
7326 7.3.9 Manipulation functions
7327 7.3.9.1 The carg functions
7329 1 #include <complex.h>
7330 double carg(double complex z);
7331 float cargf(float complex z);
7332 long double cargl(long double complex z);
7334 2 The carg functions compute the argument (also called phase angle) of z, with a branch
7335 cut along the negative real axis.
7337 3 The carg functions return the value of the argument in the interval [-pi , +pi ].
7338 7.3.9.2 The cimag functions
7340 1 #include <complex.h>
7341 double cimag(double complex z);
7342 float cimagf(float complex z);
7343 long double cimagl(long double complex z);
7348 2 The cimag functions compute the imaginary part of z.170)
7350 3 The cimag functions return the imaginary part value (as a real).
7351 7.3.9.3 The conj functions
7353 1 #include <complex.h>
7354 double complex conj(double complex z);
7355 float complex conjf(float complex z);
7356 long double complex conjl(long double complex z);
7358 2 The conj functions compute the complex conjugate of z, by reversing the sign of its
7361 3 The conj functions return the complex conjugate value.
7362 7.3.9.4 The cproj functions
7364 1 #include <complex.h>
7365 double complex cproj(double complex z);
7366 float complex cprojf(float complex z);
7367 long double complex cprojl(long double complex z);
7369 2 The cproj functions compute a projection of z onto the Riemann sphere: z projects to
7370 z except that all complex infinities (even those with one infinite part and one NaN part)
7371 project to positive infinity on the real axis. If z has an infinite part, then cproj(z) is
7373 INFINITY + I * copysign(0.0, cimag(z))
7375 3 The cproj functions return the value of the projection onto the Riemann sphere.
7380 170) For a variable z of complex type, z == creal(z) + cimag(z)*I.
7384 7.3.9.5 The creal functions
7386 1 #include <complex.h>
7387 double creal(double complex z);
7388 float crealf(float complex z);
7389 long double creall(long double complex z);
7391 2 The creal functions compute the real part of z.171)
7393 3 The creal functions return the real part value.
7398 171) For a variable z of complex type, z == creal(z) + cimag(z)*I.
7402 7.4 Character handling <ctype.h>
7403 1 The header <ctype.h> declares several functions useful for classifying and mapping
7404 characters.172) In all cases the argument is an int, the value of which shall be
7405 representable as an unsigned char or shall equal the value of the macro EOF. If the
7406 argument has any other value, the behavior is undefined.
7407 2 The behavior of these functions is affected by the current locale. Those functions that
7408 have locale-specific aspects only when not in the "C" locale are noted below.
7409 3 The term printing character refers to a member of a locale-specific set of characters, each
7410 of which occupies one printing position on a display device; the term control character
7411 refers to a member of a locale-specific set of characters that are not printing
7412 characters.173) All letters and digits are printing characters.
7413 Forward references: EOF (7.19.1), localization (7.11).
7414 7.4.1 Character classification functions
7415 1 The functions in this subclause return nonzero (true) if and only if the value of the
7416 argument c conforms to that in the description of the function.
7417 7.4.1.1 The isalnum function
7419 1 #include <ctype.h>
7422 2 The isalnum function tests for any character for which isalpha or isdigit is true.
7423 7.4.1.2 The isalpha function
7425 1 #include <ctype.h>
7428 2 The isalpha function tests for any character for which isupper or islower is true,
7429 or any character that is one of a locale-specific set of alphabetic characters for which
7433 172) See ''future library directions'' (7.26.2).
7434 173) In an implementation that uses the seven-bit US ASCII character set, the printing characters are those
7435 whose values lie from 0x20 (space) through 0x7E (tilde); the control characters are those whose
7436 values lie from 0 (NUL) through 0x1F (US), and the character 0x7F (DEL).
7440 none of iscntrl, isdigit, ispunct, or isspace is true.174) In the "C" locale,
7441 isalpha returns true only for the characters for which isupper or islower is true.
7442 7.4.1.3 The isblank function
7444 1 #include <ctype.h>
7447 2 The isblank function tests for any character that is a standard blank character or is one
7448 of a locale-specific set of characters for which isspace is true and that is used to
7449 separate words within a line of text. The standard blank characters are the following:
7450 space (' '), and horizontal tab ('\t'). In the "C" locale, isblank returns true only
7451 for the standard blank characters.
7452 7.4.1.4 The iscntrl function
7454 1 #include <ctype.h>
7457 2 The iscntrl function tests for any control character.
7458 7.4.1.5 The isdigit function
7460 1 #include <ctype.h>
7463 2 The isdigit function tests for any decimal-digit character (as defined in 5.2.1).
7464 7.4.1.6 The isgraph function
7466 1 #include <ctype.h>
7472 174) The functions islower and isupper test true or false separately for each of these additional
7473 characters; all four combinations are possible.
7478 2 The isgraph function tests for any printing character except space (' ').
7479 7.4.1.7 The islower function
7481 1 #include <ctype.h>
7484 2 The islower function tests for any character that is a lowercase letter or is one of a
7485 locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or
7486 isspace is true. In the "C" locale, islower returns true only for the lowercase
7487 letters (as defined in 5.2.1).
7488 7.4.1.8 The isprint function
7490 1 #include <ctype.h>
7493 2 The isprint function tests for any printing character including space (' ').
7494 7.4.1.9 The ispunct function
7496 1 #include <ctype.h>
7499 2 The ispunct function tests for any printing character that is one of a locale-specific set
7500 of punctuation characters for which neither isspace nor isalnum is true. In the "C"
7501 locale, ispunct returns true for every printing character for which neither isspace
7502 nor isalnum is true.
7503 7.4.1.10 The isspace function
7505 1 #include <ctype.h>
7508 2 The isspace function tests for any character that is a standard white-space character or
7509 is one of a locale-specific set of characters for which isalnum is false. The standard
7513 white-space characters are the following: space (' '), form feed ('\f'), new-line
7514 ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). In the
7515 "C" locale, isspace returns true only for the standard white-space characters.
7516 7.4.1.11 The isupper function
7518 1 #include <ctype.h>
7521 2 The isupper function tests for any character that is an uppercase letter or is one of a
7522 locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or
7523 isspace is true. In the "C" locale, isupper returns true only for the uppercase
7524 letters (as defined in 5.2.1).
7525 7.4.1.12 The isxdigit function
7527 1 #include <ctype.h>
7528 int isxdigit(int c);
7530 2 The isxdigit function tests for any hexadecimal-digit character (as defined in 6.4.4.1).
7531 7.4.2 Character case mapping functions
7532 7.4.2.1 The tolower function
7534 1 #include <ctype.h>
7537 2 The tolower function converts an uppercase letter to a corresponding lowercase letter.
7539 3 If the argument is a character for which isupper is true and there are one or more
7540 corresponding characters, as specified by the current locale, for which islower is true,
7541 the tolower function returns one of the corresponding characters (always the same one
7542 for any given locale); otherwise, the argument is returned unchanged.
7546 7.4.2.2 The toupper function
7548 1 #include <ctype.h>
7551 2 The toupper function converts a lowercase letter to a corresponding uppercase letter.
7553 3 If the argument is a character for which islower is true and there are one or more
7554 corresponding characters, as specified by the current locale, for which isupper is true,
7555 the toupper function returns one of the corresponding characters (always the same one
7556 for any given locale); otherwise, the argument is returned unchanged.
7560 7.5 Errors <errno.h>
7561 1 The header <errno.h> defines several macros, all relating to the reporting of error
7567 which expand to integer constant expressions with type int, distinct positive values, and
7568 which are suitable for use in #if preprocessing directives; and
7570 which expands to a modifiable lvalue175) that has type int, the value of which is set to a
7571 positive error number by several library functions. It is unspecified whether errno is a
7572 macro or an identifier declared with external linkage. If a macro definition is suppressed
7573 in order to access an actual object, or a program defines an identifier with the name
7574 errno, the behavior is undefined.
7575 3 The value of errno is zero at program startup, but is never set to zero by any library
7576 function.176) The value of errno may be set to nonzero by a library function call
7577 whether or not there is an error, provided the use of errno is not documented in the
7578 description of the function in this International Standard.
7579 4 Additional macro definitions, beginning with E and a digit or E and an uppercase
7580 letter,177) may also be specified by the implementation.
7585 175) The macro errno need not be the identifier of an object. It might expand to a modifiable lvalue
7586 resulting from a function call (for example, *errno()).
7587 176) Thus, a program that uses errno for error checking should set it to zero before a library function call,
7588 then inspect it before a subsequent library function call. Of course, a library function can save the
7589 value of errno on entry and then set it to zero, as long as the original value is restored if errno's
7590 value is still zero just before the return.
7591 177) See ''future library directions'' (7.26.3).
7595 7.6 Floating-point environment <fenv.h>
7596 1 The header <fenv.h> declares two types and several macros and functions to provide
7597 access to the floating-point environment. The floating-point environment refers
7598 collectively to any floating-point status flags and control modes supported by the
7599 implementation.178) A floating-point status flag is a system variable whose value is set
7600 (but never cleared) when a floating-point exception is raised, which occurs as a side effect
7601 of exceptional floating-point arithmetic to provide auxiliary information.179) A floating-
7602 point control mode is a system variable whose value may be set by the user to affect the
7603 subsequent behavior of floating-point arithmetic.
7604 2 Certain programming conventions support the intended model of use for the floating-
7605 point environment:180)
7606 -- a function call does not alter its caller's floating-point control modes, clear its caller's
7607 floating-point status flags, nor depend on the state of its caller's floating-point status
7608 flags unless the function is so documented;
7609 -- a function call is assumed to require default floating-point control modes, unless its
7610 documentation promises otherwise;
7611 -- a function call is assumed to have the potential for raising floating-point exceptions,
7612 unless its documentation promises otherwise.
7615 represents the entire floating-point environment.
7618 represents the floating-point status flags collectively, including any status the
7619 implementation associates with the flags.
7624 178) This header is designed to support the floating-point exception status flags and directed-rounding
7625 control modes required by IEC 60559, and other similar floating-point state information. Also it is
7626 designed to facilitate code portability among all systems.
7627 179) A floating-point status flag is not an object and can be set more than once within an expression.
7628 180) With these conventions, a programmer can safely assume default floating-point control modes (or be
7629 unaware of them). The responsibilities associated with accessing the floating-point environment fall
7630 on the programmer or program that does so explicitly.
7634 5 Each of the macros
7640 is defined if and only if the implementation supports the floating-point exception by
7641 means of the functions in 7.6.2.181) Additional implementation-defined floating-point
7642 exceptions, with macro definitions beginning with FE_ and an uppercase letter, may also
7643 be specified by the implementation. The defined macros expand to integer constant
7644 expressions with values such that bitwise ORs of all combinations of the macros result in
7645 distinct values, and furthermore, bitwise ANDs of all combinations of the macros result in
7649 is simply the bitwise OR of all floating-point exception macros defined by the
7650 implementation. If no such macros are defined, FE_ALL_EXCEPT shall be defined as 0.
7651 7 Each of the macros
7656 is defined if and only if the implementation supports getting and setting the represented
7657 rounding direction by means of the fegetround and fesetround functions.
7658 Additional implementation-defined rounding directions, with macro definitions beginning
7659 with FE_ and an uppercase letter, may also be specified by the implementation. The
7660 defined macros expand to integer constant expressions whose values are distinct
7661 nonnegative values.183)
7666 181) The implementation supports an exception if there are circumstances where a call to at least one of the
7667 functions in 7.6.2, using the macro as the appropriate argument, will succeed. It is not necessary for
7668 all the functions to succeed all the time.
7669 182) The macros should be distinct powers of two.
7670 183) Even though the rounding direction macros may expand to constants corresponding to the values of
7671 FLT_ROUNDS, they are not required to do so.
7676 represents the default floating-point environment -- the one installed at program startup
7677 -- and has type ''pointer to const-qualified fenv_t''. It can be used as an argument to
7678 <fenv.h> functions that manage the floating-point environment.
7679 9 Additional implementation-defined environments, with macro definitions beginning with
7680 FE_ and an uppercase letter, and having type ''pointer to const-qualified fenv_t'', may
7681 also be specified by the implementation.
7682 7.6.1 The FENV_ACCESS pragma
7685 #pragma STDC FENV_ACCESS on-off-switch
7687 2 The FENV_ACCESS pragma provides a means to inform the implementation when a
7688 program might access the floating-point environment to test floating-point status flags or
7689 run under non-default floating-point control modes.184) The pragma shall occur either
7690 outside external declarations or preceding all explicit declarations and statements inside a
7691 compound statement. When outside external declarations, the pragma takes effect from
7692 its occurrence until another FENV_ACCESS pragma is encountered, or until the end of
7693 the translation unit. When inside a compound statement, the pragma takes effect from its
7694 occurrence until another FENV_ACCESS pragma is encountered (including within a
7695 nested compound statement), or until the end of the compound statement; at the end of a
7696 compound statement the state for the pragma is restored to its condition just before the
7697 compound statement. If this pragma is used in any other context, the behavior is
7698 undefined. If part of a program tests floating-point status flags, sets floating-point control
7699 modes, or runs under non-default mode settings, but was translated with the state for the
7700 FENV_ACCESS pragma ''off'', the behavior is undefined. The default state (''on'' or
7701 ''off'') for the pragma is implementation-defined. (When execution passes from a part of
7702 the program translated with FENV_ACCESS ''off'' to a part translated with
7703 FENV_ACCESS ''on'', the state of the floating-point status flags is unspecified and the
7704 floating-point control modes have their default settings.)
7709 184) The purpose of the FENV_ACCESS pragma is to allow certain optimizations that could subvert flag
7710 tests and mode changes (e.g., global common subexpression elimination, code motion, and constant
7711 folding). In general, if the state of FENV_ACCESS is ''off'', the translator can assume that default
7712 modes are in effect and the flags are not tested.
7720 #pragma STDC FENV_ACCESS ON
7728 4 If the function g might depend on status flags set as a side effect of the first x + 1, or if the second
7729 x + 1 might depend on control modes set as a side effect of the call to function g, then the program shall
7730 contain an appropriately placed invocation of #pragma STDC FENV_ACCESS ON.185)
7732 7.6.2 Floating-point exceptions
7733 1 The following functions provide access to the floating-point status flags.186) The int
7734 input argument for the functions represents a subset of floating-point exceptions, and can
7735 be zero or the bitwise OR of one or more floating-point exception macros, for example
7736 FE_OVERFLOW | FE_INEXACT. For other argument values the behavior of these
7737 functions is undefined.
7738 7.6.2.1 The feclearexcept function
7741 int feclearexcept(int excepts);
7743 2 The feclearexcept function attempts to clear the supported floating-point exceptions
7744 represented by its argument.
7746 3 The feclearexcept function returns zero if the excepts argument is zero or if all
7747 the specified exceptions were successfully cleared. Otherwise, it returns a nonzero value.
7750 185) The side effects impose a temporal ordering that requires two evaluations of x + 1. On the other
7751 hand, without the #pragma STDC FENV_ACCESS ON pragma, and assuming the default state is
7752 ''off'', just one evaluation of x + 1 would suffice.
7753 186) The functions fetestexcept, feraiseexcept, and feclearexcept support the basic
7754 abstraction of flags that are either set or clear. An implementation may endow floating-point status
7755 flags with more information -- for example, the address of the code which first raised the floating-
7756 point exception; the functions fegetexceptflag and fesetexceptflag deal with the full
7761 7.6.2.2 The fegetexceptflag function
7764 int fegetexceptflag(fexcept_t *flagp,
7767 2 The fegetexceptflag function attempts to store an implementation-defined
7768 representation of the states of the floating-point status flags indicated by the argument
7769 excepts in the object pointed to by the argument flagp.
7771 3 The fegetexceptflag function returns zero if the representation was successfully
7772 stored. Otherwise, it returns a nonzero value.
7773 7.6.2.3 The feraiseexcept function
7776 int feraiseexcept(int excepts);
7778 2 The feraiseexcept function attempts to raise the supported floating-point exceptions
7779 represented by its argument.187) The order in which these floating-point exceptions are
7780 raised is unspecified, except as stated in F.7.6. Whether the feraiseexcept function
7781 additionally raises the ''inexact'' floating-point exception whenever it raises the
7782 ''overflow'' or ''underflow'' floating-point exception is implementation-defined.
7784 3 The feraiseexcept function returns zero if the excepts argument is zero or if all
7785 the specified exceptions were successfully raised. Otherwise, it returns a nonzero value.
7790 187) The effect is intended to be similar to that of floating-point exceptions raised by arithmetic operations.
7791 Hence, enabled traps for floating-point exceptions raised by this function are taken. The specification
7792 in F.7.6 is in the same spirit.
7796 7.6.2.4 The fesetexceptflag function
7799 int fesetexceptflag(const fexcept_t *flagp,
7802 2 The fesetexceptflag function attempts to set the floating-point status flags
7803 indicated by the argument excepts to the states stored in the object pointed to by
7804 flagp. The value of *flagp shall have been set by a previous call to
7805 fegetexceptflag whose second argument represented at least those floating-point
7806 exceptions represented by the argument excepts. This function does not raise floating-
7807 point exceptions, but only sets the state of the flags.
7809 3 The fesetexceptflag function returns zero if the excepts argument is zero or if
7810 all the specified flags were successfully set to the appropriate state. Otherwise, it returns
7812 7.6.2.5 The fetestexcept function
7815 int fetestexcept(int excepts);
7817 2 The fetestexcept function determines which of a specified subset of the floating-
7818 point exception flags are currently set. The excepts argument specifies the floating-
7819 point status flags to be queried.188)
7821 3 The fetestexcept function returns the value of the bitwise OR of the floating-point
7822 exception macros corresponding to the currently set floating-point exceptions included in
7824 4 EXAMPLE Call f if ''invalid'' is set, then g if ''overflow'' is set:
7829 188) This mechanism allows testing several floating-point exceptions with just one function call.
7836 #pragma STDC FENV_ACCESS ON
7838 feclearexcept(FE_INVALID | FE_OVERFLOW);
7839 // maybe raise exceptions
7840 set_excepts = fetestexcept(FE_INVALID | FE_OVERFLOW);
7841 if (set_excepts & FE_INVALID) f();
7842 if (set_excepts & FE_OVERFLOW) g();
7847 1 The fegetround and fesetround functions provide control of rounding direction
7849 7.6.3.1 The fegetround function
7852 int fegetround(void);
7854 2 The fegetround function gets the current rounding direction.
7856 3 The fegetround function returns the value of the rounding direction macro
7857 representing the current rounding direction or a negative value if there is no such
7858 rounding direction macro or the current rounding direction is not determinable.
7859 7.6.3.2 The fesetround function
7862 int fesetround(int round);
7864 2 The fesetround function establishes the rounding direction represented by its
7865 argument round. If the argument is not equal to the value of a rounding direction macro,
7866 the rounding direction is not changed.
7868 3 The fesetround function returns zero if and only if the requested rounding direction
7873 4 EXAMPLE Save, set, and restore the rounding direction. Report an error and abort if setting the
7874 rounding direction fails.
7877 void f(int round_dir)
7879 #pragma STDC FENV_ACCESS ON
7882 save_round = fegetround();
7883 setround_ok = fesetround(round_dir);
7884 assert(setround_ok == 0);
7886 fesetround(save_round);
7891 1 The functions in this section manage the floating-point environment -- status flags and
7892 control modes -- as one entity.
7893 7.6.4.1 The fegetenv function
7896 int fegetenv(fenv_t *envp);
7898 2 The fegetenv function attempts to store the current floating-point environment in the
7899 object pointed to by envp.
7901 3 The fegetenv function returns zero if the environment was successfully stored.
7902 Otherwise, it returns a nonzero value.
7903 7.6.4.2 The feholdexcept function
7906 int feholdexcept(fenv_t *envp);
7908 2 The feholdexcept function saves the current floating-point environment in the object
7909 pointed to by envp, clears the floating-point status flags, and then installs a non-stop
7910 (continue on floating-point exceptions) mode, if available, for all floating-point
7916 3 The feholdexcept function returns zero if and only if non-stop floating-point
7917 exception handling was successfully installed.
7918 7.6.4.3 The fesetenv function
7921 int fesetenv(const fenv_t *envp);
7923 2 The fesetenv function attempts to establish the floating-point environment represented
7924 by the object pointed to by envp. The argument envp shall point to an object set by a
7925 call to fegetenv or feholdexcept, or equal a floating-point environment macro.
7926 Note that fesetenv merely installs the state of the floating-point status flags
7927 represented through its argument, and does not raise these floating-point exceptions.
7929 3 The fesetenv function returns zero if the environment was successfully established.
7930 Otherwise, it returns a nonzero value.
7931 7.6.4.4 The feupdateenv function
7934 int feupdateenv(const fenv_t *envp);
7936 2 The feupdateenv function attempts to save the currently raised floating-point
7937 exceptions in its automatic storage, install the floating-point environment represented by
7938 the object pointed to by envp, and then raise the saved floating-point exceptions. The
7939 argument envp shall point to an object set by a call to feholdexcept or fegetenv,
7940 or equal a floating-point environment macro.
7942 3 The feupdateenv function returns zero if all the actions were successfully carried out.
7943 Otherwise, it returns a nonzero value.
7948 189) IEC 60559 systems have a default non-stop mode, and typically at least one other mode for trap
7949 handling or aborting; if the system provides only the non-stop mode then installing it is trivial. For
7950 such systems, the feholdexcept function can be used in conjunction with the feupdateenv
7951 function to write routines that hide spurious floating-point exceptions from their callers.
7955 4 EXAMPLE Hide spurious underflow floating-point exceptions:
7959 #pragma STDC FENV_ACCESS ON
7962 if (feholdexcept(&save_env))
7963 return /* indication of an environmental problem */;
7965 if (/* test spurious underflow */)
7966 if (feclearexcept(FE_UNDERFLOW))
7967 return /* indication of an environmental problem */;
7968 if (feupdateenv(&save_env))
7969 return /* indication of an environmental problem */;
7975 7.7 Characteristics of floating types <float.h>
7976 1 The header <float.h> defines several macros that expand to various limits and
7977 parameters of the standard floating-point types.
7978 2 The macros, their meanings, and the constraints (or restrictions) on their values are listed
7983 7.8 Format conversion of integer types <inttypes.h>
7984 1 The header <inttypes.h> includes the header <stdint.h> and extends it with
7985 additional facilities provided by hosted implementations.
7986 2 It declares functions for manipulating greatest-width integers and converting numeric
7987 character strings to greatest-width integers, and it declares the type
7989 which is a structure type that is the type of the value returned by the imaxdiv function.
7990 For each type declared in <stdint.h>, it defines corresponding macros for conversion
7991 specifiers for use with the formatted input/output functions.190)
7992 Forward references: integer types <stdint.h> (7.18), formatted input/output
7993 functions (7.19.6), formatted wide character input/output functions (7.24.2).
7994 7.8.1 Macros for format specifiers
7995 1 Each of the following object-like macros191) expands to a character string literal
7996 containing a conversion specifier, possibly modified by a length modifier, suitable for use
7997 within the format argument of a formatted input/output function when converting the
7998 corresponding integer type. These macro names have the general form of PRI (character
7999 string literals for the fprintf and fwprintf family) or SCN (character string literals
8000 for the fscanf and fwscanf family),192) followed by the conversion specifier,
8001 followed by a name corresponding to a similar type name in 7.18.1. In these names, N
8002 represents the width of the type as described in 7.18.1. For example, PRIdFAST32 can
8003 be used in a format string to print the value of an integer of type int_fast32_t.
8004 2 The fprintf macros for signed integers are:
8005 PRIdN PRIdLEASTN PRIdFASTN PRIdMAX PRIdPTR
8006 PRIiN PRIiLEASTN PRIiFASTN PRIiMAX PRIiPTR
8011 190) See ''future library directions'' (7.26.4).
8012 191) C++ implementations should define these macros only when __STDC_FORMAT_MACROS is defined
8013 before <inttypes.h> is included.
8014 192) Separate macros are given for use with fprintf and fscanf functions because, in the general case,
8015 different format specifiers may be required for fprintf and fscanf, even when the type is the
8020 3 The fprintf macros for unsigned integers are:
8021 PRIoN PRIoLEASTN PRIoFASTN PRIoMAX PRIoPTR
8022 PRIuN PRIuLEASTN PRIuFASTN PRIuMAX PRIuPTR
8023 PRIxN PRIxLEASTN PRIxFASTN PRIxMAX PRIxPTR
8024 PRIXN PRIXLEASTN PRIXFASTN PRIXMAX PRIXPTR
8025 4 The fscanf macros for signed integers are:
8026 SCNdN SCNdLEASTN SCNdFASTN SCNdMAX SCNdPTR
8027 SCNiN SCNiLEASTN SCNiFASTN SCNiMAX SCNiPTR
8028 5 The fscanf macros for unsigned integers are:
8029 SCNoN SCNoLEASTN SCNoFASTN SCNoMAX SCNoPTR
8030 SCNuN SCNuLEASTN SCNuFASTN SCNuMAX SCNuPTR
8031 SCNxN SCNxLEASTN SCNxFASTN SCNxMAX SCNxPTR
8032 6 For each type that the implementation provides in <stdint.h>, the corresponding
8033 fprintf macros shall be defined and the corresponding fscanf macros shall be
8034 defined unless the implementation does not have a suitable fscanf length modifier for
8037 #include <inttypes.h>
8041 uintmax_t i = UINTMAX_MAX; // this type always exists
8042 wprintf(L"The largest integer value is %020"
8047 7.8.2 Functions for greatest-width integer types
8048 7.8.2.1 The imaxabs function
8050 1 #include <inttypes.h>
8051 intmax_t imaxabs(intmax_t j);
8053 2 The imaxabs function computes the absolute value of an integer j. If the result cannot
8054 be represented, the behavior is undefined.193)
8058 193) The absolute value of the most negative number cannot be represented in two's complement.
8063 3 The imaxabs function returns the absolute value.
8064 7.8.2.2 The imaxdiv function
8066 1 #include <inttypes.h>
8067 imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
8069 2 The imaxdiv function computes numer / denom and numer % denom in a single
8072 3 The imaxdiv function returns a structure of type imaxdiv_t comprising both the
8073 quotient and the remainder. The structure shall contain (in either order) the members
8074 quot (the quotient) and rem (the remainder), each of which has type intmax_t. If
8075 either part of the result cannot be represented, the behavior is undefined.
8076 7.8.2.3 The strtoimax and strtoumax functions
8078 1 #include <inttypes.h>
8079 intmax_t strtoimax(const char * restrict nptr,
8080 char ** restrict endptr, int base);
8081 uintmax_t strtoumax(const char * restrict nptr,
8082 char ** restrict endptr, int base);
8084 2 The strtoimax and strtoumax functions are equivalent to the strtol, strtoll,
8085 strtoul, and strtoull functions, except that the initial portion of the string is
8086 converted to intmax_t and uintmax_t representation, respectively.
8088 3 The strtoimax and strtoumax functions return the converted value, if any. If no
8089 conversion could be performed, zero is returned. If the correct value is outside the range
8090 of representable values, INTMAX_MAX, INTMAX_MIN, or UINTMAX_MAX is returned
8091 (according to the return type and sign of the value, if any), and the value of the macro
8092 ERANGE is stored in errno.
8093 Forward references: the strtol, strtoll, strtoul, and strtoull functions
8098 7.8.2.4 The wcstoimax and wcstoumax functions
8100 1 #include <stddef.h> // for wchar_t
8101 #include <inttypes.h>
8102 intmax_t wcstoimax(const wchar_t * restrict nptr,
8103 wchar_t ** restrict endptr, int base);
8104 uintmax_t wcstoumax(const wchar_t * restrict nptr,
8105 wchar_t ** restrict endptr, int base);
8107 2 The wcstoimax and wcstoumax functions are equivalent to the wcstol, wcstoll,
8108 wcstoul, and wcstoull functions except that the initial portion of the wide string is
8109 converted to intmax_t and uintmax_t representation, respectively.
8111 3 The wcstoimax function returns the converted value, if any. If no conversion could be
8112 performed, zero is returned. If the correct value is outside the range of representable
8113 values, INTMAX_MAX, INTMAX_MIN, or UINTMAX_MAX is returned (according to the
8114 return type and sign of the value, if any), and the value of the macro ERANGE is stored in
8116 Forward references: the wcstol, wcstoll, wcstoul, and wcstoull functions
8121 7.9 Alternative spellings <iso646.h>
8122 1 The header <iso646.h> defines the following eleven macros (on the left) that expand
8123 to the corresponding tokens (on the right):
8138 7.10 Sizes of integer types <limits.h>
8139 1 The header <limits.h> defines several macros that expand to various limits and
8140 parameters of the standard integer types.
8141 2 The macros, their meanings, and the constraints (or restrictions) on their values are listed
8146 7.11 Localization <locale.h>
8147 1 The header <locale.h> declares two functions, one type, and defines several macros.
8150 which contains members related to the formatting of numeric values. The structure shall
8151 contain at least the following members, in any order. The semantics of the members and
8152 their normal ranges are explained in 7.11.2.1. In the "C" locale, the members shall have
8153 the values specified in the comments.
8154 char *decimal_point; // "."
8155 char *thousands_sep; // ""
8156 char *grouping; // ""
8157 char *mon_decimal_point; // ""
8158 char *mon_thousands_sep; // ""
8159 char *mon_grouping; // ""
8160 char *positive_sign; // ""
8161 char *negative_sign; // ""
8162 char *currency_symbol; // ""
8163 char frac_digits; // CHAR_MAX
8164 char p_cs_precedes; // CHAR_MAX
8165 char n_cs_precedes; // CHAR_MAX
8166 char p_sep_by_space; // CHAR_MAX
8167 char n_sep_by_space; // CHAR_MAX
8168 char p_sign_posn; // CHAR_MAX
8169 char n_sign_posn; // CHAR_MAX
8170 char *int_curr_symbol; // ""
8171 char int_frac_digits; // CHAR_MAX
8172 char int_p_cs_precedes; // CHAR_MAX
8173 char int_n_cs_precedes; // CHAR_MAX
8174 char int_p_sep_by_space; // CHAR_MAX
8175 char int_n_sep_by_space; // CHAR_MAX
8176 char int_p_sign_posn; // CHAR_MAX
8177 char int_n_sign_posn; // CHAR_MAX
8181 3 The macros defined are NULL (described in 7.17); and
8188 which expand to integer constant expressions with distinct values, suitable for use as the
8189 first argument to the setlocale function.194) Additional macro definitions, beginning
8190 with the characters LC_ and an uppercase letter,195) may also be specified by the
8192 7.11.1 Locale control
8193 7.11.1.1 The setlocale function
8195 1 #include <locale.h>
8196 char *setlocale(int category, const char *locale);
8198 2 The setlocale function selects the appropriate portion of the program's locale as
8199 specified by the category and locale arguments. The setlocale function may be
8200 used to change or query the program's entire current locale or portions thereof. The value
8201 LC_ALL for category names the program's entire locale; the other values for
8202 category name only a portion of the program's locale. LC_COLLATE affects the
8203 behavior of the strcoll and strxfrm functions. LC_CTYPE affects the behavior of
8204 the character handling functions196) and the multibyte and wide character functions.
8205 LC_MONETARY affects the monetary formatting information returned by the
8206 localeconv function. LC_NUMERIC affects the decimal-point character for the
8207 formatted input/output functions and the string conversion functions, as well as the
8208 nonmonetary formatting information returned by the localeconv function. LC_TIME
8209 affects the behavior of the strftime and wcsftime functions.
8210 3 A value of "C" for locale specifies the minimal environment for C translation; a value
8211 of "" for locale specifies the locale-specific native environment. Other
8212 implementation-defined strings may be passed as the second argument to setlocale.
8214 194) ISO/IEC 9945-2 specifies locale and charmap formats that may be used to specify locales for C.
8215 195) See ''future library directions'' (7.26.5).
8216 196) The only functions in 7.4 whose behavior is not affected by the current locale are isdigit and
8221 4 At program startup, the equivalent of
8222 setlocale(LC_ALL, "C");
8224 5 The implementation shall behave as if no library function calls the setlocale function.
8226 6 If a pointer to a string is given for locale and the selection can be honored, the
8227 setlocale function returns a pointer to the string associated with the specified
8228 category for the new locale. If the selection cannot be honored, the setlocale
8229 function returns a null pointer and the program's locale is not changed.
8230 7 A null pointer for locale causes the setlocale function to return a pointer to the
8231 string associated with the category for the program's current locale; the program's
8232 locale is not changed.197)
8233 8 The pointer to string returned by the setlocale function is such that a subsequent call
8234 with that string value and its associated category will restore that part of the program's
8235 locale. The string pointed to shall not be modified by the program, but may be
8236 overwritten by a subsequent call to the setlocale function.
8237 Forward references: formatted input/output functions (7.19.6), multibyte/wide
8238 character conversion functions (7.20.7), multibyte/wide string conversion functions
8239 (7.20.8), numeric conversion functions (7.20.1), the strcoll function (7.21.4.3), the
8240 strftime function (7.23.3.5), the strxfrm function (7.21.4.5).
8241 7.11.2 Numeric formatting convention inquiry
8242 7.11.2.1 The localeconv function
8244 1 #include <locale.h>
8245 struct lconv *localeconv(void);
8247 2 The localeconv function sets the components of an object with type struct lconv
8248 with values appropriate for the formatting of numeric quantities (monetary and otherwise)
8249 according to the rules of the current locale.
8250 3 The members of the structure with type char * are pointers to strings, any of which
8251 (except decimal_point) can point to "", to indicate that the value is not available in
8252 the current locale or is of zero length. Apart from grouping and mon_grouping, the
8254 197) The implementation shall arrange to encode in a string the various categories due to a heterogeneous
8255 locale when category has the value LC_ALL.
8259 strings shall start and end in the initial shift state. The members with type char are
8260 nonnegative numbers, any of which can be CHAR_MAX to indicate that the value is not
8261 available in the current locale. The members include the following:
8263 The decimal-point character used to format nonmonetary quantities.
8265 The character used to separate groups of digits before the decimal-point
8266 character in formatted nonmonetary quantities.
8268 A string whose elements indicate the size of each group of digits in
8269 formatted nonmonetary quantities.
8270 char *mon_decimal_point
8271 The decimal-point used to format monetary quantities.
8272 char *mon_thousands_sep
8273 The separator for groups of digits before the decimal-point in formatted
8274 monetary quantities.
8276 A string whose elements indicate the size of each group of digits in
8277 formatted monetary quantities.
8279 The string used to indicate a nonnegative-valued formatted monetary
8282 The string used to indicate a negative-valued formatted monetary quantity.
8283 char *currency_symbol
8284 The local currency symbol applicable to the current locale.
8286 The number of fractional digits (those after the decimal-point) to be
8287 displayed in a locally formatted monetary quantity.
8289 Set to 1 or 0 if the currency_symbol respectively precedes or
8290 succeeds the value for a nonnegative locally formatted monetary quantity.
8292 Set to 1 or 0 if the currency_symbol respectively precedes or
8293 succeeds the value for a negative locally formatted monetary quantity.
8298 Set to a value indicating the separation of the currency_symbol, the
8299 sign string, and the value for a nonnegative locally formatted monetary
8302 Set to a value indicating the separation of the currency_symbol, the
8303 sign string, and the value for a negative locally formatted monetary
8306 Set to a value indicating the positioning of the positive_sign for a
8307 nonnegative locally formatted monetary quantity.
8309 Set to a value indicating the positioning of the negative_sign for a
8310 negative locally formatted monetary quantity.
8311 char *int_curr_symbol
8312 The international currency symbol applicable to the current locale. The
8313 first three characters contain the alphabetic international currency symbol
8314 in accordance with those specified in ISO 4217. The fourth character
8315 (immediately preceding the null character) is the character used to separate
8316 the international currency symbol from the monetary quantity.
8317 char int_frac_digits
8318 The number of fractional digits (those after the decimal-point) to be
8319 displayed in an internationally formatted monetary quantity.
8320 char int_p_cs_precedes
8321 Set to 1 or 0 if the int_curr_symbol respectively precedes or
8322 succeeds the value for a nonnegative internationally formatted monetary
8324 char int_n_cs_precedes
8325 Set to 1 or 0 if the int_curr_symbol respectively precedes or
8326 succeeds the value for a negative internationally formatted monetary
8328 char int_p_sep_by_space
8329 Set to a value indicating the separation of the int_curr_symbol, the
8330 sign string, and the value for a nonnegative internationally formatted
8335 char int_n_sep_by_space
8336 Set to a value indicating the separation of the int_curr_symbol, the
8337 sign string, and the value for a negative internationally formatted monetary
8339 char int_p_sign_posn
8340 Set to a value indicating the positioning of the positive_sign for a
8341 nonnegative internationally formatted monetary quantity.
8342 char int_n_sign_posn
8343 Set to a value indicating the positioning of the negative_sign for a
8344 negative internationally formatted monetary quantity.
8345 4 The elements of grouping and mon_grouping are interpreted according to the
8347 CHAR_MAX No further grouping is to be performed.
8348 0 The previous element is to be repeatedly used for the remainder of the
8350 other The integer value is the number of digits that compose the current group.
8351 The next element is examined to determine the size of the next group of
8352 digits before the current group.
8353 5 The values of p_sep_by_space, n_sep_by_space, int_p_sep_by_space,
8354 and int_n_sep_by_space are interpreted according to the following:
8355 0 No space separates the currency symbol and value.
8356 1 If the currency symbol and sign string are adjacent, a space separates them from the
8357 value; otherwise, a space separates the currency symbol from the value.
8358 2 If the currency symbol and sign string are adjacent, a space separates them;
8359 otherwise, a space separates the sign string from the value.
8360 For int_p_sep_by_space and int_n_sep_by_space, the fourth character of
8361 int_curr_symbol is used instead of a space.
8362 6 The values of p_sign_posn, n_sign_posn, int_p_sign_posn, and
8363 int_n_sign_posn are interpreted according to the following:
8364 0 Parentheses surround the quantity and currency symbol.
8365 1 The sign string precedes the quantity and currency symbol.
8366 2 The sign string succeeds the quantity and currency symbol.
8367 3 The sign string immediately precedes the currency symbol.
8368 4 The sign string immediately succeeds the currency symbol.
8372 7 The implementation shall behave as if no library function calls the localeconv
8375 8 The localeconv function returns a pointer to the filled-in object. The structure
8376 pointed to by the return value shall not be modified by the program, but may be
8377 overwritten by a subsequent call to the localeconv function. In addition, calls to the
8378 setlocale function with categories LC_ALL, LC_MONETARY, or LC_NUMERIC may
8379 overwrite the contents of the structure.
8380 9 EXAMPLE 1 The following table illustrates rules which may well be used by four countries to format
8381 monetary quantities.
8382 Local format International format
8384 Country Positive Negative Positive Negative
8386 Country1 1.234,56 mk -1.234,56 mk FIM 1.234,56 FIM -1.234,56
8387 Country2 L.1.234 -L.1.234 ITL 1.234 -ITL 1.234
8388 Country3 fl. 1.234,56 fl. -1.234,56 NLG 1.234,56 NLG -1.234,56
8389 Country4 SFrs.1,234.56 SFrs.1,234.56C CHF 1,234.56 CHF 1,234.56C
8390 10 For these four countries, the respective values for the monetary members of the structure returned by
8391 localeconv could be:
8392 Country1 Country2 Country3 Country4
8394 mon_decimal_point "," "" "," "."
8395 mon_thousands_sep "." "." "." ","
8396 mon_grouping "\3" "\3" "\3" "\3"
8397 positive_sign "" "" "" ""
8398 negative_sign "-" "-" "-" "C"
8399 currency_symbol "mk" "L." "\u0192" "SFrs."
8401 p_cs_precedes 0 1 1 1
8402 n_cs_precedes 0 1 1 1
8403 p_sep_by_space 1 0 1 0
8404 n_sep_by_space 1 0 2 0
8407 int_curr_symbol "FIM " "ITL " "NLG " "CHF "
8408 int_frac_digits 2 0 2 2
8409 int_p_cs_precedes 1 1 1 1
8410 int_n_cs_precedes 1 1 1 1
8411 int_p_sep_by_space 1 1 1 1
8412 int_n_sep_by_space 2 1 2 1
8413 int_p_sign_posn 1 1 1 1
8414 int_n_sign_posn 4 1 4 2
8418 11 EXAMPLE 2 The following table illustrates how the cs_precedes, sep_by_space, and sign_posn members
8419 affect the formatted value.
8422 p_cs_precedes p_sign_posn 0 1 2
8424 0 0 (1.25$) (1.25 $) (1.25$)
8425 1 +1.25$ +1.25 $ + 1.25$
8426 2 1.25$+ 1.25 $+ 1.25$ +
8427 3 1.25+$ 1.25 +$ 1.25+ $
8428 4 1.25$+ 1.25 $+ 1.25$ +
8430 1 0 ($1.25) ($ 1.25) ($1.25)
8431 1 +$1.25 +$ 1.25 + $1.25
8432 2 $1.25+ $ 1.25+ $1.25 +
8433 3 +$1.25 +$ 1.25 + $1.25
8434 4 $+1.25 $+ 1.25 $ +1.25
8438 7.12 Mathematics <math.h>
8439 1 The header <math.h> declares two types and many mathematical functions and defines
8440 several macros. Most synopses specify a family of functions consisting of a principal
8441 function with one or more double parameters, a double return value, or both; and
8442 other functions with the same name but with f and l suffixes, which are corresponding
8443 functions with float and long double parameters, return values, or both.198)
8444 Integer arithmetic functions and conversion functions are discussed later.
8448 are floating types at least as wide as float and double, respectively, and such that
8449 double_t is at least as wide as float_t. If FLT_EVAL_METHOD equals 0,
8450 float_t and double_t are float and double, respectively; if
8451 FLT_EVAL_METHOD equals 1, they are both double; if FLT_EVAL_METHOD equals
8452 2, they are both long double; and for other values of FLT_EVAL_METHOD, they are
8453 otherwise implementation-defined.199)
8456 expands to a positive double constant expression, not necessarily representable as a
8460 are respectively float and long double analogs of HUGE_VAL.200)
8463 expands to a constant expression of type float representing positive or unsigned
8464 infinity, if available; else to a positive constant of type float that overflows at
8468 198) Particularly on systems with wide expression evaluation, a <math.h> function might pass arguments
8469 and return values in wider format than the synopsis prototype indicates.
8470 199) The types float_t and double_t are intended to be the implementation's most efficient types at
8471 least as wide as float and double, respectively. For FLT_EVAL_METHOD equal 0, 1, or 2, the
8472 type float_t is the narrowest type used by the implementation to evaluate floating expressions.
8473 200) HUGE_VAL, HUGE_VALF, and HUGE_VALL can be positive infinities in an implementation that
8474 supports infinities.
8478 translation time.201)
8481 is defined if and only if the implementation supports quiet NaNs for the float type. It
8482 expands to a constant expression of type float representing a quiet NaN.
8483 6 The number classification macros
8489 represent the mutually exclusive kinds of floating-point values. They expand to integer
8490 constant expressions with distinct values. Additional implementation-defined floating-
8491 point classifications, with macro definitions beginning with FP_ and an uppercase letter,
8492 may also be specified by the implementation.
8495 is optionally defined. If defined, it indicates that the fma function generally executes
8496 about as fast as, or faster than, a multiply and an add of double operands.202) The
8500 are, respectively, float and long double analogs of FP_FAST_FMA. If defined,
8501 these macros expand to the integer constant 1.
8505 expand to integer constant expressions whose values are returned by ilogb(x) if x is
8506 zero or NaN, respectively. The value of FP_ILOGB0 shall be either INT_MIN or
8507 -INT_MAX. The value of FP_ILOGBNAN shall be either INT_MAX or INT_MIN.
8510 201) In this case, using INFINITY will violate the constraint in 6.4.4 and thus require a diagnostic.
8511 202) Typically, the FP_FAST_FMA macro is defined if and only if the fma function is implemented
8512 directly with a hardware multiply-add instruction. Software implementations are expected to be
8513 substantially slower.
8520 expand to the integer constants 1 and 2, respectively; the macro
8522 expands to an expression that has type int and the value MATH_ERRNO,
8523 MATH_ERREXCEPT, or the bitwise OR of both. The value of math_errhandling is
8524 constant for the duration of the program. It is unspecified whether
8525 math_errhandling is a macro or an identifier with external linkage. If a macro
8526 definition is suppressed or a program defines an identifier with the name
8527 math_errhandling, the behavior is undefined. If the expression
8528 math_errhandling & MATH_ERREXCEPT can be nonzero, the implementation
8529 shall define the macros FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in
8531 7.12.1 Treatment of error conditions
8532 1 The behavior of each of the functions in <math.h> is specified for all representable
8533 values of its input arguments, except where stated otherwise. Each function shall execute
8534 as if it were a single operation without generating any externally visible exceptional
8536 2 For all functions, a domain error occurs if an input argument is outside the domain over
8537 which the mathematical function is defined. The description of each function lists any
8538 required domain errors; an implementation may define additional domain errors, provided
8539 that such errors are consistent with the mathematical definition of the function.203) On a
8540 domain error, the function returns an implementation-defined value; if the integer
8541 expression math_errhandling & MATH_ERRNO is nonzero, the integer expression
8542 errno acquires the value EDOM; if the integer expression math_errhandling &
8543 MATH_ERREXCEPT is nonzero, the ''invalid'' floating-point exception is raised.
8544 3 Similarly, a range error occurs if the mathematical result of the function cannot be
8545 represented in an object of the specified type, due to extreme magnitude.
8546 4 A floating result overflows if the magnitude of the mathematical result is finite but so
8547 large that the mathematical result cannot be represented without extraordinary roundoff
8548 error in an object of the specified type. If a floating result overflows and default rounding
8549 is in effect, or if the mathematical result is an exact infinity from finite arguments (for
8550 example log(0.0)), then the function returns the value of the macro HUGE_VAL,
8553 203) In an implementation that supports infinities, this allows an infinity as an argument to be a domain
8554 error if the mathematical domain of the function does not include the infinity.
8558 HUGE_VALF, or HUGE_VALL according to the return type, with the same sign as the
8559 correct value of the function; if the integer expression math_errhandling &
8560 MATH_ERRNO is nonzero, the integer expression errno acquires the value ERANGE; if
8561 the integer expression math_errhandling & MATH_ERREXCEPT is nonzero, the
8562 ''divide-by-zero'' floating-point exception is raised if the mathematical result is an exact
8563 infinity and the ''overflow'' floating-point exception is raised otherwise.
8564 5 The result underflows if the magnitude of the mathematical result is so small that the
8565 mathematical result cannot be represented, without extraordinary roundoff error, in an
8566 object of the specified type.204) If the result underflows, the function returns an
8567 implementation-defined value whose magnitude is no greater than the smallest
8568 normalized positive number in the specified type; if the integer expression
8569 math_errhandling & MATH_ERRNO is nonzero, whether errno acquires the
8570 value ERANGE is implementation-defined; if the integer expression
8571 math_errhandling & MATH_ERREXCEPT is nonzero, whether the ''underflow''
8572 floating-point exception is raised is implementation-defined.
8573 7.12.2 The FP_CONTRACT pragma
8576 #pragma STDC FP_CONTRACT on-off-switch
8578 2 The FP_CONTRACT pragma can be used to allow (if the state is ''on'') or disallow (if the
8579 state is ''off'') the implementation to contract expressions (6.5). Each pragma can occur
8580 either outside external declarations or preceding all explicit declarations and statements
8581 inside a compound statement. When outside external declarations, the pragma takes
8582 effect from its occurrence until another FP_CONTRACT pragma is encountered, or until
8583 the end of the translation unit. When inside a compound statement, the pragma takes
8584 effect from its occurrence until another FP_CONTRACT pragma is encountered
8585 (including within a nested compound statement), or until the end of the compound
8586 statement; at the end of a compound statement the state for the pragma is restored to its
8587 condition just before the compound statement. If this pragma is used in any other
8588 context, the behavior is undefined. The default state (''on'' or ''off'') for the pragma is
8589 implementation-defined.
8594 204) The term underflow here is intended to encompass both ''gradual underflow'' as in IEC 60559 and
8595 also ''flush-to-zero'' underflow.
8599 7.12.3 Classification macros
8600 1 In the synopses in this subclause, real-floating indicates that the argument shall be an
8601 expression of real floating type.
8602 7.12.3.1 The fpclassify macro
8605 int fpclassify(real-floating x);
8607 2 The fpclassify macro classifies its argument value as NaN, infinite, normal,
8608 subnormal, zero, or into another implementation-defined category. First, an argument
8609 represented in a format wider than its semantic type is converted to its semantic type.
8610 Then classification is based on the type of the argument.205)
8612 3 The fpclassify macro returns the value of the number classification macro
8613 appropriate to the value of its argument.
8614 4 EXAMPLE The fpclassify macro might be implemented in terms of ordinary functions as
8615 #define fpclassify(x) \
8616 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) : \
8617 (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) : \
8620 7.12.3.2 The isfinite macro
8623 int isfinite(real-floating x);
8625 2 The isfinite macro determines whether its argument has a finite value (zero,
8626 subnormal, or normal, and not infinite or NaN). First, an argument represented in a
8627 format wider than its semantic type is converted to its semantic type. Then determination
8628 is based on the type of the argument.
8633 205) Since an expression can be evaluated with more range and precision than its type has, it is important to
8634 know the type that classification is based on. For example, a normal long double value might
8635 become subnormal when converted to double, and zero when converted to float.
8640 3 The isfinite macro returns a nonzero value if and only if its argument has a finite
8642 7.12.3.3 The isinf macro
8645 int isinf(real-floating x);
8647 2 The isinf macro determines whether its argument value is an infinity (positive or
8648 negative). First, an argument represented in a format wider than its semantic type is
8649 converted to its semantic type. Then determination is based on the type of the argument.
8651 3 The isinf macro returns a nonzero value if and only if its argument has an infinite
8653 7.12.3.4 The isnan macro
8656 int isnan(real-floating x);
8658 2 The isnan macro determines whether its argument value is a NaN. First, an argument
8659 represented in a format wider than its semantic type is converted to its semantic type.
8660 Then determination is based on the type of the argument.206)
8662 3 The isnan macro returns a nonzero value if and only if its argument has a NaN value.
8663 7.12.3.5 The isnormal macro
8666 int isnormal(real-floating x);
8671 206) For the isnan macro, the type for determination does not matter unless the implementation supports
8672 NaNs in the evaluation type but not in the semantic type.
8677 2 The isnormal macro determines whether its argument value is normal (neither zero,
8678 subnormal, infinite, nor NaN). First, an argument represented in a format wider than its
8679 semantic type is converted to its semantic type. Then determination is based on the type
8682 3 The isnormal macro returns a nonzero value if and only if its argument has a normal
8684 7.12.3.6 The signbit macro
8687 int signbit(real-floating x);
8689 2 The signbit macro determines whether the sign of its argument value is negative.207)
8691 3 The signbit macro returns a nonzero value if and only if the sign of its argument value
8693 7.12.4 Trigonometric functions
8694 7.12.4.1 The acos functions
8697 double acos(double x);
8698 float acosf(float x);
8699 long double acosl(long double x);
8701 2 The acos functions compute the principal value of the arc cosine of x. A domain error
8702 occurs for arguments not in the interval [-1, +1].
8704 3 The acos functions return arccos x in the interval [0, pi ] radians.
8709 207) The signbit macro reports the sign of all values, including infinities, zeros, and NaNs. If zero is
8710 unsigned, it is treated as positive.
8714 7.12.4.2 The asin functions
8717 double asin(double x);
8718 float asinf(float x);
8719 long double asinl(long double x);
8721 2 The asin functions compute the principal value of the arc sine of x. A domain error
8722 occurs for arguments not in the interval [-1, +1].
8724 3 The asin functions return arcsin x in the interval [-pi /2, +pi /2] radians.
8725 7.12.4.3 The atan functions
8728 double atan(double x);
8729 float atanf(float x);
8730 long double atanl(long double x);
8732 2 The atan functions compute the principal value of the arc tangent of x.
8734 3 The atan functions return arctan x in the interval [-pi /2, +pi /2] radians.
8735 7.12.4.4 The atan2 functions
8738 double atan2(double y, double x);
8739 float atan2f(float y, float x);
8740 long double atan2l(long double y, long double x);
8742 2 The atan2 functions compute the value of the arc tangent of y/x, using the signs of both
8743 arguments to determine the quadrant of the return value. A domain error may occur if
8744 both arguments are zero.
8746 3 The atan2 functions return arctan y/x in the interval [-pi , +pi ] radians.
8750 7.12.4.5 The cos functions
8753 double cos(double x);
8754 float cosf(float x);
8755 long double cosl(long double x);
8757 2 The cos functions compute the cosine of x (measured in radians).
8759 3 The cos functions return cos x.
8760 7.12.4.6 The sin functions
8763 double sin(double x);
8764 float sinf(float x);
8765 long double sinl(long double x);
8767 2 The sin functions compute the sine of x (measured in radians).
8769 3 The sin functions return sin x.
8770 7.12.4.7 The tan functions
8773 double tan(double x);
8774 float tanf(float x);
8775 long double tanl(long double x);
8777 2 The tan functions return the tangent of x (measured in radians).
8779 3 The tan functions return tan x.
8783 7.12.5 Hyperbolic functions
8784 7.12.5.1 The acosh functions
8787 double acosh(double x);
8788 float acoshf(float x);
8789 long double acoshl(long double x);
8791 2 The acosh functions compute the (nonnegative) arc hyperbolic cosine of x. A domain
8792 error occurs for arguments less than 1.
8794 3 The acosh functions return arcosh x in the interval [0, +(inf)].
8795 7.12.5.2 The asinh functions
8798 double asinh(double x);
8799 float asinhf(float x);
8800 long double asinhl(long double x);
8802 2 The asinh functions compute the arc hyperbolic sine of x.
8804 3 The asinh functions return arsinh x.
8805 7.12.5.3 The atanh functions
8808 double atanh(double x);
8809 float atanhf(float x);
8810 long double atanhl(long double x);
8812 2 The atanh functions compute the arc hyperbolic tangent of x. A domain error occurs
8813 for arguments not in the interval [-1, +1]. A range error may occur if the argument
8819 3 The atanh functions return artanh x.
8820 7.12.5.4 The cosh functions
8823 double cosh(double x);
8824 float coshf(float x);
8825 long double coshl(long double x);
8827 2 The cosh functions compute the hyperbolic cosine of x. A range error occurs if the
8828 magnitude of x is too large.
8830 3 The cosh functions return cosh x.
8831 7.12.5.5 The sinh functions
8834 double sinh(double x);
8835 float sinhf(float x);
8836 long double sinhl(long double x);
8838 2 The sinh functions compute the hyperbolic sine of x. A range error occurs if the
8839 magnitude of x is too large.
8841 3 The sinh functions return sinh x.
8842 7.12.5.6 The tanh functions
8845 double tanh(double x);
8846 float tanhf(float x);
8847 long double tanhl(long double x);
8849 2 The tanh functions compute the hyperbolic tangent of x.
8854 3 The tanh functions return tanh x.
8855 7.12.6 Exponential and logarithmic functions
8856 7.12.6.1 The exp functions
8859 double exp(double x);
8860 float expf(float x);
8861 long double expl(long double x);
8863 2 The exp functions compute the base-e exponential of x. A range error occurs if the
8864 magnitude of x is too large.
8866 3 The exp functions return ex .
8867 7.12.6.2 The exp2 functions
8870 double exp2(double x);
8871 float exp2f(float x);
8872 long double exp2l(long double x);
8874 2 The exp2 functions compute the base-2 exponential of x. A range error occurs if the
8875 magnitude of x is too large.
8877 3 The exp2 functions return 2x .
8878 7.12.6.3 The expm1 functions
8881 double expm1(double x);
8882 float expm1f(float x);
8883 long double expm1l(long double x);
8888 2 The expm1 functions compute the base-e exponential of the argument, minus 1. A range
8889 error occurs if x is too large.208)
8891 3 The expm1 functions return ex - 1.
8892 7.12.6.4 The frexp functions
8895 double frexp(double value, int *exp);
8896 float frexpf(float value, int *exp);
8897 long double frexpl(long double value, int *exp);
8899 2 The frexp functions break a floating-point number into a normalized fraction and an
8900 integral power of 2. They store the integer in the int object pointed to by exp.
8902 3 If value is not a floating-point number, the results are unspecified. Otherwise, the
8903 frexp functions return the value x, such that x has a magnitude in the interval [1/2, 1) or
8904 zero, and value equals x x 2*exp . If value is zero, both parts of the result are zero.
8905 7.12.6.5 The ilogb functions
8908 int ilogb(double x);
8909 int ilogbf(float x);
8910 int ilogbl(long double x);
8912 2 The ilogb functions extract the exponent of x as a signed int value. If x is zero they
8913 compute the value FP_ILOGB0; if x is infinite they compute the value INT_MAX; if x is
8914 a NaN they compute the value FP_ILOGBNAN; otherwise, they are equivalent to calling
8915 the corresponding logb function and casting the returned value to type int. A domain
8916 error or range error may occur if x is zero, infinite, or NaN. If the correct value is outside
8917 the range of the return type, the numeric result is unspecified.
8922 208) For small magnitude x, expm1(x) is expected to be more accurate than exp(x) - 1.
8927 3 The ilogb functions return the exponent of x as a signed int value.
8928 Forward references: the logb functions (7.12.6.11).
8929 7.12.6.6 The ldexp functions
8932 double ldexp(double x, int exp);
8933 float ldexpf(float x, int exp);
8934 long double ldexpl(long double x, int exp);
8936 2 The ldexp functions multiply a floating-point number by an integral power of 2. A
8937 range error may occur.
8939 3 The ldexp functions return x x 2exp .
8940 7.12.6.7 The log functions
8943 double log(double x);
8944 float logf(float x);
8945 long double logl(long double x);
8947 2 The log functions compute the base-e (natural) logarithm of x. A domain error occurs if
8948 the argument is negative. A range error may occur if the argument is zero.
8950 3 The log functions return loge x.
8951 7.12.6.8 The log10 functions
8954 double log10(double x);
8955 float log10f(float x);
8956 long double log10l(long double x);
8961 2 The log10 functions compute the base-10 (common) logarithm of x. A domain error
8962 occurs if the argument is negative. A range error may occur if the argument is zero.
8964 3 The log10 functions return log10 x.
8965 7.12.6.9 The log1p functions
8968 double log1p(double x);
8969 float log1pf(float x);
8970 long double log1pl(long double x);
8972 2 The log1p functions compute the base-e (natural) logarithm of 1 plus the argument.209)
8973 A domain error occurs if the argument is less than -1. A range error may occur if the
8976 3 The log1p functions return loge (1 + x).
8977 7.12.6.10 The log2 functions
8980 double log2(double x);
8981 float log2f(float x);
8982 long double log2l(long double x);
8984 2 The log2 functions compute the base-2 logarithm of x. A domain error occurs if the
8985 argument is less than zero. A range error may occur if the argument is zero.
8987 3 The log2 functions return log2 x.
8992 209) For small magnitude x, log1p(x) is expected to be more accurate than log(1 + x).
8996 7.12.6.11 The logb functions
8999 double logb(double x);
9000 float logbf(float x);
9001 long double logbl(long double x);
9003 2 The logb functions extract the exponent of x, as a signed integer value in floating-point
9004 format. If x is subnormal it is treated as though it were normalized; thus, for positive
9006 1 <= x x FLT_RADIX-logb(x) < FLT_RADIX
9007 A domain error or range error may occur if the argument is zero.
9009 3 The logb functions return the signed exponent of x.
9010 7.12.6.12 The modf functions
9013 double modf(double value, double *iptr);
9014 float modff(float value, float *iptr);
9015 long double modfl(long double value, long double *iptr);
9017 2 The modf functions break the argument value into integral and fractional parts, each of
9018 which has the same type and sign as the argument. They store the integral part (in
9019 floating-point format) in the object pointed to by iptr.
9021 3 The modf functions return the signed fractional part of value.
9025 7.12.6.13 The scalbn and scalbln functions
9028 double scalbn(double x, int n);
9029 float scalbnf(float x, int n);
9030 long double scalbnl(long double x, int n);
9031 double scalbln(double x, long int n);
9032 float scalblnf(float x, long int n);
9033 long double scalblnl(long double x, long int n);
9035 2 The scalbn and scalbln functions compute x x FLT_RADIXn efficiently, not
9036 normally by computing FLT_RADIXn explicitly. A range error may occur.
9038 3 The scalbn and scalbln functions return x x FLT_RADIXn .
9039 7.12.7 Power and absolute-value functions
9040 7.12.7.1 The cbrt functions
9043 double cbrt(double x);
9044 float cbrtf(float x);
9045 long double cbrtl(long double x);
9047 2 The cbrt functions compute the real cube root of x.
9049 3 The cbrt functions return x1/3 .
9050 7.12.7.2 The fabs functions
9053 double fabs(double x);
9054 float fabsf(float x);
9055 long double fabsl(long double x);
9057 2 The fabs functions compute the absolute value of a floating-point number x.
9062 3 The fabs functions return | x |.
9063 7.12.7.3 The hypot functions
9066 double hypot(double x, double y);
9067 float hypotf(float x, float y);
9068 long double hypotl(long double x, long double y);
9070 2 The hypot functions compute the square root of the sum of the squares of x and y,
9071 without undue overflow or underflow. A range error may occur.
9073 4 The hypot functions return (sqrt)x2 + y2 .
9076 7.12.7.4 The pow functions
9079 double pow(double x, double y);
9080 float powf(float x, float y);
9081 long double powl(long double x, long double y);
9083 2 The pow functions compute x raised to the power y. A domain error occurs if x is finite
9084 and negative and y is finite and not an integer value. A range error may occur. A domain
9085 error may occur if x is zero and y is zero. A domain error or range error may occur if x
9086 is zero and y is less than zero.
9088 3 The pow functions return xy .
9089 7.12.7.5 The sqrt functions
9092 double sqrt(double x);
9093 float sqrtf(float x);
9094 long double sqrtl(long double x);
9099 2 The sqrt functions compute the nonnegative square root of x. A domain error occurs if
9100 the argument is less than zero.
9102 3 The sqrt functions return (sqrt)x.
9105 7.12.8 Error and gamma functions
9106 7.12.8.1 The erf functions
9109 double erf(double x);
9110 float erff(float x);
9111 long double erfl(long double x);
9113 2 The erf functions compute the error function of x.
9118 The erf functions return erf x = e-t dt.
9126 7.12.8.2 The erfc functions
9129 double erfc(double x);
9130 float erfcf(float x);
9131 long double erfcl(long double x);
9133 2 The erfc functions compute the complementary error function of x. A range error
9134 occurs if x is too large.
9139 The erfc functions return erfc x = 1 - erf x = e-t dt.
9149 7.12.8.3 The lgamma functions
9152 double lgamma(double x);
9153 float lgammaf(float x);
9154 long double lgammal(long double x);
9156 2 The lgamma functions compute the natural logarithm of the absolute value of gamma of
9157 x. A range error occurs if x is too large. A range error may occur if x is a negative
9160 3 The lgamma functions return loge | (Gamma)(x) |.
9161 7.12.8.4 The tgamma functions
9164 double tgamma(double x);
9165 float tgammaf(float x);
9166 long double tgammal(long double x);
9168 2 The tgamma functions compute the gamma function of x. A domain error or range error
9169 may occur if x is a negative integer or zero. A range error may occur if the magnitude of
9170 x is too large or too small.
9172 3 The tgamma functions return (Gamma)(x).
9173 7.12.9 Nearest integer functions
9174 7.12.9.1 The ceil functions
9177 double ceil(double x);
9178 float ceilf(float x);
9179 long double ceill(long double x);
9181 2 The ceil functions compute the smallest integer value not less than x.
9186 3 The ceil functions return ???x???, expressed as a floating-point number.
9187 7.12.9.2 The floor functions
9190 double floor(double x);
9191 float floorf(float x);
9192 long double floorl(long double x);
9194 2 The floor functions compute the largest integer value not greater than x.
9196 3 The floor functions return ???x???, expressed as a floating-point number.
9197 7.12.9.3 The nearbyint functions
9200 double nearbyint(double x);
9201 float nearbyintf(float x);
9202 long double nearbyintl(long double x);
9204 2 The nearbyint functions round their argument to an integer value in floating-point
9205 format, using the current rounding direction and without raising the ''inexact'' floating-
9208 3 The nearbyint functions return the rounded integer value.
9209 7.12.9.4 The rint functions
9212 double rint(double x);
9213 float rintf(float x);
9214 long double rintl(long double x);
9216 2 The rint functions differ from the nearbyint functions (7.12.9.3) only in that the
9217 rint functions may raise the ''inexact'' floating-point exception if the result differs in
9218 value from the argument.
9223 3 The rint functions return the rounded integer value.
9224 7.12.9.5 The lrint and llrint functions
9227 long int lrint(double x);
9228 long int lrintf(float x);
9229 long int lrintl(long double x);
9230 long long int llrint(double x);
9231 long long int llrintf(float x);
9232 long long int llrintl(long double x);
9234 2 The lrint and llrint functions round their argument to the nearest integer value,
9235 rounding according to the current rounding direction. If the rounded value is outside the
9236 range of the return type, the numeric result is unspecified and a domain error or range
9239 3 The lrint and llrint functions return the rounded integer value.
9240 7.12.9.6 The round functions
9243 double round(double x);
9244 float roundf(float x);
9245 long double roundl(long double x);
9247 2 The round functions round their argument to the nearest integer value in floating-point
9248 format, rounding halfway cases away from zero, regardless of the current rounding
9251 3 The round functions return the rounded integer value.
9255 7.12.9.7 The lround and llround functions
9258 long int lround(double x);
9259 long int lroundf(float x);
9260 long int lroundl(long double x);
9261 long long int llround(double x);
9262 long long int llroundf(float x);
9263 long long int llroundl(long double x);
9265 2 The lround and llround functions round their argument to the nearest integer value,
9266 rounding halfway cases away from zero, regardless of the current rounding direction. If
9267 the rounded value is outside the range of the return type, the numeric result is unspecified
9268 and a domain error or range error may occur.
9270 3 The lround and llround functions return the rounded integer value.
9271 7.12.9.8 The trunc functions
9274 double trunc(double x);
9275 float truncf(float x);
9276 long double truncl(long double x);
9278 2 The trunc functions round their argument to the integer value, in floating format,
9279 nearest to but no larger in magnitude than the argument.
9281 3 The trunc functions return the truncated integer value.
9285 7.12.10 Remainder functions
9286 7.12.10.1 The fmod functions
9289 double fmod(double x, double y);
9290 float fmodf(float x, float y);
9291 long double fmodl(long double x, long double y);
9293 2 The fmod functions compute the floating-point remainder of x/y.
9295 3 The fmod functions return the value x - ny, for some integer n such that, if y is nonzero,
9296 the result has the same sign as x and magnitude less than the magnitude of y. If y is zero,
9297 whether a domain error occurs or the fmod functions return zero is implementation-
9299 7.12.10.2 The remainder functions
9302 double remainder(double x, double y);
9303 float remainderf(float x, float y);
9304 long double remainderl(long double x, long double y);
9306 2 The remainder functions compute the remainder x REM y required by IEC 60559.210)
9308 3 The remainder functions return x REM y. If y is zero, whether a domain error occurs
9309 or the functions return zero is implementation defined.
9314 210) ''When y != 0, the remainder r = x REM y is defined regardless of the rounding mode by the
9315 mathematical relation r = x - ny, where n is the integer nearest the exact value of x/y; whenever
9316 | n - x/y | = 1/2, then n is even. Thus, the remainder is always exact. If r = 0, its sign shall be that of
9317 x.'' This definition is applicable for all implementations.
9321 7.12.10.3 The remquo functions
9324 double remquo(double x, double y, int *quo);
9325 float remquof(float x, float y, int *quo);
9326 long double remquol(long double x, long double y,
9329 2 The remquo functions compute the same remainder as the remainder functions. In
9330 the object pointed to by quo they store a value whose sign is the sign of x/y and whose
9331 magnitude is congruent modulo 2n to the magnitude of the integral quotient of x/y, where
9332 n is an implementation-defined integer greater than or equal to 3.
9334 3 The remquo functions return x REM y. If y is zero, the value stored in the object
9335 pointed to by quo is unspecified and whether a domain error occurs or the functions
9336 return zero is implementation defined.
9337 7.12.11 Manipulation functions
9338 7.12.11.1 The copysign functions
9341 double copysign(double x, double y);
9342 float copysignf(float x, float y);
9343 long double copysignl(long double x, long double y);
9345 2 The copysign functions produce a value with the magnitude of x and the sign of y.
9346 They produce a NaN (with the sign of y) if x is a NaN. On implementations that
9347 represent a signed zero but do not treat negative zero consistently in arithmetic
9348 operations, the copysign functions regard the sign of zero as positive.
9350 3 The copysign functions return a value with the magnitude of x and the sign of y.
9354 7.12.11.2 The nan functions
9357 double nan(const char *tagp);
9358 float nanf(const char *tagp);
9359 long double nanl(const char *tagp);
9361 2 The call nan("n-char-sequence") is equivalent to strtod("NAN(n-char-
9362 sequence)", (char**) NULL); the call nan("") is equivalent to
9363 strtod("NAN()", (char**) NULL). If tagp does not point to an n-char
9364 sequence or an empty string, the call is equivalent to strtod("NAN", (char**)
9365 NULL). Calls to nanf and nanl are equivalent to the corresponding calls to strtof
9368 3 The nan functions return a quiet NaN, if available, with content indicated through tagp.
9369 If the implementation does not support quiet NaNs, the functions return zero.
9370 Forward references: the strtod, strtof, and strtold functions (7.20.1.3).
9371 7.12.11.3 The nextafter functions
9374 double nextafter(double x, double y);
9375 float nextafterf(float x, float y);
9376 long double nextafterl(long double x, long double y);
9378 2 The nextafter functions determine the next representable value, in the type of the
9379 function, after x in the direction of y, where x and y are first converted to the type of the
9380 function.211) The nextafter functions return y if x equals y. A range error may occur
9381 if the magnitude of x is the largest finite value representable in the type and the result is
9382 infinite or not representable in the type.
9384 3 The nextafter functions return the next representable value in the specified format
9385 after x in the direction of y.
9388 211) The argument values are converted to the type of the function, even by a macro implementation of the
9393 7.12.11.4 The nexttoward functions
9396 double nexttoward(double x, long double y);
9397 float nexttowardf(float x, long double y);
9398 long double nexttowardl(long double x, long double y);
9400 2 The nexttoward functions are equivalent to the nextafter functions except that the
9401 second parameter has type long double and the functions return y converted to the
9402 type of the function if x equals y.212)
9403 7.12.12 Maximum, minimum, and positive difference functions
9404 7.12.12.1 The fdim functions
9407 double fdim(double x, double y);
9408 float fdimf(float x, float y);
9409 long double fdiml(long double x, long double y);
9411 2 The fdim functions determine the positive difference between their arguments:
9415 A range error may occur.
9417 3 The fdim functions return the positive difference value.
9418 7.12.12.2 The fmax functions
9421 double fmax(double x, double y);
9422 float fmaxf(float x, float y);
9423 long double fmaxl(long double x, long double y);
9427 212) The result of the nexttoward functions is determined in the type of the function, without loss of
9428 range or precision in a floating second argument.
9433 2 The fmax functions determine the maximum numeric value of their arguments.213)
9435 3 The fmax functions return the maximum numeric value of their arguments.
9436 7.12.12.3 The fmin functions
9439 double fmin(double x, double y);
9440 float fminf(float x, float y);
9441 long double fminl(long double x, long double y);
9443 2 The fmin functions determine the minimum numeric value of their arguments.214)
9445 3 The fmin functions return the minimum numeric value of their arguments.
9446 7.12.13 Floating multiply-add
9447 7.12.13.1 The fma functions
9450 double fma(double x, double y, double z);
9451 float fmaf(float x, float y, float z);
9452 long double fmal(long double x, long double y,
9455 2 The fma functions compute (x x y) + z, rounded as one ternary operation: they compute
9456 the value (as if) to infinite precision and round once to the result format, according to the
9457 current rounding mode. A range error may occur.
9459 3 The fma functions return (x x y) + z, rounded as one ternary operation.
9464 213) NaN arguments are treated as missing data: if one argument is a NaN and the other numeric, then the
9465 fmax functions choose the numeric value. See F.9.9.2.
9466 214) The fmin functions are analogous to the fmax functions in their treatment of NaNs.
9470 7.12.14 Comparison macros
9471 1 The relational and equality operators support the usual mathematical relationships
9472 between numeric values. For any ordered pair of numeric values exactly one of the
9473 relationships -- less, greater, and equal -- is true. Relational operators may raise the
9474 ''invalid'' floating-point exception when argument values are NaNs. For a NaN and a
9475 numeric value, or for two NaNs, just the unordered relationship is true.215) The following
9476 subclauses provide macros that are quiet (non floating-point exception raising) versions
9477 of the relational operators, and other comparison macros that facilitate writing efficient
9478 code that accounts for NaNs without suffering the ''invalid'' floating-point exception. In
9479 the synopses in this subclause, real-floating indicates that the argument shall be an
9480 expression of real floating type.
9481 7.12.14.1 The isgreater macro
9484 int isgreater(real-floating x, real-floating y);
9486 2 The isgreater macro determines whether its first argument is greater than its second
9487 argument. The value of isgreater(x, y) is always equal to (x) > (y); however,
9488 unlike (x) > (y), isgreater(x, y) does not raise the ''invalid'' floating-point
9489 exception when x and y are unordered.
9491 3 The isgreater macro returns the value of (x) > (y).
9492 7.12.14.2 The isgreaterequal macro
9495 int isgreaterequal(real-floating x, real-floating y);
9497 2 The isgreaterequal macro determines whether its first argument is greater than or
9498 equal to its second argument. The value of isgreaterequal(x, y) is always equal
9499 to (x) >= (y); however, unlike (x) >= (y), isgreaterequal(x, y) does
9500 not raise the ''invalid'' floating-point exception when x and y are unordered.
9504 215) IEC 60559 requires that the built-in relational operators raise the ''invalid'' floating-point exception if
9505 the operands compare unordered, as an error indicator for programs written without consideration of
9506 NaNs; the result in these cases is false.
9511 3 The isgreaterequal macro returns the value of (x) >= (y).
9512 7.12.14.3 The isless macro
9515 int isless(real-floating x, real-floating y);
9517 2 The isless macro determines whether its first argument is less than its second
9518 argument. The value of isless(x, y) is always equal to (x) < (y); however,
9519 unlike (x) < (y), isless(x, y) does not raise the ''invalid'' floating-point
9520 exception when x and y are unordered.
9522 3 The isless macro returns the value of (x) < (y).
9523 7.12.14.4 The islessequal macro
9526 int islessequal(real-floating x, real-floating y);
9528 2 The islessequal macro determines whether its first argument is less than or equal to
9529 its second argument. The value of islessequal(x, y) is always equal to
9530 (x) <= (y); however, unlike (x) <= (y), islessequal(x, y) does not raise
9531 the ''invalid'' floating-point exception when x and y are unordered.
9533 3 The islessequal macro returns the value of (x) <= (y).
9534 7.12.14.5 The islessgreater macro
9537 int islessgreater(real-floating x, real-floating y);
9539 2 The islessgreater macro determines whether its first argument is less than or
9540 greater than its second argument. The islessgreater(x, y) macro is similar to
9541 (x) < (y) || (x) > (y); however, islessgreater(x, y) does not raise
9542 the ''invalid'' floating-point exception when x and y are unordered (nor does it evaluate x
9548 3 The islessgreater macro returns the value of (x) < (y) || (x) > (y).
9549 7.12.14.6 The isunordered macro
9552 int isunordered(real-floating x, real-floating y);
9554 2 The isunordered macro determines whether its arguments are unordered.
9556 3 The isunordered macro returns 1 if its arguments are unordered and 0 otherwise.
9560 7.13 Nonlocal jumps <setjmp.h>
9561 1 The header <setjmp.h> defines the macro setjmp, and declares one function and
9562 one type, for bypassing the normal function call and return discipline.216)
9563 2 The type declared is
9565 which is an array type suitable for holding the information needed to restore a calling
9566 environment. The environment of a call to the setjmp macro consists of information
9567 sufficient for a call to the longjmp function to return execution to the correct block and
9568 invocation of that block, were it called recursively. It does not include the state of the
9569 floating-point status flags, of open files, or of any other component of the abstract
9571 3 It is unspecified whether setjmp is a macro or an identifier declared with external
9572 linkage. If a macro definition is suppressed in order to access an actual function, or a
9573 program defines an external identifier with the name setjmp, the behavior is undefined.
9574 7.13.1 Save calling environment
9575 7.13.1.1 The setjmp macro
9577 1 #include <setjmp.h>
9578 int setjmp(jmp_buf env);
9580 2 The setjmp macro saves its calling environment in its jmp_buf argument for later use
9581 by the longjmp function.
9583 3 If the return is from a direct invocation, the setjmp macro returns the value zero. If the
9584 return is from a call to the longjmp function, the setjmp macro returns a nonzero
9586 Environmental limits
9587 4 An invocation of the setjmp macro shall appear only in one of the following contexts:
9588 -- the entire controlling expression of a selection or iteration statement;
9589 -- one operand of a relational or equality operator with the other operand an integer
9590 constant expression, with the resulting expression being the entire controlling
9593 216) These functions are useful for dealing with unusual conditions encountered in a low-level function of
9598 expression of a selection or iteration statement;
9599 -- the operand of a unary ! operator with the resulting expression being the entire
9600 controlling expression of a selection or iteration statement; or
9601 -- the entire expression of an expression statement (possibly cast to void).
9602 5 If the invocation appears in any other context, the behavior is undefined.
9603 7.13.2 Restore calling environment
9604 7.13.2.1 The longjmp function
9606 1 #include <setjmp.h>
9607 void longjmp(jmp_buf env, int val);
9609 2 The longjmp function restores the environment saved by the most recent invocation of
9610 the setjmp macro in the same invocation of the program with the corresponding
9611 jmp_buf argument. If there has been no such invocation, or if the function containing
9612 the invocation of the setjmp macro has terminated execution217) in the interim, or if the
9613 invocation of the setjmp macro was within the scope of an identifier with variably
9614 modified type and execution has left that scope in the interim, the behavior is undefined.
9615 3 All accessible objects have values, and all other components of the abstract machine218)
9616 have state, as of the time the longjmp function was called, except that the values of
9617 objects of automatic storage duration that are local to the function containing the
9618 invocation of the corresponding setjmp macro that do not have volatile-qualified type
9619 and have been changed between the setjmp invocation and longjmp call are
9622 4 After longjmp is completed, program execution continues as if the corresponding
9623 invocation of the setjmp macro had just returned the value specified by val. The
9624 longjmp function cannot cause the setjmp macro to return the value 0; if val is 0,
9625 the setjmp macro returns the value 1.
9626 5 EXAMPLE The longjmp function that returns control back to the point of the setjmp invocation
9627 might cause memory associated with a variable length array object to be squandered.
9632 217) For example, by executing a return statement or because another longjmp call has caused a
9633 transfer to a setjmp invocation in a function earlier in the set of nested calls.
9634 218) This includes, but is not limited to, the floating-point status flags and the state of open files.
9645 int x[n]; // valid: f is not terminated
9651 int a[n]; // a may remain allocated
9656 int b[n]; // b may remain allocated
9657 longjmp(buf, 2); // might cause memory loss
9662 7.14 Signal handling <signal.h>
9663 1 The header <signal.h> declares a type and two functions and defines several macros,
9664 for handling various signals (conditions that may be reported during program execution).
9665 2 The type defined is
9667 which is the (possibly volatile-qualified) integer type of an object that can be accessed as
9668 an atomic entity, even in the presence of asynchronous interrupts.
9669 3 The macros defined are
9673 which expand to constant expressions with distinct values that have type compatible with
9674 the second argument to, and the return value of, the signal function, and whose values
9675 compare unequal to the address of any declarable function; and the following, which
9676 expand to positive integer constant expressions with type int and distinct values that are
9677 the signal numbers, each corresponding to the specified condition:
9678 SIGABRT abnormal termination, such as is initiated by the abort function
9679 SIGFPE an erroneous arithmetic operation, such as zero divide or an operation
9680 resulting in overflow
9681 SIGILL detection of an invalid function image, such as an invalid instruction
9682 SIGINT receipt of an interactive attention signal
9683 SIGSEGV an invalid access to storage
9684 SIGTERM a termination request sent to the program
9685 4 An implementation need not generate any of these signals, except as a result of explicit
9686 calls to the raise function. Additional signals and pointers to undeclarable functions,
9687 with macro definitions beginning, respectively, with the letters SIG and an uppercase
9688 letter or with SIG_ and an uppercase letter,219) may also be specified by the
9689 implementation. The complete set of signals, their semantics, and their default handling
9690 is implementation-defined; all signal numbers shall be positive.
9695 219) See ''future library directions'' (7.26.9). The names of the signal numbers reflect the following terms
9696 (respectively): abort, floating-point exception, illegal instruction, interrupt, segmentation violation,
9701 7.14.1 Specify signal handling
9702 7.14.1.1 The signal function
9704 1 #include <signal.h>
9705 void (*signal(int sig, void (*func)(int)))(int);
9707 2 The signal function chooses one of three ways in which receipt of the signal number
9708 sig is to be subsequently handled. If the value of func is SIG_DFL, default handling
9709 for that signal will occur. If the value of func is SIG_IGN, the signal will be ignored.
9710 Otherwise, func shall point to a function to be called when that signal occurs. An
9711 invocation of such a function because of a signal, or (recursively) of any further functions
9712 called by that invocation (other than functions in the standard library), is called a signal
9714 3 When a signal occurs and func points to a function, it is implementation-defined
9715 whether the equivalent of signal(sig, SIG_DFL); is executed or the
9716 implementation prevents some implementation-defined set of signals (at least including
9717 sig) from occurring until the current signal handling has completed; in the case of
9718 SIGILL, the implementation may alternatively define that no action is taken. Then the
9719 equivalent of (*func)(sig); is executed. If and when the function returns, if the
9720 value of sig is SIGFPE, SIGILL, SIGSEGV, or any other implementation-defined
9721 value corresponding to a computational exception, the behavior is undefined; otherwise
9722 the program will resume execution at the point it was interrupted.
9723 4 If the signal occurs as the result of calling the abort or raise function, the signal
9724 handler shall not call the raise function.
9725 5 If the signal occurs other than as the result of calling the abort or raise function, the
9726 behavior is undefined if the signal handler refers to any object with static storage duration
9727 other than by assigning a value to an object declared as volatile sig_atomic_t, or
9728 the signal handler calls any function in the standard library other than the abort
9729 function, the _Exit function, or the signal function with the first argument equal to
9730 the signal number corresponding to the signal that caused the invocation of the handler.
9731 Furthermore, if such a call to the signal function results in a SIG_ERR return, the
9732 value of errno is indeterminate.220)
9733 6 At program startup, the equivalent of
9734 signal(sig, SIG_IGN);
9737 220) If any signal is generated by an asynchronous signal handler, the behavior is undefined.
9741 may be executed for some signals selected in an implementation-defined manner; the
9743 signal(sig, SIG_DFL);
9744 is executed for all other signals defined by the implementation.
9745 7 The implementation shall behave as if no library function calls the signal function.
9747 8 If the request can be honored, the signal function returns the value of func for the
9748 most recent successful call to signal for the specified signal sig. Otherwise, a value of
9749 SIG_ERR is returned and a positive value is stored in errno.
9750 Forward references: the abort function (7.20.4.1), the exit function (7.20.4.3), the
9751 _Exit function (7.20.4.4).
9753 7.14.2.1 The raise function
9755 1 #include <signal.h>
9758 2 The raise function carries out the actions described in 7.14.1.1 for the signal sig. If a
9759 signal handler is called, the raise function shall not return until after the signal handler
9762 3 The raise function returns zero if successful, nonzero if unsuccessful.
9766 7.15 Variable arguments <stdarg.h>
9767 1 The header <stdarg.h> declares a type and defines four macros, for advancing
9768 through a list of arguments whose number and types are not known to the called function
9769 when it is translated.
9770 2 A function may be called with a variable number of arguments of varying types. As
9771 described in 6.9.1, its parameter list contains one or more parameters. The rightmost
9772 parameter plays a special role in the access mechanism, and will be designated parmN in
9774 3 The type declared is
9776 which is an object type suitable for holding information needed by the macros
9777 va_start, va_arg, va_end, and va_copy. If access to the varying arguments is
9778 desired, the called function shall declare an object (generally referred to as ap in this
9779 subclause) having type va_list. The object ap may be passed as an argument to
9780 another function; if that function invokes the va_arg macro with parameter ap, the
9781 value of ap in the calling function is indeterminate and shall be passed to the va_end
9782 macro prior to any further reference to ap.221)
9783 7.15.1 Variable argument list access macros
9784 1 The va_start and va_arg macros described in this subclause shall be implemented
9785 as macros, not functions. It is unspecified whether va_copy and va_end are macros or
9786 identifiers declared with external linkage. If a macro definition is suppressed in order to
9787 access an actual function, or a program defines an external identifier with the same name,
9788 the behavior is undefined. Each invocation of the va_start and va_copy macros
9789 shall be matched by a corresponding invocation of the va_end macro in the same
9791 7.15.1.1 The va_arg macro
9793 1 #include <stdarg.h>
9794 type va_arg(va_list ap, type);
9796 2 The va_arg macro expands to an expression that has the specified type and the value of
9797 the next argument in the call. The parameter ap shall have been initialized by the
9798 va_start or va_copy macro (without an intervening invocation of the va_end
9800 221) It is permitted to create a pointer to a va_list and pass that pointer to another function, in which
9801 case the original function may make further use of the original list after the other function returns.
9805 macro for the same ap). Each invocation of the va_arg macro modifies ap so that the
9806 values of successive arguments are returned in turn. The parameter type shall be a type
9807 name specified such that the type of a pointer to an object that has the specified type can
9808 be obtained simply by postfixing a * to type. If there is no actual next argument, or if
9809 type is not compatible with the type of the actual next argument (as promoted according
9810 to the default argument promotions), the behavior is undefined, except for the following
9812 -- one type is a signed integer type, the other type is the corresponding unsigned integer
9813 type, and the value is representable in both types;
9814 -- one type is pointer to void and the other is a pointer to a character type.
9816 3 The first invocation of the va_arg macro after that of the va_start macro returns the
9817 value of the argument after that specified by parmN . Successive invocations return the
9818 values of the remaining arguments in succession.
9819 7.15.1.2 The va_copy macro
9821 1 #include <stdarg.h>
9822 void va_copy(va_list dest, va_list src);
9824 2 The va_copy macro initializes dest as a copy of src, as if the va_start macro had
9825 been applied to dest followed by the same sequence of uses of the va_arg macro as
9826 had previously been used to reach the present state of src. Neither the va_copy nor
9827 va_start macro shall be invoked to reinitialize dest without an intervening
9828 invocation of the va_end macro for the same dest.
9830 3 The va_copy macro returns no value.
9831 7.15.1.3 The va_end macro
9833 1 #include <stdarg.h>
9834 void va_end(va_list ap);
9836 2 The va_end macro facilitates a normal return from the function whose variable
9837 argument list was referred to by the expansion of the va_start macro, or the function
9838 containing the expansion of the va_copy macro, that initialized the va_list ap. The
9839 va_end macro may modify ap so that it is no longer usable (without being reinitialized
9843 by the va_start or va_copy macro). If there is no corresponding invocation of the
9844 va_start or va_copy macro, or if the va_end macro is not invoked before the
9845 return, the behavior is undefined.
9847 3 The va_end macro returns no value.
9848 7.15.1.4 The va_start macro
9850 1 #include <stdarg.h>
9851 void va_start(va_list ap, parmN);
9853 2 The va_start macro shall be invoked before any access to the unnamed arguments.
9854 3 The va_start macro initializes ap for subsequent use by the va_arg and va_end
9855 macros. Neither the va_start nor va_copy macro shall be invoked to reinitialize ap
9856 without an intervening invocation of the va_end macro for the same ap.
9857 4 The parameter parmN is the identifier of the rightmost parameter in the variable
9858 parameter list in the function definition (the one just before the , ...). If the parameter
9859 parmN is declared with the register storage class, with a function or array type, or
9860 with a type that is not compatible with the type that results after application of the default
9861 argument promotions, the behavior is undefined.
9863 5 The va_start macro returns no value.
9864 6 EXAMPLE 1 The function f1 gathers into an array a list of arguments that are pointers to strings (but not
9865 more than MAXARGS arguments), then passes the array as a single argument to function f2. The number of
9866 pointers is specified by the first argument to f1.
9869 void f1(int n_ptrs, ...)
9872 char *array[MAXARGS];
9877 if (n_ptrs > MAXARGS)
9879 va_start(ap, n_ptrs);
9880 while (ptr_no < n_ptrs)
9881 array[ptr_no++] = va_arg(ap, char *);
9885 Each call to f1 is required to have visible the definition of the function or a declaration such as
9888 7 EXAMPLE 2 The function f3 is similar, but saves the status of the variable argument list after the
9889 indicated number of arguments; after f2 has been called once with the whole list, the trailing part of the list
9890 is gathered again and passed to function f4.
9893 void f3(int n_ptrs, int f4_after, ...)
9895 va_list ap, ap_save;
9896 char *array[MAXARGS];
9898 if (n_ptrs > MAXARGS)
9900 va_start(ap, f4_after);
9901 while (ptr_no < n_ptrs) {
9902 array[ptr_no++] = va_arg(ap, char *);
9903 if (ptr_no == f4_after)
9904 va_copy(ap_save, ap);
9908 // Now process the saved copy.
9911 while (ptr_no < n_ptrs)
9912 array[ptr_no++] = va_arg(ap_save, char *);
9919 7.16 Boolean type and values <stdbool.h>
9920 1 The header <stdbool.h> defines four macros.
9924 3 The remaining three macros are suitable for use in #if preprocessing directives. They
9927 which expands to the integer constant 1,
9929 which expands to the integer constant 0, and
9930 __bool_true_false_are_defined
9931 which expands to the integer constant 1.
9932 4 Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then
9933 redefine the macros bool, true, and false.222)
9938 222) See ''future library directions'' (7.26.7).
9942 7.17 Common definitions <stddef.h>
9943 1 The following types and macros are defined in the standard header <stddef.h>. Some
9944 are also defined in other headers, as noted in their respective subclauses.
9947 which is the signed integer type of the result of subtracting two pointers;
9949 which is the unsigned integer type of the result of the sizeof operator; and
9951 which is an integer type whose range of values can represent distinct codes for all
9952 members of the largest extended character set specified among the supported locales; the
9953 null character shall have the code value zero. Each member of the basic character set
9954 shall have a code value equal to its value when used as the lone character in an integer
9955 character constant if an implementation does not define
9956 __STDC_MB_MIGHT_NEQ_WC__.
9959 which expands to an implementation-defined null pointer constant; and
9960 offsetof(type, member-designator)
9961 which expands to an integer constant expression that has type size_t, the value of
9962 which is the offset in bytes, to the structure member (designated by member-designator),
9963 from the beginning of its structure (designated by type). The type and member designator
9964 shall be such that given
9966 then the expression &(t.member-designator) evaluates to an address constant. (If the
9967 specified member is a bit-field, the behavior is undefined.)
9968 Recommended practice
9969 4 The types used for size_t and ptrdiff_t should not have an integer conversion rank
9970 greater than that of signed long int unless the implementation supports objects
9971 large enough to make this necessary.
9972 Forward references: localization (7.11).
9976 7.18 Integer types <stdint.h>
9977 1 The header <stdint.h> declares sets of integer types having specified widths, and
9978 defines corresponding sets of macros.223) It also defines macros that specify limits of
9979 integer types corresponding to types defined in other standard headers.
9980 2 Types are defined in the following categories:
9981 -- integer types having certain exact widths;
9982 -- integer types having at least certain specified widths;
9983 -- fastest integer types having at least certain specified widths;
9984 -- integer types wide enough to hold pointers to objects;
9985 -- integer types having greatest width.
9986 (Some of these types may denote the same type.)
9987 3 Corresponding macros specify limits of the declared types and construct suitable
9989 4 For each type described herein that the implementation provides,224) <stdint.h> shall
9990 declare that typedef name and define the associated macros. Conversely, for each type
9991 described herein that the implementation does not provide, <stdint.h> shall not
9992 declare that typedef name nor shall it define the associated macros. An implementation
9993 shall provide those types described as ''required'', but need not provide any of the others
9994 (described as ''optional'').
9995 7.18.1 Integer types
9996 1 When typedef names differing only in the absence or presence of the initial u are defined,
9997 they shall denote corresponding signed and unsigned types as described in 6.2.5; an
9998 implementation providing one of these corresponding types shall also provide the other.
9999 2 In the following descriptions, the symbol N represents an unsigned decimal integer with
10000 no leading zeros (e.g., 8 or 24, but not 04 or 048).
10005 223) See ''future library directions'' (7.26.8).
10006 224) Some of these types may denote implementation-defined extended integer types.
10010 7.18.1.1 Exact-width integer types
10011 1 The typedef name intN_t designates a signed integer type with width N , no padding
10012 bits, and a two's complement representation. Thus, int8_t denotes a signed integer
10013 type with a width of exactly 8 bits.
10014 2 The typedef name uintN_t designates an unsigned integer type with width N . Thus,
10015 uint24_t denotes an unsigned integer type with a width of exactly 24 bits.
10016 3 These types are optional. However, if an implementation provides integer types with
10017 widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a
10018 two's complement representation, it shall define the corresponding typedef names.
10019 7.18.1.2 Minimum-width integer types
10020 1 The typedef name int_leastN_t designates a signed integer type with a width of at
10021 least N , such that no signed integer type with lesser size has at least the specified width.
10022 Thus, int_least32_t denotes a signed integer type with a width of at least 32 bits.
10023 2 The typedef name uint_leastN_t designates an unsigned integer type with a width
10024 of at least N , such that no unsigned integer type with lesser size has at least the specified
10025 width. Thus, uint_least16_t denotes an unsigned integer type with a width of at
10027 3 The following types are required:
10028 int_least8_t uint_least8_t
10029 int_least16_t uint_least16_t
10030 int_least32_t uint_least32_t
10031 int_least64_t uint_least64_t
10032 All other types of this form are optional.
10033 7.18.1.3 Fastest minimum-width integer types
10034 1 Each of the following types designates an integer type that is usually fastest225) to operate
10035 with among all integer types that have at least the specified width.
10036 2 The typedef name int_fastN_t designates the fastest signed integer type with a width
10037 of at least N . The typedef name uint_fastN_t designates the fastest unsigned integer
10038 type with a width of at least N .
10043 225) The designated type is not guaranteed to be fastest for all purposes; if the implementation has no clear
10044 grounds for choosing one type over another, it will simply pick some integer type satisfying the
10045 signedness and width requirements.
10049 3 The following types are required:
10050 int_fast8_t uint_fast8_t
10051 int_fast16_t uint_fast16_t
10052 int_fast32_t uint_fast32_t
10053 int_fast64_t uint_fast64_t
10054 All other types of this form are optional.
10055 7.18.1.4 Integer types capable of holding object pointers
10056 1 The following type designates a signed integer type with the property that any valid
10057 pointer to void can be converted to this type, then converted back to pointer to void,
10058 and the result will compare equal to the original pointer:
10060 The following type designates an unsigned integer type with the property that any valid
10061 pointer to void can be converted to this type, then converted back to pointer to void,
10062 and the result will compare equal to the original pointer:
10064 These types are optional.
10065 7.18.1.5 Greatest-width integer types
10066 1 The following type designates a signed integer type capable of representing any value of
10067 any signed integer type:
10069 The following type designates an unsigned integer type capable of representing any value
10070 of any unsigned integer type:
10072 These types are required.
10073 7.18.2 Limits of specified-width integer types
10074 1 The following object-like macros226) specify the minimum and maximum limits of the
10075 types declared in <stdint.h>. Each macro name corresponds to a similar type name in
10077 2 Each instance of any defined macro shall be replaced by a constant expression suitable
10078 for use in #if preprocessing directives, and this expression shall have the same type as
10079 would an expression that is an object of the corresponding type converted according to
10081 226) C++ implementations should define these macros only when __STDC_LIMIT_MACROS is defined
10082 before <stdint.h> is included.
10086 the integer promotions. Its implementation-defined value shall be equal to or greater in
10087 magnitude (absolute value) than the corresponding value given below, with the same sign,
10088 except where stated to be exactly the given value.
10089 7.18.2.1 Limits of exact-width integer types
10090 1 -- minimum values of exact-width signed integer types
10091 INTN_MIN exactly -(2 N -1 )
10092 -- maximum values of exact-width signed integer types
10093 INTN_MAX exactly 2 N -1 - 1
10094 -- maximum values of exact-width unsigned integer types
10095 UINTN_MAX exactly 2 N - 1
10096 7.18.2.2 Limits of minimum-width integer types
10097 1 -- minimum values of minimum-width signed integer types
10098 INT_LEASTN_MIN -(2 N -1 - 1)
10099 -- maximum values of minimum-width signed integer types
10100 INT_LEASTN_MAX 2 N -1 - 1
10101 -- maximum values of minimum-width unsigned integer types
10102 UINT_LEASTN_MAX 2N - 1
10103 7.18.2.3 Limits of fastest minimum-width integer types
10104 1 -- minimum values of fastest minimum-width signed integer types
10105 INT_FASTN_MIN -(2 N -1 - 1)
10106 -- maximum values of fastest minimum-width signed integer types
10107 INT_FASTN_MAX 2 N -1 - 1
10108 -- maximum values of fastest minimum-width unsigned integer types
10109 UINT_FASTN_MAX 2N - 1
10110 7.18.2.4 Limits of integer types capable of holding object pointers
10111 1 -- minimum value of pointer-holding signed integer type
10112 INTPTR_MIN -(215 - 1)
10113 -- maximum value of pointer-holding signed integer type
10118 -- maximum value of pointer-holding unsigned integer type
10119 UINTPTR_MAX 216 - 1
10120 7.18.2.5 Limits of greatest-width integer types
10121 1 -- minimum value of greatest-width signed integer type
10122 INTMAX_MIN -(263 - 1)
10123 -- maximum value of greatest-width signed integer type
10125 -- maximum value of greatest-width unsigned integer type
10126 UINTMAX_MAX 264 - 1
10127 7.18.3 Limits of other integer types
10128 1 The following object-like macros227) specify the minimum and maximum limits of
10129 integer types corresponding to types defined in other standard headers.
10130 2 Each instance of these macros shall be replaced by a constant expression suitable for use
10131 in #if preprocessing directives, and this expression shall have the same type as would an
10132 expression that is an object of the corresponding type converted according to the integer
10133 promotions. Its implementation-defined value shall be equal to or greater in magnitude
10134 (absolute value) than the corresponding value given below, with the same sign. An
10135 implementation shall define only the macros corresponding to those typedef names it
10136 actually provides.228)
10137 -- limits of ptrdiff_t
10140 -- limits of sig_atomic_t
10141 SIG_ATOMIC_MIN see below
10142 SIG_ATOMIC_MAX see below
10145 -- limits of wchar_t
10149 227) C++ implementations should define these macros only when __STDC_LIMIT_MACROS is defined
10150 before <stdint.h> is included.
10151 228) A freestanding implementation need not provide all of these types.
10155 WCHAR_MIN see below
10156 WCHAR_MAX see below
10157 -- limits of wint_t
10160 3 If sig_atomic_t (see 7.14) is defined as a signed integer type, the value of
10161 SIG_ATOMIC_MIN shall be no greater than -127 and the value of SIG_ATOMIC_MAX
10162 shall be no less than 127; otherwise, sig_atomic_t is defined as an unsigned integer
10163 type, and the value of SIG_ATOMIC_MIN shall be 0 and the value of
10164 SIG_ATOMIC_MAX shall be no less than 255.
10165 4 If wchar_t (see 7.17) is defined as a signed integer type, the value of WCHAR_MIN
10166 shall be no greater than -127 and the value of WCHAR_MAX shall be no less than 127;
10167 otherwise, wchar_t is defined as an unsigned integer type, and the value of
10168 WCHAR_MIN shall be 0 and the value of WCHAR_MAX shall be no less than 255.229)
10169 5 If wint_t (see 7.24) is defined as a signed integer type, the value of WINT_MIN shall
10170 be no greater than -32767 and the value of WINT_MAX shall be no less than 32767;
10171 otherwise, wint_t is defined as an unsigned integer type, and the value of WINT_MIN
10172 shall be 0 and the value of WINT_MAX shall be no less than 65535.
10173 7.18.4 Macros for integer constants
10174 1 The following function-like macros230) expand to integer constants suitable for
10175 initializing objects that have integer types corresponding to types defined in
10176 <stdint.h>. Each macro name corresponds to a similar type name in 7.18.1.2 or
10178 2 The argument in any instance of these macros shall be an unsuffixed integer constant (as
10179 defined in 6.4.4.1) with a value that does not exceed the limits for the corresponding type.
10180 3 Each invocation of one of these macros shall expand to an integer constant expression
10181 suitable for use in #if preprocessing directives. The type of the expression shall have
10182 the same type as would an expression of the corresponding type converted according to
10183 the integer promotions. The value of the expression shall be that of the argument.
10188 229) The values WCHAR_MIN and WCHAR_MAX do not necessarily correspond to members of the extended
10190 230) C++ implementations should define these macros only when __STDC_CONSTANT_MACROS is
10191 defined before <stdint.h> is included.
10195 7.18.4.1 Macros for minimum-width integer constants
10196 1 The macro INTN_C(value) shall expand to an integer constant expression
10197 corresponding to the type int_leastN_t. The macro UINTN_C(value) shall expand
10198 to an integer constant expression corresponding to the type uint_leastN_t. For
10199 example, if uint_least64_t is a name for the type unsigned long long int,
10200 then UINT64_C(0x123) might expand to the integer constant 0x123ULL.
10201 7.18.4.2 Macros for greatest-width integer constants
10202 1 The following macro expands to an integer constant expression having the value specified
10203 by its argument and the type intmax_t:
10205 The following macro expands to an integer constant expression having the value specified
10206 by its argument and the type uintmax_t:
10211 7.19 Input/output <stdio.h>
10212 7.19.1 Introduction
10213 1 The header <stdio.h> declares three types, several macros, and many functions for
10214 performing input and output.
10215 2 The types declared are size_t (described in 7.17);
10217 which is an object type capable of recording all the information needed to control a
10218 stream, including its file position indicator, a pointer to its associated buffer (if any), an
10219 error indicator that records whether a read/write error has occurred, and an end-of-file
10220 indicator that records whether the end of the file has been reached; and
10222 which is an object type other than an array type capable of recording all the information
10223 needed to specify uniquely every position within a file.
10224 3 The macros are NULL (described in 7.17);
10228 which expand to integer constant expressions with distinct values, suitable for use as the
10229 third argument to the setvbuf function;
10231 which expands to an integer constant expression that is the size of the buffer used by the
10234 which expands to an integer constant expression, with type int and a negative value, that
10235 is returned by several functions to indicate end-of-file, that is, no more input from a
10238 which expands to an integer constant expression that is the minimum number of files that
10239 the implementation guarantees can be open simultaneously;
10241 which expands to an integer constant expression that is the size needed for an array of
10242 char large enough to hold the longest file name string that the implementation
10246 guarantees can be opened;231)
10248 which expands to an integer constant expression that is the size needed for an array of
10249 char large enough to hold a temporary file name string generated by the tmpnam
10254 which expand to integer constant expressions with distinct values, suitable for use as the
10255 third argument to the fseek function;
10257 which expands to an integer constant expression that is the maximum number of unique
10258 file names that can be generated by the tmpnam function;
10262 which are expressions of type ''pointer to FILE'' that point to the FILE objects
10263 associated, respectively, with the standard error, input, and output streams.
10264 4 The header <wchar.h> declares a number of functions useful for wide character input
10265 and output. The wide character input/output functions described in that subclause
10266 provide operations analogous to most of those described here, except that the
10267 fundamental units internal to the program are wide characters. The external
10268 representation (in the file) is a sequence of ''generalized'' multibyte characters, as
10269 described further in 7.19.3.
10270 5 The input/output functions are given the following collective terms:
10271 -- The wide character input functions -- those functions described in 7.24 that perform
10272 input into wide characters and wide strings: fgetwc, fgetws, getwc, getwchar,
10273 fwscanf, wscanf, vfwscanf, and vwscanf.
10274 -- The wide character output functions -- those functions described in 7.24 that perform
10275 output from wide characters and wide strings: fputwc, fputws, putwc,
10276 putwchar, fwprintf, wprintf, vfwprintf, and vwprintf.
10279 231) If the implementation imposes no practical limit on the length of file name strings, the value of
10280 FILENAME_MAX should instead be the recommended size of an array intended to hold a file name
10281 string. Of course, file name string contents are subject to other system-specific constraints; therefore
10282 all possible strings of length FILENAME_MAX cannot be expected to be opened successfully.
10286 -- The wide character input/output functions -- the union of the ungetwc function, the
10287 wide character input functions, and the wide character output functions.
10288 -- The byte input/output functions -- those functions described in this subclause that
10289 perform input/output: fgetc, fgets, fprintf, fputc, fputs, fread,
10290 fscanf, fwrite, getc, getchar, gets, printf, putc, putchar, puts,
10291 scanf, ungetc, vfprintf, vfscanf, vprintf, and vscanf.
10292 Forward references: files (7.19.3), the fseek function (7.19.9.2), streams (7.19.2), the
10293 tmpnam function (7.19.4.4), <wchar.h> (7.24).
10295 1 Input and output, whether to or from physical devices such as terminals and tape drives,
10296 or whether to or from files supported on structured storage devices, are mapped into
10297 logical data streams, whose properties are more uniform than their various inputs and
10298 outputs. Two forms of mapping are supported, for text streams and for binary
10300 2 A text stream is an ordered sequence of characters composed into lines, each line
10301 consisting of zero or more characters plus a terminating new-line character. Whether the
10302 last line requires a terminating new-line character is implementation-defined. Characters
10303 may have to be added, altered, or deleted on input and output to conform to differing
10304 conventions for representing text in the host environment. Thus, there need not be a one-
10305 to-one correspondence between the characters in a stream and those in the external
10306 representation. Data read in from a text stream will necessarily compare equal to the data
10307 that were earlier written out to that stream only if: the data consist only of printing
10308 characters and the control characters horizontal tab and new-line; no new-line character is
10309 immediately preceded by space characters; and the last character is a new-line character.
10310 Whether space characters that are written out immediately before a new-line character
10311 appear when read in is implementation-defined.
10312 3 A binary stream is an ordered sequence of characters that can transparently record
10313 internal data. Data read in from a binary stream shall compare equal to the data that were
10314 earlier written out to that stream, under the same implementation. Such a stream may,
10315 however, have an implementation-defined number of null characters appended to the end
10317 4 Each stream has an orientation. After a stream is associated with an external file, but
10318 before any operations are performed on it, the stream is without orientation. Once a wide
10319 character input/output function has been applied to a stream without orientation, the
10322 232) An implementation need not distinguish between text streams and binary streams. In such an
10323 implementation, there need be no new-line characters in a text stream nor any limit to the length of a
10328 stream becomes a wide-oriented stream. Similarly, once a byte input/output function has
10329 been applied to a stream without orientation, the stream becomes a byte-oriented stream.
10330 Only a call to the freopen function or the fwide function can otherwise alter the
10331 orientation of a stream. (A successful call to freopen removes any orientation.)233)
10332 5 Byte input/output functions shall not be applied to a wide-oriented stream and wide
10333 character input/output functions shall not be applied to a byte-oriented stream. The
10334 remaining stream operations do not affect, and are not affected by, a stream's orientation,
10335 except for the following additional restrictions:
10336 -- Binary wide-oriented streams have the file-positioning restrictions ascribed to both
10337 text and binary streams.
10338 -- For wide-oriented streams, after a successful call to a file-positioning function that
10339 leaves the file position indicator prior to the end-of-file, a wide character output
10340 function can overwrite a partial multibyte character; any file contents beyond the
10341 byte(s) written are henceforth indeterminate.
10342 6 Each wide-oriented stream has an associated mbstate_t object that stores the current
10343 parse state of the stream. A successful call to fgetpos stores a representation of the
10344 value of this mbstate_t object as part of the value of the fpos_t object. A later
10345 successful call to fsetpos using the same stored fpos_t value restores the value of
10346 the associated mbstate_t object as well as the position within the controlled stream.
10347 Environmental limits
10348 7 An implementation shall support text files with lines containing at least 254 characters,
10349 including the terminating new-line character. The value of the macro BUFSIZ shall be at
10351 Forward references: the freopen function (7.19.5.4), the fwide function (7.24.3.5),
10352 mbstate_t (7.25.1), the fgetpos function (7.19.9.1), the fsetpos function
10358 233) The three predefined streams stdin, stdout, and stderr are unoriented at program startup.
10363 1 A stream is associated with an external file (which may be a physical device) by opening
10364 a file, which may involve creating a new file. Creating an existing file causes its former
10365 contents to be discarded, if necessary. If a file can support positioning requests (such as a
10366 disk file, as opposed to a terminal), then a file position indicator associated with the
10367 stream is positioned at the start (character number zero) of the file, unless the file is
10368 opened with append mode in which case it is implementation-defined whether the file
10369 position indicator is initially positioned at the beginning or the end of the file. The file
10370 position indicator is maintained by subsequent reads, writes, and positioning requests, to
10371 facilitate an orderly progression through the file.
10372 2 Binary files are not truncated, except as defined in 7.19.5.3. Whether a write on a text
10373 stream causes the associated file to be truncated beyond that point is implementation-
10375 3 When a stream is unbuffered, characters are intended to appear from the source or at the
10376 destination as soon as possible. Otherwise characters may be accumulated and
10377 transmitted to or from the host environment as a block. When a stream is fully buffered,
10378 characters are intended to be transmitted to or from the host environment as a block when
10379 a buffer is filled. When a stream is line buffered, characters are intended to be
10380 transmitted to or from the host environment as a block when a new-line character is
10381 encountered. Furthermore, characters are intended to be transmitted as a block to the host
10382 environment when a buffer is filled, when input is requested on an unbuffered stream, or
10383 when input is requested on a line buffered stream that requires the transmission of
10384 characters from the host environment. Support for these characteristics is
10385 implementation-defined, and may be affected via the setbuf and setvbuf functions.
10386 4 A file may be disassociated from a controlling stream by closing the file. Output streams
10387 are flushed (any unwritten buffer contents are transmitted to the host environment) before
10388 the stream is disassociated from the file. The value of a pointer to a FILE object is
10389 indeterminate after the associated file is closed (including the standard text streams).
10390 Whether a file of zero length (on which no characters have been written by an output
10391 stream) actually exists is implementation-defined.
10392 5 The file may be subsequently reopened, by the same or another program execution, and
10393 its contents reclaimed or modified (if it can be repositioned at its start). If the main
10394 function returns to its original caller, or if the exit function is called, all open files are
10395 closed (hence all output streams are flushed) before program termination. Other paths to
10396 program termination, such as calling the abort function, need not close all files
10398 6 The address of the FILE object used to control a stream may be significant; a copy of a
10399 FILE object need not serve in place of the original.
10403 7 At program startup, three text streams are predefined and need not be opened explicitly
10404 -- standard input (for reading conventional input), standard output (for writing
10405 conventional output), and standard error (for writing diagnostic output). As initially
10406 opened, the standard error stream is not fully buffered; the standard input and standard
10407 output streams are fully buffered if and only if the stream can be determined not to refer
10408 to an interactive device.
10409 8 Functions that open additional (nontemporary) files require a file name, which is a string.
10410 The rules for composing valid file names are implementation-defined. Whether the same
10411 file can be simultaneously open multiple times is also implementation-defined.
10412 9 Although both text and binary wide-oriented streams are conceptually sequences of wide
10413 characters, the external file associated with a wide-oriented stream is a sequence of
10414 multibyte characters, generalized as follows:
10415 -- Multibyte encodings within files may contain embedded null bytes (unlike multibyte
10416 encodings valid for use internal to the program).
10417 -- A file need not begin nor end in the initial shift state.234)
10418 10 Moreover, the encodings used for multibyte characters may differ among files. Both the
10419 nature and choice of such encodings are implementation-defined.
10420 11 The wide character input functions read multibyte characters from the stream and convert
10421 them to wide characters as if they were read by successive calls to the fgetwc function.
10422 Each conversion occurs as if by a call to the mbrtowc function, with the conversion state
10423 described by the stream's own mbstate_t object. The byte input functions read
10424 characters from the stream as if by successive calls to the fgetc function.
10425 12 The wide character output functions convert wide characters to multibyte characters and
10426 write them to the stream as if they were written by successive calls to the fputwc
10427 function. Each conversion occurs as if by a call to the wcrtomb function, with the
10428 conversion state described by the stream's own mbstate_t object. The byte output
10429 functions write characters to the stream as if by successive calls to the fputc function.
10430 13 In some cases, some of the byte input/output functions also perform conversions between
10431 multibyte characters and wide characters. These conversions also occur as if by calls to
10432 the mbrtowc and wcrtomb functions.
10433 14 An encoding error occurs if the character sequence presented to the underlying
10434 mbrtowc function does not form a valid (generalized) multibyte character, or if the code
10435 value passed to the underlying wcrtomb does not correspond to a valid (generalized)
10438 234) Setting the file position indicator to end-of-file, as with fseek(file, 0, SEEK_END), has
10439 undefined behavior for a binary stream (because of possible trailing null characters) or for any stream
10440 with state-dependent encoding that does not assuredly end in the initial shift state.
10444 multibyte character. The wide character input/output functions and the byte input/output
10445 functions store the value of the macro EILSEQ in errno if and only if an encoding error
10447 Environmental limits
10448 15 The value of FOPEN_MAX shall be at least eight, including the three standard text
10450 Forward references: the exit function (7.20.4.3), the fgetc function (7.19.7.1), the
10451 fopen function (7.19.5.3), the fputc function (7.19.7.3), the setbuf function
10452 (7.19.5.5), the setvbuf function (7.19.5.6), the fgetwc function (7.24.3.1), the
10453 fputwc function (7.24.3.3), conversion state (7.24.6), the mbrtowc function
10454 (7.24.6.3.2), the wcrtomb function (7.24.6.3.3).
10455 7.19.4 Operations on files
10456 7.19.4.1 The remove function
10458 1 #include <stdio.h>
10459 int remove(const char *filename);
10461 2 The remove function causes the file whose name is the string pointed to by filename
10462 to be no longer accessible by that name. A subsequent attempt to open that file using that
10463 name will fail, unless it is created anew. If the file is open, the behavior of the remove
10464 function is implementation-defined.
10466 3 The remove function returns zero if the operation succeeds, nonzero if it fails.
10467 7.19.4.2 The rename function
10469 1 #include <stdio.h>
10470 int rename(const char *old, const char *new);
10472 2 The rename function causes the file whose name is the string pointed to by old to be
10473 henceforth known by the name given by the string pointed to by new. The file named
10474 old is no longer accessible by that name. If a file named by the string pointed to by new
10475 exists prior to the call to the rename function, the behavior is implementation-defined.
10480 3 The rename function returns zero if the operation succeeds, nonzero if it fails,235) in
10481 which case if the file existed previously it is still known by its original name.
10482 7.19.4.3 The tmpfile function
10484 1 #include <stdio.h>
10485 FILE *tmpfile(void);
10487 2 The tmpfile function creates a temporary binary file that is different from any other
10488 existing file and that will automatically be removed when it is closed or at program
10489 termination. If the program terminates abnormally, whether an open temporary file is
10490 removed is implementation-defined. The file is opened for update with "wb+" mode.
10491 Recommended practice
10492 3 It should be possible to open at least TMP_MAX temporary files during the lifetime of the
10493 program (this limit may be shared with tmpnam) and there should be no limit on the
10494 number simultaneously open other than this limit and any limit on the number of open
10497 4 The tmpfile function returns a pointer to the stream of the file that it created. If the file
10498 cannot be created, the tmpfile function returns a null pointer.
10499 Forward references: the fopen function (7.19.5.3).
10500 7.19.4.4 The tmpnam function
10502 1 #include <stdio.h>
10503 char *tmpnam(char *s);
10505 2 The tmpnam function generates a string that is a valid file name and that is not the same
10506 as the name of an existing file.236) The function is potentially capable of generating
10509 235) Among the reasons the implementation may cause the rename function to fail are that the file is open
10510 or that it is necessary to copy its contents to effectuate its renaming.
10511 236) Files created using strings generated by the tmpnam function are temporary only in the sense that
10512 their names should not collide with those generated by conventional naming rules for the
10513 implementation. It is still necessary to use the remove function to remove such files when their use
10514 is ended, and before program termination.
10518 TMP_MAX different strings, but any or all of them may already be in use by existing files
10519 and thus not be suitable return values.
10520 3 The tmpnam function generates a different string each time it is called.
10521 4 The implementation shall behave as if no library function calls the tmpnam function.
10523 5 If no suitable string can be generated, the tmpnam function returns a null pointer.
10524 Otherwise, if the argument is a null pointer, the tmpnam function leaves its result in an
10525 internal static object and returns a pointer to that object (subsequent calls to the tmpnam
10526 function may modify the same object). If the argument is not a null pointer, it is assumed
10527 to point to an array of at least L_tmpnam chars; the tmpnam function writes its result
10528 in that array and returns the argument as its value.
10529 Environmental limits
10530 6 The value of the macro TMP_MAX shall be at least 25.
10531 7.19.5 File access functions
10532 7.19.5.1 The fclose function
10534 1 #include <stdio.h>
10535 int fclose(FILE *stream);
10537 2 A successful call to the fclose function causes the stream pointed to by stream to be
10538 flushed and the associated file to be closed. Any unwritten buffered data for the stream
10539 are delivered to the host environment to be written to the file; any unread buffered data
10540 are discarded. Whether or not the call succeeds, the stream is disassociated from the file
10541 and any buffer set by the setbuf or setvbuf function is disassociated from the stream
10542 (and deallocated if it was automatically allocated).
10544 3 The fclose function returns zero if the stream was successfully closed, or EOF if any
10545 errors were detected.
10546 7.19.5.2 The fflush function
10548 1 #include <stdio.h>
10549 int fflush(FILE *stream);
10554 2 If stream points to an output stream or an update stream in which the most recent
10555 operation was not input, the fflush function causes any unwritten data for that stream
10556 to be delivered to the host environment to be written to the file; otherwise, the behavior is
10558 3 If stream is a null pointer, the fflush function performs this flushing action on all
10559 streams for which the behavior is defined above.
10561 4 The fflush function sets the error indicator for the stream and returns EOF if a write
10562 error occurs, otherwise it returns zero.
10563 Forward references: the fopen function (7.19.5.3).
10564 7.19.5.3 The fopen function
10566 1 #include <stdio.h>
10567 FILE *fopen(const char * restrict filename,
10568 const char * restrict mode);
10570 2 The fopen function opens the file whose name is the string pointed to by filename,
10571 and associates a stream with it.
10572 3 The argument mode points to a string. If the string is one of the following, the file is
10573 open in the indicated mode. Otherwise, the behavior is undefined.237)
10574 r open text file for reading
10575 w truncate to zero length or create text file for writing
10576 a append; open or create text file for writing at end-of-file
10577 rb open binary file for reading
10578 wb truncate to zero length or create binary file for writing
10579 ab append; open or create binary file for writing at end-of-file
10580 r+ open text file for update (reading and writing)
10581 w+ truncate to zero length or create text file for update
10582 a+ append; open or create text file for update, writing at end-of-file
10587 237) If the string begins with one of the above sequences, the implementation might choose to ignore the
10588 remaining characters, or it might use them to select different kinds of a file (some of which might not
10589 conform to the properties in 7.19.2).
10593 r+b or rb+ open binary file for update (reading and writing)
10594 w+b or wb+ truncate to zero length or create binary file for update
10595 a+b or ab+ append; open or create binary file for update, writing at end-of-file
10596 4 Opening a file with read mode ('r' as the first character in the mode argument) fails if
10597 the file does not exist or cannot be read.
10598 5 Opening a file with append mode ('a' as the first character in the mode argument)
10599 causes all subsequent writes to the file to be forced to the then current end-of-file,
10600 regardless of intervening calls to the fseek function. In some implementations, opening
10601 a binary file with append mode ('b' as the second or third character in the above list of
10602 mode argument values) may initially position the file position indicator for the stream
10603 beyond the last data written, because of null character padding.
10604 6 When a file is opened with update mode ('+' as the second or third character in the
10605 above list of mode argument values), both input and output may be performed on the
10606 associated stream. However, output shall not be directly followed by input without an
10607 intervening call to the fflush function or to a file positioning function (fseek,
10608 fsetpos, or rewind), and input shall not be directly followed by output without an
10609 intervening call to a file positioning function, unless the input operation encounters end-
10610 of-file. Opening (or creating) a text file with update mode may instead open (or create) a
10611 binary stream in some implementations.
10612 7 When opened, a stream is fully buffered if and only if it can be determined not to refer to
10613 an interactive device. The error and end-of-file indicators for the stream are cleared.
10615 8 The fopen function returns a pointer to the object controlling the stream. If the open
10616 operation fails, fopen returns a null pointer.
10617 Forward references: file positioning functions (7.19.9).
10618 7.19.5.4 The freopen function
10620 1 #include <stdio.h>
10621 FILE *freopen(const char * restrict filename,
10622 const char * restrict mode,
10623 FILE * restrict stream);
10625 2 The freopen function opens the file whose name is the string pointed to by filename
10626 and associates the stream pointed to by stream with it. The mode argument is used just
10630 as in the fopen function.238)
10631 3 If filename is a null pointer, the freopen function attempts to change the mode of
10632 the stream to that specified by mode, as if the name of the file currently associated with
10633 the stream had been used. It is implementation-defined which changes of mode are
10634 permitted (if any), and under what circumstances.
10635 4 The freopen function first attempts to close any file that is associated with the specified
10636 stream. Failure to close the file is ignored. The error and end-of-file indicators for the
10637 stream are cleared.
10639 5 The freopen function returns a null pointer if the open operation fails. Otherwise,
10640 freopen returns the value of stream.
10641 7.19.5.5 The setbuf function
10643 1 #include <stdio.h>
10644 void setbuf(FILE * restrict stream,
10645 char * restrict buf);
10647 2 Except that it returns no value, the setbuf function is equivalent to the setvbuf
10648 function invoked with the values _IOFBF for mode and BUFSIZ for size, or (if buf
10649 is a null pointer), with the value _IONBF for mode.
10651 3 The setbuf function returns no value.
10652 Forward references: the setvbuf function (7.19.5.6).
10653 7.19.5.6 The setvbuf function
10655 1 #include <stdio.h>
10656 int setvbuf(FILE * restrict stream,
10657 char * restrict buf,
10658 int mode, size_t size);
10663 238) The primary use of the freopen function is to change the file associated with a standard text stream
10664 (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value
10665 returned by the fopen function may be assigned.
10670 2 The setvbuf function may be used only after the stream pointed to by stream has
10671 been associated with an open file and before any other operation (other than an
10672 unsuccessful call to setvbuf) is performed on the stream. The argument mode
10673 determines how stream will be buffered, as follows: _IOFBF causes input/output to be
10674 fully buffered; _IOLBF causes input/output to be line buffered; _IONBF causes
10675 input/output to be unbuffered. If buf is not a null pointer, the array it points to may be
10676 used instead of a buffer allocated by the setvbuf function239) and the argument size
10677 specifies the size of the array; otherwise, size may determine the size of a buffer
10678 allocated by the setvbuf function. The contents of the array at any time are
10681 3 The setvbuf function returns zero on success, or nonzero if an invalid value is given
10682 for mode or if the request cannot be honored.
10683 7.19.6 Formatted input/output functions
10684 1 The formatted input/output functions shall behave as if there is a sequence point after the
10685 actions associated with each specifier.240)
10686 7.19.6.1 The fprintf function
10688 1 #include <stdio.h>
10689 int fprintf(FILE * restrict stream,
10690 const char * restrict format, ...);
10692 2 The fprintf function writes output to the stream pointed to by stream, under control
10693 of the string pointed to by format that specifies how subsequent arguments are
10694 converted for output. If there are insufficient arguments for the format, the behavior is
10695 undefined. If the format is exhausted while arguments remain, the excess arguments are
10696 evaluated (as always) but are otherwise ignored. The fprintf function returns when
10697 the end of the format string is encountered.
10698 3 The format shall be a multibyte character sequence, beginning and ending in its initial
10699 shift state. The format is composed of zero or more directives: ordinary multibyte
10700 characters (not %), which are copied unchanged to the output stream; and conversion
10703 239) The buffer has to have a lifetime at least as great as the open stream, so the stream should be closed
10704 before a buffer that has automatic storage duration is deallocated upon block exit.
10705 240) The fprintf functions perform writes to memory for the %n specifier.
10709 specifications, each of which results in fetching zero or more subsequent arguments,
10710 converting them, if applicable, according to the corresponding conversion specifier, and
10711 then writing the result to the output stream.
10712 4 Each conversion specification is introduced by the character %. After the %, the following
10713 appear in sequence:
10714 -- Zero or more flags (in any order) that modify the meaning of the conversion
10716 -- An optional minimum field width. If the converted value has fewer characters than the
10717 field width, it is padded with spaces (by default) on the left (or right, if the left
10718 adjustment flag, described later, has been given) to the field width. The field width
10719 takes the form of an asterisk * (described later) or a nonnegative decimal integer.241)
10720 -- An optional precision that gives the minimum number of digits to appear for the d, i,
10721 o, u, x, and X conversions, the number of digits to appear after the decimal-point
10722 character for a, A, e, E, f, and F conversions, the maximum number of significant
10723 digits for the g and G conversions, or the maximum number of bytes to be written for
10724 s conversions. The precision takes the form of a period (.) followed either by an
10725 asterisk * (described later) or by an optional decimal integer; if only the period is
10726 specified, the precision is taken as zero. If a precision appears with any other
10727 conversion specifier, the behavior is undefined.
10728 -- An optional length modifier that specifies the size of the argument.
10729 -- A conversion specifier character that specifies the type of conversion to be applied.
10730 5 As noted above, a field width, or precision, or both, may be indicated by an asterisk. In
10731 this case, an int argument supplies the field width or precision. The arguments
10732 specifying field width, or precision, or both, shall appear (in that order) before the
10733 argument (if any) to be converted. A negative field width argument is taken as a - flag
10734 followed by a positive field width. A negative precision argument is taken as if the
10735 precision were omitted.
10736 6 The flag characters and their meanings are:
10737 - The result of the conversion is left-justified within the field. (It is right-justified if
10738 this flag is not specified.)
10739 + The result of a signed conversion always begins with a plus or minus sign. (It
10740 begins with a sign only when a negative value is converted if this flag is not
10745 241) Note that 0 is taken as a flag, not as the beginning of a field width.
10750 space If the first character of a signed conversion is not a sign, or if a signed conversion
10751 results in no characters, a space is prefixed to the result. If the space and + flags
10752 both appear, the space flag is ignored.
10753 # The result is converted to an ''alternative form''. For o conversion, it increases
10754 the precision, if and only if necessary, to force the first digit of the result to be a
10755 zero (if the value and precision are both 0, a single 0 is printed). For x (or X)
10756 conversion, a nonzero result has 0x (or 0X) prefixed to it. For a, A, e, E, f, F, g,
10757 and G conversions, the result of converting a floating-point number always
10758 contains a decimal-point character, even if no digits follow it. (Normally, a
10759 decimal-point character appears in the result of these conversions only if a digit
10760 follows it.) For g and G conversions, trailing zeros are not removed from the
10761 result. For other conversions, the behavior is undefined.
10762 0 For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros
10763 (following any indication of sign or base) are used to pad to the field width rather
10764 than performing space padding, except when converting an infinity or NaN. If the
10765 0 and - flags both appear, the 0 flag is ignored. For d, i, o, u, x, and X
10766 conversions, if a precision is specified, the 0 flag is ignored. For other
10767 conversions, the behavior is undefined.
10768 7 The length modifiers and their meanings are:
10769 hh Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
10770 signed char or unsigned char argument (the argument will have
10771 been promoted according to the integer promotions, but its value shall be
10772 converted to signed char or unsigned char before printing); or that
10773 a following n conversion specifier applies to a pointer to a signed char
10775 h Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
10776 short int or unsigned short int argument (the argument will
10777 have been promoted according to the integer promotions, but its value shall
10778 be converted to short int or unsigned short int before printing);
10779 or that a following n conversion specifier applies to a pointer to a short
10781 l (ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
10782 long int or unsigned long int argument; that a following n
10783 conversion specifier applies to a pointer to a long int argument; that a
10785 242) The results of all floating conversions of a negative zero, and of negative values that round to zero,
10786 include a minus sign.
10790 following c conversion specifier applies to a wint_t argument; that a
10791 following s conversion specifier applies to a pointer to a wchar_t
10792 argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion
10794 ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
10795 long long int or unsigned long long int argument; or that a
10796 following n conversion specifier applies to a pointer to a long long int
10798 j Specifies that a following d, i, o, u, x, or X conversion specifier applies to
10799 an intmax_t or uintmax_t argument; or that a following n conversion
10800 specifier applies to a pointer to an intmax_t argument.
10801 z Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
10802 size_t or the corresponding signed integer type argument; or that a
10803 following n conversion specifier applies to a pointer to a signed integer type
10804 corresponding to size_t argument.
10805 t Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
10806 ptrdiff_t or the corresponding unsigned integer type argument; or that a
10807 following n conversion specifier applies to a pointer to a ptrdiff_t
10809 L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
10810 applies to a long double argument.
10811 If a length modifier appears with any conversion specifier other than as specified above,
10812 the behavior is undefined.
10813 8 The conversion specifiers and their meanings are:
10814 d,i The int argument is converted to signed decimal in the style [-]dddd. The
10815 precision specifies the minimum number of digits to appear; if the value
10816 being converted can be represented in fewer digits, it is expanded with
10817 leading zeros. The default precision is 1. The result of converting a zero
10818 value with a precision of zero is no characters.
10819 o,u,x,X The unsigned int argument is converted to unsigned octal (o), unsigned
10820 decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; the
10821 letters abcdef are used for x conversion and the letters ABCDEF for X
10822 conversion. The precision specifies the minimum number of digits to appear;
10823 if the value being converted can be represented in fewer digits, it is expanded
10824 with leading zeros. The default precision is 1. The result of converting a
10825 zero value with a precision of zero is no characters.
10829 f,F A double argument representing a floating-point number is converted to
10830 decimal notation in the style [-]ddd.ddd, where the number of digits after
10831 the decimal-point character is equal to the precision specification. If the
10832 precision is missing, it is taken as 6; if the precision is zero and the # flag is
10833 not specified, no decimal-point character appears. If a decimal-point
10834 character appears, at least one digit appears before it. The value is rounded to
10835 the appropriate number of digits.
10836 A double argument representing an infinity is converted in one of the styles
10837 [-]inf or [-]infinity -- which style is implementation-defined. A
10838 double argument representing a NaN is converted in one of the styles
10839 [-]nan or [-]nan(n-char-sequence) -- which style, and the meaning of
10840 any n-char-sequence, is implementation-defined. The F conversion specifier
10841 produces INF, INFINITY, or NAN instead of inf, infinity, or nan,
10843 e,E A double argument representing a floating-point number is converted in the
10844 style [-]d.ddd e(+-)dd, where there is one digit (which is nonzero if the
10845 argument is nonzero) before the decimal-point character and the number of
10846 digits after it is equal to the precision; if the precision is missing, it is taken as
10847 6; if the precision is zero and the # flag is not specified, no decimal-point
10848 character appears. The value is rounded to the appropriate number of digits.
10849 The E conversion specifier produces a number with E instead of e
10850 introducing the exponent. The exponent always contains at least two digits,
10851 and only as many more digits as necessary to represent the exponent. If the
10852 value is zero, the exponent is zero.
10853 A double argument representing an infinity or NaN is converted in the style
10854 of an f or F conversion specifier.
10855 g,G A double argument representing a floating-point number is converted in
10856 style f or e (or in style F or E in the case of a G conversion specifier),
10857 depending on the value converted and the precision. Let P equal the
10858 precision if nonzero, 6 if the precision is omitted, or 1 if the precision is zero.
10859 Then, if a conversion with style E would have an exponent of X :
10860 -- if P > X >= -4, the conversion is with style f (or F) and precision
10862 -- otherwise, the conversion is with style e (or E) and precision P - 1.
10863 Finally, unless the # flag is used, any trailing zeros are removed from the
10865 243) When applied to infinite and NaN values, the -, +, and space flag characters have their usual meaning;
10866 the # and 0 flag characters have no effect.
10870 fractional portion of the result and the decimal-point character is removed if
10871 there is no fractional portion remaining.
10872 A double argument representing an infinity or NaN is converted in the style
10873 of an f or F conversion specifier.
10874 a,A A double argument representing a floating-point number is converted in the
10875 style [-]0xh.hhhh p(+-)d, where there is one hexadecimal digit (which is
10876 nonzero if the argument is a normalized floating-point number and is
10877 otherwise unspecified) before the decimal-point character244) and the number
10878 of hexadecimal digits after it is equal to the precision; if the precision is
10879 missing and FLT_RADIX is a power of 2, then the precision is sufficient for
10880 an exact representation of the value; if the precision is missing and
10881 FLT_RADIX is not a power of 2, then the precision is sufficient to
10882 distinguish245) values of type double, except that trailing zeros may be
10883 omitted; if the precision is zero and the # flag is not specified, no decimal-
10884 point character appears. The letters abcdef are used for a conversion and
10885 the letters ABCDEF for A conversion. The A conversion specifier produces a
10886 number with X and P instead of x and p. The exponent always contains at
10887 least one digit, and only as many more digits as necessary to represent the
10888 decimal exponent of 2. If the value is zero, the exponent is zero.
10889 A double argument representing an infinity or NaN is converted in the style
10890 of an f or F conversion specifier.
10891 c If no l length modifier is present, the int argument is converted to an
10892 unsigned char, and the resulting character is written.
10893 If an l length modifier is present, the wint_t argument is converted as if by
10894 an ls conversion specification with no precision and an argument that points
10895 to the initial element of a two-element array of wchar_t, the first element
10896 containing the wint_t argument to the lc conversion specification and the
10897 second a null wide character.
10898 s If no l length modifier is present, the argument shall be a pointer to the initial
10899 element of an array of character type.246) Characters from the array are
10902 244) Binary implementations can choose the hexadecimal digit to the left of the decimal-point character so
10903 that subsequent digits align to nibble (4-bit) boundaries.
10904 245) The precision p is sufficient to distinguish values of the source type if 16 p-1 > b n where b is
10905 FLT_RADIX and n is the number of base-b digits in the significand of the source type. A smaller p
10906 might suffice depending on the implementation's scheme for determining the digit to the left of the
10907 decimal-point character.
10908 246) No special provisions are made for multibyte characters.
10912 written up to (but not including) the terminating null character. If the
10913 precision is specified, no more than that many bytes are written. If the
10914 precision is not specified or is greater than the size of the array, the array shall
10915 contain a null character.
10916 If an l length modifier is present, the argument shall be a pointer to the initial
10917 element of an array of wchar_t type. Wide characters from the array are
10918 converted to multibyte characters (each as if by a call to the wcrtomb
10919 function, with the conversion state described by an mbstate_t object
10920 initialized to zero before the first wide character is converted) up to and
10921 including a terminating null wide character. The resulting multibyte
10922 characters are written up to (but not including) the terminating null character
10923 (byte). If no precision is specified, the array shall contain a null wide
10924 character. If a precision is specified, no more than that many bytes are
10925 written (including shift sequences, if any), and the array shall contain a null
10926 wide character if, to equal the multibyte character sequence length given by
10927 the precision, the function would need to access a wide character one past the
10928 end of the array. In no case is a partial multibyte character written.247)
10929 p The argument shall be a pointer to void. The value of the pointer is
10930 converted to a sequence of printing characters, in an implementation-defined
10932 n The argument shall be a pointer to signed integer into which is written the
10933 number of characters written to the output stream so far by this call to
10934 fprintf. No argument is converted, but one is consumed. If the conversion
10935 specification includes any flags, a field width, or a precision, the behavior is
10937 % A % character is written. No argument is converted. The complete
10938 conversion specification shall be %%.
10939 9 If a conversion specification is invalid, the behavior is undefined.248) If any argument is
10940 not the correct type for the corresponding conversion specification, the behavior is
10942 10 In no case does a nonexistent or small field width cause truncation of a field; if the result
10943 of a conversion is wider than the field width, the field is expanded to contain the
10949 247) Redundant shift sequences may result if multibyte characters have a state-dependent encoding.
10950 248) See ''future library directions'' (7.26.9).
10954 11 For a and A conversions, if FLT_RADIX is a power of 2, the value is correctly rounded
10955 to a hexadecimal floating number with the given precision.
10956 Recommended practice
10957 12 For a and A conversions, if FLT_RADIX is not a power of 2 and the result is not exactly
10958 representable in the given precision, the result should be one of the two adjacent numbers
10959 in hexadecimal floating style with the given precision, with the extra stipulation that the
10960 error should have a correct sign for the current rounding direction.
10961 13 For e, E, f, F, g, and G conversions, if the number of significant decimal digits is at most
10962 DECIMAL_DIG, then the result should be correctly rounded.249) If the number of
10963 significant decimal digits is more than DECIMAL_DIG but the source value is exactly
10964 representable with DECIMAL_DIG digits, then the result should be an exact
10965 representation with trailing zeros. Otherwise, the source value is bounded by two
10966 adjacent decimal strings L < U, both having DECIMAL_DIG significant digits; the value
10967 of the resultant decimal string D should satisfy L <= D <= U, with the extra stipulation that
10968 the error should have a correct sign for the current rounding direction.
10970 14 The fprintf function returns the number of characters transmitted, or a negative value
10971 if an output or encoding error occurred.
10972 Environmental limits
10973 15 The number of characters that can be produced by any single conversion shall be at least
10975 16 EXAMPLE 1 To print a date and time in the form ''Sunday, July 3, 10:02'' followed by pi to five decimal
10980 char *weekday, *month; // pointers to strings
10981 int day, hour, min;
10982 fprintf(stdout, "%s, %s %d, %.2d:%.2d\n",
10983 weekday, month, day, hour, min);
10984 fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0));
10986 17 EXAMPLE 2 In this example, multibyte characters do not have a state-dependent encoding, and the
10987 members of the extended character set that consist of more than one byte each consist of exactly two bytes,
10988 the first of which is denoted here by a and the second by an uppercase letter.
10993 249) For binary-to-decimal conversion, the result format's values are the numbers representable with the
10994 given format specifier. The number of significant digits is determined by the format specifier, and in
10995 the case of fixed-point conversion by the source value as well.
10999 18 Given the following wide string with length seven,
11000 static wchar_t wstr[] = L" X Yabc Z W";
11002 fprintf(stdout, "|1234567890123|\n");
11003 fprintf(stdout, "|%13ls|\n", wstr);
11004 fprintf(stdout, "|%-13.9ls|\n", wstr);
11005 fprintf(stdout, "|%13.10ls|\n", wstr);
11006 fprintf(stdout, "|%13.11ls|\n", wstr);
11007 fprintf(stdout, "|%13.15ls|\n", &wstr[2]);
11008 fprintf(stdout, "|%13lc|\n", (wint_t) wstr[5]);
11009 will print the following seven lines:
11018 Forward references: conversion state (7.24.6), the wcrtomb function (7.24.6.3.3).
11019 7.19.6.2 The fscanf function
11021 1 #include <stdio.h>
11022 int fscanf(FILE * restrict stream,
11023 const char * restrict format, ...);
11025 2 The fscanf function reads input from the stream pointed to by stream, under control
11026 of the string pointed to by format that specifies the admissible input sequences and how
11027 they are to be converted for assignment, using subsequent arguments as pointers to the
11028 objects to receive the converted input. If there are insufficient arguments for the format,
11029 the behavior is undefined. If the format is exhausted while arguments remain, the excess
11030 arguments are evaluated (as always) but are otherwise ignored.
11031 3 The format shall be a multibyte character sequence, beginning and ending in its initial
11032 shift state. The format is composed of zero or more directives: one or more white-space
11033 characters, an ordinary multibyte character (neither % nor a white-space character), or a
11034 conversion specification. Each conversion specification is introduced by the character %.
11035 After the %, the following appear in sequence:
11036 -- An optional assignment-suppressing character *.
11037 -- An optional decimal integer greater than zero that specifies the maximum field width
11042 -- An optional length modifier that specifies the size of the receiving object.
11043 -- A conversion specifier character that specifies the type of conversion to be applied.
11044 4 The fscanf function executes each directive of the format in turn. If a directive fails, as
11045 detailed below, the function returns. Failures are described as input failures (due to the
11046 occurrence of an encoding error or the unavailability of input characters), or matching
11047 failures (due to inappropriate input).
11048 5 A directive composed of white-space character(s) is executed by reading input up to the
11049 first non-white-space character (which remains unread), or until no more characters can
11051 6 A directive that is an ordinary multibyte character is executed by reading the next
11052 characters of the stream. If any of those characters differ from the ones composing the
11053 directive, the directive fails and the differing and subsequent characters remain unread.
11054 Similarly, if end-of-file, an encoding error, or a read error prevents a character from being
11055 read, the directive fails.
11056 7 A directive that is a conversion specification defines a set of matching input sequences, as
11057 described below for each specifier. A conversion specification is executed in the
11059 8 Input white-space characters (as specified by the isspace function) are skipped, unless
11060 the specification includes a [, c, or n specifier.250)
11061 9 An input item is read from the stream, unless the specification includes an n specifier. An
11062 input item is defined as the longest sequence of input characters which does not exceed
11063 any specified field width and which is, or is a prefix of, a matching input sequence.251)
11064 The first character, if any, after the input item remains unread. If the length of the input
11065 item is zero, the execution of the directive fails; this condition is a matching failure unless
11066 end-of-file, an encoding error, or a read error prevented input from the stream, in which
11067 case it is an input failure.
11068 10 Except in the case of a % specifier, the input item (or, in the case of a %n directive, the
11069 count of input characters) is converted to a type appropriate to the conversion specifier. If
11070 the input item is not a matching sequence, the execution of the directive fails: this
11071 condition is a matching failure. Unless assignment suppression was indicated by a *, the
11072 result of the conversion is placed in the object pointed to by the first argument following
11073 the format argument that has not already received a conversion result. If this object
11074 does not have an appropriate type, or if the result of the conversion cannot be represented
11077 250) These white-space characters are not counted against a specified field width.
11078 251) fscanf pushes back at most one input character onto the input stream. Therefore, some sequences
11079 that are acceptable to strtod, strtol, etc., are unacceptable to fscanf.
11083 in the object, the behavior is undefined.
11084 11 The length modifiers and their meanings are:
11085 hh Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11086 to an argument with type pointer to signed char or unsigned char.
11087 h Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11088 to an argument with type pointer to short int or unsigned short
11090 l (ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11091 to an argument with type pointer to long int or unsigned long
11092 int; that a following a, A, e, E, f, F, g, or G conversion specifier applies to
11093 an argument with type pointer to double; or that a following c, s, or [
11094 conversion specifier applies to an argument with type pointer to wchar_t.
11095 ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11096 to an argument with type pointer to long long int or unsigned
11098 j Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11099 to an argument with type pointer to intmax_t or uintmax_t.
11100 z Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11101 to an argument with type pointer to size_t or the corresponding signed
11103 t Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11104 to an argument with type pointer to ptrdiff_t or the corresponding
11105 unsigned integer type.
11106 L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
11107 applies to an argument with type pointer to long double.
11108 If a length modifier appears with any conversion specifier other than as specified above,
11109 the behavior is undefined.
11110 12 The conversion specifiers and their meanings are:
11111 d Matches an optionally signed decimal integer, whose format is the same as
11112 expected for the subject sequence of the strtol function with the value 10
11113 for the base argument. The corresponding argument shall be a pointer to
11115 i Matches an optionally signed integer, whose format is the same as expected
11116 for the subject sequence of the strtol function with the value 0 for the
11117 base argument. The corresponding argument shall be a pointer to signed
11122 o Matches an optionally signed octal integer, whose format is the same as
11123 expected for the subject sequence of the strtoul function with the value 8
11124 for the base argument. The corresponding argument shall be a pointer to
11126 u Matches an optionally signed decimal integer, whose format is the same as
11127 expected for the subject sequence of the strtoul function with the value 10
11128 for the base argument. The corresponding argument shall be a pointer to
11130 x Matches an optionally signed hexadecimal integer, whose format is the same
11131 as expected for the subject sequence of the strtoul function with the value
11132 16 for the base argument. The corresponding argument shall be a pointer to
11134 a,e,f,g Matches an optionally signed floating-point number, infinity, or NaN, whose
11135 format is the same as expected for the subject sequence of the strtod
11136 function. The corresponding argument shall be a pointer to floating.
11137 c Matches a sequence of characters of exactly the number specified by the field
11138 width (1 if no field width is present in the directive).252)
11139 If no l length modifier is present, the corresponding argument shall be a
11140 pointer to the initial element of a character array large enough to accept the
11141 sequence. No null character is added.
11142 If an l length modifier is present, the input shall be a sequence of multibyte
11143 characters that begins in the initial shift state. Each multibyte character in the
11144 sequence is converted to a wide character as if by a call to the mbrtowc
11145 function, with the conversion state described by an mbstate_t object
11146 initialized to zero before the first multibyte character is converted. The
11147 corresponding argument shall be a pointer to the initial element of an array of
11148 wchar_t large enough to accept the resulting sequence of wide characters.
11149 No null wide character is added.
11150 s Matches a sequence of non-white-space characters.252)
11151 If no l length modifier is present, the corresponding argument shall be a
11152 pointer to the initial element of a character array large enough to accept the
11153 sequence and a terminating null character, which will be added automatically.
11154 If an l length modifier is present, the input shall be a sequence of multibyte
11157 252) No special provisions are made for multibyte characters in the matching rules used by the c, s, and [
11158 conversion specifiers -- the extent of the input field is determined on a byte-by-byte basis. The
11159 resulting field is nevertheless a sequence of multibyte characters that begins in the initial shift state.
11163 characters that begins in the initial shift state. Each multibyte character is
11164 converted to a wide character as if by a call to the mbrtowc function, with
11165 the conversion state described by an mbstate_t object initialized to zero
11166 before the first multibyte character is converted. The corresponding argument
11167 shall be a pointer to the initial element of an array of wchar_t large enough
11168 to accept the sequence and the terminating null wide character, which will be
11169 added automatically.
11170 [ Matches a nonempty sequence of characters from a set of expected characters
11172 If no l length modifier is present, the corresponding argument shall be a
11173 pointer to the initial element of a character array large enough to accept the
11174 sequence and a terminating null character, which will be added automatically.
11175 If an l length modifier is present, the input shall be a sequence of multibyte
11176 characters that begins in the initial shift state. Each multibyte character is
11177 converted to a wide character as if by a call to the mbrtowc function, with
11178 the conversion state described by an mbstate_t object initialized to zero
11179 before the first multibyte character is converted. The corresponding argument
11180 shall be a pointer to the initial element of an array of wchar_t large enough
11181 to accept the sequence and the terminating null wide character, which will be
11182 added automatically.
11183 The conversion specifier includes all subsequent characters in the format
11184 string, up to and including the matching right bracket (]). The characters
11185 between the brackets (the scanlist) compose the scanset, unless the character
11186 after the left bracket is a circumflex (^), in which case the scanset contains all
11187 characters that do not appear in the scanlist between the circumflex and the
11188 right bracket. If the conversion specifier begins with [] or [^], the right
11189 bracket character is in the scanlist and the next following right bracket
11190 character is the matching right bracket that ends the specification; otherwise
11191 the first following right bracket character is the one that ends the
11192 specification. If a - character is in the scanlist and is not the first, nor the
11193 second where the first character is a ^, nor the last character, the behavior is
11194 implementation-defined.
11195 p Matches an implementation-defined set of sequences, which should be the
11196 same as the set of sequences that may be produced by the %p conversion of
11197 the fprintf function. The corresponding argument shall be a pointer to a
11198 pointer to void. The input item is converted to a pointer value in an
11199 implementation-defined manner. If the input item is a value converted earlier
11200 during the same program execution, the pointer that results shall compare
11201 equal to that value; otherwise the behavior of the %p conversion is undefined.
11205 n No input is consumed. The corresponding argument shall be a pointer to
11206 signed integer into which is to be written the number of characters read from
11207 the input stream so far by this call to the fscanf function. Execution of a
11208 %n directive does not increment the assignment count returned at the
11209 completion of execution of the fscanf function. No argument is converted,
11210 but one is consumed. If the conversion specification includes an assignment-
11211 suppressing character or a field width, the behavior is undefined.
11212 % Matches a single % character; no conversion or assignment occurs. The
11213 complete conversion specification shall be %%.
11214 13 If a conversion specification is invalid, the behavior is undefined.253)
11215 14 The conversion specifiers A, E, F, G, and X are also valid and behave the same as,
11216 respectively, a, e, f, g, and x.
11217 15 Trailing white space (including new-line characters) is left unread unless matched by a
11218 directive. The success of literal matches and suppressed assignments is not directly
11219 determinable other than via the %n directive.
11221 16 The fscanf function returns the value of the macro EOF if an input failure occurs
11222 before any conversion. Otherwise, the function returns the number of input items
11223 assigned, which can be fewer than provided for, or even zero, in the event of an early
11225 17 EXAMPLE 1 The call:
11228 int n, i; float x; char name[50];
11229 n = fscanf(stdin, "%d%f%s", &i, &x, name);
11230 with the input line:
11231 25 54.32E-1 thompson
11232 will assign to n the value 3, to i the value 25, to x the value 5.432, and to name the sequence
11235 18 EXAMPLE 2 The call:
11238 int i; float x; char name[50];
11239 fscanf(stdin, "%2d%f%*d %[0123456789]", &i, &x, name);
11244 253) See ''future library directions'' (7.26.9).
11249 will assign to i the value 56 and to x the value 789.0, will skip 0123, and will assign to name the
11250 sequence 56\0. The next character read from the input stream will be a.
11252 19 EXAMPLE 3 To accept repeatedly from stdin a quantity, a unit of measure, and an item name:
11255 int count; float quant; char units[21], item[21];
11257 count = fscanf(stdin, "%f%20s of %20s", &quant, units, item);
11258 fscanf(stdin,"%*[^\n]");
11259 } while (!feof(stdin) && !ferror(stdin));
11260 20 If the stdin stream contains the following lines:
11262 -12.8degrees Celsius
11267 the execution of the above example will be analogous to the following assignments:
11268 quant = 2; strcpy(units, "quarts"); strcpy(item, "oil");
11270 quant = -12.8; strcpy(units, "degrees");
11271 count = 2; // "C" fails to match "o"
11272 count = 0; // "l" fails to match "%f"
11273 quant = 10.0; strcpy(units, "LBS"); strcpy(item, "dirt");
11275 count = 0; // "100e" fails to match "%f"
11281 int d1, d2, n1, n2, i;
11282 i = sscanf("123", "%d%n%n%d", &d1, &n1, &n2, &d2);
11283 the value 123 is assigned to d1 and the value 3 to n1. Because %n can never get an input failure the value
11284 of 3 is also assigned to n2. The value of d2 is not affected. The value 1 is assigned to i.
11286 22 EXAMPLE 5 In these examples, multibyte characters do have a state-dependent encoding, and the
11287 members of the extended character set that consist of more than one byte each consist of exactly two bytes,
11288 the first of which is denoted here by a and the second by an uppercase letter, but are only recognized as
11289 such when in the alternate shift state. The shift sequences are denoted by (uparrow) and (downarrow), in which the first causes
11290 entry into the alternate shift state.
11298 fscanf(stdin, "a%s", str);
11299 with the input line:
11300 a(uparrow) X Y(downarrow) bc
11301 str will contain (uparrow) X Y(downarrow)\0 assuming that none of the bytes of the shift sequences (or of the multibyte
11302 characters, in the more general case) appears to be a single-byte white-space character.
11303 24 In contrast, after the call:
11305 #include <stddef.h>
11308 fscanf(stdin, "a%ls", wstr);
11309 with the same input line, wstr will contain the two wide characters that correspond to X and Y and a
11310 terminating null wide character.
11311 25 However, the call:
11313 #include <stddef.h>
11316 fscanf(stdin, "a(uparrow) X(downarrow)%ls", wstr);
11317 with the same input line will return zero due to a matching failure against the (downarrow) sequence in the format
11319 26 Assuming that the first byte of the multibyte character X is the same as the first byte of the multibyte
11320 character Y, after the call:
11322 #include <stddef.h>
11325 fscanf(stdin, "a(uparrow) Y(downarrow)%ls", wstr);
11326 with the same input line, zero will again be returned, but stdin will be left with a partially consumed
11327 multibyte character.
11329 Forward references: the strtod, strtof, and strtold functions (7.20.1.3), the
11330 strtol, strtoll, strtoul, and strtoull functions (7.20.1.4), conversion state
11331 (7.24.6), the wcrtomb function (7.24.6.3.3).
11335 7.19.6.3 The printf function
11337 1 #include <stdio.h>
11338 int printf(const char * restrict format, ...);
11340 2 The printf function is equivalent to fprintf with the argument stdout interposed
11341 before the arguments to printf.
11343 3 The printf function returns the number of characters transmitted, or a negative value if
11344 an output or encoding error occurred.
11345 7.19.6.4 The scanf function
11347 1 #include <stdio.h>
11348 int scanf(const char * restrict format, ...);
11350 2 The scanf function is equivalent to fscanf with the argument stdin interposed
11351 before the arguments to scanf.
11353 3 The scanf function returns the value of the macro EOF if an input failure occurs before
11354 any conversion. Otherwise, the scanf function returns the number of input items
11355 assigned, which can be fewer than provided for, or even zero, in the event of an early
11357 7.19.6.5 The snprintf function
11359 1 #include <stdio.h>
11360 int snprintf(char * restrict s, size_t n,
11361 const char * restrict format, ...);
11363 2 The snprintf function is equivalent to fprintf, except that the output is written into
11364 an array (specified by argument s) rather than to a stream. If n is zero, nothing is written,
11365 and s may be a null pointer. Otherwise, output characters beyond the n-1st are
11366 discarded rather than being written to the array, and a null character is written at the end
11367 of the characters actually written into the array. If copying takes place between objects
11368 that overlap, the behavior is undefined.
11373 3 The snprintf function returns the number of characters that would have been written
11374 had n been sufficiently large, not counting the terminating null character, or a negative
11375 value if an encoding error occurred. Thus, the null-terminated output has been
11376 completely written if and only if the returned value is nonnegative and less than n.
11377 7.19.6.6 The sprintf function
11379 1 #include <stdio.h>
11380 int sprintf(char * restrict s,
11381 const char * restrict format, ...);
11383 2 The sprintf function is equivalent to fprintf, except that the output is written into
11384 an array (specified by the argument s) rather than to a stream. A null character is written
11385 at the end of the characters written; it is not counted as part of the returned value. If
11386 copying takes place between objects that overlap, the behavior is undefined.
11388 3 The sprintf function returns the number of characters written in the array, not
11389 counting the terminating null character, or a negative value if an encoding error occurred.
11390 7.19.6.7 The sscanf function
11392 1 #include <stdio.h>
11393 int sscanf(const char * restrict s,
11394 const char * restrict format, ...);
11396 2 The sscanf function is equivalent to fscanf, except that input is obtained from a
11397 string (specified by the argument s) rather than from a stream. Reaching the end of the
11398 string is equivalent to encountering end-of-file for the fscanf function. If copying
11399 takes place between objects that overlap, the behavior is undefined.
11401 3 The sscanf function returns the value of the macro EOF if an input failure occurs
11402 before any conversion. Otherwise, the sscanf function returns the number of input
11403 items assigned, which can be fewer than provided for, or even zero, in the event of an
11404 early matching failure.
11408 7.19.6.8 The vfprintf function
11410 1 #include <stdarg.h>
11412 int vfprintf(FILE * restrict stream,
11413 const char * restrict format,
11416 2 The vfprintf function is equivalent to fprintf, with the variable argument list
11417 replaced by arg, which shall have been initialized by the va_start macro (and
11418 possibly subsequent va_arg calls). The vfprintf function does not invoke the
11421 3 The vfprintf function returns the number of characters transmitted, or a negative
11422 value if an output or encoding error occurred.
11423 4 EXAMPLE The following shows the use of the vfprintf function in a general error-reporting routine.
11424 #include <stdarg.h>
11426 void error(char *function_name, char *format, ...)
11429 va_start(args, format);
11430 // print out name of function causing error
11431 fprintf(stderr, "ERROR in %s: ", function_name);
11432 // print out remainder of message
11433 vfprintf(stderr, format, args);
11440 254) As the functions vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf, and
11441 vsscanf invoke the va_arg macro, the value of arg after the return is indeterminate.
11445 7.19.6.9 The vfscanf function
11447 1 #include <stdarg.h>
11449 int vfscanf(FILE * restrict stream,
11450 const char * restrict format,
11453 2 The vfscanf function is equivalent to fscanf, with the variable argument list
11454 replaced by arg, which shall have been initialized by the va_start macro (and
11455 possibly subsequent va_arg calls). The vfscanf function does not invoke the
11458 3 The vfscanf function returns the value of the macro EOF if an input failure occurs
11459 before any conversion. Otherwise, the vfscanf function returns the number of input
11460 items assigned, which can be fewer than provided for, or even zero, in the event of an
11461 early matching failure.
11462 7.19.6.10 The vprintf function
11464 1 #include <stdarg.h>
11466 int vprintf(const char * restrict format,
11469 2 The vprintf function is equivalent to printf, with the variable argument list
11470 replaced by arg, which shall have been initialized by the va_start macro (and
11471 possibly subsequent va_arg calls). The vprintf function does not invoke the
11474 3 The vprintf function returns the number of characters transmitted, or a negative value
11475 if an output or encoding error occurred.
11479 7.19.6.11 The vscanf function
11481 1 #include <stdarg.h>
11483 int vscanf(const char * restrict format,
11486 2 The vscanf function is equivalent to scanf, with the variable argument list replaced
11487 by arg, which shall have been initialized by the va_start macro (and possibly
11488 subsequent va_arg calls). The vscanf function does not invoke the va_end
11491 3 The vscanf function returns the value of the macro EOF if an input failure occurs
11492 before any conversion. Otherwise, the vscanf function returns the number of input
11493 items assigned, which can be fewer than provided for, or even zero, in the event of an
11494 early matching failure.
11495 7.19.6.12 The vsnprintf function
11497 1 #include <stdarg.h>
11499 int vsnprintf(char * restrict s, size_t n,
11500 const char * restrict format,
11503 2 The vsnprintf function is equivalent to snprintf, with the variable argument list
11504 replaced by arg, which shall have been initialized by the va_start macro (and
11505 possibly subsequent va_arg calls). The vsnprintf function does not invoke the
11506 va_end macro.254) If copying takes place between objects that overlap, the behavior is
11509 3 The vsnprintf function returns the number of characters that would have been written
11510 had n been sufficiently large, not counting the terminating null character, or a negative
11511 value if an encoding error occurred. Thus, the null-terminated output has been
11512 completely written if and only if the returned value is nonnegative and less than n.
11516 7.19.6.13 The vsprintf function
11518 1 #include <stdarg.h>
11520 int vsprintf(char * restrict s,
11521 const char * restrict format,
11524 2 The vsprintf function is equivalent to sprintf, with the variable argument list
11525 replaced by arg, which shall have been initialized by the va_start macro (and
11526 possibly subsequent va_arg calls). The vsprintf function does not invoke the
11527 va_end macro.254) If copying takes place between objects that overlap, the behavior is
11530 3 The vsprintf function returns the number of characters written in the array, not
11531 counting the terminating null character, or a negative value if an encoding error occurred.
11532 7.19.6.14 The vsscanf function
11534 1 #include <stdarg.h>
11536 int vsscanf(const char * restrict s,
11537 const char * restrict format,
11540 2 The vsscanf function is equivalent to sscanf, with the variable argument list
11541 replaced by arg, which shall have been initialized by the va_start macro (and
11542 possibly subsequent va_arg calls). The vsscanf function does not invoke the
11545 3 The vsscanf function returns the value of the macro EOF if an input failure occurs
11546 before any conversion. Otherwise, the vsscanf function returns the number of input
11547 items assigned, which can be fewer than provided for, or even zero, in the event of an
11548 early matching failure.
11552 7.19.7 Character input/output functions
11553 7.19.7.1 The fgetc function
11555 1 #include <stdio.h>
11556 int fgetc(FILE *stream);
11558 2 If the end-of-file indicator for the input stream pointed to by stream is not set and a
11559 next character is present, the fgetc function obtains that character as an unsigned
11560 char converted to an int and advances the associated file position indicator for the
11561 stream (if defined).
11563 3 If the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-
11564 of-file indicator for the stream is set and the fgetc function returns EOF. Otherwise, the
11565 fgetc function returns the next character from the input stream pointed to by stream.
11566 If a read error occurs, the error indicator for the stream is set and the fgetc function
11568 7.19.7.2 The fgets function
11570 1 #include <stdio.h>
11571 char *fgets(char * restrict s, int n,
11572 FILE * restrict stream);
11574 2 The fgets function reads at most one less than the number of characters specified by n
11575 from the stream pointed to by stream into the array pointed to by s. No additional
11576 characters are read after a new-line character (which is retained) or after end-of-file. A
11577 null character is written immediately after the last character read into the array.
11579 3 The fgets function returns s if successful. If end-of-file is encountered and no
11580 characters have been read into the array, the contents of the array remain unchanged and a
11581 null pointer is returned. If a read error occurs during the operation, the array contents are
11582 indeterminate and a null pointer is returned.
11587 255) An end-of-file and a read error can be distinguished by use of the feof and ferror functions.
11591 7.19.7.3 The fputc function
11593 1 #include <stdio.h>
11594 int fputc(int c, FILE *stream);
11596 2 The fputc function writes the character specified by c (converted to an unsigned
11597 char) to the output stream pointed to by stream, at the position indicated by the
11598 associated file position indicator for the stream (if defined), and advances the indicator
11599 appropriately. If the file cannot support positioning requests, or if the stream was opened
11600 with append mode, the character is appended to the output stream.
11602 3 The fputc function returns the character written. If a write error occurs, the error
11603 indicator for the stream is set and fputc returns EOF.
11604 7.19.7.4 The fputs function
11606 1 #include <stdio.h>
11607 int fputs(const char * restrict s,
11608 FILE * restrict stream);
11610 2 The fputs function writes the string pointed to by s to the stream pointed to by
11611 stream. The terminating null character is not written.
11613 3 The fputs function returns EOF if a write error occurs; otherwise it returns a
11615 7.19.7.5 The getc function
11617 1 #include <stdio.h>
11618 int getc(FILE *stream);
11620 2 The getc function is equivalent to fgetc, except that if it is implemented as a macro, it
11621 may evaluate stream more than once, so the argument should never be an expression
11627 3 The getc function returns the next character from the input stream pointed to by
11628 stream. If the stream is at end-of-file, the end-of-file indicator for the stream is set and
11629 getc returns EOF. If a read error occurs, the error indicator for the stream is set and
11631 7.19.7.6 The getchar function
11633 1 #include <stdio.h>
11636 2 The getchar function is equivalent to getc with the argument stdin.
11638 3 The getchar function returns the next character from the input stream pointed to by
11639 stdin. If the stream is at end-of-file, the end-of-file indicator for the stream is set and
11640 getchar returns EOF. If a read error occurs, the error indicator for the stream is set and
11641 getchar returns EOF.
11642 7.19.7.7 The gets function
11644 1 #include <stdio.h>
11645 char *gets(char *s);
11647 2 The gets function reads characters from the input stream pointed to by stdin, into the
11648 array pointed to by s, until end-of-file is encountered or a new-line character is read.
11649 Any new-line character is discarded, and a null character is written immediately after the
11650 last character read into the array.
11652 3 The gets function returns s if successful. If end-of-file is encountered and no
11653 characters have been read into the array, the contents of the array remain unchanged and a
11654 null pointer is returned. If a read error occurs during the operation, the array contents are
11655 indeterminate and a null pointer is returned.
11656 Forward references: future library directions (7.26.9).
11660 7.19.7.8 The putc function
11662 1 #include <stdio.h>
11663 int putc(int c, FILE *stream);
11665 2 The putc function is equivalent to fputc, except that if it is implemented as a macro, it
11666 may evaluate stream more than once, so that argument should never be an expression
11669 3 The putc function returns the character written. If a write error occurs, the error
11670 indicator for the stream is set and putc returns EOF.
11671 7.19.7.9 The putchar function
11673 1 #include <stdio.h>
11674 int putchar(int c);
11676 2 The putchar function is equivalent to putc with the second argument stdout.
11678 3 The putchar function returns the character written. If a write error occurs, the error
11679 indicator for the stream is set and putchar returns EOF.
11680 7.19.7.10 The puts function
11682 1 #include <stdio.h>
11683 int puts(const char *s);
11685 2 The puts function writes the string pointed to by s to the stream pointed to by stdout,
11686 and appends a new-line character to the output. The terminating null character is not
11689 3 The puts function returns EOF if a write error occurs; otherwise it returns a nonnegative
11694 7.19.7.11 The ungetc function
11696 1 #include <stdio.h>
11697 int ungetc(int c, FILE *stream);
11699 2 The ungetc function pushes the character specified by c (converted to an unsigned
11700 char) back onto the input stream pointed to by stream. Pushed-back characters will be
11701 returned by subsequent reads on that stream in the reverse order of their pushing. A
11702 successful intervening call (with the stream pointed to by stream) to a file positioning
11703 function (fseek, fsetpos, or rewind) discards any pushed-back characters for the
11704 stream. The external storage corresponding to the stream is unchanged.
11705 3 One character of pushback is guaranteed. If the ungetc function is called too many
11706 times on the same stream without an intervening read or file positioning operation on that
11707 stream, the operation may fail.
11708 4 If the value of c equals that of the macro EOF, the operation fails and the input stream is
11710 5 A successful call to the ungetc function clears the end-of-file indicator for the stream.
11711 The value of the file position indicator for the stream after reading or discarding all
11712 pushed-back characters shall be the same as it was before the characters were pushed
11713 back. For a text stream, the value of its file position indicator after a successful call to the
11714 ungetc function is unspecified until all pushed-back characters are read or discarded.
11715 For a binary stream, its file position indicator is decremented by each successful call to
11716 the ungetc function; if its value was zero before a call, it is indeterminate after the
11719 6 The ungetc function returns the character pushed back after conversion, or EOF if the
11721 Forward references: file positioning functions (7.19.9).
11726 256) See ''future library directions'' (7.26.9).
11730 7.19.8 Direct input/output functions
11731 7.19.8.1 The fread function
11733 1 #include <stdio.h>
11734 size_t fread(void * restrict ptr,
11735 size_t size, size_t nmemb,
11736 FILE * restrict stream);
11738 2 The fread function reads, into the array pointed to by ptr, up to nmemb elements
11739 whose size is specified by size, from the stream pointed to by stream. For each
11740 object, size calls are made to the fgetc function and the results stored, in the order
11741 read, in an array of unsigned char exactly overlaying the object. The file position
11742 indicator for the stream (if defined) is advanced by the number of characters successfully
11743 read. If an error occurs, the resulting value of the file position indicator for the stream is
11744 indeterminate. If a partial element is read, its value is indeterminate.
11746 3 The fread function returns the number of elements successfully read, which may be
11747 less than nmemb if a read error or end-of-file is encountered. If size or nmemb is zero,
11748 fread returns zero and the contents of the array and the state of the stream remain
11750 7.19.8.2 The fwrite function
11752 1 #include <stdio.h>
11753 size_t fwrite(const void * restrict ptr,
11754 size_t size, size_t nmemb,
11755 FILE * restrict stream);
11757 2 The fwrite function writes, from the array pointed to by ptr, up to nmemb elements
11758 whose size is specified by size, to the stream pointed to by stream. For each object,
11759 size calls are made to the fputc function, taking the values (in order) from an array of
11760 unsigned char exactly overlaying the object. The file position indicator for the
11761 stream (if defined) is advanced by the number of characters successfully written. If an
11762 error occurs, the resulting value of the file position indicator for the stream is
11768 3 The fwrite function returns the number of elements successfully written, which will be
11769 less than nmemb only if a write error is encountered. If size or nmemb is zero,
11770 fwrite returns zero and the state of the stream remains unchanged.
11771 7.19.9 File positioning functions
11772 7.19.9.1 The fgetpos function
11774 1 #include <stdio.h>
11775 int fgetpos(FILE * restrict stream,
11776 fpos_t * restrict pos);
11778 2 The fgetpos function stores the current values of the parse state (if any) and file
11779 position indicator for the stream pointed to by stream in the object pointed to by pos.
11780 The values stored contain unspecified information usable by the fsetpos function for
11781 repositioning the stream to its position at the time of the call to the fgetpos function.
11783 3 If successful, the fgetpos function returns zero; on failure, the fgetpos function
11784 returns nonzero and stores an implementation-defined positive value in errno.
11785 Forward references: the fsetpos function (7.19.9.3).
11786 7.19.9.2 The fseek function
11788 1 #include <stdio.h>
11789 int fseek(FILE *stream, long int offset, int whence);
11791 2 The fseek function sets the file position indicator for the stream pointed to by stream.
11792 If a read or write error occurs, the error indicator for the stream is set and fseek fails.
11793 3 For a binary stream, the new position, measured in characters from the beginning of the
11794 file, is obtained by adding offset to the position specified by whence. The specified
11795 position is the beginning of the file if whence is SEEK_SET, the current value of the file
11796 position indicator if SEEK_CUR, or end-of-file if SEEK_END. A binary stream need not
11797 meaningfully support fseek calls with a whence value of SEEK_END.
11798 4 For a text stream, either offset shall be zero, or offset shall be a value returned by
11799 an earlier successful call to the ftell function on a stream associated with the same file
11800 and whence shall be SEEK_SET.
11804 5 After determining the new position, a successful call to the fseek function undoes any
11805 effects of the ungetc function on the stream, clears the end-of-file indicator for the
11806 stream, and then establishes the new position. After a successful fseek call, the next
11807 operation on an update stream may be either input or output.
11809 6 The fseek function returns nonzero only for a request that cannot be satisfied.
11810 Forward references: the ftell function (7.19.9.4).
11811 7.19.9.3 The fsetpos function
11813 1 #include <stdio.h>
11814 int fsetpos(FILE *stream, const fpos_t *pos);
11816 2 The fsetpos function sets the mbstate_t object (if any) and file position indicator
11817 for the stream pointed to by stream according to the value of the object pointed to by
11818 pos, which shall be a value obtained from an earlier successful call to the fgetpos
11819 function on a stream associated with the same file. If a read or write error occurs, the
11820 error indicator for the stream is set and fsetpos fails.
11821 3 A successful call to the fsetpos function undoes any effects of the ungetc function
11822 on the stream, clears the end-of-file indicator for the stream, and then establishes the new
11823 parse state and position. After a successful fsetpos call, the next operation on an
11824 update stream may be either input or output.
11826 4 If successful, the fsetpos function returns zero; on failure, the fsetpos function
11827 returns nonzero and stores an implementation-defined positive value in errno.
11828 7.19.9.4 The ftell function
11830 1 #include <stdio.h>
11831 long int ftell(FILE *stream);
11833 2 The ftell function obtains the current value of the file position indicator for the stream
11834 pointed to by stream. For a binary stream, the value is the number of characters from
11835 the beginning of the file. For a text stream, its file position indicator contains unspecified
11836 information, usable by the fseek function for returning the file position indicator for the
11837 stream to its position at the time of the ftell call; the difference between two such
11838 return values is not necessarily a meaningful measure of the number of characters written
11844 3 If successful, the ftell function returns the current value of the file position indicator
11845 for the stream. On failure, the ftell function returns -1L and stores an
11846 implementation-defined positive value in errno.
11847 7.19.9.5 The rewind function
11849 1 #include <stdio.h>
11850 void rewind(FILE *stream);
11852 2 The rewind function sets the file position indicator for the stream pointed to by
11853 stream to the beginning of the file. It is equivalent to
11854 (void)fseek(stream, 0L, SEEK_SET)
11855 except that the error indicator for the stream is also cleared.
11857 3 The rewind function returns no value.
11858 7.19.10 Error-handling functions
11859 7.19.10.1 The clearerr function
11861 1 #include <stdio.h>
11862 void clearerr(FILE *stream);
11864 2 The clearerr function clears the end-of-file and error indicators for the stream pointed
11867 3 The clearerr function returns no value.
11871 7.19.10.2 The feof function
11873 1 #include <stdio.h>
11874 int feof(FILE *stream);
11876 2 The feof function tests the end-of-file indicator for the stream pointed to by stream.
11878 3 The feof function returns nonzero if and only if the end-of-file indicator is set for
11880 7.19.10.3 The ferror function
11882 1 #include <stdio.h>
11883 int ferror(FILE *stream);
11885 2 The ferror function tests the error indicator for the stream pointed to by stream.
11887 3 The ferror function returns nonzero if and only if the error indicator is set for
11889 7.19.10.4 The perror function
11891 1 #include <stdio.h>
11892 void perror(const char *s);
11894 2 The perror function maps the error number in the integer expression errno to an
11895 error message. It writes a sequence of characters to the standard error stream thus: first
11896 (if s is not a null pointer and the character pointed to by s is not the null character), the
11897 string pointed to by s followed by a colon (:) and a space; then an appropriate error
11898 message string followed by a new-line character. The contents of the error message
11899 strings are the same as those returned by the strerror function with argument errno.
11901 3 The perror function returns no value.
11902 Forward references: the strerror function (7.21.6.2).
11906 7.20 General utilities <stdlib.h>
11907 1 The header <stdlib.h> declares five types and several functions of general utility, and
11908 defines several macros.257)
11909 2 The types declared are size_t and wchar_t (both described in 7.17),
11911 which is a structure type that is the type of the value returned by the div function,
11913 which is a structure type that is the type of the value returned by the ldiv function, and
11915 which is a structure type that is the type of the value returned by the lldiv function.
11916 3 The macros defined are NULL (described in 7.17);
11920 which expand to integer constant expressions that can be used as the argument to the
11921 exit function to return unsuccessful or successful termination status, respectively, to the
11924 which expands to an integer constant expression that is the maximum value returned by
11925 the rand function; and
11927 which expands to a positive integer expression with type size_t that is the maximum
11928 number of bytes in a multibyte character for the extended character set specified by the
11929 current locale (category LC_CTYPE), which is never greater than MB_LEN_MAX.
11934 257) See ''future library directions'' (7.26.10).
11938 7.20.1 Numeric conversion functions
11939 1 The functions atof, atoi, atol, and atoll need not affect the value of the integer
11940 expression errno on an error. If the value of the result cannot be represented, the
11941 behavior is undefined.
11942 7.20.1.1 The atof function
11944 1 #include <stdlib.h>
11945 double atof(const char *nptr);
11947 2 The atof function converts the initial portion of the string pointed to by nptr to
11948 double representation. Except for the behavior on error, it is equivalent to
11949 strtod(nptr, (char **)NULL)
11951 3 The atof function returns the converted value.
11952 Forward references: the strtod, strtof, and strtold functions (7.20.1.3).
11953 7.20.1.2 The atoi, atol, and atoll functions
11955 1 #include <stdlib.h>
11956 int atoi(const char *nptr);
11957 long int atol(const char *nptr);
11958 long long int atoll(const char *nptr);
11960 2 The atoi, atol, and atoll functions convert the initial portion of the string pointed
11961 to by nptr to int, long int, and long long int representation, respectively.
11962 Except for the behavior on error, they are equivalent to
11963 atoi: (int)strtol(nptr, (char **)NULL, 10)
11964 atol: strtol(nptr, (char **)NULL, 10)
11965 atoll: strtoll(nptr, (char **)NULL, 10)
11967 3 The atoi, atol, and atoll functions return the converted value.
11968 Forward references: the strtol, strtoll, strtoul, and strtoull functions
11973 7.20.1.3 The strtod, strtof, and strtold functions
11975 1 #include <stdlib.h>
11976 double strtod(const char * restrict nptr,
11977 char ** restrict endptr);
11978 float strtof(const char * restrict nptr,
11979 char ** restrict endptr);
11980 long double strtold(const char * restrict nptr,
11981 char ** restrict endptr);
11983 2 The strtod, strtof, and strtold functions convert the initial portion of the string
11984 pointed to by nptr to double, float, and long double representation,
11985 respectively. First, they decompose the input string into three parts: an initial, possibly
11986 empty, sequence of white-space characters (as specified by the isspace function), a
11987 subject sequence resembling a floating-point constant or representing an infinity or NaN;
11988 and a final string of one or more unrecognized characters, including the terminating null
11989 character of the input string. Then, they attempt to convert the subject sequence to a
11990 floating-point number, and return the result.
11991 3 The expected form of the subject sequence is an optional plus or minus sign, then one of
11993 -- a nonempty sequence of decimal digits optionally containing a decimal-point
11994 character, then an optional exponent part as defined in 6.4.4.2;
11995 -- a 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing a
11996 decimal-point character, then an optional binary exponent part as defined in 6.4.4.2;
11997 -- INF or INFINITY, ignoring case
11998 -- NAN or NAN(n-char-sequenceopt), ignoring case in the NAN part, where:
12002 n-char-sequence digit
12003 n-char-sequence nondigit
12004 The subject sequence is defined as the longest initial subsequence of the input string,
12005 starting with the first non-white-space character, that is of the expected form. The subject
12006 sequence contains no characters if the input string is not of the expected form.
12007 4 If the subject sequence has the expected form for a floating-point number, the sequence of
12008 characters starting with the first digit or the decimal-point character (whichever occurs
12009 first) is interpreted as a floating constant according to the rules of 6.4.4.2, except that the
12013 decimal-point character is used in place of a period, and that if neither an exponent part
12014 nor a decimal-point character appears in a decimal floating point number, or if a binary
12015 exponent part does not appear in a hexadecimal floating point number, an exponent part
12016 of the appropriate type with value zero is assumed to follow the last digit in the string. If
12017 the subject sequence begins with a minus sign, the sequence is interpreted as negated.258)
12018 A character sequence INF or INFINITY is interpreted as an infinity, if representable in
12019 the return type, else like a floating constant that is too large for the range of the return
12020 type. A character sequence NAN or NAN(n-char-sequenceopt), is interpreted as a quiet
12021 NaN, if supported in the return type, else like a subject sequence part that does not have
12022 the expected form; the meaning of the n-char sequences is implementation-defined.259) A
12023 pointer to the final string is stored in the object pointed to by endptr, provided that
12024 endptr is not a null pointer.
12025 5 If the subject sequence has the hexadecimal form and FLT_RADIX is a power of 2, the
12026 value resulting from the conversion is correctly rounded.
12027 6 In other than the "C" locale, additional locale-specific subject sequence forms may be
12029 7 If the subject sequence is empty or does not have the expected form, no conversion is
12030 performed; the value of nptr is stored in the object pointed to by endptr, provided
12031 that endptr is not a null pointer.
12032 Recommended practice
12033 8 If the subject sequence has the hexadecimal form, FLT_RADIX is not a power of 2, and
12034 the result is not exactly representable, the result should be one of the two numbers in the
12035 appropriate internal format that are adjacent to the hexadecimal floating source value,
12036 with the extra stipulation that the error should have a correct sign for the current rounding
12038 9 If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in
12039 <float.h>) significant digits, the result should be correctly rounded. If the subject
12040 sequence D has the decimal form and more than DECIMAL_DIG significant digits,
12041 consider the two bounding, adjacent decimal strings L and U, both having
12042 DECIMAL_DIG significant digits, such that the values of L, D, and U satisfy L <= D <= U.
12043 The result should be one of the (equal or adjacent) values that would be obtained by
12044 correctly rounding L and U according to the current rounding direction, with the extra
12046 258) It is unspecified whether a minus-signed sequence is converted to a negative number directly or by
12047 negating the value resulting from converting the corresponding unsigned sequence (see F.5); the two
12048 methods may yield different results if rounding is toward positive or negative infinity. In either case,
12049 the functions honor the sign of zero if floating-point arithmetic supports signed zeros.
12050 259) An implementation may use the n-char sequence to determine extra information to be represented in
12051 the NaN's significand.
12055 stipulation that the error with respect to D should have a correct sign for the current
12056 rounding direction.260)
12058 10 The functions return the converted value, if any. If no conversion could be performed,
12059 zero is returned. If the correct value is outside the range of representable values, plus or
12060 minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the return
12061 type and sign of the value), and the value of the macro ERANGE is stored in errno. If
12062 the result underflows (7.12.1), the functions return a value whose magnitude is no greater
12063 than the smallest normalized positive number in the return type; whether errno acquires
12064 the value ERANGE is implementation-defined.
12065 7.20.1.4 The strtol, strtoll, strtoul, and strtoull functions
12067 1 #include <stdlib.h>
12069 const char * restrict nptr,
12070 char ** restrict endptr,
12072 long long int strtoll(
12073 const char * restrict nptr,
12074 char ** restrict endptr,
12076 unsigned long int strtoul(
12077 const char * restrict nptr,
12078 char ** restrict endptr,
12080 unsigned long long int strtoull(
12081 const char * restrict nptr,
12082 char ** restrict endptr,
12085 2 The strtol, strtoll, strtoul, and strtoull functions convert the initial
12086 portion of the string pointed to by nptr to long int, long long int, unsigned
12087 long int, and unsigned long long int representation, respectively. First,
12088 they decompose the input string into three parts: an initial, possibly empty, sequence of
12089 white-space characters (as specified by the isspace function), a subject sequence
12092 260) DECIMAL_DIG, defined in <float.h>, should be sufficiently large that L and U will usually round
12093 to the same internal floating value, but if not will round to adjacent values.
12097 resembling an integer represented in some radix determined by the value of base, and a
12098 final string of one or more unrecognized characters, including the terminating null
12099 character of the input string. Then, they attempt to convert the subject sequence to an
12100 integer, and return the result.
12101 3 If the value of base is zero, the expected form of the subject sequence is that of an
12102 integer constant as described in 6.4.4.1, optionally preceded by a plus or minus sign, but
12103 not including an integer suffix. If the value of base is between 2 and 36 (inclusive), the
12104 expected form of the subject sequence is a sequence of letters and digits representing an
12105 integer with the radix specified by base, optionally preceded by a plus or minus sign,
12106 but not including an integer suffix. The letters from a (or A) through z (or Z) are
12107 ascribed the values 10 through 35; only letters and digits whose ascribed values are less
12108 than that of base are permitted. If the value of base is 16, the characters 0x or 0X may
12109 optionally precede the sequence of letters and digits, following the sign if present.
12110 4 The subject sequence is defined as the longest initial subsequence of the input string,
12111 starting with the first non-white-space character, that is of the expected form. The subject
12112 sequence contains no characters if the input string is empty or consists entirely of white
12113 space, or if the first non-white-space character is other than a sign or a permissible letter
12115 5 If the subject sequence has the expected form and the value of base is zero, the sequence
12116 of characters starting with the first digit is interpreted as an integer constant according to
12117 the rules of 6.4.4.1. If the subject sequence has the expected form and the value of base
12118 is between 2 and 36, it is used as the base for conversion, ascribing to each letter its value
12119 as given above. If the subject sequence begins with a minus sign, the value resulting from
12120 the conversion is negated (in the return type). A pointer to the final string is stored in the
12121 object pointed to by endptr, provided that endptr is not a null pointer.
12122 6 In other than the "C" locale, additional locale-specific subject sequence forms may be
12124 7 If the subject sequence is empty or does not have the expected form, no conversion is
12125 performed; the value of nptr is stored in the object pointed to by endptr, provided
12126 that endptr is not a null pointer.
12128 8 The strtol, strtoll, strtoul, and strtoull functions return the converted
12129 value, if any. If no conversion could be performed, zero is returned. If the correct value
12130 is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
12131 LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type
12132 and sign of the value, if any), and the value of the macro ERANGE is stored in errno.
12136 7.20.2 Pseudo-random sequence generation functions
12137 7.20.2.1 The rand function
12139 1 #include <stdlib.h>
12142 2 The rand function computes a sequence of pseudo-random integers in the range 0 to
12144 3 The implementation shall behave as if no library function calls the rand function.
12146 4 The rand function returns a pseudo-random integer.
12147 Environmental limits
12148 5 The value of the RAND_MAX macro shall be at least 32767.
12149 7.20.2.2 The srand function
12151 1 #include <stdlib.h>
12152 void srand(unsigned int seed);
12154 2 The srand function uses the argument as a seed for a new sequence of pseudo-random
12155 numbers to be returned by subsequent calls to rand. If srand is then called with the
12156 same seed value, the sequence of pseudo-random numbers shall be repeated. If rand is
12157 called before any calls to srand have been made, the same sequence shall be generated
12158 as when srand is first called with a seed value of 1.
12159 3 The implementation shall behave as if no library function calls the srand function.
12161 4 The srand function returns no value.
12162 5 EXAMPLE The following functions define a portable implementation of rand and srand.
12163 static unsigned long int next = 1;
12164 int rand(void) // RAND_MAX assumed to be 32767
12166 next = next * 1103515245 + 12345;
12167 return (unsigned int)(next/65536) % 32768;
12172 void srand(unsigned int seed)
12177 7.20.3 Memory management functions
12178 1 The order and contiguity of storage allocated by successive calls to the calloc,
12179 malloc, and realloc functions is unspecified. The pointer returned if the allocation
12180 succeeds is suitably aligned so that it may be assigned to a pointer to any type of object
12181 and then used to access such an object or an array of such objects in the space allocated
12182 (until the space is explicitly deallocated). The lifetime of an allocated object extends
12183 from the allocation until the deallocation. Each such allocation shall yield a pointer to an
12184 object disjoint from any other object. The pointer returned points to the start (lowest byte
12185 address) of the allocated space. If the space cannot be allocated, a null pointer is
12186 returned. If the size of the space requested is zero, the behavior is implementation-
12187 defined: either a null pointer is returned, or the behavior is as if the size were some
12188 nonzero value, except that the returned pointer shall not be used to access an object.
12189 7.20.3.1 The calloc function
12191 1 #include <stdlib.h>
12192 void *calloc(size_t nmemb, size_t size);
12194 2 The calloc function allocates space for an array of nmemb objects, each of whose size
12195 is size. The space is initialized to all bits zero.261)
12197 3 The calloc function returns either a null pointer or a pointer to the allocated space.
12198 7.20.3.2 The free function
12200 1 #include <stdlib.h>
12201 void free(void *ptr);
12203 2 The free function causes the space pointed to by ptr to be deallocated, that is, made
12204 available for further allocation. If ptr is a null pointer, no action occurs. Otherwise, if
12205 the argument does not match a pointer earlier returned by the calloc, malloc, or
12208 261) Note that this need not be the same as the representation of floating-point zero or a null pointer
12213 realloc function, or if the space has been deallocated by a call to free or realloc,
12214 the behavior is undefined.
12216 3 The free function returns no value.
12217 7.20.3.3 The malloc function
12219 1 #include <stdlib.h>
12220 void *malloc(size_t size);
12222 2 The malloc function allocates space for an object whose size is specified by size and
12223 whose value is indeterminate.
12225 3 The malloc function returns either a null pointer or a pointer to the allocated space.
12226 7.20.3.4 The realloc function
12228 1 #include <stdlib.h>
12229 void *realloc(void *ptr, size_t size);
12231 2 The realloc function deallocates the old object pointed to by ptr and returns a
12232 pointer to a new object that has the size specified by size. The contents of the new
12233 object shall be the same as that of the old object prior to deallocation, up to the lesser of
12234 the new and old sizes. Any bytes in the new object beyond the size of the old object have
12235 indeterminate values.
12236 3 If ptr is a null pointer, the realloc function behaves like the malloc function for the
12237 specified size. Otherwise, if ptr does not match a pointer earlier returned by the
12238 calloc, malloc, or realloc function, or if the space has been deallocated by a call
12239 to the free or realloc function, the behavior is undefined. If memory for the new
12240 object cannot be allocated, the old object is not deallocated and its value is unchanged.
12242 4 The realloc function returns a pointer to the new object (which may have the same
12243 value as a pointer to the old object), or a null pointer if the new object could not be
12248 7.20.4 Communication with the environment
12249 7.20.4.1 The abort function
12251 1 #include <stdlib.h>
12254 2 The abort function causes abnormal program termination to occur, unless the signal
12255 SIGABRT is being caught and the signal handler does not return. Whether open streams
12256 with unwritten buffered data are flushed, open streams are closed, or temporary files are
12257 removed is implementation-defined. An implementation-defined form of the status
12258 unsuccessful termination is returned to the host environment by means of the function
12259 call raise(SIGABRT).
12261 3 The abort function does not return to its caller.
12262 7.20.4.2 The atexit function
12264 1 #include <stdlib.h>
12265 int atexit(void (*func)(void));
12267 2 The atexit function registers the function pointed to by func, to be called without
12268 arguments at normal program termination.
12269 Environmental limits
12270 3 The implementation shall support the registration of at least 32 functions.
12272 4 The atexit function returns zero if the registration succeeds, nonzero if it fails.
12273 Forward references: the exit function (7.20.4.3).
12274 7.20.4.3 The exit function
12276 1 #include <stdlib.h>
12277 void exit(int status);
12279 2 The exit function causes normal program termination to occur. If more than one call to
12280 the exit function is executed by a program, the behavior is undefined.
12284 3 First, all functions registered by the atexit function are called, in the reverse order of
12285 their registration,262) except that a function is called after any previously registered
12286 functions that had already been called at the time it was registered. If, during the call to
12287 any such function, a call to the longjmp function is made that would terminate the call
12288 to the registered function, the behavior is undefined.
12289 4 Next, all open streams with unwritten buffered data are flushed, all open streams are
12290 closed, and all files created by the tmpfile function are removed.
12291 5 Finally, control is returned to the host environment. If the value of status is zero or
12292 EXIT_SUCCESS, an implementation-defined form of the status successful termination is
12293 returned. If the value of status is EXIT_FAILURE, an implementation-defined form
12294 of the status unsuccessful termination is returned. Otherwise the status returned is
12295 implementation-defined.
12297 6 The exit function cannot return to its caller.
12298 7.20.4.4 The _Exit function
12300 1 #include <stdlib.h>
12301 void _Exit(int status);
12303 2 The _Exit function causes normal program termination to occur and control to be
12304 returned to the host environment. No functions registered by the atexit function or
12305 signal handlers registered by the signal function are called. The status returned to the
12306 host environment is determined in the same way as for the exit function (7.20.4.3).
12307 Whether open streams with unwritten buffered data are flushed, open streams are closed,
12308 or temporary files are removed is implementation-defined.
12310 3 The _Exit function cannot return to its caller.
12315 262) Each function is called as many times as it was registered, and in the correct order with respect to
12316 other registered functions.
12320 7.20.4.5 The getenv function
12322 1 #include <stdlib.h>
12323 char *getenv(const char *name);
12325 2 The getenv function searches an environment list, provided by the host environment,
12326 for a string that matches the string pointed to by name. The set of environment names
12327 and the method for altering the environment list are implementation-defined.
12328 3 The implementation shall behave as if no library function calls the getenv function.
12330 4 The getenv function returns a pointer to a string associated with the matched list
12331 member. The string pointed to shall not be modified by the program, but may be
12332 overwritten by a subsequent call to the getenv function. If the specified name cannot
12333 be found, a null pointer is returned.
12334 7.20.4.6 The system function
12336 1 #include <stdlib.h>
12337 int system(const char *string);
12339 2 If string is a null pointer, the system function determines whether the host
12340 environment has a command processor. If string is not a null pointer, the system
12341 function passes the string pointed to by string to that command processor to be
12342 executed in a manner which the implementation shall document; this might then cause the
12343 program calling system to behave in a non-conforming manner or to terminate.
12345 3 If the argument is a null pointer, the system function returns nonzero only if a
12346 command processor is available. If the argument is not a null pointer, and the system
12347 function does return, it returns an implementation-defined value.
12351 7.20.5 Searching and sorting utilities
12352 1 These utilities make use of a comparison function to search or sort arrays of unspecified
12353 type. Where an argument declared as size_t nmemb specifies the length of the array
12354 for a function, nmemb can have the value zero on a call to that function; the comparison
12355 function is not called, a search finds no matching element, and sorting performs no
12356 rearrangement. Pointer arguments on such a call shall still have valid values, as described
12358 2 The implementation shall ensure that the second argument of the comparison function
12359 (when called from bsearch), or both arguments (when called from qsort), are
12360 pointers to elements of the array.263) The first argument when called from bsearch
12362 3 The comparison function shall not alter the contents of the array. The implementation
12363 may reorder elements of the array between calls to the comparison function, but shall not
12364 alter the contents of any individual element.
12365 4 When the same objects (consisting of size bytes, irrespective of their current positions
12366 in the array) are passed more than once to the comparison function, the results shall be
12367 consistent with one another. That is, for qsort they shall define a total ordering on the
12368 array, and for bsearch the same object shall always compare the same way with the
12370 5 A sequence point occurs immediately before and immediately after each call to the
12371 comparison function, and also between any call to the comparison function and any
12372 movement of the objects passed as arguments to that call.
12373 7.20.5.1 The bsearch function
12375 1 #include <stdlib.h>
12376 void *bsearch(const void *key, const void *base,
12377 size_t nmemb, size_t size,
12378 int (*compar)(const void *, const void *));
12380 2 The bsearch function searches an array of nmemb objects, the initial element of which
12381 is pointed to by base, for an element that matches the object pointed to by key. The
12384 263) That is, if the value passed is p, then the following expressions are always nonzero:
12385 ((char *)p - (char *)base) % size == 0
12386 (char *)p >= (char *)base
12387 (char *)p < (char *)base + nmemb * size
12391 size of each element of the array is specified by size.
12392 3 The comparison function pointed to by compar is called with two arguments that point
12393 to the key object and to an array element, in that order. The function shall return an
12394 integer less than, equal to, or greater than zero if the key object is considered,
12395 respectively, to be less than, to match, or to be greater than the array element. The array
12396 shall consist of: all the elements that compare less than, all the elements that compare
12397 equal to, and all the elements that compare greater than the key object, in that order.264)
12399 4 The bsearch function returns a pointer to a matching element of the array, or a null
12400 pointer if no match is found. If two elements compare as equal, which element is
12401 matched is unspecified.
12402 7.20.5.2 The qsort function
12404 1 #include <stdlib.h>
12405 void qsort(void *base, size_t nmemb, size_t size,
12406 int (*compar)(const void *, const void *));
12408 2 The qsort function sorts an array of nmemb objects, the initial element of which is
12409 pointed to by base. The size of each object is specified by size.
12410 3 The contents of the array are sorted into ascending order according to a comparison
12411 function pointed to by compar, which is called with two arguments that point to the
12412 objects being compared. The function shall return an integer less than, equal to, or
12413 greater than zero if the first argument is considered to be respectively less than, equal to,
12414 or greater than the second.
12415 4 If two elements compare as equal, their order in the resulting sorted array is unspecified.
12417 5 The qsort function returns no value.
12422 264) In practice, the entire array is sorted according to the comparison function.
12426 7.20.6 Integer arithmetic functions
12427 7.20.6.1 The abs, labs and llabs functions
12429 1 #include <stdlib.h>
12431 long int labs(long int j);
12432 long long int llabs(long long int j);
12434 2 The abs, labs, and llabs functions compute the absolute value of an integer j. If the
12435 result cannot be represented, the behavior is undefined.265)
12437 3 The abs, labs, and llabs, functions return the absolute value.
12438 7.20.6.2 The div, ldiv, and lldiv functions
12440 1 #include <stdlib.h>
12441 div_t div(int numer, int denom);
12442 ldiv_t ldiv(long int numer, long int denom);
12443 lldiv_t lldiv(long long int numer, long long int denom);
12445 2 The div, ldiv, and lldiv, functions compute numer / denom and numer %
12446 denom in a single operation.
12448 3 The div, ldiv, and lldiv functions return a structure of type div_t, ldiv_t, and
12449 lldiv_t, respectively, comprising both the quotient and the remainder. The structures
12450 shall contain (in either order) the members quot (the quotient) and rem (the remainder),
12451 each of which has the same type as the arguments numer and denom. If either part of
12452 the result cannot be represented, the behavior is undefined.
12457 265) The absolute value of the most negative number cannot be represented in two's complement.
12461 7.20.7 Multibyte/wide character conversion functions
12462 1 The behavior of the multibyte character functions is affected by the LC_CTYPE category
12463 of the current locale. For a state-dependent encoding, each function is placed into its
12464 initial conversion state by a call for which its character pointer argument, s, is a null
12465 pointer. Subsequent calls with s as other than a null pointer cause the internal conversion
12466 state of the function to be altered as necessary. A call with s as a null pointer causes
12467 these functions to return a nonzero value if encodings have state dependency, and zero
12468 otherwise.266) Changing the LC_CTYPE category causes the conversion state of these
12469 functions to be indeterminate.
12470 7.20.7.1 The mblen function
12472 1 #include <stdlib.h>
12473 int mblen(const char *s, size_t n);
12475 2 If s is not a null pointer, the mblen function determines the number of bytes contained
12476 in the multibyte character pointed to by s. Except that the conversion state of the
12477 mbtowc function is not affected, it is equivalent to
12478 mbtowc((wchar_t *)0, s, n);
12479 3 The implementation shall behave as if no library function calls the mblen function.
12481 4 If s is a null pointer, the mblen function returns a nonzero or zero value, if multibyte
12482 character encodings, respectively, do or do not have state-dependent encodings. If s is
12483 not a null pointer, the mblen function either returns 0 (if s points to the null character),
12484 or returns the number of bytes that are contained in the multibyte character (if the next n
12485 or fewer bytes form a valid multibyte character), or returns -1 (if they do not form a valid
12486 multibyte character).
12487 Forward references: the mbtowc function (7.20.7.2).
12492 266) If the locale employs special bytes to change the shift state, these bytes do not produce separate wide
12493 character codes, but are grouped with an adjacent multibyte character.
12497 7.20.7.2 The mbtowc function
12499 1 #include <stdlib.h>
12500 int mbtowc(wchar_t * restrict pwc,
12501 const char * restrict s,
12504 2 If s is not a null pointer, the mbtowc function inspects at most n bytes beginning with
12505 the byte pointed to by s to determine the number of bytes needed to complete the next
12506 multibyte character (including any shift sequences). If the function determines that the
12507 next multibyte character is complete and valid, it determines the value of the
12508 corresponding wide character and then, if pwc is not a null pointer, stores that value in
12509 the object pointed to by pwc. If the corresponding wide character is the null wide
12510 character, the function is left in the initial conversion state.
12511 3 The implementation shall behave as if no library function calls the mbtowc function.
12513 4 If s is a null pointer, the mbtowc function returns a nonzero or zero value, if multibyte
12514 character encodings, respectively, do or do not have state-dependent encodings. If s is
12515 not a null pointer, the mbtowc function either returns 0 (if s points to the null character),
12516 or returns the number of bytes that are contained in the converted multibyte character (if
12517 the next n or fewer bytes form a valid multibyte character), or returns -1 (if they do not
12518 form a valid multibyte character).
12519 5 In no case will the value returned be greater than n or the value of the MB_CUR_MAX
12521 7.20.7.3 The wctomb function
12523 1 #include <stdlib.h>
12524 int wctomb(char *s, wchar_t wc);
12526 2 The wctomb function determines the number of bytes needed to represent the multibyte
12527 character corresponding to the wide character given by wc (including any shift
12528 sequences), and stores the multibyte character representation in the array whose first
12529 element is pointed to by s (if s is not a null pointer). At most MB_CUR_MAX characters
12530 are stored. If wc is a null wide character, a null byte is stored, preceded by any shift
12531 sequence needed to restore the initial shift state, and the function is left in the initial
12536 3 The implementation shall behave as if no library function calls the wctomb function.
12538 4 If s is a null pointer, the wctomb function returns a nonzero or zero value, if multibyte
12539 character encodings, respectively, do or do not have state-dependent encodings. If s is
12540 not a null pointer, the wctomb function returns -1 if the value of wc does not correspond
12541 to a valid multibyte character, or returns the number of bytes that are contained in the
12542 multibyte character corresponding to the value of wc.
12543 5 In no case will the value returned be greater than the value of the MB_CUR_MAX macro.
12544 7.20.8 Multibyte/wide string conversion functions
12545 1 The behavior of the multibyte string functions is affected by the LC_CTYPE category of
12546 the current locale.
12547 7.20.8.1 The mbstowcs function
12549 1 #include <stdlib.h>
12550 size_t mbstowcs(wchar_t * restrict pwcs,
12551 const char * restrict s,
12554 2 The mbstowcs function converts a sequence of multibyte characters that begins in the
12555 initial shift state from the array pointed to by s into a sequence of corresponding wide
12556 characters and stores not more than n wide characters into the array pointed to by pwcs.
12557 No multibyte characters that follow a null character (which is converted into a null wide
12558 character) will be examined or converted. Each multibyte character is converted as if by
12559 a call to the mbtowc function, except that the conversion state of the mbtowc function is
12561 3 No more than n elements will be modified in the array pointed to by pwcs. If copying
12562 takes place between objects that overlap, the behavior is undefined.
12564 4 If an invalid multibyte character is encountered, the mbstowcs function returns
12565 (size_t)(-1). Otherwise, the mbstowcs function returns the number of array
12566 elements modified, not including a terminating null wide character, if any.267)
12571 267) The array will not be null-terminated if the value returned is n.
12575 7.20.8.2 The wcstombs function
12577 1 #include <stdlib.h>
12578 size_t wcstombs(char * restrict s,
12579 const wchar_t * restrict pwcs,
12582 2 The wcstombs function converts a sequence of wide characters from the array pointed
12583 to by pwcs into a sequence of corresponding multibyte characters that begins in the
12584 initial shift state, and stores these multibyte characters into the array pointed to by s,
12585 stopping if a multibyte character would exceed the limit of n total bytes or if a null
12586 character is stored. Each wide character is converted as if by a call to the wctomb
12587 function, except that the conversion state of the wctomb function is not affected.
12588 3 No more than n bytes will be modified in the array pointed to by s. If copying takes place
12589 between objects that overlap, the behavior is undefined.
12591 4 If a wide character is encountered that does not correspond to a valid multibyte character,
12592 the wcstombs function returns (size_t)(-1). Otherwise, the wcstombs function
12593 returns the number of bytes modified, not including a terminating null character, if
12598 7.21 String handling <string.h>
12599 7.21.1 String function conventions
12600 1 The header <string.h> declares one type and several functions, and defines one
12601 macro useful for manipulating arrays of character type and other objects treated as arrays
12602 of character type.268) The type is size_t and the macro is NULL (both described in
12603 7.17). Various methods are used for determining the lengths of the arrays, but in all cases
12604 a char * or void * argument points to the initial (lowest addressed) character of the
12605 array. If an array is accessed beyond the end of an object, the behavior is undefined.
12606 2 Where an argument declared as size_t n specifies the length of the array for a
12607 function, n can have the value zero on a call to that function. Unless explicitly stated
12608 otherwise in the description of a particular function in this subclause, pointer arguments
12609 on such a call shall still have valid values, as described in 7.1.4. On such a call, a
12610 function that locates a character finds no occurrence, a function that compares two
12611 character sequences returns zero, and a function that copies characters copies zero
12613 3 For all functions in this subclause, each character shall be interpreted as if it had the type
12614 unsigned char (and therefore every possible object representation is valid and has a
12616 7.21.2 Copying functions
12617 7.21.2.1 The memcpy function
12619 1 #include <string.h>
12620 void *memcpy(void * restrict s1,
12621 const void * restrict s2,
12624 2 The memcpy function copies n characters from the object pointed to by s2 into the
12625 object pointed to by s1. If copying takes place between objects that overlap, the behavior
12628 3 The memcpy function returns the value of s1.
12633 268) See ''future library directions'' (7.26.11).
12637 7.21.2.2 The memmove function
12639 1 #include <string.h>
12640 void *memmove(void *s1, const void *s2, size_t n);
12642 2 The memmove function copies n characters from the object pointed to by s2 into the
12643 object pointed to by s1. Copying takes place as if the n characters from the object
12644 pointed to by s2 are first copied into a temporary array of n characters that does not
12645 overlap the objects pointed to by s1 and s2, and then the n characters from the
12646 temporary array are copied into the object pointed to by s1.
12648 3 The memmove function returns the value of s1.
12649 7.21.2.3 The strcpy function
12651 1 #include <string.h>
12652 char *strcpy(char * restrict s1,
12653 const char * restrict s2);
12655 2 The strcpy function copies the string pointed to by s2 (including the terminating null
12656 character) into the array pointed to by s1. If copying takes place between objects that
12657 overlap, the behavior is undefined.
12659 3 The strcpy function returns the value of s1.
12660 7.21.2.4 The strncpy function
12662 1 #include <string.h>
12663 char *strncpy(char * restrict s1,
12664 const char * restrict s2,
12667 2 The strncpy function copies not more than n characters (characters that follow a null
12668 character are not copied) from the array pointed to by s2 to the array pointed to by
12672 s1.269) If copying takes place between objects that overlap, the behavior is undefined.
12673 3 If the array pointed to by s2 is a string that is shorter than n characters, null characters
12674 are appended to the copy in the array pointed to by s1, until n characters in all have been
12677 4 The strncpy function returns the value of s1.
12678 7.21.3 Concatenation functions
12679 7.21.3.1 The strcat function
12681 1 #include <string.h>
12682 char *strcat(char * restrict s1,
12683 const char * restrict s2);
12685 2 The strcat function appends a copy of the string pointed to by s2 (including the
12686 terminating null character) to the end of the string pointed to by s1. The initial character
12687 of s2 overwrites the null character at the end of s1. If copying takes place between
12688 objects that overlap, the behavior is undefined.
12690 3 The strcat function returns the value of s1.
12691 7.21.3.2 The strncat function
12693 1 #include <string.h>
12694 char *strncat(char * restrict s1,
12695 const char * restrict s2,
12698 2 The strncat function appends not more than n characters (a null character and
12699 characters that follow it are not appended) from the array pointed to by s2 to the end of
12700 the string pointed to by s1. The initial character of s2 overwrites the null character at the
12701 end of s1. A terminating null character is always appended to the result.270) If copying
12703 269) Thus, if there is no null character in the first n characters of the array pointed to by s2, the result will
12704 not be null-terminated.
12705 270) Thus, the maximum number of characters that can end up in the array pointed to by s1 is
12710 takes place between objects that overlap, the behavior is undefined.
12712 3 The strncat function returns the value of s1.
12713 Forward references: the strlen function (7.21.6.3).
12714 7.21.4 Comparison functions
12715 1 The sign of a nonzero value returned by the comparison functions memcmp, strcmp,
12716 and strncmp is determined by the sign of the difference between the values of the first
12717 pair of characters (both interpreted as unsigned char) that differ in the objects being
12719 7.21.4.1 The memcmp function
12721 1 #include <string.h>
12722 int memcmp(const void *s1, const void *s2, size_t n);
12724 2 The memcmp function compares the first n characters of the object pointed to by s1 to
12725 the first n characters of the object pointed to by s2.271)
12727 3 The memcmp function returns an integer greater than, equal to, or less than zero,
12728 accordingly as the object pointed to by s1 is greater than, equal to, or less than the object
12730 7.21.4.2 The strcmp function
12732 1 #include <string.h>
12733 int strcmp(const char *s1, const char *s2);
12735 2 The strcmp function compares the string pointed to by s1 to the string pointed to by
12738 3 The strcmp function returns an integer greater than, equal to, or less than zero,
12739 accordingly as the string pointed to by s1 is greater than, equal to, or less than the string
12741 271) The contents of ''holes'' used as padding for purposes of alignment within structure objects are
12742 indeterminate. Strings shorter than their allocated space and unions may also cause problems in
12748 7.21.4.3 The strcoll function
12750 1 #include <string.h>
12751 int strcoll(const char *s1, const char *s2);
12753 2 The strcoll function compares the string pointed to by s1 to the string pointed to by
12754 s2, both interpreted as appropriate to the LC_COLLATE category of the current locale.
12756 3 The strcoll function returns an integer greater than, equal to, or less than zero,
12757 accordingly as the string pointed to by s1 is greater than, equal to, or less than the string
12758 pointed to by s2 when both are interpreted as appropriate to the current locale.
12759 7.21.4.4 The strncmp function
12761 1 #include <string.h>
12762 int strncmp(const char *s1, const char *s2, size_t n);
12764 2 The strncmp function compares not more than n characters (characters that follow a
12765 null character are not compared) from the array pointed to by s1 to the array pointed to
12768 3 The strncmp function returns an integer greater than, equal to, or less than zero,
12769 accordingly as the possibly null-terminated array pointed to by s1 is greater than, equal
12770 to, or less than the possibly null-terminated array pointed to by s2.
12771 7.21.4.5 The strxfrm function
12773 1 #include <string.h>
12774 size_t strxfrm(char * restrict s1,
12775 const char * restrict s2,
12778 2 The strxfrm function transforms the string pointed to by s2 and places the resulting
12779 string into the array pointed to by s1. The transformation is such that if the strcmp
12780 function is applied to two transformed strings, it returns a value greater than, equal to, or
12784 less than zero, corresponding to the result of the strcoll function applied to the same
12785 two original strings. No more than n characters are placed into the resulting array
12786 pointed to by s1, including the terminating null character. If n is zero, s1 is permitted to
12787 be a null pointer. If copying takes place between objects that overlap, the behavior is
12790 3 The strxfrm function returns the length of the transformed string (not including the
12791 terminating null character). If the value returned is n or more, the contents of the array
12792 pointed to by s1 are indeterminate.
12793 4 EXAMPLE The value of the following expression is the size of the array needed to hold the
12794 transformation of the string pointed to by s.
12795 1 + strxfrm(NULL, s, 0)
12797 7.21.5 Search functions
12798 7.21.5.1 The memchr function
12800 1 #include <string.h>
12801 void *memchr(const void *s, int c, size_t n);
12803 2 The memchr function locates the first occurrence of c (converted to an unsigned
12804 char) in the initial n characters (each interpreted as unsigned char) of the object
12807 3 The memchr function returns a pointer to the located character, or a null pointer if the
12808 character does not occur in the object.
12809 7.21.5.2 The strchr function
12811 1 #include <string.h>
12812 char *strchr(const char *s, int c);
12814 2 The strchr function locates the first occurrence of c (converted to a char) in the
12815 string pointed to by s. The terminating null character is considered to be part of the
12818 3 The strchr function returns a pointer to the located character, or a null pointer if the
12819 character does not occur in the string.
12823 7.21.5.3 The strcspn function
12825 1 #include <string.h>
12826 size_t strcspn(const char *s1, const char *s2);
12828 2 The strcspn function computes the length of the maximum initial segment of the string
12829 pointed to by s1 which consists entirely of characters not from the string pointed to by
12832 3 The strcspn function returns the length of the segment.
12833 7.21.5.4 The strpbrk function
12835 1 #include <string.h>
12836 char *strpbrk(const char *s1, const char *s2);
12838 2 The strpbrk function locates the first occurrence in the string pointed to by s1 of any
12839 character from the string pointed to by s2.
12841 3 The strpbrk function returns a pointer to the character, or a null pointer if no character
12842 from s2 occurs in s1.
12843 7.21.5.5 The strrchr function
12845 1 #include <string.h>
12846 char *strrchr(const char *s, int c);
12848 2 The strrchr function locates the last occurrence of c (converted to a char) in the
12849 string pointed to by s. The terminating null character is considered to be part of the
12852 3 The strrchr function returns a pointer to the character, or a null pointer if c does not
12853 occur in the string.
12857 7.21.5.6 The strspn function
12859 1 #include <string.h>
12860 size_t strspn(const char *s1, const char *s2);
12862 2 The strspn function computes the length of the maximum initial segment of the string
12863 pointed to by s1 which consists entirely of characters from the string pointed to by s2.
12865 3 The strspn function returns the length of the segment.
12866 7.21.5.7 The strstr function
12868 1 #include <string.h>
12869 char *strstr(const char *s1, const char *s2);
12871 2 The strstr function locates the first occurrence in the string pointed to by s1 of the
12872 sequence of characters (excluding the terminating null character) in the string pointed to
12875 3 The strstr function returns a pointer to the located string, or a null pointer if the string
12876 is not found. If s2 points to a string with zero length, the function returns s1.
12877 7.21.5.8 The strtok function
12879 1 #include <string.h>
12880 char *strtok(char * restrict s1,
12881 const char * restrict s2);
12883 2 A sequence of calls to the strtok function breaks the string pointed to by s1 into a
12884 sequence of tokens, each of which is delimited by a character from the string pointed to
12885 by s2. The first call in the sequence has a non-null first argument; subsequent calls in the
12886 sequence have a null first argument. The separator string pointed to by s2 may be
12887 different from call to call.
12888 3 The first call in the sequence searches the string pointed to by s1 for the first character
12889 that is not contained in the current separator string pointed to by s2. If no such character
12890 is found, then there are no tokens in the string pointed to by s1 and the strtok function
12894 returns a null pointer. If such a character is found, it is the start of the first token.
12895 4 The strtok function then searches from there for a character that is contained in the
12896 current separator string. If no such character is found, the current token extends to the
12897 end of the string pointed to by s1, and subsequent searches for a token will return a null
12898 pointer. If such a character is found, it is overwritten by a null character, which
12899 terminates the current token. The strtok function saves a pointer to the following
12900 character, from which the next search for a token will start.
12901 5 Each subsequent call, with a null pointer as the value of the first argument, starts
12902 searching from the saved pointer and behaves as described above.
12903 6 The implementation shall behave as if no library function calls the strtok function.
12905 7 The strtok function returns a pointer to the first character of a token, or a null pointer
12906 if there is no token.
12908 #include <string.h>
12909 static char str[] = "?a???b,,,#c";
12911 t = strtok(str, "?"); // t points to the token "a"
12912 t = strtok(NULL, ","); // t points to the token "??b"
12913 t = strtok(NULL, "#,"); // t points to the token "c"
12914 t = strtok(NULL, "?"); // t is a null pointer
12916 7.21.6 Miscellaneous functions
12917 7.21.6.1 The memset function
12919 1 #include <string.h>
12920 void *memset(void *s, int c, size_t n);
12922 2 The memset function copies the value of c (converted to an unsigned char) into
12923 each of the first n characters of the object pointed to by s.
12925 3 The memset function returns the value of s.
12929 7.21.6.2 The strerror function
12931 1 #include <string.h>
12932 char *strerror(int errnum);
12934 2 The strerror function maps the number in errnum to a message string. Typically,
12935 the values for errnum come from errno, but strerror shall map any value of type
12937 3 The implementation shall behave as if no library function calls the strerror function.
12939 4 The strerror function returns a pointer to the string, the contents of which are locale-
12940 specific. The array pointed to shall not be modified by the program, but may be
12941 overwritten by a subsequent call to the strerror function.
12942 7.21.6.3 The strlen function
12944 1 #include <string.h>
12945 size_t strlen(const char *s);
12947 2 The strlen function computes the length of the string pointed to by s.
12949 3 The strlen function returns the number of characters that precede the terminating null
12954 7.22 Type-generic math <tgmath.h>
12955 1 The header <tgmath.h> includes the headers <math.h> and <complex.h> and
12956 defines several type-generic macros.
12957 2 Of the <math.h> and <complex.h> functions without an f (float) or l (long
12958 double) suffix, several have one or more parameters whose corresponding real type is
12959 double. For each such function, except modf, there is a corresponding type-generic
12960 macro.272) The parameters whose corresponding real type is double in the function
12961 synopsis are generic parameters. Use of the macro invokes a function whose
12962 corresponding real type and type domain are determined by the arguments for the generic
12964 3 Use of the macro invokes a function whose generic parameters have the corresponding
12965 real type determined as follows:
12966 -- First, if any argument for generic parameters has type long double, the type
12967 determined is long double.
12968 -- Otherwise, if any argument for generic parameters has type double or is of integer
12969 type, the type determined is double.
12970 -- Otherwise, the type determined is float.
12971 4 For each unsuffixed function in <math.h> for which there is a function in
12972 <complex.h> with the same name except for a c prefix, the corresponding type-
12973 generic macro (for both functions) has the same name as the function in <math.h>. The
12974 corresponding type-generic macro for fabs and cabs is fabs.
12979 272) Like other function-like macros in Standard libraries, each type-generic macro can be suppressed to
12980 make available the corresponding ordinary function.
12981 273) If the type of the argument is not compatible with the type of the parameter for the selected function,
12982 the behavior is undefined.
12986 <math.h> <complex.h> type-generic
12987 function function macro
13005 If at least one argument for a generic parameter is complex, then use of the macro invokes
13006 a complex function; otherwise, use of the macro invokes a real function.
13007 5 For each unsuffixed function in <math.h> without a c-prefixed counterpart in
13008 <complex.h> (except modf), the corresponding type-generic macro has the same
13009 name as the function. These type-generic macros are:
13010 atan2 fma llround remainder
13011 cbrt fmax log10 remquo
13012 ceil fmin log1p rint
13013 copysign fmod log2 round
13014 erf frexp logb scalbn
13015 erfc hypot lrint scalbln
13016 exp2 ilogb lround tgamma
13017 expm1 ldexp nearbyint trunc
13018 fdim lgamma nextafter
13019 floor llrint nexttoward
13020 If all arguments for generic parameters are real, then use of the macro invokes a real
13021 function; otherwise, use of the macro results in undefined behavior.
13022 6 For each unsuffixed function in <complex.h> that is not a c-prefixed counterpart to a
13023 function in <math.h>, the corresponding type-generic macro has the same name as the
13024 function. These type-generic macros are:
13030 Use of the macro with any real or complex argument invokes a complex function.
13031 7 EXAMPLE With the declarations
13032 #include <tgmath.h>
13039 long double complex ldc;
13040 functions invoked by use of type-generic macros are shown in the following table:
13042 exp(n) exp(n), the function
13044 sin(d) sin(d), the function
13048 pow(ldc, f) cpowl(ldc, f)
13049 remainder(n, n) remainder(n, n), the function
13050 nextafter(d, f) nextafter(d, f), the function
13051 nexttoward(f, ld) nexttowardf(f, ld)
13052 copysign(n, ld) copysignl(n, ld)
13053 ceil(fc) undefined behavior
13054 rint(dc) undefined behavior
13055 fmax(ldc, ld) undefined behavior
13056 carg(n) carg(n), the function
13058 creal(d) creal(d), the function
13059 cimag(ld) cimagl(ld)
13061 carg(dc) carg(dc), the function
13062 cproj(ldc) cprojl(ldc)
13066 7.23 Date and time <time.h>
13067 7.23.1 Components of time
13068 1 The header <time.h> defines two macros, and declares several types and functions for
13069 manipulating time. Many functions deal with a calendar time that represents the current
13070 date (according to the Gregorian calendar) and time. Some functions deal with local
13071 time, which is the calendar time expressed for some specific time zone, and with Daylight
13072 Saving Time, which is a temporary change in the algorithm for determining local time.
13073 The local time zone and Daylight Saving Time are implementation-defined.
13074 2 The macros defined are NULL (described in 7.17); and
13076 which expands to an expression with type clock_t (described below) that is the
13077 number per second of the value returned by the clock function.
13078 3 The types declared are size_t (described in 7.17);
13082 which are arithmetic types capable of representing times; and
13084 which holds the components of a calendar time, called the broken-down time.
13085 4 The range and precision of times representable in clock_t and time_t are
13086 implementation-defined. The tm structure shall contain at least the following members,
13087 in any order. The semantics of the members and their normal ranges are expressed in the
13089 int tm_sec; // seconds after the minute -- [0, 60]
13090 int tm_min; // minutes after the hour -- [0, 59]
13091 int tm_hour; // hours since midnight -- [0, 23]
13092 int tm_mday; // day of the month -- [1, 31]
13093 int tm_mon; // months since January -- [0, 11]
13094 int tm_year; // years since 1900
13095 int tm_wday; // days since Sunday -- [0, 6]
13096 int tm_yday; // days since January 1 -- [0, 365]
13097 int tm_isdst; // Daylight Saving Time flag
13101 274) The range [0, 60] for tm_sec allows for a positive leap second.
13105 The value of tm_isdst is positive if Daylight Saving Time is in effect, zero if Daylight
13106 Saving Time is not in effect, and negative if the information is not available.
13107 7.23.2 Time manipulation functions
13108 7.23.2.1 The clock function
13110 1 #include <time.h>
13111 clock_t clock(void);
13113 2 The clock function determines the processor time used.
13115 3 The clock function returns the implementation's best approximation to the processor
13116 time used by the program since the beginning of an implementation-defined era related
13117 only to the program invocation. To determine the time in seconds, the value returned by
13118 the clock function should be divided by the value of the macro CLOCKS_PER_SEC. If
13119 the processor time used is not available or its value cannot be represented, the function
13120 returns the value (clock_t)(-1).275)
13121 7.23.2.2 The difftime function
13123 1 #include <time.h>
13124 double difftime(time_t time1, time_t time0);
13126 2 The difftime function computes the difference between two calendar times: time1 -
13129 3 The difftime function returns the difference expressed in seconds as a double.
13134 275) In order to measure the time spent in a program, the clock function should be called at the start of
13135 the program and its return value subtracted from the value returned by subsequent calls.
13139 7.23.2.3 The mktime function
13141 1 #include <time.h>
13142 time_t mktime(struct tm *timeptr);
13144 2 The mktime function converts the broken-down time, expressed as local time, in the
13145 structure pointed to by timeptr into a calendar time value with the same encoding as
13146 that of the values returned by the time function. The original values of the tm_wday
13147 and tm_yday components of the structure are ignored, and the original values of the
13148 other components are not restricted to the ranges indicated above.276) On successful
13149 completion, the values of the tm_wday and tm_yday components of the structure are
13150 set appropriately, and the other components are set to represent the specified calendar
13151 time, but with their values forced to the ranges indicated above; the final value of
13152 tm_mday is not set until tm_mon and tm_year are determined.
13154 3 The mktime function returns the specified calendar time encoded as a value of type
13155 time_t. If the calendar time cannot be represented, the function returns the value
13157 4 EXAMPLE What day of the week is July 4, 2001?
13160 static const char *const wday[] = {
13161 "Sunday", "Monday", "Tuesday", "Wednesday",
13162 "Thursday", "Friday", "Saturday", "-unknown-"
13164 struct tm time_str;
13170 276) Thus, a positive or zero value for tm_isdst causes the mktime function to presume initially that
13171 Daylight Saving Time, respectively, is or is not in effect for the specified time. A negative value
13172 causes it to attempt to determine whether Daylight Saving Time is in effect for the specified time.
13176 time_str.tm_year = 2001 - 1900;
13177 time_str.tm_mon = 7 - 1;
13178 time_str.tm_mday = 4;
13179 time_str.tm_hour = 0;
13180 time_str.tm_min = 0;
13181 time_str.tm_sec = 1;
13182 time_str.tm_isdst = -1;
13183 if (mktime(&time_str) == (time_t)(-1))
13184 time_str.tm_wday = 7;
13185 printf("%s\n", wday[time_str.tm_wday]);
13187 7.23.2.4 The time function
13189 1 #include <time.h>
13190 time_t time(time_t *timer);
13192 2 The time function determines the current calendar time. The encoding of the value is
13195 3 The time function returns the implementation's best approximation to the current
13196 calendar time. The value (time_t)(-1) is returned if the calendar time is not
13197 available. If timer is not a null pointer, the return value is also assigned to the object it
13199 7.23.3 Time conversion functions
13200 1 Except for the strftime function, these functions each return a pointer to one of two
13201 types of static objects: a broken-down time structure or an array of char. Execution of
13202 any of the functions that return a pointer to one of these object types may overwrite the
13203 information in any object of the same type pointed to by the value returned from any
13204 previous call to any of them. The implementation shall behave as if no other library
13205 functions call these functions.
13206 7.23.3.1 The asctime function
13208 1 #include <time.h>
13209 char *asctime(const struct tm *timeptr);
13211 2 The asctime function converts the broken-down time in the structure pointed to by
13212 timeptr into a string in the form
13213 Sun Sep 16 01:03:52 1973\n\0
13217 using the equivalent of the following algorithm.
13218 char *asctime(const struct tm *timeptr)
13220 static const char wday_name[7][3] = {
13221 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
13223 static const char mon_name[12][3] = {
13224 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
13225 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
13227 static char result[26];
13228 sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
13229 wday_name[timeptr->tm_wday],
13230 mon_name[timeptr->tm_mon],
13231 timeptr->tm_mday, timeptr->tm_hour,
13232 timeptr->tm_min, timeptr->tm_sec,
13233 1900 + timeptr->tm_year);
13237 3 The asctime function returns a pointer to the string.
13238 7.23.3.2 The ctime function
13240 1 #include <time.h>
13241 char *ctime(const time_t *timer);
13243 2 The ctime function converts the calendar time pointed to by timer to local time in the
13244 form of a string. It is equivalent to
13245 asctime(localtime(timer))
13247 3 The ctime function returns the pointer returned by the asctime function with that
13248 broken-down time as argument.
13249 Forward references: the localtime function (7.23.3.4).
13253 7.23.3.3 The gmtime function
13255 1 #include <time.h>
13256 struct tm *gmtime(const time_t *timer);
13258 2 The gmtime function converts the calendar time pointed to by timer into a broken-
13259 down time, expressed as UTC.
13261 3 The gmtime function returns a pointer to the broken-down time, or a null pointer if the
13262 specified time cannot be converted to UTC.
13263 7.23.3.4 The localtime function
13265 1 #include <time.h>
13266 struct tm *localtime(const time_t *timer);
13268 2 The localtime function converts the calendar time pointed to by timer into a
13269 broken-down time, expressed as local time.
13271 3 The localtime function returns a pointer to the broken-down time, or a null pointer if
13272 the specified time cannot be converted to local time.
13273 7.23.3.5 The strftime function
13275 1 #include <time.h>
13276 size_t strftime(char * restrict s,
13278 const char * restrict format,
13279 const struct tm * restrict timeptr);
13281 2 The strftime function places characters into the array pointed to by s as controlled by
13282 the string pointed to by format. The format shall be a multibyte character sequence,
13283 beginning and ending in its initial shift state. The format string consists of zero or
13284 more conversion specifiers and ordinary multibyte characters. A conversion specifier
13285 consists of a % character, possibly followed by an E or O modifier character (described
13286 below), followed by a character that determines the behavior of the conversion specifier.
13287 All ordinary multibyte characters (including the terminating null character) are copied
13291 unchanged into the array. If copying takes place between objects that overlap, the
13292 behavior is undefined. No more than maxsize characters are placed into the array.
13293 3 Each conversion specifier is replaced by appropriate characters as described in the
13294 following list. The appropriate characters are determined using the LC_TIME category
13295 of the current locale and by the values of zero or more members of the broken-down time
13296 structure pointed to by timeptr, as specified in brackets in the description. If any of
13297 the specified values is outside the normal range, the characters stored are unspecified.
13298 %a is replaced by the locale's abbreviated weekday name. [tm_wday]
13299 %A is replaced by the locale's full weekday name. [tm_wday]
13300 %b is replaced by the locale's abbreviated month name. [tm_mon]
13301 %B is replaced by the locale's full month name. [tm_mon]
13302 %c is replaced by the locale's appropriate date and time representation. [all specified
13304 %C is replaced by the year divided by 100 and truncated to an integer, as a decimal
13305 number (00-99). [tm_year]
13306 %d is replaced by the day of the month as a decimal number (01-31). [tm_mday]
13307 %D is equivalent to ''%m/%d/%y''. [tm_mon, tm_mday, tm_year]
13308 %e is replaced by the day of the month as a decimal number (1-31); a single digit is
13309 preceded by a space. [tm_mday]
13310 %F is equivalent to ''%Y-%m-%d'' (the ISO 8601 date format). [tm_year, tm_mon,
13312 %g is replaced by the last 2 digits of the week-based year (see below) as a decimal
13313 number (00-99). [tm_year, tm_wday, tm_yday]
13314 %G is replaced by the week-based year (see below) as a decimal number (e.g., 1997).
13315 [tm_year, tm_wday, tm_yday]
13316 %h is equivalent to ''%b''. [tm_mon]
13317 %H is replaced by the hour (24-hour clock) as a decimal number (00-23). [tm_hour]
13318 %I is replaced by the hour (12-hour clock) as a decimal number (01-12). [tm_hour]
13319 %j is replaced by the day of the year as a decimal number (001-366). [tm_yday]
13320 %m is replaced by the month as a decimal number (01-12). [tm_mon]
13321 %M is replaced by the minute as a decimal number (00-59). [tm_min]
13322 %n is replaced by a new-line character.
13323 %p is replaced by the locale's equivalent of the AM/PM designations associated with a
13324 12-hour clock. [tm_hour]
13325 %r is replaced by the locale's 12-hour clock time. [tm_hour, tm_min, tm_sec]
13326 %R is equivalent to ''%H:%M''. [tm_hour, tm_min]
13327 %S is replaced by the second as a decimal number (00-60). [tm_sec]
13328 %t is replaced by a horizontal-tab character.
13329 %T is equivalent to ''%H:%M:%S'' (the ISO 8601 time format). [tm_hour, tm_min,
13334 %u is replaced by the ISO 8601 weekday as a decimal number (1-7), where Monday
13336 %U is replaced by the week number of the year (the first Sunday as the first day of week
13337 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
13338 %V is replaced by the ISO 8601 week number (see below) as a decimal number
13339 (01-53). [tm_year, tm_wday, tm_yday]
13340 %w is replaced by the weekday as a decimal number (0-6), where Sunday is 0.
13342 %W is replaced by the week number of the year (the first Monday as the first day of
13343 week 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
13344 %x is replaced by the locale's appropriate date representation. [all specified in 7.23.1]
13345 %X is replaced by the locale's appropriate time representation. [all specified in 7.23.1]
13346 %y is replaced by the last 2 digits of the year as a decimal number (00-99).
13348 %Y is replaced by the year as a decimal number (e.g., 1997). [tm_year]
13349 %z is replaced by the offset from UTC in the ISO 8601 format ''-0430'' (meaning 4
13350 hours 30 minutes behind UTC, west of Greenwich), or by no characters if no time
13351 zone is determinable. [tm_isdst]
13352 %Z is replaced by the locale's time zone name or abbreviation, or by no characters if no
13353 time zone is determinable. [tm_isdst]
13354 %% is replaced by %.
13355 4 Some conversion specifiers can be modified by the inclusion of an E or O modifier
13356 character to indicate an alternative format or specification. If the alternative format or
13357 specification does not exist for the current locale, the modifier is ignored.
13358 %Ec is replaced by the locale's alternative date and time representation.
13359 %EC is replaced by the name of the base year (period) in the locale's alternative
13361 %Ex is replaced by the locale's alternative date representation.
13362 %EX is replaced by the locale's alternative time representation.
13363 %Ey is replaced by the offset from %EC (year only) in the locale's alternative
13365 %EY is replaced by the locale's full alternative year representation.
13366 %Od is replaced by the day of the month, using the locale's alternative numeric symbols
13367 (filled as needed with leading zeros, or with leading spaces if there is no alternative
13369 %Oe is replaced by the day of the month, using the locale's alternative numeric symbols
13370 (filled as needed with leading spaces).
13371 %OH is replaced by the hour (24-hour clock), using the locale's alternative numeric
13376 %OI is replaced by the hour (12-hour clock), using the locale's alternative numeric
13378 %Om is replaced by the month, using the locale's alternative numeric symbols.
13379 %OM is replaced by the minutes, using the locale's alternative numeric symbols.
13380 %OS is replaced by the seconds, using the locale's alternative numeric symbols.
13381 %Ou is replaced by the ISO 8601 weekday as a number in the locale's alternative
13382 representation, where Monday is 1.
13383 %OU is replaced by the week number, using the locale's alternative numeric symbols.
13384 %OV is replaced by the ISO 8601 week number, using the locale's alternative numeric
13386 %Ow is replaced by the weekday as a number, using the locale's alternative numeric
13388 %OW is replaced by the week number of the year, using the locale's alternative numeric
13390 %Oy is replaced by the last 2 digits of the year, using the locale's alternative numeric
13392 5 %g, %G, and %V give values according to the ISO 8601 week-based year. In this system,
13393 weeks begin on a Monday and week 1 of the year is the week that includes January 4th,
13394 which is also the week that includes the first Thursday of the year, and is also the first
13395 week that contains at least four days in the year. If the first Monday of January is the
13396 2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year; thus,
13397 for Saturday 2nd January 1999, %G is replaced by 1998 and %V is replaced by 53. If
13398 December 29th, 30th, or 31st is a Monday, it and any following days are part of week 1 of
13399 the following year. Thus, for Tuesday 30th December 1997, %G is replaced by 1998 and
13400 %V is replaced by 01.
13401 6 If a conversion specifier is not one of the above, the behavior is undefined.
13402 7 In the "C" locale, the E and O modifiers are ignored and the replacement strings for the
13403 following specifiers are:
13404 %a the first three characters of %A.
13405 %A one of ''Sunday'', ''Monday'', ... , ''Saturday''.
13406 %b the first three characters of %B.
13407 %B one of ''January'', ''February'', ... , ''December''.
13408 %c equivalent to ''%a %b %e %T %Y''.
13409 %p one of ''AM'' or ''PM''.
13410 %r equivalent to ''%I:%M:%S %p''.
13411 %x equivalent to ''%m/%d/%y''.
13412 %X equivalent to %T.
13413 %Z implementation-defined.
13418 8 If the total number of resulting characters including the terminating null character is not
13419 more than maxsize, the strftime function returns the number of characters placed
13420 into the array pointed to by s not including the terminating null character. Otherwise,
13421 zero is returned and the contents of the array are indeterminate.
13425 7.24 Extended multibyte and wide character utilities <wchar.h>
13426 7.24.1 Introduction
13427 1 The header <wchar.h> declares four data types, one tag, four macros, and many
13429 2 The types declared are wchar_t and size_t (both described in 7.17);
13431 which is an object type other than an array type that can hold the conversion state
13432 information necessary to convert between sequences of multibyte characters and wide
13435 which is an integer type unchanged by default argument promotions that can hold any
13436 value corresponding to members of the extended character set, as well as at least one
13437 value that does not correspond to any member of the extended character set (see WEOF
13440 which is declared as an incomplete structure type (the contents are described in 7.23.1).
13441 3 The macros defined are NULL (described in 7.17); WCHAR_MIN and WCHAR_MAX
13442 (described in 7.18.3); and
13444 which expands to a constant expression of type wint_t whose value does not
13445 correspond to any member of the extended character set.279) It is accepted (and returned)
13446 by several functions in this subclause to indicate end-of-file, that is, no more input from a
13447 stream. It is also used as a wide character value that does not correspond to any member
13448 of the extended character set.
13449 4 The functions declared are grouped as follows:
13450 -- Functions that perform input and output of wide characters, or multibyte characters,
13452 -- Functions that provide wide string numeric conversion;
13453 -- Functions that perform general wide string manipulation;
13456 277) See ''future library directions'' (7.26.12).
13457 278) wchar_t and wint_t can be the same integer type.
13458 279) The value of the macro WEOF may differ from that of EOF and need not be negative.
13462 -- Functions for wide string date and time conversion; and
13463 -- Functions that provide extended capabilities for conversion between multibyte and
13464 wide character sequences.
13465 5 Unless explicitly stated otherwise, if the execution of a function described in this
13466 subclause causes copying to take place between objects that overlap, the behavior is
13468 7.24.2 Formatted wide character input/output functions
13469 1 The formatted wide character input/output functions shall behave as if there is a sequence
13470 point after the actions associated with each specifier.280)
13471 7.24.2.1 The fwprintf function
13473 1 #include <stdio.h>
13475 int fwprintf(FILE * restrict stream,
13476 const wchar_t * restrict format, ...);
13478 2 The fwprintf function writes output to the stream pointed to by stream, under
13479 control of the wide string pointed to by format that specifies how subsequent arguments
13480 are converted for output. If there are insufficient arguments for the format, the behavior
13481 is undefined. If the format is exhausted while arguments remain, the excess arguments
13482 are evaluated (as always) but are otherwise ignored. The fwprintf function returns
13483 when the end of the format string is encountered.
13484 3 The format is composed of zero or more directives: ordinary wide characters (not %),
13485 which are copied unchanged to the output stream; and conversion specifications, each of
13486 which results in fetching zero or more subsequent arguments, converting them, if
13487 applicable, according to the corresponding conversion specifier, and then writing the
13488 result to the output stream.
13489 4 Each conversion specification is introduced by the wide character %. After the %, the
13490 following appear in sequence:
13491 -- Zero or more flags (in any order) that modify the meaning of the conversion
13493 -- An optional minimum field width. If the converted value has fewer wide characters
13494 than the field width, it is padded with spaces (by default) on the left (or right, if the
13497 280) The fwprintf functions perform writes to memory for the %n specifier.
13501 left adjustment flag, described later, has been given) to the field width. The field
13502 width takes the form of an asterisk * (described later) or a nonnegative decimal
13504 -- An optional precision that gives the minimum number of digits to appear for the d, i,
13505 o, u, x, and X conversions, the number of digits to appear after the decimal-point
13506 wide character for a, A, e, E, f, and F conversions, the maximum number of
13507 significant digits for the g and G conversions, or the maximum number of wide
13508 characters to be written for s conversions. The precision takes the form of a period
13509 (.) followed either by an asterisk * (described later) or by an optional decimal
13510 integer; if only the period is specified, the precision is taken as zero. If a precision
13511 appears with any other conversion specifier, the behavior is undefined.
13512 -- An optional length modifier that specifies the size of the argument.
13513 -- A conversion specifier wide character that specifies the type of conversion to be
13515 5 As noted above, a field width, or precision, or both, may be indicated by an asterisk. In
13516 this case, an int argument supplies the field width or precision. The arguments
13517 specifying field width, or precision, or both, shall appear (in that order) before the
13518 argument (if any) to be converted. A negative field width argument is taken as a - flag
13519 followed by a positive field width. A negative precision argument is taken as if the
13520 precision were omitted.
13521 6 The flag wide characters and their meanings are:
13522 - The result of the conversion is left-justified within the field. (It is right-justified if
13523 this flag is not specified.)
13524 + The result of a signed conversion always begins with a plus or minus sign. (It
13525 begins with a sign only when a negative value is converted if this flag is not
13527 space If the first wide character of a signed conversion is not a sign, or if a signed
13528 conversion results in no wide characters, a space is prefixed to the result. If the
13529 space and + flags both appear, the space flag is ignored.
13530 # The result is converted to an ''alternative form''. For o conversion, it increases
13531 the precision, if and only if necessary, to force the first digit of the result to be a
13532 zero (if the value and precision are both 0, a single 0 is printed). For x (or X)
13533 conversion, a nonzero result has 0x (or 0X) prefixed to it. For a, A, e, E, f, F, g,
13535 281) Note that 0 is taken as a flag, not as the beginning of a field width.
13536 282) The results of all floating conversions of a negative zero, and of negative values that round to zero,
13537 include a minus sign.
13541 and G conversions, the result of converting a floating-point number always
13542 contains a decimal-point wide character, even if no digits follow it. (Normally, a
13543 decimal-point wide character appears in the result of these conversions only if a
13544 digit follows it.) For g and G conversions, trailing zeros are not removed from the
13545 result. For other conversions, the behavior is undefined.
13546 0 For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros
13547 (following any indication of sign or base) are used to pad to the field width rather
13548 than performing space padding, except when converting an infinity or NaN. If the
13549 0 and - flags both appear, the 0 flag is ignored. For d, i, o, u, x, and X
13550 conversions, if a precision is specified, the 0 flag is ignored. For other
13551 conversions, the behavior is undefined.
13552 7 The length modifiers and their meanings are:
13553 hh Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13554 signed char or unsigned char argument (the argument will have
13555 been promoted according to the integer promotions, but its value shall be
13556 converted to signed char or unsigned char before printing); or that
13557 a following n conversion specifier applies to a pointer to a signed char
13559 h Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13560 short int or unsigned short int argument (the argument will
13561 have been promoted according to the integer promotions, but its value shall
13562 be converted to short int or unsigned short int before printing);
13563 or that a following n conversion specifier applies to a pointer to a short
13565 l (ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13566 long int or unsigned long int argument; that a following n
13567 conversion specifier applies to a pointer to a long int argument; that a
13568 following c conversion specifier applies to a wint_t argument; that a
13569 following s conversion specifier applies to a pointer to a wchar_t
13570 argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion
13572 ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13573 long long int or unsigned long long int argument; or that a
13574 following n conversion specifier applies to a pointer to a long long int
13576 j Specifies that a following d, i, o, u, x, or X conversion specifier applies to
13577 an intmax_t or uintmax_t argument; or that a following n conversion
13578 specifier applies to a pointer to an intmax_t argument.
13582 z Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13583 size_t or the corresponding signed integer type argument; or that a
13584 following n conversion specifier applies to a pointer to a signed integer type
13585 corresponding to size_t argument.
13586 t Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13587 ptrdiff_t or the corresponding unsigned integer type argument; or that a
13588 following n conversion specifier applies to a pointer to a ptrdiff_t
13590 L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
13591 applies to a long double argument.
13592 If a length modifier appears with any conversion specifier other than as specified above,
13593 the behavior is undefined.
13594 8 The conversion specifiers and their meanings are:
13595 d,i The int argument is converted to signed decimal in the style [-]dddd. The
13596 precision specifies the minimum number of digits to appear; if the value
13597 being converted can be represented in fewer digits, it is expanded with
13598 leading zeros. The default precision is 1. The result of converting a zero
13599 value with a precision of zero is no wide characters.
13600 o,u,x,X The unsigned int argument is converted to unsigned octal (o), unsigned
13601 decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; the
13602 letters abcdef are used for x conversion and the letters ABCDEF for X
13603 conversion. The precision specifies the minimum number of digits to appear;
13604 if the value being converted can be represented in fewer digits, it is expanded
13605 with leading zeros. The default precision is 1. The result of converting a
13606 zero value with a precision of zero is no wide characters.
13607 f,F A double argument representing a floating-point number is converted to
13608 decimal notation in the style [-]ddd.ddd, where the number of digits after
13609 the decimal-point wide character is equal to the precision specification. If the
13610 precision is missing, it is taken as 6; if the precision is zero and the # flag is
13611 not specified, no decimal-point wide character appears. If a decimal-point
13612 wide character appears, at least one digit appears before it. The value is
13613 rounded to the appropriate number of digits.
13614 A double argument representing an infinity is converted in one of the styles
13615 [-]inf or [-]infinity -- which style is implementation-defined. A
13616 double argument representing a NaN is converted in one of the styles
13617 [-]nan or [-]nan(n-wchar-sequence) -- which style, and the meaning of
13618 any n-wchar-sequence, is implementation-defined. The F conversion
13619 specifier produces INF, INFINITY, or NAN instead of inf, infinity, or
13623 nan, respectively.283)
13624 e,E A double argument representing a floating-point number is converted in the
13625 style [-]d.ddd e(+-)dd, where there is one digit (which is nonzero if the
13626 argument is nonzero) before the decimal-point wide character and the number
13627 of digits after it is equal to the precision; if the precision is missing, it is taken
13628 as 6; if the precision is zero and the # flag is not specified, no decimal-point
13629 wide character appears. The value is rounded to the appropriate number of
13630 digits. The E conversion specifier produces a number with E instead of e
13631 introducing the exponent. The exponent always contains at least two digits,
13632 and only as many more digits as necessary to represent the exponent. If the
13633 value is zero, the exponent is zero.
13634 A double argument representing an infinity or NaN is converted in the style
13635 of an f or F conversion specifier.
13636 g,G A double argument representing a floating-point number is converted in
13637 style f or e (or in style F or E in the case of a G conversion specifier),
13638 depending on the value converted and the precision. Let P equal the
13639 precision if nonzero, 6 if the precision is omitted, or 1 if the precision is zero.
13640 Then, if a conversion with style E would have an exponent of X :
13641 -- if P > X >= -4, the conversion is with style f (or F) and precision
13643 -- otherwise, the conversion is with style e (or E) and precision P - 1.
13644 Finally, unless the # flag is used, any trailing zeros are removed from the
13645 fractional portion of the result and the decimal-point wide character is
13646 removed if there is no fractional portion remaining.
13647 A double argument representing an infinity or NaN is converted in the style
13648 of an f or F conversion specifier.
13649 a,A A double argument representing a floating-point number is converted in the
13650 style [-]0xh.hhhh p(+-)d, where there is one hexadecimal digit (which is
13651 nonzero if the argument is a normalized floating-point number and is
13652 otherwise unspecified) before the decimal-point wide character284) and the
13653 number of hexadecimal digits after it is equal to the precision; if the precision
13654 is missing and FLT_RADIX is a power of 2, then the precision is sufficient
13657 283) When applied to infinite and NaN values, the -, +, and space flag wide characters have their usual
13658 meaning; the # and 0 flag wide characters have no effect.
13659 284) Binary implementations can choose the hexadecimal digit to the left of the decimal-point wide
13660 character so that subsequent digits align to nibble (4-bit) boundaries.
13664 for an exact representation of the value; if the precision is missing and
13665 FLT_RADIX is not a power of 2, then the precision is sufficient to
13666 distinguish285) values of type double, except that trailing zeros may be
13667 omitted; if the precision is zero and the # flag is not specified, no decimal-
13668 point wide character appears. The letters abcdef are used for a conversion
13669 and the letters ABCDEF for A conversion. The A conversion specifier
13670 produces a number with X and P instead of x and p. The exponent always
13671 contains at least one digit, and only as many more digits as necessary to
13672 represent the decimal exponent of 2. If the value is zero, the exponent is
13674 A double argument representing an infinity or NaN is converted in the style
13675 of an f or F conversion specifier.
13676 c If no l length modifier is present, the int argument is converted to a wide
13677 character as if by calling btowc and the resulting wide character is written.
13678 If an l length modifier is present, the wint_t argument is converted to
13679 wchar_t and written.
13680 s If no l length modifier is present, the argument shall be a pointer to the initial
13681 element of a character array containing a multibyte character sequence
13682 beginning in the initial shift state. Characters from the array are converted as
13683 if by repeated calls to the mbrtowc function, with the conversion state
13684 described by an mbstate_t object initialized to zero before the first
13685 multibyte character is converted, and written up to (but not including) the
13686 terminating null wide character. If the precision is specified, no more than
13687 that many wide characters are written. If the precision is not specified or is
13688 greater than the size of the converted array, the converted array shall contain a
13689 null wide character.
13690 If an l length modifier is present, the argument shall be a pointer to the initial
13691 element of an array of wchar_t type. Wide characters from the array are
13692 written up to (but not including) a terminating null wide character. If the
13693 precision is specified, no more than that many wide characters are written. If
13694 the precision is not specified or is greater than the size of the array, the array
13695 shall contain a null wide character.
13696 p The argument shall be a pointer to void. The value of the pointer is
13697 converted to a sequence of printing wide characters, in an implementation-
13699 285) The precision p is sufficient to distinguish values of the source type if 16 p-1 > b n where b is
13700 FLT_RADIX and n is the number of base-b digits in the significand of the source type. A smaller p
13701 might suffice depending on the implementation's scheme for determining the digit to the left of the
13702 decimal-point wide character.
13707 n The argument shall be a pointer to signed integer into which is written the
13708 number of wide characters written to the output stream so far by this call to
13709 fwprintf. No argument is converted, but one is consumed. If the
13710 conversion specification includes any flags, a field width, or a precision, the
13711 behavior is undefined.
13712 % A % wide character is written. No argument is converted. The complete
13713 conversion specification shall be %%.
13714 9 If a conversion specification is invalid, the behavior is undefined.286) If any argument is
13715 not the correct type for the corresponding conversion specification, the behavior is
13717 10 In no case does a nonexistent or small field width cause truncation of a field; if the result
13718 of a conversion is wider than the field width, the field is expanded to contain the
13720 11 For a and A conversions, if FLT_RADIX is a power of 2, the value is correctly rounded
13721 to a hexadecimal floating number with the given precision.
13722 Recommended practice
13723 12 For a and A conversions, if FLT_RADIX is not a power of 2 and the result is not exactly
13724 representable in the given precision, the result should be one of the two adjacent numbers
13725 in hexadecimal floating style with the given precision, with the extra stipulation that the
13726 error should have a correct sign for the current rounding direction.
13727 13 For e, E, f, F, g, and G conversions, if the number of significant decimal digits is at most
13728 DECIMAL_DIG, then the result should be correctly rounded.287) If the number of
13729 significant decimal digits is more than DECIMAL_DIG but the source value is exactly
13730 representable with DECIMAL_DIG digits, then the result should be an exact
13731 representation with trailing zeros. Otherwise, the source value is bounded by two
13732 adjacent decimal strings L < U, both having DECIMAL_DIG significant digits; the value
13733 of the resultant decimal string D should satisfy L <= D <= U, with the extra stipulation that
13734 the error should have a correct sign for the current rounding direction.
13736 14 The fwprintf function returns the number of wide characters transmitted, or a negative
13737 value if an output or encoding error occurred.
13739 286) See ''future library directions'' (7.26.12).
13740 287) For binary-to-decimal conversion, the result format's values are the numbers representable with the
13741 given format specifier. The number of significant digits is determined by the format specifier, and in
13742 the case of fixed-point conversion by the source value as well.
13746 Environmental limits
13747 15 The number of wide characters that can be produced by any single conversion shall be at
13749 16 EXAMPLE To print a date and time in the form ''Sunday, July 3, 10:02'' followed by pi to five decimal
13755 wchar_t *weekday, *month; // pointers to wide strings
13756 int day, hour, min;
13757 fwprintf(stdout, L"%ls, %ls %d, %.2d:%.2d\n",
13758 weekday, month, day, hour, min);
13759 fwprintf(stdout, L"pi = %.5f\n", 4 * atan(1.0));
13761 Forward references: the btowc function (7.24.6.1.1), the mbrtowc function
13763 7.24.2.2 The fwscanf function
13765 1 #include <stdio.h>
13767 int fwscanf(FILE * restrict stream,
13768 const wchar_t * restrict format, ...);
13770 2 The fwscanf function reads input from the stream pointed to by stream, under
13771 control of the wide string pointed to by format that specifies the admissible input
13772 sequences and how they are to be converted for assignment, using subsequent arguments
13773 as pointers to the objects to receive the converted input. If there are insufficient
13774 arguments for the format, the behavior is undefined. If the format is exhausted while
13775 arguments remain, the excess arguments are evaluated (as always) but are otherwise
13777 3 The format is composed of zero or more directives: one or more white-space wide
13778 characters, an ordinary wide character (neither % nor a white-space wide character), or a
13779 conversion specification. Each conversion specification is introduced by the wide
13780 character %. After the %, the following appear in sequence:
13781 -- An optional assignment-suppressing wide character *.
13782 -- An optional decimal integer greater than zero that specifies the maximum field width
13783 (in wide characters).
13787 -- An optional length modifier that specifies the size of the receiving object.
13788 -- A conversion specifier wide character that specifies the type of conversion to be
13790 4 The fwscanf function executes each directive of the format in turn. If a directive fails,
13791 as detailed below, the function returns. Failures are described as input failures (due to the
13792 occurrence of an encoding error or the unavailability of input characters), or matching
13793 failures (due to inappropriate input).
13794 5 A directive composed of white-space wide character(s) is executed by reading input up to
13795 the first non-white-space wide character (which remains unread), or until no more wide
13796 characters can be read.
13797 6 A directive that is an ordinary wide character is executed by reading the next wide
13798 character of the stream. If that wide character differs from the directive, the directive
13799 fails and the differing and subsequent wide characters remain unread. Similarly, if end-
13800 of-file, an encoding error, or a read error prevents a wide character from being read, the
13802 7 A directive that is a conversion specification defines a set of matching input sequences, as
13803 described below for each specifier. A conversion specification is executed in the
13805 8 Input white-space wide characters (as specified by the iswspace function) are skipped,
13806 unless the specification includes a [, c, or n specifier.288)
13807 9 An input item is read from the stream, unless the specification includes an n specifier. An
13808 input item is defined as the longest sequence of input wide characters which does not
13809 exceed any specified field width and which is, or is a prefix of, a matching input
13810 sequence.289) The first wide character, if any, after the input item remains unread. If the
13811 length of the input item is zero, the execution of the directive fails; this condition is a
13812 matching failure unless end-of-file, an encoding error, or a read error prevented input
13813 from the stream, in which case it is an input failure.
13814 10 Except in the case of a % specifier, the input item (or, in the case of a %n directive, the
13815 count of input wide characters) is converted to a type appropriate to the conversion
13816 specifier. If the input item is not a matching sequence, the execution of the directive fails:
13817 this condition is a matching failure. Unless assignment suppression was indicated by a *,
13818 the result of the conversion is placed in the object pointed to by the first argument
13819 following the format argument that has not already received a conversion result. If this
13822 288) These white-space wide characters are not counted against a specified field width.
13823 289) fwscanf pushes back at most one input wide character onto the input stream. Therefore, some
13824 sequences that are acceptable to wcstod, wcstol, etc., are unacceptable to fwscanf.
13828 object does not have an appropriate type, or if the result of the conversion cannot be
13829 represented in the object, the behavior is undefined.
13830 11 The length modifiers and their meanings are:
13831 hh Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
13832 to an argument with type pointer to signed char or unsigned char.
13833 h Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
13834 to an argument with type pointer to short int or unsigned short
13836 l (ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
13837 to an argument with type pointer to long int or unsigned long
13838 int; that a following a, A, e, E, f, F, g, or G conversion specifier applies to
13839 an argument with type pointer to double; or that a following c, s, or [
13840 conversion specifier applies to an argument with type pointer to wchar_t.
13841 ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
13842 to an argument with type pointer to long long int or unsigned
13844 j Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
13845 to an argument with type pointer to intmax_t or uintmax_t.
13846 z Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
13847 to an argument with type pointer to size_t or the corresponding signed
13849 t Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
13850 to an argument with type pointer to ptrdiff_t or the corresponding
13851 unsigned integer type.
13852 L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
13853 applies to an argument with type pointer to long double.
13854 If a length modifier appears with any conversion specifier other than as specified above,
13855 the behavior is undefined.
13856 12 The conversion specifiers and their meanings are:
13857 d Matches an optionally signed decimal integer, whose format is the same as
13858 expected for the subject sequence of the wcstol function with the value 10
13859 for the base argument. The corresponding argument shall be a pointer to
13861 i Matches an optionally signed integer, whose format is the same as expected
13862 for the subject sequence of the wcstol function with the value 0 for the
13863 base argument. The corresponding argument shall be a pointer to signed
13868 o Matches an optionally signed octal integer, whose format is the same as
13869 expected for the subject sequence of the wcstoul function with the value 8
13870 for the base argument. The corresponding argument shall be a pointer to
13872 u Matches an optionally signed decimal integer, whose format is the same as
13873 expected for the subject sequence of the wcstoul function with the value 10
13874 for the base argument. The corresponding argument shall be a pointer to
13876 x Matches an optionally signed hexadecimal integer, whose format is the same
13877 as expected for the subject sequence of the wcstoul function with the value
13878 16 for the base argument. The corresponding argument shall be a pointer to
13880 a,e,f,g Matches an optionally signed floating-point number, infinity, or NaN, whose
13881 format is the same as expected for the subject sequence of the wcstod
13882 function. The corresponding argument shall be a pointer to floating.
13883 c Matches a sequence of wide characters of exactly the number specified by the
13884 field width (1 if no field width is present in the directive).
13885 If no l length modifier is present, characters from the input field are
13886 converted as if by repeated calls to the wcrtomb function, with the
13887 conversion state described by an mbstate_t object initialized to zero
13888 before the first wide character is converted. The corresponding argument
13889 shall be a pointer to the initial element of a character array large enough to
13890 accept the sequence. No null character is added.
13891 If an l length modifier is present, the corresponding argument shall be a
13892 pointer to the initial element of an array of wchar_t large enough to accept
13893 the sequence. No null wide character is added.
13894 s Matches a sequence of non-white-space wide characters.
13895 If no l length modifier is present, characters from the input field are
13896 converted as if by repeated calls to the wcrtomb function, with the
13897 conversion state described by an mbstate_t object initialized to zero
13898 before the first wide character is converted. The corresponding argument
13899 shall be a pointer to the initial element of a character array large enough to
13900 accept the sequence and a terminating null character, which will be added
13902 If an l length modifier is present, the corresponding argument shall be a
13903 pointer to the initial element of an array of wchar_t large enough to accept
13907 the sequence and the terminating null wide character, which will be added
13909 [ Matches a nonempty sequence of wide characters from a set of expected
13910 characters (the scanset).
13911 If no l length modifier is present, characters from the input field are
13912 converted as if by repeated calls to the wcrtomb function, with the
13913 conversion state described by an mbstate_t object initialized to zero
13914 before the first wide character is converted. The corresponding argument
13915 shall be a pointer to the initial element of a character array large enough to
13916 accept the sequence and a terminating null character, which will be added
13918 If an l length modifier is present, the corresponding argument shall be a
13919 pointer to the initial element of an array of wchar_t large enough to accept
13920 the sequence and the terminating null wide character, which will be added
13922 The conversion specifier includes all subsequent wide characters in the
13923 format string, up to and including the matching right bracket (]). The wide
13924 characters between the brackets (the scanlist) compose the scanset, unless the
13925 wide character after the left bracket is a circumflex (^), in which case the
13926 scanset contains all wide characters that do not appear in the scanlist between
13927 the circumflex and the right bracket. If the conversion specifier begins with
13928 [] or [^], the right bracket wide character is in the scanlist and the next
13929 following right bracket wide character is the matching right bracket that ends
13930 the specification; otherwise the first following right bracket wide character is
13931 the one that ends the specification. If a - wide character is in the scanlist and
13932 is not the first, nor the second where the first wide character is a ^, nor the
13933 last character, the behavior is implementation-defined.
13934 p Matches an implementation-defined set of sequences, which should be the
13935 same as the set of sequences that may be produced by the %p conversion of
13936 the fwprintf function. The corresponding argument shall be a pointer to a
13937 pointer to void. The input item is converted to a pointer value in an
13938 implementation-defined manner. If the input item is a value converted earlier
13939 during the same program execution, the pointer that results shall compare
13940 equal to that value; otherwise the behavior of the %p conversion is undefined.
13941 n No input is consumed. The corresponding argument shall be a pointer to
13942 signed integer into which is to be written the number of wide characters read
13943 from the input stream so far by this call to the fwscanf function. Execution
13944 of a %n directive does not increment the assignment count returned at the
13945 completion of execution of the fwscanf function. No argument is
13949 converted, but one is consumed. If the conversion specification includes an
13950 assignment-suppressing wide character or a field width, the behavior is
13952 % Matches a single % wide character; no conversion or assignment occurs. The
13953 complete conversion specification shall be %%.
13954 13 If a conversion specification is invalid, the behavior is undefined.290)
13955 14 The conversion specifiers A, E, F, G, and X are also valid and behave the same as,
13956 respectively, a, e, f, g, and x.
13957 15 Trailing white space (including new-line wide characters) is left unread unless matched
13958 by a directive. The success of literal matches and suppressed assignments is not directly
13959 determinable other than via the %n directive.
13961 16 The fwscanf function returns the value of the macro EOF if an input failure occurs
13962 before any conversion. Otherwise, the function returns the number of input items
13963 assigned, which can be fewer than provided for, or even zero, in the event of an early
13965 17 EXAMPLE 1 The call:
13969 int n, i; float x; wchar_t name[50];
13970 n = fwscanf(stdin, L"%d%f%ls", &i, &x, name);
13971 with the input line:
13972 25 54.32E-1 thompson
13973 will assign to n the value 3, to i the value 25, to x the value 5.432, and to name the sequence
13976 18 EXAMPLE 2 The call:
13980 int i; float x; double y;
13981 fwscanf(stdin, L"%2d%f%*d %lf", &i, &x, &y);
13984 will assign to i the value 56 and to x the value 789.0, will skip past 0123, and will assign to y the value
13985 56.0. The next wide character read from the input stream will be a.
13988 290) See ''future library directions'' (7.26.12).
13992 Forward references: the wcstod, wcstof, and wcstold functions (7.24.4.1.1), the
13993 wcstol, wcstoll, wcstoul, and wcstoull functions (7.24.4.1.2), the wcrtomb
13994 function (7.24.6.3.3).
13995 7.24.2.3 The swprintf function
13997 1 #include <wchar.h>
13998 int swprintf(wchar_t * restrict s,
14000 const wchar_t * restrict format, ...);
14002 2 The swprintf function is equivalent to fwprintf, except that the argument s
14003 specifies an array of wide characters into which the generated output is to be written,
14004 rather than written to a stream. No more than n wide characters are written, including a
14005 terminating null wide character, which is always added (unless n is zero).
14007 3 The swprintf function returns the number of wide characters written in the array, not
14008 counting the terminating null wide character, or a negative value if an encoding error
14009 occurred or if n or more wide characters were requested to be written.
14010 7.24.2.4 The swscanf function
14012 1 #include <wchar.h>
14013 int swscanf(const wchar_t * restrict s,
14014 const wchar_t * restrict format, ...);
14016 2 The swscanf function is equivalent to fwscanf, except that the argument s specifies a
14017 wide string from which the input is to be obtained, rather than from a stream. Reaching
14018 the end of the wide string is equivalent to encountering end-of-file for the fwscanf
14021 3 The swscanf function returns the value of the macro EOF if an input failure occurs
14022 before any conversion. Otherwise, the swscanf function returns the number of input
14023 items assigned, which can be fewer than provided for, or even zero, in the event of an
14024 early matching failure.
14028 7.24.2.5 The vfwprintf function
14030 1 #include <stdarg.h>
14033 int vfwprintf(FILE * restrict stream,
14034 const wchar_t * restrict format,
14037 2 The vfwprintf function is equivalent to fwprintf, with the variable argument list
14038 replaced by arg, which shall have been initialized by the va_start macro (and
14039 possibly subsequent va_arg calls). The vfwprintf function does not invoke the
14042 3 The vfwprintf function returns the number of wide characters transmitted, or a
14043 negative value if an output or encoding error occurred.
14044 4 EXAMPLE The following shows the use of the vfwprintf function in a general error-reporting
14046 #include <stdarg.h>
14049 void error(char *function_name, wchar_t *format, ...)
14052 va_start(args, format);
14053 // print out name of function causing error
14054 fwprintf(stderr, L"ERROR in %s: ", function_name);
14055 // print out remainder of message
14056 vfwprintf(stderr, format, args);
14063 291) As the functions vfwprintf, vswprintf, vfwscanf, vwprintf, vwscanf, and vswscanf
14064 invoke the va_arg macro, the value of arg after the return is indeterminate.
14068 7.24.2.6 The vfwscanf function
14070 1 #include <stdarg.h>
14073 int vfwscanf(FILE * restrict stream,
14074 const wchar_t * restrict format,
14077 2 The vfwscanf function is equivalent to fwscanf, with the variable argument list
14078 replaced by arg, which shall have been initialized by the va_start macro (and
14079 possibly subsequent va_arg calls). The vfwscanf function does not invoke the
14082 3 The vfwscanf function returns the value of the macro EOF if an input failure occurs
14083 before any conversion. Otherwise, the vfwscanf function returns the number of input
14084 items assigned, which can be fewer than provided for, or even zero, in the event of an
14085 early matching failure.
14086 7.24.2.7 The vswprintf function
14088 1 #include <stdarg.h>
14090 int vswprintf(wchar_t * restrict s,
14092 const wchar_t * restrict format,
14095 2 The vswprintf function is equivalent to swprintf, with the variable argument list
14096 replaced by arg, which shall have been initialized by the va_start macro (and
14097 possibly subsequent va_arg calls). The vswprintf function does not invoke the
14100 3 The vswprintf function returns the number of wide characters written in the array, not
14101 counting the terminating null wide character, or a negative value if an encoding error
14102 occurred or if n or more wide characters were requested to be generated.
14106 7.24.2.8 The vswscanf function
14108 1 #include <stdarg.h>
14110 int vswscanf(const wchar_t * restrict s,
14111 const wchar_t * restrict format,
14114 2 The vswscanf function is equivalent to swscanf, with the variable argument list
14115 replaced by arg, which shall have been initialized by the va_start macro (and
14116 possibly subsequent va_arg calls). The vswscanf function does not invoke the
14119 3 The vswscanf function returns the value of the macro EOF if an input failure occurs
14120 before any conversion. Otherwise, the vswscanf function returns the number of input
14121 items assigned, which can be fewer than provided for, or even zero, in the event of an
14122 early matching failure.
14123 7.24.2.9 The vwprintf function
14125 1 #include <stdarg.h>
14127 int vwprintf(const wchar_t * restrict format,
14130 2 The vwprintf function is equivalent to wprintf, with the variable argument list
14131 replaced by arg, which shall have been initialized by the va_start macro (and
14132 possibly subsequent va_arg calls). The vwprintf function does not invoke the
14135 3 The vwprintf function returns the number of wide characters transmitted, or a negative
14136 value if an output or encoding error occurred.
14140 7.24.2.10 The vwscanf function
14142 1 #include <stdarg.h>
14144 int vwscanf(const wchar_t * restrict format,
14147 2 The vwscanf function is equivalent to wscanf, with the variable argument list
14148 replaced by arg, which shall have been initialized by the va_start macro (and
14149 possibly subsequent va_arg calls). The vwscanf function does not invoke the
14152 3 The vwscanf function returns the value of the macro EOF if an input failure occurs
14153 before any conversion. Otherwise, the vwscanf function returns the number of input
14154 items assigned, which can be fewer than provided for, or even zero, in the event of an
14155 early matching failure.
14156 7.24.2.11 The wprintf function
14158 1 #include <wchar.h>
14159 int wprintf(const wchar_t * restrict format, ...);
14161 2 The wprintf function is equivalent to fwprintf with the argument stdout
14162 interposed before the arguments to wprintf.
14164 3 The wprintf function returns the number of wide characters transmitted, or a negative
14165 value if an output or encoding error occurred.
14166 7.24.2.12 The wscanf function
14168 1 #include <wchar.h>
14169 int wscanf(const wchar_t * restrict format, ...);
14171 2 The wscanf function is equivalent to fwscanf with the argument stdin interposed
14172 before the arguments to wscanf.
14177 3 The wscanf function returns the value of the macro EOF if an input failure occurs
14178 before any conversion. Otherwise, the wscanf function returns the number of input
14179 items assigned, which can be fewer than provided for, or even zero, in the event of an
14180 early matching failure.
14181 7.24.3 Wide character input/output functions
14182 7.24.3.1 The fgetwc function
14184 1 #include <stdio.h>
14186 wint_t fgetwc(FILE *stream);
14188 2 If the end-of-file indicator for the input stream pointed to by stream is not set and a
14189 next wide character is present, the fgetwc function obtains that wide character as a
14190 wchar_t converted to a wint_t and advances the associated file position indicator for
14191 the stream (if defined).
14193 3 If the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-
14194 of-file indicator for the stream is set and the fgetwc function returns WEOF. Otherwise,
14195 the fgetwc function returns the next wide character from the input stream pointed to by
14196 stream. If a read error occurs, the error indicator for the stream is set and the fgetwc
14197 function returns WEOF. If an encoding error occurs (including too few bytes), the value of
14198 the macro EILSEQ is stored in errno and the fgetwc function returns WEOF.292)
14199 7.24.3.2 The fgetws function
14201 1 #include <stdio.h>
14203 wchar_t *fgetws(wchar_t * restrict s,
14204 int n, FILE * restrict stream);
14206 2 The fgetws function reads at most one less than the number of wide characters
14207 specified by n from the stream pointed to by stream into the array pointed to by s. No
14210 292) An end-of-file and a read error can be distinguished by use of the feof and ferror functions.
14211 Also, errno will be set to EILSEQ by input/output functions only if an encoding error occurs.
14215 additional wide characters are read after a new-line wide character (which is retained) or
14216 after end-of-file. A null wide character is written immediately after the last wide
14217 character read into the array.
14219 3 The fgetws function returns s if successful. If end-of-file is encountered and no
14220 characters have been read into the array, the contents of the array remain unchanged and a
14221 null pointer is returned. If a read or encoding error occurs during the operation, the array
14222 contents are indeterminate and a null pointer is returned.
14223 7.24.3.3 The fputwc function
14225 1 #include <stdio.h>
14227 wint_t fputwc(wchar_t c, FILE *stream);
14229 2 The fputwc function writes the wide character specified by c to the output stream
14230 pointed to by stream, at the position indicated by the associated file position indicator
14231 for the stream (if defined), and advances the indicator appropriately. If the file cannot
14232 support positioning requests, or if the stream was opened with append mode, the
14233 character is appended to the output stream.
14235 3 The fputwc function returns the wide character written. If a write error occurs, the
14236 error indicator for the stream is set and fputwc returns WEOF. If an encoding error
14237 occurs, the value of the macro EILSEQ is stored in errno and fputwc returns WEOF.
14238 7.24.3.4 The fputws function
14240 1 #include <stdio.h>
14242 int fputws(const wchar_t * restrict s,
14243 FILE * restrict stream);
14245 2 The fputws function writes the wide string pointed to by s to the stream pointed to by
14246 stream. The terminating null wide character is not written.
14248 3 The fputws function returns EOF if a write or encoding error occurs; otherwise, it
14249 returns a nonnegative value.
14253 7.24.3.5 The fwide function
14255 1 #include <stdio.h>
14257 int fwide(FILE *stream, int mode);
14259 2 The fwide function determines the orientation of the stream pointed to by stream. If
14260 mode is greater than zero, the function first attempts to make the stream wide oriented. If
14261 mode is less than zero, the function first attempts to make the stream byte oriented.293)
14262 Otherwise, mode is zero and the function does not alter the orientation of the stream.
14264 3 The fwide function returns a value greater than zero if, after the call, the stream has
14265 wide orientation, a value less than zero if the stream has byte orientation, or zero if the
14266 stream has no orientation.
14267 7.24.3.6 The getwc function
14269 1 #include <stdio.h>
14271 wint_t getwc(FILE *stream);
14273 2 The getwc function is equivalent to fgetwc, except that if it is implemented as a
14274 macro, it may evaluate stream more than once, so the argument should never be an
14275 expression with side effects.
14277 3 The getwc function returns the next wide character from the input stream pointed to by
14279 7.24.3.7 The getwchar function
14281 1 #include <wchar.h>
14282 wint_t getwchar(void);
14287 293) If the orientation of the stream has already been determined, fwide does not change it.
14292 2 The getwchar function is equivalent to getwc with the argument stdin.
14294 3 The getwchar function returns the next wide character from the input stream pointed to
14296 7.24.3.8 The putwc function
14298 1 #include <stdio.h>
14300 wint_t putwc(wchar_t c, FILE *stream);
14302 2 The putwc function is equivalent to fputwc, except that if it is implemented as a
14303 macro, it may evaluate stream more than once, so that argument should never be an
14304 expression with side effects.
14306 3 The putwc function returns the wide character written, or WEOF.
14307 7.24.3.9 The putwchar function
14309 1 #include <wchar.h>
14310 wint_t putwchar(wchar_t c);
14312 2 The putwchar function is equivalent to putwc with the second argument stdout.
14314 3 The putwchar function returns the character written, or WEOF.
14315 7.24.3.10 The ungetwc function
14317 1 #include <stdio.h>
14319 wint_t ungetwc(wint_t c, FILE *stream);
14321 2 The ungetwc function pushes the wide character specified by c back onto the input
14322 stream pointed to by stream. Pushed-back wide characters will be returned by
14323 subsequent reads on that stream in the reverse order of their pushing. A successful
14327 intervening call (with the stream pointed to by stream) to a file positioning function
14328 (fseek, fsetpos, or rewind) discards any pushed-back wide characters for the
14329 stream. The external storage corresponding to the stream is unchanged.
14330 3 One wide character of pushback is guaranteed, even if the call to the ungetwc function
14331 follows just after a call to a formatted wide character input function fwscanf,
14332 vfwscanf, vwscanf, or wscanf. If the ungetwc function is called too many times
14333 on the same stream without an intervening read or file positioning operation on that
14334 stream, the operation may fail.
14335 4 If the value of c equals that of the macro WEOF, the operation fails and the input stream is
14337 5 A successful call to the ungetwc function clears the end-of-file indicator for the stream.
14338 The value of the file position indicator for the stream after reading or discarding all
14339 pushed-back wide characters is the same as it was before the wide characters were pushed
14340 back. For a text or binary stream, the value of its file position indicator after a successful
14341 call to the ungetwc function is unspecified until all pushed-back wide characters are
14344 6 The ungetwc function returns the wide character pushed back, or WEOF if the operation
14346 7.24.4 General wide string utilities
14347 1 The header <wchar.h> declares a number of functions useful for wide string
14348 manipulation. Various methods are used for determining the lengths of the arrays, but in
14349 all cases a wchar_t * argument points to the initial (lowest addressed) element of the
14350 array. If an array is accessed beyond the end of an object, the behavior is undefined.
14351 2 Where an argument declared as size_t n determines the length of the array for a
14352 function, n can have the value zero on a call to that function. Unless explicitly stated
14353 otherwise in the description of a particular function in this subclause, pointer arguments
14354 on such a call shall still have valid values, as described in 7.1.4. On such a call, a
14355 function that locates a wide character finds no occurrence, a function that compares two
14356 wide character sequences returns zero, and a function that copies wide characters copies
14357 zero wide characters.
14361 7.24.4.1 Wide string numeric conversion functions
14362 7.24.4.1.1 The wcstod, wcstof, and wcstold functions
14364 1 #include <wchar.h>
14365 double wcstod(const wchar_t * restrict nptr,
14366 wchar_t ** restrict endptr);
14367 float wcstof(const wchar_t * restrict nptr,
14368 wchar_t ** restrict endptr);
14369 long double wcstold(const wchar_t * restrict nptr,
14370 wchar_t ** restrict endptr);
14372 2 The wcstod, wcstof, and wcstold functions convert the initial portion of the wide
14373 string pointed to by nptr to double, float, and long double representation,
14374 respectively. First, they decompose the input string into three parts: an initial, possibly
14375 empty, sequence of white-space wide characters (as specified by the iswspace
14376 function), a subject sequence resembling a floating-point constant or representing an
14377 infinity or NaN; and a final wide string of one or more unrecognized wide characters,
14378 including the terminating null wide character of the input wide string. Then, they attempt
14379 to convert the subject sequence to a floating-point number, and return the result.
14380 3 The expected form of the subject sequence is an optional plus or minus sign, then one of
14382 -- a nonempty sequence of decimal digits optionally containing a decimal-point wide
14383 character, then an optional exponent part as defined for the corresponding single-byte
14384 characters in 6.4.4.2;
14385 -- a 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing a
14386 decimal-point wide character, then an optional binary exponent part as defined in
14388 -- INF or INFINITY, or any other wide string equivalent except for case
14389 -- NAN or NAN(n-wchar-sequenceopt), or any other wide string equivalent except for
14390 case in the NAN part, where:
14394 n-wchar-sequence digit
14395 n-wchar-sequence nondigit
14396 The subject sequence is defined as the longest initial subsequence of the input wide
14397 string, starting with the first non-white-space wide character, that is of the expected form.
14401 The subject sequence contains no wide characters if the input wide string is not of the
14403 4 If the subject sequence has the expected form for a floating-point number, the sequence of
14404 wide characters starting with the first digit or the decimal-point wide character
14405 (whichever occurs first) is interpreted as a floating constant according to the rules of
14406 6.4.4.2, except that the decimal-point wide character is used in place of a period, and that
14407 if neither an exponent part nor a decimal-point wide character appears in a decimal
14408 floating point number, or if a binary exponent part does not appear in a hexadecimal
14409 floating point number, an exponent part of the appropriate type with value zero is
14410 assumed to follow the last digit in the string. If the subject sequence begins with a minus
14411 sign, the sequence is interpreted as negated.294) A wide character sequence INF or
14412 INFINITY is interpreted as an infinity, if representable in the return type, else like a
14413 floating constant that is too large for the range of the return type. A wide character
14414 sequence NAN or NAN(n-wchar-sequenceopt) is interpreted as a quiet NaN, if supported
14415 in the return type, else like a subject sequence part that does not have the expected form;
14416 the meaning of the n-wchar sequences is implementation-defined.295) A pointer to the
14417 final wide string is stored in the object pointed to by endptr, provided that endptr is
14418 not a null pointer.
14419 5 If the subject sequence has the hexadecimal form and FLT_RADIX is a power of 2, the
14420 value resulting from the conversion is correctly rounded.
14421 6 In other than the "C" locale, additional locale-specific subject sequence forms may be
14423 7 If the subject sequence is empty or does not have the expected form, no conversion is
14424 performed; the value of nptr is stored in the object pointed to by endptr, provided
14425 that endptr is not a null pointer.
14426 Recommended practice
14427 8 If the subject sequence has the hexadecimal form, FLT_RADIX is not a power of 2, and
14428 the result is not exactly representable, the result should be one of the two numbers in the
14429 appropriate internal format that are adjacent to the hexadecimal floating source value,
14430 with the extra stipulation that the error should have a correct sign for the current rounding
14435 294) It is unspecified whether a minus-signed sequence is converted to a negative number directly or by
14436 negating the value resulting from converting the corresponding unsigned sequence (see F.5); the two
14437 methods may yield different results if rounding is toward positive or negative infinity. In either case,
14438 the functions honor the sign of zero if floating-point arithmetic supports signed zeros.
14439 295) An implementation may use the n-wchar sequence to determine extra information to be represented in
14440 the NaN's significand.
14444 9 If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in
14445 <float.h>) significant digits, the result should be correctly rounded. If the subject
14446 sequence D has the decimal form and more than DECIMAL_DIG significant digits,
14447 consider the two bounding, adjacent decimal strings L and U, both having
14448 DECIMAL_DIG significant digits, such that the values of L, D, and U satisfy L <= D <= U.
14449 The result should be one of the (equal or adjacent) values that would be obtained by
14450 correctly rounding L and U according to the current rounding direction, with the extra
14451 stipulation that the error with respect to D should have a correct sign for the current
14452 rounding direction.296)
14454 10 The functions return the converted value, if any. If no conversion could be performed,
14455 zero is returned. If the correct value is outside the range of representable values, plus or
14456 minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the return
14457 type and sign of the value), and the value of the macro ERANGE is stored in errno. If
14458 the result underflows (7.12.1), the functions return a value whose magnitude is no greater
14459 than the smallest normalized positive number in the return type; whether errno acquires
14460 the value ERANGE is implementation-defined.
14465 296) DECIMAL_DIG, defined in <float.h>, should be sufficiently large that L and U will usually round
14466 to the same internal floating value, but if not will round to adjacent values.
14470 7.24.4.1.2 The wcstol, wcstoll, wcstoul, and wcstoull functions
14472 1 #include <wchar.h>
14474 const wchar_t * restrict nptr,
14475 wchar_t ** restrict endptr,
14477 long long int wcstoll(
14478 const wchar_t * restrict nptr,
14479 wchar_t ** restrict endptr,
14481 unsigned long int wcstoul(
14482 const wchar_t * restrict nptr,
14483 wchar_t ** restrict endptr,
14485 unsigned long long int wcstoull(
14486 const wchar_t * restrict nptr,
14487 wchar_t ** restrict endptr,
14490 2 The wcstol, wcstoll, wcstoul, and wcstoull functions convert the initial
14491 portion of the wide string pointed to by nptr to long int, long long int,
14492 unsigned long int, and unsigned long long int representation,
14493 respectively. First, they decompose the input string into three parts: an initial, possibly
14494 empty, sequence of white-space wide characters (as specified by the iswspace
14495 function), a subject sequence resembling an integer represented in some radix determined
14496 by the value of base, and a final wide string of one or more unrecognized wide
14497 characters, including the terminating null wide character of the input wide string. Then,
14498 they attempt to convert the subject sequence to an integer, and return the result.
14499 3 If the value of base is zero, the expected form of the subject sequence is that of an
14500 integer constant as described for the corresponding single-byte characters in 6.4.4.1,
14501 optionally preceded by a plus or minus sign, but not including an integer suffix. If the
14502 value of base is between 2 and 36 (inclusive), the expected form of the subject sequence
14503 is a sequence of letters and digits representing an integer with the radix specified by
14504 base, optionally preceded by a plus or minus sign, but not including an integer suffix.
14505 The letters from a (or A) through z (or Z) are ascribed the values 10 through 35; only
14506 letters and digits whose ascribed values are less than that of base are permitted. If the
14507 value of base is 16, the wide characters 0x or 0X may optionally precede the sequence
14508 of letters and digits, following the sign if present.
14512 4 The subject sequence is defined as the longest initial subsequence of the input wide
14513 string, starting with the first non-white-space wide character, that is of the expected form.
14514 The subject sequence contains no wide characters if the input wide string is empty or
14515 consists entirely of white space, or if the first non-white-space wide character is other
14516 than a sign or a permissible letter or digit.
14517 5 If the subject sequence has the expected form and the value of base is zero, the sequence
14518 of wide characters starting with the first digit is interpreted as an integer constant
14519 according to the rules of 6.4.4.1. If the subject sequence has the expected form and the
14520 value of base is between 2 and 36, it is used as the base for conversion, ascribing to each
14521 letter its value as given above. If the subject sequence begins with a minus sign, the value
14522 resulting from the conversion is negated (in the return type). A pointer to the final wide
14523 string is stored in the object pointed to by endptr, provided that endptr is not a null
14525 6 In other than the "C" locale, additional locale-specific subject sequence forms may be
14527 7 If the subject sequence is empty or does not have the expected form, no conversion is
14528 performed; the value of nptr is stored in the object pointed to by endptr, provided
14529 that endptr is not a null pointer.
14531 8 The wcstol, wcstoll, wcstoul, and wcstoull functions return the converted
14532 value, if any. If no conversion could be performed, zero is returned. If the correct value
14533 is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
14534 LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type
14535 sign of the value, if any), and the value of the macro ERANGE is stored in errno.
14536 7.24.4.2 Wide string copying functions
14537 7.24.4.2.1 The wcscpy function
14539 1 #include <wchar.h>
14540 wchar_t *wcscpy(wchar_t * restrict s1,
14541 const wchar_t * restrict s2);
14543 2 The wcscpy function copies the wide string pointed to by s2 (including the terminating
14544 null wide character) into the array pointed to by s1.
14546 3 The wcscpy function returns the value of s1.
14550 7.24.4.2.2 The wcsncpy function
14552 1 #include <wchar.h>
14553 wchar_t *wcsncpy(wchar_t * restrict s1,
14554 const wchar_t * restrict s2,
14557 2 The wcsncpy function copies not more than n wide characters (those that follow a null
14558 wide character are not copied) from the array pointed to by s2 to the array pointed to by
14560 3 If the array pointed to by s2 is a wide string that is shorter than n wide characters, null
14561 wide characters are appended to the copy in the array pointed to by s1, until n wide
14562 characters in all have been written.
14564 4 The wcsncpy function returns the value of s1.
14565 7.24.4.2.3 The wmemcpy function
14567 1 #include <wchar.h>
14568 wchar_t *wmemcpy(wchar_t * restrict s1,
14569 const wchar_t * restrict s2,
14572 2 The wmemcpy function copies n wide characters from the object pointed to by s2 to the
14573 object pointed to by s1.
14575 3 The wmemcpy function returns the value of s1.
14580 297) Thus, if there is no null wide character in the first n wide characters of the array pointed to by s2, the
14581 result will not be null-terminated.
14585 7.24.4.2.4 The wmemmove function
14587 1 #include <wchar.h>
14588 wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2,
14591 2 The wmemmove function copies n wide characters from the object pointed to by s2 to
14592 the object pointed to by s1. Copying takes place as if the n wide characters from the
14593 object pointed to by s2 are first copied into a temporary array of n wide characters that
14594 does not overlap the objects pointed to by s1 or s2, and then the n wide characters from
14595 the temporary array are copied into the object pointed to by s1.
14597 3 The wmemmove function returns the value of s1.
14598 7.24.4.3 Wide string concatenation functions
14599 7.24.4.3.1 The wcscat function
14601 1 #include <wchar.h>
14602 wchar_t *wcscat(wchar_t * restrict s1,
14603 const wchar_t * restrict s2);
14605 2 The wcscat function appends a copy of the wide string pointed to by s2 (including the
14606 terminating null wide character) to the end of the wide string pointed to by s1. The initial
14607 wide character of s2 overwrites the null wide character at the end of s1.
14609 3 The wcscat function returns the value of s1.
14610 7.24.4.3.2 The wcsncat function
14612 1 #include <wchar.h>
14613 wchar_t *wcsncat(wchar_t * restrict s1,
14614 const wchar_t * restrict s2,
14617 2 The wcsncat function appends not more than n wide characters (a null wide character
14618 and those that follow it are not appended) from the array pointed to by s2 to the end of
14622 the wide string pointed to by s1. The initial wide character of s2 overwrites the null
14623 wide character at the end of s1. A terminating null wide character is always appended to
14626 3 The wcsncat function returns the value of s1.
14627 7.24.4.4 Wide string comparison functions
14628 1 Unless explicitly stated otherwise, the functions described in this subclause order two
14629 wide characters the same way as two integers of the underlying integer type designated
14631 7.24.4.4.1 The wcscmp function
14633 1 #include <wchar.h>
14634 int wcscmp(const wchar_t *s1, const wchar_t *s2);
14636 2 The wcscmp function compares the wide string pointed to by s1 to the wide string
14639 3 The wcscmp function returns an integer greater than, equal to, or less than zero,
14640 accordingly as the wide string pointed to by s1 is greater than, equal to, or less than the
14641 wide string pointed to by s2.
14642 7.24.4.4.2 The wcscoll function
14644 1 #include <wchar.h>
14645 int wcscoll(const wchar_t *s1, const wchar_t *s2);
14647 2 The wcscoll function compares the wide string pointed to by s1 to the wide string
14648 pointed to by s2, both interpreted as appropriate to the LC_COLLATE category of the
14651 3 The wcscoll function returns an integer greater than, equal to, or less than zero,
14652 accordingly as the wide string pointed to by s1 is greater than, equal to, or less than the
14655 298) Thus, the maximum number of wide characters that can end up in the array pointed to by s1 is
14660 wide string pointed to by s2 when both are interpreted as appropriate to the current
14662 7.24.4.4.3 The wcsncmp function
14664 1 #include <wchar.h>
14665 int wcsncmp(const wchar_t *s1, const wchar_t *s2,
14668 2 The wcsncmp function compares not more than n wide characters (those that follow a
14669 null wide character are not compared) from the array pointed to by s1 to the array
14672 3 The wcsncmp function returns an integer greater than, equal to, or less than zero,
14673 accordingly as the possibly null-terminated array pointed to by s1 is greater than, equal
14674 to, or less than the possibly null-terminated array pointed to by s2.
14675 7.24.4.4.4 The wcsxfrm function
14677 1 #include <wchar.h>
14678 size_t wcsxfrm(wchar_t * restrict s1,
14679 const wchar_t * restrict s2,
14682 2 The wcsxfrm function transforms the wide string pointed to by s2 and places the
14683 resulting wide string into the array pointed to by s1. The transformation is such that if
14684 the wcscmp function is applied to two transformed wide strings, it returns a value greater
14685 than, equal to, or less than zero, corresponding to the result of the wcscoll function
14686 applied to the same two original wide strings. No more than n wide characters are placed
14687 into the resulting array pointed to by s1, including the terminating null wide character. If
14688 n is zero, s1 is permitted to be a null pointer.
14690 3 The wcsxfrm function returns the length of the transformed wide string (not including
14691 the terminating null wide character). If the value returned is n or greater, the contents of
14692 the array pointed to by s1 are indeterminate.
14693 4 EXAMPLE The value of the following expression is the length of the array needed to hold the
14694 transformation of the wide string pointed to by s:
14698 1 + wcsxfrm(NULL, s, 0)
14700 7.24.4.4.5 The wmemcmp function
14702 1 #include <wchar.h>
14703 int wmemcmp(const wchar_t *s1, const wchar_t *s2,
14706 2 The wmemcmp function compares the first n wide characters of the object pointed to by
14707 s1 to the first n wide characters of the object pointed to by s2.
14709 3 The wmemcmp function returns an integer greater than, equal to, or less than zero,
14710 accordingly as the object pointed to by s1 is greater than, equal to, or less than the object
14712 7.24.4.5 Wide string search functions
14713 7.24.4.5.1 The wcschr function
14715 1 #include <wchar.h>
14716 wchar_t *wcschr(const wchar_t *s, wchar_t c);
14718 2 The wcschr function locates the first occurrence of c in the wide string pointed to by s.
14719 The terminating null wide character is considered to be part of the wide string.
14721 3 The wcschr function returns a pointer to the located wide character, or a null pointer if
14722 the wide character does not occur in the wide string.
14723 7.24.4.5.2 The wcscspn function
14725 1 #include <wchar.h>
14726 size_t wcscspn(const wchar_t *s1, const wchar_t *s2);
14728 2 The wcscspn function computes the length of the maximum initial segment of the wide
14729 string pointed to by s1 which consists entirely of wide characters not from the wide
14730 string pointed to by s2.
14735 3 The wcscspn function returns the length of the segment.
14736 7.24.4.5.3 The wcspbrk function
14738 1 #include <wchar.h>
14739 wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2);
14741 2 The wcspbrk function locates the first occurrence in the wide string pointed to by s1 of
14742 any wide character from the wide string pointed to by s2.
14744 3 The wcspbrk function returns a pointer to the wide character in s1, or a null pointer if
14745 no wide character from s2 occurs in s1.
14746 7.24.4.5.4 The wcsrchr function
14748 1 #include <wchar.h>
14749 wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
14751 2 The wcsrchr function locates the last occurrence of c in the wide string pointed to by
14752 s. The terminating null wide character is considered to be part of the wide string.
14754 3 The wcsrchr function returns a pointer to the wide character, or a null pointer if c does
14755 not occur in the wide string.
14756 7.24.4.5.5 The wcsspn function
14758 1 #include <wchar.h>
14759 size_t wcsspn(const wchar_t *s1, const wchar_t *s2);
14761 2 The wcsspn function computes the length of the maximum initial segment of the wide
14762 string pointed to by s1 which consists entirely of wide characters from the wide string
14765 3 The wcsspn function returns the length of the segment.
14769 7.24.4.5.6 The wcsstr function
14771 1 #include <wchar.h>
14772 wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);
14774 2 The wcsstr function locates the first occurrence in the wide string pointed to by s1 of
14775 the sequence of wide characters (excluding the terminating null wide character) in the
14776 wide string pointed to by s2.
14778 3 The wcsstr function returns a pointer to the located wide string, or a null pointer if the
14779 wide string is not found. If s2 points to a wide string with zero length, the function
14781 7.24.4.5.7 The wcstok function
14783 1 #include <wchar.h>
14784 wchar_t *wcstok(wchar_t * restrict s1,
14785 const wchar_t * restrict s2,
14786 wchar_t ** restrict ptr);
14788 2 A sequence of calls to the wcstok function breaks the wide string pointed to by s1 into
14789 a sequence of tokens, each of which is delimited by a wide character from the wide string
14790 pointed to by s2. The third argument points to a caller-provided wchar_t pointer into
14791 which the wcstok function stores information necessary for it to continue scanning the
14793 3 The first call in a sequence has a non-null first argument and stores an initial value in the
14794 object pointed to by ptr. Subsequent calls in the sequence have a null first argument and
14795 the object pointed to by ptr is required to have the value stored by the previous call in
14796 the sequence, which is then updated. The separator wide string pointed to by s2 may be
14797 different from call to call.
14798 4 The first call in the sequence searches the wide string pointed to by s1 for the first wide
14799 character that is not contained in the current separator wide string pointed to by s2. If no
14800 such wide character is found, then there are no tokens in the wide string pointed to by s1
14801 and the wcstok function returns a null pointer. If such a wide character is found, it is
14802 the start of the first token.
14803 5 The wcstok function then searches from there for a wide character that is contained in
14804 the current separator wide string. If no such wide character is found, the current token
14808 extends to the end of the wide string pointed to by s1, and subsequent searches in the
14809 same wide string for a token return a null pointer. If such a wide character is found, it is
14810 overwritten by a null wide character, which terminates the current token.
14811 6 In all cases, the wcstok function stores sufficient information in the pointer pointed to
14812 by ptr so that subsequent calls, with a null pointer for s1 and the unmodified pointer
14813 value for ptr, shall start searching just past the element overwritten by a null wide
14814 character (if any).
14816 7 The wcstok function returns a pointer to the first wide character of a token, or a null
14817 pointer if there is no token.
14820 static wchar_t str1[] = L"?a???b,,,#c";
14821 static wchar_t str2[] = L"\t \t";
14822 wchar_t *t, *ptr1, *ptr2;
14823 t = wcstok(str1, L"?", &ptr1); // t points to the token L"a"
14824 t = wcstok(NULL, L",", &ptr1); // t points to the token L"??b"
14825 t = wcstok(str2, L" \t", &ptr2); // t is a null pointer
14826 t = wcstok(NULL, L"#,", &ptr1); // t points to the token L"c"
14827 t = wcstok(NULL, L"?", &ptr1); // t is a null pointer
14829 7.24.4.5.8 The wmemchr function
14831 1 #include <wchar.h>
14832 wchar_t *wmemchr(const wchar_t *s, wchar_t c,
14835 2 The wmemchr function locates the first occurrence of c in the initial n wide characters of
14836 the object pointed to by s.
14838 3 The wmemchr function returns a pointer to the located wide character, or a null pointer if
14839 the wide character does not occur in the object.
14843 7.24.4.6 Miscellaneous functions
14844 7.24.4.6.1 The wcslen function
14846 1 #include <wchar.h>
14847 size_t wcslen(const wchar_t *s);
14849 2 The wcslen function computes the length of the wide string pointed to by s.
14851 3 The wcslen function returns the number of wide characters that precede the terminating
14852 null wide character.
14853 7.24.4.6.2 The wmemset function
14855 1 #include <wchar.h>
14856 wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);
14858 2 The wmemset function copies the value of c into each of the first n wide characters of
14859 the object pointed to by s.
14861 3 The wmemset function returns the value of s.
14862 7.24.5 Wide character time conversion functions
14863 7.24.5.1 The wcsftime function
14865 1 #include <time.h>
14867 size_t wcsftime(wchar_t * restrict s,
14869 const wchar_t * restrict format,
14870 const struct tm * restrict timeptr);
14872 2 The wcsftime function is equivalent to the strftime function, except that:
14873 -- The argument s points to the initial element of an array of wide characters into which
14874 the generated output is to be placed.
14878 -- The argument maxsize indicates the limiting number of wide characters.
14879 -- The argument format is a wide string and the conversion specifiers are replaced by
14880 corresponding sequences of wide characters.
14881 -- The return value indicates the number of wide characters.
14883 3 If the total number of resulting wide characters including the terminating null wide
14884 character is not more than maxsize, the wcsftime function returns the number of
14885 wide characters placed into the array pointed to by s not including the terminating null
14886 wide character. Otherwise, zero is returned and the contents of the array are
14888 7.24.6 Extended multibyte/wide character conversion utilities
14889 1 The header <wchar.h> declares an extended set of functions useful for conversion
14890 between multibyte characters and wide characters.
14891 2 Most of the following functions -- those that are listed as ''restartable'', 7.24.6.3 and
14892 7.24.6.4 -- take as a last argument a pointer to an object of type mbstate_t that is used
14893 to describe the current conversion state from a particular multibyte character sequence to
14894 a wide character sequence (or the reverse) under the rules of a particular setting for the
14895 LC_CTYPE category of the current locale.
14896 3 The initial conversion state corresponds, for a conversion in either direction, to the
14897 beginning of a new multibyte character in the initial shift state. A zero-valued
14898 mbstate_t object is (at least) one way to describe an initial conversion state. A zero-
14899 valued mbstate_t object can be used to initiate conversion involving any multibyte
14900 character sequence, in any LC_CTYPE category setting. If an mbstate_t object has
14901 been altered by any of the functions described in this subclause, and is then used with a
14902 different multibyte character sequence, or in the other conversion direction, or with a
14903 different LC_CTYPE category setting than on earlier function calls, the behavior is
14905 4 On entry, each function takes the described conversion state (either internal or pointed to
14906 by an argument) as current. The conversion state described by the pointed-to object is
14907 altered as needed to track the shift state, and the position within a multibyte character, for
14908 the associated multibyte character sequence.
14913 299) Thus, a particular mbstate_t object can be used, for example, with both the mbrtowc and
14914 mbsrtowcs functions as long as they are used to step sequentially through the same multibyte
14919 7.24.6.1 Single-byte/wide character conversion functions
14920 7.24.6.1.1 The btowc function
14922 1 #include <stdio.h>
14924 wint_t btowc(int c);
14926 2 The btowc function determines whether c constitutes a valid single-byte character in the
14927 initial shift state.
14929 3 The btowc function returns WEOF if c has the value EOF or if (unsigned char)c
14930 does not constitute a valid single-byte character in the initial shift state. Otherwise, it
14931 returns the wide character representation of that character.
14932 7.24.6.1.2 The wctob function
14934 1 #include <stdio.h>
14936 int wctob(wint_t c);
14938 2 The wctob function determines whether c corresponds to a member of the extended
14939 character set whose multibyte character representation is a single byte when in the initial
14942 3 The wctob function returns EOF if c does not correspond to a multibyte character with
14943 length one in the initial shift state. Otherwise, it returns the single-byte representation of
14944 that character as an unsigned char converted to an int.
14945 7.24.6.2 Conversion state functions
14946 7.24.6.2.1 The mbsinit function
14948 1 #include <wchar.h>
14949 int mbsinit(const mbstate_t *ps);
14951 2 If ps is not a null pointer, the mbsinit function determines whether the pointed-to
14952 mbstate_t object describes an initial conversion state.
14957 3 The mbsinit function returns nonzero if ps is a null pointer or if the pointed-to object
14958 describes an initial conversion state; otherwise, it returns zero.
14959 7.24.6.3 Restartable multibyte/wide character conversion functions
14960 1 These functions differ from the corresponding multibyte character functions of 7.20.7
14961 (mblen, mbtowc, and wctomb) in that they have an extra parameter, ps, of type
14962 pointer to mbstate_t that points to an object that can completely describe the current
14963 conversion state of the associated multibyte character sequence. If ps is a null pointer,
14964 each function uses its own internal mbstate_t object instead, which is initialized at
14965 program startup to the initial conversion state. The implementation behaves as if no
14966 library function calls these functions with a null pointer for ps.
14967 2 Also unlike their corresponding functions, the return value does not represent whether the
14968 encoding is state-dependent.
14969 7.24.6.3.1 The mbrlen function
14971 1 #include <wchar.h>
14972 size_t mbrlen(const char * restrict s,
14974 mbstate_t * restrict ps);
14976 2 The mbrlen function is equivalent to the call:
14977 mbrtowc(NULL, s, n, ps != NULL ? ps : &internal)
14978 where internal is the mbstate_t object for the mbrlen function, except that the
14979 expression designated by ps is evaluated only once.
14981 3 The mbrlen function returns a value between zero and n, inclusive, (size_t)(-2),
14983 Forward references: the mbrtowc function (7.24.6.3.2).
14987 7.24.6.3.2 The mbrtowc function
14989 1 #include <wchar.h>
14990 size_t mbrtowc(wchar_t * restrict pwc,
14991 const char * restrict s,
14993 mbstate_t * restrict ps);
14995 2 If s is a null pointer, the mbrtowc function is equivalent to the call:
14996 mbrtowc(NULL, "", 1, ps)
14997 In this case, the values of the parameters pwc and n are ignored.
14998 3 If s is not a null pointer, the mbrtowc function inspects at most n bytes beginning with
14999 the byte pointed to by s to determine the number of bytes needed to complete the next
15000 multibyte character (including any shift sequences). If the function determines that the
15001 next multibyte character is complete and valid, it determines the value of the
15002 corresponding wide character and then, if pwc is not a null pointer, stores that value in
15003 the object pointed to by pwc. If the corresponding wide character is the null wide
15004 character, the resulting state described is the initial conversion state.
15006 4 The mbrtowc function returns the first of the following that applies (given the current
15008 0 if the next n or fewer bytes complete the multibyte character that
15009 corresponds to the null wide character (which is the value stored).
15010 between 1 and n inclusive if the next n or fewer bytes complete a valid multibyte
15011 character (which is the value stored); the value returned is the number
15012 of bytes that complete the multibyte character.
15013 (size_t)(-2) if the next n bytes contribute to an incomplete (but potentially valid)
15014 multibyte character, and all n bytes have been processed (no value is
15016 (size_t)(-1) if an encoding error occurs, in which case the next n or fewer bytes
15017 do not contribute to a complete and valid multibyte character (no
15018 value is stored); the value of the macro EILSEQ is stored in errno,
15019 and the conversion state is unspecified.
15021 300) When n has at least the value of the MB_CUR_MAX macro, this case can only occur if s points at a
15022 sequence of redundant shift sequences (for implementations with state-dependent encodings).
15026 7.24.6.3.3 The wcrtomb function
15028 1 #include <wchar.h>
15029 size_t wcrtomb(char * restrict s,
15031 mbstate_t * restrict ps);
15033 2 If s is a null pointer, the wcrtomb function is equivalent to the call
15034 wcrtomb(buf, L'\0', ps)
15035 where buf is an internal buffer.
15036 3 If s is not a null pointer, the wcrtomb function determines the number of bytes needed
15037 to represent the multibyte character that corresponds to the wide character given by wc
15038 (including any shift sequences), and stores the multibyte character representation in the
15039 array whose first element is pointed to by s. At most MB_CUR_MAX bytes are stored. If
15040 wc is a null wide character, a null byte is stored, preceded by any shift sequence needed
15041 to restore the initial shift state; the resulting state described is the initial conversion state.
15043 4 The wcrtomb function returns the number of bytes stored in the array object (including
15044 any shift sequences). When wc is not a valid wide character, an encoding error occurs:
15045 the function stores the value of the macro EILSEQ in errno and returns
15046 (size_t)(-1); the conversion state is unspecified.
15047 7.24.6.4 Restartable multibyte/wide string conversion functions
15048 1 These functions differ from the corresponding multibyte string functions of 7.20.8
15049 (mbstowcs and wcstombs) in that they have an extra parameter, ps, of type pointer to
15050 mbstate_t that points to an object that can completely describe the current conversion
15051 state of the associated multibyte character sequence. If ps is a null pointer, each function
15052 uses its own internal mbstate_t object instead, which is initialized at program startup
15053 to the initial conversion state. The implementation behaves as if no library function calls
15054 these functions with a null pointer for ps.
15055 2 Also unlike their corresponding functions, the conversion source parameter, src, has a
15056 pointer-to-pointer type. When the function is storing the results of conversions (that is,
15057 when dst is not a null pointer), the pointer object pointed to by this parameter is updated
15058 to reflect the amount of the source processed by that invocation.
15062 7.24.6.4.1 The mbsrtowcs function
15064 1 #include <wchar.h>
15065 size_t mbsrtowcs(wchar_t * restrict dst,
15066 const char ** restrict src,
15068 mbstate_t * restrict ps);
15070 2 The mbsrtowcs function converts a sequence of multibyte characters that begins in the
15071 conversion state described by the object pointed to by ps, from the array indirectly
15072 pointed to by src into a sequence of corresponding wide characters. If dst is not a null
15073 pointer, the converted characters are stored into the array pointed to by dst. Conversion
15074 continues up to and including a terminating null character, which is also stored.
15075 Conversion stops earlier in two cases: when a sequence of bytes is encountered that does
15076 not form a valid multibyte character, or (if dst is not a null pointer) when len wide
15077 characters have been stored into the array pointed to by dst.301) Each conversion takes
15078 place as if by a call to the mbrtowc function.
15079 3 If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
15080 pointer (if conversion stopped due to reaching a terminating null character) or the address
15081 just past the last multibyte character converted (if any). If conversion stopped due to
15082 reaching a terminating null character and if dst is not a null pointer, the resulting state
15083 described is the initial conversion state.
15085 4 If the input conversion encounters a sequence of bytes that do not form a valid multibyte
15086 character, an encoding error occurs: the mbsrtowcs function stores the value of the
15087 macro EILSEQ in errno and returns (size_t)(-1); the conversion state is
15088 unspecified. Otherwise, it returns the number of multibyte characters successfully
15089 converted, not including the terminating null character (if any).
15094 301) Thus, the value of len is ignored if dst is a null pointer.
15098 7.24.6.4.2 The wcsrtombs function
15100 1 #include <wchar.h>
15101 size_t wcsrtombs(char * restrict dst,
15102 const wchar_t ** restrict src,
15104 mbstate_t * restrict ps);
15106 2 The wcsrtombs function converts a sequence of wide characters from the array
15107 indirectly pointed to by src into a sequence of corresponding multibyte characters that
15108 begins in the conversion state described by the object pointed to by ps. If dst is not a
15109 null pointer, the converted characters are then stored into the array pointed to by dst.
15110 Conversion continues up to and including a terminating null wide character, which is also
15111 stored. Conversion stops earlier in two cases: when a wide character is reached that does
15112 not correspond to a valid multibyte character, or (if dst is not a null pointer) when the
15113 next multibyte character would exceed the limit of len total bytes to be stored into the
15114 array pointed to by dst. Each conversion takes place as if by a call to the wcrtomb
15116 3 If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
15117 pointer (if conversion stopped due to reaching a terminating null wide character) or the
15118 address just past the last wide character converted (if any). If conversion stopped due to
15119 reaching a terminating null wide character, the resulting state described is the initial
15122 4 If conversion stops because a wide character is reached that does not correspond to a
15123 valid multibyte character, an encoding error occurs: the wcsrtombs function stores the
15124 value of the macro EILSEQ in errno and returns (size_t)(-1); the conversion
15125 state is unspecified. Otherwise, it returns the number of bytes in the resulting multibyte
15126 character sequence, not including the terminating null character (if any).
15131 302) If conversion stops because a terminating null wide character has been reached, the bytes stored
15132 include those necessary to reach the initial shift state immediately before the null byte.
15136 7.25 Wide character classification and mapping utilities <wctype.h>
15137 7.25.1 Introduction
15138 1 The header <wctype.h> declares three data types, one macro, and many functions.303)
15139 2 The types declared are
15141 described in 7.24.1;
15143 which is a scalar type that can hold values which represent locale-specific character
15146 which is a scalar type that can hold values which represent locale-specific character
15148 3 The macro defined is WEOF (described in 7.24.1).
15149 4 The functions declared are grouped as follows:
15150 -- Functions that provide wide character classification;
15151 -- Extensible functions that provide wide character classification;
15152 -- Functions that provide wide character case mapping;
15153 -- Extensible functions that provide wide character mapping.
15154 5 For all functions described in this subclause that accept an argument of type wint_t, the
15155 value shall be representable as a wchar_t or shall equal the value of the macro WEOF. If
15156 this argument has any other value, the behavior is undefined.
15157 6 The behavior of these functions is affected by the LC_CTYPE category of the current
15163 303) See ''future library directions'' (7.26.13).
15167 7.25.2 Wide character classification utilities
15168 1 The header <wctype.h> declares several functions useful for classifying wide
15170 2 The term printing wide character refers to a member of a locale-specific set of wide
15171 characters, each of which occupies at least one printing position on a display device. The
15172 term control wide character refers to a member of a locale-specific set of wide characters
15173 that are not printing wide characters.
15174 7.25.2.1 Wide character classification functions
15175 1 The functions in this subclause return nonzero (true) if and only if the value of the
15176 argument wc conforms to that in the description of the function.
15177 2 Each of the following functions returns true for each wide character that corresponds (as
15178 if by a call to the wctob function) to a single-byte character for which the corresponding
15179 character classification function from 7.4.1 returns true, except that the iswgraph and
15180 iswpunct functions may differ with respect to wide characters other than L' ' that are
15181 both printing and white-space wide characters.304)
15182 Forward references: the wctob function (7.24.6.1.2).
15183 7.25.2.1.1 The iswalnum function
15185 1 #include <wctype.h>
15186 int iswalnum(wint_t wc);
15188 2 The iswalnum function tests for any wide character for which iswalpha or
15190 7.25.2.1.2 The iswalpha function
15192 1 #include <wctype.h>
15193 int iswalpha(wint_t wc);
15195 2 The iswalpha function tests for any wide character for which iswupper or
15196 iswlower is true, or any wide character that is one of a locale-specific set of alphabetic
15198 304) For example, if the expression isalpha(wctob(wc)) evaluates to true, then the call
15199 iswalpha(wc) also returns true. But, if the expression isgraph(wctob(wc)) evaluates to true
15200 (which cannot occur for wc == L' ' of course), then either iswgraph(wc) or iswprint(wc)
15201 && iswspace(wc) is true, but not both.
15205 wide characters for which none of iswcntrl, iswdigit, iswpunct, or iswspace
15207 7.25.2.1.3 The iswblank function
15209 1 #include <wctype.h>
15210 int iswblank(wint_t wc);
15212 2 The iswblank function tests for any wide character that is a standard blank wide
15213 character or is one of a locale-specific set of wide characters for which iswspace is true
15214 and that is used to separate words within a line of text. The standard blank wide
15215 characters are the following: space (L' '), and horizontal tab (L'\t'). In the "C"
15216 locale, iswblank returns true only for the standard blank characters.
15217 7.25.2.1.4 The iswcntrl function
15219 1 #include <wctype.h>
15220 int iswcntrl(wint_t wc);
15222 2 The iswcntrl function tests for any control wide character.
15223 7.25.2.1.5 The iswdigit function
15225 1 #include <wctype.h>
15226 int iswdigit(wint_t wc);
15228 2 The iswdigit function tests for any wide character that corresponds to a decimal-digit
15229 character (as defined in 5.2.1).
15230 7.25.2.1.6 The iswgraph function
15232 1 #include <wctype.h>
15233 int iswgraph(wint_t wc);
15238 305) The functions iswlower and iswupper test true or false separately for each of these additional
15239 wide characters; all four combinations are possible.
15244 2 The iswgraph function tests for any wide character for which iswprint is true and
15245 iswspace is false.306)
15246 7.25.2.1.7 The iswlower function
15248 1 #include <wctype.h>
15249 int iswlower(wint_t wc);
15251 2 The iswlower function tests for any wide character that corresponds to a lowercase
15252 letter or is one of a locale-specific set of wide characters for which none of iswcntrl,
15253 iswdigit, iswpunct, or iswspace is true.
15254 7.25.2.1.8 The iswprint function
15256 1 #include <wctype.h>
15257 int iswprint(wint_t wc);
15259 2 The iswprint function tests for any printing wide character.
15260 7.25.2.1.9 The iswpunct function
15262 1 #include <wctype.h>
15263 int iswpunct(wint_t wc);
15265 2 The iswpunct function tests for any printing wide character that is one of a locale-
15266 specific set of punctuation wide characters for which neither iswspace nor iswalnum
15268 7.25.2.1.10 The iswspace function
15270 1 #include <wctype.h>
15271 int iswspace(wint_t wc);
15275 306) Note that the behavior of the iswgraph and iswpunct functions may differ from their
15276 corresponding functions in 7.4.1 with respect to printing, white-space, single-byte execution
15277 characters other than ' '.
15282 2 The iswspace function tests for any wide character that corresponds to a locale-specific
15283 set of white-space wide characters for which none of iswalnum, iswgraph, or
15285 7.25.2.1.11 The iswupper function
15287 1 #include <wctype.h>
15288 int iswupper(wint_t wc);
15290 2 The iswupper function tests for any wide character that corresponds to an uppercase
15291 letter or is one of a locale-specific set of wide characters for which none of iswcntrl,
15292 iswdigit, iswpunct, or iswspace is true.
15293 7.25.2.1.12 The iswxdigit function
15295 1 #include <wctype.h>
15296 int iswxdigit(wint_t wc);
15298 2 The iswxdigit function tests for any wide character that corresponds to a
15299 hexadecimal-digit character (as defined in 6.4.4.1).
15300 7.25.2.2 Extensible wide character classification functions
15301 1 The functions wctype and iswctype provide extensible wide character classification
15302 as well as testing equivalent to that performed by the functions described in the previous
15303 subclause (7.25.2.1).
15304 7.25.2.2.1 The iswctype function
15306 1 #include <wctype.h>
15307 int iswctype(wint_t wc, wctype_t desc);
15309 2 The iswctype function determines whether the wide character wc has the property
15310 described by desc. The current setting of the LC_CTYPE category shall be the same as
15311 during the call to wctype that returned the value desc.
15312 3 Each of the following expressions has a truth-value equivalent to the call to the wide
15313 character classification function (7.25.2.1) in the comment that follows the expression:
15317 iswctype(wc, wctype("alnum")) // iswalnum(wc)
15318 iswctype(wc, wctype("alpha")) // iswalpha(wc)
15319 iswctype(wc, wctype("blank")) // iswblank(wc)
15320 iswctype(wc, wctype("cntrl")) // iswcntrl(wc)
15321 iswctype(wc, wctype("digit")) // iswdigit(wc)
15322 iswctype(wc, wctype("graph")) // iswgraph(wc)
15323 iswctype(wc, wctype("lower")) // iswlower(wc)
15324 iswctype(wc, wctype("print")) // iswprint(wc)
15325 iswctype(wc, wctype("punct")) // iswpunct(wc)
15326 iswctype(wc, wctype("space")) // iswspace(wc)
15327 iswctype(wc, wctype("upper")) // iswupper(wc)
15328 iswctype(wc, wctype("xdigit")) // iswxdigit(wc)
15330 4 The iswctype function returns nonzero (true) if and only if the value of the wide
15331 character wc has the property described by desc.
15332 Forward references: the wctype function (7.25.2.2.2).
15333 7.25.2.2.2 The wctype function
15335 1 #include <wctype.h>
15336 wctype_t wctype(const char *property);
15338 2 The wctype function constructs a value with type wctype_t that describes a class of
15339 wide characters identified by the string argument property.
15340 3 The strings listed in the description of the iswctype function shall be valid in all
15341 locales as property arguments to the wctype function.
15343 4 If property identifies a valid class of wide characters according to the LC_CTYPE
15344 category of the current locale, the wctype function returns a nonzero value that is valid
15345 as the second argument to the iswctype function; otherwise, it returns zero. *
15349 7.25.3 Wide character case mapping utilities
15350 1 The header <wctype.h> declares several functions useful for mapping wide characters.
15351 7.25.3.1 Wide character case mapping functions
15352 7.25.3.1.1 The towlower function
15354 1 #include <wctype.h>
15355 wint_t towlower(wint_t wc);
15357 2 The towlower function converts an uppercase letter to a corresponding lowercase letter.
15359 3 If the argument is a wide character for which iswupper is true and there are one or
15360 more corresponding wide characters, as specified by the current locale, for which
15361 iswlower is true, the towlower function returns one of the corresponding wide
15362 characters (always the same one for any given locale); otherwise, the argument is
15363 returned unchanged.
15364 7.25.3.1.2 The towupper function
15366 1 #include <wctype.h>
15367 wint_t towupper(wint_t wc);
15369 2 The towupper function converts a lowercase letter to a corresponding uppercase letter.
15371 3 If the argument is a wide character for which iswlower is true and there are one or
15372 more corresponding wide characters, as specified by the current locale, for which
15373 iswupper is true, the towupper function returns one of the corresponding wide
15374 characters (always the same one for any given locale); otherwise, the argument is
15375 returned unchanged.
15376 7.25.3.2 Extensible wide character case mapping functions
15377 1 The functions wctrans and towctrans provide extensible wide character mapping as
15378 well as case mapping equivalent to that performed by the functions described in the
15379 previous subclause (7.25.3.1).
15383 7.25.3.2.1 The towctrans function
15385 1 #include <wctype.h>
15386 wint_t towctrans(wint_t wc, wctrans_t desc);
15388 2 The towctrans function maps the wide character wc using the mapping described by
15389 desc. The current setting of the LC_CTYPE category shall be the same as during the call
15390 to wctrans that returned the value desc.
15391 3 Each of the following expressions behaves the same as the call to the wide character case
15392 mapping function (7.25.3.1) in the comment that follows the expression:
15393 towctrans(wc, wctrans("tolower")) // towlower(wc)
15394 towctrans(wc, wctrans("toupper")) // towupper(wc)
15396 4 The towctrans function returns the mapped value of wc using the mapping described
15398 7.25.3.2.2 The wctrans function
15400 1 #include <wctype.h>
15401 wctrans_t wctrans(const char *property);
15403 2 The wctrans function constructs a value with type wctrans_t that describes a
15404 mapping between wide characters identified by the string argument property.
15405 3 The strings listed in the description of the towctrans function shall be valid in all
15406 locales as property arguments to the wctrans function.
15408 4 If property identifies a valid mapping of wide characters according to the LC_CTYPE
15409 category of the current locale, the wctrans function returns a nonzero value that is valid
15410 as the second argument to the towctrans function; otherwise, it returns zero.
15414 7.26 Future library directions
15415 1 The following names are grouped under individual headers for convenience. All external
15416 names described below are reserved no matter what headers are included by the program.
15417 7.26.1 Complex arithmetic <complex.h>
15418 1 The function names
15420 cerfc clog10 clgamma
15421 cexp2 clog1p ctgamma
15422 and the same names suffixed with f or l may be added to the declarations in the
15423 <complex.h> header.
15424 7.26.2 Character handling <ctype.h>
15425 1 Function names that begin with either is or to, and a lowercase letter may be added to
15426 the declarations in the <ctype.h> header.
15427 7.26.3 Errors <errno.h>
15428 1 Macros that begin with E and a digit or E and an uppercase letter may be added to the
15429 declarations in the <errno.h> header.
15430 7.26.4 Format conversion of integer types <inttypes.h>
15431 1 Macro names beginning with PRI or SCN followed by any lowercase letter or X may be
15432 added to the macros defined in the <inttypes.h> header.
15433 7.26.5 Localization <locale.h>
15434 1 Macros that begin with LC_ and an uppercase letter may be added to the definitions in
15435 the <locale.h> header.
15436 7.26.6 Signal handling <signal.h>
15437 1 Macros that begin with either SIG and an uppercase letter or SIG_ and an uppercase
15438 letter may be added to the definitions in the <signal.h> header.
15439 7.26.7 Boolean type and values <stdbool.h>
15440 1 The ability to undefine and perhaps then redefine the macros bool, true, and false is
15441 an obsolescent feature.
15442 7.26.8 Integer types <stdint.h>
15443 1 Typedef names beginning with int or uint and ending with _t may be added to the
15444 types defined in the <stdint.h> header. Macro names beginning with INT or UINT
15445 and ending with _MAX, _MIN, or _C may be added to the macros defined in the
15450 7.26.9 Input/output <stdio.h>
15451 1 Lowercase letters may be added to the conversion specifiers and length modifiers in
15452 fprintf and fscanf. Other characters may be used in extensions.
15453 2 The gets function is obsolescent, and is deprecated.
15454 3 The use of ungetc on a binary stream where the file position indicator is zero prior to
15455 the call is an obsolescent feature.
15456 7.26.10 General utilities <stdlib.h>
15457 1 Function names that begin with str and a lowercase letter may be added to the
15458 declarations in the <stdlib.h> header.
15459 7.26.11 String handling <string.h>
15460 1 Function names that begin with str, mem, or wcs and a lowercase letter may be added
15461 to the declarations in the <string.h> header.
15462 7.26.12 Extended multibyte and wide character utilities <wchar.h>
15463 1 Function names that begin with wcs and a lowercase letter may be added to the
15464 declarations in the <wchar.h> header.
15465 2 Lowercase letters may be added to the conversion specifiers and length modifiers in
15466 fwprintf and fwscanf. Other characters may be used in extensions.
15467 7.26.13 Wide character classification and mapping utilities
15469 1 Function names that begin with is or to and a lowercase letter may be added to the
15470 declarations in the <wctype.h> header.
15476 Language syntax summary
15477 1 NOTE The notation is described in 6.1.
15479 A.1 Lexical grammar
15480 A.1.1 Lexical elements
15487 (6.4) preprocessing-token:
15494 each non-white-space character that cannot be one of the above
15496 (6.4.1) keyword: one of
15497 auto enum restrict unsigned
15498 break extern return void
15499 case float short volatile
15500 char for signed while
15501 const goto sizeof _Bool
15502 continue if static _Complex
15503 default inline struct _Imaginary
15505 double long typedef
15506 else register union
15511 (6.4.2.1) identifier:
15512 identifier-nondigit
15513 identifier identifier-nondigit
15515 (6.4.2.1) identifier-nondigit:
15517 universal-character-name
15518 other implementation-defined characters
15519 (6.4.2.1) nondigit: one of
15520 _ a b c d e f g h i j k l m
15521 n o p q r s t u v w x y z
15522 A B C D E F G H I J K L M
15523 N O P Q R S T U V W X Y Z
15524 (6.4.2.1) digit: one of
15525 0 1 2 3 4 5 6 7 8 9
15526 A.1.4 Universal character names
15527 (6.4.3) universal-character-name:
15529 \U hex-quad hex-quad
15531 hexadecimal-digit hexadecimal-digit
15532 hexadecimal-digit hexadecimal-digit
15537 enumeration-constant
15539 (6.4.4.1) integer-constant:
15540 decimal-constant integer-suffixopt
15541 octal-constant integer-suffixopt
15542 hexadecimal-constant integer-suffixopt
15543 (6.4.4.1) decimal-constant:
15545 decimal-constant digit
15549 (6.4.4.1) octal-constant:
15551 octal-constant octal-digit
15552 (6.4.4.1) hexadecimal-constant:
15553 hexadecimal-prefix hexadecimal-digit
15554 hexadecimal-constant hexadecimal-digit
15555 (6.4.4.1) hexadecimal-prefix: one of
15557 (6.4.4.1) nonzero-digit: one of
15559 (6.4.4.1) octal-digit: one of
15561 (6.4.4.1) hexadecimal-digit: one of
15562 0 1 2 3 4 5 6 7 8 9
15565 (6.4.4.1) integer-suffix:
15566 unsigned-suffix long-suffixopt
15567 unsigned-suffix long-long-suffix
15568 long-suffix unsigned-suffixopt
15569 long-long-suffix unsigned-suffixopt
15570 (6.4.4.1) unsigned-suffix: one of
15572 (6.4.4.1) long-suffix: one of
15574 (6.4.4.1) long-long-suffix: one of
15576 (6.4.4.2) floating-constant:
15577 decimal-floating-constant
15578 hexadecimal-floating-constant
15579 (6.4.4.2) decimal-floating-constant:
15580 fractional-constant exponent-partopt floating-suffixopt
15581 digit-sequence exponent-part floating-suffixopt
15585 (6.4.4.2) hexadecimal-floating-constant:
15586 hexadecimal-prefix hexadecimal-fractional-constant
15587 binary-exponent-part floating-suffixopt
15588 hexadecimal-prefix hexadecimal-digit-sequence
15589 binary-exponent-part floating-suffixopt
15590 (6.4.4.2) fractional-constant:
15591 digit-sequenceopt . digit-sequence
15593 (6.4.4.2) exponent-part:
15594 e signopt digit-sequence
15595 E signopt digit-sequence
15596 (6.4.4.2) sign: one of
15598 (6.4.4.2) digit-sequence:
15600 digit-sequence digit
15601 (6.4.4.2) hexadecimal-fractional-constant:
15602 hexadecimal-digit-sequenceopt .
15603 hexadecimal-digit-sequence
15604 hexadecimal-digit-sequence .
15605 (6.4.4.2) binary-exponent-part:
15606 p signopt digit-sequence
15607 P signopt digit-sequence
15608 (6.4.4.2) hexadecimal-digit-sequence:
15610 hexadecimal-digit-sequence hexadecimal-digit
15611 (6.4.4.2) floating-suffix: one of
15613 (6.4.4.3) enumeration-constant:
15615 (6.4.4.4) character-constant:
15616 ' c-char-sequence '
15617 L' c-char-sequence '
15621 (6.4.4.4) c-char-sequence:
15623 c-char-sequence c-char
15625 any member of the source character set except
15626 the single-quote ', backslash \, or new-line character
15628 (6.4.4.4) escape-sequence:
15629 simple-escape-sequence
15630 octal-escape-sequence
15631 hexadecimal-escape-sequence
15632 universal-character-name
15633 (6.4.4.4) simple-escape-sequence: one of
15635 \a \b \f \n \r \t \v
15636 (6.4.4.4) octal-escape-sequence:
15638 \ octal-digit octal-digit
15639 \ octal-digit octal-digit octal-digit
15640 (6.4.4.4) hexadecimal-escape-sequence:
15641 \x hexadecimal-digit
15642 hexadecimal-escape-sequence hexadecimal-digit
15643 A.1.6 String literals
15644 (6.4.5) string-literal:
15645 " s-char-sequenceopt "
15646 L" s-char-sequenceopt "
15647 (6.4.5) s-char-sequence:
15649 s-char-sequence s-char
15651 any member of the source character set except
15652 the double-quote ", backslash \, or new-line character
15658 (6.4.6) punctuator: one of
15661 / % << >> < > <= >= == != ^ | && ||
15663 = *= /= %= += -= <<= >>= &= ^= |=
15665 <: :> <% %> %: %:%:
15667 (6.4.7) header-name:
15668 < h-char-sequence >
15669 " q-char-sequence "
15670 (6.4.7) h-char-sequence:
15672 h-char-sequence h-char
15674 any member of the source character set except
15675 the new-line character and >
15676 (6.4.7) q-char-sequence:
15678 q-char-sequence q-char
15680 any member of the source character set except
15681 the new-line character and "
15682 A.1.9 Preprocessing numbers
15687 pp-number identifier-nondigit
15696 A.2 Phrase structure grammar
15698 (6.5.1) primary-expression:
15703 (6.5.2) postfix-expression:
15705 postfix-expression [ expression ]
15706 postfix-expression ( argument-expression-listopt )
15707 postfix-expression . identifier
15708 postfix-expression -> identifier
15709 postfix-expression ++
15710 postfix-expression --
15711 ( type-name ) { initializer-list }
15712 ( type-name ) { initializer-list , }
15713 (6.5.2) argument-expression-list:
15714 assignment-expression
15715 argument-expression-list , assignment-expression
15716 (6.5.3) unary-expression:
15718 ++ unary-expression
15719 -- unary-expression
15720 unary-operator cast-expression
15721 sizeof unary-expression
15722 sizeof ( type-name )
15723 (6.5.3) unary-operator: one of
15725 (6.5.4) cast-expression:
15727 ( type-name ) cast-expression
15728 (6.5.5) multiplicative-expression:
15730 multiplicative-expression * cast-expression
15731 multiplicative-expression / cast-expression
15732 multiplicative-expression % cast-expression
15736 (6.5.6) additive-expression:
15737 multiplicative-expression
15738 additive-expression + multiplicative-expression
15739 additive-expression - multiplicative-expression
15740 (6.5.7) shift-expression:
15741 additive-expression
15742 shift-expression << additive-expression
15743 shift-expression >> additive-expression
15744 (6.5.8) relational-expression:
15746 relational-expression < shift-expression
15747 relational-expression > shift-expression
15748 relational-expression <= shift-expression
15749 relational-expression >= shift-expression
15750 (6.5.9) equality-expression:
15751 relational-expression
15752 equality-expression == relational-expression
15753 equality-expression != relational-expression
15754 (6.5.10) AND-expression:
15755 equality-expression
15756 AND-expression & equality-expression
15757 (6.5.11) exclusive-OR-expression:
15759 exclusive-OR-expression ^ AND-expression
15760 (6.5.12) inclusive-OR-expression:
15761 exclusive-OR-expression
15762 inclusive-OR-expression | exclusive-OR-expression
15763 (6.5.13) logical-AND-expression:
15764 inclusive-OR-expression
15765 logical-AND-expression && inclusive-OR-expression
15766 (6.5.14) logical-OR-expression:
15767 logical-AND-expression
15768 logical-OR-expression || logical-AND-expression
15769 (6.5.15) conditional-expression:
15770 logical-OR-expression
15771 logical-OR-expression ? expression : conditional-expression
15775 (6.5.16) assignment-expression:
15776 conditional-expression
15777 unary-expression assignment-operator assignment-expression
15778 (6.5.16) assignment-operator: one of
15779 = *= /= %= += -= <<= >>= &= ^= |=
15780 (6.5.17) expression:
15781 assignment-expression
15782 expression , assignment-expression
15783 (6.6) constant-expression:
15784 conditional-expression
15787 declaration-specifiers init-declarator-listopt ;
15788 (6.7) declaration-specifiers:
15789 storage-class-specifier declaration-specifiersopt
15790 type-specifier declaration-specifiersopt
15791 type-qualifier declaration-specifiersopt
15792 function-specifier declaration-specifiersopt
15793 (6.7) init-declarator-list:
15795 init-declarator-list , init-declarator
15796 (6.7) init-declarator:
15798 declarator = initializer
15799 (6.7.1) storage-class-specifier:
15808 (6.7.2) type-specifier:
15820 struct-or-union-specifier *
15823 (6.7.2.1) struct-or-union-specifier:
15824 struct-or-union identifieropt { struct-declaration-list }
15825 struct-or-union identifier
15826 (6.7.2.1) struct-or-union:
15829 (6.7.2.1) struct-declaration-list:
15831 struct-declaration-list struct-declaration
15832 (6.7.2.1) struct-declaration:
15833 specifier-qualifier-list struct-declarator-list ;
15834 (6.7.2.1) specifier-qualifier-list:
15835 type-specifier specifier-qualifier-listopt
15836 type-qualifier specifier-qualifier-listopt
15837 (6.7.2.1) struct-declarator-list:
15839 struct-declarator-list , struct-declarator
15840 (6.7.2.1) struct-declarator:
15842 declaratoropt : constant-expression
15846 (6.7.2.2) enum-specifier:
15847 enum identifieropt { enumerator-list }
15848 enum identifieropt { enumerator-list , }
15850 (6.7.2.2) enumerator-list:
15852 enumerator-list , enumerator
15853 (6.7.2.2) enumerator:
15854 enumeration-constant
15855 enumeration-constant = constant-expression
15856 (6.7.3) type-qualifier:
15860 (6.7.4) function-specifier:
15862 (6.7.5) declarator:
15863 pointeropt direct-declarator
15864 (6.7.5) direct-declarator:
15867 direct-declarator [ type-qualifier-listopt assignment-expressionopt ]
15868 direct-declarator [ static type-qualifier-listopt assignment-expression ]
15869 direct-declarator [ type-qualifier-list static assignment-expression ]
15870 direct-declarator [ type-qualifier-listopt * ]
15871 direct-declarator ( parameter-type-list )
15872 direct-declarator ( identifier-listopt )
15874 * type-qualifier-listopt
15875 * type-qualifier-listopt pointer
15876 (6.7.5) type-qualifier-list:
15878 type-qualifier-list type-qualifier
15879 (6.7.5) parameter-type-list:
15881 parameter-list , ...
15885 (6.7.5) parameter-list:
15886 parameter-declaration
15887 parameter-list , parameter-declaration
15888 (6.7.5) parameter-declaration:
15889 declaration-specifiers declarator
15890 declaration-specifiers abstract-declaratoropt
15891 (6.7.5) identifier-list:
15893 identifier-list , identifier
15895 specifier-qualifier-list abstract-declaratoropt
15896 (6.7.6) abstract-declarator:
15898 pointeropt direct-abstract-declarator
15899 (6.7.6) direct-abstract-declarator:
15900 ( abstract-declarator )
15901 direct-abstract-declaratoropt [ type-qualifier-listopt
15902 assignment-expressionopt ]
15903 direct-abstract-declaratoropt [ static type-qualifier-listopt
15904 assignment-expression ]
15905 direct-abstract-declaratoropt [ type-qualifier-list static
15906 assignment-expression ]
15907 direct-abstract-declaratoropt [ * ]
15908 direct-abstract-declaratoropt ( parameter-type-listopt )
15909 (6.7.7) typedef-name:
15911 (6.7.8) initializer:
15912 assignment-expression
15913 { initializer-list }
15914 { initializer-list , }
15915 (6.7.8) initializer-list:
15916 designationopt initializer
15917 initializer-list , designationopt initializer
15918 (6.7.8) designation:
15923 (6.7.8) designator-list:
15925 designator-list designator
15926 (6.7.8) designator:
15927 [ constant-expression ]
15933 expression-statement
15934 selection-statement
15935 iteration-statement
15937 (6.8.1) labeled-statement:
15938 identifier : statement
15939 case constant-expression : statement
15940 default : statement
15941 (6.8.2) compound-statement:
15942 { block-item-listopt }
15943 (6.8.2) block-item-list:
15945 block-item-list block-item
15946 (6.8.2) block-item:
15949 (6.8.3) expression-statement:
15951 (6.8.4) selection-statement:
15952 if ( expression ) statement
15953 if ( expression ) statement else statement
15954 switch ( expression ) statement
15958 (6.8.5) iteration-statement:
15959 while ( expression ) statement
15960 do statement while ( expression ) ;
15961 for ( expressionopt ; expressionopt ; expressionopt ) statement
15962 for ( declaration expressionopt ; expressionopt ) statement
15963 (6.8.6) jump-statement:
15967 return expressionopt ;
15968 A.2.4 External definitions
15969 (6.9) translation-unit:
15970 external-declaration
15971 translation-unit external-declaration
15972 (6.9) external-declaration:
15973 function-definition
15975 (6.9.1) function-definition:
15976 declaration-specifiers declarator declaration-listopt compound-statement
15977 (6.9.1) declaration-list:
15979 declaration-list declaration
15980 A.3 Preprocessing directives
15981 (6.10) preprocessing-file:
15992 if-group elif-groupsopt else-groupopt endif-line
15997 # if constant-expression new-line groupopt
15998 # ifdef identifier new-line groupopt
15999 # ifndef identifier new-line groupopt
16000 (6.10) elif-groups:
16002 elif-groups elif-group
16004 # elif constant-expression new-line groupopt
16006 # else new-line groupopt
16009 (6.10) control-line:
16010 # include pp-tokens new-line
16011 # define identifier replacement-list new-line
16012 # define identifier lparen identifier-listopt )
16013 replacement-list new-line
16014 # define identifier lparen ... ) replacement-list new-line
16015 # define identifier lparen identifier-list , ... )
16016 replacement-list new-line
16017 # undef identifier new-line
16018 # line pp-tokens new-line
16019 # error pp-tokensopt new-line
16020 # pragma pp-tokensopt new-line
16023 pp-tokensopt new-line
16024 (6.10) non-directive:
16027 a ( character not immediately preceded by white-space
16028 (6.10) replacement-list:
16034 preprocessing-token
16035 pp-tokens preprocessing-token
16037 the new-line character
16044 B.1 Diagnostics <assert.h>
16046 void assert(scalar expression);
16047 B.2 Complex <complex.h>
16048 complex imaginary I
16049 _Complex_I _Imaginary_I
16050 #pragma STDC CX_LIMITED_RANGE on-off-switch
16051 double complex cacos(double complex z);
16052 float complex cacosf(float complex z);
16053 long double complex cacosl(long double complex z);
16054 double complex casin(double complex z);
16055 float complex casinf(float complex z);
16056 long double complex casinl(long double complex z);
16057 double complex catan(double complex z);
16058 float complex catanf(float complex z);
16059 long double complex catanl(long double complex z);
16060 double complex ccos(double complex z);
16061 float complex ccosf(float complex z);
16062 long double complex ccosl(long double complex z);
16063 double complex csin(double complex z);
16064 float complex csinf(float complex z);
16065 long double complex csinl(long double complex z);
16066 double complex ctan(double complex z);
16067 float complex ctanf(float complex z);
16068 long double complex ctanl(long double complex z);
16069 double complex cacosh(double complex z);
16070 float complex cacoshf(float complex z);
16071 long double complex cacoshl(long double complex z);
16072 double complex casinh(double complex z);
16073 float complex casinhf(float complex z);
16074 long double complex casinhl(long double complex z);
16075 double complex catanh(double complex z);
16076 float complex catanhf(float complex z);
16077 long double complex catanhl(long double complex z);
16081 double complex ccosh(double complex z);
16082 float complex ccoshf(float complex z);
16083 long double complex ccoshl(long double complex z);
16084 double complex csinh(double complex z);
16085 float complex csinhf(float complex z);
16086 long double complex csinhl(long double complex z);
16087 double complex ctanh(double complex z);
16088 float complex ctanhf(float complex z);
16089 long double complex ctanhl(long double complex z);
16090 double complex cexp(double complex z);
16091 float complex cexpf(float complex z);
16092 long double complex cexpl(long double complex z);
16093 double complex clog(double complex z);
16094 float complex clogf(float complex z);
16095 long double complex clogl(long double complex z);
16096 double cabs(double complex z);
16097 float cabsf(float complex z);
16098 long double cabsl(long double complex z);
16099 double complex cpow(double complex x, double complex y);
16100 float complex cpowf(float complex x, float complex y);
16101 long double complex cpowl(long double complex x,
16102 long double complex y);
16103 double complex csqrt(double complex z);
16104 float complex csqrtf(float complex z);
16105 long double complex csqrtl(long double complex z);
16106 double carg(double complex z);
16107 float cargf(float complex z);
16108 long double cargl(long double complex z);
16109 double cimag(double complex z);
16110 float cimagf(float complex z);
16111 long double cimagl(long double complex z);
16112 double complex conj(double complex z);
16113 float complex conjf(float complex z);
16114 long double complex conjl(long double complex z);
16115 double complex cproj(double complex z);
16116 float complex cprojf(float complex z);
16117 long double complex cprojl(long double complex z);
16118 double creal(double complex z);
16119 float crealf(float complex z);
16120 long double creall(long double complex z);
16124 B.3 Character handling <ctype.h>
16125 int isalnum(int c);
16126 int isalpha(int c);
16127 int isblank(int c);
16128 int iscntrl(int c);
16129 int isdigit(int c);
16130 int isgraph(int c);
16131 int islower(int c);
16132 int isprint(int c);
16133 int ispunct(int c);
16134 int isspace(int c);
16135 int isupper(int c);
16136 int isxdigit(int c);
16137 int tolower(int c);
16138 int toupper(int c);
16139 B.4 Errors <errno.h>
16140 EDOM EILSEQ ERANGE errno
16141 B.5 Floating-point environment <fenv.h>
16142 fenv_t FE_OVERFLOW FE_TOWARDZERO
16143 fexcept_t FE_UNDERFLOW FE_UPWARD
16144 FE_DIVBYZERO FE_ALL_EXCEPT FE_DFL_ENV
16145 FE_INEXACT FE_DOWNWARD
16146 FE_INVALID FE_TONEAREST
16147 #pragma STDC FENV_ACCESS on-off-switch
16148 int feclearexcept(int excepts);
16149 int fegetexceptflag(fexcept_t *flagp, int excepts);
16150 int feraiseexcept(int excepts);
16151 int fesetexceptflag(const fexcept_t *flagp,
16153 int fetestexcept(int excepts);
16154 int fegetround(void);
16155 int fesetround(int round);
16156 int fegetenv(fenv_t *envp);
16157 int feholdexcept(fenv_t *envp);
16158 int fesetenv(const fenv_t *envp);
16159 int feupdateenv(const fenv_t *envp);
16163 B.6 Characteristics of floating types <float.h>
16164 FLT_ROUNDS DBL_MIN_EXP FLT_MAX
16165 FLT_EVAL_METHOD LDBL_MIN_EXP DBL_MAX
16166 FLT_RADIX FLT_MIN_10_EXP LDBL_MAX
16167 FLT_MANT_DIG DBL_MIN_10_EXP FLT_EPSILON
16168 DBL_MANT_DIG LDBL_MIN_10_EXP DBL_EPSILON
16169 LDBL_MANT_DIG FLT_MAX_EXP LDBL_EPSILON
16170 DECIMAL_DIG DBL_MAX_EXP FLT_MIN
16171 FLT_DIG LDBL_MAX_EXP DBL_MIN
16172 DBL_DIG FLT_MAX_10_EXP LDBL_MIN
16173 LDBL_DIG DBL_MAX_10_EXP
16174 FLT_MIN_EXP LDBL_MAX_10_EXP
16175 B.7 Format conversion of integer types <inttypes.h>
16177 PRIdN PRIdLEASTN PRIdFASTN PRIdMAX PRIdPTR
16178 PRIiN PRIiLEASTN PRIiFASTN PRIiMAX PRIiPTR
16179 PRIoN PRIoLEASTN PRIoFASTN PRIoMAX PRIoPTR
16180 PRIuN PRIuLEASTN PRIuFASTN PRIuMAX PRIuPTR
16181 PRIxN PRIxLEASTN PRIxFASTN PRIxMAX PRIxPTR
16182 PRIXN PRIXLEASTN PRIXFASTN PRIXMAX PRIXPTR
16183 SCNdN SCNdLEASTN SCNdFASTN SCNdMAX SCNdPTR
16184 SCNiN SCNiLEASTN SCNiFASTN SCNiMAX SCNiPTR
16185 SCNoN SCNoLEASTN SCNoFASTN SCNoMAX SCNoPTR
16186 SCNuN SCNuLEASTN SCNuFASTN SCNuMAX SCNuPTR
16187 SCNxN SCNxLEASTN SCNxFASTN SCNxMAX SCNxPTR
16188 intmax_t imaxabs(intmax_t j);
16189 imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
16190 intmax_t strtoimax(const char * restrict nptr,
16191 char ** restrict endptr, int base);
16192 uintmax_t strtoumax(const char * restrict nptr,
16193 char ** restrict endptr, int base);
16194 intmax_t wcstoimax(const wchar_t * restrict nptr,
16195 wchar_t ** restrict endptr, int base);
16196 uintmax_t wcstoumax(const wchar_t * restrict nptr,
16197 wchar_t ** restrict endptr, int base);
16201 B.8 Alternative spellings <iso646.h>
16202 and bitor not_eq xor
16203 and_eq compl or xor_eq
16205 B.9 Sizes of integer types <limits.h>
16206 CHAR_BIT CHAR_MAX INT_MIN ULONG_MAX
16207 SCHAR_MIN MB_LEN_MAX INT_MAX LLONG_MIN
16208 SCHAR_MAX SHRT_MIN UINT_MAX LLONG_MAX
16209 UCHAR_MAX SHRT_MAX LONG_MIN ULLONG_MAX
16210 CHAR_MIN USHRT_MAX LONG_MAX
16211 B.10 Localization <locale.h>
16212 struct lconv LC_ALL LC_CTYPE LC_NUMERIC
16213 NULL LC_COLLATE LC_MONETARY LC_TIME
16214 char *setlocale(int category, const char *locale);
16215 struct lconv *localeconv(void);
16216 B.11 Mathematics <math.h>
16217 float_t FP_INFINITE FP_FAST_FMAL
16218 double_t FP_NAN FP_ILOGB0
16219 HUGE_VAL FP_NORMAL FP_ILOGBNAN
16220 HUGE_VALF FP_SUBNORMAL MATH_ERRNO
16221 HUGE_VALL FP_ZERO MATH_ERREXCEPT
16222 INFINITY FP_FAST_FMA math_errhandling
16224 #pragma STDC FP_CONTRACT on-off-switch
16225 int fpclassify(real-floating x);
16226 int isfinite(real-floating x);
16227 int isinf(real-floating x);
16228 int isnan(real-floating x);
16229 int isnormal(real-floating x);
16230 int signbit(real-floating x);
16231 double acos(double x);
16232 float acosf(float x);
16233 long double acosl(long double x);
16234 double asin(double x);
16235 float asinf(float x);
16236 long double asinl(long double x);
16237 double atan(double x);
16241 float atanf(float x);
16242 long double atanl(long double x);
16243 double atan2(double y, double x);
16244 float atan2f(float y, float x);
16245 long double atan2l(long double y, long double x);
16246 double cos(double x);
16247 float cosf(float x);
16248 long double cosl(long double x);
16249 double sin(double x);
16250 float sinf(float x);
16251 long double sinl(long double x);
16252 double tan(double x);
16253 float tanf(float x);
16254 long double tanl(long double x);
16255 double acosh(double x);
16256 float acoshf(float x);
16257 long double acoshl(long double x);
16258 double asinh(double x);
16259 float asinhf(float x);
16260 long double asinhl(long double x);
16261 double atanh(double x);
16262 float atanhf(float x);
16263 long double atanhl(long double x);
16264 double cosh(double x);
16265 float coshf(float x);
16266 long double coshl(long double x);
16267 double sinh(double x);
16268 float sinhf(float x);
16269 long double sinhl(long double x);
16270 double tanh(double x);
16271 float tanhf(float x);
16272 long double tanhl(long double x);
16273 double exp(double x);
16274 float expf(float x);
16275 long double expl(long double x);
16276 double exp2(double x);
16277 float exp2f(float x);
16278 long double exp2l(long double x);
16279 double expm1(double x);
16280 float expm1f(float x);
16281 long double expm1l(long double x);
16285 double frexp(double value, int *exp);
16286 float frexpf(float value, int *exp);
16287 long double frexpl(long double value, int *exp);
16288 int ilogb(double x);
16289 int ilogbf(float x);
16290 int ilogbl(long double x);
16291 double ldexp(double x, int exp);
16292 float ldexpf(float x, int exp);
16293 long double ldexpl(long double x, int exp);
16294 double log(double x);
16295 float logf(float x);
16296 long double logl(long double x);
16297 double log10(double x);
16298 float log10f(float x);
16299 long double log10l(long double x);
16300 double log1p(double x);
16301 float log1pf(float x);
16302 long double log1pl(long double x);
16303 double log2(double x);
16304 float log2f(float x);
16305 long double log2l(long double x);
16306 double logb(double x);
16307 float logbf(float x);
16308 long double logbl(long double x);
16309 double modf(double value, double *iptr);
16310 float modff(float value, float *iptr);
16311 long double modfl(long double value, long double *iptr);
16312 double scalbn(double x, int n);
16313 float scalbnf(float x, int n);
16314 long double scalbnl(long double x, int n);
16315 double scalbln(double x, long int n);
16316 float scalblnf(float x, long int n);
16317 long double scalblnl(long double x, long int n);
16318 double cbrt(double x);
16319 float cbrtf(float x);
16320 long double cbrtl(long double x);
16321 double fabs(double x);
16322 float fabsf(float x);
16323 long double fabsl(long double x);
16324 double hypot(double x, double y);
16325 float hypotf(float x, float y);
16329 long double hypotl(long double x, long double y);
16330 double pow(double x, double y);
16331 float powf(float x, float y);
16332 long double powl(long double x, long double y);
16333 double sqrt(double x);
16334 float sqrtf(float x);
16335 long double sqrtl(long double x);
16336 double erf(double x);
16337 float erff(float x);
16338 long double erfl(long double x);
16339 double erfc(double x);
16340 float erfcf(float x);
16341 long double erfcl(long double x);
16342 double lgamma(double x);
16343 float lgammaf(float x);
16344 long double lgammal(long double x);
16345 double tgamma(double x);
16346 float tgammaf(float x);
16347 long double tgammal(long double x);
16348 double ceil(double x);
16349 float ceilf(float x);
16350 long double ceill(long double x);
16351 double floor(double x);
16352 float floorf(float x);
16353 long double floorl(long double x);
16354 double nearbyint(double x);
16355 float nearbyintf(float x);
16356 long double nearbyintl(long double x);
16357 double rint(double x);
16358 float rintf(float x);
16359 long double rintl(long double x);
16360 long int lrint(double x);
16361 long int lrintf(float x);
16362 long int lrintl(long double x);
16363 long long int llrint(double x);
16364 long long int llrintf(float x);
16365 long long int llrintl(long double x);
16366 double round(double x);
16367 float roundf(float x);
16368 long double roundl(long double x);
16369 long int lround(double x);
16373 long int lroundf(float x);
16374 long int lroundl(long double x);
16375 long long int llround(double x);
16376 long long int llroundf(float x);
16377 long long int llroundl(long double x);
16378 double trunc(double x);
16379 float truncf(float x);
16380 long double truncl(long double x);
16381 double fmod(double x, double y);
16382 float fmodf(float x, float y);
16383 long double fmodl(long double x, long double y);
16384 double remainder(double x, double y);
16385 float remainderf(float x, float y);
16386 long double remainderl(long double x, long double y);
16387 double remquo(double x, double y, int *quo);
16388 float remquof(float x, float y, int *quo);
16389 long double remquol(long double x, long double y,
16391 double copysign(double x, double y);
16392 float copysignf(float x, float y);
16393 long double copysignl(long double x, long double y);
16394 double nan(const char *tagp);
16395 float nanf(const char *tagp);
16396 long double nanl(const char *tagp);
16397 double nextafter(double x, double y);
16398 float nextafterf(float x, float y);
16399 long double nextafterl(long double x, long double y);
16400 double nexttoward(double x, long double y);
16401 float nexttowardf(float x, long double y);
16402 long double nexttowardl(long double x, long double y);
16403 double fdim(double x, double y);
16404 float fdimf(float x, float y);
16405 long double fdiml(long double x, long double y);
16406 double fmax(double x, double y);
16407 float fmaxf(float x, float y);
16408 long double fmaxl(long double x, long double y);
16409 double fmin(double x, double y);
16410 float fminf(float x, float y);
16411 long double fminl(long double x, long double y);
16412 double fma(double x, double y, double z);
16413 float fmaf(float x, float y, float z);
16417 long double fmal(long double x, long double y,
16419 int isgreater(real-floating x, real-floating y);
16420 int isgreaterequal(real-floating x, real-floating y);
16421 int isless(real-floating x, real-floating y);
16422 int islessequal(real-floating x, real-floating y);
16423 int islessgreater(real-floating x, real-floating y);
16424 int isunordered(real-floating x, real-floating y);
16425 B.12 Nonlocal jumps <setjmp.h>
16427 int setjmp(jmp_buf env);
16428 void longjmp(jmp_buf env, int val);
16429 B.13 Signal handling <signal.h>
16430 sig_atomic_t SIG_IGN SIGILL SIGTERM
16431 SIG_DFL SIGABRT SIGINT
16432 SIG_ERR SIGFPE SIGSEGV
16433 void (*signal(int sig, void (*func)(int)))(int);
16434 int raise(int sig);
16435 B.14 Variable arguments <stdarg.h>
16437 type va_arg(va_list ap, type);
16438 void va_copy(va_list dest, va_list src);
16439 void va_end(va_list ap);
16440 void va_start(va_list ap, parmN);
16441 B.15 Boolean type and values <stdbool.h>
16445 __bool_true_false_are_defined
16449 B.16 Common definitions <stddef.h>
16450 ptrdiff_t size_t wchar_t NULL
16451 offsetof(type, member-designator)
16452 B.17 Integer types <stdint.h>
16453 intN_t INT_LEASTN_MIN PTRDIFF_MAX
16454 uintN_t INT_LEASTN_MAX SIG_ATOMIC_MIN
16455 int_leastN_t UINT_LEASTN_MAX SIG_ATOMIC_MAX
16456 uint_leastN_t INT_FASTN_MIN SIZE_MAX
16457 int_fastN_t INT_FASTN_MAX WCHAR_MIN
16458 uint_fastN_t UINT_FASTN_MAX WCHAR_MAX
16459 intptr_t INTPTR_MIN WINT_MIN
16460 uintptr_t INTPTR_MAX WINT_MAX
16461 intmax_t UINTPTR_MAX INTN_C(value)
16462 uintmax_t INTMAX_MIN UINTN_C(value)
16463 INTN_MIN INTMAX_MAX INTMAX_C(value)
16464 INTN_MAX UINTMAX_MAX UINTMAX_C(value)
16465 UINTN_MAX PTRDIFF_MIN
16466 B.18 Input/output <stdio.h>
16467 size_t _IOLBF FILENAME_MAX TMP_MAX
16468 FILE _IONBF L_tmpnam stderr
16469 fpos_t BUFSIZ SEEK_CUR stdin
16470 NULL EOF SEEK_END stdout
16471 _IOFBF FOPEN_MAX SEEK_SET
16472 int remove(const char *filename);
16473 int rename(const char *old, const char *new);
16474 FILE *tmpfile(void);
16475 char *tmpnam(char *s);
16476 int fclose(FILE *stream);
16477 int fflush(FILE *stream);
16478 FILE *fopen(const char * restrict filename,
16479 const char * restrict mode);
16480 FILE *freopen(const char * restrict filename,
16481 const char * restrict mode,
16482 FILE * restrict stream);
16483 void setbuf(FILE * restrict stream,
16484 char * restrict buf);
16488 int setvbuf(FILE * restrict stream,
16489 char * restrict buf,
16490 int mode, size_t size);
16491 int fprintf(FILE * restrict stream,
16492 const char * restrict format, ...);
16493 int fscanf(FILE * restrict stream,
16494 const char * restrict format, ...);
16495 int printf(const char * restrict format, ...);
16496 int scanf(const char * restrict format, ...);
16497 int snprintf(char * restrict s, size_t n,
16498 const char * restrict format, ...);
16499 int sprintf(char * restrict s,
16500 const char * restrict format, ...);
16501 int sscanf(const char * restrict s,
16502 const char * restrict format, ...);
16503 int vfprintf(FILE * restrict stream,
16504 const char * restrict format, va_list arg);
16505 int vfscanf(FILE * restrict stream,
16506 const char * restrict format, va_list arg);
16507 int vprintf(const char * restrict format, va_list arg);
16508 int vscanf(const char * restrict format, va_list arg);
16509 int vsnprintf(char * restrict s, size_t n,
16510 const char * restrict format, va_list arg);
16511 int vsprintf(char * restrict s,
16512 const char * restrict format, va_list arg);
16513 int vsscanf(const char * restrict s,
16514 const char * restrict format, va_list arg);
16515 int fgetc(FILE *stream);
16516 char *fgets(char * restrict s, int n,
16517 FILE * restrict stream);
16518 int fputc(int c, FILE *stream);
16519 int fputs(const char * restrict s,
16520 FILE * restrict stream);
16521 int getc(FILE *stream);
16523 char *gets(char *s);
16524 int putc(int c, FILE *stream);
16525 int putchar(int c);
16526 int puts(const char *s);
16527 int ungetc(int c, FILE *stream);
16531 size_t fread(void * restrict ptr,
16532 size_t size, size_t nmemb,
16533 FILE * restrict stream);
16534 size_t fwrite(const void * restrict ptr,
16535 size_t size, size_t nmemb,
16536 FILE * restrict stream);
16537 int fgetpos(FILE * restrict stream,
16538 fpos_t * restrict pos);
16539 int fseek(FILE *stream, long int offset, int whence);
16540 int fsetpos(FILE *stream, const fpos_t *pos);
16541 long int ftell(FILE *stream);
16542 void rewind(FILE *stream);
16543 void clearerr(FILE *stream);
16544 int feof(FILE *stream);
16545 int ferror(FILE *stream);
16546 void perror(const char *s);
16547 B.19 General utilities <stdlib.h>
16548 size_t ldiv_t EXIT_FAILURE MB_CUR_MAX
16549 wchar_t lldiv_t EXIT_SUCCESS
16550 div_t NULL RAND_MAX
16551 double atof(const char *nptr);
16552 int atoi(const char *nptr);
16553 long int atol(const char *nptr);
16554 long long int atoll(const char *nptr);
16555 double strtod(const char * restrict nptr,
16556 char ** restrict endptr);
16557 float strtof(const char * restrict nptr,
16558 char ** restrict endptr);
16559 long double strtold(const char * restrict nptr,
16560 char ** restrict endptr);
16561 long int strtol(const char * restrict nptr,
16562 char ** restrict endptr, int base);
16563 long long int strtoll(const char * restrict nptr,
16564 char ** restrict endptr, int base);
16565 unsigned long int strtoul(
16566 const char * restrict nptr,
16567 char ** restrict endptr, int base);
16571 unsigned long long int strtoull(
16572 const char * restrict nptr,
16573 char ** restrict endptr, int base);
16575 void srand(unsigned int seed);
16576 void *calloc(size_t nmemb, size_t size);
16577 void free(void *ptr);
16578 void *malloc(size_t size);
16579 void *realloc(void *ptr, size_t size);
16581 int atexit(void (*func)(void));
16582 void exit(int status);
16583 void _Exit(int status);
16584 char *getenv(const char *name);
16585 int system(const char *string);
16586 void *bsearch(const void *key, const void *base,
16587 size_t nmemb, size_t size,
16588 int (*compar)(const void *, const void *));
16589 void qsort(void *base, size_t nmemb, size_t size,
16590 int (*compar)(const void *, const void *));
16592 long int labs(long int j);
16593 long long int llabs(long long int j);
16594 div_t div(int numer, int denom);
16595 ldiv_t ldiv(long int numer, long int denom);
16596 lldiv_t lldiv(long long int numer,
16597 long long int denom);
16598 int mblen(const char *s, size_t n);
16599 int mbtowc(wchar_t * restrict pwc,
16600 const char * restrict s, size_t n);
16601 int wctomb(char *s, wchar_t wchar);
16602 size_t mbstowcs(wchar_t * restrict pwcs,
16603 const char * restrict s, size_t n);
16604 size_t wcstombs(char * restrict s,
16605 const wchar_t * restrict pwcs, size_t n);
16609 B.20 String handling <string.h>
16612 void *memcpy(void * restrict s1,
16613 const void * restrict s2, size_t n);
16614 void *memmove(void *s1, const void *s2, size_t n);
16615 char *strcpy(char * restrict s1,
16616 const char * restrict s2);
16617 char *strncpy(char * restrict s1,
16618 const char * restrict s2, size_t n);
16619 char *strcat(char * restrict s1,
16620 const char * restrict s2);
16621 char *strncat(char * restrict s1,
16622 const char * restrict s2, size_t n);
16623 int memcmp(const void *s1, const void *s2, size_t n);
16624 int strcmp(const char *s1, const char *s2);
16625 int strcoll(const char *s1, const char *s2);
16626 int strncmp(const char *s1, const char *s2, size_t n);
16627 size_t strxfrm(char * restrict s1,
16628 const char * restrict s2, size_t n);
16629 void *memchr(const void *s, int c, size_t n);
16630 char *strchr(const char *s, int c);
16631 size_t strcspn(const char *s1, const char *s2);
16632 char *strpbrk(const char *s1, const char *s2);
16633 char *strrchr(const char *s, int c);
16634 size_t strspn(const char *s1, const char *s2);
16635 char *strstr(const char *s1, const char *s2);
16636 char *strtok(char * restrict s1,
16637 const char * restrict s2);
16638 void *memset(void *s, int c, size_t n);
16639 char *strerror(int errnum);
16640 size_t strlen(const char *s);
16644 B.21 Type-generic math <tgmath.h>
16645 acos sqrt fmod nextafter
16646 asin fabs frexp nexttoward
16647 atan atan2 hypot remainder
16648 acosh cbrt ilogb remquo
16649 asinh ceil ldexp rint
16650 atanh copysign lgamma round
16651 cos erf llrint scalbn
16652 sin erfc llround scalbln
16653 tan exp2 log10 tgamma
16654 cosh expm1 log1p trunc
16655 sinh fdim log2 carg
16656 tanh floor logb cimag
16658 log fmax lround cproj
16659 pow fmin nearbyint creal
16660 B.22 Date and time <time.h>
16662 CLOCKS_PER_SEC clock_t struct tm
16663 clock_t clock(void);
16664 double difftime(time_t time1, time_t time0);
16665 time_t mktime(struct tm *timeptr);
16666 time_t time(time_t *timer);
16667 char *asctime(const struct tm *timeptr);
16668 char *ctime(const time_t *timer);
16669 struct tm *gmtime(const time_t *timer);
16670 struct tm *localtime(const time_t *timer);
16671 size_t strftime(char * restrict s,
16673 const char * restrict format,
16674 const struct tm * restrict timeptr);
16678 B.23 Extended multibyte/wide character utilities <wchar.h>
16679 wchar_t wint_t WCHAR_MAX
16680 size_t struct tm WCHAR_MIN
16681 mbstate_t NULL WEOF
16682 int fwprintf(FILE * restrict stream,
16683 const wchar_t * restrict format, ...);
16684 int fwscanf(FILE * restrict stream,
16685 const wchar_t * restrict format, ...);
16686 int swprintf(wchar_t * restrict s, size_t n,
16687 const wchar_t * restrict format, ...);
16688 int swscanf(const wchar_t * restrict s,
16689 const wchar_t * restrict format, ...);
16690 int vfwprintf(FILE * restrict stream,
16691 const wchar_t * restrict format, va_list arg);
16692 int vfwscanf(FILE * restrict stream,
16693 const wchar_t * restrict format, va_list arg);
16694 int vswprintf(wchar_t * restrict s, size_t n,
16695 const wchar_t * restrict format, va_list arg);
16696 int vswscanf(const wchar_t * restrict s,
16697 const wchar_t * restrict format, va_list arg);
16698 int vwprintf(const wchar_t * restrict format,
16700 int vwscanf(const wchar_t * restrict format,
16702 int wprintf(const wchar_t * restrict format, ...);
16703 int wscanf(const wchar_t * restrict format, ...);
16704 wint_t fgetwc(FILE *stream);
16705 wchar_t *fgetws(wchar_t * restrict s, int n,
16706 FILE * restrict stream);
16707 wint_t fputwc(wchar_t c, FILE *stream);
16708 int fputws(const wchar_t * restrict s,
16709 FILE * restrict stream);
16710 int fwide(FILE *stream, int mode);
16711 wint_t getwc(FILE *stream);
16712 wint_t getwchar(void);
16713 wint_t putwc(wchar_t c, FILE *stream);
16714 wint_t putwchar(wchar_t c);
16715 wint_t ungetwc(wint_t c, FILE *stream);
16719 double wcstod(const wchar_t * restrict nptr,
16720 wchar_t ** restrict endptr);
16721 float wcstof(const wchar_t * restrict nptr,
16722 wchar_t ** restrict endptr);
16723 long double wcstold(const wchar_t * restrict nptr,
16724 wchar_t ** restrict endptr);
16725 long int wcstol(const wchar_t * restrict nptr,
16726 wchar_t ** restrict endptr, int base);
16727 long long int wcstoll(const wchar_t * restrict nptr,
16728 wchar_t ** restrict endptr, int base);
16729 unsigned long int wcstoul(const wchar_t * restrict nptr,
16730 wchar_t ** restrict endptr, int base);
16731 unsigned long long int wcstoull(
16732 const wchar_t * restrict nptr,
16733 wchar_t ** restrict endptr, int base);
16734 wchar_t *wcscpy(wchar_t * restrict s1,
16735 const wchar_t * restrict s2);
16736 wchar_t *wcsncpy(wchar_t * restrict s1,
16737 const wchar_t * restrict s2, size_t n);
16738 wchar_t *wmemcpy(wchar_t * restrict s1,
16739 const wchar_t * restrict s2, size_t n);
16740 wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2,
16742 wchar_t *wcscat(wchar_t * restrict s1,
16743 const wchar_t * restrict s2);
16744 wchar_t *wcsncat(wchar_t * restrict s1,
16745 const wchar_t * restrict s2, size_t n);
16746 int wcscmp(const wchar_t *s1, const wchar_t *s2);
16747 int wcscoll(const wchar_t *s1, const wchar_t *s2);
16748 int wcsncmp(const wchar_t *s1, const wchar_t *s2,
16750 size_t wcsxfrm(wchar_t * restrict s1,
16751 const wchar_t * restrict s2, size_t n);
16752 int wmemcmp(const wchar_t *s1, const wchar_t *s2,
16754 wchar_t *wcschr(const wchar_t *s, wchar_t c);
16755 size_t wcscspn(const wchar_t *s1, const wchar_t *s2);
16756 wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2); *
16757 wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
16758 size_t wcsspn(const wchar_t *s1, const wchar_t *s2);
16759 wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);
16763 wchar_t *wcstok(wchar_t * restrict s1,
16764 const wchar_t * restrict s2,
16765 wchar_t ** restrict ptr);
16766 wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n);
16767 size_t wcslen(const wchar_t *s);
16768 wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);
16769 size_t wcsftime(wchar_t * restrict s, size_t maxsize,
16770 const wchar_t * restrict format,
16771 const struct tm * restrict timeptr);
16772 wint_t btowc(int c);
16773 int wctob(wint_t c);
16774 int mbsinit(const mbstate_t *ps);
16775 size_t mbrlen(const char * restrict s, size_t n,
16776 mbstate_t * restrict ps);
16777 size_t mbrtowc(wchar_t * restrict pwc,
16778 const char * restrict s, size_t n,
16779 mbstate_t * restrict ps);
16780 size_t wcrtomb(char * restrict s, wchar_t wc,
16781 mbstate_t * restrict ps);
16782 size_t mbsrtowcs(wchar_t * restrict dst,
16783 const char ** restrict src, size_t len,
16784 mbstate_t * restrict ps);
16785 size_t wcsrtombs(char * restrict dst,
16786 const wchar_t ** restrict src, size_t len,
16787 mbstate_t * restrict ps);
16788 B.24 Wide character classification and mapping utilities <wctype.h>
16789 wint_t wctrans_t wctype_t WEOF
16790 int iswalnum(wint_t wc);
16791 int iswalpha(wint_t wc);
16792 int iswblank(wint_t wc);
16793 int iswcntrl(wint_t wc);
16794 int iswdigit(wint_t wc);
16795 int iswgraph(wint_t wc);
16796 int iswlower(wint_t wc);
16797 int iswprint(wint_t wc);
16798 int iswpunct(wint_t wc);
16799 int iswspace(wint_t wc);
16800 int iswupper(wint_t wc);
16801 int iswxdigit(wint_t wc);
16802 int iswctype(wint_t wc, wctype_t desc);
16806 wctype_t wctype(const char *property);
16807 wint_t towlower(wint_t wc);
16808 wint_t towupper(wint_t wc);
16809 wint_t towctrans(wint_t wc, wctrans_t desc);
16810 wctrans_t wctrans(const char *property);
16817 1 The following are the sequence points described in 5.1.2.3:
16818 -- The call to a function, after the arguments have been evaluated (6.5.2.2).
16819 -- The end of the first operand of the following operators: logical AND && (6.5.13);
16820 logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17).
16821 -- The end of a full declarator: declarators (6.7.5);
16822 -- The end of a full expression: an initializer (6.7.8); the expression in an expression
16823 statement (6.8.3); the controlling expression of a selection statement (if or switch)
16824 (6.8.4); the controlling expression of a while or do statement (6.8.5); each of the
16825 expressions of a for statement (6.8.5.3); the expression in a return statement
16827 -- Immediately before a library function returns (7.1.4).
16828 -- After the actions associated with each formatted input/output function conversion
16829 specifier (7.19.6, 7.24.2).
16830 -- Immediately before and immediately after each call to a comparison function, and
16831 also between any call to a comparison function and any movement of the objects
16832 passed as arguments to that call (7.20.5).
16838 Universal character names for identifiers
16839 1 This clause lists the hexadecimal code values that are valid in universal character names
16841 2 This table is reproduced unchanged from ISO/IEC TR 10176:1998, produced by ISO/IEC
16842 JTC 1/SC 22/WG 20, except for the omission of ranges that are part of the basic character
16844 Latin: 00AA, 00BA, 00C0-00D6, 00D8-00F6, 00F8-01F5, 01FA-0217,
16845 0250-02A8, 1E00-1E9B, 1EA0-1EF9, 207F
16846 Greek: 0386, 0388-038A, 038C, 038E-03A1, 03A3-03CE, 03D0-03D6,
16847 03DA, 03DC, 03DE, 03E0, 03E2-03F3, 1F00-1F15, 1F18-1F1D,
16848 1F20-1F45, 1F48-1F4D, 1F50-1F57, 1F59, 1F5B, 1F5D,
16849 1F5F-1F7D, 1F80-1FB4, 1FB6-1FBC, 1FC2-1FC4, 1FC6-1FCC,
16850 1FD0-1FD3, 1FD6-1FDB, 1FE0-1FEC, 1FF2-1FF4, 1FF6-1FFC
16851 Cyrillic: 0401-040C, 040E-044F, 0451-045C, 045E-0481, 0490-04C4,
16852 04C7-04C8, 04CB-04CC, 04D0-04EB, 04EE-04F5, 04F8-04F9
16853 Armenian: 0531-0556, 0561-0587
16854 Hebrew: 05B0-05B9, 05BB-05BD, 05BF, 05C1-05C2, 05D0-05EA,
16856 Arabic: 0621-063A, 0640-0652, 0670-06B7, 06BA-06BE, 06C0-06CE,
16857 06D0-06DC, 06E5-06E8, 06EA-06ED
16858 Devanagari: 0901-0903, 0905-0939, 093E-094D, 0950-0952, 0958-0963
16859 Bengali: 0981-0983, 0985-098C, 098F-0990, 0993-09A8, 09AA-09B0,
16860 09B2, 09B6-09B9, 09BE-09C4, 09C7-09C8, 09CB-09CD,
16861 09DC-09DD, 09DF-09E3, 09F0-09F1
16862 Gurmukhi: 0A02, 0A05-0A0A, 0A0F-0A10, 0A13-0A28, 0A2A-0A30,
16863 0A32-0A33, 0A35-0A36, 0A38-0A39, 0A3E-0A42, 0A47-0A48,
16864 0A4B-0A4D, 0A59-0A5C, 0A5E, 0A74
16865 Gujarati: 0A81-0A83, 0A85-0A8B, 0A8D, 0A8F-0A91, 0A93-0AA8,
16866 0AAA-0AB0, 0AB2-0AB3, 0AB5-0AB9, 0ABD-0AC5,
16867 0AC7-0AC9, 0ACB-0ACD, 0AD0, 0AE0
16868 Oriya: 0B01-0B03, 0B05-0B0C, 0B0F-0B10, 0B13-0B28, 0B2A-0B30,
16869 0B32-0B33, 0B36-0B39, 0B3E-0B43, 0B47-0B48, 0B4B-0B4D,
16873 0B5C-0B5D, 0B5F-0B61
16874 Tamil: 0B82-0B83, 0B85-0B8A, 0B8E-0B90, 0B92-0B95, 0B99-0B9A,
16875 0B9C, 0B9E-0B9F, 0BA3-0BA4, 0BA8-0BAA, 0BAE-0BB5,
16876 0BB7-0BB9, 0BBE-0BC2, 0BC6-0BC8, 0BCA-0BCD
16877 Telugu: 0C01-0C03, 0C05-0C0C, 0C0E-0C10, 0C12-0C28, 0C2A-0C33,
16878 0C35-0C39, 0C3E-0C44, 0C46-0C48, 0C4A-0C4D, 0C60-0C61
16879 Kannada: 0C82-0C83, 0C85-0C8C, 0C8E-0C90, 0C92-0CA8, 0CAA-0CB3,
16880 0CB5-0CB9, 0CBE-0CC4, 0CC6-0CC8, 0CCA-0CCD, 0CDE,
16882 Malayalam: 0D02-0D03, 0D05-0D0C, 0D0E-0D10, 0D12-0D28, 0D2A-0D39,
16883 0D3E-0D43, 0D46-0D48, 0D4A-0D4D, 0D60-0D61
16884 Thai: 0E01-0E3A, 0E40-0E5B
16885 Lao: 0E81-0E82, 0E84, 0E87-0E88, 0E8A, 0E8D, 0E94-0E97,
16886 0E99-0E9F, 0EA1-0EA3, 0EA5, 0EA7, 0EAA-0EAB,
16887 0EAD-0EAE, 0EB0-0EB9, 0EBB-0EBD, 0EC0-0EC4, 0EC6,
16888 0EC8-0ECD, 0EDC-0EDD
16889 Tibetan: 0F00, 0F18-0F19, 0F35, 0F37, 0F39, 0F3E-0F47, 0F49-0F69,
16890 0F71-0F84, 0F86-0F8B, 0F90-0F95, 0F97, 0F99-0FAD,
16892 Georgian: 10A0-10C5, 10D0-10F6
16893 Hiragana: 3041-3093, 309B-309C
16894 Katakana: 30A1-30F6, 30FB-30FC
16895 Bopomofo: 3105-312C
16896 CJK Unified Ideographs: 4E00-9FA5
16898 Digits: 0660-0669, 06F0-06F9, 0966-096F, 09E6-09EF, 0A66-0A6F,
16899 0AE6-0AEF, 0B66-0B6F, 0BE7-0BEF, 0C66-0C6F, 0CE6-0CEF,
16900 0D66-0D6F, 0E50-0E59, 0ED0-0ED9, 0F20-0F33
16901 Special characters: 00B5, 00B7, 02B0-02B8, 02BB, 02BD-02C1, 02D0-02D1,
16902 02E0-02E4, 037A, 0559, 093D, 0B3D, 1FBE, 203F-2040, 2102,
16903 2107, 210A-2113, 2115, 2118-211D, 2124, 2126, 2128, 212A-2131,
16904 2133-2138, 2160-2182, 3005-3007, 3021-3029
16910 Implementation limits
16911 1 The contents of the header <limits.h> are given below, in alphabetical order. The
16912 minimum magnitudes shown shall be replaced by implementation-defined magnitudes
16913 with the same sign. The values shall all be constant expressions suitable for use in #if
16914 preprocessing directives. The components are described further in 5.2.4.2.1.
16916 #define CHAR_MAX UCHAR_MAX or SCHAR_MAX
16917 #define CHAR_MIN 0 or SCHAR_MIN
16918 #define INT_MAX +32767
16919 #define INT_MIN -32767
16920 #define LONG_MAX +2147483647
16921 #define LONG_MIN -2147483647
16922 #define LLONG_MAX +9223372036854775807
16923 #define LLONG_MIN -9223372036854775807
16924 #define MB_LEN_MAX 1
16925 #define SCHAR_MAX +127
16926 #define SCHAR_MIN -127
16927 #define SHRT_MAX +32767
16928 #define SHRT_MIN -32767
16929 #define UCHAR_MAX 255
16930 #define USHRT_MAX 65535
16931 #define UINT_MAX 65535
16932 #define ULONG_MAX 4294967295
16933 #define ULLONG_MAX 18446744073709551615
16934 2 The contents of the header <float.h> are given below. All integer values, except
16935 FLT_ROUNDS, shall be constant expressions suitable for use in #if preprocessing
16936 directives; all floating values shall be constant expressions. The components are
16937 described further in 5.2.4.2.2.
16938 3 The values given in the following list shall be replaced by implementation-defined
16940 #define FLT_EVAL_METHOD
16942 4 The values given in the following list shall be replaced by implementation-defined
16943 constant expressions that are greater or equal in magnitude (absolute value) to those
16944 shown, with the same sign:
16949 #define DBL_MANT_DIG
16950 #define DBL_MAX_10_EXP +37
16951 #define DBL_MAX_EXP
16952 #define DBL_MIN_10_EXP -37
16953 #define DBL_MIN_EXP
16954 #define DECIMAL_DIG 10
16956 #define FLT_MANT_DIG
16957 #define FLT_MAX_10_EXP +37
16958 #define FLT_MAX_EXP
16959 #define FLT_MIN_10_EXP -37
16960 #define FLT_MIN_EXP
16961 #define FLT_RADIX 2
16962 #define LDBL_DIG 10
16963 #define LDBL_MANT_DIG
16964 #define LDBL_MAX_10_EXP +37
16965 #define LDBL_MAX_EXP
16966 #define LDBL_MIN_10_EXP -37
16967 #define LDBL_MIN_EXP
16968 5 The values given in the following list shall be replaced by implementation-defined
16969 constant expressions with values that are greater than or equal to those shown:
16970 #define DBL_MAX 1E+37
16971 #define FLT_MAX 1E+37
16972 #define LDBL_MAX 1E+37
16973 6 The values given in the following list shall be replaced by implementation-defined
16974 constant expressions with (positive) values that are less than or equal to those shown:
16975 #define DBL_EPSILON 1E-9
16976 #define DBL_MIN 1E-37
16977 #define FLT_EPSILON 1E-5
16978 #define FLT_MIN 1E-37
16979 #define LDBL_EPSILON 1E-9
16980 #define LDBL_MIN 1E-37
16986 IEC 60559 floating-point arithmetic
16988 1 This annex specifies C language support for the IEC 60559 floating-point standard. The
16989 IEC 60559 floating-point standard is specifically Binary floating-point arithmetic for
16990 microprocessor systems, second edition (IEC 60559:1989), previously designated
16991 IEC 559:1989 and as IEEE Standard for Binary Floating-Point Arithmetic
16992 (ANSI/IEEE 754-1985). IEEE Standard for Radix-Independent Floating-Point
16993 Arithmetic (ANSI/IEEE 854-1987) generalizes the binary standard to remove
16994 dependencies on radix and word length. IEC 60559 generally refers to the floating-point
16995 standard, as in IEC 60559 operation, IEC 60559 format, etc. An implementation that
16996 defines __STDC_IEC_559__ shall conform to the specifications in this annex. Where
16997 a binding between the C language and IEC 60559 is indicated, the IEC 60559-specified
16998 behavior is adopted by reference, unless stated otherwise.
17000 1 The C floating types match the IEC 60559 formats as follows:
17001 -- The float type matches the IEC 60559 single format.
17002 -- The double type matches the IEC 60559 double format.
17003 -- The long double type matches an IEC 60559 extended format,307) else a
17004 non-IEC 60559 extended format, else the IEC 60559 double format.
17005 Any non-IEC 60559 extended format used for the long double type shall have more
17006 precision than IEC 60559 double and at least the range of IEC 60559 double.308)
17007 Recommended practice
17008 2 The long double type should match an IEC 60559 extended format.
17013 307) ''Extended'' is IEC 60559's double-extended data format. Extended refers to both the common 80-bit
17014 and quadruple 128-bit IEC 60559 formats.
17015 308) A non-IEC 60559 long double type is required to provide infinity and NaNs, as its values include
17020 F.2.1 Infinities, signed zeros, and NaNs
17021 1 This specification does not define the behavior of signaling NaNs.309) It generally uses
17022 the term NaN to denote quiet NaNs. The NAN and INFINITY macros and the nan
17023 functions in <math.h> provide designations for IEC 60559 NaNs and infinities.
17024 F.3 Operators and functions
17025 1 C operators and functions provide IEC 60559 required and recommended facilities as
17027 -- The +, -, *, and / operators provide the IEC 60559 add, subtract, multiply, and
17029 -- The sqrt functions in <math.h> provide the IEC 60559 square root operation.
17030 -- The remainder functions in <math.h> provide the IEC 60559 remainder
17031 operation. The remquo functions in <math.h> provide the same operation but
17032 with additional information.
17033 -- The rint functions in <math.h> provide the IEC 60559 operation that rounds a
17034 floating-point number to an integer value (in the same precision). The nearbyint
17035 functions in <math.h> provide the nearbyinteger function recommended in the
17036 Appendix to ANSI/IEEE 854.
17037 -- The conversions for floating types provide the IEC 60559 conversions between
17038 floating-point precisions.
17039 -- The conversions from integer to floating types provide the IEC 60559 conversions
17040 from integer to floating point.
17041 -- The conversions from floating to integer types provide IEC 60559-like conversions
17042 but always round toward zero.
17043 -- The lrint and llrint functions in <math.h> provide the IEC 60559
17044 conversions, which honor the directed rounding mode, from floating point to the
17045 long int and long long int integer formats. The lrint and llrint
17046 functions can be used to implement IEC 60559 conversions from floating to other
17048 -- The translation time conversion of floating constants and the strtod, strtof,
17049 strtold, fprintf, fscanf, and related library functions in <stdlib.h>,
17050 <stdio.h>, and <wchar.h> provide IEC 60559 binary-decimal conversions. The
17051 strtold function in <stdlib.h> provides the conv function recommended in the
17052 Appendix to ANSI/IEEE 854.
17054 309) Since NaNs created by IEC 60559 operations are always quiet, quiet NaNs (along with infinities) are
17055 sufficient for closure of the arithmetic.
17059 -- The relational and equality operators provide IEC 60559 comparisons. IEC 60559
17060 identifies a need for additional comparison predicates to facilitate writing code that
17061 accounts for NaNs. The comparison macros (isgreater, isgreaterequal,
17062 isless, islessequal, islessgreater, and isunordered) in <math.h>
17063 supplement the language operators to address this need. The islessgreater and
17064 isunordered macros provide respectively a quiet version of the <> predicate and
17065 the unordered predicate recommended in the Appendix to IEC 60559.
17066 -- The feclearexcept, feraiseexcept, and fetestexcept functions in
17067 <fenv.h> provide the facility to test and alter the IEC 60559 floating-point
17068 exception status flags. The fegetexceptflag and fesetexceptflag
17069 functions in <fenv.h> provide the facility to save and restore all five status flags at
17070 one time. These functions are used in conjunction with the type fexcept_t and the
17071 floating-point exception macros (FE_INEXACT, FE_DIVBYZERO,
17072 FE_UNDERFLOW, FE_OVERFLOW, FE_INVALID) also in <fenv.h>.
17073 -- The fegetround and fesetround functions in <fenv.h> provide the facility
17074 to select among the IEC 60559 directed rounding modes represented by the rounding
17075 direction macros in <fenv.h> (FE_TONEAREST, FE_UPWARD, FE_DOWNWARD,
17076 FE_TOWARDZERO) and the values 0, 1, 2, and 3 of FLT_ROUNDS are the
17077 IEC 60559 directed rounding modes.
17078 -- The fegetenv, feholdexcept, fesetenv, and feupdateenv functions in
17079 <fenv.h> provide a facility to manage the floating-point environment, comprising
17080 the IEC 60559 status flags and control modes.
17081 -- The copysign functions in <math.h> provide the copysign function
17082 recommended in the Appendix to IEC 60559.
17083 -- The unary minus (-) operator provides the minus (-) operation recommended in the
17084 Appendix to IEC 60559.
17085 -- The scalbn and scalbln functions in <math.h> provide the scalb function
17086 recommended in the Appendix to IEC 60559.
17087 -- The logb functions in <math.h> provide the logb function recommended in the
17088 Appendix to IEC 60559, but following the newer specifications in ANSI/IEEE 854.
17089 -- The nextafter and nexttoward functions in <math.h> provide the nextafter
17090 function recommended in the Appendix to IEC 60559 (but with a minor change to
17091 better handle signed zeros).
17092 -- The isfinite macro in <math.h> provides the finite function recommended in
17093 the Appendix to IEC 60559.
17094 -- The isnan macro in <math.h> provides the isnan function recommended in the
17095 Appendix to IEC 60559.
17099 -- The signbit macro and the fpclassify macro in <math.h>, used in
17100 conjunction with the number classification macros (FP_NAN, FP_INFINITE,
17101 FP_NORMAL, FP_SUBNORMAL, FP_ZERO), provide the facility of the class
17102 function recommended in the Appendix to IEC 60559 (except that the classification
17103 macros defined in 7.12.3 do not distinguish signaling from quiet NaNs).
17104 F.4 Floating to integer conversion
17105 1 If the floating value is infinite or NaN or if the integral part of the floating value exceeds
17106 the range of the integer type, then the ''invalid'' floating-point exception is raised and the
17107 resulting value is unspecified. Whether conversion of non-integer floating values whose
17108 integral part is within the range of the integer type raises the ''inexact'' floating-point
17109 exception is unspecified.310)
17110 F.5 Binary-decimal conversion
17111 1 Conversion from the widest supported IEC 60559 format to decimal with
17112 DECIMAL_DIG digits and back is the identity function.311)
17113 2 Conversions involving IEC 60559 formats follow all pertinent recommended practice. In
17114 particular, conversion between any supported IEC 60559 format and decimal with
17115 DECIMAL_DIG or fewer significant digits is correctly rounded (honoring the current
17116 rounding mode), which assures that conversion from the widest supported IEC 60559
17117 format to decimal with DECIMAL_DIG digits and back is the identity function.
17118 3 Functions such as strtod that convert character sequences to floating types honor the
17119 rounding direction. Hence, if the rounding direction might be upward or downward, the
17120 implementation cannot convert a minus-signed sequence by negating the converted
17126 310) ANSI/IEEE 854, but not IEC 60559 (ANSI/IEEE 754), directly specifies that floating-to-integer
17127 conversions raise the ''inexact'' floating-point exception for non-integer in-range values. In those
17128 cases where it matters, library functions can be used to effect such conversions with or without raising
17129 the ''inexact'' floating-point exception. See rint, lrint, llrint, and nearbyint in
17131 311) If the minimum-width IEC 60559 extended format (64 bits of precision) is supported,
17132 DECIMAL_DIG shall be at least 21. If IEC 60559 double (53 bits of precision) is the widest
17133 IEC 60559 format supported, then DECIMAL_DIG shall be at least 17. (By contrast, LDBL_DIG and
17134 DBL_DIG are 18 and 15, respectively, for these formats.)
17138 F.6 Contracted expressions
17139 1 A contracted expression treats infinities, NaNs, signed zeros, subnormals, and the
17140 rounding directions in a manner consistent with the basic arithmetic operations covered
17142 Recommended practice
17143 2 A contracted expression should raise floating-point exceptions in a manner generally
17144 consistent with the basic arithmetic operations. A contracted expression should deliver
17145 the same value as its uncontracted counterpart, else should be correctly rounded (once).
17146 F.7 Floating-point environment
17147 1 The floating-point environment defined in <fenv.h> includes the IEC 60559 floating-
17148 point exception status flags and directed-rounding control modes. It includes also
17149 IEC 60559 dynamic rounding precision and trap enablement modes, if the
17150 implementation supports them.312)
17151 F.7.1 Environment management
17152 1 IEC 60559 requires that floating-point operations implicitly raise floating-point exception
17153 status flags, and that rounding control modes can be set explicitly to affect result values of
17154 floating-point operations. When the state for the FENV_ACCESS pragma (defined in
17155 <fenv.h>) is ''on'', these changes to the floating-point state are treated as side effects
17156 which respect sequence points.313)
17158 1 During translation the IEC 60559 default modes are in effect:
17159 -- The rounding direction mode is rounding to nearest.
17160 -- The rounding precision mode (if supported) is set so that results are not shortened.
17161 -- Trapping or stopping (if supported) is disabled on all floating-point exceptions.
17162 Recommended practice
17163 2 The implementation should produce a diagnostic message for each translation-time
17168 312) This specification does not require dynamic rounding precision nor trap enablement modes.
17169 313) If the state for the FENV_ACCESS pragma is ''off'', the implementation is free to assume the floating-
17170 point control modes will be the default ones and the floating-point status flags will not be tested,
17171 which allows certain optimizations (see F.8).
17175 floating-point exception, other than ''inexact'';314) the implementation should then
17176 proceed with the translation of the program.
17178 1 At program startup the floating-point environment is initialized as prescribed by
17180 -- All floating-point exception status flags are cleared.
17181 -- The rounding direction mode is rounding to nearest.
17182 -- The dynamic rounding precision mode (if supported) is set so that results are not
17184 -- Trapping or stopping (if supported) is disabled on all floating-point exceptions.
17185 F.7.4 Constant expressions
17186 1 An arithmetic constant expression of floating type, other than one in an initializer for an
17187 object that has static storage duration, is evaluated (as if) during execution; thus, it is
17188 affected by any operative floating-point control modes and raises floating-point
17189 exceptions as required by IEC 60559 (provided the state for the FENV_ACCESS pragma
17193 #pragma STDC FENV_ACCESS ON
17196 float w[] = { 0.0/0.0 }; // raises an exception
17197 static float x = 0.0/0.0; // does not raise an exception
17198 float y = 0.0/0.0; // raises an exception
17199 double z = 0.0/0.0; // raises an exception
17202 3 For the static initialization, the division is done at translation time, raising no (execution-time) floating-
17203 point exceptions. On the other hand, for the three automatic initializations the invalid division occurs at
17206 314) As floating constants are converted to appropriate internal representations at translation time, their
17207 conversion is subject to default rounding modes and raises no execution-time floating-point exceptions
17208 (even where the state of the FENV_ACCESS pragma is ''on''). Library functions, for example
17209 strtod, provide execution-time conversion of numeric strings.
17210 315) Where the state for the FENV_ACCESS pragma is ''on'', results of inexact expressions like 1.0/3.0
17211 are affected by rounding modes set at execution time, and expressions such as 0.0/0.0 and
17212 1.0/0.0 generate execution-time floating-point exceptions. The programmer can achieve the
17213 efficiency of translation-time evaluation through static initialization, such as
17214 const static double one_third = 1.0/3.0;
17220 F.7.5 Initialization
17221 1 All computation for automatic initialization is done (as if) at execution time; thus, it is
17222 affected by any operative modes and raises floating-point exceptions as required by
17223 IEC 60559 (provided the state for the FENV_ACCESS pragma is ''on''). All computation
17224 for initialization of objects that have static storage duration is done (as if) at translation
17228 #pragma STDC FENV_ACCESS ON
17231 float u[] = { 1.1e75 }; // raises exceptions
17232 static float v = 1.1e75; // does not raise exceptions
17233 float w = 1.1e75; // raises exceptions
17234 double x = 1.1e75; // may raise exceptions
17235 float y = 1.1e75f; // may raise exceptions
17236 long double z = 1.1e75; // does not raise exceptions
17239 3 The static initialization of v raises no (execution-time) floating-point exceptions because its computation is
17240 done at translation time. The automatic initialization of u and w require an execution-time conversion to
17241 float of the wider value 1.1e75, which raises floating-point exceptions. The automatic initializations
17242 of x and y entail execution-time conversion; however, in some expression evaluation methods, the
17243 conversions is not to a narrower format, in which case no floating-point exception is raised.316) The
17244 automatic initialization of z entails execution-time conversion, but not to a narrower format, so no floating-
17245 point exception is raised. Note that the conversions of the floating constants 1.1e75 and 1.1e75f to
17246 their internal representations occur at translation time in all cases.
17251 316) Use of float_t and double_t variables increases the likelihood of translation-time computation.
17252 For example, the automatic initialization
17253 double_t x = 1.1e75;
17254 could be done at translation time, regardless of the expression evaluation method.
17258 F.7.6 Changing the environment
17259 1 Operations defined in 6.5 and functions and macros defined for the standard libraries
17260 change floating-point status flags and control modes just as indicated by their
17261 specifications (including conformance to IEC 60559). They do not change flags or modes
17262 (so as to be detectable by the user) in any other cases.
17263 2 If the argument to the feraiseexcept function in <fenv.h> represents IEC 60559
17264 valid coincident floating-point exceptions for atomic operations (namely ''overflow'' and
17265 ''inexact'', or ''underflow'' and ''inexact''), then ''overflow'' or ''underflow'' is raised
17266 before ''inexact''.
17268 1 This section identifies code transformations that might subvert IEC 60559-specified
17269 behavior, and others that do not.
17270 F.8.1 Global transformations
17271 1 Floating-point arithmetic operations and external function calls may entail side effects
17272 which optimization shall honor, at least where the state of the FENV_ACCESS pragma is
17273 ''on''. The flags and modes in the floating-point environment may be regarded as global
17274 variables; floating-point operations (+, *, etc.) implicitly read the modes and write the
17276 2 Concern about side effects may inhibit code motion and removal of seemingly useless
17277 code. For example, in
17279 #pragma STDC FENV_ACCESS ON
17283 for (i = 0; i < n; i++) x + 1;
17286 x + 1 might raise floating-point exceptions, so cannot be removed. And since the loop
17287 body might not execute (maybe 0 >= n), x + 1 cannot be moved out of the loop. (Of
17288 course these optimizations are valid if the implementation can rule out the nettlesome
17290 3 This specification does not require support for trap handlers that maintain information
17291 about the order or count of floating-point exceptions. Therefore, between function calls,
17292 floating-point exceptions need not be precise: the actual order and number of occurrences
17293 of floating-point exceptions (> 1) may vary from what the source code expresses. Thus,
17294 the preceding loop could be treated as
17299 F.8.2 Expression transformations
17300 1 x / 2 <-> x * 0.5 Although similar transformations involving inexact
17301 constants generally do not yield numerically equivalent
17302 expressions, if the constants are exact then such
17303 transformations can be made on IEC 60559 machines
17304 and others that round perfectly.
17305 1 * x and x / 1 -> x The expressions 1 * x, x / 1, and x are equivalent
17306 (on IEC 60559 machines, among others).317)
17307 x / x -> 1.0 The expressions x / x and 1.0 are not equivalent if x
17308 can be zero, infinite, or NaN.
17309 x - y <-> x + (-y) The expressions x - y, x + (-y), and (-y) + x
17310 are equivalent (on IEC 60559 machines, among others).
17311 x - y <-> -(y - x) The expressions x - y and -(y - x) are not
17312 equivalent because 1 - 1 is +0 but -(1 - 1) is -0 (in the
17313 default rounding direction).318)
17314 x - x -> 0.0 The expressions x - x and 0.0 are not equivalent if
17315 x is a NaN or infinite.
17316 0 * x -> 0.0 The expressions 0 * x and 0.0 are not equivalent if
17317 x is a NaN, infinite, or -0.
17318 x + 0->x The expressions x + 0 and x are not equivalent if x is
17319 -0, because (-0) + (+0) yields +0 (in the default
17320 rounding direction), not -0.
17321 x - 0->x (+0) - (+0) yields -0 when rounding is downward
17322 (toward -(inf)), but +0 otherwise, and (-0) - (+0) always
17323 yields -0; so, if the state of the FENV_ACCESS pragma
17324 is ''off'', promising default rounding, then the
17325 implementation can replace x - 0 by x, even if x
17328 317) Strict support for signaling NaNs -- not required by this specification -- would invalidate these and
17329 other transformations that remove arithmetic operators.
17330 318) IEC 60559 prescribes a signed zero to preserve mathematical identities across certain discontinuities.
17332 1/(1/ (+-) (inf)) is (+-) (inf)
17334 conj(csqrt(z)) is csqrt(conj(z)),
17340 -x <-> 0 - x The expressions -x and 0 - x are not equivalent if x
17341 is +0, because -(+0) yields -0, but 0 - (+0) yields +0
17342 (unless rounding is downward).
17343 F.8.3 Relational operators
17344 1 x != x -> false The statement x != x is true if x is a NaN.
17345 x == x -> true The statement x == x is false if x is a NaN.
17346 x < y -> isless(x,y) (and similarly for <=, >, >=) Though numerically
17347 equal, these expressions are not equivalent because of
17348 side effects when x or y is a NaN and the state of the
17349 FENV_ACCESS pragma is ''on''. This transformation,
17350 which would be desirable if extra code were required to
17351 cause the ''invalid'' floating-point exception for
17352 unordered cases, could be performed provided the state
17353 of the FENV_ACCESS pragma is ''off''.
17354 The sense of relational operators shall be maintained. This includes handling unordered
17355 cases as expressed by the source code.
17357 // calls g and raises ''invalid'' if a and b are unordered
17362 is not equivalent to
17363 // calls f and raises ''invalid'' if a and b are unordered
17369 // calls f without raising ''invalid'' if a and b are unordered
17370 if (isgreaterequal(a,b))
17374 nor, unless the state of the FENV_ACCESS pragma is ''off'', to
17378 // calls g without raising ''invalid'' if a and b are unordered
17383 but is equivalent to
17389 F.8.4 Constant arithmetic
17390 1 The implementation shall honor floating-point exceptions raised by execution-time
17391 constant arithmetic wherever the state of the FENV_ACCESS pragma is ''on''. (See F.7.4
17392 and F.7.5.) An operation on constants that raises no floating-point exception can be
17393 folded during translation, except, if the state of the FENV_ACCESS pragma is ''on'', a
17394 further check is required to assure that changing the rounding direction to downward does
17395 not alter the sign of the result,319) and implementations that support dynamic rounding
17396 precision modes shall assure further that the result of the operation raises no floating-
17397 point exception when converted to the semantic type of the operation.
17398 F.9 Mathematics <math.h>
17399 1 This subclause contains specifications of <math.h> facilities that are particularly suited
17400 for IEC 60559 implementations.
17401 2 The Standard C macro HUGE_VAL and its float and long double analogs,
17402 HUGE_VALF and HUGE_VALL, expand to expressions whose values are positive
17404 3 Special cases for functions in <math.h> are covered directly or indirectly by
17405 IEC 60559. The functions that IEC 60559 specifies directly are identified in F.3. The
17406 other functions in <math.h> treat infinities, NaNs, signed zeros, subnormals, and
17407 (provided the state of the FENV_ACCESS pragma is ''on'') the floating-point status flags
17408 in a manner consistent with the basic arithmetic operations covered by IEC 60559.
17409 4 The expression math_errhandling & MATH_ERREXCEPT shall evaluate to a
17411 5 The ''invalid'' and ''divide-by-zero'' floating-point exceptions are raised as specified in
17412 subsequent subclauses of this annex.
17413 6 The ''overflow'' floating-point exception is raised whenever an infinity -- or, because of
17414 rounding direction, a maximal-magnitude finite number -- is returned in lieu of a value
17417 319) 0 - 0 yields -0 instead of +0 just when the rounding direction is downward.
17421 whose magnitude is too large.
17422 7 The ''underflow'' floating-point exception is raised whenever a result is tiny (essentially
17423 subnormal or zero) and suffers loss of accuracy.320)
17424 8 Whether or when library functions raise the ''inexact'' floating-point exception is
17425 unspecified, unless explicitly specified otherwise.
17426 9 Whether or when library functions raise an undeserved ''underflow'' floating-point
17427 exception is unspecified.321) Otherwise, as implied by F.7.6, the <math.h> functions do
17428 not raise spurious floating-point exceptions (detectable by the user), other than the
17429 ''inexact'' floating-point exception.
17430 10 Whether the functions honor the rounding direction mode is implementation-defined,
17431 unless explicitly specified otherwise.
17432 11 Functions with a NaN argument return a NaN result and raise no floating-point exception,
17433 except where stated otherwise.
17434 12 The specifications in the following subclauses append to the definitions in <math.h>.
17435 For families of functions, the specifications apply to all of the functions even though only
17436 the principal function is shown. Unless otherwise specified, where the symbol ''(+-)''
17437 occurs in both an argument and the result, the result has the same sign as the argument.
17438 Recommended practice
17439 13 If a function with one or more NaN arguments returns a NaN result, the result should be
17440 the same as one of the NaN arguments (after possible type conversion), except perhaps
17442 F.9.1 Trigonometric functions
17443 F.9.1.1 The acos functions
17444 1 -- acos(1) returns +0.
17445 -- acos(x) returns a NaN and raises the ''invalid'' floating-point exception for
17451 320) IEC 60559 allows different definitions of underflow. They all result in the same values, but differ on
17452 when the floating-point exception is raised.
17453 321) It is intended that undeserved ''underflow'' and ''inexact'' floating-point exceptions are raised only if
17454 avoiding them would be too costly.
17458 F.9.1.2 The asin functions
17459 1 -- asin((+-)0) returns (+-)0.
17460 -- asin(x) returns a NaN and raises the ''invalid'' floating-point exception for
17462 F.9.1.3 The atan functions
17463 1 -- atan((+-)0) returns (+-)0.
17464 -- atan((+-)(inf)) returns (+-)pi /2.
17465 F.9.1.4 The atan2 functions
17466 1 -- atan2((+-)0, -0) returns (+-)pi .322)
17467 -- atan2((+-)0, +0) returns (+-)0.
17468 -- atan2((+-)0, x) returns (+-)pi for x < 0.
17469 -- atan2((+-)0, x) returns (+-)0 for x > 0.
17470 -- atan2(y, (+-)0) returns -pi /2 for y < 0.
17471 -- atan2(y, (+-)0) returns pi /2 for y > 0.
17472 -- atan2((+-)y, -(inf)) returns (+-)pi for finite y > 0.
17473 -- atan2((+-)y, +(inf)) returns (+-)0 for finite y > 0.
17474 -- atan2((+-)(inf), x) returns (+-)pi /2 for finite x.
17475 -- atan2((+-)(inf), -(inf)) returns (+-)3pi /4.
17476 -- atan2((+-)(inf), +(inf)) returns (+-)pi /4.
17477 F.9.1.5 The cos functions
17478 1 -- cos((+-)0) returns 1.
17479 -- cos((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
17480 F.9.1.6 The sin functions
17481 1 -- sin((+-)0) returns (+-)0.
17482 -- sin((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
17487 322) atan2(0, 0) does not raise the ''invalid'' floating-point exception, nor does atan2( y , 0) raise
17488 the ''divide-by-zero'' floating-point exception.
17492 F.9.1.7 The tan functions
17493 1 -- tan((+-)0) returns (+-)0.
17494 -- tan((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
17495 F.9.2 Hyperbolic functions
17496 F.9.2.1 The acosh functions
17497 1 -- acosh(1) returns +0.
17498 -- acosh(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 1.
17499 -- acosh(+(inf)) returns +(inf).
17500 F.9.2.2 The asinh functions
17501 1 -- asinh((+-)0) returns (+-)0.
17502 -- asinh((+-)(inf)) returns (+-)(inf).
17503 F.9.2.3 The atanh functions
17504 1 -- atanh((+-)0) returns (+-)0.
17505 -- atanh((+-)1) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception.
17506 -- atanh(x) returns a NaN and raises the ''invalid'' floating-point exception for
17508 F.9.2.4 The cosh functions
17509 1 -- cosh((+-)0) returns 1.
17510 -- cosh((+-)(inf)) returns +(inf).
17511 F.9.2.5 The sinh functions
17512 1 -- sinh((+-)0) returns (+-)0.
17513 -- sinh((+-)(inf)) returns (+-)(inf).
17514 F.9.2.6 The tanh functions
17515 1 -- tanh((+-)0) returns (+-)0.
17516 -- tanh((+-)(inf)) returns (+-)1.
17520 F.9.3 Exponential and logarithmic functions
17521 F.9.3.1 The exp functions
17522 1 -- exp((+-)0) returns 1.
17523 -- exp(-(inf)) returns +0.
17524 -- exp(+(inf)) returns +(inf).
17525 F.9.3.2 The exp2 functions
17526 1 -- exp2((+-)0) returns 1.
17527 -- exp2(-(inf)) returns +0.
17528 -- exp2(+(inf)) returns +(inf).
17529 F.9.3.3 The expm1 functions
17530 1 -- expm1((+-)0) returns (+-)0.
17531 -- expm1(-(inf)) returns -1.
17532 -- expm1(+(inf)) returns +(inf).
17533 F.9.3.4 The frexp functions
17534 1 -- frexp((+-)0, exp) returns (+-)0, and stores 0 in the object pointed to by exp.
17535 -- frexp((+-)(inf), exp) returns (+-)(inf), and stores an unspecified value in the object
17537 -- frexp(NaN, exp) stores an unspecified value in the object pointed to by exp
17538 (and returns a NaN).
17539 2 frexp raises no floating-point exceptions.
17540 3 On a binary system, the body of the frexp function might be
17542 *exp = (value == 0) ? 0 : (int)(1 + logb(value));
17543 return scalbn(value, -(*exp));
17545 F.9.3.5 The ilogb functions
17546 1 If the correct result is outside the range of the return type, the numeric result is
17547 unspecified and the ''invalid'' floating-point exception is raised.
17551 F.9.3.6 The ldexp functions
17552 1 On a binary system, ldexp(x, exp) is equivalent to scalbn(x, exp).
17553 F.9.3.7 The log functions
17554 1 -- log((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
17555 -- log(1) returns +0.
17556 -- log(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
17557 -- log(+(inf)) returns +(inf).
17558 F.9.3.8 The log10 functions
17559 1 -- log10((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
17560 -- log10(1) returns +0.
17561 -- log10(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
17562 -- log10(+(inf)) returns +(inf).
17563 F.9.3.9 The log1p functions
17564 1 -- log1p((+-)0) returns (+-)0.
17565 -- log1p(-1) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
17566 -- log1p(x) returns a NaN and raises the ''invalid'' floating-point exception for
17568 -- log1p(+(inf)) returns +(inf).
17569 F.9.3.10 The log2 functions
17570 1 -- log2((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
17571 -- log2(1) returns +0.
17572 -- log2(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
17573 -- log2(+(inf)) returns +(inf).
17574 F.9.3.11 The logb functions
17575 1 -- logb((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
17576 -- logb((+-)(inf)) returns +(inf).
17580 F.9.3.12 The modf functions
17581 1 -- modf((+-)x, iptr) returns a result with the same sign as x.
17582 -- modf((+-)(inf), iptr) returns (+-)0 and stores (+-)(inf) in the object pointed to by iptr.
17583 -- modf(NaN, iptr) stores a NaN in the object pointed to by iptr (and returns a
17585 2 modf behaves as though implemented by
17588 #pragma STDC FENV_ACCESS ON
17589 double modf(double value, double *iptr)
17591 int save_round = fegetround();
17592 fesetround(FE_TOWARDZERO);
17593 *iptr = nearbyint(value);
17594 fesetround(save_round);
17596 isinf(value) ? 0.0 :
17597 value - (*iptr), value);
17599 F.9.3.13 The scalbn and scalbln functions
17600 1 -- scalbn((+-)0, n) returns (+-)0.
17601 -- scalbn(x, 0) returns x.
17602 -- scalbn((+-)(inf), n) returns (+-)(inf).
17603 F.9.4 Power and absolute value functions
17604 F.9.4.1 The cbrt functions
17605 1 -- cbrt((+-)0) returns (+-)0.
17606 -- cbrt((+-)(inf)) returns (+-)(inf).
17607 F.9.4.2 The fabs functions
17608 1 -- fabs((+-)0) returns +0.
17609 -- fabs((+-)(inf)) returns +(inf).
17613 F.9.4.3 The hypot functions
17614 1 -- hypot(x, y), hypot(y, x), and hypot(x, -y) are equivalent.
17615 -- hypot(x, (+-)0) is equivalent to fabs(x).
17616 -- hypot((+-)(inf), y) returns +(inf), even if y is a NaN.
17617 F.9.4.4 The pow functions
17618 1 -- pow((+-)0, y) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception
17619 for y an odd integer < 0.
17620 -- pow((+-)0, y) returns +(inf) and raises the ''divide-by-zero'' floating-point exception
17621 for y < 0 and not an odd integer.
17622 -- pow((+-)0, y) returns (+-)0 for y an odd integer > 0.
17623 -- pow((+-)0, y) returns +0 for y > 0 and not an odd integer.
17624 -- pow(-1, (+-)(inf)) returns 1.
17625 -- pow(+1, y) returns 1 for any y, even a NaN.
17626 -- pow(x, (+-)0) returns 1 for any x, even a NaN.
17627 -- pow(x, y) returns a NaN and raises the ''invalid'' floating-point exception for
17628 finite x < 0 and finite non-integer y.
17629 -- pow(x, -(inf)) returns +(inf) for | x | < 1.
17630 -- pow(x, -(inf)) returns +0 for | x | > 1.
17631 -- pow(x, +(inf)) returns +0 for | x | < 1.
17632 -- pow(x, +(inf)) returns +(inf) for | x | > 1.
17633 -- pow(-(inf), y) returns -0 for y an odd integer < 0.
17634 -- pow(-(inf), y) returns +0 for y < 0 and not an odd integer.
17635 -- pow(-(inf), y) returns -(inf) for y an odd integer > 0.
17636 -- pow(-(inf), y) returns +(inf) for y > 0 and not an odd integer.
17637 -- pow(+(inf), y) returns +0 for y < 0.
17638 -- pow(+(inf), y) returns +(inf) for y > 0.
17642 F.9.4.5 The sqrt functions
17643 1 sqrt is fully specified as a basic arithmetic operation in IEC 60559.
17644 F.9.5 Error and gamma functions
17645 F.9.5.1 The erf functions
17646 1 -- erf((+-)0) returns (+-)0.
17647 -- erf((+-)(inf)) returns (+-)1.
17648 F.9.5.2 The erfc functions
17649 1 -- erfc(-(inf)) returns 2.
17650 -- erfc(+(inf)) returns +0.
17651 F.9.5.3 The lgamma functions
17652 1 -- lgamma(1) returns +0.
17653 -- lgamma(2) returns +0.
17654 -- lgamma(x) returns +(inf) and raises the ''divide-by-zero'' floating-point exception for
17655 x a negative integer or zero.
17656 -- lgamma(-(inf)) returns +(inf).
17657 -- lgamma(+(inf)) returns +(inf).
17658 F.9.5.4 The tgamma functions
17659 1 -- tgamma((+-)0) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception.
17660 -- tgamma(x) returns a NaN and raises the ''invalid'' floating-point exception for x a
17662 -- tgamma(-(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
17663 -- tgamma(+(inf)) returns +(inf).
17664 F.9.6 Nearest integer functions
17665 F.9.6.1 The ceil functions
17666 1 -- ceil((+-)0) returns (+-)0.
17667 -- ceil((+-)(inf)) returns (+-)(inf).
17668 2 The double version of ceil behaves as though implemented by
17674 #pragma STDC FENV_ACCESS ON
17675 double ceil(double x)
17678 int save_round = fegetround();
17679 fesetround(FE_UPWARD);
17680 result = rint(x); // or nearbyint instead of rint
17681 fesetround(save_round);
17684 F.9.6.2 The floor functions
17685 1 -- floor((+-)0) returns (+-)0.
17686 -- floor((+-)(inf)) returns (+-)(inf).
17687 2 See the sample implementation for ceil in F.9.6.1.
17688 F.9.6.3 The nearbyint functions
17689 1 The nearbyint functions use IEC 60559 rounding according to the current rounding
17690 direction. They do not raise the ''inexact'' floating-point exception if the result differs in
17691 value from the argument.
17692 -- nearbyint((+-)0) returns (+-)0 (for all rounding directions).
17693 -- nearbyint((+-)(inf)) returns (+-)(inf) (for all rounding directions).
17694 F.9.6.4 The rint functions
17695 1 The rint functions differ from the nearbyint functions only in that they do raise the
17696 ''inexact'' floating-point exception if the result differs in value from the argument.
17697 F.9.6.5 The lrint and llrint functions
17698 1 The lrint and llrint functions provide floating-to-integer conversion as prescribed
17699 by IEC 60559. They round according to the current rounding direction. If the rounded
17700 value is outside the range of the return type, the numeric result is unspecified and the
17701 ''invalid'' floating-point exception is raised. When they raise no other floating-point
17702 exception and the result differs from the argument, they raise the ''inexact'' floating-point
17707 F.9.6.6 The round functions
17708 1 -- round((+-)0) returns (+-)0.
17709 -- round((+-)(inf)) returns (+-)(inf).
17710 2 The double version of round behaves as though implemented by
17713 #pragma STDC FENV_ACCESS ON
17714 double round(double x)
17718 feholdexcept(&save_env);
17720 if (fetestexcept(FE_INEXACT)) {
17721 fesetround(FE_TOWARDZERO);
17722 result = rint(copysign(0.5 + fabs(x), x));
17724 feupdateenv(&save_env);
17727 The round functions may, but are not required to, raise the ''inexact'' floating-point
17728 exception for non-integer numeric arguments, as this implementation does.
17729 F.9.6.7 The lround and llround functions
17730 1 The lround and llround functions differ from the lrint and llrint functions
17731 with the default rounding direction just in that the lround and llround functions
17732 round halfway cases away from zero and need not raise the ''inexact'' floating-point
17733 exception for non-integer arguments that round to within the range of the return type.
17734 F.9.6.8 The trunc functions
17735 1 The trunc functions use IEC 60559 rounding toward zero (regardless of the current
17736 rounding direction).
17737 -- trunc((+-)0) returns (+-)0.
17738 -- trunc((+-)(inf)) returns (+-)(inf).
17742 F.9.7 Remainder functions
17743 F.9.7.1 The fmod functions
17744 1 -- fmod((+-)0, y) returns (+-)0 for y not zero.
17745 -- fmod(x, y) returns a NaN and raises the ''invalid'' floating-point exception for x
17746 infinite or y zero.
17747 -- fmod(x, (+-)(inf)) returns x for x not infinite.
17748 2 The double version of fmod behaves as though implemented by
17751 #pragma STDC FENV_ACCESS ON
17752 double fmod(double x, double y)
17755 result = remainder(fabs(x), (y = fabs(y)));
17756 if (signbit(result)) result += y;
17757 return copysign(result, x);
17759 F.9.7.2 The remainder functions
17760 1 The remainder functions are fully specified as a basic arithmetic operation in
17762 F.9.7.3 The remquo functions
17763 1 The remquo functions follow the specifications for the remainder functions. They
17764 have no further specifications special to IEC 60559 implementations.
17765 F.9.8 Manipulation functions
17766 F.9.8.1 The copysign functions
17767 1 copysign is specified in the Appendix to IEC 60559.
17768 F.9.8.2 The nan functions
17769 1 All IEC 60559 implementations support quiet NaNs, in all floating formats.
17773 F.9.8.3 The nextafter functions
17774 1 -- nextafter(x, y) raises the ''overflow'' and ''inexact'' floating-point exceptions
17775 for x finite and the function value infinite.
17776 -- nextafter(x, y) raises the ''underflow'' and ''inexact'' floating-point
17777 exceptions for the function value subnormal or zero and x != y.
17778 F.9.8.4 The nexttoward functions
17779 1 No additional requirements beyond those on nextafter.
17780 F.9.9 Maximum, minimum, and positive difference functions
17781 F.9.9.1 The fdim functions
17782 1 No additional requirements.
17783 F.9.9.2 The fmax functions
17784 1 If just one argument is a NaN, the fmax functions return the other argument (if both
17785 arguments are NaNs, the functions return a NaN).
17786 2 The body of the fmax function might be323)
17787 { return (isgreaterequal(x, y) ||
17788 isnan(y)) ? x : y; }
17789 F.9.9.3 The fmin functions
17790 1 The fmin functions are analogous to the fmax functions (see F.9.9.2).
17791 F.9.10 Floating multiply-add
17792 F.9.10.1 The fma functions
17793 1 -- fma(x, y, z) computes xy + z, correctly rounded once.
17794 -- fma(x, y, z) returns a NaN and optionally raises the ''invalid'' floating-point
17795 exception if one of x and y is infinite, the other is zero, and z is a NaN.
17796 -- fma(x, y, z) returns a NaN and raises the ''invalid'' floating-point exception if
17797 one of x and y is infinite, the other is zero, and z is not a NaN.
17798 -- fma(x, y, z) returns a NaN and raises the ''invalid'' floating-point exception if x
17799 times y is an exact infinity and z is also an infinity but with the opposite sign.
17804 323) Ideally, fmax would be sensitive to the sign of zero, for example fmax(-0.0, +0.0) would
17805 return +0; however, implementation in software might be impractical.
17811 IEC 60559-compatible complex arithmetic
17813 1 This annex supplements annex F to specify complex arithmetic for compatibility with
17814 IEC 60559 real floating-point arithmetic. Although these specifications have been
17815 carefully designed, there is little existing practice to validate the design decisions.
17816 Therefore, these specifications are not normative, but should be viewed more as
17817 recommended practice. An implementation that defines
17818 __STDC_IEC_559_COMPLEX__ should conform to the specifications in this annex.
17820 1 There is a new keyword _Imaginary, which is used to specify imaginary types. It is
17821 used as a type specifier within declaration specifiers in the same way as _Complex is
17822 (thus, _Imaginary float is a valid type name).
17823 2 There are three imaginary types, designated as float _Imaginary, double
17824 _Imaginary, and long double _Imaginary. The imaginary types (along with
17825 the real floating and complex types) are floating types.
17826 3 For imaginary types, the corresponding real type is given by deleting the keyword
17827 _Imaginary from the type name.
17828 4 Each imaginary type has the same representation and alignment requirements as the
17829 corresponding real type. The value of an object of imaginary type is the value of the real
17830 representation times the imaginary unit.
17831 5 The imaginary type domain comprises the imaginary types.
17833 1 A complex or imaginary value with at least one infinite part is regarded as an infinity
17834 (even if its other part is a NaN). A complex or imaginary value is a finite number if each
17835 of its parts is a finite number (neither infinite nor NaN). A complex or imaginary value is
17836 a zero if each of its parts is a zero.
17841 G.4.1 Imaginary types
17842 1 Conversions among imaginary types follow rules analogous to those for real floating
17844 G.4.2 Real and imaginary
17845 1 When a value of imaginary type is converted to a real type other than _Bool,324) the
17846 result is a positive zero.
17847 2 When a value of real type is converted to an imaginary type, the result is a positive
17849 G.4.3 Imaginary and complex
17850 1 When a value of imaginary type is converted to a complex type, the real part of the
17851 complex result value is a positive zero and the imaginary part of the complex result value
17852 is determined by the conversion rules for the corresponding real types.
17853 2 When a value of complex type is converted to an imaginary type, the real part of the
17854 complex value is discarded and the value of the imaginary part is converted according to
17855 the conversion rules for the corresponding real types.
17856 G.5 Binary operators
17857 1 The following subclauses supplement 6.5 in order to specify the type of the result for an
17858 operation with an imaginary operand.
17859 2 For most operand types, the value of the result of a binary operator with an imaginary or
17860 complex operand is completely determined, with reference to real arithmetic, by the usual
17861 mathematical formula. For some operand types, the usual mathematical formula is
17862 problematic because of its treatment of infinities and because of undue overflow or
17863 underflow; in these cases the result satisfies certain properties (specified in G.5.1), but is
17864 not completely determined.
17873 G.5.1 Multiplicative operators
17875 1 If one operand has real type and the other operand has imaginary type, then the result has
17876 imaginary type. If both operands have imaginary type, then the result has real type. (If
17877 either operand has complex type, then the result has complex type.)
17878 2 If the operands are not both complex, then the result and floating-point exception
17879 behavior of the * operator is defined by the usual mathematical formula:
17882 x xu i(xv) (xu) + i(xv)
17884 iy i(yu) -yv (-yv) + i(yu)
17886 x + iy (xu) + i(yu) (-yv) + i(xv)
17887 3 If the second operand is not complex, then the result and floating-point exception
17888 behavior of the / operator is defined by the usual mathematical formula:
17895 x + iy (x/u) + i(y/u) (y/v) + i(-x/v)
17896 4 The * and / operators satisfy the following infinity properties for all real, imaginary, and
17897 complex operands:325)
17898 -- if one operand is an infinity and the other operand is a nonzero finite number or an
17899 infinity, then the result of the * operator is an infinity;
17900 -- if the first operand is an infinity and the second operand is a finite number, then the
17901 result of the / operator is an infinity;
17902 -- if the first operand is a finite number and the second operand is an infinity, then the
17903 result of the / operator is a zero;
17908 325) These properties are already implied for those cases covered in the tables, but are required for all cases
17909 (at least where the state for CX_LIMITED_RANGE is ''off'').
17913 -- if the first operand is a nonzero finite number or an infinity and the second operand is
17914 a zero, then the result of the / operator is an infinity.
17915 5 If both operands of the * operator are complex or if the second operand of the / operator
17916 is complex, the operator raises floating-point exceptions if appropriate for the calculation
17917 of the parts of the result, and may raise spurious floating-point exceptions.
17918 6 EXAMPLE 1 Multiplication of double _Complex operands could be implemented as follows. Note
17919 that the imaginary unit I has imaginary type (see G.6).
17921 #include <complex.h>
17922 /* Multiply z * w ... */
17923 double complex _Cmultd(double complex z, double complex w)
17925 #pragma STDC FP_CONTRACT OFF
17926 double a, b, c, d, ac, bd, ad, bc, x, y;
17927 a = creal(z); b = cimag(z);
17928 c = creal(w); d = cimag(w);
17929 ac = a * c; bd = b * d;
17930 ad = a * d; bc = b * c;
17931 x = ac - bd; y = ad + bc;
17932 if (isnan(x) && isnan(y)) {
17933 /* Recover infinities that computed as NaN+iNaN ... */
17935 if ( isinf(a) || isinf(b) ) { // z is infinite
17936 /* "Box" the infinity and change NaNs in the other factor to 0 */
17937 a = copysign(isinf(a) ? 1.0 : 0.0, a);
17938 b = copysign(isinf(b) ? 1.0 : 0.0, b);
17939 if (isnan(c)) c = copysign(0.0, c);
17940 if (isnan(d)) d = copysign(0.0, d);
17943 if ( isinf(c) || isinf(d) ) { // w is infinite
17944 /* "Box" the infinity and change NaNs in the other factor to 0 */
17945 c = copysign(isinf(c) ? 1.0 : 0.0, c);
17946 d = copysign(isinf(d) ? 1.0 : 0.0, d);
17947 if (isnan(a)) a = copysign(0.0, a);
17948 if (isnan(b)) b = copysign(0.0, b);
17951 if (!recalc && (isinf(ac) || isinf(bd) ||
17952 isinf(ad) || isinf(bc))) {
17953 /* Recover infinities from overflow by changing NaNs to 0 ... */
17954 if (isnan(a)) a = copysign(0.0, a);
17955 if (isnan(b)) b = copysign(0.0, b);
17956 if (isnan(c)) c = copysign(0.0, c);
17957 if (isnan(d)) d = copysign(0.0, d);
17964 x = INFINITY * ( a * c - b * d );
17965 y = INFINITY * ( a * d + b * c );
17970 7 This implementation achieves the required treatment of infinities at the cost of only one isnan test in
17971 ordinary (finite) cases. It is less than ideal in that undue overflow and underflow may occur.
17973 8 EXAMPLE 2 Division of two double _Complex operands could be implemented as follows.
17975 #include <complex.h>
17976 /* Divide z / w ... */
17977 double complex _Cdivd(double complex z, double complex w)
17979 #pragma STDC FP_CONTRACT OFF
17980 double a, b, c, d, logbw, denom, x, y;
17982 a = creal(z); b = cimag(z);
17983 c = creal(w); d = cimag(w);
17984 logbw = logb(fmax(fabs(c), fabs(d)));
17985 if (isfinite(logbw)) {
17986 ilogbw = (int)logbw;
17987 c = scalbn(c, -ilogbw); d = scalbn(d, -ilogbw);
17989 denom = c * c + d * d;
17990 x = scalbn((a * c + b * d) / denom, -ilogbw);
17991 y = scalbn((b * c - a * d) / denom, -ilogbw);
17992 /* Recover infinities and zeros that computed as NaN+iNaN; */
17993 /* the only cases are nonzero/zero, infinite/finite, and finite/infinite, ... */
17994 if (isnan(x) && isnan(y)) {
17995 if ((denom == 0.0) &&
17996 (!isnan(a) || !isnan(b))) {
17997 x = copysign(INFINITY, c) * a;
17998 y = copysign(INFINITY, c) * b;
18000 else if ((isinf(a) || isinf(b)) &&
18001 isfinite(c) && isfinite(d)) {
18002 a = copysign(isinf(a) ? 1.0 : 0.0, a);
18003 b = copysign(isinf(b) ? 1.0 : 0.0, b);
18004 x = INFINITY * ( a * c + b * d );
18005 y = INFINITY * ( b * c - a * d );
18007 else if (isinf(logbw) &&
18008 isfinite(a) && isfinite(b)) {
18009 c = copysign(isinf(c) ? 1.0 : 0.0, c);
18010 d = copysign(isinf(d) ? 1.0 : 0.0, d);
18011 x = 0.0 * ( a * c + b * d );
18012 y = 0.0 * ( b * c - a * d );
18020 9 Scaling the denominator alleviates the main overflow and underflow problem, which is more serious than
18021 for multiplication. In the spirit of the multiplication example above, this code does not defend against
18022 overflow and underflow in the calculation of the numerator. Scaling with the scalbn function, instead of
18023 with division, provides better roundoff characteristics.
18025 G.5.2 Additive operators
18027 1 If both operands have imaginary type, then the result has imaginary type. (If one operand
18028 has real type and the other operand has imaginary type, or if either operand has complex
18029 type, then the result has complex type.)
18030 2 In all cases the result and floating-point exception behavior of a + or - operator is defined
18031 by the usual mathematical formula:
18034 x x(+-)u x (+-) iv (x (+-) u) (+-) iv
18036 iy (+-)u + iy i(y (+-) v) (+-)u + i(y (+-) v)
18038 x + iy (x (+-) u) + iy x + i(y (+-) v) (x (+-) u) + i(y (+-) v)
18039 G.6 Complex arithmetic <complex.h>
18044 are defined, respectively, as _Imaginary and a constant expression of type const
18045 float _Imaginary with the value of the imaginary unit. The macro
18047 is defined to be _Imaginary_I (not _Complex_I as stated in 7.3). Notwithstanding
18048 the provisions of 7.1.3, a program may undefine and then perhaps redefine the macro
18050 2 This subclause contains specifications for the <complex.h> functions that are
18051 particularly suited to IEC 60559 implementations. For families of functions, the
18052 specifications apply to all of the functions even though only the principal function is
18056 shown. Unless otherwise specified, where the symbol ''(+-)'' occurs in both an argument
18057 and the result, the result has the same sign as the argument.
18058 3 The functions are continuous onto both sides of their branch cuts, taking into account the
18059 sign of zero. For example, csqrt(-2 (+-) i0) = (+-)i(sqrt)2. ???
18060 4 Since complex and imaginary values are composed of real values, each function may be
18061 regarded as computing real values from real values. Except as noted, the functions treat
18062 real infinities, NaNs, signed zeros, subnormals, and the floating-point exception flags in a
18063 manner consistent with the specifications for real functions in F.9.326)
18064 5 The functions cimag, conj, cproj, and creal are fully specified for all
18065 implementations, including IEC 60559 ones, in 7.3.9. These functions raise no floating-
18067 6 Each of the functions cabs and carg is specified by a formula in terms of a real
18068 function (whose special cases are covered in annex F):
18069 cabs(x + iy) = hypot(x, y)
18070 carg(x + iy) = atan2(y, x)
18071 7 Each of the functions casin, catan, ccos, csin, and ctan is specified implicitly by
18072 a formula in terms of other complex functions (whose special cases are specified below):
18073 casin(z) = -i casinh(iz)
18074 catan(z) = -i catanh(iz)
18075 ccos(z) = ccosh(iz)
18076 csin(z) = -i csinh(iz)
18077 ctan(z) = -i ctanh(iz)
18078 8 For the other functions, the following subclauses specify behavior for special cases,
18079 including treatment of the ''invalid'' and ''divide-by-zero'' floating-point exceptions. For
18080 families of functions, the specifications apply to all of the functions even though only the
18081 principal function is shown. For a function f satisfying f (conj(z)) = conj( f (z)), the
18082 specifications for the upper half-plane imply the specifications for the lower half-plane; if
18083 the function f is also either even, f (-z) = f (z), or odd, f (-z) = - f (z), then the
18084 specifications for the first quadrant imply the specifications for the other three quadrants.
18085 9 In the following subclauses, cis(y) is defined as cos(y) + i sin(y).
18090 326) As noted in G.3, a complex value with at least one infinite part is regarded as an infinity even if its
18091 other part is a NaN.
18095 G.6.1 Trigonometric functions
18096 G.6.1.1 The cacos functions
18097 1 -- cacos(conj(z)) = conj(cacos(z)).
18098 -- cacos((+-)0 + i0) returns pi /2 - i0.
18099 -- cacos((+-)0 + iNaN) returns pi /2 + iNaN.
18100 -- cacos(x + i (inf)) returns pi /2 - i (inf), for finite x.
18101 -- cacos(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18102 point exception, for nonzero finite x.
18103 -- cacos(-(inf) + iy) returns pi - i (inf), for positive-signed finite y.
18104 -- cacos(+(inf) + iy) returns +0 - i (inf), for positive-signed finite y.
18105 -- cacos(-(inf) + i (inf)) returns 3pi /4 - i (inf).
18106 -- cacos(+(inf) + i (inf)) returns pi /4 - i (inf).
18107 -- cacos((+-)(inf) + iNaN) returns NaN (+-) i (inf) (where the sign of the imaginary part of the
18108 result is unspecified).
18109 -- cacos(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18110 point exception, for finite y.
18111 -- cacos(NaN + i (inf)) returns NaN - i (inf).
18112 -- cacos(NaN + iNaN) returns NaN + iNaN.
18113 G.6.2 Hyperbolic functions
18114 G.6.2.1 The cacosh functions
18115 1 -- cacosh(conj(z)) = conj(cacosh(z)).
18116 -- cacosh((+-)0 + i0) returns +0 + ipi /2.
18117 -- cacosh(x + i (inf)) returns +(inf) + ipi /2, for finite x.
18118 -- cacosh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
18119 floating-point exception, for finite x.
18120 -- cacosh(-(inf) + iy) returns +(inf) + ipi , for positive-signed finite y.
18121 -- cacosh(+(inf) + iy) returns +(inf) + i0, for positive-signed finite y.
18122 -- cacosh(-(inf) + i (inf)) returns +(inf) + i3pi /4.
18123 -- cacosh(+(inf) + i (inf)) returns +(inf) + ipi /4.
18124 -- cacosh((+-)(inf) + iNaN) returns +(inf) + iNaN.
18128 -- cacosh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
18129 floating-point exception, for finite y.
18130 -- cacosh(NaN + i (inf)) returns +(inf) + iNaN.
18131 -- cacosh(NaN + iNaN) returns NaN + iNaN.
18132 G.6.2.2 The casinh functions
18133 1 -- casinh(conj(z)) = conj(casinh(z)) and casinh is odd.
18134 -- casinh(+0 + i0) returns 0 + i0.
18135 -- casinh(x + i (inf)) returns +(inf) + ipi /2 for positive-signed finite x.
18136 -- casinh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
18137 floating-point exception, for finite x.
18138 -- casinh(+(inf) + iy) returns +(inf) + i0 for positive-signed finite y.
18139 -- casinh(+(inf) + i (inf)) returns +(inf) + ipi /4.
18140 -- casinh(+(inf) + iNaN) returns +(inf) + iNaN.
18141 -- casinh(NaN + i0) returns NaN + i0.
18142 -- casinh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
18143 floating-point exception, for finite nonzero y.
18144 -- casinh(NaN + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result
18146 -- casinh(NaN + iNaN) returns NaN + iNaN.
18147 G.6.2.3 The catanh functions
18148 1 -- catanh(conj(z)) = conj(catanh(z)) and catanh is odd.
18149 -- catanh(+0 + i0) returns +0 + i0.
18150 -- catanh(+0 + iNaN) returns +0 + iNaN.
18151 -- catanh(+1 + i0) returns +(inf) + i0 and raises the ''divide-by-zero'' floating-point
18153 -- catanh(x + i (inf)) returns +0 + ipi /2, for finite positive-signed x.
18154 -- catanh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
18155 floating-point exception, for nonzero finite x.
18156 -- catanh(+(inf) + iy) returns +0 + ipi /2, for finite positive-signed y.
18157 -- catanh(+(inf) + i (inf)) returns +0 + ipi /2.
18158 -- catanh(+(inf) + iNaN) returns +0 + iNaN.
18162 -- catanh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
18163 floating-point exception, for finite y.
18164 -- catanh(NaN + i (inf)) returns (+-)0 + ipi /2 (where the sign of the real part of the result is
18166 -- catanh(NaN + iNaN) returns NaN + iNaN.
18167 G.6.2.4 The ccosh functions
18168 1 -- ccosh(conj(z)) = conj(ccosh(z)) and ccosh is even.
18169 -- ccosh(+0 + i0) returns 1 + i0.
18170 -- ccosh(+0 + i (inf)) returns NaN (+-) i0 (where the sign of the imaginary part of the
18171 result is unspecified) and raises the ''invalid'' floating-point exception.
18172 -- ccosh(+0 + iNaN) returns NaN (+-) i0 (where the sign of the imaginary part of the
18173 result is unspecified).
18174 -- ccosh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
18175 exception, for finite nonzero x.
18176 -- ccosh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18177 point exception, for finite nonzero x.
18178 -- ccosh(+(inf) + i0) returns +(inf) + i0.
18179 -- ccosh(+(inf) + iy) returns +(inf) cis(y), for finite nonzero y.
18180 -- ccosh(+(inf) + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result is
18181 unspecified) and raises the ''invalid'' floating-point exception.
18182 -- ccosh(+(inf) + iNaN) returns +(inf) + iNaN.
18183 -- ccosh(NaN + i0) returns NaN (+-) i0 (where the sign of the imaginary part of the
18184 result is unspecified).
18185 -- ccosh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18186 point exception, for all nonzero numbers y.
18187 -- ccosh(NaN + iNaN) returns NaN + iNaN.
18188 G.6.2.5 The csinh functions
18189 1 -- csinh(conj(z)) = conj(csinh(z)) and csinh is odd.
18190 -- csinh(+0 + i0) returns +0 + i0.
18191 -- csinh(+0 + i (inf)) returns (+-)0 + iNaN (where the sign of the real part of the result is
18192 unspecified) and raises the ''invalid'' floating-point exception.
18193 -- csinh(+0 + iNaN) returns (+-)0 + iNaN (where the sign of the real part of the result is
18198 -- csinh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
18199 exception, for positive finite x.
18200 -- csinh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18201 point exception, for finite nonzero x.
18202 -- csinh(+(inf) + i0) returns +(inf) + i0.
18203 -- csinh(+(inf) + iy) returns +(inf) cis(y), for positive finite y.
18204 -- csinh(+(inf) + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result is
18205 unspecified) and raises the ''invalid'' floating-point exception.
18206 -- csinh(+(inf) + iNaN) returns (+-)(inf) + iNaN (where the sign of the real part of the result
18208 -- csinh(NaN + i0) returns NaN + i0.
18209 -- csinh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18210 point exception, for all nonzero numbers y.
18211 -- csinh(NaN + iNaN) returns NaN + iNaN.
18212 G.6.2.6 The ctanh functions
18213 1 -- ctanh(conj(z)) = conj(ctanh(z))and ctanh is odd.
18214 -- ctanh(+0 + i0) returns +0 + i0.
18215 -- ctanh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
18216 exception, for finite x.
18217 -- ctanh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18218 point exception, for finite x.
18219 -- ctanh(+(inf) + iy) returns 1 + i0 sin(2y), for positive-signed finite y.
18220 -- ctanh(+(inf) + i (inf)) returns 1 (+-) i0 (where the sign of the imaginary part of the result
18222 -- ctanh(+(inf) + iNaN) returns 1 (+-) i0 (where the sign of the imaginary part of the
18223 result is unspecified).
18224 -- ctanh(NaN + i0) returns NaN + i0.
18225 -- ctanh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18226 point exception, for all nonzero numbers y.
18227 -- ctanh(NaN + iNaN) returns NaN + iNaN.
18231 G.6.3 Exponential and logarithmic functions
18232 G.6.3.1 The cexp functions
18233 1 -- cexp(conj(z)) = conj(cexp(z)).
18234 -- cexp((+-)0 + i0) returns 1 + i0.
18235 -- cexp(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
18236 exception, for finite x.
18237 -- cexp(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18238 point exception, for finite x.
18239 -- cexp(+(inf) + i0) returns +(inf) + i0.
18240 -- cexp(-(inf) + iy) returns +0 cis(y), for finite y.
18241 -- cexp(+(inf) + iy) returns +(inf) cis(y), for finite nonzero y.
18242 -- cexp(-(inf) + i (inf)) returns (+-)0 (+-) i0 (where the signs of the real and imaginary parts of
18243 the result are unspecified).
18244 -- cexp(+(inf) + i (inf)) returns (+-)(inf) + iNaN and raises the ''invalid'' floating-point
18245 exception (where the sign of the real part of the result is unspecified).
18246 -- cexp(-(inf) + iNaN) returns (+-)0 (+-) i0 (where the signs of the real and imaginary parts
18247 of the result are unspecified).
18248 -- cexp(+(inf) + iNaN) returns (+-)(inf) + iNaN (where the sign of the real part of the result
18250 -- cexp(NaN + i0) returns NaN + i0.
18251 -- cexp(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18252 point exception, for all nonzero numbers y.
18253 -- cexp(NaN + iNaN) returns NaN + iNaN.
18254 G.6.3.2 The clog functions
18255 1 -- clog(conj(z)) = conj(clog(z)).
18256 -- clog(-0 + i0) returns -(inf) + ipi and raises the ''divide-by-zero'' floating-point
18258 -- clog(+0 + i0) returns -(inf) + i0 and raises the ''divide-by-zero'' floating-point
18260 -- clog(x + i (inf)) returns +(inf) + ipi /2, for finite x.
18261 -- clog(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18262 point exception, for finite x.
18266 -- clog(-(inf) + iy) returns +(inf) + ipi , for finite positive-signed y.
18267 -- clog(+(inf) + iy) returns +(inf) + i0, for finite positive-signed y.
18268 -- clog(-(inf) + i (inf)) returns +(inf) + i3pi /4.
18269 -- clog(+(inf) + i (inf)) returns +(inf) + ipi /4.
18270 -- clog((+-)(inf) + iNaN) returns +(inf) + iNaN.
18271 -- clog(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18272 point exception, for finite y.
18273 -- clog(NaN + i (inf)) returns +(inf) + iNaN.
18274 -- clog(NaN + iNaN) returns NaN + iNaN.
18275 G.6.4 Power and absolute-value functions
18276 G.6.4.1 The cpow functions
18277 1 The cpow functions raise floating-point exceptions if appropriate for the calculation of
18278 the parts of the result, and may raise spurious exceptions.327)
18279 G.6.4.2 The csqrt functions
18280 1 -- csqrt(conj(z)) = conj(csqrt(z)).
18281 -- csqrt((+-)0 + i0) returns +0 + i0.
18282 -- csqrt(x + i (inf)) returns +(inf) + i (inf), for all x (including NaN).
18283 -- csqrt(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18284 point exception, for finite x.
18285 -- csqrt(-(inf) + iy) returns +0 + i (inf), for finite positive-signed y.
18286 -- csqrt(+(inf) + iy) returns +(inf) + i0, for finite positive-signed y.
18287 -- csqrt(-(inf) + iNaN) returns NaN (+-) i (inf) (where the sign of the imaginary part of the
18288 result is unspecified).
18289 -- csqrt(+(inf) + iNaN) returns +(inf) + iNaN.
18290 -- csqrt(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18291 point exception, for finite y.
18292 -- csqrt(NaN + iNaN) returns NaN + iNaN.
18297 327) This allows cpow( z , c ) to be implemented as cexp(c clog( z )) without precluding
18298 implementations that treat special cases more carefully.
18302 G.7 Type-generic math <tgmath.h>
18303 1 Type-generic macros that accept complex arguments also accept imaginary arguments. If
18304 an argument is imaginary, the macro expands to an expression whose type is real,
18305 imaginary, or complex, as appropriate for the particular function: if the argument is
18306 imaginary, then the types of cos, cosh, fabs, carg, cimag, and creal are real; the
18307 types of sin, tan, sinh, tanh, asin, atan, asinh, and atanh are imaginary; and
18308 the types of the others are complex.
18309 2 Given an imaginary argument, each of the type-generic macros cos, sin, tan, cosh,
18310 sinh, tanh, asin, atan, asinh, atanh is specified by a formula in terms of real
18313 sin(iy) = i sinh(y)
18314 tan(iy) = i tanh(y)
18316 sinh(iy) = i sin(y)
18317 tanh(iy) = i tan(y)
18318 asin(iy) = i asinh(y)
18319 atan(iy) = i atanh(y)
18320 asinh(iy) = i asin(y)
18321 atanh(iy) = i atan(y)
18327 Language independent arithmetic
18329 1 This annex documents the extent to which the C language supports the ISO/IEC 10967-1
18330 standard for language-independent arithmetic (LIA-1). LIA-1 is more general than
18331 IEC 60559 (annex F) in that it covers integer and diverse floating-point arithmetics.
18333 1 The relevant C arithmetic types meet the requirements of LIA-1 types if an
18334 implementation adds notification of exceptional arithmetic operations and meets the 1
18335 unit in the last place (ULP) accuracy requirement (LIA-1 subclause 5.2.8).
18337 1 The LIA-1 data type Boolean is implemented by the C data type bool with values of
18338 true and false, all from <stdbool.h>.
18339 H.2.2 Integer types
18340 1 The signed C integer types int, long int, long long int, and the corresponding
18341 unsigned types are compatible with LIA-1. If an implementation adds support for the
18342 LIA-1 exceptional values ''integer_overflow'' and ''undefined'', then those types are
18343 LIA-1 conformant types. C's unsigned integer types are ''modulo'' in the LIA-1 sense
18344 in that overflows or out-of-bounds results silently wrap. An implementation that defines
18345 signed integer types as also being modulo need not detect integer overflow, in which case,
18346 only integer divide-by-zero need be detected.
18347 2 The parameters for the integer data types can be accessed by the following:
18348 maxint INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX,
18350 minint INT_MIN, LONG_MIN, LLONG_MIN
18351 3 The parameter ''bounded'' is always true, and is not provided. The parameter ''minint''
18352 is always 0 for the unsigned types, and is not provided for those types.
18356 H.2.2.1 Integer operations
18357 1 The integer operations on integer types are the following:
18364 absI abs(x), labs(x), llabs(x)
18371 where x and y are expressions of the same integer type.
18372 H.2.3 Floating-point types
18373 1 The C floating-point types float, double, and long double are compatible with
18374 LIA-1. If an implementation adds support for the LIA-1 exceptional values
18375 ''underflow'', ''floating_overflow'', and ''"undefined'', then those types are conformant
18376 with LIA-1. An implementation that uses IEC 60559 floating-point formats and
18377 operations (see annex F) along with IEC 60559 status flags and traps has LIA-1
18379 H.2.3.1 Floating-point parameters
18380 1 The parameters for a floating point data type can be accessed by the following:
18382 p FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG
18383 emax FLT_MAX_EXP, DBL_MAX_EXP, LDBL_MAX_EXP
18384 emin FLT_MIN_EXP, DBL_MIN_EXP, LDBL_MIN_EXP
18385 2 The derived constants for the floating point types are accessed by the following:
18389 fmax FLT_MAX, DBL_MAX, LDBL_MAX
18390 fminN FLT_MIN, DBL_MIN, LDBL_MIN
18391 epsilon FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON
18392 rnd_style FLT_ROUNDS
18393 H.2.3.2 Floating-point operations
18394 1 The floating-point operations on floating-point types are the following:
18400 absF fabsf(x), fabs(x), fabsl(x)
18401 exponentF 1.f+logbf(x), 1.0+logb(x), 1.L+logbl(x)
18402 scaleF scalbnf(x, n), scalbn(x, n), scalbnl(x, n),
18403 scalblnf(x, li), scalbln(x, li), scalblnl(x, li)
18404 intpartF modff(x, &y), modf(x, &y), modfl(x, &y)
18405 fractpartF modff(x, &y), modf(x, &y), modfl(x, &y)
18412 where x and y are expressions of the same floating point type, n is of type int, and li
18413 is of type long int.
18414 H.2.3.3 Rounding styles
18415 1 The C Standard requires all floating types to use the same radix and rounding style, so
18416 that only one identifier for each is provided to map to LIA-1.
18417 2 The FLT_ROUNDS parameter can be used to indicate the LIA-1 rounding styles:
18418 truncate FLT_ROUNDS == 0
18422 nearest FLT_ROUNDS == 1
18423 other FLT_ROUNDS != 0 && FLT_ROUNDS != 1
18424 provided that an implementation extends FLT_ROUNDS to cover the rounding style used
18425 in all relevant LIA-1 operations, not just addition as in C.
18426 H.2.4 Type conversions
18427 1 The LIA-1 type conversions are the following type casts:
18428 cvtI' -> I (int)i, (long int)i, (long long int)i,
18429 (unsigned int)i, (unsigned long int)i,
18430 (unsigned long long int)i
18431 cvtF -> I (int)x, (long int)x, (long long int)x,
18432 (unsigned int)x, (unsigned long int)x,
18433 (unsigned long long int)x
18434 cvtI -> F (float)i, (double)i, (long double)i
18435 cvtF' -> F (float)x, (double)x, (long double)x
18436 2 In the above conversions from floating to integer, the use of (cast)x can be replaced with
18437 (cast)round(x), (cast)rint(x), (cast)nearbyint(x), (cast)trunc(x),
18438 (cast)ceil(x), or (cast)floor(x). In addition, C's floating-point to integer
18439 conversion functions, lrint(), llrint(), lround(), and llround(), can be
18440 used. They all meet LIA-1's requirements on floating to integer rounding for in-range
18441 values. For out-of-range values, the conversions shall silently wrap for the modulo types.
18442 3 The fmod() function is useful for doing silent wrapping to unsigned integer types, e.g.,
18443 fmod( fabs(rint(x)), 65536.0 ) or (0.0 <= (y = fmod( rint(x),
18444 65536.0 )) ? y : 65536.0 + y) will compute an integer value in the range 0.0
18445 to 65535.0 which can then be cast to unsigned short int. But, the
18446 remainder() function is not useful for doing silent wrapping to signed integer types,
18447 e.g., remainder( rint(x), 65536.0 ) will compute an integer value in the
18448 range -32767.0 to +32768.0 which is not, in general, in the range of signed short
18450 4 C's conversions (casts) from floating-point to floating-point can meet LIA-1
18451 requirements if an implementation uses round-to-nearest (IEC 60559 default).
18452 5 C's conversions (casts) from integer to floating-point can meet LIA-1 requirements if an
18453 implementation uses round-to-nearest.
18458 1 Notification is the process by which a user or program is informed that an exceptional
18459 arithmetic operation has occurred. C's operations are compatible with LIA-1 in that C
18460 allows an implementation to cause a notification to occur when any arithmetic operation
18461 returns an exceptional value as defined in LIA-1 clause 5.
18462 H.3.1 Notification alternatives
18463 1 LIA-1 requires at least the following two alternatives for handling of notifications:
18464 setting indicators or trap-and-terminate. LIA-1 allows a third alternative: trap-and-
18466 2 An implementation need only support a given notification alternative for the entire
18467 program. An implementation may support the ability to switch between notification
18468 alternatives during execution, but is not required to do so. An implementation can
18469 provide separate selection for each kind of notification, but this is not required.
18470 3 C allows an implementation to provide notification. C's SIGFPE (for traps) and
18471 FE_INVALID, FE_DIVBYZERO, FE_OVERFLOW, FE_UNDERFLOW (for indicators)
18472 can provide LIA-1 notification.
18473 4 C's signal handlers are compatible with LIA-1. Default handling of SIGFPE can
18474 provide trap-and-terminate behavior, except for those LIA-1 operations implemented by
18475 math library function calls. User-provided signal handlers for SIGFPE allow for trap-
18476 and-resume behavior with the same constraint.
18478 1 C's <fenv.h> status flags are compatible with the LIA-1 indicators.
18479 2 The following mapping is for floating-point types:
18480 undefined FE_INVALID, FE_DIVBYZERO
18481 floating_overflow FE_OVERFLOW
18482 underflow FE_UNDERFLOW
18483 3 The floating-point indicator interrogation and manipulation operations are:
18484 set_indicators feraiseexcept(i)
18485 clear_indicators feclearexcept(i)
18486 test_indicators fetestexcept(i)
18487 current_indicators fetestexcept(FE_ALL_EXCEPT)
18488 where i is an expression of type int representing a subset of the LIA-1 indicators.
18489 4 C allows an implementation to provide the following LIA-1 required behavior: at
18490 program termination if any indicator is set the implementation shall send an unambiguous
18494 and ''hard to ignore'' message (see LIA-1 subclause 6.1.2)
18495 5 LIA-1 does not make the distinction between floating-point and integer for ''undefined''.
18496 This documentation makes that distinction because <fenv.h> covers only the floating-
18499 1 C is compatible with LIA-1's trap requirements for arithmetic operations, but not for
18500 math library functions (which are not permitted to generate any externally visible
18501 exceptional conditions). An implementation can provide an alternative of notification
18502 through termination with a ''hard-to-ignore'' message (see LIA-1 subclause 6.1.3).
18503 2 LIA-1 does not require that traps be precise.
18504 3 C does require that SIGFPE be the signal corresponding to arithmetic exceptions, if there
18505 is any signal raised for them.
18506 4 C supports signal handlers for SIGFPE and allows trapping of arithmetic exceptions.
18507 When arithmetic exceptions do trap, C's signal-handler mechanism allows trap-and-
18508 terminate (either default implementation behavior or user replacement for it) or trap-and-
18509 resume, at the programmer's option.
18516 1 An implementation may generate warnings in many situations, none of which are
18517 specified as part of this International Standard. The following are a few of the more
18519 2 -- A new struct or union type appears in a function prototype (6.2.1, 6.7.2.3).
18520 -- A block with initialization of an object that has automatic storage duration is jumped
18522 -- An implicit narrowing conversion is encountered, such as the assignment of a long
18523 int or a double to an int, or a pointer to void to a pointer to any type other than
18524 a character type (6.3).
18525 -- A hexadecimal floating constant cannot be represented exactly in its evaluation format
18527 -- An integer character constant includes more than one character or a wide character
18528 constant includes more than one multibyte character (6.4.4.4).
18529 -- The characters /* are found in a comment (6.4.7).
18530 -- An ''unordered'' binary operator (not comma, &&, or ||) contains a side effect to an
18531 lvalue in one operand, and a side effect to, or an access to the value of, the identical
18532 lvalue in the other operand (6.5).
18533 -- A function is called but no prototype has been supplied (6.5.2.2).
18534 -- The arguments in a function call do not agree in number and type with those of the
18535 parameters in a function definition that is not a prototype (6.5.2.2).
18536 -- An object is defined but not used (6.7).
18537 -- A value is given to an object of an enumerated type other than by assignment of an
18538 enumeration constant that is a member of that type, or an enumeration object that has
18539 the same type, or the value of a function that returns the same enumerated type
18541 -- An aggregate has a partly bracketed initialization (6.7.7).
18542 -- A statement cannot be reached (6.8).
18543 -- A statement with no apparent effect is encountered (6.8).
18544 -- A constant expression is used as the controlling expression of a selection statement
18549 -- An incorrectly formed preprocessing group is encountered while skipping a
18550 preprocessing group (6.10.1).
18551 -- An unrecognized #pragma directive is encountered (6.10.6).
18558 1 This annex collects some information about portability that appears in this International
18560 J.1 Unspecified behavior
18561 1 The following are unspecified:
18562 -- The manner and timing of static initialization (5.1.2).
18563 -- The termination status returned to the hosted environment if the return type of main
18564 is not compatible with int (5.1.2.2.3).
18565 -- The behavior of the display device if a printing character is written when the active
18566 position is at the final position of a line (5.2.2).
18567 -- The behavior of the display device if a backspace character is written when the active
18568 position is at the initial position of a line (5.2.2).
18569 -- The behavior of the display device if a horizontal tab character is written when the
18570 active position is at or past the last defined horizontal tabulation position (5.2.2).
18571 -- The behavior of the display device if a vertical tab character is written when the active
18572 position is at or past the last defined vertical tabulation position (5.2.2).
18573 -- How an extended source character that does not correspond to a universal character
18574 name counts toward the significant initial characters in an external identifier (5.2.4.1).
18575 -- Many aspects of the representations of types (6.2.6).
18576 -- The value of padding bytes when storing values in structures or unions (6.2.6.1).
18577 -- The value of a union member other than the last one stored into (6.2.6.1).
18578 -- The representation used when storing a value in an object that has more than one
18579 object representation for that value (6.2.6.1).
18580 -- The values of any padding bits in integer representations (6.2.6.2).
18581 -- Whether certain operators can generate negative zeros and whether a negative zero
18582 becomes a normal zero when stored in an object (6.2.6.2).
18583 -- Whether two string literals result in distinct arrays (6.4.5).
18584 -- The order in which subexpressions are evaluated and the order in which side effects
18585 take place, except as specified for the function-call (), &&, ||, ?:, and comma
18590 -- The order in which the function designator, arguments, and subexpressions within the
18591 arguments are evaluated in a function call (6.5.2.2).
18592 -- The order of side effects among compound literal initialization list expressions
18594 -- The order in which the operands of an assignment operator are evaluated (6.5.16).
18595 -- The alignment of the addressable storage unit allocated to hold a bit-field (6.7.2.1).
18596 -- Whether a call to an inline function uses the inline definition or the external definition
18597 of the function (6.7.4).
18598 -- Whether or not a size expression is evaluated when it is part of the operand of a
18599 sizeof operator and changing the value of the size expression would not affect the
18600 result of the operator (6.7.5.2).
18601 -- The order in which any side effects occur among the initialization list expressions in
18602 an initializer (6.7.8).
18603 -- The layout of storage for function parameters (6.9.1).
18604 -- When a fully expanded macro replacement list contains a function-like macro name
18605 as its last preprocessing token and the next preprocessing token from the source file is
18606 a (, and the fully expanded replacement of that macro ends with the name of the first
18607 macro and the next preprocessing token from the source file is again a (, whether that
18608 is considered a nested replacement (6.10.3).
18609 -- The order in which # and ## operations are evaluated during macro substitution
18610 (6.10.3.2, 6.10.3.3).
18611 -- Whether errno is a macro or an identifier with external linkage (7.5).
18612 -- The state of the floating-point status flags when execution passes from a part of the
18613 program translated with FENV_ACCESS ''off'' to a part translated with
18614 FENV_ACCESS ''on'' (7.6.1).
18615 -- The order in which feraiseexcept raises floating-point exceptions, except as
18616 stated in F.7.6 (7.6.2.3).
18617 -- Whether math_errhandling is a macro or an identifier with external linkage
18619 -- The results of the frexp functions when the specified value is not a floating-point
18621 -- The numeric result of the ilogb functions when the correct value is outside the
18622 range of the return type (7.12.6.5, F.9.3.5).
18623 -- The result of rounding when the value is out of range (7.12.9.5, 7.12.9.7, F.9.6.5).
18627 -- The value stored by the remquo functions in the object pointed to by quo when y is
18629 -- Whether setjmp is a macro or an identifier with external linkage (7.13).
18630 -- Whether va_copy and va_end are macros or identifiers with external linkage
18632 -- The hexadecimal digit before the decimal point when a non-normalized floating-point
18633 number is printed with an a or A conversion specifier (7.19.6.1, 7.24.2.1).
18634 -- The value of the file position indicator after a successful call to the ungetc function
18635 for a text stream, or the ungetwc function for any stream, until all pushed-back
18636 characters are read or discarded (7.19.7.11, 7.24.3.10).
18637 -- The details of the value stored by the fgetpos function (7.19.9.1).
18638 -- The details of the value returned by the ftell function for a text stream (7.19.9.4).
18639 -- Whether the strtod, strtof, strtold, wcstod, wcstof, and wcstold
18640 functions convert a minus-signed sequence to a negative number directly or by
18641 negating the value resulting from converting the corresponding unsigned sequence
18642 (7.20.1.3, 7.24.4.1.1).
18643 -- The order and contiguity of storage allocated by successive calls to the calloc,
18644 malloc, and realloc functions (7.20.3).
18645 -- The amount of storage allocated by a successful call to the calloc, malloc, or
18646 realloc function when 0 bytes was requested (7.20.3).
18647 -- Which of two elements that compare as equal is matched by the bsearch function
18649 -- The order of two elements that compare as equal in an array sorted by the qsort
18650 function (7.20.5.2).
18651 -- The encoding of the calendar time returned by the time function (7.23.2.4).
18652 -- The characters stored by the strftime or wcsftime function if any of the time
18653 values being converted is outside the normal range (7.23.3.5, 7.24.5.1).
18654 -- The conversion state after an encoding error occurs (7.24.6.3.2, 7.24.6.3.3, 7.24.6.4.1,
18656 -- The resulting value when the ''invalid'' floating-point exception is raised during
18657 IEC 60559 floating to integer conversion (F.4).
18658 -- Whether conversion of non-integer IEC 60559 floating values to integer raises the
18659 ''inexact'' floating-point exception (F.4).
18663 -- Whether or when library functions in <math.h> raise the ''inexact'' floating-point
18664 exception in an IEC 60559 conformant implementation (F.9).
18665 -- Whether or when library functions in <math.h> raise an undeserved ''underflow''
18666 floating-point exception in an IEC 60559 conformant implementation (F.9).
18667 -- The exponent value stored by frexp for a NaN or infinity (F.9.3.4).
18668 -- The numeric result returned by the lrint, llrint, lround, and llround
18669 functions if the rounded value is outside the range of the return type (F.9.6.5, F.9.6.7).
18670 -- The sign of one part of the complex result of several math functions for certain
18671 exceptional values in IEC 60559 compatible implementations (G.6.1.1, G.6.2.2,
18672 G.6.2.3, G.6.2.4, G.6.2.5, G.6.2.6, G.6.3.1, G.6.4.2).
18673 J.2 Undefined behavior
18674 1 The behavior is undefined in the following circumstances:
18675 -- A ''shall'' or ''shall not'' requirement that appears outside of a constraint is violated
18677 -- A nonempty source file does not end in a new-line character which is not immediately
18678 preceded by a backslash character or ends in a partial preprocessing token or
18680 -- Token concatenation produces a character sequence matching the syntax of a
18681 universal character name (5.1.1.2).
18682 -- A program in a hosted environment does not define a function named main using one
18683 of the specified forms (5.1.2.2.1).
18684 -- A character not in the basic source character set is encountered in a source file, except
18685 in an identifier, a character constant, a string literal, a header name, a comment, or a
18686 preprocessing token that is never converted to a token (5.2.1).
18687 -- An identifier, comment, string literal, character constant, or header name contains an
18688 invalid multibyte character or does not begin and end in the initial shift state (5.2.1.2).
18689 -- The same identifier has both internal and external linkage in the same translation unit
18691 -- An object is referred to outside of its lifetime (6.2.4).
18692 -- The value of a pointer to an object whose lifetime has ended is used (6.2.4).
18693 -- The value of an object with automatic storage duration is used while it is
18694 indeterminate (6.2.4, 6.7.8, 6.8).
18695 -- A trap representation is read by an lvalue expression that does not have character type
18700 -- A trap representation is produced by a side effect that modifies any part of the object
18701 using an lvalue expression that does not have character type (6.2.6.1).
18702 -- The arguments to certain operators are such that could produce a negative zero result,
18703 but the implementation does not support negative zeros (6.2.6.2).
18704 -- Two declarations of the same object or function specify types that are not compatible
18706 -- Conversion to or from an integer type produces a value outside the range that can be
18707 represented (6.3.1.4).
18708 -- Demotion of one real floating type to another produces a value outside the range that
18709 can be represented (6.3.1.5).
18710 -- An lvalue does not designate an object when evaluated (6.3.2.1).
18711 -- A non-array lvalue with an incomplete type is used in a context that requires the value
18712 of the designated object (6.3.2.1).
18713 -- An lvalue having array type is converted to a pointer to the initial element of the
18714 array, and the array object has register storage class (6.3.2.1).
18715 -- An attempt is made to use the value of a void expression, or an implicit or explicit
18716 conversion (except to void) is applied to a void expression (6.3.2.2).
18717 -- Conversion of a pointer to an integer type produces a value outside the range that can
18718 be represented (6.3.2.3).
18719 -- Conversion between two pointer types produces a result that is incorrectly aligned
18721 -- A pointer is used to call a function whose type is not compatible with the pointed-to
18723 -- An unmatched ' or " character is encountered on a logical source line during
18724 tokenization (6.4).
18725 -- A reserved keyword token is used in translation phase 7 or 8 for some purpose other
18726 than as a keyword (6.4.1).
18727 -- A universal character name in an identifier does not designate a character whose
18728 encoding falls into one of the specified ranges (6.4.2.1).
18729 -- The initial character of an identifier is a universal character name designating a digit
18731 -- Two identifiers differ only in nonsignificant characters (6.4.2.1).
18732 -- The identifier __func__ is explicitly declared (6.4.2.2).
18736 -- The program attempts to modify a string literal (6.4.5).
18737 -- The characters ', \, ", //, or /* occur in the sequence between the < and >
18738 delimiters, or the characters ', \, //, or /* occur in the sequence between the "
18739 delimiters, in a header name preprocessing token (6.4.7).
18740 -- Between two sequence points, an object is modified more than once, or is modified
18741 and the prior value is read other than to determine the value to be stored (6.5).
18742 -- An exceptional condition occurs during the evaluation of an expression (6.5).
18743 -- An object has its stored value accessed other than by an lvalue of an allowable type
18745 -- An attempt is made to modify the result of a function call, a conditional operator, an
18746 assignment operator, or a comma operator, or to access it after the next sequence
18747 point (6.5.2.2, 6.5.15, 6.5.16, 6.5.17).
18748 -- For a call to a function without a function prototype in scope, the number of
18749 arguments does not equal the number of parameters (6.5.2.2).
18750 -- For call to a function without a function prototype in scope where the function is
18751 defined with a function prototype, either the prototype ends with an ellipsis or the
18752 types of the arguments after promotion are not compatible with the types of the
18753 parameters (6.5.2.2).
18754 -- For a call to a function without a function prototype in scope where the function is not
18755 defined with a function prototype, the types of the arguments after promotion are not
18756 compatible with those of the parameters after promotion (with certain exceptions)
18758 -- A function is defined with a type that is not compatible with the type (of the
18759 expression) pointed to by the expression that denotes the called function (6.5.2.2).
18760 -- The operand of the unary * operator has an invalid value (6.5.3.2).
18761 -- A pointer is converted to other than an integer or pointer type (6.5.4).
18762 -- The value of the second operand of the / or % operator is zero (6.5.5).
18763 -- Addition or subtraction of a pointer into, or just beyond, an array object and an
18764 integer type produces a result that does not point into, or just beyond, the same array
18766 -- Addition or subtraction of a pointer into, or just beyond, an array object and an
18767 integer type produces a result that points just beyond the array object and is used as
18768 the operand of a unary * operator that is evaluated (6.5.6).
18769 -- Pointers that do not point into, or just beyond, the same array object are subtracted
18774 -- An array subscript is out of range, even if an object is apparently accessible with the
18775 given subscript (as in the lvalue expression a[1][7] given the declaration int
18777 -- The result of subtracting two pointers is not representable in an object of type
18779 -- An expression is shifted by a negative number or by an amount greater than or equal
18780 to the width of the promoted expression (6.5.7).
18781 -- An expression having signed promoted type is left-shifted and either the value of the
18782 expression is negative or the result of shifting would be not be representable in the
18783 promoted type (6.5.7).
18784 -- Pointers that do not point to the same aggregate or union (nor just beyond the same
18785 array object) are compared using relational operators (6.5.8).
18786 -- An object is assigned to an inexactly overlapping object or to an exactly overlapping
18787 object with incompatible type (6.5.16.1).
18788 -- An expression that is required to be an integer constant expression does not have an
18789 integer type; has operands that are not integer constants, enumeration constants,
18790 character constants, sizeof expressions whose results are integer constants, or
18791 immediately-cast floating constants; or contains casts (outside operands to sizeof
18792 operators) other than conversions of arithmetic types to integer types (6.6).
18793 -- A constant expression in an initializer is not, or does not evaluate to, one of the
18794 following: an arithmetic constant expression, a null pointer constant, an address
18795 constant, or an address constant for an object type plus or minus an integer constant
18797 -- An arithmetic constant expression does not have arithmetic type; has operands that
18798 are not integer constants, floating constants, enumeration constants, character
18799 constants, or sizeof expressions; or contains casts (outside operands to sizeof
18800 operators) other than conversions of arithmetic types to arithmetic types (6.6).
18801 -- The value of an object is accessed by an array-subscript [], member-access . or ->,
18802 address &, or indirection * operator or a pointer cast in creating an address constant
18804 -- An identifier for an object is declared with no linkage and the type of the object is
18805 incomplete after its declarator, or after its init-declarator if it has an initializer (6.7).
18806 -- A function is declared at block scope with an explicit storage-class specifier other
18807 than extern (6.7.1).
18808 -- A structure or union is defined as containing no named members (6.7.2.1).
18812 -- An attempt is made to access, or generate a pointer to just past, a flexible array
18813 member of a structure when the referenced object provides no elements for that array
18815 -- When the complete type is needed, an incomplete structure or union type is not
18816 completed in the same scope by another declaration of the tag that defines the content
18818 -- An attempt is made to modify an object defined with a const-qualified type through
18819 use of an lvalue with non-const-qualified type (6.7.3).
18820 -- An attempt is made to refer to an object defined with a volatile-qualified type through
18821 use of an lvalue with non-volatile-qualified type (6.7.3).
18822 -- The specification of a function type includes any type qualifiers (6.7.3).
18823 -- Two qualified types that are required to be compatible do not have the identically
18824 qualified version of a compatible type (6.7.3).
18825 -- An object which has been modified is accessed through a restrict-qualified pointer to
18826 a const-qualified type, or through a restrict-qualified pointer and another pointer that
18827 are not both based on the same object (6.7.3.1).
18828 -- A restrict-qualified pointer is assigned a value based on another restricted pointer
18829 whose associated block neither began execution before the block associated with this
18830 pointer, nor ended before the assignment (6.7.3.1).
18831 -- A function with external linkage is declared with an inline function specifier, but is
18832 not also defined in the same translation unit (6.7.4).
18833 -- Two pointer types that are required to be compatible are not identically qualified, or
18834 are not pointers to compatible types (6.7.5.1).
18835 -- The size expression in an array declaration is not a constant expression and evaluates
18836 at program execution time to a nonpositive value (6.7.5.2).
18837 -- In a context requiring two array types to be compatible, they do not have compatible
18838 element types, or their size specifiers evaluate to unequal values (6.7.5.2).
18839 -- A declaration of an array parameter includes the keyword static within the [ and
18840 ] and the corresponding argument does not provide access to the first element of an
18841 array with at least the specified number of elements (6.7.5.3).
18842 -- A storage-class specifier or type qualifier modifies the keyword void as a function
18843 parameter type list (6.7.5.3).
18844 -- In a context requiring two function types to be compatible, they do not have
18845 compatible return types, or their parameters disagree in use of the ellipsis terminator
18846 or the number and type of parameters (after default argument promotion, when there
18847 is no parameter type list or when one type is specified by a function definition with an
18851 identifier list) (6.7.5.3).
18852 -- The value of an unnamed member of a structure or union is used (6.7.8).
18853 -- The initializer for a scalar is neither a single expression nor a single expression
18854 enclosed in braces (6.7.8).
18855 -- The initializer for a structure or union object that has automatic storage duration is
18856 neither an initializer list nor a single expression that has compatible structure or union
18858 -- The initializer for an aggregate or union, other than an array initialized by a string
18859 literal, is not a brace-enclosed list of initializers for its elements or members (6.7.8).
18860 -- An identifier with external linkage is used, but in the program there does not exist
18861 exactly one external definition for the identifier, or the identifier is not used and there
18862 exist multiple external definitions for the identifier (6.9).
18863 -- A function definition includes an identifier list, but the types of the parameters are not
18864 declared in a following declaration list (6.9.1).
18865 -- An adjusted parameter type in a function definition is not an object type (6.9.1).
18866 -- A function that accepts a variable number of arguments is defined without a
18867 parameter type list that ends with the ellipsis notation (6.9.1).
18868 -- The } that terminates a function is reached, and the value of the function call is used
18869 by the caller (6.9.1).
18870 -- An identifier for an object with internal linkage and an incomplete type is declared
18871 with a tentative definition (6.9.2).
18872 -- The token defined is generated during the expansion of a #if or #elif
18873 preprocessing directive, or the use of the defined unary operator does not match
18874 one of the two specified forms prior to macro replacement (6.10.1).
18875 -- The #include preprocessing directive that results after expansion does not match
18876 one of the two header name forms (6.10.2).
18877 -- The character sequence in an #include preprocessing directive does not start with a
18879 -- There are sequences of preprocessing tokens within the list of macro arguments that
18880 would otherwise act as preprocessing directives (6.10.3).
18881 -- The result of the preprocessing operator # is not a valid character string literal
18883 -- The result of the preprocessing operator ## is not a valid preprocessing token
18888 -- The #line preprocessing directive that results after expansion does not match one of
18889 the two well-defined forms, or its digit sequence specifies zero or a number greater
18890 than 2147483647 (6.10.4).
18891 -- A non-STDC #pragma preprocessing directive that is documented as causing
18892 translation failure or some other form of undefined behavior is encountered (6.10.6).
18893 -- A #pragma STDC preprocessing directive does not match one of the well-defined
18895 -- The name of a predefined macro, or the identifier defined, is the subject of a
18896 #define or #undef preprocessing directive (6.10.8).
18897 -- An attempt is made to copy an object to an overlapping object by use of a library
18898 function, other than as explicitly allowed (e.g., memmove) (clause 7).
18899 -- A file with the same name as one of the standard headers, not provided as part of the
18900 implementation, is placed in any of the standard places that are searched for included
18901 source files (7.1.2).
18902 -- A header is included within an external declaration or definition (7.1.2).
18903 -- A function, object, type, or macro that is specified as being declared or defined by
18904 some standard header is used before any header that declares or defines it is included
18906 -- A standard header is included while a macro is defined with the same name as a
18908 -- The program attempts to declare a library function itself, rather than via a standard
18909 header, but the declaration does not have external linkage (7.1.2).
18910 -- The program declares or defines a reserved identifier, other than as allowed by 7.1.4
18912 -- The program removes the definition of a macro whose name begins with an
18913 underscore and either an uppercase letter or another underscore (7.1.3).
18914 -- An argument to a library function has an invalid value or a type not expected by a
18915 function with variable number of arguments (7.1.4).
18916 -- The pointer passed to a library function array parameter does not have a value such
18917 that all address computations and object accesses are valid (7.1.4).
18918 -- The macro definition of assert is suppressed in order to access an actual function
18920 -- The argument to the assert macro does not have a scalar type (7.2).
18921 -- The CX_LIMITED_RANGE, FENV_ACCESS, or FP_CONTRACT pragma is used in
18922 any context other than outside all external declarations or preceding all explicit
18926 declarations and statements inside a compound statement (7.3.4, 7.6.1, 7.12.2).
18927 -- The value of an argument to a character handling function is neither equal to the value
18928 of EOF nor representable as an unsigned char (7.4).
18929 -- A macro definition of errno is suppressed in order to access an actual object, or the
18930 program defines an identifier with the name errno (7.5).
18931 -- Part of the program tests floating-point status flags, sets floating-point control modes,
18932 or runs under non-default mode settings, but was translated with the state for the
18933 FENV_ACCESS pragma ''off'' (7.6.1).
18934 -- The exception-mask argument for one of the functions that provide access to the
18935 floating-point status flags has a nonzero value not obtained by bitwise OR of the
18936 floating-point exception macros (7.6.2).
18937 -- The fesetexceptflag function is used to set floating-point status flags that were
18938 not specified in the call to the fegetexceptflag function that provided the value
18939 of the corresponding fexcept_t object (7.6.2.4).
18940 -- The argument to fesetenv or feupdateenv is neither an object set by a call to
18941 fegetenv or feholdexcept, nor is it an environment macro (7.6.4.3, 7.6.4.4).
18942 -- The value of the result of an integer arithmetic or conversion function cannot be
18943 represented (7.8.2.1, 7.8.2.2, 7.8.2.3, 7.8.2.4, 7.20.6.1, 7.20.6.2, 7.20.1).
18944 -- The program modifies the string pointed to by the value returned by the setlocale
18945 function (7.11.1.1).
18946 -- The program modifies the structure pointed to by the value returned by the
18947 localeconv function (7.11.2.1).
18948 -- A macro definition of math_errhandling is suppressed or the program defines
18949 an identifier with the name math_errhandling (7.12).
18950 -- An argument to a floating-point classification or comparison macro is not of real
18951 floating type (7.12.3, 7.12.14).
18952 -- A macro definition of setjmp is suppressed in order to access an actual function, or
18953 the program defines an external identifier with the name setjmp (7.13).
18954 -- An invocation of the setjmp macro occurs other than in an allowed context
18956 -- The longjmp function is invoked to restore a nonexistent environment (7.13.2.1).
18957 -- After a longjmp, there is an attempt to access the value of an object of automatic
18958 storage class with non-volatile-qualified type, local to the function containing the
18959 invocation of the corresponding setjmp macro, that was changed between the
18960 setjmp invocation and longjmp call (7.13.2.1).
18964 -- The program specifies an invalid pointer to a signal handler function (7.14.1.1).
18965 -- A signal handler returns when the signal corresponded to a computational exception
18967 -- A signal occurs as the result of calling the abort or raise function, and the signal
18968 handler calls the raise function (7.14.1.1).
18969 -- A signal occurs other than as the result of calling the abort or raise function, and
18970 the signal handler refers to an object with static storage duration other than by
18971 assigning a value to an object declared as volatile sig_atomic_t, or calls any
18972 function in the standard library other than the abort function, the _Exit function,
18973 or the signal function (for the same signal number) (7.14.1.1).
18974 -- The value of errno is referred to after a signal occurred other than as the result of
18975 calling the abort or raise function and the corresponding signal handler obtained
18976 a SIG_ERR return from a call to the signal function (7.14.1.1).
18977 -- A signal is generated by an asynchronous signal handler (7.14.1.1).
18978 -- A function with a variable number of arguments attempts to access its varying
18979 arguments other than through a properly declared and initialized va_list object, or
18980 before the va_start macro is invoked (7.15, 7.15.1.1, 7.15.1.4).
18981 -- The macro va_arg is invoked using the parameter ap that was passed to a function
18982 that invoked the macro va_arg with the same parameter (7.15).
18983 -- A macro definition of va_start, va_arg, va_copy, or va_end is suppressed in
18984 order to access an actual function, or the program defines an external identifier with
18985 the name va_copy or va_end (7.15.1).
18986 -- The va_start or va_copy macro is invoked without a corresponding invocation
18987 of the va_end macro in the same function, or vice versa (7.15.1, 7.15.1.2, 7.15.1.3,
18989 -- The type parameter to the va_arg macro is not such that a pointer to an object of
18990 that type can be obtained simply by postfixing a * (7.15.1.1).
18991 -- The va_arg macro is invoked when there is no actual next argument, or with a
18992 specified type that is not compatible with the promoted type of the actual next
18993 argument, with certain exceptions (7.15.1.1).
18994 -- The va_copy or va_start macro is called to initialize a va_list that was
18995 previously initialized by either macro without an intervening invocation of the
18996 va_end macro for the same va_list (7.15.1.2, 7.15.1.4).
18997 -- The parameter parmN of a va_start macro is declared with the register
18998 storage class, with a function or array type, or with a type that is not compatible with
18999 the type that results after application of the default argument promotions (7.15.1.4).
19003 -- The member designator parameter of an offsetof macro is an invalid right
19004 operand of the . operator for the type parameter, or designates a bit-field (7.17).
19005 -- The argument in an instance of one of the integer-constant macros is not a decimal,
19006 octal, or hexadecimal constant, or it has a value that exceeds the limits for the
19007 corresponding type (7.18.4).
19008 -- A byte input/output function is applied to a wide-oriented stream, or a wide character
19009 input/output function is applied to a byte-oriented stream (7.19.2).
19010 -- Use is made of any portion of a file beyond the most recent wide character written to
19011 a wide-oriented stream (7.19.2).
19012 -- The value of a pointer to a FILE object is used after the associated file is closed
19014 -- The stream for the fflush function points to an input stream or to an update stream
19015 in which the most recent operation was input (7.19.5.2).
19016 -- The string pointed to by the mode argument in a call to the fopen function does not
19017 exactly match one of the specified character sequences (7.19.5.3).
19018 -- An output operation on an update stream is followed by an input operation without an
19019 intervening call to the fflush function or a file positioning function, or an input
19020 operation on an update stream is followed by an output operation with an intervening
19021 call to a file positioning function (7.19.5.3).
19022 -- An attempt is made to use the contents of the array that was supplied in a call to the
19023 setvbuf function (7.19.5.6).
19024 -- There are insufficient arguments for the format in a call to one of the formatted
19025 input/output functions, or an argument does not have an appropriate type (7.19.6.1,
19026 7.19.6.2, 7.24.2.1, 7.24.2.2).
19027 -- The format in a call to one of the formatted input/output functions or to the
19028 strftime or wcsftime function is not a valid multibyte character sequence that
19029 begins and ends in its initial shift state (7.19.6.1, 7.19.6.2, 7.23.3.5, 7.24.2.1, 7.24.2.2,
19031 -- In a call to one of the formatted output functions, a precision appears with a
19032 conversion specifier other than those described (7.19.6.1, 7.24.2.1).
19033 -- A conversion specification for a formatted output function uses an asterisk to denote
19034 an argument-supplied field width or precision, but the corresponding argument is not
19035 provided (7.19.6.1, 7.24.2.1).
19036 -- A conversion specification for a formatted output function uses a # or 0 flag with a
19037 conversion specifier other than those described (7.19.6.1, 7.24.2.1).
19041 -- A conversion specification for one of the formatted input/output functions uses a
19042 length modifier with a conversion specifier other than those described (7.19.6.1,
19043 7.19.6.2, 7.24.2.1, 7.24.2.2).
19044 -- An s conversion specifier is encountered by one of the formatted output functions,
19045 and the argument is missing the null terminator (unless a precision is specified that
19046 does not require null termination) (7.19.6.1, 7.24.2.1).
19047 -- An n conversion specification for one of the formatted input/output functions includes
19048 any flags, an assignment-suppressing character, a field width, or a precision (7.19.6.1,
19049 7.19.6.2, 7.24.2.1, 7.24.2.2).
19050 -- A % conversion specifier is encountered by one of the formatted input/output
19051 functions, but the complete conversion specification is not exactly %% (7.19.6.1,
19052 7.19.6.2, 7.24.2.1, 7.24.2.2).
19053 -- An invalid conversion specification is found in the format for one of the formatted
19054 input/output functions, or the strftime or wcsftime function (7.19.6.1, 7.19.6.2,
19055 7.23.3.5, 7.24.2.1, 7.24.2.2, 7.24.5.1).
19056 -- The number of characters transmitted by a formatted output function is greater than
19057 INT_MAX (7.19.6.1, 7.19.6.3, 7.19.6.8, 7.19.6.10).
19058 -- The result of a conversion by one of the formatted input functions cannot be
19059 represented in the corresponding object, or the receiving object does not have an
19060 appropriate type (7.19.6.2, 7.24.2.2).
19061 -- A c, s, or [ conversion specifier is encountered by one of the formatted input
19062 functions, and the array pointed to by the corresponding argument is not large enough
19063 to accept the input sequence (and a null terminator if the conversion specifier is s or
19064 [) (7.19.6.2, 7.24.2.2).
19065 -- A c, s, or [ conversion specifier with an l qualifier is encountered by one of the
19066 formatted input functions, but the input is not a valid multibyte character sequence
19067 that begins in the initial shift state (7.19.6.2, 7.24.2.2).
19068 -- The input item for a %p conversion by one of the formatted input functions is not a
19069 value converted earlier during the same program execution (7.19.6.2, 7.24.2.2).
19070 -- The vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf,
19071 vsscanf, vfwprintf, vfwscanf, vswprintf, vswscanf, vwprintf, or
19072 vwscanf function is called with an improperly initialized va_list argument, or
19073 the argument is used (other than in an invocation of va_end) after the function
19074 returns (7.19.6.8, 7.19.6.9, 7.19.6.10, 7.19.6.11, 7.19.6.12, 7.19.6.13, 7.19.6.14,
19075 7.24.2.5, 7.24.2.6, 7.24.2.7, 7.24.2.8, 7.24.2.9, 7.24.2.10).
19076 -- The contents of the array supplied in a call to the fgets, gets, or fgetws function
19077 are used after a read error occurred (7.19.7.2, 7.19.7.7, 7.24.3.2).
19081 -- The file position indicator for a binary stream is used after a call to the ungetc
19082 function where its value was zero before the call (7.19.7.11).
19083 -- The file position indicator for a stream is used after an error occurred during a call to
19084 the fread or fwrite function (7.19.8.1, 7.19.8.2).
19085 -- A partial element read by a call to the fread function is used (7.19.8.1).
19086 -- The fseek function is called for a text stream with a nonzero offset and either the
19087 offset was not returned by a previous successful call to the ftell function on a
19088 stream associated with the same file or whence is not SEEK_SET (7.19.9.2).
19089 -- The fsetpos function is called to set a position that was not returned by a previous
19090 successful call to the fgetpos function on a stream associated with the same file
19092 -- A non-null pointer returned by a call to the calloc, malloc, or realloc function
19093 with a zero requested size is used to access an object (7.20.3).
19094 -- The value of a pointer that refers to space deallocated by a call to the free or
19095 realloc function is used (7.20.3).
19096 -- The pointer argument to the free or realloc function does not match a pointer
19097 earlier returned by calloc, malloc, or realloc, or the space has been
19098 deallocated by a call to free or realloc (7.20.3.2, 7.20.3.4).
19099 -- The value of the object allocated by the malloc function is used (7.20.3.3).
19100 -- The value of any bytes in a new object allocated by the realloc function beyond
19101 the size of the old object are used (7.20.3.4).
19102 -- The program executes more than one call to the exit function (7.20.4.3).
19103 -- During the call to a function registered with the atexit function, a call is made to
19104 the longjmp function that would terminate the call to the registered function
19106 -- The string set up by the getenv or strerror function is modified by the program
19107 (7.20.4.5, 7.21.6.2).
19108 -- A command is executed through the system function in a way that is documented as
19109 causing termination or some other form of undefined behavior (7.20.4.6).
19110 -- A searching or sorting utility function is called with an invalid pointer argument, even
19111 if the number of elements is zero (7.20.5).
19112 -- The comparison function called by a searching or sorting utility function alters the
19113 contents of the array being searched or sorted, or returns ordering values
19114 inconsistently (7.20.5).
19118 -- The array being searched by the bsearch function does not have its elements in
19119 proper order (7.20.5.1).
19120 -- The current conversion state is used by a multibyte/wide character conversion
19121 function after changing the LC_CTYPE category (7.20.7).
19122 -- A string or wide string utility function is instructed to access an array beyond the end
19123 of an object (7.21.1, 7.24.4).
19124 -- A string or wide string utility function is called with an invalid pointer argument, even
19125 if the length is zero (7.21.1, 7.24.4).
19126 -- The contents of the destination array are used after a call to the strxfrm,
19127 strftime, wcsxfrm, or wcsftime function in which the specified length was
19128 too small to hold the entire null-terminated result (7.21.4.5, 7.23.3.5, 7.24.4.4.4,
19130 -- The first argument in the very first call to the strtok or wcstok is a null pointer
19131 (7.21.5.8, 7.24.4.5.7).
19132 -- The type of an argument to a type-generic macro is not compatible with the type of
19133 the corresponding parameter of the selected function (7.22).
19134 -- A complex argument is supplied for a generic parameter of a type-generic macro that
19135 has no corresponding complex function (7.22).
19136 -- The argument corresponding to an s specifier without an l qualifier in a call to the
19137 fwprintf function does not point to a valid multibyte character sequence that
19138 begins in the initial shift state (7.24.2.11).
19139 -- In a call to the wcstok function, the object pointed to by ptr does not have the
19140 value stored by the previous call for the same wide string (7.24.4.5.7).
19141 -- An mbstate_t object is used inappropriately (7.24.6).
19142 -- The value of an argument of type wint_t to a wide character classification or case
19143 mapping function is neither equal to the value of WEOF nor representable as a
19145 -- The iswctype function is called using a different LC_CTYPE category from the
19146 one in effect for the call to the wctype function that returned the description
19148 -- The towctrans function is called using a different LC_CTYPE category from the
19149 one in effect for the call to the wctrans function that returned the description
19154 J.3 Implementation-defined behavior
19155 1 A conforming implementation is required to document its choice of behavior in each of
19156 the areas listed in this subclause. The following are implementation-defined:
19158 1 -- How a diagnostic is identified (3.10, 5.1.1.3).
19159 -- Whether each nonempty sequence of white-space characters other than new-line is
19160 retained or replaced by one space character in translation phase 3 (5.1.1.2).
19162 1 -- The mapping between physical source file multibyte characters and the source
19163 character set in translation phase 1 (5.1.1.2).
19164 -- The name and type of the function called at program startup in a freestanding
19165 environment (5.1.2.1).
19166 -- The effect of program termination in a freestanding environment (5.1.2.1).
19167 -- An alternative manner in which the main function may be defined (5.1.2.2.1).
19168 -- The values given to the strings pointed to by the argv argument to main (5.1.2.2.1).
19169 -- What constitutes an interactive device (5.1.2.3).
19170 -- The set of signals, their semantics, and their default handling (7.14).
19171 -- Signal values other than SIGFPE, SIGILL, and SIGSEGV that correspond to a
19172 computational exception (7.14.1.1).
19173 -- Signals for which the equivalent of signal(sig, SIG_IGN); is executed at
19174 program startup (7.14.1.1).
19175 -- The set of environment names and the method for altering the environment list used
19176 by the getenv function (7.20.4.5).
19177 -- The manner of execution of the string by the system function (7.20.4.6).
19179 1 -- Which additional multibyte characters may appear in identifiers and their
19180 correspondence to universal character names (6.4.2).
19181 -- The number of significant initial characters in an identifier (5.2.4.1, 6.4.2).
19186 1 -- The number of bits in a byte (3.6).
19187 -- The values of the members of the execution character set (5.2.1).
19188 -- The unique value of the member of the execution character set produced for each of
19189 the standard alphabetic escape sequences (5.2.2).
19190 -- The value of a char object into which has been stored any character other than a
19191 member of the basic execution character set (6.2.5).
19192 -- Which of signed char or unsigned char has the same range, representation,
19193 and behavior as ''plain'' char (6.2.5, 6.3.1.1).
19194 -- The mapping of members of the source character set (in character constants and string
19195 literals) to members of the execution character set (6.4.4.4, 5.1.1.2).
19196 -- The value of an integer character constant containing more than one character or
19197 containing a character or escape sequence that does not map to a single-byte
19198 execution character (6.4.4.4).
19199 -- The value of a wide character constant containing more than one multibyte character,
19200 or containing a multibyte character or escape sequence not represented in the
19201 extended execution character set (6.4.4.4).
19202 -- The current locale used to convert a wide character constant consisting of a single
19203 multibyte character that maps to a member of the extended execution character set
19204 into a corresponding wide character code (6.4.4.4).
19205 -- The current locale used to convert a wide string literal into corresponding wide
19206 character codes (6.4.5).
19207 -- The value of a string literal containing a multibyte character or escape sequence not
19208 represented in the execution character set (6.4.5).
19210 1 -- Any extended integer types that exist in the implementation (6.2.5).
19211 -- Whether signed integer types are represented using sign and magnitude, two's
19212 complement, or ones' complement, and whether the extraordinary value is a trap
19213 representation or an ordinary value (6.2.6.2).
19214 -- The rank of any extended integer type relative to another extended integer type with
19215 the same precision (6.3.1.1).
19216 -- The result of, or the signal raised by, converting an integer to a signed integer type
19217 when the value cannot be represented in an object of that type (6.3.1.3).
19221 -- The results of some bitwise operations on signed integers (6.5).
19222 J.3.6 Floating point
19223 1 -- The accuracy of the floating-point operations and of the library functions in
19224 <math.h> and <complex.h> that return floating-point results (5.2.4.2.2).
19225 -- The accuracy of the conversions between floating-point internal representations and
19226 string representations performed by the library functions in <stdio.h>,
19227 <stdlib.h>, and <wchar.h> (5.2.4.2.2).
19228 -- The rounding behaviors characterized by non-standard values of FLT_ROUNDS
19230 -- The evaluation methods characterized by non-standard negative values of
19231 FLT_EVAL_METHOD (5.2.4.2.2).
19232 -- The direction of rounding when an integer is converted to a floating-point number that
19233 cannot exactly represent the original value (6.3.1.4).
19234 -- The direction of rounding when a floating-point number is converted to a narrower
19235 floating-point number (6.3.1.5).
19236 -- How the nearest representable value or the larger or smaller representable value
19237 immediately adjacent to the nearest representable value is chosen for certain floating
19238 constants (6.4.4.2).
19239 -- Whether and how floating expressions are contracted when not disallowed by the
19240 FP_CONTRACT pragma (6.5).
19241 -- The default state for the FENV_ACCESS pragma (7.6.1).
19242 -- Additional floating-point exceptions, rounding modes, environments, and
19243 classifications, and their macro names (7.6, 7.12).
19244 -- The default state for the FP_CONTRACT pragma (7.12.2). *
19245 J.3.7 Arrays and pointers
19246 1 -- The result of converting a pointer to an integer or vice versa (6.3.2.3).
19247 -- The size of the result of subtracting two pointers to elements of the same array
19253 1 -- The extent to which suggestions made by using the register storage-class
19254 specifier are effective (6.7.1).
19255 -- The extent to which suggestions made by using the inline function specifier are
19257 J.3.9 Structures, unions, enumerations, and bit-fields
19258 1 -- Whether a ''plain'' int bit-field is treated as a signed int bit-field or as an
19259 unsigned int bit-field (6.7.2, 6.7.2.1).
19260 -- Allowable bit-field types other than _Bool, signed int, and unsigned int
19262 -- Whether a bit-field can straddle a storage-unit boundary (6.7.2.1).
19263 -- The order of allocation of bit-fields within a unit (6.7.2.1).
19264 -- The alignment of non-bit-field members of structures (6.7.2.1). This should present
19265 no problem unless binary data written by one implementation is read by another.
19266 -- The integer type compatible with each enumerated type (6.7.2.2).
19268 1 -- What constitutes an access to an object that has volatile-qualified type (6.7.3).
19269 J.3.11 Preprocessing directives
19270 1 -- The locations within #pragma directives where header name preprocessing tokens
19271 are recognized (6.4, 6.4.7).
19272 -- How sequences in both forms of header names are mapped to headers or external
19273 source file names (6.4.7).
19274 -- Whether the value of a character constant in a constant expression that controls
19275 conditional inclusion matches the value of the same character constant in the
19276 execution character set (6.10.1).
19277 -- Whether the value of a single-character character constant in a constant expression
19278 that controls conditional inclusion may have a negative value (6.10.1).
19279 -- The places that are searched for an included < > delimited header, and how the places
19280 are specified or the header is identified (6.10.2).
19281 -- How the named source file is searched for in an included " " delimited header
19283 -- The method by which preprocessing tokens (possibly resulting from macro
19284 expansion) in a #include directive are combined into a header name (6.10.2).
19288 -- The nesting limit for #include processing (6.10.2).
19289 -- Whether the # operator inserts a \ character before the \ character that begins a
19290 universal character name in a character constant or string literal (6.10.3.2).
19291 -- The behavior on each recognized non-STDC #pragma directive (6.10.6).
19292 -- The definitions for __DATE__ and __TIME__ when respectively, the date and
19293 time of translation are not available (6.10.8).
19294 J.3.12 Library functions
19295 1 -- Any library facilities available to a freestanding program, other than the minimal set
19296 required by clause 4 (5.1.2.1).
19297 -- The format of the diagnostic printed by the assert macro (7.2.1.1).
19298 -- The representation of the floating-point status flags stored by the
19299 fegetexceptflag function (7.6.2.2).
19300 -- Whether the feraiseexcept function raises the ''inexact'' floating-point
19301 exception in addition to the ''overflow'' or ''underflow'' floating-point exception
19303 -- Strings other than "C" and "" that may be passed as the second argument to the
19304 setlocale function (7.11.1.1).
19305 -- The types defined for float_t and double_t when the value of the
19306 FLT_EVAL_METHOD macro is less than 0 (7.12).
19307 -- Domain errors for the mathematics functions, other than those required by this
19308 International Standard (7.12.1).
19309 -- The values returned by the mathematics functions on domain errors (7.12.1).
19310 -- The values returned by the mathematics functions on underflow range errors, whether
19311 errno is set to the value of the macro ERANGE when the integer expression
19312 math_errhandling & MATH_ERRNO is nonzero, and whether the ''underflow''
19313 floating-point exception is raised when the integer expression math_errhandling
19314 & MATH_ERREXCEPT is nonzero. (7.12.1).
19315 -- Whether a domain error occurs or zero is returned when an fmod function has a
19316 second argument of zero (7.12.10.1).
19317 -- Whether a domain error occurs or zero is returned when a remainder function has
19318 a second argument of zero (7.12.10.2).
19319 -- The base-2 logarithm of the modulus used by the remquo functions in reducing the
19320 quotient (7.12.10.3).
19324 -- Whether a domain error occurs or zero is returned when a remquo function has a
19325 second argument of zero (7.12.10.3).
19326 -- Whether the equivalent of signal(sig, SIG_DFL); is executed prior to the call
19327 of a signal handler, and, if not, the blocking of signals that is performed (7.14.1.1).
19328 -- The null pointer constant to which the macro NULL expands (7.17).
19329 -- Whether the last line of a text stream requires a terminating new-line character
19331 -- Whether space characters that are written out to a text stream immediately before a
19332 new-line character appear when read in (7.19.2).
19333 -- The number of null characters that may be appended to data written to a binary
19335 -- Whether the file position indicator of an append-mode stream is initially positioned at
19336 the beginning or end of the file (7.19.3).
19337 -- Whether a write on a text stream causes the associated file to be truncated beyond that
19339 -- The characteristics of file buffering (7.19.3).
19340 -- Whether a zero-length file actually exists (7.19.3).
19341 -- The rules for composing valid file names (7.19.3).
19342 -- Whether the same file can be simultaneously open multiple times (7.19.3).
19343 -- The nature and choice of encodings used for multibyte characters in files (7.19.3).
19344 -- The effect of the remove function on an open file (7.19.4.1).
19345 -- The effect if a file with the new name exists prior to a call to the rename function
19347 -- Whether an open temporary file is removed upon abnormal program termination
19349 -- Which changes of mode are permitted (if any), and under what circumstances
19351 -- The style used to print an infinity or NaN, and the meaning of any n-char or n-wchar
19352 sequence printed for a NaN (7.19.6.1, 7.24.2.1).
19353 -- The output for %p conversion in the fprintf or fwprintf function (7.19.6.1,
19355 -- The interpretation of a - character that is neither the first nor the last character, nor
19356 the second where a ^ character is the first, in the scanlist for %[ conversion in the
19357 fscanf or fwscanf function (7.19.6.2, 7.24.2.1).
19361 -- The set of sequences matched by a %p conversion and the interpretation of the
19362 corresponding input item in the fscanf or fwscanf function (7.19.6.2, 7.24.2.2).
19363 -- The value to which the macro errno is set by the fgetpos, fsetpos, or ftell
19364 functions on failure (7.19.9.1, 7.19.9.3, 7.19.9.4).
19365 -- The meaning of any n-char or n-wchar sequence in a string representing a NaN that is
19366 converted by the strtod, strtof, strtold, wcstod, wcstof, or wcstold
19367 function (7.20.1.3, 7.24.4.1.1).
19368 -- Whether or not the strtod, strtof, strtold, wcstod, wcstof, or wcstold
19369 function sets errno to ERANGE when underflow occurs (7.20.1.3, 7.24.4.1.1).
19370 -- Whether the calloc, malloc, and realloc functions return a null pointer or a
19371 pointer to an allocated object when the size requested is zero (7.20.3).
19372 -- Whether open streams with unwritten buffered data are flushed, open streams are
19373 closed, or temporary files are removed when the abort or _Exit function is called
19374 (7.20.4.1, 7.20.4.4).
19375 -- The termination status returned to the host environment by the abort, exit, or
19376 _Exit function (7.20.4.1, 7.20.4.3, 7.20.4.4).
19377 -- The value returned by the system function when its argument is not a null pointer
19379 -- The local time zone and Daylight Saving Time (7.23.1).
19380 -- The range and precision of times representable in clock_t and time_t (7.23).
19381 -- The era for the clock function (7.23.2.1).
19382 -- The replacement string for the %Z specifier to the strftime, and wcsftime
19383 functions in the "C" locale (7.23.3.5, 7.24.5.1).
19384 -- Whether the functions in <math.h> honor the rounding direction mode in an
19385 IEC 60559 conformant implementation, unless explicitly specified otherwise (F.9).
19386 J.3.13 Architecture
19387 1 -- The values or expressions assigned to the macros specified in the headers
19388 <float.h>, <limits.h>, and <stdint.h> (5.2.4.2, 7.18.2, 7.18.3).
19389 -- The number, order, and encoding of bytes in any object (when not explicitly specified
19390 in this International Standard) (6.2.6.1).
19391 -- The value of the result of the sizeof operator (6.5.3.4).
19395 J.4 Locale-specific behavior
19396 1 The following characteristics of a hosted environment are locale-specific and are required
19397 to be documented by the implementation:
19398 -- Additional members of the source and execution character sets beyond the basic
19399 character set (5.2.1).
19400 -- The presence, meaning, and representation of additional multibyte characters in the
19401 execution character set beyond the basic character set (5.2.1.2).
19402 -- The shift states used for the encoding of multibyte characters (5.2.1.2).
19403 -- The direction of writing of successive printing characters (5.2.2).
19404 -- The decimal-point character (7.1.1).
19405 -- The set of printing characters (7.4, 7.25.2).
19406 -- The set of control characters (7.4, 7.25.2).
19407 -- The sets of characters tested for by the isalpha, isblank, islower, ispunct,
19408 isspace, isupper, iswalpha, iswblank, iswlower, iswpunct,
19409 iswspace, or iswupper functions (7.4.1.2, 7.4.1.3, 7.4.1.7, 7.4.1.9, 7.4.1.10,
19410 7.4.1.11, 7.25.2.1.2, 7.25.2.1.3, 7.25.2.1.7, 7.25.2.1.9, 7.25.2.1.10, 7.25.2.1.11).
19411 -- The native environment (7.11.1.1).
19412 -- Additional subject sequences accepted by the numeric conversion functions (7.20.1,
19414 -- The collation sequence of the execution character set (7.21.4.3, 7.24.4.4.2).
19415 -- The contents of the error message strings set up by the strerror function
19417 -- The formats for time and date (7.23.3.5, 7.24.5.1).
19418 -- Character mappings that are supported by the towctrans function (7.25.1).
19419 -- Character classifications that are supported by the iswctype function (7.25.1).
19423 J.5 Common extensions
19424 1 The following extensions are widely used in many systems, but are not portable to all
19425 implementations. The inclusion of any extension that may cause a strictly conforming
19426 program to become invalid renders an implementation nonconforming. Examples of such
19427 extensions are new keywords, extra library functions declared in standard headers, or
19428 predefined macros with names that do not begin with an underscore.
19429 J.5.1 Environment arguments
19430 1 In a hosted environment, the main function receives a third argument, char *envp[],
19431 that points to a null-terminated array of pointers to char, each of which points to a string
19432 that provides information about the environment for this execution of the program
19434 J.5.2 Specialized identifiers
19435 1 Characters other than the underscore _, letters, and digits, that are not part of the basic
19436 source character set (such as the dollar sign $, or characters in national character sets)
19437 may appear in an identifier (6.4.2).
19438 J.5.3 Lengths and cases of identifiers
19439 1 All characters in identifiers (with or without external linkage) are significant (6.4.2).
19440 J.5.4 Scopes of identifiers
19441 1 A function identifier, or the identifier of an object the declaration of which contains the
19442 keyword extern, has file scope (6.2.1).
19443 J.5.5 Writable string literals
19444 1 String literals are modifiable (in which case, identical string literals should denote distinct
19446 J.5.6 Other arithmetic types
19447 1 Additional arithmetic types, such as __int128 or double double, and their
19448 appropriate conversions are defined (6.2.5, 6.3.1). Additional floating types may have
19449 more range or precision than long double, may be used for evaluating expressions of
19450 other floating types, and may be used to define float_t or double_t.
19454 J.5.7 Function pointer casts
19455 1 A pointer to an object or to void may be cast to a pointer to a function, allowing data to
19456 be invoked as a function (6.5.4).
19457 2 A pointer to a function may be cast to a pointer to an object or to void, allowing a
19458 function to be inspected or modified (for example, by a debugger) (6.5.4).
19459 J.5.8 Extended bit-field types
19460 1 A bit-field may be declared with a type other than _Bool, unsigned int, or
19461 signed int, with an appropriate maximum width (6.7.2.1).
19462 J.5.9 The fortran keyword
19463 1 The fortran function specifier may be used in a function declaration to indicate that
19464 calls suitable for FORTRAN should be generated, or that a different representation for the
19465 external name is to be generated (6.7.4).
19466 J.5.10 The asm keyword
19467 1 The asm keyword may be used to insert assembly language directly into the translator
19468 output (6.8). The most common implementation is via a statement of the form:
19469 asm ( character-string-literal );
19470 J.5.11 Multiple external definitions
19471 1 There may be more than one external definition for the identifier of an object, with or
19472 without the explicit use of the keyword extern; if the definitions disagree, or more than
19473 one is initialized, the behavior is undefined (6.9.2).
19474 J.5.12 Predefined macro names
19475 1 Macro names that do not begin with an underscore, describing the translation and
19476 execution environments, are defined by the implementation before translation begins
19478 J.5.13 Floating-point status flags
19479 1 If any floating-point status flags are set on normal termination after all calls to functions
19480 registered by the atexit function have been made (see 7.20.4.3), the implementation
19481 writes some diagnostics indicating the fact to the stderr stream, if it is still open,
19485 J.5.14 Extra arguments for signal handlers
19486 1 Handlers for specific signals are called with extra arguments in addition to the signal
19488 J.5.15 Additional stream types and file-opening modes
19489 1 Additional mappings from files to streams are supported (7.19.2).
19490 2 Additional file-opening modes may be specified by characters appended to the mode
19491 argument of the fopen function (7.19.5.3).
19492 J.5.16 Defined file position indicator
19493 1 The file position indicator is decremented by each successful call to the ungetc or
19494 ungetwc function for a text stream, except if its value was zero before a call (7.19.7.11,
19496 J.5.17 Math error reporting
19497 1 Functions declared in <complex.h> and <math.h> raise SIGFPE to report errors
19498 instead of, or in addition to, setting errno or raising floating-point exceptions (7.3,
19505 1. ''The C Reference Manual'' by Dennis M. Ritchie, a version of which was
19506 published in The C Programming Language by Brian W. Kernighan and Dennis
19507 M. Ritchie, Prentice-Hall, Inc., (1978). Copyright owned by AT&T.
19508 2. 1984 /usr/group Standard by the /usr/group Standards Committee, Santa Clara,
19509 California, USA, November 1984.
19510 3. ANSI X3/TR-1-82 (1982), American National Dictionary for Information
19511 Processing Systems, Information Processing Systems Technical Report.
19512 4. ANSI/IEEE 754-1985, American National Standard for Binary Floating-Point
19514 5. ANSI/IEEE 854-1988, American National Standard for Radix-Independent
19515 Floating-Point Arithmetic.
19516 6. IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems,
19517 second edition (previously designated IEC 559:1989).
19518 7. ISO 31-11:1992, Quantities and units -- Part 11: Mathematical signs and
19519 symbols for use in the physical sciences and technology.
19520 8. ISO/IEC 646:1991, Information technology -- ISO 7-bit coded character set for
19521 information interchange.
19522 9. ISO/IEC 2382-1:1993, Information technology -- Vocabulary -- Part 1:
19524 10. ISO 4217:1995, Codes for the representation of currencies and funds.
19525 11. ISO 8601:1988, Data elements and interchange formats -- Information
19526 interchange -- Representation of dates and times.
19527 12. ISO/IEC 9899:1990, Programming languages -- C.
19528 13. ISO/IEC 9899/COR1:1994, Technical Corrigendum 1.
19529 14. ISO/IEC 9899/COR2:1996, Technical Corrigendum 2.
19530 15. ISO/IEC 9899/AMD1:1995, Amendment 1 to ISO/IEC 9899:1990 C Integrity.
19531 16. ISO/IEC 9945-2:1993, Information technology -- Portable Operating System
19532 Interface (POSIX) -- Part 2: Shell and Utilities.
19533 17. ISO/IEC TR 10176:1998, Information technology -- Guidelines for the
19534 preparation of programming language standards.
19535 18. ISO/IEC 10646-1:1993, Information technology -- Universal Multiple-Octet
19536 Coded Character Set (UCS) -- Part 1: Architecture and Basic Multilingual Plane.
19540 19. ISO/IEC 10646-1/COR1:1996, Technical Corrigendum 1 to
19541 ISO/IEC 10646-1:1993.
19542 20. ISO/IEC 10646-1/COR2:1998, Technical Corrigendum 2 to
19543 ISO/IEC 10646-1:1993.
19544 21. ISO/IEC 10646-1/AMD1:1996, Amendment 1 to ISO/IEC 10646-1:1993
19545 Transformation Format for 16 planes of group 00 (UTF-16).
19546 22. ISO/IEC 10646-1/AMD2:1996, Amendment 2 to ISO/IEC 10646-1:1993 UCS
19547 Transformation Format 8 (UTF-8).
19548 23. ISO/IEC 10646-1/AMD3:1996, Amendment 3 to ISO/IEC 10646-1:1993.
19549 24. ISO/IEC 10646-1/AMD4:1996, Amendment 4 to ISO/IEC 10646-1:1993.
19550 25. ISO/IEC 10646-1/AMD5:1998, Amendment 5 to ISO/IEC 10646-1:1993 Hangul
19552 26. ISO/IEC 10646-1/AMD6:1997, Amendment 6 to ISO/IEC 10646-1:1993 Tibetan.
19553 27. ISO/IEC 10646-1/AMD7:1997, Amendment 7 to ISO/IEC 10646-1:1993 33
19554 additional characters.
19555 28. ISO/IEC 10646-1/AMD8:1997, Amendment 8 to ISO/IEC 10646-1:1993.
19556 29. ISO/IEC 10646-1/AMD9:1997, Amendment 9 to ISO/IEC 10646-1:1993
19557 Identifiers for characters.
19558 30. ISO/IEC 10646-1/AMD10:1998, Amendment 10 to ISO/IEC 10646-1:1993
19560 31. ISO/IEC 10646-1/AMD11:1998, Amendment 11 to ISO/IEC 10646-1:1993
19561 Unified Canadian Aboriginal Syllabics.
19562 32. ISO/IEC 10646-1/AMD12:1998, Amendment 12 to ISO/IEC 10646-1:1993
19564 33. ISO/IEC 10967-1:1994, Information technology -- Language independent
19565 arithmetic -- Part 1: Integer and floating point arithmetic.
19574 ??? x ???, 3.18 , (comma punctuator), 6.5.2, 6.7, 6.7.2.1, 6.7.2.2,
19576 ??? x ???, 3.19 - (subtraction operator), 6.5.6, F.3, G.5.2
19577 ! (logical negation operator), 6.5.3.3 - (unary minus operator), 6.5.3.3, F.3
19578 != (inequality operator), 6.5.9 -- (postfix decrement operator), 6.3.2.1, 6.5.2.4
19579 # operator, 6.10.3.2 -- (prefix decrement operator), 6.3.2.1, 6.5.3.1
19580 # preprocessing directive, 6.10.7 -= (subtraction assignment operator), 6.5.16.2
19581 # punctuator, 6.10 -> (structure/union pointer operator), 6.5.2.3
19582 ## operator, 6.10.3.3 . (structure/union member operator), 6.3.2.1,
19583 #define preprocessing directive, 6.10.3 6.5.2.3
19584 #elif preprocessing directive, 6.10.1 . punctuator, 6.7.8
19585 #else preprocessing directive, 6.10.1 ... (ellipsis punctuator), 6.5.2.2, 6.7.5.3, 6.10.3
19586 #endif preprocessing directive, 6.10.1 / (division operator), 6.5.5, F.3, G.5.1
19587 #error preprocessing directive, 4, 6.10.5 /* */ (comment delimiters), 6.4.9
19588 #if preprocessing directive, 5.2.4.2.1, 5.2.4.2.2, // (comment delimiter), 6.4.9
19589 6.10.1, 7.1.4 /= (division assignment operator), 6.5.16.2
19590 #ifdef preprocessing directive, 6.10.1 : (colon punctuator), 6.7.2.1
19591 #ifndef preprocessing directive, 6.10.1 :> (alternative spelling of ]), 6.4.6
19592 #include preprocessing directive, 5.1.1.2, ; (semicolon punctuator), 6.7, 6.7.2.1, 6.8.3,
19593 6.10.2 6.8.5, 6.8.6
19594 #line preprocessing directive, 6.10.4 < (less-than operator), 6.5.8
19595 #pragma preprocessing directive, 6.10.6 <% (alternative spelling of {), 6.4.6
19596 #undef preprocessing directive, 6.10.3.5, 7.1.3, <: (alternative spelling of [), 6.4.6
19597 7.1.4 << (left-shift operator), 6.5.7
19598 % (remainder operator), 6.5.5 <<= (left-shift assignment operator), 6.5.16.2
19599 %: (alternative spelling of #), 6.4.6 <= (less-than-or-equal-to operator), 6.5.8
19600 %:%: (alternative spelling of ##), 6.4.6 <assert.h> header, 7.2, B.1
19601 %= (remainder assignment operator), 6.5.16.2 <complex.h> header, 5.2.4.2.2, 7.3, 7.22,
19602 %> (alternative spelling of }), 6.4.6 7.26.1, G.6, J.5.17
19603 & (address operator), 6.3.2.1, 6.5.3.2 <ctype.h> header, 7.4, 7.26.2
19604 & (bitwise AND operator), 6.5.10 <errno.h> header, 7.5, 7.26.3
19605 && (logical AND operator), 6.5.13 <fenv.h> header, 5.1.2.3, 5.2.4.2.2, 7.6, 7.12, F,
19606 &= (bitwise AND assignment operator), 6.5.16.2 H
19607 ' ' (space character), 5.1.1.2, 5.2.1, 6.4, 7.4.1.3, <float.h> header, 4, 5.2.4.2.2, 7.7, 7.20.1.3,
19608 7.4.1.10, 7.25.2.1.3 7.24.4.1.1
19609 ( ) (cast operator), 6.5.4 <inttypes.h> header, 7.8, 7.26.4
19610 ( ) (function-call operator), 6.5.2.2 <iso646.h> header, 4, 7.9
19611 ( ) (parentheses punctuator), 6.7.5.3, 6.8.4, 6.8.5 <limits.h> header, 4, 5.2.4.2.1, 6.2.5, 7.10
19612 ( ){ } (compound-literal operator), 6.5.2.5 <locale.h> header, 7.11, 7.26.5
19613 * (asterisk punctuator), 6.7.5.1, 6.7.5.2 <math.h> header, 5.2.4.2.2, 6.5, 7.12, 7.22, F,
19614 * (indirection operator), 6.5.2.1, 6.5.3.2 F.9, J.5.17
19615 * (multiplication operator), 6.5.5, F.3, G.5.1 <setjmp.h> header, 7.13
19616 *= (multiplication assignment operator), 6.5.16.2 <signal.h> header, 7.14, 7.26.6
19617 + (addition operator), 6.5.2.1, 6.5.3.2, 6.5.6, F.3, <stdarg.h> header, 4, 6.7.5.3, 7.15
19618 G.5.2 <stdbool.h> header, 4, 7.16, 7.26.7, H
19619 + (unary plus operator), 6.5.3.3 <stddef.h> header, 4, 6.3.2.1, 6.3.2.3, 6.4.4.4,
19620 ++ (postfix increment operator), 6.3.2.1, 6.5.2.4 6.4.5, 6.5.3.4, 6.5.6, 7.17
19621 ++ (prefix increment operator), 6.3.2.1, 6.5.3.1 <stdint.h> header, 4, 5.2.4.2, 6.10.1, 7.8,
19622 += (addition assignment operator), 6.5.16.2 7.18, 7.26.8
19623 , (comma operator), 6.5.17
19627 <stdio.h> header, 5.2.4.2.2, 7.19, 7.26.9, F __cplusplus macro, 6.10.8
19628 <stdlib.h> header, 5.2.4.2.2, 7.20, 7.26.10, F __DATE__ macro, 6.10.8
19629 <string.h> header, 7.21, 7.26.11 __FILE__ macro, 6.10.8, 7.2.1.1
19630 <tgmath.h> header, 7.22, G.7 __func__ identifier, 6.4.2.2, 7.2.1.1
19631 <time.h> header, 7.23 __LINE__ macro, 6.10.8, 7.2.1.1
19632 <wchar.h> header, 5.2.4.2.2, 7.19.1, 7.24, __STDC_, 6.11.9
19633 7.26.12, F __STDC__ macro, 6.10.8
19634 <wctype.h> header, 7.25, 7.26.13 __STDC_CONSTANT_MACROS macro, 7.18.4
19635 = (equal-sign punctuator), 6.7, 6.7.2.2, 6.7.8 __STDC_FORMAT_MACROS macro, 7.8.1
19636 = (simple assignment operator), 6.5.16.1 __STDC_HOSTED__ macro, 6.10.8
19637 == (equality operator), 6.5.9 __STDC_IEC_559__ macro, 6.10.8, F.1
19638 > (greater-than operator), 6.5.8 __STDC_IEC_559_COMPLEX__ macro,
19639 >= (greater-than-or-equal-to operator), 6.5.8 6.10.8, G.1
19640 >> (right-shift operator), 6.5.7 __STDC_ISO_10646__ macro, 6.10.8
19641 >>= (right-shift assignment operator), 6.5.16.2 __STDC_LIMIT_MACROS macro, 7.18.2,
19642 ? : (conditional operator), 6.5.15 7.18.3
19643 ?? (trigraph sequences), 5.2.1.1 __STDC_MB_MIGHT_NEQ_WC__ macro,
19644 [ ] (array subscript operator), 6.5.2.1, 6.5.3.2 6.10.8, 7.17
19645 [ ] (brackets punctuator), 6.7.5.2, 6.7.8 __STDC_VERSION__ macro, 6.10.8
19646 \ (backslash character), 5.1.1.2, 5.2.1, 6.4.4.4 __TIME__ macro, 6.10.8
19647 \ (escape character), 6.4.4.4 __VA_ARGS__ identifier, 6.10.3, 6.10.3.1
19648 \" (double-quote escape sequence), 6.4.4.4, _Bool type, 6.2.5, 6.3.1.1, 6.3.1.2, 6.7.2
19649 6.4.5, 6.10.9 _Bool type conversions, 6.3.1.2
19650 \\ (backslash escape sequence), 6.4.4.4, 6.10.9 _Complex types, 6.2.5, 6.7.2, 7.3.1, G
19651 \' (single-quote escape sequence), 6.4.4.4, 6.4.5 _Complex_I macro, 7.3.1
19652 \0 (null character), 5.2.1, 6.4.4.4, 6.4.5 _Exit function, 7.20.4.4
19653 padding of binary stream, 7.19.2 _Imaginary keyword, G.2
19654 \? (question-mark escape sequence), 6.4.4.4 _Imaginary types, 7.3.1, G
19655 \a (alert escape sequence), 5.2.2, 6.4.4.4 _Imaginary_I macro, 7.3.1, G.6
19656 \b (backspace escape sequence), 5.2.2, 6.4.4.4 _IOFBF macro, 7.19.1, 7.19.5.5, 7.19.5.6
19657 \f (form-feed escape sequence), 5.2.2, 6.4.4.4, _IOLBF macro, 7.19.1, 7.19.5.6
19658 7.4.1.10 _IONBF macro, 7.19.1, 7.19.5.5, 7.19.5.6
19659 \n (new-line escape sequence), 5.2.2, 6.4.4.4, _Pragma operator, 5.1.1.2, 6.10.9
19660 7.4.1.10 { } (braces punctuator), 6.7.2.2, 6.7.2.3, 6.7.8,
19661 \octal digits (octal-character escape sequence), 6.8.2
19662 6.4.4.4 { } (compound-literal operator), 6.5.2.5
19663 \r (carriage-return escape sequence), 5.2.2, | (bitwise inclusive OR operator), 6.5.12
19664 6.4.4.4, 7.4.1.10 |= (bitwise inclusive OR assignment operator),
19665 \t (horizontal-tab escape sequence), 5.2.2, 6.5.16.2
19666 6.4.4.4, 7.4.1.3, 7.4.1.10, 7.25.2.1.3 || (logical OR operator), 6.5.14
19667 \U (universal character names), 6.4.3 ~ (bitwise complement operator), 6.5.3.3
19668 \u (universal character names), 6.4.3
19669 \v (vertical-tab escape sequence), 5.2.2, 6.4.4.4, abort function, 7.2.1.1, 7.14.1.1, 7.19.3,
19671 \x hexadecimal digits (hexadecimal-character abs function, 7.20.6.1
19672 escape sequence), 6.4.4.4 absolute-value functions
19673 ^ (bitwise exclusive OR operator), 6.5.11 complex, 7.3.8, G.6.4
19674 ^= (bitwise exclusive OR assignment operator), integer, 7.8.2.1, 7.20.6.1
19675 6.5.16.2 real, 7.12.7, F.9.4
19676 __bool_true_false_are_defined abstract declarator, 6.7.6
19677 macro, 7.16 abstract machine, 5.1.2.3
19681 access, 3.1, 6.7.3 array
19682 accuracy, see floating-point accuracy argument, 6.9.1
19683 acos functions, 7.12.4.1, F.9.1.1 declarator, 6.7.5.2
19684 acos type-generic macro, 7.22 initialization, 6.7.8
19685 acosh functions, 7.12.5.1, F.9.2.1 multidimensional, 6.5.2.1
19686 acosh type-generic macro, 7.22 parameter, 6.9.1
19687 active position, 5.2.2 storage order, 6.5.2.1
19688 actual argument, 3.3 subscript operator ([ ]), 6.5.2.1, 6.5.3.2
19689 actual parameter (deprecated), 3.3 subscripting, 6.5.2.1
19690 addition assignment operator (+=), 6.5.16.2 type, 6.2.5
19691 addition operator (+), 6.5.2.1, 6.5.3.2, 6.5.6, F.3, type conversion, 6.3.2.1
19692 G.5.2 variable length, 6.7.5, 6.7.5.2
19693 additive expressions, 6.5.6, G.5.2 arrow operator (->), 6.5.2.3
19694 address constant, 6.6 as-if rule, 5.1.2.3
19695 address operator (&), 6.3.2.1, 6.5.3.2 ASCII code set, 5.2.1.1
19696 aggregate initialization, 6.7.8 asctime function, 7.23.3.1
19697 aggregate types, 6.2.5 asin functions, 7.12.4.2, F.9.1.2
19698 alert escape sequence (\a), 5.2.2, 6.4.4.4 asin type-generic macro, 7.22, G.7
19699 aliasing, 6.5 asinh functions, 7.12.5.2, F.9.2.2
19700 alignment, 3.2 asinh type-generic macro, 7.22, G.7
19701 pointer, 6.2.5, 6.3.2.3 asm keyword, J.5.10
19702 structure/union member, 6.7.2.1 assert macro, 7.2.1.1
19703 allocated storage, order and contiguity, 7.20.3 assert.h header, 7.2, B.1
19704 and macro, 7.9 assignment
19705 AND operators compound, 6.5.16.2
19706 bitwise (&), 6.5.10 conversion, 6.5.16.1
19707 bitwise assignment (&=), 6.5.16.2 expression, 6.5.16
19708 logical (&&), 6.5.13 operators, 6.3.2.1, 6.5.16
19709 and_eq macro, 7.9 simple, 6.5.16.1
19710 ANSI/IEEE 754, F.1 associativity of operators, 6.5
19711 ANSI/IEEE 854, F.1 asterisk punctuator (*), 6.7.5.1, 6.7.5.2
19712 argc (main function parameter), 5.1.2.2.1 atan functions, 7.12.4.3, F.9.1.3
19713 argument, 3.3 atan type-generic macro, 7.22, G.7
19714 array, 6.9.1 atan2 functions, 7.12.4.4, F.9.1.4
19715 default promotions, 6.5.2.2 atan2 type-generic macro, 7.22
19716 function, 6.5.2.2, 6.9.1 atanh functions, 7.12.5.3, F.9.2.3
19717 macro, substitution, 6.10.3.1 atanh type-generic macro, 7.22, G.7
19718 argument, complex, 7.3.9.1 atexit function, 7.20.4.2, 7.20.4.3, 7.20.4.4,
19719 argv (main function parameter), 5.1.2.2.1 J.5.13
19720 arithmetic constant expression, 6.6 atof function, 7.20.1, 7.20.1.1
19721 arithmetic conversions, usual, see usual arithmetic atoi function, 7.20.1, 7.20.1.2
19722 conversions atol function, 7.20.1, 7.20.1.2
19723 arithmetic operators atoll function, 7.20.1, 7.20.1.2
19724 additive, 6.5.6, G.5.2 auto storage-class specifier, 6.7.1, 6.9
19725 bitwise, 6.5.10, 6.5.11, 6.5.12 automatic storage duration, 5.2.3, 6.2.4
19726 increment and decrement, 6.5.2.4, 6.5.3.1
19727 multiplicative, 6.5.5, G.5.1 backslash character (\), 5.1.1.2, 5.2.1, 6.4.4.4
19728 shift, 6.5.7 backslash escape sequence (\\), 6.4.4.4, 6.10.9
19729 unary, 6.5.3.3 backspace escape sequence (\b), 5.2.2, 6.4.4.4
19730 arithmetic types, 6.2.5 basic character set, 3.6, 3.7.2, 5.2.1
19731 arithmetic, pointer, 6.5.6 basic types, 6.2.5
19735 behavior, 3.4 call by value, 6.5.2.2
19736 binary streams, 7.19.2, 7.19.7.11, 7.19.9.2, calloc function, 7.20.3, 7.20.3.1, 7.20.3.2,
19738 bit, 3.5 carg functions, 7.3.9.1, G.6
19739 high order, 3.6 carg type-generic macro, 7.22, G.7
19740 low order, 3.6 carriage-return escape sequence (\r), 5.2.2,
19741 bit-field, 6.7.2.1 6.4.4.4, 7.4.1.10
19742 bitand macro, 7.9 case label, 6.8.1, 6.8.4.2
19743 bitor macro, 7.9 case mapping functions
19744 bitwise operators, 6.5 character, 7.4.2
19745 AND, 6.5.10 wide character, 7.25.3.1
19746 AND assignment (&=), 6.5.16.2 extensible, 7.25.3.2
19747 complement (~), 6.5.3.3 casin functions, 7.3.5.2, G.6
19748 exclusive OR, 6.5.11 type-generic macro for, 7.22
19749 exclusive OR assignment (^=), 6.5.16.2 casinh functions, 7.3.6.2, G.6.2.2
19750 inclusive OR, 6.5.12 type-generic macro for, 7.22
19751 inclusive OR assignment (|=), 6.5.16.2 cast expression, 6.5.4
19752 shift, 6.5.7 cast operator (( )), 6.5.4
19753 blank character, 7.4.1.3 catan functions, 7.3.5.3, G.6
19754 block, 6.8, 6.8.2, 6.8.4, 6.8.5 type-generic macro for, 7.22
19755 block scope, 6.2.1 catanh functions, 7.3.6.3, G.6.2.3
19756 block structure, 6.2.1 type-generic macro for, 7.22
19757 bold type convention, 6.1 cbrt functions, 7.12.7.1, F.9.4.1
19758 bool macro, 7.16 cbrt type-generic macro, 7.22
19759 boolean type, 6.3.1.2 ccos functions, 7.3.5.4, G.6
19760 boolean type conversion, 6.3.1.1, 6.3.1.2 type-generic macro for, 7.22
19761 braces punctuator ({ }), 6.7.2.2, 6.7.2.3, 6.7.8, ccosh functions, 7.3.6.4, G.6.2.4
19762 6.8.2 type-generic macro for, 7.22
19763 brackets operator ([ ]), 6.5.2.1, 6.5.3.2 ceil functions, 7.12.9.1, F.9.6.1
19764 brackets punctuator ([ ]), 6.7.5.2, 6.7.8 ceil type-generic macro, 7.22
19765 branch cuts, 7.3.3 cerf function, 7.26.1
19766 break statement, 6.8.6.3 cerfc function, 7.26.1
19767 broken-down time, 7.23.1, 7.23.2.3, 7.23.3, cexp functions, 7.3.7.1, G.6.3.1
19768 7.23.3.1, 7.23.3.3, 7.23.3.4, 7.23.3.5 type-generic macro for, 7.22
19769 bsearch function, 7.20.5, 7.20.5.1 cexp2 function, 7.26.1
19770 btowc function, 7.24.6.1.1 cexpm1 function, 7.26.1
19771 BUFSIZ macro, 7.19.1, 7.19.2, 7.19.5.5 char type, 6.2.5, 6.3.1.1, 6.7.2
19772 byte, 3.6, 6.5.3.4 char type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,
19773 byte input/output functions, 7.19.1 6.3.1.8
19774 byte-oriented stream, 7.19.2 CHAR_BIT macro, 5.2.4.2.1
19775 CHAR_MAX macro, 5.2.4.2.1, 7.11.2.1
19776 C program, 5.1.1.1 CHAR_MIN macro, 5.2.4.2.1
19777 C++, 7.8.1, 7.18.2, 7.18.3, 7.18.4 character, 3.7, 3.7.1
19778 cabs functions, 7.3.8.1, G.6 character array initialization, 6.7.8
19779 type-generic macro for, 7.22 character case mapping functions, 7.4.2
19780 cacos functions, 7.3.5.1, G.6.1.1 wide character, 7.25.3.1
19781 type-generic macro for, 7.22 extensible, 7.25.3.2
19782 cacosh functions, 7.3.6.1, G.6.2.1 character classification functions, 7.4.1
19783 type-generic macro for, 7.22 wide character, 7.25.2.1
19784 calendar time, 7.23.1, 7.23.2.2, 7.23.2.3, 7.23.2.4, extensible, 7.25.2.2
19785 7.23.3.2, 7.23.3.3, 7.23.3.4 character constant, 5.1.1.2, 5.2.1, 6.4.4.4
19789 character display semantics, 5.2.2 complex.h header, 5.2.4.2.2, 7.3, 7.22, 7.26.1,
19790 character handling header, 7.4, 7.11.1.1 G.6, J.5.17
19791 character input/output functions, 7.19.7 compliance, see conformance
19792 wide character, 7.24.3 components of time, 7.23.1
19793 character sets, 5.2.1 composite type, 6.2.7
19794 character string literal, see string literal compound assignment, 6.5.16.2
19795 character type conversion, 6.3.1.1 compound literals, 6.5.2.5
19796 character types, 6.2.5, 6.7.8 compound statement, 6.8.2
19797 cimag functions, 7.3.9.2, 7.3.9.4, G.6 compound-literal operator (( ){ }), 6.5.2.5
19798 cimag type-generic macro, 7.22, G.7 concatenation functions
19799 cis function, G.6 string, 7.21.3
19800 classification functions wide string, 7.24.4.3
19801 character, 7.4.1 concatenation, preprocessing, see preprocessing
19802 floating-point, 7.12.3 concatenation
19803 wide character, 7.25.2.1 conceptual models, 5.1
19804 extensible, 7.25.2.2 conditional inclusion, 6.10.1
19805 clearerr function, 7.19.10.1 conditional operator (? :), 6.5.15
19806 clgamma function, 7.26.1 conformance, 4
19807 clock function, 7.23.2.1 conj functions, 7.3.9.3, G.6
19808 clock_t type, 7.23.1, 7.23.2.1 conj type-generic macro, 7.22
19809 CLOCKS_PER_SEC macro, 7.23.1, 7.23.2.1 const type qualifier, 6.7.3
19810 clog functions, 7.3.7.2, G.6.3.2 const-qualified type, 6.2.5, 6.3.2.1, 6.7.3
19811 type-generic macro for, 7.22 constant expression, 6.6, F.7.4
19812 clog10 function, 7.26.1 constants, 6.4.4
19813 clog1p function, 7.26.1 as primary expression, 6.5.1
19814 clog2 function, 7.26.1 character, 6.4.4.4
19815 collating sequences, 5.2.1 enumeration, 6.2.1, 6.4.4.3
19816 colon punctuator (:), 6.7.2.1 floating, 6.4.4.2
19817 comma operator (,), 6.5.17 hexadecimal, 6.4.4.1
19818 comma punctuator (,), 6.5.2, 6.7, 6.7.2.1, 6.7.2.2, integer, 6.4.4.1
19819 6.7.2.3, 6.7.8 octal, 6.4.4.1
19820 command processor, 7.20.4.6 constraint, 3.8, 4
19821 comment delimiters (/* */ and //), 6.4.9 content of structure/union/enumeration, 6.7.2.3
19822 comments, 5.1.1.2, 6.4, 6.4.9 contiguity of allocated storage, 7.20.3
19823 common extensions, J.5 continue statement, 6.8.6.2
19824 common initial sequence, 6.5.2.3 contracted expression, 6.5, 7.12.2, F.6
19825 common real type, 6.3.1.8 control character, 5.2.1, 7.4
19826 common warnings, I control wide character, 7.25.2
19827 comparison functions, 7.20.5, 7.20.5.1, 7.20.5.2 conversion, 6.3
19828 string, 7.21.4 arithmetic operands, 6.3.1
19829 wide string, 7.24.4.4 array argument, 6.9.1 *
19830 comparison macros, 7.12.14 array parameter, 6.9.1
19831 comparison, pointer, 6.5.8 arrays, 6.3.2.1
19832 compatible type, 6.2.7, 6.7.2, 6.7.3, 6.7.5 boolean, 6.3.1.2
19833 compl macro, 7.9 boolean, characters, and integers, 6.3.1.1
19834 complement operator (~), 6.5.3.3 by assignment, 6.5.16.1
19835 complex macro, 7.3.1 by return statement, 6.8.6.4
19836 complex numbers, 6.2.5, G complex types, 6.3.1.6
19837 complex type conversion, 6.3.1.6, 6.3.1.7 explicit, 6.3
19838 complex type domain, 6.2.5 function, 6.3.2.1
19839 complex types, 6.2.5, 6.7.2, G function argument, 6.5.2.2, 6.9.1
19843 function designators, 6.3.2.1 type-generic macro for, 7.22
19844 function parameter, 6.9.1 csinh functions, 7.3.6.5, G.6.2.5
19845 imaginary, G.4.1 type-generic macro for, 7.22
19846 imaginary and complex, G.4.3 csqrt functions, 7.3.8.3, G.6.4.2
19847 implicit, 6.3 type-generic macro for, 7.22
19848 lvalues, 6.3.2.1 ctan functions, 7.3.5.6, G.6
19849 pointer, 6.3.2.1, 6.3.2.3 type-generic macro for, 7.22
19850 real and complex, 6.3.1.7 ctanh functions, 7.3.6.6, G.6.2.6
19851 real and imaginary, G.4.2 type-generic macro for, 7.22
19852 real floating and integer, 6.3.1.4, F.3, F.4 ctgamma function, 7.26.1
19853 real floating types, 6.3.1.5, F.3 ctime function, 7.23.3.2
19854 signed and unsigned integers, 6.3.1.3 ctype.h header, 7.4, 7.26.2
19855 usual arithmetic, see usual arithmetic current object, 6.7.8
19856 conversions CX_LIMITED_RANGE pragma, 6.10.6, 7.3.4
19858 conversion functions data stream, see streams
19859 multibyte/wide character, 7.20.7 date and time header, 7.23
19860 extended, 7.24.6 Daylight Saving Time, 7.23.1
19861 restartable, 7.24.6.3 DBL_DIG macro, 5.2.4.2.2
19862 multibyte/wide string, 7.20.8 DBL_EPSILON macro, 5.2.4.2.2
19863 restartable, 7.24.6.4 DBL_MANT_DIG macro, 5.2.4.2.2
19864 numeric, 7.8.2.3, 7.20.1 DBL_MAX macro, 5.2.4.2.2
19865 wide string, 7.8.2.4, 7.24.4.1 DBL_MAX_10_EXP macro, 5.2.4.2.2
19866 single byte/wide character, 7.24.6.1 DBL_MAX_EXP macro, 5.2.4.2.2
19867 time, 7.23.3 DBL_MIN macro, 5.2.4.2.2
19868 wide character, 7.24.5 DBL_MIN_10_EXP macro, 5.2.4.2.2
19869 conversion specifier, 7.19.6.1, 7.19.6.2, 7.24.2.1, DBL_MIN_EXP macro, 5.2.4.2.2
19870 7.24.2.2 decimal constant, 6.4.4.1
19871 conversion state, 7.20.7, 7.24.6, 7.24.6.2.1, decimal digit, 5.2.1
19872 7.24.6.3, 7.24.6.3.2, 7.24.6.3.3, 7.24.6.4, decimal-point character, 7.1.1, 7.11.2.1
19873 7.24.6.4.1, 7.24.6.4.2 DECIMAL_DIG macro, 5.2.4.2.2, 7.19.6.1,
19874 conversion state functions, 7.24.6.2 7.20.1.3, 7.24.2.1, 7.24.4.1.1, F.5
19875 copying functions declaration specifiers, 6.7
19876 string, 7.21.2 declarations, 6.7
19877 wide string, 7.24.4.2 function, 6.7.5.3
19878 copysign functions, 7.3.9.4, 7.12.11.1, F.3, pointer, 6.7.5.1
19879 F.9.8.1 structure/union, 6.7.2.1
19880 copysign type-generic macro, 7.22 typedef, 6.7.7
19881 correctly rounded result, 3.9 declarator, 6.7.5
19882 corresponding real type, 6.2.5 abstract, 6.7.6
19883 cos functions, 7.12.4.5, F.9.1.5 declarator type derivation, 6.2.5, 6.7.5
19884 cos type-generic macro, 7.22, G.7 decrement operators, see arithmetic operators,
19885 cosh functions, 7.12.5.4, F.9.2.4 increment and decrement
19886 cosh type-generic macro, 7.22, G.7 default argument promotions, 6.5.2.2
19887 cpow functions, 7.3.8.2, G.6.4.1 default initialization, 6.7.8
19888 type-generic macro for, 7.22 default label, 6.8.1, 6.8.4.2
19889 cproj functions, 7.3.9.4, G.6 define preprocessing directive, 6.10.3
19890 cproj type-generic macro, 7.22 defined operator, 6.10.1, 6.10.8
19891 creal functions, 7.3.9.5, G.6 definition, 6.7
19892 creal type-generic macro, 7.22, G.7 function, 6.9.1
19893 csin functions, 7.3.5.5, G.6 derived declarator types, 6.2.5
19897 derived types, 6.2.5 end-of-file indicator, 7.19.1, 7.19.5.3, 7.19.7.1,
19898 designated initializer, 6.7.8 7.19.7.5, 7.19.7.6, 7.19.7.11, 7.19.9.2,
19899 destringizing, 6.10.9 7.19.9.3, 7.19.10.1, 7.19.10.2, 7.24.3.1,
19900 device input/output, 5.1.2.3 7.24.3.10
19901 diagnostic message, 3.10, 5.1.1.3 end-of-file macro, see EOF macro
19902 diagnostics, 5.1.1.3 end-of-line indicator, 5.2.1
19903 diagnostics header, 7.2 endif preprocessing directive, 6.10.1
19904 difftime function, 7.23.2.2 enum type, 6.2.5, 6.7.2, 6.7.2.2
19905 digit, 5.2.1, 7.4 enumerated type, 6.2.5
19906 digraphs, 6.4.6 enumeration, 6.2.5, 6.7.2.2
19907 direct input/output functions, 7.19.8 enumeration constant, 6.2.1, 6.4.4.3
19908 display device, 5.2.2 enumeration content, 6.7.2.3
19909 div function, 7.20.6.2 enumeration members, 6.7.2.2
19910 div_t type, 7.20 enumeration specifiers, 6.7.2.2
19911 division assignment operator (/=), 6.5.16.2 enumeration tag, 6.2.3, 6.7.2.3
19912 division operator (/), 6.5.5, F.3, G.5.1 enumerator, 6.7.2.2
19913 do statement, 6.8.5.2 environment, 5
19914 documentation of implementation, 4 environment functions, 7.20.4
19915 domain error, 7.12.1, 7.12.4.1, 7.12.4.2, 7.12.4.4, environment list, 7.20.4.5
19916 7.12.5.1, 7.12.5.3, 7.12.6.5, 7.12.6.7, environmental considerations, 5.2
19917 7.12.6.8, 7.12.6.9, 7.12.6.10, 7.12.6.11, environmental limits, 5.2.4, 7.13.1.1, 7.19.2,
19918 7.12.7.4, 7.12.7.5, 7.12.8.4, 7.12.9.5, 7.19.3, 7.19.4.4, 7.19.6.1, 7.20.2.1, 7.20.4.2,
19919 7.12.9.7, 7.12.10.1, 7.12.10.2, 7.12.10.3 7.24.2.1
19920 dot operator (.), 6.5.2.3 EOF macro, 7.4, 7.19.1, 7.19.5.1, 7.19.5.2,
19921 double _Complex type, 6.2.5 7.19.6.2, 7.19.6.7, 7.19.6.9, 7.19.6.11,
19922 double _Complex type conversion, 6.3.1.6, 7.19.6.14, 7.19.7.1, 7.19.7.3, 7.19.7.4,
19923 6.3.1.7, 6.3.1.8 7.19.7.5, 7.19.7.6, 7.19.7.9, 7.19.7.10,
19924 double _Imaginary type, G.2 7.19.7.11, 7.24.1, 7.24.2.2, 7.24.2.4,
19925 double type, 6.2.5, 6.4.4.2, 6.7.2, 7.19.6.2, 7.24.2.6, 7.24.2.8, 7.24.2.10, 7.24.2.12,
19926 7.24.2.2, F.2 7.24.3.4, 7.24.6.1.1, 7.24.6.1.2
19927 double type conversion, 6.3.1.4, 6.3.1.5, 6.3.1.7, equal-sign punctuator (=), 6.7, 6.7.2.2, 6.7.8
19928 6.3.1.8 equal-to operator, see equality operator
19929 double-precision arithmetic, 5.1.2.3 equality expressions, 6.5.9
19930 double-quote escape sequence (\"), 6.4.4.4, equality operator (==), 6.5.9
19931 6.4.5, 6.10.9 ERANGE macro, 7.5, 7.8.2.3, 7.8.2.4, 7.12.1,
19932 double_t type, 7.12, J.5.6 7.20.1.3, 7.20.1.4, 7.24.4.1.1, 7.24.4.1.2, see
19934 EDOM macro, 7.5, 7.12.1, see also domain error erf functions, 7.12.8.1, F.9.5.1
19935 effective type, 6.5 erf type-generic macro, 7.22
19936 EILSEQ macro, 7.5, 7.19.3, 7.24.3.1, 7.24.3.3, erfc functions, 7.12.8.2, F.9.5.2
19937 7.24.6.3.2, 7.24.6.3.3, 7.24.6.4.1, 7.24.6.4.2, erfc type-generic macro, 7.22
19938 see also encoding error errno macro, 7.1.3, 7.3.2, 7.5, 7.8.2.3, 7.8.2.4,
19939 element type, 6.2.5 7.12.1, 7.14.1.1, 7.19.3, 7.19.9.3, 7.19.10.4,
19940 elif preprocessing directive, 6.10.1 7.20.1, 7.20.1.3, 7.20.1.4, 7.21.6.2, 7.24.3.1,
19941 ellipsis punctuator (...), 6.5.2.2, 6.7.5.3, 6.10.3 7.24.3.3, 7.24.4.1.1, 7.24.4.1.2, 7.24.6.3.2,
19942 else preprocessing directive, 6.10.1 7.24.6.3.3, 7.24.6.4.1, 7.24.6.4.2, J.5.17
19943 else statement, 6.8.4.1 errno.h header, 7.5, 7.26.3
19944 empty statement, 6.8.3 error
19945 encoding error, 7.19.3, 7.24.3.1, 7.24.3.3, domain, see domain error
19946 7.24.6.3.2, 7.24.6.3.3, 7.24.6.4.1, 7.24.6.4.2 encoding, see encoding error
19947 end-of-file, 7.24.1 range, see range error
19951 error conditions, 7.12.1 extended characters, 5.2.1
19952 error functions, 7.12.8, F.9.5 extended integer types, 6.2.5, 6.3.1.1, 6.4.4.1,
19953 error indicator, 7.19.1, 7.19.5.3, 7.19.7.1, 7.18
19954 7.19.7.3, 7.19.7.5, 7.19.7.6, 7.19.7.8, extended multibyte/wide character conversion
19955 7.19.7.9, 7.19.9.2, 7.19.10.1, 7.19.10.3, utilities, 7.24.6
19956 7.24.3.1, 7.24.3.3 extensible wide character case mapping functions,
19957 error preprocessing directive, 4, 6.10.5 7.25.3.2
19958 error-handling functions, 7.19.10, 7.21.6.2 extensible wide character classification functions,
19959 escape character (\), 6.4.4.4 7.25.2.2
19960 escape sequences, 5.2.1, 5.2.2, 6.4.4.4, 6.11.4 extern storage-class specifier, 6.2.2, 6.7.1
19961 evaluation format, 5.2.4.2.2, 6.4.4.2, 7.12 external definition, 6.9
19962 evaluation method, 5.2.4.2.2, 6.5, F.7.5 external identifiers, underscore, 7.1.3
19963 evaluation order, 6.5 external linkage, 6.2.2
19964 exceptional condition, 6.5, 7.12.1 external name, 6.4.2.1
19965 excess precision, 5.2.4.2.2, 6.3.1.5, 6.3.1.8, external object definitions, 6.9.2
19967 excess range, 5.2.4.2.2, 6.3.1.5, 6.3.1.8, 6.8.6.4 fabs functions, 7.12.7.2, F.9.4.2
19968 exclusive OR operators fabs type-generic macro, 7.22, G.7
19969 bitwise (^), 6.5.11 false macro, 7.16
19970 bitwise assignment (^=), 6.5.16.2 fclose function, 7.19.5.1
19971 executable program, 5.1.1.1 fdim functions, 7.12.12.1, F.9.9.1
19972 execution character set, 5.2.1 fdim type-generic macro, 7.22
19973 execution environment, 5, 5.1.2, see also FE_ALL_EXCEPT macro, 7.6
19974 environmental limits FE_DFL_ENV macro, 7.6
19975 execution sequence, 5.1.2.3, 6.8 FE_DIVBYZERO macro, 7.6, 7.12, F.3
19976 exit function, 5.1.2.2.3, 7.19.3, 7.20, 7.20.4.3, FE_DOWNWARD macro, 7.6, F.3
19977 7.20.4.4 FE_INEXACT macro, 7.6, F.3
19978 EXIT_FAILURE macro, 7.20, 7.20.4.3 FE_INVALID macro, 7.6, 7.12, F.3
19979 EXIT_SUCCESS macro, 7.20, 7.20.4.3 FE_OVERFLOW macro, 7.6, 7.12, F.3
19980 exp functions, 7.12.6.1, F.9.3.1 FE_TONEAREST macro, 7.6, F.3
19981 exp type-generic macro, 7.22 FE_TOWARDZERO macro, 7.6, F.3
19982 exp2 functions, 7.12.6.2, F.9.3.2 FE_UNDERFLOW macro, 7.6, F.3
19983 exp2 type-generic macro, 7.22 FE_UPWARD macro, 7.6, F.3
19984 explicit conversion, 6.3 feclearexcept function, 7.6.2, 7.6.2.1, F.3
19985 expm1 functions, 7.12.6.3, F.9.3.3 fegetenv function, 7.6.4.1, 7.6.4.3, 7.6.4.4, F.3
19986 expm1 type-generic macro, 7.22 fegetexceptflag function, 7.6.2, 7.6.2.2, F.3
19987 exponent part, 6.4.4.2 fegetround function, 7.6, 7.6.3.1, F.3
19988 exponential functions feholdexcept function, 7.6.4.2, 7.6.4.3,
19989 complex, 7.3.7, G.6.3 7.6.4.4, F.3
19990 real, 7.12.6, F.9.3 fenv.h header, 5.1.2.3, 5.2.4.2.2, 7.6, 7.12, F, H
19991 expression, 6.5 FENV_ACCESS pragma, 6.10.6, 7.6.1, F.7, F.8,
19992 assignment, 6.5.16 F.9
19993 cast, 6.5.4 fenv_t type, 7.6
19994 constant, 6.6 feof function, 7.19.10.2
19995 full, 6.8 feraiseexcept function, 7.6.2, 7.6.2.3, F.3
19996 order of evaluation, 6.5 ferror function, 7.19.10.3
19997 parenthesized, 6.5.1 fesetenv function, 7.6.4.3, F.3
19998 primary, 6.5.1 fesetexceptflag function, 7.6.2, 7.6.2.4, F.3
19999 unary, 6.5.3 fesetround function, 7.6, 7.6.3.2, F.3
20000 expression statement, 6.8.3 fetestexcept function, 7.6.2, 7.6.2.5, F.3
20001 extended character set, 3.7.2, 5.2.1, 5.2.1.2 feupdateenv function, 7.6.4.2, 7.6.4.4, F.3
20005 fexcept_t type, 7.6, F.3 floating-point status flag, 7.6, F.7.6
20006 fflush function, 7.19.5.2, 7.19.5.3 floor functions, 7.12.9.2, F.9.6.2
20007 fgetc function, 7.19.1, 7.19.3, 7.19.7.1, floor type-generic macro, 7.22
20008 7.19.7.5, 7.19.8.1 FLT_DIG macro, 5.2.4.2.2
20009 fgetpos function, 7.19.2, 7.19.9.1, 7.19.9.3 FLT_EPSILON macro, 5.2.4.2.2
20010 fgets function, 7.19.1, 7.19.7.2 FLT_EVAL_METHOD macro, 5.2.4.2.2, 6.8.6.4,
20011 fgetwc function, 7.19.1, 7.19.3, 7.24.3.1, 7.12
20012 7.24.3.6 FLT_MANT_DIG macro, 5.2.4.2.2
20013 fgetws function, 7.19.1, 7.24.3.2 FLT_MAX macro, 5.2.4.2.2
20014 field width, 7.19.6.1, 7.24.2.1 FLT_MAX_10_EXP macro, 5.2.4.2.2
20015 file, 7.19.3 FLT_MAX_EXP macro, 5.2.4.2.2
20016 access functions, 7.19.5 FLT_MIN macro, 5.2.4.2.2
20017 name, 7.19.3 FLT_MIN_10_EXP macro, 5.2.4.2.2
20018 operations, 7.19.4 FLT_MIN_EXP macro, 5.2.4.2.2
20019 position indicator, 7.19.1, 7.19.2, 7.19.3, FLT_RADIX macro, 5.2.4.2.2, 7.19.6.1, 7.20.1.3,
20020 7.19.5.3, 7.19.7.1, 7.19.7.3, 7.19.7.11, 7.24.2.1, 7.24.4.1.1
20021 7.19.8.1, 7.19.8.2, 7.19.9.1, 7.19.9.2, FLT_ROUNDS macro, 5.2.4.2.2, 7.6, F.3
20022 7.19.9.3, 7.19.9.4, 7.19.9.5, 7.24.3.1, fma functions, 7.12, 7.12.13.1, F.9.10.1
20023 7.24.3.3, 7.24.3.10 fma type-generic macro, 7.22
20024 positioning functions, 7.19.9 fmax functions, 7.12.12.2, F.9.9.2
20025 file scope, 6.2.1, 6.9 fmax type-generic macro, 7.22
20026 FILE type, 7.19.1, 7.19.3 fmin functions, 7.12.12.3, F.9.9.3
20027 FILENAME_MAX macro, 7.19.1 fmin type-generic macro, 7.22
20028 flags, 7.19.6.1, 7.24.2.1 fmod functions, 7.12.10.1, F.9.7.1
20029 floating-point status, see floating-point status fmod type-generic macro, 7.22
20030 flag fopen function, 7.19.5.3, 7.19.5.4
20031 flexible array member, 6.7.2.1 FOPEN_MAX macro, 7.19.1, 7.19.3, 7.19.4.3
20032 float _Complex type, 6.2.5 for statement, 6.8.5, 6.8.5.3
20033 float _Complex type conversion, 6.3.1.6, form-feed character, 5.2.1, 6.4
20034 6.3.1.7, 6.3.1.8 form-feed escape sequence (\f), 5.2.2, 6.4.4.4,
20035 float _Imaginary type, G.2 7.4.1.10
20036 float type, 6.2.5, 6.4.4.2, 6.7.2, F.2 formal argument (deprecated), 3.15
20037 float type conversion, 6.3.1.4, 6.3.1.5, 6.3.1.7, formal parameter, 3.15
20038 6.3.1.8 formatted input/output functions, 7.11.1.1, 7.19.6
20039 float.h header, 4, 5.2.4.2.2, 7.7, 7.20.1.3, wide character, 7.24.2
20040 7.24.4.1.1 fortran keyword, J.5.9
20041 float_t type, 7.12, J.5.6 forward reference, 3.11
20042 floating constant, 6.4.4.2 FP_CONTRACT pragma, 6.5, 6.10.6, 7.12.2, see
20043 floating suffix, f or F, 6.4.4.2 also contracted expression
20044 floating type conversion, 6.3.1.4, 6.3.1.5, 6.3.1.7, FP_FAST_FMA macro, 7.12
20045 F.3, F.4 FP_FAST_FMAF macro, 7.12
20046 floating types, 6.2.5, 6.11.1 FP_FAST_FMAL macro, 7.12
20047 floating-point accuracy, 5.2.4.2.2, 6.4.4.2, 6.5, FP_ILOGB0 macro, 7.12, 7.12.6.5
20048 7.20.1.3, F.5, see also contracted expression FP_ILOGBNAN macro, 7.12, 7.12.6.5
20049 floating-point arithmetic functions, 7.12, F.9 FP_INFINITE macro, 7.12, F.3
20050 floating-point classification functions, 7.12.3 FP_NAN macro, 7.12, F.3
20051 floating-point control mode, 7.6, F.7.6 FP_NORMAL macro, 7.12, F.3
20052 floating-point environment, 7.6, F.7, F.7.6 FP_SUBNORMAL macro, 7.12, F.3
20053 floating-point exception, 7.6, 7.6.2, F.9 FP_ZERO macro, 7.12, F.3
20054 floating-point number, 5.2.4.2.2, 6.2.5 fpclassify macro, 7.12.3.1, F.3
20055 floating-point rounding mode, 5.2.4.2.2 fpos_t type, 7.19.1, 7.19.2
20059 fprintf function, 7.8.1, 7.19.1, 7.19.6.1, language, 6.11
20060 7.19.6.2, 7.19.6.3, 7.19.6.5, 7.19.6.6, library, 7.26
20061 7.19.6.8, 7.24.2.2, F.3 fwide function, 7.19.2, 7.24.3.5
20062 fputc function, 5.2.2, 7.19.1, 7.19.3, 7.19.7.3, fwprintf function, 7.8.1, 7.19.1, 7.19.6.2,
20063 7.19.7.8, 7.19.8.2 7.24.2.1, 7.24.2.2, 7.24.2.3, 7.24.2.5,
20064 fputs function, 7.19.1, 7.19.7.4 7.24.2.11
20065 fputwc function, 7.19.1, 7.19.3, 7.24.3.3, fwrite function, 7.19.1, 7.19.8.2
20066 7.24.3.8 fwscanf function, 7.8.1, 7.19.1, 7.24.2.2,
20067 fputws function, 7.19.1, 7.24.3.4 7.24.2.4, 7.24.2.6, 7.24.2.12, 7.24.3.10
20068 fread function, 7.19.1, 7.19.8.1
20069 free function, 7.20.3.2, 7.20.3.4 gamma functions, 7.12.8, F.9.5
20070 freestanding execution environment, 4, 5.1.2, general utilities, 7.20
20071 5.1.2.1 wide string, 7.24.4
20072 freopen function, 7.19.2, 7.19.5.4 general wide string utilities, 7.24.4
20073 frexp functions, 7.12.6.4, F.9.3.4 generic parameters, 7.22
20074 frexp type-generic macro, 7.22 getc function, 7.19.1, 7.19.7.5, 7.19.7.6
20075 fscanf function, 7.8.1, 7.19.1, 7.19.6.2, getchar function, 7.19.1, 7.19.7.6
20076 7.19.6.4, 7.19.6.7, 7.19.6.9, F.3 getenv function, 7.20.4.5
20077 fseek function, 7.19.1, 7.19.5.3, 7.19.7.11, gets function, 7.19.1, 7.19.7.7, 7.26.9
20078 7.19.9.2, 7.19.9.4, 7.19.9.5, 7.24.3.10 getwc function, 7.19.1, 7.24.3.6, 7.24.3.7
20079 fsetpos function, 7.19.2, 7.19.5.3, 7.19.7.11, getwchar function, 7.19.1, 7.24.3.7
20080 7.19.9.1, 7.19.9.3, 7.24.3.10 gmtime function, 7.23.3.3
20081 ftell function, 7.19.9.2, 7.19.9.4 goto statement, 6.2.1, 6.8.1, 6.8.6.1
20082 full declarator, 6.7.5 graphic characters, 5.2.1
20083 full expression, 6.8 greater-than operator (>), 6.5.8
20084 fully buffered stream, 7.19.3 greater-than-or-equal-to operator (>=), 6.5.8
20086 argument, 6.5.2.2, 6.9.1 header, 5.1.1.1, 7.1.2, see also standard headers
20087 body, 6.9.1 header names, 6.4, 6.4.7, 6.10.2
20088 call, 6.5.2.2 hexadecimal constant, 6.4.4.1
20089 library, 7.1.4 hexadecimal digit, 6.4.4.1, 6.4.4.2, 6.4.4.4
20090 declarator, 6.7.5.3, 6.11.6 hexadecimal prefix, 6.4.4.1
20091 definition, 6.7.5.3, 6.9.1, 6.11.7 hexadecimal-character escape sequence
20092 designator, 6.3.2.1 (\x hexadecimal digits), 6.4.4.4
20093 image, 5.2.3 high-order bit, 3.6
20094 library, 5.1.1.1, 7.1.4 horizontal-tab character, 5.2.1, 6.4
20095 name length, 5.2.4.1, 6.4.2.1, 6.11.3 horizontal-tab escape sequence (\r), 7.25.2.1.3
20096 parameter, 5.1.2.2.1, 6.5.2.2, 6.7, 6.9.1 horizontal-tab escape sequence (\t), 5.2.2,
20097 prototype, 5.1.2.2.1, 6.2.1, 6.2.7, 6.5.2.2, 6.7, 6.4.4.4, 7.4.1.3, 7.4.1.10
20098 6.7.5.3, 6.9.1, 6.11.6, 6.11.7, 7.1.2, 7.12 hosted execution environment, 4, 5.1.2, 5.1.2.2
20099 prototype scope, 6.2.1, 6.7.5.2 HUGE_VAL macro, 7.12, 7.12.1, 7.20.1.3,
20100 recursive call, 6.5.2.2 7.24.4.1.1, F.9
20101 return, 6.8.6.4 HUGE_VALF macro, 7.12, 7.12.1, 7.20.1.3,
20102 scope, 6.2.1 7.24.4.1.1, F.9
20103 type, 6.2.5 HUGE_VALL macro, 7.12, 7.12.1, 7.20.1.3,
20104 type conversion, 6.3.2.1 7.24.4.1.1, F.9
20105 function specifiers, 6.7.4 hyperbolic functions
20106 function type, 6.2.5 complex, 7.3.6, G.6.2
20107 function-call operator (( )), 6.5.2.2 real, 7.12.5, F.9.2
20108 function-like macro, 6.10.3 hypot functions, 7.12.7.3, F.9.4.3
20109 future directions hypot type-generic macro, 7.22
20113 I macro, 7.3.1, 7.3.9.4, G.6 initial position, 5.2.2
20114 identifier, 6.4.2.1, 6.5.1 initial shift state, 5.2.1.2
20115 linkage, see linkage initialization, 5.1.2, 6.2.4, 6.3.2.1, 6.5.2.5, 6.7.8,
20116 maximum length, 6.4.2.1 F.7.5
20117 name spaces, 6.2.3 in blocks, 6.8
20118 reserved, 6.4.1, 7.1.3 initializer, 6.7.8
20119 scope, 6.2.1 permitted form, 6.6
20120 type, 6.2.5 string literal, 6.3.2.1
20121 identifier list, 6.7.5 inline, 6.7.4
20122 identifier nondigit, 6.4.2.1 inner scope, 6.2.1
20123 IEC 559, F.1 input failure, 7.24.2.6, 7.24.2.8, 7.24.2.10
20124 IEC 60559, 2, 5.1.2.3, 5.2.4.2.2, 6.10.8, 7.3.3, 7.6, input/output functions
20125 7.6.4.2, 7.12.1, 7.12.10.2, 7.12.14, F, G, H.1 character, 7.19.7
20126 IEEE 754, F.1 direct, 7.19.8
20127 IEEE 854, F.1 formatted, 7.19.6
20128 IEEE floating-point arithmetic standard, see wide character, 7.24.2
20129 IEC 60559, ANSI/IEEE 754, wide character, 7.24.3
20130 ANSI/IEEE 854 formatted, 7.24.2
20131 if preprocessing directive, 5.2.4.2.1, 5.2.4.2.2, input/output header, 7.19
20132 6.10.1, 7.1.4 input/output, device, 5.1.2.3
20133 if statement, 6.8.4.1 int type, 6.2.5, 6.3.1.1, 6.3.1.3, 6.4.4.1, 6.7.2
20134 ifdef preprocessing directive, 6.10.1 int type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,
20135 ifndef preprocessing directive, 6.10.1 6.3.1.8
20136 ilogb functions, 7.12, 7.12.6.5, F.9.3.5 INT_FASTN_MAX macros, 7.18.2.3
20137 ilogb type-generic macro, 7.22 INT_FASTN_MIN macros, 7.18.2.3
20138 imaginary macro, 7.3.1, G.6 int_fastN_t types, 7.18.1.3
20139 imaginary numbers, G INT_LEASTN_MAX macros, 7.18.2.2
20140 imaginary type domain, G.2 INT_LEASTN_MIN macros, 7.18.2.2
20141 imaginary types, G int_leastN_t types, 7.18.1.2
20142 imaxabs function, 7.8.2.1 INT_MAX macro, 5.2.4.2.1, 7.12, 7.12.6.5
20143 imaxdiv function, 7.8, 7.8.2.2 INT_MIN macro, 5.2.4.2.1, 7.12
20144 imaxdiv_t type, 7.8 integer arithmetic functions, 7.8.2.1, 7.8.2.2,
20145 implementation, 3.12 7.20.6
20146 implementation limit, 3.13, 4, 5.2.4.2, 6.4.2.1, integer character constant, 6.4.4.4
20147 6.7.5, 6.8.4.2, E, see also environmental integer constant, 6.4.4.1
20148 limits integer constant expression, 6.6
20149 implementation-defined behavior, 3.4.1, 4, J.3 integer conversion rank, 6.3.1.1
20150 implementation-defined value, 3.17.1 integer promotions, 5.1.2.3, 5.2.4.2.1, 6.3.1.1,
20151 implicit conversion, 6.3 6.5.2.2, 6.5.3.3, 6.5.7, 6.8.4.2, 7.18.2, 7.18.3,
20152 implicit initialization, 6.7.8 7.19.6.1, 7.24.2.1
20153 include preprocessing directive, 5.1.1.2, 6.10.2 integer suffix, 6.4.4.1
20154 inclusive OR operators integer type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,
20155 bitwise (|), 6.5.12 F.3, F.4
20156 bitwise assignment (|=), 6.5.16.2 integer types, 6.2.5, 7.18
20157 incomplete type, 6.2.5 extended, 6.2.5, 6.3.1.1, 6.4.4.1, 7.18
20158 increment operators, see arithmetic operators, interactive device, 5.1.2.3, 7.19.3, 7.19.5.3
20159 increment and decrement internal linkage, 6.2.2
20160 indeterminate value, 3.17.2 internal name, 6.4.2.1
20161 indirection operator (*), 6.5.2.1, 6.5.3.2 interrupt, 5.2.3
20162 inequality operator (!=), 6.5.9 INTMAX_C macro, 7.18.4.2
20163 INFINITY macro, 7.3.9.4, 7.12, F.2.1 INTMAX_MAX macro, 7.8.2.3, 7.8.2.4, 7.18.2.5
20167 INTMAX_MIN macro, 7.8.2.3, 7.8.2.4, 7.18.2.5 iswalpha function, 7.25.2.1.1, 7.25.2.1.2,
20168 intmax_t type, 7.18.1.5, 7.19.6.1, 7.19.6.2, 7.25.2.2.1
20169 7.24.2.1, 7.24.2.2 iswblank function, 7.25.2.1.3, 7.25.2.2.1
20170 INTN_C macros, 7.18.4.1 iswcntrl function, 7.25.2.1.2, 7.25.2.1.4,
20171 INTN_MAX macros, 7.18.2.1 7.25.2.1.7, 7.25.2.1.11, 7.25.2.2.1
20172 INTN_MIN macros, 7.18.2.1 iswctype function, 7.25.2.2.1, 7.25.2.2.2
20173 intN_t types, 7.18.1.1 iswdigit function, 7.25.2.1.1, 7.25.2.1.2,
20174 INTPTR_MAX macro, 7.18.2.4 7.25.2.1.5, 7.25.2.1.7, 7.25.2.1.11, 7.25.2.2.1
20175 INTPTR_MIN macro, 7.18.2.4 iswgraph function, 7.25.2.1, 7.25.2.1.6,
20176 intptr_t type, 7.18.1.4 7.25.2.1.10, 7.25.2.2.1
20177 inttypes.h header, 7.8, 7.26.4 iswlower function, 7.25.2.1.2, 7.25.2.1.7,
20178 isalnum function, 7.4.1.1, 7.4.1.9, 7.4.1.10 7.25.2.2.1, 7.25.3.1.1, 7.25.3.1.2
20179 isalpha function, 7.4.1.1, 7.4.1.2 iswprint function, 7.25.2.1.6, 7.25.2.1.8,
20180 isblank function, 7.4.1.3 7.25.2.2.1
20181 iscntrl function, 7.4.1.2, 7.4.1.4, 7.4.1.7, iswpunct function, 7.25.2.1, 7.25.2.1.2,
20182 7.4.1.11 7.25.2.1.7, 7.25.2.1.9, 7.25.2.1.10,
20183 isdigit function, 7.4.1.1, 7.4.1.2, 7.4.1.5, 7.25.2.1.11, 7.25.2.2.1
20184 7.4.1.7, 7.4.1.11, 7.11.1.1 iswspace function, 7.19.6.2, 7.24.2.2,
20185 isfinite macro, 7.12.3.2, F.3 7.24.4.1.1, 7.24.4.1.2, 7.25.2.1.2, 7.25.2.1.6,
20186 isgraph function, 7.4.1.6 7.25.2.1.7, 7.25.2.1.9, 7.25.2.1.10,
20187 isgreater macro, 7.12.14.1, F.3 7.25.2.1.11, 7.25.2.2.1
20188 isgreaterequal macro, 7.12.14.2, F.3 iswupper function, 7.25.2.1.2, 7.25.2.1.11,
20189 isinf macro, 7.12.3.3 7.25.2.2.1, 7.25.3.1.1, 7.25.3.1.2
20190 isless macro, 7.12.14.3, F.3 iswxdigit function, 7.25.2.1.12, 7.25.2.2.1
20191 islessequal macro, 7.12.14.4, F.3 isxdigit function, 7.4.1.12, 7.11.1.1
20192 islessgreater macro, 7.12.14.5, F.3 italic type convention, 3, 6.1
20193 islower function, 7.4.1.2, 7.4.1.7, 7.4.2.1, iteration statements, 6.8.5
20195 isnan macro, 7.12.3.4, F.3 jmp_buf type, 7.13
20196 isnormal macro, 7.12.3.5 jump statements, 6.8.6
20198 ISO 4217, 2, 7.11.2.1 keywords, 6.4.1, G.2, J.5.9, J.5.10
20199 ISO 8601, 2, 7.23.3.5 known constant size, 6.2.5
20200 ISO/IEC 10646, 2, 6.4.2.1, 6.4.3, 6.10.8
20201 ISO/IEC 10976-1, H.1 L_tmpnam macro, 7.19.1, 7.19.4.4
20202 ISO/IEC 2382-1, 2, 3 label name, 6.2.1, 6.2.3
20203 ISO/IEC 646, 2, 5.2.1.1 labeled statement, 6.8.1
20204 ISO/IEC 9945-2, 7.11 labs function, 7.20.6.1
20205 ISO/IEC TR 10176, D language, 6
20206 iso646.h header, 4, 7.9 future directions, 6.11
20207 isprint function, 5.2.2, 7.4.1.8 syntax summary, A
20208 ispunct function, 7.4.1.2, 7.4.1.7, 7.4.1.9, Latin alphabet, 5.2.1, 6.4.2.1
20209 7.4.1.11 LC_ALL macro, 7.11, 7.11.1.1, 7.11.2.1
20210 isspace function, 7.4.1.2, 7.4.1.7, 7.4.1.9, LC_COLLATE macro, 7.11, 7.11.1.1, 7.21.4.3,
20211 7.4.1.10, 7.4.1.11, 7.19.6.2, 7.20.1.3, 7.24.4.4.2
20212 7.20.1.4, 7.24.2.2 LC_CTYPE macro, 7.11, 7.11.1.1, 7.20, 7.20.7,
20213 isunordered macro, 7.12.14.6, F.3 7.20.8, 7.24.6, 7.25.1, 7.25.2.2.1, 7.25.2.2.2,
20214 isupper function, 7.4.1.2, 7.4.1.11, 7.4.2.1, 7.25.3.2.1, 7.25.3.2.2
20215 7.4.2.2 LC_MONETARY macro, 7.11, 7.11.1.1, 7.11.2.1
20216 iswalnum function, 7.25.2.1.1, 7.25.2.1.9, LC_NUMERIC macro, 7.11, 7.11.1.1, 7.11.2.1
20217 7.25.2.1.10, 7.25.2.2.1 LC_TIME macro, 7.11, 7.11.1.1, 7.23.3.5
20221 lconv structure type, 7.11 llabs function, 7.20.6.1
20222 LDBL_DIG macro, 5.2.4.2.2 lldiv function, 7.20.6.2
20223 LDBL_EPSILON macro, 5.2.4.2.2 lldiv_t type, 7.20
20224 LDBL_MANT_DIG macro, 5.2.4.2.2 LLONG_MAX macro, 5.2.4.2.1, 7.20.1.4,
20225 LDBL_MAX macro, 5.2.4.2.2 7.24.4.1.2
20226 LDBL_MAX_10_EXP macro, 5.2.4.2.2 LLONG_MIN macro, 5.2.4.2.1, 7.20.1.4,
20227 LDBL_MAX_EXP macro, 5.2.4.2.2 7.24.4.1.2
20228 LDBL_MIN macro, 5.2.4.2.2 llrint functions, 7.12.9.5, F.3, F.9.6.5
20229 LDBL_MIN_10_EXP macro, 5.2.4.2.2 llrint type-generic macro, 7.22
20230 LDBL_MIN_EXP macro, 5.2.4.2.2 llround functions, 7.12.9.7, F.9.6.7
20231 ldexp functions, 7.12.6.6, F.9.3.6 llround type-generic macro, 7.22
20232 ldexp type-generic macro, 7.22 local time, 7.23.1
20233 ldiv function, 7.20.6.2 locale, 3.4.2
20234 ldiv_t type, 7.20 locale-specific behavior, 3.4.2, J.4
20235 leading underscore in identifiers, 7.1.3 locale.h header, 7.11, 7.26.5
20236 left-shift assignment operator (<<=), 6.5.16.2 localeconv function, 7.11.1.1, 7.11.2.1
20237 left-shift operator (<<), 6.5.7 localization, 7.11
20238 length localtime function, 7.23.3.4
20239 external name, 5.2.4.1, 6.4.2.1, 6.11.3 log functions, 7.12.6.7, F.9.3.7
20240 function name, 5.2.4.1, 6.4.2.1, 6.11.3 log type-generic macro, 7.22
20241 identifier, 6.4.2.1 log10 functions, 7.12.6.8, F.9.3.8
20242 internal name, 5.2.4.1, 6.4.2.1 log10 type-generic macro, 7.22
20243 length function, 7.20.7.1, 7.21.6.3, 7.24.4.6.1, log1p functions, 7.12.6.9, F.9.3.9
20244 7.24.6.3.1 log1p type-generic macro, 7.22
20245 length modifier, 7.19.6.1, 7.19.6.2, 7.24.2.1, log2 functions, 7.12.6.10, F.9.3.10
20246 7.24.2.2 log2 type-generic macro, 7.22
20247 less-than operator (<), 6.5.8 logarithmic functions
20248 less-than-or-equal-to operator (<=), 6.5.8 complex, 7.3.7, G.6.3
20249 letter, 5.2.1, 7.4 real, 7.12.6, F.9.3
20250 lexical elements, 5.1.1.2, 6.4 logb functions, 7.12.6.11, F.3, F.9.3.11
20251 lgamma functions, 7.12.8.3, F.9.5.3 logb type-generic macro, 7.22
20252 lgamma type-generic macro, 7.22 logical operators
20253 library, 5.1.1.1, 7 AND (&&), 6.5.13
20254 future directions, 7.26 negation (!), 6.5.3.3
20255 summary, B OR (||), 6.5.14
20256 terms, 7.1.1 logical source lines, 5.1.1.2
20257 use of functions, 7.1.4 long double _Complex type, 6.2.5
20258 lifetime, 6.2.4 long double _Complex type conversion,
20259 limits 6.3.1.6, 6.3.1.7, 6.3.1.8
20260 environmental, see environmental limits long double _Imaginary type, G.2
20261 implementation, see implementation limits long double suffix, l or L, 6.4.4.2
20262 numerical, see numerical limits long double type, 6.2.5, 6.4.4.2, 6.7.2,
20263 translation, see translation limits 7.19.6.1, 7.19.6.2, 7.24.2.1, 7.24.2.2, F.2
20264 limits.h header, 4, 5.2.4.2.1, 6.2.5, 7.10 long double type conversion, 6.3.1.4, 6.3.1.5,
20265 line buffered stream, 7.19.3 6.3.1.7, 6.3.1.8
20266 line number, 6.10.4, 6.10.8 long int type, 6.2.5, 6.3.1.1, 6.7.2, 7.19.6.1,
20267 line preprocessing directive, 6.10.4 7.19.6.2, 7.24.2.1, 7.24.2.2
20268 lines, 5.1.1.2, 7.19.2 long int type conversion, 6.3.1.1, 6.3.1.3,
20269 preprocessing directive, 6.10 6.3.1.4, 6.3.1.8
20270 linkage, 6.2.2, 6.7, 6.7.4, 6.7.5.2, 6.9, 6.9.2, long integer suffix, l or L, 6.4.4.1
20271 6.11.2 long long int type, 6.2.5, 6.3.1.1, 6.7.2,
20275 7.19.6.1, 7.19.6.2, 7.24.2.1, 7.24.2.2 mbsinit function, 7.24.6.2.1
20276 long long int type conversion, 6.3.1.1, mbsrtowcs function, 7.24.6.4.1
20277 6.3.1.3, 6.3.1.4, 6.3.1.8 mbstate_t type, 7.19.2, 7.19.3, 7.19.6.1,
20278 long long integer suffix, ll or LL, 6.4.4.1 7.19.6.2, 7.24.1, 7.24.2.1, 7.24.2.2, 7.24.6,
20279 LONG_MAX macro, 5.2.4.2.1, 7.20.1.4, 7.24.4.1.2 7.24.6.2.1, 7.24.6.3, 7.24.6.3.1, 7.24.6.4
20280 LONG_MIN macro, 5.2.4.2.1, 7.20.1.4, 7.24.4.1.2 mbstowcs function, 6.4.5, 7.20.8.1, 7.24.6.4
20281 longjmp function, 7.13.1.1, 7.13.2.1, 7.20.4.3 mbtowc function, 7.20.7.1, 7.20.7.2, 7.20.8.1,
20282 loop body, 6.8.5 7.24.6.3
20283 low-order bit, 3.6 member access operators (. and ->), 6.5.2.3
20284 lowercase letter, 5.2.1 member alignment, 6.7.2.1
20285 lrint functions, 7.12.9.5, F.3, F.9.6.5 memchr function, 7.21.5.1
20286 lrint type-generic macro, 7.22 memcmp function, 7.21.4, 7.21.4.1
20287 lround functions, 7.12.9.7, F.9.6.7 memcpy function, 7.21.2.1
20288 lround type-generic macro, 7.22 memmove function, 7.21.2.2
20289 lvalue, 6.3.2.1, 6.5.1, 6.5.2.4, 6.5.3.1, 6.5.16 memory management functions, 7.20.3
20290 memset function, 7.21.6.1
20291 macro argument substitution, 6.10.3.1 minimum functions, 7.12.12, F.9.9
20292 macro definition minus operator, unary, 6.5.3.3
20293 library function, 7.1.4 miscellaneous functions
20294 macro invocation, 6.10.3 string, 7.21.6
20295 macro name, 6.10.3 wide string, 7.24.4.6
20296 length, 5.2.4.1 mktime function, 7.23.2.3
20297 predefined, 6.10.8, 6.11.9 modf functions, 7.12.6.12, F.9.3.12
20298 redefinition, 6.10.3 modifiable lvalue, 6.3.2.1
20299 scope, 6.10.3.5 modulus functions, 7.12.6.12
20300 macro parameter, 6.10.3 modulus, complex, 7.3.8.1
20301 macro preprocessor, 6.10 multibyte character, 3.7.2, 5.2.1.2, 6.4.4.4
20302 macro replacement, 6.10.3 multibyte conversion functions
20303 magnitude, complex, 7.3.8.1 wide character, 7.20.7
20304 main function, 5.1.2.2.1, 5.1.2.2.3, 6.7.3.1, 6.7.4, extended, 7.24.6
20305 7.19.3 restartable, 7.24.6.3
20306 malloc function, 7.20.3, 7.20.3.2, 7.20.3.3, wide string, 7.20.8
20307 7.20.3.4 restartable, 7.24.6.4
20308 manipulation functions multibyte string, 7.1.1
20309 complex, 7.3.9 multibyte/wide character conversion functions,
20310 real, 7.12.11, F.9.8 7.20.7
20311 matching failure, 7.24.2.6, 7.24.2.8, 7.24.2.10 extended, 7.24.6
20312 math.h header, 5.2.4.2.2, 6.5, 7.12, 7.22, F, F.9, restartable, 7.24.6.3
20313 J.5.17 multibyte/wide string conversion functions, 7.20.8
20314 MATH_ERREXCEPT macro, 7.12, F.9 restartable, 7.24.6.4
20315 math_errhandling macro, 7.1.3, 7.12, F.9 multidimensional array, 6.5.2.1
20316 MATH_ERRNO macro, 7.12 multiplication assignment operator (*=), 6.5.16.2
20317 maximum functions, 7.12.12, F.9.9 multiplication operator (*), 6.5.5, F.3, G.5.1
20318 MB_CUR_MAX macro, 7.1.1, 7.20, 7.20.7.2, multiplicative expressions, 6.5.5, G.5.1
20319 7.20.7.3, 7.24.6.3.3
20320 MB_LEN_MAX macro, 5.2.4.2.1, 7.1.1, 7.20 n-char sequence, 7.20.1.3
20321 mblen function, 7.20.7.1, 7.24.6.3 n-wchar sequence, 7.24.4.1.1
20322 mbrlen function, 7.24.6.3.1 name
20323 mbrtowc function, 7.19.3, 7.19.6.1, 7.19.6.2, external, 5.2.4.1, 6.4.2.1, 6.11.3
20324 7.24.2.1, 7.24.2.2, 7.24.6.3.1, 7.24.6.3.2, file, 7.19.3
20325 7.24.6.4.1 internal, 5.2.4.1, 6.4.2.1
20329 label, 6.2.3 octal-character escape sequence (\octal digits),
20330 structure/union member, 6.2.3 6.4.4.4
20331 name spaces, 6.2.3 offsetof macro, 7.17
20332 named label, 6.8.1 on-off switch, 6.10.6
20333 NaN, 5.2.4.2.2 ones' complement, 6.2.6.2
20334 nan functions, 7.12.11.2, F.2.1, F.9.8.2 operand, 6.4.6, 6.5
20335 NAN macro, 7.12, F.2.1 operating system, 5.1.2.1, 7.20.4.6
20336 NDEBUG macro, 7.2 operations on files, 7.19.4
20337 nearbyint functions, 7.12.9.3, 7.12.9.4, F.3, operator, 6.4.6
20338 F.9.6.3 operators, 6.5
20339 nearbyint type-generic macro, 7.22 assignment, 6.5.16
20340 nearest integer functions, 7.12.9, F.9.6 associativity, 6.5
20341 negation operator (!), 6.5.3.3 equality, 6.5.9
20342 negative zero, 6.2.6.2, 7.12.11.1 multiplicative, 6.5.5, G.5.1
20343 new-line character, 5.1.1.2, 5.2.1, 6.4, 6.10, 6.10.4 postfix, 6.5.2
20344 new-line escape sequence (\n), 5.2.2, 6.4.4.4, precedence, 6.5
20345 7.4.1.10 preprocessing, 6.10.1, 6.10.3.2, 6.10.3.3, 6.10.9
20346 nextafter functions, 7.12.11.3, 7.12.11.4, F.3, relational, 6.5.8
20347 F.9.8.3 shift, 6.5.7
20348 nextafter type-generic macro, 7.22 unary, 6.5.3
20349 nexttoward functions, 7.12.11.4, F.3, F.9.8.4 unary arithmetic, 6.5.3.3
20350 nexttoward type-generic macro, 7.22 or macro, 7.9
20351 no linkage, 6.2.2 OR operators
20352 non-stop floating-point control mode, 7.6.4.2 bitwise exclusive (^), 6.5.11
20353 nongraphic characters, 5.2.2, 6.4.4.4 bitwise exclusive assignment (^=), 6.5.16.2
20354 nonlocal jumps header, 7.13 bitwise inclusive (|), 6.5.12
20355 norm, complex, 7.3.8.1 bitwise inclusive assignment (|=), 6.5.16.2
20356 not macro, 7.9 logical (||), 6.5.14
20357 not-equal-to operator, see inequality operator or_eq macro, 7.9
20358 not_eq macro, 7.9 order of allocated storage, 7.20.3
20359 null character (\0), 5.2.1, 6.4.4.4, 6.4.5 order of evaluation, 6.5
20360 padding of binary stream, 7.19.2 ordinary identifier name space, 6.2.3
20361 NULL macro, 7.11, 7.17, 7.19.1, 7.20, 7.21.1, orientation of stream, 7.19.2, 7.24.3.5
20362 7.23.1, 7.24.1 outer scope, 6.2.1
20363 null pointer, 6.3.2.3
20364 null pointer constant, 6.3.2.3 padding
20365 null preprocessing directive, 6.10.7 binary stream, 7.19.2
20366 null statement, 6.8.3 bits, 6.2.6.2, 7.18.1.1
20367 null wide character, 7.1.1 structure/union, 6.2.6.1, 6.7.2.1
20368 number classification macros, 7.12, 7.12.3.1 parameter, 3.15
20369 numeric conversion functions, 7.8.2.3, 7.20.1 array, 6.9.1
20370 wide string, 7.8.2.4, 7.24.4.1 ellipsis, 6.7.5.3, 6.10.3
20371 numerical limits, 5.2.4.2 function, 6.5.2.2, 6.7, 6.9.1
20373 object, 3.14 main function, 5.1.2.2.1
20374 object representation, 6.2.6.1 program, 5.1.2.2.1
20375 object type, 6.2.5 parameter type list, 6.7.5.3
20376 object-like macro, 6.10.3 parentheses punctuator (( )), 6.7.5.3, 6.8.4, 6.8.5
20377 obsolescence, 6.11, 7.26 parenthesized expression, 6.5.1
20378 octal constant, 6.4.4.1 parse state, 7.19.2
20379 octal digit, 6.4.4.1, 6.4.4.4 permitted form of initializer, 6.6
20383 perror function, 7.19.10.4 PRIcPTR macros, 7.8.1
20384 phase angle, complex, 7.3.9.1 primary expression, 6.5.1
20385 physical source lines, 5.1.1.2 printf function, 7.19.1, 7.19.6.3, 7.19.6.10
20386 placemarker, 6.10.3.3 printing character, 5.2.2, 7.4, 7.4.1.8
20387 plus operator, unary, 6.5.3.3 printing wide character, 7.25.2
20388 pointer arithmetic, 6.5.6 program diagnostics, 7.2.1
20389 pointer comparison, 6.5.8 program execution, 5.1.2.2.2, 5.1.2.3
20390 pointer declarator, 6.7.5.1 program file, 5.1.1.1
20391 pointer operator (->), 6.5.2.3 program image, 5.1.1.2
20392 pointer to function, 6.5.2.2 program name (argv[0]), 5.1.2.2.1
20393 pointer type, 6.2.5 program parameters, 5.1.2.2.1
20394 pointer type conversion, 6.3.2.1, 6.3.2.3 program startup, 5.1.2, 5.1.2.1, 5.1.2.2.1
20395 pointer, null, 6.3.2.3 program structure, 5.1.1.1
20396 portability, 4, J program termination, 5.1.2, 5.1.2.1, 5.1.2.2.3,
20397 position indicator, file, see file position indicator 5.1.2.3
20398 positive difference, 7.12.12.1 program, conforming, 4
20399 positive difference functions, 7.12.12, F.9.9 program, strictly conforming, 4
20400 postfix decrement operator (--), 6.3.2.1, 6.5.2.4 promotions
20401 postfix expressions, 6.5.2 default argument, 6.5.2.2
20402 postfix increment operator (++), 6.3.2.1, 6.5.2.4 integer, 5.1.2.3, 6.3.1.1
20403 pow functions, 7.12.7.4, F.9.4.4 prototype, see function prototype
20404 pow type-generic macro, 7.22 pseudo-random sequence functions, 7.20.2
20405 power functions PTRDIFF_MAX macro, 7.18.3
20406 complex, 7.3.8, G.6.4 PTRDIFF_MIN macro, 7.18.3
20407 real, 7.12.7, F.9.4 ptrdiff_t type, 7.17, 7.18.3, 7.19.6.1,
20408 pp-number, 6.4.8 7.19.6.2, 7.24.2.1, 7.24.2.2
20409 pragma operator, 6.10.9 punctuators, 6.4.6
20410 pragma preprocessing directive, 6.10.6, 6.11.8 putc function, 7.19.1, 7.19.7.8, 7.19.7.9
20411 precedence of operators, 6.5 putchar function, 7.19.1, 7.19.7.9
20412 precedence of syntax rules, 5.1.1.2 puts function, 7.19.1, 7.19.7.10
20413 precision, 6.2.6.2, 6.3.1.1, 7.19.6.1, 7.24.2.1 putwc function, 7.19.1, 7.24.3.8, 7.24.3.9
20414 excess, 5.2.4.2.2, 6.3.1.5, 6.3.1.8, 6.8.6.4 putwchar function, 7.19.1, 7.24.3.9
20415 predefined macro names, 6.10.8, 6.11.9
20416 prefix decrement operator (--), 6.3.2.1, 6.5.3.1 qsort function, 7.20.5, 7.20.5.2
20417 prefix increment operator (++), 6.3.2.1, 6.5.3.1 qualified types, 6.2.5
20418 preprocessing concatenation, 6.10.3.3 qualified version of type, 6.2.5
20419 preprocessing directives, 5.1.1.2, 6.10 question-mark escape sequence (\?), 6.4.4.4
20420 preprocessing file, 5.1.1.1, 6.10 quiet NaN, 5.2.4.2.2
20421 preprocessing numbers, 6.4, 6.4.8
20422 preprocessing operators raise function, 7.14, 7.14.1.1, 7.14.2.1, 7.20.4.1
20423 #, 6.10.3.2 rand function, 7.20, 7.20.2.1, 7.20.2.2
20424 ##, 6.10.3.3 RAND_MAX macro, 7.20, 7.20.2.1
20425 _Pragma, 5.1.1.2, 6.10.9 range
20426 defined, 6.10.1 excess, 5.2.4.2.2, 6.3.1.5, 6.3.1.8, 6.8.6.4
20427 preprocessing tokens, 5.1.1.2, 6.4, 6.10 range error, 7.12.1, 7.12.5.3, 7.12.5.4, 7.12.5.5,
20428 preprocessing translation unit, 5.1.1.1 7.12.6.1, 7.12.6.2, 7.12.6.3, 7.12.6.5,
20429 preprocessor, 6.10 7.12.6.6, 7.12.6.7, 7.12.6.8, 7.12.6.9,
20430 PRIcFASTN macros, 7.8.1 7.12.6.10, 7.12.6.11, 7.12.6.13, 7.12.7.3,
20431 PRIcLEASTN macros, 7.8.1 7.12.7.4, 7.12.8.2, 7.12.8.3, 7.12.8.4,
20432 PRIcMAX macros, 7.8.1 7.12.9.5, 7.12.9.7, 7.12.11.3, 7.12.12.1,
20433 PRIcN macros, 7.8.1 7.12.13.1
20437 rank, see integer conversion rank same scope, 6.2.1
20438 real floating type conversion, 6.3.1.4, 6.3.1.5, save calling environment function, 7.13.1
20439 6.3.1.7, F.3, F.4 scalar types, 6.2.5
20440 real floating types, 6.2.5 scalbln function, 7.12.6.13, F.3, F.9.3.13
20441 real type domain, 6.2.5 scalbln type-generic macro, 7.22
20442 real types, 6.2.5 scalbn function, 7.12.6.13, F.3, F.9.3.13
20443 real-floating, 7.12.3 scalbn type-generic macro, 7.22
20444 realloc function, 7.20.3, 7.20.3.2, 7.20.3.4 scanf function, 7.19.1, 7.19.6.4, 7.19.6.11
20445 recommended practice, 3.16 scanlist, 7.19.6.2, 7.24.2.2
20446 recursion, 6.5.2.2 scanset, 7.19.6.2, 7.24.2.2
20447 recursive function call, 6.5.2.2 SCHAR_MAX macro, 5.2.4.2.1
20448 redefinition of macro, 6.10.3 SCHAR_MIN macro, 5.2.4.2.1
20449 reentrancy, 5.1.2.3, 5.2.3 SCNcFASTN macros, 7.8.1
20450 library functions, 7.1.4 SCNcLEASTN macros, 7.8.1
20451 referenced type, 6.2.5 SCNcMAX macros, 7.8.1
20452 register storage-class specifier, 6.7.1, 6.9 SCNcN macros, 7.8.1
20453 relational expressions, 6.5.8 SCNcPTR macros, 7.8.1
20454 reliability of data, interrupted, 5.1.2.3 scope of identifier, 6.2.1, 6.9.2
20455 remainder assignment operator (%=), 6.5.16.2 search functions
20456 remainder functions, 7.12.10, F.9.7 string, 7.21.5
20457 remainder functions, 7.12.10.2, 7.12.10.3, F.3, utility, 7.20.5
20458 F.9.7.2 wide string, 7.24.4.5
20459 remainder operator (%), 6.5.5 SEEK_CUR macro, 7.19.1, 7.19.9.2
20460 remainder type-generic macro, 7.22 SEEK_END macro, 7.19.1, 7.19.9.2
20461 remove function, 7.19.4.1, 7.19.4.4 SEEK_SET macro, 7.19.1, 7.19.9.2
20462 remquo functions, 7.12.10.3, F.3, F.9.7.3 selection statements, 6.8.4
20463 remquo type-generic macro, 7.22 self-referential structure, 6.7.2.3
20464 rename function, 7.19.4.2 semicolon punctuator (;), 6.7, 6.7.2.1, 6.8.3,
20465 representations of types, 6.2.6 6.8.5, 6.8.6
20466 pointer, 6.2.5 separate compilation, 5.1.1.1
20467 rescanning and replacement, 6.10.3.4 separate translation, 5.1.1.1
20468 reserved identifiers, 6.4.1, 7.1.3 sequence points, 5.1.2.3, 6.5, 6.8, 7.1.4, 7.19.6,
20469 restartable multibyte/wide character conversion 7.20.5, 7.24.2, C
20470 functions, 7.24.6.3 sequencing of statements, 6.8
20471 restartable multibyte/wide string conversion setbuf function, 7.19.3, 7.19.5.1, 7.19.5.5
20472 functions, 7.24.6.4 setjmp macro, 7.1.3, 7.13.1.1, 7.13.2.1
20473 restore calling environment function, 7.13.2 setjmp.h header, 7.13
20474 restrict type qualifier, 6.7.3, 6.7.3.1 setlocale function, 7.11.1.1, 7.11.2.1
20475 restrict-qualified type, 6.2.5, 6.7.3 setvbuf function, 7.19.1, 7.19.3, 7.19.5.1,
20476 return statement, 6.8.6.4 7.19.5.5, 7.19.5.6
20477 rewind function, 7.19.5.3, 7.19.7.11, 7.19.9.5, shall, 4
20478 7.24.3.10 shift expressions, 6.5.7
20479 right-shift assignment operator (>>=), 6.5.16.2 shift sequence, 7.1.1
20480 right-shift operator (>>), 6.5.7 shift states, 5.2.1.2
20481 rint functions, 7.12.9.4, F.3, F.9.6.4 short identifier, character, 5.2.4.1, 6.4.3
20482 rint type-generic macro, 7.22 short int type, 6.2.5, 6.3.1.1, 6.7.2, 7.19.6.1,
20483 round functions, 7.12.9.6, F.9.6.6 7.19.6.2, 7.24.2.1, 7.24.2.2
20484 round type-generic macro, 7.22 short int type conversion, 6.3.1.1, 6.3.1.3,
20485 rounding mode, floating point, 5.2.4.2.2 6.3.1.4, 6.3.1.8
20486 rvalue, 6.3.2.1 SHRT_MAX macro, 5.2.4.2.1
20487 SHRT_MIN macro, 5.2.4.2.1
20491 side effects, 5.1.2.3, 6.5 source lines, 5.1.1.2
20492 SIG_ATOMIC_MAX macro, 7.18.3 source text, 5.1.1.2
20493 SIG_ATOMIC_MIN macro, 7.18.3 space character (' '), 5.1.1.2, 5.2.1, 6.4, 7.4.1.3,
20494 sig_atomic_t type, 7.14, 7.14.1.1, 7.18.3 7.4.1.10, 7.25.2.1.3
20495 SIG_DFL macro, 7.14, 7.14.1.1 sprintf function, 7.19.6.6, 7.19.6.13
20496 SIG_ERR macro, 7.14, 7.14.1.1 sqrt functions, 7.12.7.5, F.3, F.9.4.5
20497 SIG_IGN macro, 7.14, 7.14.1.1 sqrt type-generic macro, 7.22
20498 SIGABRT macro, 7.14, 7.20.4.1 srand function, 7.20.2.2
20499 SIGFPE macro, 7.14, 7.14.1.1, J.5.17 sscanf function, 7.19.6.7, 7.19.6.14
20500 SIGILL macro, 7.14, 7.14.1.1 standard error stream, 7.19.1, 7.19.3, 7.19.10.4
20501 SIGINT macro, 7.14 standard headers, 4, 7.1.2
20502 sign and magnitude, 6.2.6.2 <assert.h>, 7.2, B.1
20503 sign bit, 6.2.6.2 <complex.h>, 5.2.4.2.2, 7.3, 7.22, 7.26.1,
20504 signal function, 7.14.1.1, 7.20.4.4 G.6, J.5.17
20505 signal handler, 5.1.2.3, 5.2.3, 7.14.1.1, 7.14.2.1 <ctype.h>, 7.4, 7.26.2
20506 signal handling functions, 7.14.1 <errno.h>, 7.5, 7.26.3
20507 signal.h header, 7.14, 7.26.6 <fenv.h>, 5.1.2.3, 5.2.4.2.2, 7.6, 7.12, F, H
20508 signaling NaN, 5.2.4.2.2, F.2.1 <float.h>, 4, 5.2.4.2.2, 7.7, 7.20.1.3,
20509 signals, 5.1.2.3, 5.2.3, 7.14.1 7.24.4.1.1
20510 signbit macro, 7.12.3.6, F.3 <inttypes.h>, 7.8, 7.26.4
20511 signed char type, 6.2.5, 7.19.6.1, 7.19.6.2, <iso646.h>, 4, 7.9
20512 7.24.2.1, 7.24.2.2 <limits.h>, 4, 5.2.4.2.1, 6.2.5, 7.10
20513 signed character, 6.3.1.1 <locale.h>, 7.11, 7.26.5
20514 signed integer types, 6.2.5, 6.3.1.3, 6.4.4.1 <math.h>, 5.2.4.2.2, 6.5, 7.12, 7.22, F, F.9,
20515 signed type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4, J.5.17
20516 6.3.1.8 <setjmp.h>, 7.13
20517 signed types, 6.2.5, 6.7.2 <signal.h>, 7.14, 7.26.6
20518 significand part, 6.4.4.2 <stdarg.h>, 4, 6.7.5.3, 7.15
20519 SIGSEGV macro, 7.14, 7.14.1.1 <stdbool.h>, 4, 7.16, 7.26.7, H
20520 SIGTERM macro, 7.14 <stddef.h>, 4, 6.3.2.1, 6.3.2.3, 6.4.4.4,
20521 simple assignment operator (=), 6.5.16.1 6.4.5, 6.5.3.4, 6.5.6, 7.17
20522 sin functions, 7.12.4.6, F.9.1.6 <stdint.h>, 4, 5.2.4.2, 6.10.1, 7.8, 7.18,
20523 sin type-generic macro, 7.22, G.7 7.26.8
20524 single-byte character, 3.7.1, 5.2.1.2 <stdio.h>, 5.2.4.2.2, 7.19, 7.26.9, F
20525 single-byte/wide character conversion functions, <stdlib.h>, 5.2.4.2.2, 7.20, 7.26.10, F
20526 7.24.6.1 <string.h>, 7.21, 7.26.11
20527 single-precision arithmetic, 5.1.2.3 <tgmath.h>, 7.22, G.7
20528 single-quote escape sequence (\'), 6.4.4.4, 6.4.5 <time.h>, 7.23
20529 sinh functions, 7.12.5.5, F.9.2.5 <wchar.h>, 5.2.4.2.2, 7.19.1, 7.24, 7.26.12,
20530 sinh type-generic macro, 7.22, G.7 F
20531 SIZE_MAX macro, 7.18.3 <wctype.h>, 7.25, 7.26.13
20532 size_t type, 6.5.3.4, 7.17, 7.18.3, 7.19.1, standard input stream, 7.19.1, 7.19.3
20533 7.19.6.1, 7.19.6.2, 7.20, 7.21.1, 7.23.1, standard integer types, 6.2.5
20534 7.24.1, 7.24.2.1, 7.24.2.2 standard output stream, 7.19.1, 7.19.3
20535 sizeof operator, 6.3.2.1, 6.5.3, 6.5.3.4 standard signed integer types, 6.2.5
20536 snprintf function, 7.19.6.5, 7.19.6.12 state-dependent encoding, 5.2.1.2, 7.20.7
20537 sorting utility functions, 7.20.5 statements, 6.8
20538 source character set, 5.1.1.2, 5.2.1 break, 6.8.6.3
20539 source file, 5.1.1.1 compound, 6.8.2
20540 name, 6.10.4, 6.10.8 continue, 6.8.6.2
20541 source file inclusion, 6.10.2 do, 6.8.5.2
20545 else, 6.8.4.1 strictly conforming program, 4
20546 expression, 6.8.3 string, 7.1.1
20547 for, 6.8.5.3 comparison functions, 7.21.4
20548 goto, 6.8.6.1 concatenation functions, 7.21.3
20549 if, 6.8.4.1 conversion functions, 7.11.1.1
20550 iteration, 6.8.5 copying functions, 7.21.2
20551 jump, 6.8.6 library function conventions, 7.21.1
20552 labeled, 6.8.1 literal, 5.1.1.2, 5.2.1, 6.3.2.1, 6.4.5, 6.5.1, 6.7.8
20553 null, 6.8.3 miscellaneous functions, 7.21.6
20554 return, 6.8.6.4 numeric conversion functions, 7.8.2.3, 7.20.1
20555 selection, 6.8.4 search functions, 7.21.5
20556 sequencing, 6.8 string handling header, 7.21
20557 switch, 6.8.4.2 string.h header, 7.21, 7.26.11
20558 while, 6.8.5.1 stringizing, 6.10.3.2, 6.10.9
20559 static storage duration, 6.2.4 strlen function, 7.21.6.3
20560 static storage-class specifier, 6.2.2, 6.2.4, 6.7.1 strncat function, 7.21.3.2
20561 static, in array declarators, 6.7.5.2, 6.7.5.3 strncmp function, 7.21.4, 7.21.4.4
20562 stdarg.h header, 4, 6.7.5.3, 7.15 strncpy function, 7.21.2.4
20563 stdbool.h header, 4, 7.16, 7.26.7, H strpbrk function, 7.21.5.4
20564 STDC, 6.10.6, 6.11.8 strrchr function, 7.21.5.5
20565 stddef.h header, 4, 6.3.2.1, 6.3.2.3, 6.4.4.4, strspn function, 7.21.5.6
20566 6.4.5, 6.5.3.4, 6.5.6, 7.17 strstr function, 7.21.5.7
20567 stderr macro, 7.19.1, 7.19.2, 7.19.3 strtod function, 7.12.11.2, 7.19.6.2, 7.20.1.3,
20568 stdin macro, 7.19.1, 7.19.2, 7.19.3, 7.19.6.4, 7.24.2.2, F.3
20569 7.19.7.6, 7.19.7.7, 7.24.2.12, 7.24.3.7 strtof function, 7.12.11.2, 7.20.1.3, F.3
20570 stdint.h header, 4, 5.2.4.2, 6.10.1, 7.8, 7.18, strtoimax function, 7.8.2.3
20571 7.26.8 strtok function, 7.21.5.8
20572 stdio.h header, 5.2.4.2.2, 7.19, 7.26.9, F strtol function, 7.8.2.3, 7.19.6.2, 7.20.1.2,
20573 stdlib.h header, 5.2.4.2.2, 7.20, 7.26.10, F 7.20.1.4, 7.24.2.2
20574 stdout macro, 7.19.1, 7.19.2, 7.19.3, 7.19.6.3, strtold function, 7.12.11.2, 7.20.1.3, F.3
20575 7.19.7.9, 7.19.7.10, 7.24.2.11, 7.24.3.9 strtoll function, 7.8.2.3, 7.20.1.2, 7.20.1.4
20576 storage duration, 6.2.4 strtoul function, 7.8.2.3, 7.19.6.2, 7.20.1.2,
20577 storage order of array, 6.5.2.1 7.20.1.4, 7.24.2.2
20578 storage-class specifiers, 6.7.1, 6.11.5 strtoull function, 7.8.2.3, 7.20.1.2, 7.20.1.4
20579 strcat function, 7.21.3.1 strtoumax function, 7.8.2.3
20580 strchr function, 7.21.5.2 struct hack, see flexible array member
20581 strcmp function, 7.21.4, 7.21.4.2 structure
20582 strcoll function, 7.11.1.1, 7.21.4.3, 7.21.4.5 arrow operator (->), 6.5.2.3
20583 strcpy function, 7.21.2.3 content, 6.7.2.3
20584 strcspn function, 7.21.5.3 dot operator (.), 6.5.2.3
20585 streams, 7.19.2, 7.20.4.3 initialization, 6.7.8
20586 fully buffered, 7.19.3 member alignment, 6.7.2.1
20587 line buffered, 7.19.3 member name space, 6.2.3
20588 orientation, 7.19.2 member operator (.), 6.3.2.1, 6.5.2.3
20589 standard error, 7.19.1, 7.19.3 pointer operator (->), 6.5.2.3
20590 standard input, 7.19.1, 7.19.3 specifier, 6.7.2.1
20591 standard output, 7.19.1, 7.19.3 tag, 6.2.3, 6.7.2.3
20592 unbuffered, 7.19.3 type, 6.2.5, 6.7.2.1
20593 strerror function, 7.19.10.4, 7.21.6.2 strxfrm function, 7.11.1.1, 7.21.4.5
20594 strftime function, 7.11.1.1, 7.23.3, 7.23.3.5, subscripting, 6.5.2.1
20595 7.24.5.1 subtraction assignment operator (-=), 6.5.16.2
20599 subtraction operator (-), 6.5.6, F.3, G.5.2 tolower function, 7.4.2.1
20600 suffix toupper function, 7.4.2.2
20601 floating constant, 6.4.4.2 towctrans function, 7.25.3.2.1, 7.25.3.2.2
20602 integer constant, 6.4.4.1 towlower function, 7.25.3.1.1, 7.25.3.2.1
20603 switch body, 6.8.4.2 towupper function, 7.25.3.1.2, 7.25.3.2.1
20604 switch case label, 6.8.1, 6.8.4.2 translation environment, 5, 5.1.1
20605 switch default label, 6.8.1, 6.8.4.2 translation limits, 5.2.4.1
20606 switch statement, 6.8.1, 6.8.4.2 translation phases, 5.1.1.2
20607 swprintf function, 7.24.2.3, 7.24.2.7 translation unit, 5.1.1.1, 6.9
20608 swscanf function, 7.24.2.4, 7.24.2.8 trap representation, 6.2.6.1, 6.2.6.2, 6.3.2.3,
20610 syntactic categories, 6.1 trigonometric functions
20611 syntax notation, 6.1 complex, 7.3.5, G.6.1
20612 syntax rule precedence, 5.1.1.2 real, 7.12.4, F.9.1
20613 syntax summary, language, A trigraph sequences, 5.1.1.2, 5.2.1.1
20614 system function, 7.20.4.6 true macro, 7.16
20615 trunc functions, 7.12.9.8, F.9.6.8
20616 tab characters, 5.2.1, 6.4 trunc type-generic macro, 7.22
20617 tag compatibility, 6.2.7 truncation, 6.3.1.4, 7.12.9.8, 7.19.3, 7.19.5.3
20618 tag name space, 6.2.3 truncation toward zero, 6.5.5
20619 tags, 6.7.2.3 two's complement, 6.2.6.2, 7.18.1.1
20620 tan functions, 7.12.4.7, F.9.1.7 type category, 6.2.5
20621 tan type-generic macro, 7.22, G.7 type conversion, 6.3
20622 tanh functions, 7.12.5.6, F.9.2.6 type definitions, 6.7.7
20623 tanh type-generic macro, 7.22, G.7 type domain, 6.2.5, G.2
20624 tentative definition, 6.9.2 type names, 6.7.6
20625 terms, 3 type punning, 6.5.2.3
20626 text streams, 7.19.2, 7.19.7.11, 7.19.9.2, 7.19.9.4 type qualifiers, 6.7.3
20627 tgamma functions, 7.12.8.4, F.9.5.4 type specifiers, 6.7.2
20628 tgamma type-generic macro, 7.22 type-generic macro, 7.22, G.7
20629 tgmath.h header, 7.22, G.7 typedef declaration, 6.7.7
20630 time typedef storage-class specifier, 6.7.1, 6.7.7
20631 broken down, 7.23.1, 7.23.2.3, 7.23.3, 7.23.3.1, types, 6.2.5
20632 7.23.3.3, 7.23.3.4, 7.23.3.5 character, 6.7.8
20633 calendar, 7.23.1, 7.23.2.2, 7.23.2.3, 7.23.2.4, compatible, 6.2.7, 6.7.2, 6.7.3, 6.7.5
20634 7.23.3.2, 7.23.3.3, 7.23.3.4 complex, 6.2.5, G
20635 components, 7.23.1 composite, 6.2.7
20636 conversion functions, 7.23.3 const qualified, 6.7.3
20637 wide character, 7.24.5 conversions, 6.3
20638 local, 7.23.1 imaginary, G
20639 manipulation functions, 7.23.2 restrict qualified, 6.7.3
20640 time function, 7.23.2.4 volatile qualified, 6.7.3
20641 time.h header, 7.23
20642 time_t type, 7.23.1 UCHAR_MAX macro, 5.2.4.2.1
20643 tm structure type, 7.23.1, 7.24.1 UINT_FASTN_MAX macros, 7.18.2.3
20644 TMP_MAX macro, 7.19.1, 7.19.4.3, 7.19.4.4 uint_fastN_t types, 7.18.1.3
20645 tmpfile function, 7.19.4.3, 7.20.4.3 UINT_LEASTN_MAX macros, 7.18.2.2
20646 tmpnam function, 7.19.1, 7.19.4.3, 7.19.4.4 uint_leastN_t types, 7.18.1.2
20647 token, 5.1.1.2, 6.4, see also preprocessing tokens UINT_MAX macro, 5.2.4.2.1
20648 token concatenation, 6.10.3.3 UINTMAX_C macro, 7.18.4.2
20649 token pasting, 6.10.3.3 UINTMAX_MAX macro, 7.8.2.3, 7.8.2.4, 7.18.2.5
20653 uintmax_t type, 7.18.1.5, 7.19.6.1, 7.19.6.2, USHRT_MAX macro, 5.2.4.2.1
20654 7.24.2.1, 7.24.2.2 usual arithmetic conversions, 6.3.1.8, 6.5.5, 6.5.6,
20655 UINTN_C macros, 7.18.4.1 6.5.8, 6.5.9, 6.5.10, 6.5.11, 6.5.12, 6.5.15
20656 UINTN_MAX macros, 7.18.2.1 utilities, general, 7.20
20657 uintN_t types, 7.18.1.1 wide string, 7.24.4
20658 UINTPTR_MAX macro, 7.18.2.4
20659 uintptr_t type, 7.18.1.4 va_arg macro, 7.15, 7.15.1, 7.15.1.1, 7.15.1.2,
20660 ULLONG_MAX macro, 5.2.4.2.1, 7.20.1.4, 7.15.1.4, 7.19.6.8, 7.19.6.9, 7.19.6.10,
20661 7.24.4.1.2 7.19.6.11, 7.19.6.12, 7.19.6.13, 7.19.6.14,
20662 ULONG_MAX macro, 5.2.4.2.1, 7.20.1.4, 7.24.2.5, 7.24.2.6, 7.24.2.7, 7.24.2.8,
20663 7.24.4.1.2 7.24.2.9, 7.24.2.10
20664 unary arithmetic operators, 6.5.3.3 va_copy macro, 7.15, 7.15.1, 7.15.1.1, 7.15.1.2,
20665 unary expression, 6.5.3 7.15.1.3
20666 unary minus operator (-), 6.5.3.3, F.3 va_end macro, 7.1.3, 7.15, 7.15.1, 7.15.1.3,
20667 unary operators, 6.5.3 7.15.1.4, 7.19.6.8, 7.19.6.9, 7.19.6.10,
20668 unary plus operator (+), 6.5.3.3 7.19.6.11, 7.19.6.12, 7.19.6.13, 7.19.6.14,
20669 unbuffered stream, 7.19.3 7.24.2.5, 7.24.2.6, 7.24.2.7, 7.24.2.8,
20670 undef preprocessing directive, 6.10.3.5, 7.1.3, 7.24.2.9, 7.24.2.10
20671 7.1.4 va_list type, 7.15, 7.15.1.3
20672 undefined behavior, 3.4.3, 4, J.2 va_start macro, 7.15, 7.15.1, 7.15.1.1,
20673 underscore character, 6.4.2.1 7.15.1.2, 7.15.1.3, 7.15.1.4, 7.19.6.8,
20674 underscore, leading, in identifier, 7.1.3 7.19.6.9, 7.19.6.10, 7.19.6.11, 7.19.6.12,
20675 ungetc function, 7.19.1, 7.19.7.11, 7.19.9.2, 7.19.6.13, 7.19.6.14, 7.24.2.5, 7.24.2.6,
20676 7.19.9.3 7.24.2.7, 7.24.2.8, 7.24.2.9, 7.24.2.10
20677 ungetwc function, 7.19.1, 7.24.3.10 value, 3.17
20678 Unicode required set, 6.10.8 value bits, 6.2.6.2
20679 union variable arguments, 6.10.3, 7.15
20680 arrow operator (->), 6.5.2.3 variable arguments header, 7.15
20681 content, 6.7.2.3 variable length array, 6.7.5, 6.7.5.2
20682 dot operator (.), 6.5.2.3 variably modified type, 6.7.5, 6.7.5.2
20683 initialization, 6.7.8 vertical-tab character, 5.2.1, 6.4
20684 member alignment, 6.7.2.1 vertical-tab escape sequence (\v), 5.2.2, 6.4.4.4,
20685 member name space, 6.2.3 7.4.1.10
20686 member operator (.), 6.3.2.1, 6.5.2.3 vfprintf function, 7.19.1, 7.19.6.8
20687 pointer operator (->), 6.5.2.3 vfscanf function, 7.19.1, 7.19.6.8, 7.19.6.9
20688 specifier, 6.7.2.1 vfwprintf function, 7.19.1, 7.24.2.5
20689 tag, 6.2.3, 6.7.2.3 vfwscanf function, 7.19.1, 7.24.2.6, 7.24.3.10
20690 type, 6.2.5, 6.7.2.1 visibility of identifier, 6.2.1
20691 universal character name, 6.4.3 VLA, see variable length array
20692 unqualified type, 6.2.5 void expression, 6.3.2.2
20693 unqualified version of type, 6.2.5 void function parameter, 6.7.5.3
20694 unsigned integer suffix, u or U, 6.4.4.1 void type, 6.2.5, 6.3.2.2, 6.7.2
20695 unsigned integer types, 6.2.5, 6.3.1.3, 6.4.4.1 void type conversion, 6.3.2.2
20696 unsigned type conversion, 6.3.1.1, 6.3.1.3, volatile storage, 5.1.2.3
20697 6.3.1.4, 6.3.1.8 volatile type qualifier, 6.7.3
20698 unsigned types, 6.2.5, 6.7.2, 7.19.6.1, 7.19.6.2, volatile-qualified type, 6.2.5, 6.7.3
20699 7.24.2.1, 7.24.2.2 vprintf function, 7.19.1, 7.19.6.8, 7.19.6.10
20700 unspecified behavior, 3.4.4, 4, J.1 vscanf function, 7.19.1, 7.19.6.8, 7.19.6.11
20701 unspecified value, 3.17.3 vsnprintf function, 7.19.6.8, 7.19.6.12
20702 uppercase letter, 5.2.1 vsprintf function, 7.19.6.8, 7.19.6.13
20703 use of library functions, 7.1.4 vsscanf function, 7.19.6.8, 7.19.6.14
20707 vswprintf function, 7.24.2.7 wctype.h header, 7.25, 7.26.13
20708 vswscanf function, 7.24.2.8 wctype_t type, 7.25.1, 7.25.2.2.2
20709 vwprintf function, 7.19.1, 7.24.2.9 WEOF macro, 7.24.1, 7.24.3.1, 7.24.3.3, 7.24.3.6,
20710 vwscanf function, 7.19.1, 7.24.2.10, 7.24.3.10 7.24.3.7, 7.24.3.8, 7.24.3.9, 7.24.3.10,
20712 warnings, I while statement, 6.8.5.1
20713 wchar.h header, 5.2.4.2.2, 7.19.1, 7.24, 7.26.12, white space, 5.1.1.2, 6.4, 6.10, 7.4.1.10,
20715 WCHAR_MAX macro, 7.18.3, 7.24.1 white-space characters, 6.4
20716 WCHAR_MIN macro, 7.18.3, 7.24.1 wide character, 3.7.3
20717 wchar_t type, 3.7.3, 6.4.4.4, 6.4.5, 6.7.8, case mapping functions, 7.25.3.1
20718 6.10.8, 7.17, 7.18.3, 7.19.6.1, 7.19.6.2, 7.20, extensible, 7.25.3.2
20719 7.24.1, 7.24.2.1, 7.24.2.2 classification functions, 7.25.2.1
20720 wcrtomb function, 7.19.3, 7.19.6.2, 7.24.2.2, extensible, 7.25.2.2
20721 7.24.6.3.3, 7.24.6.4.2 constant, 6.4.4.4
20722 wcscat function, 7.24.4.3.1 formatted input/output functions, 7.24.2
20723 wcschr function, 7.24.4.5.1 input functions, 7.19.1
20724 wcscmp function, 7.24.4.4.1, 7.24.4.4.4 input/output functions, 7.19.1, 7.24.3
20725 wcscoll function, 7.24.4.4.2, 7.24.4.4.4 output functions, 7.19.1
20726 wcscpy function, 7.24.4.2.1 single-byte conversion functions, 7.24.6.1
20727 wcscspn function, 7.24.4.5.2 wide string, 7.1.1
20728 wcsftime function, 7.11.1.1, 7.24.5.1 wide string comparison functions, 7.24.4.4
20729 wcslen function, 7.24.4.6.1 wide string concatenation functions, 7.24.4.3
20730 wcsncat function, 7.24.4.3.2 wide string copying functions, 7.24.4.2
20731 wcsncmp function, 7.24.4.4.3 wide string literal, see string literal
20732 wcsncpy function, 7.24.4.2.2 wide string miscellaneous functions, 7.24.4.6
20733 wcspbrk function, 7.24.4.5.3 wide string numeric conversion functions, 7.8.2.4,
20734 wcsrchr function, 7.24.4.5.4 7.24.4.1
20735 wcsrtombs function, 7.24.6.4.2 wide string search functions, 7.24.4.5
20736 wcsspn function, 7.24.4.5.5 wide-oriented stream, 7.19.2
20737 wcsstr function, 7.24.4.5.6 width, 6.2.6.2
20738 wcstod function, 7.19.6.2, 7.24.2.2 WINT_MAX macro, 7.18.3
20739 wcstod function, 7.24.4.1.1 WINT_MIN macro, 7.18.3
20740 wcstof function, 7.24.4.1.1 wint_t type, 7.18.3, 7.19.6.1, 7.24.1, 7.24.2.1,
20741 wcstoimax function, 7.8.2.4 7.25.1
20742 wcstok function, 7.24.4.5.7 wmemchr function, 7.24.4.5.8
20743 wcstol function, 7.8.2.4, 7.19.6.2, 7.24.2.2, wmemcmp function, 7.24.4.4.5
20744 7.24.4.1.2 wmemcpy function, 7.24.4.2.3
20745 wcstold function, 7.24.4.1.1 wmemmove function, 7.24.4.2.4
20746 wcstoll function, 7.8.2.4, 7.24.4.1.2 wmemset function, 7.24.4.6.2
20747 wcstombs function, 7.20.8.2, 7.24.6.4 wprintf function, 7.19.1, 7.24.2.9, 7.24.2.11
20748 wcstoul function, 7.8.2.4, 7.19.6.2, 7.24.2.2, wscanf function, 7.19.1, 7.24.2.10, 7.24.2.12,
20749 7.24.4.1.2 7.24.3.10
20750 wcstoull function, 7.8.2.4, 7.24.4.1.2
20751 wcstoumax function, 7.8.2.4 xor macro, 7.9
20752 wcsxfrm function, 7.24.4.4.4 xor_eq macro, 7.9
20753 wctob function, 7.24.6.1.2, 7.25.2.1
20754 wctomb function, 7.20.7.3, 7.20.8.2, 7.24.6.3
20755 wctrans function, 7.25.3.2.1, 7.25.3.2.2
20756 wctrans_t type, 7.25.1, 7.25.3.2.2
20757 wctype function, 7.25.2.2.1, 7.25.2.2.2