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
48 6.5.1 Primary expressions . . . . . . . . . . . . . . . . . 69
49 6.5.2 Postfix operators . . . . . . . . . . . . . . . . . . . 69
50 6.5.3 Unary operators . . . . . . . . . . . . . . . . . . . 78
51 6.5.4 Cast operators . . . . . . . . . . . . . . . . . . . . 81
52 6.5.5 Multiplicative operators . . . . . . . . . . . . . . . . 82
53 6.5.6 Additive operators . . . . . . . . . . . . . . . . . . 82
54 6.5.7 Bitwise shift operators . . . . . . . . . . . . . . . . . 84
55 6.5.8 Relational operators . . . . . . . . . . . . . . . . . . 85
56 6.5.9 Equality operators . . . . . . . . . . . . . . . . . . 86
57 6.5.10 Bitwise AND operator . . . . . . . . . . . . . . . . . 87
58 6.5.11 Bitwise exclusive OR operator . . . . . . . . . . . . . 88
59 6.5.12 Bitwise inclusive OR operator . . . . . . . . . . . . . . 88
60 6.5.13 Logical AND operator . . . . . . . . . . . . . . . . . 89
61 6.5.14 Logical OR operator . . . . . . . . . . . . . . . . . 89
62 6.5.15 Conditional operator . . . . . . . . . . . . . . . . . 90
63 6.5.16 Assignment operators . . . . . . . . . . . . . . . . . 91
64 6.5.17 Comma operator . . . . . . . . . . . . . . . . . . . 94
65 6.6 Constant expressions . . . . . . . . . . . . . . . . . . . . . 95
66 6.7 Declarations . . . . . . . . . . . . . . . . . . . . . . . . 97
67 6.7.1 Storage-class specifiers . . . . . . . . . . . . . . . . 98
68 6.7.2 Type specifiers . . . . . . . . . . . . . . . . . . . . 99
69 6.7.3 Type qualifiers . . . . . . . . . . . . . . . . . . . . 108
70 6.7.4 Function specifiers . . . . . . . . . . . . . . . . . . 112
71 6.7.5 Declarators . . . . . . . . . . . . . . . . . . . . . 114
72 6.7.6 Type names . . . . . . . . . . . . . . . . . . . . . 122
73 6.7.7 Type definitions . . . . . . . . . . . . . . . . . . . 123
74 6.7.8 Initialization . . . . . . . . . . . . . . . . . . . . 125
75 6.8 Statements and blocks . . . . . . . . . . . . . . . . . . . . 131
76 6.8.1 Labeled statements . . . . . . . . . . . . . . . . . . 131
77 6.8.2 Compound statement . . . . . . . . . . . . . . . . . 132
78 6.8.3 Expression and null statements . . . . . . . . . . . . . 132
79 6.8.4 Selection statements . . . . . . . . . . . . . . . . . 133
80 6.8.5 Iteration statements . . . . . . . . . . . . . . . . . . 135
81 6.8.6 Jump statements . . . . . . . . . . . . . . . . . . . 136
82 6.9 External definitions . . . . . . . . . . . . . . . . . . . . . 140
83 6.9.1 Function definitions . . . . . . . . . . . . . . . . . . 141
84 6.9.2 External object definitions . . . . . . . . . . . . . . . 143
85 6.10 Preprocessing directives . . . . . . . . . . . . . . . . . . . 145
86 6.10.1 Conditional inclusion . . . . . . . . . . . . . . . . . 147
87 6.10.2 Source file inclusion . . . . . . . . . . . . . . . . . 149
88 6.10.3 Macro replacement . . . . . . . . . . . . . . . . . . 151
89 6.10.4 Line control . . . . . . . . . . . . . . . . . . . . . 158
90 6.10.5 Error directive . . . . . . . . . . . . . . . . . . . . 159
91 6.10.6 Pragma directive . . . . . . . . . . . . . . . . . . . 159
95 6.10.7 Null directive . . . . . . . . . . . . . . . . . . . . 160
96 6.10.8 Predefined macro names . . . . . . . . . . . . . . . . 160
97 6.10.9 Pragma operator . . . . . . . . . . . . . . . . . . . 161
98 6.11 Future language directions . . . . . . . . . . . . . . . . . . 163
99 6.11.1 Floating types . . . . . . . . . . . . . . . . . . . . 163
100 6.11.2 Linkages of identifiers . . . . . . . . . . . . . . . . . 163
101 6.11.3 External names . . . . . . . . . . . . . . . . . . . 163
102 6.11.4 Character escape sequences . . . . . . . . . . . . . . 163
103 6.11.5 Storage-class specifiers . . . . . . . . . . . . . . . . 163
104 6.11.6 Function declarators . . . . . . . . . . . . . . . . . 163
105 6.11.7 Function definitions . . . . . . . . . . . . . . . . . . 163
106 6.11.8 Pragma directives . . . . . . . . . . . . . . . . . . 163
107 6.11.9 Predefined macro names . . . . . . . . . . . . . . . . 163
108 7. Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
109 7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 164
110 7.1.1 Definitions of terms . . . . . . . . . . . . . . . . . . 164
111 7.1.2 Standard headers . . . . . . . . . . . . . . . . . . . 165
112 7.1.3 Reserved identifiers . . . . . . . . . . . . . . . . . . 166
113 7.1.4 Use of library functions . . . . . . . . . . . . . . . . 166
114 7.2 Diagnostics <assert.h> . . . . . . . . . . . . . . . . . . 169
115 7.2.1 Program diagnostics . . . . . . . . . . . . . . . . . 169
116 7.3 Complex arithmetic <complex.h> . . . . . . . . . . . . . . 170
117 7.3.1 Introduction . . . . . . . . . . . . . . . . . . . . . 170
118 7.3.2 Conventions . . . . . . . . . . . . . . . . . . . . . 171
119 7.3.3 Branch cuts . . . . . . . . . . . . . . . . . . . . . 171
120 7.3.4 The CX_LIMITED_RANGE pragma . . . . . . . . . . . 171
121 7.3.5 Trigonometric functions . . . . . . . . . . . . . . . . 172
122 7.3.6 Hyperbolic functions . . . . . . . . . . . . . . . . . 174
123 7.3.7 Exponential and logarithmic functions . . . . . . . . . . 176
124 7.3.8 Power and absolute-value functions . . . . . . . . . . . 177
125 7.3.9 Manipulation functions . . . . . . . . . . . . . . . . 178
126 7.4 Character handling <ctype.h> . . . . . . . . . . . . . . . . 181
127 7.4.1 Character classification functions . . . . . . . . . . . . 181
128 7.4.2 Character case mapping functions . . . . . . . . . . . . 184
129 7.5 Errors <errno.h> . . . . . . . . . . . . . . . . . . . . . 186
130 7.6 Floating-point environment <fenv.h> . . . . . . . . . . . . . 187
131 7.6.1 The FENV_ACCESS pragma . . . . . . . . . . . . . . 189
132 7.6.2 Floating-point exceptions . . . . . . . . . . . . . . . 190
133 7.6.3 Rounding . . . . . . . . . . . . . . . . . . . . . . 193
134 7.6.4 Environment . . . . . . . . . . . . . . . . . . . . 194
135 7.7 Characteristics of floating types <float.h> . . . . . . . . . . . 197
136 7.8 Format conversion of integer types <inttypes.h> . . . . . . . . 198
137 7.8.1 Macros for format specifiers . . . . . . . . . . . . . . 198
138 7.8.2 Functions for greatest-width integer types . . . . . . . . . 199
142 7.9 Alternative spellings <iso646.h> . . . . . . . . . . . . . . . 202
143 7.10 Sizes of integer types <limits.h> . . . . . . . . . . . . . . 203
144 7.11 Localization <locale.h> . . . . . . . . . . . . . . . . . . 204
145 7.11.1 Locale control . . . . . . . . . . . . . . . . . . . . 205
146 7.11.2 Numeric formatting convention inquiry . . . . . . . . . . 206
147 7.12 Mathematics <math.h> . . . . . . . . . . . . . . . . . . . 212
148 7.12.1 Treatment of error conditions . . . . . . . . . . . . . . 214
149 7.12.2 The FP_CONTRACT pragma . . . . . . . . . . . . . . 215
150 7.12.3 Classification macros . . . . . . . . . . . . . . . . . 216
151 7.12.4 Trigonometric functions . . . . . . . . . . . . . . . . 218
152 7.12.5 Hyperbolic functions . . . . . . . . . . . . . . . . . 221
153 7.12.6 Exponential and logarithmic functions . . . . . . . . . . 223
154 7.12.7 Power and absolute-value functions . . . . . . . . . . . 228
155 7.12.8 Error and gamma functions . . . . . . . . . . . . . . . 230
156 7.12.9 Nearest integer functions . . . . . . . . . . . . . . . . 231
157 7.12.10 Remainder functions . . . . . . . . . . . . . . . . . 235
158 7.12.11 Manipulation functions . . . . . . . . . . . . . . . . 236
159 7.12.12 Maximum, minimum, and positive difference functions . . . 238
160 7.12.13 Floating multiply-add . . . . . . . . . . . . . . . . . 239
161 7.12.14 Comparison macros . . . . . . . . . . . . . . . . . . 240
162 7.13 Nonlocal jumps <setjmp.h> . . . . . . . . . . . . . . . . 243
163 7.13.1 Save calling environment . . . . . . . . . . . . . . . 243
164 7.13.2 Restore calling environment . . . . . . . . . . . . . . 244
165 7.14 Signal handling <signal.h> . . . . . . . . . . . . . . . . . 246
166 7.14.1 Specify signal handling . . . . . . . . . . . . . . . . 247
167 7.14.2 Send signal . . . . . . . . . . . . . . . . . . . . . 248
168 7.15 Variable arguments <stdarg.h> . . . . . . . . . . . . . . . 249
169 7.15.1 Variable argument list access macros . . . . . . . . . . . 249
170 7.16 Boolean type and values <stdbool.h> . . . . . . . . . . . . 253
171 7.17 Common definitions <stddef.h> . . . . . . . . . . . . . . . 254
172 7.18 Integer types <stdint.h> . . . . . . . . . . . . . . . . . . 255
173 7.18.1 Integer types . . . . . . . . . . . . . . . . . . . . 255
174 7.18.2 Limits of specified-width integer types . . . . . . . . . . 257
175 7.18.3 Limits of other integer types . . . . . . . . . . . . . . 259
176 7.18.4 Macros for integer constants . . . . . . . . . . . . . . 260
177 7.19 Input/output <stdio.h> . . . . . . . . . . . . . . . . . . 262
178 7.19.1 Introduction . . . . . . . . . . . . . . . . . . . . . 262
179 7.19.2 Streams . . . . . . . . . . . . . . . . . . . . . . 264
180 7.19.3 Files . . . . . . . . . . . . . . . . . . . . . . . . 266
181 7.19.4 Operations on files . . . . . . . . . . . . . . . . . . 268
182 7.19.5 File access functions . . . . . . . . . . . . . . . . . 270
183 7.19.6 Formatted input/output functions . . . . . . . . . . . . 274
184 7.19.7 Character input/output functions . . . . . . . . . . . . . 296
185 7.19.8 Direct input/output functions . . . . . . . . . . . . . . 301
189 7.19.9 File positioning functions . . . . . . . . . . . . . . . 302
190 7.19.10 Error-handling functions . . . . . . . . . . . . . . . . 304
191 7.20 General utilities <stdlib.h> . . . . . . . . . . . . . . . . 306
192 7.20.1 Numeric conversion functions . . . . . . . . . . . . . . 307
193 7.20.2 Pseudo-random sequence generation functions . . . . . . . 312
194 7.20.3 Memory management functions . . . . . . . . . . . . . 313
195 7.20.4 Communication with the environment . . . . . . . . . . 315
196 7.20.5 Searching and sorting utilities . . . . . . . . . . . . . . 318
197 7.20.6 Integer arithmetic functions . . . . . . . . . . . . . . 320
198 7.20.7 Multibyte/wide character conversion functions . . . . . . . 321
199 7.20.8 Multibyte/wide string conversion functions . . . . . . . . 323
200 7.21 String handling <string.h> . . . . . . . . . . . . . . . . . 325
201 7.21.1 String function conventions . . . . . . . . . . . . . . . 325
202 7.21.2 Copying functions . . . . . . . . . . . . . . . . . . 325
203 7.21.3 Concatenation functions . . . . . . . . . . . . . . . . 327
204 7.21.4 Comparison functions . . . . . . . . . . . . . . . . . 328
205 7.21.5 Search functions . . . . . . . . . . . . . . . . . . . 330
206 7.21.6 Miscellaneous functions . . . . . . . . . . . . . . . . 333
207 7.22 Type-generic math <tgmath.h> . . . . . . . . . . . . . . . 335
208 7.23 Date and time <time.h> . . . . . . . . . . . . . . . . . . 338
209 7.23.1 Components of time . . . . . . . . . . . . . . . . . 338
210 7.23.2 Time manipulation functions . . . . . . . . . . . . . . 339
211 7.23.3 Time conversion functions . . . . . . . . . . . . . . . 341
212 7.24 Extended multibyte and wide character utilities <wchar.h> . . . . . 348
213 7.24.1 Introduction . . . . . . . . . . . . . . . . . . . . . 348
214 7.24.2 Formatted wide character input/output functions . . . . . . 349
215 7.24.3 Wide character input/output functions . . . . . . . . . . 367
216 7.24.4 General wide string utilities . . . . . . . . . . . . . . 371
217 7.24.5 Wide character time conversion functions . . . . . . . . . 385
218 7.24.6 Extended multibyte/wide character conversion utilities . . . . 386
219 7.25 Wide character classification and mapping utilities <wctype.h> . . . 393
220 7.25.1 Introduction . . . . . . . . . . . . . . . . . . . . . 393
221 7.25.2 Wide character classification utilities . . . . . . . . . . . 394
222 7.25.3 Wide character case mapping utilities . . . . . . . . . . . 399
223 7.26 Future library directions . . . . . . . . . . . . . . . . . . . 401
224 7.26.1 Complex arithmetic <complex.h> . . . . . . . . . . . 401
225 7.26.2 Character handling <ctype.h> . . . . . . . . . . . . 401
226 7.26.3 Errors <errno.h> . . . . . . . . . . . . . . . . . 401
227 7.26.4 Format conversion of integer types <inttypes.h> . . . . 401
228 7.26.5 Localization <locale.h> . . . . . . . . . . . . . . 401
229 7.26.6 Signal handling <signal.h> . . . . . . . . . . . . . 401
230 7.26.7 Boolean type and values <stdbool.h> . . . . . . . . . 401
231 7.26.8 Integer types <stdint.h> . . . . . . . . . . . . . . 401
232 7.26.9 Input/output <stdio.h> . . . . . . . . . . . . . . . 402
236 7.26.10 General utilities <stdlib.h> . . . . . . . . . . . . . 402
237 7.26.11 String handling <string.h> . . . . . . . . . . . . . 402
238 7.26.12 Extended multibyte and wide character utilities
239 <wchar.h> . . . . . . . . . . . . . . . . . . . . 402
240 7.26.13 Wide character classification and mapping utilities
241 <wctype.h> . . . . . . . . . . . . . . . . . . . . 402
242 Annex A (informative) Language syntax summary . . . . . . . . . . . . 403
243 A.1 Lexical grammar . . . . . . . . . . . . . . . . . . . . . . 403
244 A.2 Phrase structure grammar . . . . . . . . . . . . . . . . . . . 409
245 A.3 Preprocessing directives . . . . . . . . . . . . . . . . . . . 416
246 Annex B (informative) Library summary . . . . . . . . . . . . . . . . 419
247 B.1 Diagnostics <assert.h> . . . . . . . . . . . . . . . . . . 419
248 B.2 Complex <complex.h> . . . . . . . . . . . . . . . . . . . 419
249 B.3 Character handling <ctype.h> . . . . . . . . . . . . . . . . 421
250 B.4 Errors <errno.h> . . . . . . . . . . . . . . . . . . . . . 421
251 B.5 Floating-point environment <fenv.h> . . . . . . . . . . . . . 421
252 B.6 Characteristics of floating types <float.h> . . . . . . . . . . . 422
253 B.7 Format conversion of integer types <inttypes.h> . . . . . . . . 422
254 B.8 Alternative spellings <iso646.h> . . . . . . . . . . . . . . . 423
255 B.9 Sizes of integer types <limits.h> . . . . . . . . . . . . . . 423
256 B.10 Localization <locale.h> . . . . . . . . . . . . . . . . . . 423
257 B.11 Mathematics <math.h> . . . . . . . . . . . . . . . . . . . 423
258 B.12 Nonlocal jumps <setjmp.h> . . . . . . . . . . . . . . . . 428
259 B.13 Signal handling <signal.h> . . . . . . . . . . . . . . . . . 428
260 B.14 Variable arguments <stdarg.h> . . . . . . . . . . . . . . . 428
261 B.15 Boolean type and values <stdbool.h> . . . . . . . . . . . . 428
262 B.16 Common definitions <stddef.h> . . . . . . . . . . . . . . . 429
263 B.17 Integer types <stdint.h> . . . . . . . . . . . . . . . . . . 429
264 B.18 Input/output <stdio.h> . . . . . . . . . . . . . . . . . . 429
265 B.19 General utilities <stdlib.h> . . . . . . . . . . . . . . . . 431
266 B.20 String handling <string.h> . . . . . . . . . . . . . . . . . 433
267 B.21 Type-generic math <tgmath.h> . . . . . . . . . . . . . . . 434
268 B.22 Date and time <time.h> . . . . . . . . . . . . . . . . . . 434
269 B.23 Extended multibyte/wide character utilities <wchar.h> . . . . . . 435
270 B.24 Wide character classification and mapping utilities <wctype.h> . . . 437
271 Annex C (informative) Sequence points . . . . . . . . . . . . . . . . . 439
272 Annex D (normative) Universal character names for identifiers . . . . . . . 440
273 Annex E (informative) Implementation limits . . . . . . . . . . . . . . 442
274 Annex F (normative) IEC 60559 floating-point arithmetic . . . . . . . . . . 444
275 F.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 444
276 F.2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
277 F.3 Operators and functions . . . . . . . . . . . . . . . . . . . 445
281 F.4 Floating to integer conversion . . . . . . . . . . . . . . . . . 447
282 F.5 Binary-decimal conversion . . . . . . . . . . . . . . . . . . 447
283 F.6 Contracted expressions . . . . . . . . . . . . . . . . . . . . 448
284 F.7 Floating-point environment . . . . . . . . . . . . . . . . . . 448
285 F.8 Optimization . . . . . . . . . . . . . . . . . . . . . . . . 451
286 F.9 Mathematics <math.h> . . . . . . . . . . . . . . . . . . . 454
287 Annex G (informative) IEC 60559-compatible complex arithmetic . . . . . . 467
288 G.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 467
289 G.2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
290 G.3 Conventions . . . . . . . . . . . . . . . . . . . . . . . . 467
291 G.4 Conversions . . . . . . . . . . . . . . . . . . . . . . . . 468
292 G.5 Binary operators . . . . . . . . . . . . . . . . . . . . . . 468
293 G.6 Complex arithmetic <complex.h> . . . . . . . . . . . . . . 472
294 G.7 Type-generic math <tgmath.h> . . . . . . . . . . . . . . . 480
295 Annex H (informative) Language independent arithmetic . . . . . . . . . . 481
296 H.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . 481
297 H.2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
298 H.3 Notification . . . . . . . . . . . . . . . . . . . . . . . . 485
299 Annex I (informative) Common warnings . . . . . . . . . . . . . . . . 487
300 Annex J (informative) Portability issues . . . . . . . . . . . . . . . . . 489
301 J.1 Unspecified behavior . . . . . . . . . . . . . . . . . . . . . 489
302 J.2 Undefined behavior . . . . . . . . . . . . . . . . . . . . . 492
303 J.3 Implementation-defined behavior . . . . . . . . . . . . . . . . 505
304 J.4 Locale-specific behavior . . . . . . . . . . . . . . . . . . . 512
305 J.5 Common extensions . . . . . . . . . . . . . . . . . . . . . 513
306 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
307 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
319 1 ISO (the International Organization for Standardization) and IEC (the International
320 Electrotechnical Commission) form the specialized system for worldwide
321 standardization. National bodies that are member of ISO or IEC participate in the
322 development of International Standards through technical committees established by the
323 respective organization to deal with particular fields of technical activity. ISO and IEC
324 technical committees collaborate in fields of mutual interest. Other international
325 organizations, governmental and non-governmental, in liaison with ISO and IEC, also
326 take part in the work.
327 2 International Standards are drafted in accordance with the rules given in the ISO/IEC
329 3 In the field of information technology, ISO and IEC have established a joint technical
330 committee, ISO/IEC JTC 1. Draft International Standards adopted by the joint technical
331 committee are circulated to national bodies for voting. Publication as an International
332 Standard requires approval by at least 75% of the national bodies casting a vote.
333 4 International Standard ISO/IEC 9899 was prepared by Joint Technical Committee
334 ISO/IEC JTC 1, Information technology, Subcommittee SC 22, Programming languages,
335 their environments and system software interfaces. The Working Group responsible for
336 this standard (WG 14) maintains a site on the World Wide Web at
337 http://www.open-std.org/JTC1/SC22/WG14/ containing additional
338 information relevant to this standard such as a Rationale for many of the decisions made
339 during its preparation and a log of Defect Reports and Responses.
340 5 This second edition cancels and replaces the first edition, ISO/IEC 9899:1990, as
341 amended and corrected by ISO/IEC 9899/COR1:1994, ISO/IEC 9899/AMD1:1995, and
342 ISO/IEC 9899/COR2:1996. Major changes from the previous edition include:
343 -- restricted character set support via digraphs and <iso646.h> (originally specified
345 -- wide character library support in <wchar.h> and <wctype.h> (originally
347 -- more precise aliasing rules via effective type
348 -- restricted pointers
349 -- variable length arrays
350 -- flexible array members
351 -- static and type qualifiers in parameter array declarators
352 -- complex (and imaginary) support in <complex.h>
353 -- type-generic math macros in <tgmath.h>
354 -- the long long int type and library functions
359 -- increased minimum translation limits
360 -- additional floating-point characteristics in <float.h>
361 -- remove implicit int
362 -- reliable integer division
363 -- universal character names (\u and \U)
364 -- extended identifiers
365 -- hexadecimal floating-point constants and %a and %A printf/scanf conversion
368 -- designated initializers
370 -- extended integer types and library functions in <inttypes.h> and <stdint.h>
371 -- remove implicit function declaration
372 -- preprocessor arithmetic done in intmax_t/uintmax_t
373 -- mixed declarations and code
374 -- new block scopes for selection and iteration statements
375 -- integer constant type rules
376 -- integer promotion rules
377 -- macros with a variable number of arguments
378 -- the vscanf family of functions in <stdio.h> and <wchar.h>
379 -- additional math library functions in <math.h>
380 -- treatment of error conditions by math library functions (math_errhandling)
381 -- floating-point environment access in <fenv.h>
382 -- IEC 60559 (also known as IEC 559 or IEEE arithmetic) support
383 -- trailing comma allowed in enum declaration
384 -- %lf conversion specifier allowed in printf
386 -- the snprintf family of functions in <stdio.h>
387 -- boolean type in <stdbool.h>
388 -- idempotent type qualifiers
389 -- empty macro arguments
394 -- new structure type compatibility rules (tag compatibility)
395 -- additional predefined macro names
396 -- _Pragma preprocessing operator
398 -- __func__ predefined identifier
400 -- additional strftime conversion specifiers
401 -- LIA compatibility annex
402 -- deprecate ungetc at the beginning of a binary file
403 -- remove deprecation of aliased array parameters
404 -- conversion of array to pointer not limited to lvalues
405 -- relaxed constraints on aggregate and union initialization
406 -- relaxed restrictions on portable header names
407 -- return without expression not permitted in function that returns a value (and vice
409 6 Annexes D and F form a normative part of this standard; annexes A, B, C, E, G, H, I, J,
410 the bibliography, and the index are for information only. In accordance with Part 3 of the
411 ISO/IEC Directives, this foreword, the introduction, notes, footnotes, and examples are
412 also for information only.
420 1 With the introduction of new devices and extended character sets, new features may be
421 added to this International Standard. Subclauses in the language and library clauses warn
422 implementors and programmers of usages which, though valid in themselves, may
423 conflict with future additions.
424 2 Certain features are obsolescent, which means that they may be considered for
425 withdrawal in future revisions of this International Standard. They are retained because
426 of their widespread use, but their use in new implementations (for implementation
427 features) or new programs (for language [6.11] or library features [7.26]) is discouraged.
428 3 This International Standard is divided into four major subdivisions:
429 -- preliminary elements (clauses 1-4);
430 -- the characteristics of environments that translate and execute C programs (clause 5);
431 -- the language syntax, constraints, and semantics (clause 6);
432 -- the library facilities (clause 7).
433 4 Examples are provided to illustrate possible forms of the constructions described.
434 Footnotes are provided to emphasize consequences of the rules described in that
435 subclause or elsewhere in this International Standard. References are used to refer to
436 other related subclauses. Recommendations are provided to give advice or guidance to
437 implementors. Annexes provide additional information and summarize the information
438 contained in this International Standard. A bibliography lists documents that were
439 referred to during the preparation of the standard.
440 5 The language clause (clause 6) is derived from ''The C Reference Manual''.
441 6 The library clause (clause 7) is based on the 1984 /usr/group Standard.
450 Programming languages -- C
456 1 This International Standard specifies the form and establishes the interpretation of
457 programs written in the C programming language.1) It specifies
458 -- the representation of C programs;
459 -- the syntax and constraints of the C language;
460 -- the semantic rules for interpreting C programs;
461 -- the representation of input data to be processed by C programs;
462 -- the representation of output data produced by C programs;
463 -- the restrictions and limits imposed by a conforming implementation of C.
464 2 This International Standard does not specify
465 -- the mechanism by which C programs are transformed for use by a data-processing
467 -- the mechanism by which C programs are invoked for use by a data-processing
469 -- the mechanism by which input data are transformed for use by a C program;
470 -- the mechanism by which output data are transformed after being produced by a C
472 -- the size or complexity of a program and its data that will exceed the capacity of any
473 specific data-processing system or the capacity of a particular processor;
476 1) This International Standard is designed to promote the portability of C programs among a variety of
477 data-processing systems. It is intended for use by implementors and programmers.
481 -- all minimal requirements of a data-processing system that is capable of supporting a
482 conforming implementation.
484 2. Normative references
485 1 The following normative documents contain provisions which, through reference in this
486 text, constitute provisions of this International Standard. For dated references,
487 subsequent amendments to, or revisions of, any of these publications do not apply.
488 However, parties to agreements based on this International Standard are encouraged to
489 investigate the possibility of applying the most recent editions of the normative
490 documents indicated below. For undated references, the latest edition of the normative
491 document referred to applies. Members of ISO and IEC maintain registers of currently
492 valid International Standards.
493 2 ISO 31-11:1992, Quantities and units -- Part 11: Mathematical signs and symbols for
494 use in the physical sciences and technology.
495 3 ISO/IEC 646, Information technology -- ISO 7-bit coded character set for information
497 4 ISO/IEC 2382-1:1993, Information technology -- Vocabulary -- Part 1: Fundamental
499 5 ISO 4217, Codes for the representation of currencies and funds.
500 6 ISO 8601, Data elements and interchange formats -- Information interchange --
501 Representation of dates and times.
502 7 ISO/IEC 10646 (all parts), Information technology -- Universal Multiple-Octet Coded
504 8 IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems (previously
505 designated IEC 559:1989).
513 3. Terms, definitions, and symbols
514 1 For the purposes of this International Standard, the following definitions apply. Other
515 terms are defined where they appear in italic type or on the left side of a syntax rule.
516 Terms explicitly defined in this International Standard are not to be presumed to refer
517 implicitly to similar terms defined elsewhere. Terms not defined in this International
518 Standard are to be interpreted according to ISO/IEC 2382-1. Mathematical symbols not
519 defined in this International Standard are to be interpreted according to ISO 31-11.
522 <execution-time action> to read or modify the value of an object
523 2 NOTE 1 Where only one of these two actions is meant, ''read'' or ''modify'' is used.
525 3 NOTE 2 "Modify'' includes the case where the new value being stored is the same as the previous value.
527 4 NOTE 3 Expressions that are not evaluated do not access objects.
531 requirement that objects of a particular type be located on storage boundaries with
532 addresses that are particular multiples of a byte address
536 actual parameter (deprecated)
537 expression in the comma-separated list bounded by the parentheses in a function call
538 expression, or a sequence of preprocessing tokens in the comma-separated list bounded
539 by the parentheses in a function-like macro invocation
542 external appearance or action
544 1 implementation-defined behavior
545 unspecified behavior where each implementation documents how the choice is made
546 2 EXAMPLE An example of implementation-defined behavior is the propagation of the high-order bit
547 when a signed integer is shifted right.
550 1 locale-specific behavior
551 behavior that depends on local conventions of nationality, culture, and language that each
552 implementation documents
557 2 EXAMPLE An example of locale-specific behavior is whether the islower function returns true for
558 characters other than the 26 lowercase Latin letters.
562 behavior, upon use of a nonportable or erroneous program construct or of erroneous data,
563 for which this International Standard imposes no requirements
564 2 NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable
565 results, to behaving during translation or program execution in a documented manner characteristic of the
566 environment (with or without the issuance of a diagnostic message), to terminating a translation or
567 execution (with the issuance of a diagnostic message).
569 3 EXAMPLE An example of undefined behavior is the behavior on integer overflow.
572 1 unspecified behavior
573 use of an unspecified value, or other behavior where this International Standard provides
574 two or more possibilities and imposes no further requirements on which is chosen in any
576 2 EXAMPLE An example of unspecified behavior is the order in which the arguments to a function are
581 unit of data storage in the execution environment large enough to hold an object that may
582 have one of two values
583 2 NOTE It need not be possible to express the address of each individual bit of an object.
587 addressable unit of data storage large enough to hold any member of the basic character
588 set of the execution environment
589 2 NOTE 1 It is possible to express the address of each individual byte of an object uniquely.
591 3 NOTE 2 A byte is composed of a contiguous sequence of bits, the number of which is implementation-
592 defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order
597 <abstract> member of a set of elements used for the organization, control, or
598 representation of data
601 single-byte character
602 <C> bit representation that fits in a byte
606 1 multibyte character
607 sequence of one or more bytes representing a member of the extended character set of
608 either the source or the execution environment
609 2 NOTE The extended character set is a superset of the basic character set.
613 bit representation that fits in an object of type wchar_t, capable of representing any
614 character in the current locale
617 restriction, either syntactic or semantic, by which the exposition of language elements is
620 1 correctly rounded result
621 representation in the result format that is nearest in value, subject to the current rounding
622 mode, to what the result would be given unlimited range and precision
625 message belonging to an implementation-defined subset of the implementation's message
629 reference to a later subclause of this International Standard that contains additional
630 information relevant to this subclause
633 particular set of software, running in a particular translation environment under particular
634 control options, that performs translation of programs for, and supports execution of
635 functions in, a particular execution environment
637 1 implementation limit
638 restriction imposed upon programs by the implementation
641 region of data storage in the execution environment, the contents of which can represent
646 2 NOTE When referenced, an object may be interpreted as having a particular type; see 6.3.2.1.
651 formal argument (deprecated)
652 object declared as part of a function declaration or definition that acquires a value on
653 entry to the function, or an identifier from the comma-separated list bounded by the
654 parentheses immediately following the macro name in a function-like macro definition
656 1 recommended practice
657 specification that is strongly recommended as being in keeping with the intent of the
658 standard, but that may be impractical for some implementations
661 precise meaning of the contents of an object when interpreted as having a specific type
663 1 implementation-defined value
664 unspecified value where each implementation documents how the choice is made
666 1 indeterminate value
667 either an unspecified value or a trap representation
670 valid value of the relevant type where this International Standard imposes no
671 requirements on which value is chosen in any instance
672 2 NOTE An unspecified value cannot be a trap representation.
676 ceiling of x: the least integer greater than or equal to x
677 2 EXAMPLE ???2.4??? is 3, ???-2.4??? is -2.
681 floor of x: the greatest integer less than or equal to x
682 2 EXAMPLE ???2.4??? is 2, ???-2.4??? is -3.
691 1 In this International Standard, ''shall'' is to be interpreted as a requirement on an
692 implementation or on a program; conversely, ''shall not'' is to be interpreted as a
694 2 If a ''shall'' or ''shall not'' requirement that appears outside of a constraint is violated, the
695 behavior is undefined. Undefined behavior is otherwise indicated in this International
696 Standard by the words ''undefined behavior'' or by the omission of any explicit definition
697 of behavior. There is no difference in emphasis among these three; they all describe
698 ''behavior that is undefined''.
699 3 A program that is correct in all other aspects, operating on correct data, containing
700 unspecified behavior shall be a correct program and act in accordance with 5.1.2.3.
701 4 The implementation shall not successfully translate a preprocessing translation unit
702 containing a #error preprocessing directive unless it is part of a group skipped by
703 conditional inclusion.
704 5 A strictly conforming program shall use only those features of the language and library
705 specified in this International Standard.2) It shall not produce output dependent on any
706 unspecified, undefined, or implementation-defined behavior, and shall not exceed any
707 minimum implementation limit.
708 6 The two forms of conforming implementation are hosted and freestanding. A conforming
709 hosted implementation shall accept any strictly conforming program. A conforming
710 freestanding implementation shall accept any strictly conforming program that does not
711 use complex types and in which the use of the features specified in the library clause
712 (clause 7) is confined to the contents of the standard headers <float.h>,
713 <iso646.h>, <limits.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, and
714 <stdint.h>. A conforming implementation may have extensions (including additional
715 library functions), provided they do not alter the behavior of any strictly conforming
720 2) A strictly conforming program can use conditional features (such as those in annex F) provided the
721 use is guarded by a #ifdef directive with the appropriate macro. For example:
722 #ifdef __STDC_IEC_559__ /* FE_UPWARD defined */
724 fesetround(FE_UPWARD);
728 3) This implies that a conforming implementation reserves no identifiers other than those explicitly
729 reserved in this International Standard.
733 7 A conforming program is one that is acceptable to a conforming implementation.4)
734 8 An implementation shall be accompanied by a document that defines all implementation-
735 defined and locale-specific characteristics and all extensions.
736 Forward references: conditional inclusion (6.10.1), error directive (6.10.5),
737 characteristics of floating types <float.h> (7.7), alternative spellings <iso646.h>
738 (7.9), sizes of integer types <limits.h> (7.10), variable arguments <stdarg.h>
739 (7.15), boolean type and values <stdbool.h> (7.16), common definitions
740 <stddef.h> (7.17), integer types <stdint.h> (7.18).
745 4) Strictly conforming programs are intended to be maximally portable among conforming
746 implementations. Conforming programs may depend upon nonportable features of a conforming
753 1 An implementation translates C source files and executes C programs in two data-
754 processing-system environments, which will be called the translation environment and
755 the execution environment in this International Standard. Their characteristics define and
756 constrain the results of executing conforming C programs constructed according to the
757 syntactic and semantic rules for conforming implementations.
758 Forward references: In this clause, only a few of many possible forward references
760 5.1 Conceptual models
761 5.1.1 Translation environment
762 5.1.1.1 Program structure
763 1 A C program need not all be translated at the same time. The text of the program is kept
764 in units called source files, (or preprocessing files) in this International Standard. A
765 source file together with all the headers and source files included via the preprocessing
766 directive #include is known as a preprocessing translation unit. After preprocessing, a
767 preprocessing translation unit is called a translation unit. Previously translated translation
768 units may be preserved individually or in libraries. The separate translation units of a
769 program communicate by (for example) calls to functions whose identifiers have external
770 linkage, manipulation of objects whose identifiers have external linkage, or manipulation
771 of data files. Translation units may be separately translated and then later linked to
772 produce an executable program.
773 Forward references: linkages of identifiers (6.2.2), external definitions (6.9),
774 preprocessing directives (6.10).
775 5.1.1.2 Translation phases
776 1 The precedence among the syntax rules of translation is specified by the following
778 1. Physical source file multibyte characters are mapped, in an implementation-
779 defined manner, to the source character set (introducing new-line characters for
780 end-of-line indicators) if necessary. Trigraph sequences are replaced by
781 corresponding single-character internal representations.
785 5) Implementations shall behave as if these separate phases occur, even though many are typically folded
786 together in practice. Source files, translation units, and translated translation units need not
787 necessarily be stored as files, nor need there be any one-to-one correspondence between these entities
788 and any external representation. The description is conceptual only, and does not specify any
789 particular implementation.
793 2. Each instance of a backslash character (\) immediately followed by a new-line
794 character is deleted, splicing physical source lines to form logical source lines.
795 Only the last backslash on any physical source line shall be eligible for being part
796 of such a splice. A source file that is not empty shall end in a new-line character,
797 which shall not be immediately preceded by a backslash character before any such
798 splicing takes place.
799 3. The source file is decomposed into preprocessing tokens6) and sequences of
800 white-space characters (including comments). A source file shall not end in a
801 partial preprocessing token or in a partial comment. Each comment is replaced by
802 one space character. New-line characters are retained. Whether each nonempty
803 sequence of white-space characters other than new-line is retained or replaced by
804 one space character is implementation-defined.
805 4. Preprocessing directives are executed, macro invocations are expanded, and
806 _Pragma unary operator expressions are executed. If a character sequence that
807 matches the syntax of a universal character name is produced by token
808 concatenation (6.10.3.3), the behavior is undefined. A #include preprocessing
809 directive causes the named header or source file to be processed from phase 1
810 through phase 4, recursively. All preprocessing directives are then deleted.
811 5. Each source character set member and escape sequence in character constants and
812 string literals is converted to the corresponding member of the execution character
813 set; if there is no corresponding member, it is converted to an implementation-
814 defined member other than the null (wide) character.7)
815 6. Adjacent string literal tokens are concatenated.
816 7. White-space characters separating tokens are no longer significant. Each
817 preprocessing token is converted into a token. The resulting tokens are
818 syntactically and semantically analyzed and translated as a translation unit.
819 8. All external object and function references are resolved. Library components are
820 linked to satisfy external references to functions and objects not defined in the
821 current translation. All such translator output is collected into a program image
822 which contains information needed for execution in its execution environment.
823 Forward references: universal character names (6.4.3), lexical elements (6.4),
824 preprocessing directives (6.10), trigraph sequences (5.2.1.1), external definitions (6.9).
828 6) As described in 6.4, the process of dividing a source file's characters into preprocessing tokens is
829 context-dependent. For example, see the handling of < within a #include preprocessing directive.
830 7) An implementation need not convert all non-corresponding source characters to the same execution
836 1 A conforming implementation shall produce at least one diagnostic message (identified in
837 an implementation-defined manner) if a preprocessing translation unit or translation unit
838 contains a violation of any syntax rule or constraint, even if the behavior is also explicitly
839 specified as undefined or implementation-defined. Diagnostic messages need not be
840 produced in other circumstances.8)
841 2 EXAMPLE An implementation shall issue a diagnostic for the translation unit:
844 because in those cases where wording in this International Standard describes the behavior for a construct
845 as being both a constraint error and resulting in undefined behavior, the constraint error shall be diagnosed.
847 5.1.2 Execution environments
848 1 Two execution environments are defined: freestanding and hosted. In both cases,
849 program startup occurs when a designated C function is called by the execution
850 environment. All objects with static storage duration shall be initialized (set to their
851 initial values) before program startup. The manner and timing of such initialization are
852 otherwise unspecified. Program termination returns control to the execution
854 Forward references: storage durations of objects (6.2.4), initialization (6.7.8).
855 5.1.2.1 Freestanding environment
856 1 In a freestanding environment (in which C program execution may take place without any
857 benefit of an operating system), the name and type of the function called at program
858 startup are implementation-defined. Any library facilities available to a freestanding
859 program, other than the minimal set required by clause 4, are implementation-defined.
860 2 The effect of program termination in a freestanding environment is implementation-
862 5.1.2.2 Hosted environment
863 1 A hosted environment need not be provided, but shall conform to the following
864 specifications if present.
869 8) The intent is that an implementation should identify the nature of, and where possible localize, each
870 violation. Of course, an implementation is free to produce any number of diagnostics as long as a
871 valid program is still correctly translated. It may also successfully translate an invalid program.
875 5.1.2.2.1 Program startup
876 1 The function called at program startup is named main. The implementation declares no
877 prototype for this function. It shall be defined with a return type of int and with no
879 int main(void) { /* ... */ }
880 or with two parameters (referred to here as argc and argv, though any names may be
881 used, as they are local to the function in which they are declared):
882 int main(int argc, char *argv[]) { /* ... */ }
883 or equivalent;9) or in some other implementation-defined manner.
884 2 If they are declared, the parameters to the main function shall obey the following
886 -- The value of argc shall be nonnegative.
887 -- argv[argc] shall be a null pointer.
888 -- If the value of argc is greater than zero, the array members argv[0] through
889 argv[argc-1] inclusive shall contain pointers to strings, which are given
890 implementation-defined values by the host environment prior to program startup. The
891 intent is to supply to the program information determined prior to program startup
892 from elsewhere in the hosted environment. If the host environment is not capable of
893 supplying strings with letters in both uppercase and lowercase, the implementation
894 shall ensure that the strings are received in lowercase.
895 -- If the value of argc is greater than zero, the string pointed to by argv[0]
896 represents the program name; argv[0][0] shall be the null character if the
897 program name is not available from the host environment. If the value of argc is
898 greater than one, the strings pointed to by argv[1] through argv[argc-1]
899 represent the program parameters.
900 -- The parameters argc and argv and the strings pointed to by the argv array shall
901 be modifiable by the program, and retain their last-stored values between program
902 startup and program termination.
903 5.1.2.2.2 Program execution
904 1 In a hosted environment, a program may use all the functions, macros, type definitions,
905 and objects described in the library clause (clause 7).
909 9) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as
910 char ** argv, and so on.
914 5.1.2.2.3 Program termination
915 1 If the return type of the main function is a type compatible with int, a return from the
916 initial call to the main function is equivalent to calling the exit function with the value
917 returned by the main function as its argument;10) reaching the } that terminates the
918 main function returns a value of 0. If the return type is not compatible with int, the
919 termination status returned to the host environment is unspecified.
920 Forward references: definition of terms (7.1.1), the exit function (7.20.4.3).
921 5.1.2.3 Program execution
922 1 The semantic descriptions in this International Standard describe the behavior of an
923 abstract machine in which issues of optimization are irrelevant.
924 2 Accessing a volatile object, modifying an object, modifying a file, or calling a function
925 that does any of those operations are all side effects,11) which are changes in the state of
926 the execution environment. Evaluation of an expression may produce side effects. At
927 certain specified points in the execution sequence called sequence points, all side effects
928 of previous evaluations shall be complete and no side effects of subsequent evaluations
929 shall have taken place. (A summary of the sequence points is given in annex C.)
930 3 In the abstract machine, all expressions are evaluated as specified by the semantics. An
931 actual implementation need not evaluate part of an expression if it can deduce that its
932 value is not used and that no needed side effects are produced (including any caused by
933 calling a function or accessing a volatile object).
934 4 When the processing of the abstract machine is interrupted by receipt of a signal, only the
935 values of objects as of the previous sequence point may be relied on. Objects that may be
936 modified between the previous sequence point and the next sequence point need not have
937 received their correct values yet.
938 5 The least requirements on a conforming implementation are:
939 -- At sequence points, volatile objects are stable in the sense that previous accesses are
940 complete and subsequent accesses have not yet occurred.
945 10) In accordance with 6.2.4, the lifetimes of objects with automatic storage duration declared in main
946 will have ended in the former case, even where they would not have in the latter.
947 11) The IEC 60559 standard for binary floating-point arithmetic requires certain user-accessible status
948 flags and control modes. Floating-point operations implicitly set the status flags; modes affect result
949 values of floating-point operations. Implementations that support such floating-point state are
950 required to regard changes to it as side effects -- see annex F for details. The floating-point
951 environment library <fenv.h> provides a programming facility for indicating when these side
952 effects matter, freeing the implementations in other cases.
956 -- At program termination, all data written into files shall be identical to the result that
957 execution of the program according to the abstract semantics would have produced.
958 -- The input and output dynamics of interactive devices shall take place as specified in
959 7.19.3. The intent of these requirements is that unbuffered or line-buffered output
960 appear as soon as possible, to ensure that prompting messages actually appear prior to
961 a program waiting for input.
962 6 What constitutes an interactive device is implementation-defined.
963 7 More stringent correspondences between abstract and actual semantics may be defined by
965 8 EXAMPLE 1 An implementation might define a one-to-one correspondence between abstract and actual
966 semantics: at every sequence point, the values of the actual objects would agree with those specified by the
967 abstract semantics. The keyword volatile would then be redundant.
968 9 Alternatively, an implementation might perform various optimizations within each translation unit, such
969 that the actual semantics would agree with the abstract semantics only when making function calls across
970 translation unit boundaries. In such an implementation, at the time of each function entry and function
971 return where the calling function and the called function are in different translation units, the values of all
972 externally linked objects and of all objects accessible via pointers therein would agree with the abstract
973 semantics. Furthermore, at the time of each such function entry the values of the parameters of the called
974 function and of all objects accessible via pointers therein would agree with the abstract semantics. In this
975 type of implementation, objects referred to by interrupt service routines activated by the signal function
976 would require explicit specification of volatile storage, as well as other implementation-defined
979 10 EXAMPLE 2 In executing the fragment
983 the ''integer promotions'' require that the abstract machine promote the value of each variable to int size
984 and then add the two ints and truncate the sum. Provided the addition of two chars can be done without
985 overflow, or with overflow wrapping silently to produce the correct result, the actual execution need only
986 produce the same result, possibly omitting the promotions.
988 11 EXAMPLE 3 Similarly, in the fragment
993 the multiplication may be executed using single-precision arithmetic if the implementation can ascertain
994 that the result would be the same as if it were executed using double-precision arithmetic (for example, if d
995 were replaced by the constant 2.0, which has type double).
1002 12 EXAMPLE 4 Implementations employing wide registers have to take care to honor appropriate
1003 semantics. Values are independent of whether they are represented in a register or in memory. For
1004 example, an implicit spilling of a register is not permitted to alter the value. Also, an explicit store and load
1005 is required to round to the precision of the storage type. In particular, casts and assignments are required to
1006 perform their specified conversion. For the fragment
1009 d1 = f = expression;
1010 d2 = (float) expression;
1011 the values assigned to d1 and d2 are required to have been converted to float.
1013 13 EXAMPLE 5 Rearrangement for floating-point expressions is often restricted because of limitations in
1014 precision as well as range. The implementation cannot generally apply the mathematical associative rules
1015 for addition or multiplication, nor the distributive rule, because of roundoff error, even in the absence of
1016 overflow and underflow. Likewise, implementations cannot generally replace decimal constants in order to
1017 rearrange expressions. In the following fragment, rearrangements suggested by mathematical rules for real
1018 numbers are often not valid (see F.8).
1021 x = (x * y) * z; // not equivalent to x *= y * z;
1022 z = (x - y) + y ; // not equivalent to z = x;
1023 z = x + x * y; // not equivalent to z = x * (1.0 + y);
1024 y = x / 5.0; // not equivalent to y = x * 0.2;
1026 14 EXAMPLE 6 To illustrate the grouping behavior of expressions, in the following fragment
1029 a = a + 32760 + b + 5;
1030 the expression statement behaves exactly the same as
1031 a = (((a + 32760) + b) + 5);
1032 due to the associativity and precedence of these operators. Thus, the result of the sum (a + 32760) is
1033 next added to b, and that result is then added to 5 which results in the value assigned to a. On a machine in
1034 which overflows produce an explicit trap and in which the range of values representable by an int is
1035 [-32768, +32767], the implementation cannot rewrite this expression as
1036 a = ((a + b) + 32765);
1037 since if the values for a and b were, respectively, -32754 and -15, the sum a + b would produce a trap
1038 while the original expression would not; nor can the expression be rewritten either as
1039 a = ((a + 32765) + b);
1041 a = (a + (b + 32765));
1042 since the values for a and b might have been, respectively, 4 and -8 or -17 and 12. However, on a machine
1043 in which overflow silently generates some value and where positive and negative overflows cancel, the
1044 above expression statement can be rewritten by the implementation in any of the above ways because the
1045 same result will occur.
1052 15 EXAMPLE 7 The grouping of an expression does not completely determine its evaluation. In the
1058 sum = sum * 10 - '0' + (*p++ = getchar());
1059 the expression statement is grouped as if it were written as
1060 sum = (((sum * 10) - '0') + ((*(p++)) = (getchar())));
1061 but the actual increment of p can occur at any time between the previous sequence point and the next
1062 sequence point (the ;), and the call to getchar can occur at any point prior to the need of its returned
1065 Forward references: expressions (6.5), type qualifiers (6.7.3), statements (6.8), the
1066 signal function (7.14), files (7.19.3).
1073 5.2 Environmental considerations
1074 5.2.1 Character sets
1075 1 Two sets of characters and their associated collating sequences shall be defined: the set in
1076 which source files are written (the source character set), and the set interpreted in the
1077 execution environment (the execution character set). Each set is further divided into a
1078 basic character set, whose contents are given by this subclause, and a set of zero or more
1079 locale-specific members (which are not members of the basic character set) called
1080 extended characters. The combined set is also called the extended character set. The
1081 values of the members of the execution character set are implementation-defined.
1082 2 In a character constant or string literal, members of the execution character set shall be
1083 represented by corresponding members of the source character set or by escape
1084 sequences consisting of the backslash \ followed by one or more characters. A byte with
1085 all bits set to 0, called the null character, shall exist in the basic execution character set; it
1086 is used to terminate a character string.
1087 3 Both the basic source and basic execution character sets shall have the following
1088 members: the 26 uppercase letters of the Latin alphabet
1089 A B C D E F G H I J K L M
1090 N O P Q R S T U V W X Y Z
1091 the 26 lowercase letters of the Latin alphabet
1092 a b c d e f g h i j k l m
1093 n o p q r s t u v w x y z
1094 the 10 decimal digits
1096 the following 29 graphic characters
1097 ! " # % & ' ( ) * + , - . / :
1098 ; < = > ? [ \ ] ^ _ { | } ~
1099 the space character, and control characters representing horizontal tab, vertical tab, and
1100 form feed. The representation of each member of the source and execution basic
1101 character sets shall fit in a byte. In both the source and execution basic character sets, the
1102 value of each character after 0 in the above list of decimal digits shall be one greater than
1103 the value of the previous. In source files, there shall be some way of indicating the end of
1104 each line of text; this International Standard treats such an end-of-line indicator as if it
1105 were a single new-line character. In the basic execution character set, there shall be
1106 control characters representing alert, backspace, carriage return, and new line. If any
1107 other characters are encountered in a source file (except in an identifier, a character
1108 constant, a string literal, a header name, a comment, or a preprocessing token that is never
1112 converted to a token), the behavior is undefined.
1113 4 A letter is an uppercase letter or a lowercase letter as defined above; in this International
1114 Standard the term does not include other characters that are letters in other alphabets.
1115 5 The universal character name construct provides a way to name other characters.
1116 Forward references: universal character names (6.4.3), character constants (6.4.4.4),
1117 preprocessing directives (6.10), string literals (6.4.5), comments (6.4.9), string (7.1.1).
1118 5.2.1.1 Trigraph sequences
1119 1 Before any other processing takes place, each occurrence of one of the following
1120 sequences of three characters (called trigraph sequences12)) is replaced with the
1121 corresponding single character.
1125 No other trigraph sequences exist. Each ? that does not begin one of the trigraphs listed
1126 above is not changed.
1128 ??=define arraycheck(a, b) a??(b??) ??!??! b??(a??)
1130 #define arraycheck(a, b) a[b] || b[a]
1132 3 EXAMPLE 2 The following source line
1134 becomes (after replacement of the trigraph sequence ??/)
1137 5.2.1.2 Multibyte characters
1138 1 The source character set may contain multibyte characters, used to represent members of
1139 the extended character set. The execution character set may also contain multibyte
1140 characters, which need not have the same encoding as for the source character set. For
1141 both character sets, the following shall hold:
1142 -- The basic character set shall be present and each character shall be encoded as a
1144 -- The presence, meaning, and representation of any additional members is locale-
1147 12) The trigraph sequences enable the input of characters that are not defined in the Invariant Code Set as
1148 described in ISO/IEC 646, which is a subset of the seven-bit US ASCII code set.
1152 -- A multibyte character set may have a state-dependent encoding, wherein each
1153 sequence of multibyte characters begins in an initial shift state and enters other
1154 locale-specific shift states when specific multibyte characters are encountered in the
1155 sequence. While in the initial shift state, all single-byte characters retain their usual
1156 interpretation and do not alter the shift state. The interpretation for subsequent bytes
1157 in the sequence is a function of the current shift state.
1158 -- A byte with all bits zero shall be interpreted as a null character independent of shift
1159 state. Such a byte shall not occur as part of any other multibyte character.
1160 2 For source files, the following shall hold:
1161 -- An identifier, comment, string literal, character constant, or header name shall begin
1162 and end in the initial shift state.
1163 -- An identifier, comment, string literal, character constant, or header name shall consist
1164 of a sequence of valid multibyte characters.
1165 5.2.2 Character display semantics
1166 1 The active position is that location on a display device where the next character output by
1167 the fputc function would appear. The intent of writing a printing character (as defined
1168 by the isprint function) to a display device is to display a graphic representation of
1169 that character at the active position and then advance the active position to the next
1170 position on the current line. The direction of writing is locale-specific. If the active
1171 position is at the final position of a line (if there is one), the behavior of the display device
1173 2 Alphabetic escape sequences representing nongraphic characters in the execution
1174 character set are intended to produce actions on display devices as follows:
1175 \a (alert) Produces an audible or visible alert without changing the active position.
1176 \b (backspace) Moves the active position to the previous position on the current line. If
1177 the active position is at the initial position of a line, the behavior of the display
1178 device is unspecified.
1179 \f ( form feed) Moves the active position to the initial position at the start of the next
1181 \n (new line) Moves the active position to the initial position of the next line.
1182 \r (carriage return) Moves the active position to the initial position of the current line.
1183 \t (horizontal tab) Moves the active position to the next horizontal tabulation position
1184 on the current line. If the active position is at or past the last defined horizontal
1185 tabulation position, the behavior of the display device is unspecified.
1186 \v (vertical tab) Moves the active position to the initial position of the next vertical
1187 tabulation position. If the active position is at or past the last defined vertical
1190 tabulation position, the behavior of the display device is unspecified.
1191 3 Each of these escape sequences shall produce a unique implementation-defined value
1192 which can be stored in a single char object. The external representations in a text file
1193 need not be identical to the internal representations, and are outside the scope of this
1194 International Standard.
1195 Forward references: the isprint function (7.4.1.8), the fputc function (7.19.7.3).
1196 5.2.3 Signals and interrupts
1197 1 Functions shall be implemented such that they may be interrupted at any time by a signal,
1198 or may be called by a signal handler, or both, with no alteration to earlier, but still active,
1199 invocations' control flow (after the interruption), function return values, or objects with
1200 automatic storage duration. All such objects shall be maintained outside the function
1201 image (the instructions that compose the executable representation of a function) on a
1202 per-invocation basis.
1203 5.2.4 Environmental limits
1204 1 Both the translation and execution environments constrain the implementation of
1205 language translators and libraries. The following summarizes the language-related
1206 environmental limits on a conforming implementation; the library-related limits are
1207 discussed in clause 7.
1208 5.2.4.1 Translation limits
1209 1 The implementation shall be able to translate and execute at least one program that
1210 contains at least one instance of every one of the following limits:13)
1211 -- 127 nesting levels of blocks
1212 -- 63 nesting levels of conditional inclusion
1213 -- 12 pointer, array, and function declarators (in any combinations) modifying an
1214 arithmetic, structure, union, or incomplete type in a declaration
1215 -- 63 nesting levels of parenthesized declarators within a full declarator
1216 -- 63 nesting levels of parenthesized expressions within a full expression
1217 -- 63 significant initial characters in an internal identifier or a macro name (each
1218 universal character name or extended source character is considered a single
1220 -- 31 significant initial characters in an external identifier (each universal character name
1221 specifying a short identifier of 0000FFFF or less is considered 6 characters, each
1224 13) Implementations should avoid imposing fixed translation limits whenever possible.
1228 universal character name specifying a short identifier of 00010000 or more is
1229 considered 10 characters, and each extended source character is considered the same
1230 number of characters as the corresponding universal character name, if any)14)
1231 -- 4095 external identifiers in one translation unit
1232 -- 511 identifiers with block scope declared in one block
1233 -- 4095 macro identifiers simultaneously defined in one preprocessing translation unit
1234 -- 127 parameters in one function definition
1235 -- 127 arguments in one function call
1236 -- 127 parameters in one macro definition
1237 -- 127 arguments in one macro invocation
1238 -- 4095 characters in a logical source line
1239 -- 4095 characters in a character string literal or wide string literal (after concatenation)
1240 -- 65535 bytes in an object (in a hosted environment only)
1241 -- 15 nesting levels for #included files
1242 -- 1023 case labels for a switch statement (excluding those for any nested switch
1244 -- 1023 members in a single structure or union
1245 -- 1023 enumeration constants in a single enumeration
1246 -- 63 levels of nested structure or union definitions in a single struct-declaration-list
1247 5.2.4.2 Numerical limits
1248 1 An implementation is required to document all the limits specified in this subclause,
1249 which are specified in the headers <limits.h> and <float.h>. Additional limits are
1250 specified in <stdint.h>.
1251 Forward references: integer types <stdint.h> (7.18).
1252 5.2.4.2.1 Sizes of integer types <limits.h>
1253 1 The values given below shall be replaced by constant expressions suitable for use in #if
1254 preprocessing directives. Moreover, except for CHAR_BIT and MB_LEN_MAX, the
1255 following shall be replaced by expressions that have the same type as would an
1256 expression that is an object of the corresponding type converted according to the integer
1257 promotions. Their implementation-defined values shall be equal or greater in magnitude
1260 14) See ''future language directions'' (6.11.3).
1264 (absolute value) to those shown, with the same sign.
1265 -- number of bits for smallest object that is not a bit-field (byte)
1267 -- minimum value for an object of type signed char
1268 SCHAR_MIN -127 // -(27 - 1)
1269 -- maximum value for an object of type signed char
1270 SCHAR_MAX +127 // 27 - 1
1271 -- maximum value for an object of type unsigned char
1272 UCHAR_MAX 255 // 28 - 1
1273 -- minimum value for an object of type char
1275 -- maximum value for an object of type char
1277 -- maximum number of bytes in a multibyte character, for any supported locale
1279 -- minimum value for an object of type short int
1280 SHRT_MIN -32767 // -(215 - 1)
1281 -- maximum value for an object of type short int
1282 SHRT_MAX +32767 // 215 - 1
1283 -- maximum value for an object of type unsigned short int
1284 USHRT_MAX 65535 // 216 - 1
1285 -- minimum value for an object of type int
1286 INT_MIN -32767 // -(215 - 1)
1287 -- maximum value for an object of type int
1288 INT_MAX +32767 // 215 - 1
1289 -- maximum value for an object of type unsigned int
1290 UINT_MAX 65535 // 216 - 1
1291 -- minimum value for an object of type long int
1292 LONG_MIN -2147483647 // -(231 - 1)
1293 -- maximum value for an object of type long int
1294 LONG_MAX +2147483647 // 231 - 1
1295 -- maximum value for an object of type unsigned long int
1296 ULONG_MAX 4294967295 // 232 - 1
1301 -- minimum value for an object of type long long int
1302 LLONG_MIN -9223372036854775807 // -(263 - 1)
1303 -- maximum value for an object of type long long int
1304 LLONG_MAX +9223372036854775807 // 263 - 1
1305 -- maximum value for an object of type unsigned long long int
1306 ULLONG_MAX 18446744073709551615 // 264 - 1
1307 2 If the value of an object of type char is treated as a signed integer when used in an
1308 expression, the value of CHAR_MIN shall be the same as that of SCHAR_MIN and the
1309 value of CHAR_MAX shall be the same as that of SCHAR_MAX. Otherwise, the value of
1310 CHAR_MIN shall be 0 and the value of CHAR_MAX shall be the same as that of
1311 UCHAR_MAX.15) The value UCHAR_MAX shall equal 2CHAR_BIT - 1.
1312 Forward references: representations of types (6.2.6), conditional inclusion (6.10.1).
1313 5.2.4.2.2 Characteristics of floating types <float.h>
1314 1 The characteristics of floating types are defined in terms of a model that describes a
1315 representation of floating-point numbers and values that provide information about an
1316 implementation's floating-point arithmetic.16) The following parameters are used to
1317 define the model for each floating-point type:
1319 b base or radix of exponent representation (an integer > 1)
1320 e exponent (an integer between a minimum emin and a maximum emax )
1321 p precision (the number of base-b digits in the significand)
1322 fk nonnegative integers less than b (the significand digits)
1323 2 A floating-point number (x) is defined by the following model:
1325 x = sb e (Sum) f k b-k ,
1329 3 In addition to normalized floating-point numbers ( f 1 > 0 if x != 0), floating types may be
1330 able to contain other kinds of floating-point numbers, such as subnormal floating-point
1331 numbers (x != 0, e = emin , f 1 = 0) and unnormalized floating-point numbers (x != 0,
1332 e > emin , f 1 = 0), and values that are not floating-point numbers, such as infinities and
1333 NaNs. A NaN is an encoding signifying Not-a-Number. A quiet NaN propagates
1334 through almost every arithmetic operation without raising a floating-point exception; a
1335 signaling NaN generally raises a floating-point exception when occurring as an
1339 16) The floating-point model is intended to clarify the description of each floating-point characteristic and
1340 does not require the floating-point arithmetic of the implementation to be identical.
1344 arithmetic operand.17)
1345 4 An implementation may give zero and non-numeric values (such as infinities and NaNs) a
1346 sign or may leave them unsigned. Wherever such values are unsigned, any requirement
1347 in this International Standard to retrieve the sign shall produce an unspecified sign, and
1348 any requirement to set the sign shall be ignored.
1349 5 The accuracy of the floating-point operations (+, -, *, /) and of the library functions in
1350 <math.h> and <complex.h> that return floating-point results is implementation-
1351 defined, as is the accuracy of the conversion between floating-point internal
1352 representations and string representations performed by the library functions in
1353 <stdio.h>, <stdlib.h>, and <wchar.h>. The implementation may state that the
1354 accuracy is unknown.
1355 6 All integer values in the <float.h> header, except FLT_ROUNDS, shall be constant
1356 expressions suitable for use in #if preprocessing directives; all floating values shall be
1357 constant expressions. All except DECIMAL_DIG, FLT_EVAL_METHOD, FLT_RADIX,
1358 and FLT_ROUNDS have separate names for all three floating-point types. The floating-
1359 point model representation is provided for all values except FLT_EVAL_METHOD and
1361 7 The rounding mode for floating-point addition is characterized by the implementation-
1362 defined value of FLT_ROUNDS:18)
1366 2 toward positive infinity
1367 3 toward negative infinity
1368 All other values for FLT_ROUNDS characterize implementation-defined rounding
1370 8 Except for assignment and cast (which remove all extra range and precision), the values
1371 of operations with floating operands and values subject to the usual arithmetic
1372 conversions and of floating constants are evaluated to a format whose range and precision
1373 may be greater than required by the type. The use of evaluation formats is characterized
1374 by the implementation-defined value of FLT_EVAL_METHOD:19)
1378 17) IEC 60559:1989 specifies quiet and signaling NaNs. For implementations that do not support
1379 IEC 60559:1989, the terms quiet NaN and signaling NaN are intended to apply to encodings with
1381 18) Evaluation of FLT_ROUNDS correctly reflects any execution-time change of rounding mode through
1382 the function fesetround in <fenv.h>.
1387 0 evaluate all operations and constants just to the range and precision of the
1389 1 evaluate operations and constants of type float and double to the
1390 range and precision of the double type, evaluate long double
1391 operations and constants to the range and precision of the long double
1393 2 evaluate all operations and constants to the range and precision of the
1395 All other negative values for FLT_EVAL_METHOD characterize implementation-defined
1397 9 The values given in the following list shall be replaced by constant expressions with
1398 implementation-defined values that are greater or equal in magnitude (absolute value) to
1399 those shown, with the same sign:
1400 -- radix of exponent representation, b
1402 -- number of base-FLT_RADIX digits in the floating-point significand, p
1406 -- number of decimal digits, n, such that any floating-point number in the widest
1407 supported floating type with pmax radix b digits can be rounded to a floating-point
1408 number with n decimal digits and back again without change to the value,
1409 ??? pmax log10 b if b is a power of 10
1411 ??? ???1 + pmax log10 b??? otherwise
1413 -- number of decimal digits, q, such that any floating-point number with q decimal digits
1414 can be rounded into a floating-point number with p radix b digits and back again
1415 without change to the q decimal digits,
1420 19) The evaluation method determines evaluation formats of expressions involving all floating types, not
1421 just real types. For example, if FLT_EVAL_METHOD is 1, then the product of two float
1422 _Complex operands is represented in the double _Complex format, and its parts are evaluated to
1427 ??? p log10 b if b is a power of 10
1429 ??? ???( p - 1) log10 b??? otherwise
1433 -- minimum negative integer such that FLT_RADIX raised to one less than that power is
1434 a normalized floating-point number, emin
1438 -- minimum negative integer such that 10 raised to that power is in the range of
1439 normalized floating-point numbers, ???log10 b emin -1 ???
1444 -- maximum integer such that FLT_RADIX raised to one less than that power is a
1445 representable finite floating-point number, emax
1449 -- maximum integer such that 10 raised to that power is in the range of representable
1450 finite floating-point numbers, ???log10 ((1 - b- p )b emax )???
1454 10 The values given in the following list shall be replaced by constant expressions with
1455 implementation-defined values that are greater than or equal to those shown:
1456 -- maximum representable finite floating-point number, (1 - b- p )b emax
1460 11 The values given in the following list shall be replaced by constant expressions with
1461 implementation-defined (positive) values that are less than or equal to those shown:
1462 -- the difference between 1 and the least value greater than 1 that is representable in the
1463 given floating point type, b1- p
1469 -- minimum normalized positive floating-point number, b emin -1
1473 Recommended practice
1474 12 Conversion from (at least) double to decimal with DECIMAL_DIG digits and back
1475 should be the identity function.
1476 13 EXAMPLE 1 The following describes an artificial floating-point representation that meets the minimum
1477 requirements of this International Standard, and the appropriate values in a <float.h> header for type
1480 x = s16e (Sum) f k 16-k ,
1486 FLT_EPSILON 9.53674316E-07F
1489 FLT_MIN 2.93873588E-39F
1492 FLT_MAX 3.40282347E+38F
1495 14 EXAMPLE 2 The following describes floating-point representations that also meet the requirements for
1496 single-precision and double-precision normalized numbers in IEC 60559,20) and the appropriate values in a
1497 <float.h> header for types float and double:
1499 x f = s2e (Sum) f k 2-k ,
1504 x d = s2e (Sum) f k 2-k ,
1511 FLT_EPSILON 1.19209290E-07F // decimal constant
1512 FLT_EPSILON 0X1P-23F // hex constant
1515 20) The floating-point model in that standard sums powers of b from zero, so the values of the exponent
1516 limits are one less than shown here.
1522 FLT_MIN 1.17549435E-38F // decimal constant
1523 FLT_MIN 0X1P-126F // hex constant
1526 FLT_MAX 3.40282347E+38F // decimal constant
1527 FLT_MAX 0X1.fffffeP127F // hex constant
1530 DBL_EPSILON 2.2204460492503131E-16 // decimal constant
1531 DBL_EPSILON 0X1P-52 // hex constant
1534 DBL_MIN 2.2250738585072014E-308 // decimal constant
1535 DBL_MIN 0X1P-1022 // hex constant
1538 DBL_MAX 1.7976931348623157E+308 // decimal constant
1539 DBL_MAX 0X1.fffffffffffffP1023 // hex constant
1541 If a type wider than double were supported, then DECIMAL_DIG would be greater than 17. For
1542 example, if the widest type were to use the minimal-width IEC 60559 double-extended format (64 bits of
1543 precision), then DECIMAL_DIG would be 21.
1545 Forward references: conditional inclusion (6.10.1), complex arithmetic
1546 <complex.h> (7.3), extended multibyte and wide character utilities <wchar.h>
1547 (7.24), floating-point environment <fenv.h> (7.6), general utilities <stdlib.h>
1548 (7.20), input/output <stdio.h> (7.19), mathematics <math.h> (7.12).
1558 1 In the syntax notation used in this clause, syntactic categories (nonterminals) are
1559 indicated by italic type, and literal words and character set members (terminals) by bold
1560 type. A colon (:) following a nonterminal introduces its definition. Alternative
1561 definitions are listed on separate lines, except when prefaced by the words ''one of''. An
1562 optional symbol is indicated by the subscript ''opt'', so that
1564 indicates an optional expression enclosed in braces.
1565 2 When syntactic categories are referred to in the main text, they are not italicized and
1566 words are separated by spaces instead of hyphens.
1567 3 A summary of the language syntax is given in annex A.
1569 6.2.1 Scopes of identifiers
1570 1 An identifier can denote an object; a function; a tag or a member of a structure, union, or
1571 enumeration; a typedef name; a label name; a macro name; or a macro parameter. The
1572 same identifier can denote different entities at different points in the program. A member
1573 of an enumeration is called an enumeration constant. Macro names and macro
1574 parameters are not considered further here, because prior to the semantic phase of
1575 program translation any occurrences of macro names in the source file are replaced by the
1576 preprocessing token sequences that constitute their macro definitions.
1577 2 For each different entity that an identifier designates, the identifier is visible (i.e., can be
1578 used) only within a region of program text called its scope. Different entities designated
1579 by the same identifier either have different scopes, or are in different name spaces. There
1580 are four kinds of scopes: function, file, block, and function prototype. (A function
1581 prototype is a declaration of a function that declares the types of its parameters.)
1582 3 A label name is the only kind of identifier that has function scope. It can be used (in a
1583 goto statement) anywhere in the function in which it appears, and is declared implicitly
1584 by its syntactic appearance (followed by a : and a statement).
1585 4 Every other identifier has scope determined by the placement of its declaration (in a
1586 declarator or type specifier). If the declarator or type specifier that declares the identifier
1587 appears outside of any block or list of parameters, the identifier has file scope, which
1588 terminates at the end of the translation unit. If the declarator or type specifier that
1589 declares the identifier appears inside a block or within the list of parameter declarations in
1590 a function definition, the identifier has block scope, which terminates at the end of the
1591 associated block. If the declarator or type specifier that declares the identifier appears
1594 within the list of parameter declarations in a function prototype (not part of a function
1595 definition), the identifier has function prototype scope, which terminates at the end of the
1596 function declarator. If an identifier designates two different entities in the same name
1597 space, the scopes might overlap. If so, the scope of one entity (the inner scope) will be a
1598 strict subset of the scope of the other entity (the outer scope). Within the inner scope, the
1599 identifier designates the entity declared in the inner scope; the entity declared in the outer
1600 scope is hidden (and not visible) within the inner scope.
1601 5 Unless explicitly stated otherwise, where this International Standard uses the term
1602 ''identifier'' to refer to some entity (as opposed to the syntactic construct), it refers to the
1603 entity in the relevant name space whose declaration is visible at the point the identifier
1605 6 Two identifiers have the same scope if and only if their scopes terminate at the same
1607 7 Structure, union, and enumeration tags have scope that begins just after the appearance of
1608 the tag in a type specifier that declares the tag. Each enumeration constant has scope that
1609 begins just after the appearance of its defining enumerator in an enumerator list. Any
1610 other identifier has scope that begins just after the completion of its declarator.
1611 Forward references: declarations (6.7), function calls (6.5.2.2), function definitions
1612 (6.9.1), identifiers (6.4.2), name spaces of identifiers (6.2.3), macro replacement (6.10.3),
1613 source file inclusion (6.10.2), statements (6.8).
1614 6.2.2 Linkages of identifiers
1615 1 An identifier declared in different scopes or in the same scope more than once can be
1616 made to refer to the same object or function by a process called linkage.21) There are
1617 three kinds of linkage: external, internal, and none.
1618 2 In the set of translation units and libraries that constitutes an entire program, each
1619 declaration of a particular identifier with external linkage denotes the same object or
1620 function. Within one translation unit, each declaration of an identifier with internal
1621 linkage denotes the same object or function. Each declaration of an identifier with no
1622 linkage denotes a unique entity.
1623 3 If the declaration of a file scope identifier for an object or a function contains the storage-
1624 class specifier static, the identifier has internal linkage.22)
1625 4 For an identifier declared with the storage-class specifier extern in a scope in which a
1629 21) There is no linkage between different identifiers.
1630 22) A function declaration can contain the storage-class specifier static only if it is at file scope; see
1635 prior declaration of that identifier is visible,23) if the prior declaration specifies internal or
1636 external linkage, the linkage of the identifier at the later declaration is the same as the
1637 linkage specified at the prior declaration. If no prior declaration is visible, or if the prior
1638 declaration specifies no linkage, then the identifier has external linkage.
1639 5 If the declaration of an identifier for a function has no storage-class specifier, its linkage
1640 is determined exactly as if it were declared with the storage-class specifier extern. If
1641 the declaration of an identifier for an object has file scope and no storage-class specifier,
1642 its linkage is external.
1643 6 The following identifiers have no linkage: an identifier declared to be anything other than
1644 an object or a function; an identifier declared to be a function parameter; a block scope
1645 identifier for an object declared without the storage-class specifier extern.
1646 7 If, within a translation unit, the same identifier appears with both internal and external
1647 linkage, the behavior is undefined.
1648 Forward references: declarations (6.7), expressions (6.5), external definitions (6.9),
1650 6.2.3 Name spaces of identifiers
1651 1 If more than one declaration of a particular identifier is visible at any point in a
1652 translation unit, the syntactic context disambiguates uses that refer to different entities.
1653 Thus, there are separate name spaces for various categories of identifiers, as follows:
1654 -- label names (disambiguated by the syntax of the label declaration and use);
1655 -- the tags of structures, unions, and enumerations (disambiguated by following any24)
1656 of the keywords struct, union, or enum);
1657 -- the members of structures or unions; each structure or union has a separate name
1658 space for its members (disambiguated by the type of the expression used to access the
1659 member via the . or -> operator);
1660 -- all other identifiers, called ordinary identifiers (declared in ordinary declarators or as
1661 enumeration constants).
1662 Forward references: enumeration specifiers (6.7.2.2), labeled statements (6.8.1),
1663 structure and union specifiers (6.7.2.1), structure and union members (6.5.2.3), tags
1664 (6.7.2.3), the goto statement (6.8.6.1).
1669 23) As specified in 6.2.1, the later declaration might hide the prior declaration.
1670 24) There is only one name space for tags even though three are possible.
1674 6.2.4 Storage durations of objects
1675 1 An object has a storage duration that determines its lifetime. There are three storage
1676 durations: static, automatic, and allocated. Allocated storage is described in 7.20.3.
1677 2 The lifetime of an object is the portion of program execution during which storage is
1678 guaranteed to be reserved for it. An object exists, has a constant address,25) and retains
1679 its last-stored value throughout its lifetime.26) If an object is referred to outside of its
1680 lifetime, the behavior is undefined. The value of a pointer becomes indeterminate when
1681 the object it points to reaches the end of its lifetime.
1682 3 An object whose identifier is declared with external or internal linkage, or with the
1683 storage-class specifier static has static storage duration. Its lifetime is the entire
1684 execution of the program and its stored value is initialized only once, prior to program
1686 4 An object whose identifier is declared with no linkage and without the storage-class
1687 specifier static has automatic storage duration.
1688 5 For such an object that does not have a variable length array type, its lifetime extends
1689 from entry into the block with which it is associated until execution of that block ends in
1690 any way. (Entering an enclosed block or calling a function suspends, but does not end,
1691 execution of the current block.) If the block is entered recursively, a new instance of the
1692 object is created each time. The initial value of the object is indeterminate. If an
1693 initialization is specified for the object, it is performed each time the declaration is
1694 reached in the execution of the block; otherwise, the value becomes indeterminate each
1695 time the declaration is reached.
1696 6 For such an object that does have a variable length array type, its lifetime extends from
1697 the declaration of the object until execution of the program leaves the scope of the
1698 declaration.27) If the scope is entered recursively, a new instance of the object is created
1699 each time. The initial value of the object is indeterminate.
1700 Forward references: statements (6.8), function calls (6.5.2.2), declarators (6.7.5), array
1701 declarators (6.7.5.2), initialization (6.7.8).
1706 25) The term ''constant address'' means that two pointers to the object constructed at possibly different
1707 times will compare equal. The address may be different during two different executions of the same
1709 26) In the case of a volatile object, the last store need not be explicit in the program.
1710 27) Leaving the innermost block containing the declaration, or jumping to a point in that block or an
1711 embedded block prior to the declaration, leaves the scope of the declaration.
1716 1 The meaning of a value stored in an object or returned by a function is determined by the
1717 type of the expression used to access it. (An identifier declared to be an object is the
1718 simplest such expression; the type is specified in the declaration of the identifier.) Types
1719 are partitioned into object types (types that fully describe objects), function types (types
1720 that describe functions), and incomplete types (types that describe objects but lack
1721 information needed to determine their sizes).
1722 2 An object declared as type _Bool is large enough to store the values 0 and 1.
1723 3 An object declared as type char is large enough to store any member of the basic
1724 execution character set. If a member of the basic execution character set is stored in a
1725 char object, its value is guaranteed to be nonnegative. If any other character is stored in
1726 a char object, the resulting value is implementation-defined but shall be within the range
1727 of values that can be represented in that type.
1728 4 There are five standard signed integer types, designated as signed char, short
1729 int, int, long int, and long long int. (These and other types may be
1730 designated in several additional ways, as described in 6.7.2.) There may also be
1731 implementation-defined extended signed integer types.28) The standard and extended
1732 signed integer types are collectively called signed integer types.29)
1733 5 An object declared as type signed char occupies the same amount of storage as a
1734 ''plain'' char object. A ''plain'' int object has the natural size suggested by the
1735 architecture of the execution environment (large enough to contain any value in the range
1736 INT_MIN to INT_MAX as defined in the header <limits.h>).
1737 6 For each of the signed integer types, there is a corresponding (but different) unsigned
1738 integer type (designated with the keyword unsigned) that uses the same amount of
1739 storage (including sign information) and has the same alignment requirements. The type
1740 _Bool and the unsigned integer types that correspond to the standard signed integer
1741 types are the standard unsigned integer types. The unsigned integer types that
1742 correspond to the extended signed integer types are the extended unsigned integer types.
1743 The standard and extended unsigned integer types are collectively called unsigned integer
1748 28) Implementation-defined keywords shall have the form of an identifier reserved for any use as
1750 29) Therefore, any statement in this Standard about signed integer types also applies to the extended
1751 signed integer types.
1752 30) Therefore, any statement in this Standard about unsigned integer types also applies to the extended
1753 unsigned integer types.
1757 7 The standard signed integer types and standard unsigned integer types are collectively
1758 called the standard integer types, the extended signed integer types and extended
1759 unsigned integer types are collectively called the extended integer types.
1760 8 For any two integer types with the same signedness and different integer conversion rank
1761 (see 6.3.1.1), the range of values of the type with smaller integer conversion rank is a
1762 subrange of the values of the other type.
1763 9 The range of nonnegative values of a signed integer type is a subrange of the
1764 corresponding unsigned integer type, and the representation of the same value in each
1765 type is the same.31) A computation involving unsigned operands can never overflow,
1766 because a result that cannot be represented by the resulting unsigned integer type is
1767 reduced modulo the number that is one greater than the largest value that can be
1768 represented by the resulting type.
1769 10 There are three real floating types, designated as float, double, and long
1770 double.32) The set of values of the type float is a subset of the set of values of the
1771 type double; the set of values of the type double is a subset of the set of values of the
1773 11 There are three complex types, designated as float _Complex, double
1774 _Complex, and long double _Complex.33) The real floating and complex types
1775 are collectively called the floating types.
1776 12 For each floating type there is a corresponding real type, which is always a real floating
1777 type. For real floating types, it is the same type. For complex types, it is the type given
1778 by deleting the keyword _Complex from the type name.
1779 13 Each complex type has the same representation and alignment requirements as an array
1780 type containing exactly two elements of the corresponding real type; the first element is
1781 equal to the real part, and the second element to the imaginary part, of the complex
1783 14 The type char, the signed and unsigned integer types, and the floating types are
1784 collectively called the basic types. Even if the implementation defines two or more basic
1785 types to have the same representation, they are nevertheless different types.34)
1787 31) The same representation and alignment requirements are meant to imply interchangeability as
1788 arguments to functions, return values from functions, and members of unions.
1789 32) See ''future language directions'' (6.11.1).
1790 33) A specification for imaginary types is in informative annex G.
1791 34) An implementation may define new keywords that provide alternative ways to designate a basic (or
1792 any other) type; this does not violate the requirement that all basic types be different.
1793 Implementation-defined keywords shall have the form of an identifier reserved for any use as
1798 15 The three types char, signed char, and unsigned char are collectively called
1799 the character types. The implementation shall define char to have the same range,
1800 representation, and behavior as either signed char or unsigned char.35)
1801 16 An enumeration comprises a set of named integer constant values. Each distinct
1802 enumeration constitutes a different enumerated type.
1803 17 The type char, the signed and unsigned integer types, and the enumerated types are
1804 collectively called integer types. The integer and real floating types are collectively called
1806 18 Integer and floating types are collectively called arithmetic types. Each arithmetic type
1807 belongs to one type domain: the real type domain comprises the real types, the complex
1808 type domain comprises the complex types.
1809 19 The void type comprises an empty set of values; it is an incomplete type that cannot be
1811 20 Any number of derived types can be constructed from the object, function, and
1812 incomplete types, as follows:
1813 -- An array type describes a contiguously allocated nonempty set of objects with a
1814 particular member object type, called the element type.36) Array types are
1815 characterized by their element type and by the number of elements in the array. An
1816 array type is said to be derived from its element type, and if its element type is T , the
1817 array type is sometimes called ''array of T ''. The construction of an array type from
1818 an element type is called ''array type derivation''.
1819 -- A structure type describes a sequentially allocated nonempty set of member objects
1820 (and, in certain circumstances, an incomplete array), each of which has an optionally
1821 specified name and possibly distinct type.
1822 -- A union type describes an overlapping nonempty set of member objects, each of
1823 which has an optionally specified name and possibly distinct type.
1824 -- A function type describes a function with specified return type. A function type is
1825 characterized by its return type and the number and types of its parameters. A
1826 function type is said to be derived from its return type, and if its return type is T , the
1827 function type is sometimes called ''function returning T ''. The construction of a
1828 function type from a return type is called ''function type derivation''.
1832 35) CHAR_MIN, defined in <limits.h>, will have one of the values 0 or SCHAR_MIN, and this can be
1833 used to distinguish the two options. Irrespective of the choice made, char is a separate type from the
1834 other two and is not compatible with either.
1835 36) Since object types do not include incomplete types, an array of incomplete type cannot be constructed.
1839 -- A pointer type may be derived from a function type, an object type, or an incomplete
1840 type, called the referenced type. A pointer type describes an object whose value
1841 provides a reference to an entity of the referenced type. A pointer type derived from
1842 the referenced type T is sometimes called ''pointer to T ''. The construction of a
1843 pointer type from a referenced type is called ''pointer type derivation''.
1844 These methods of constructing derived types can be applied recursively.
1845 21 Arithmetic types and pointer types are collectively called scalar types. Array and
1846 structure types are collectively called aggregate types.37)
1847 22 An array type of unknown size is an incomplete type. It is completed, for an identifier of
1848 that type, by specifying the size in a later declaration (with internal or external linkage).
1849 A structure or union type of unknown content (as described in 6.7.2.3) is an incomplete
1850 type. It is completed, for all declarations of that type, by declaring the same structure or
1851 union tag with its defining content later in the same scope.
1852 23 A type has known constant size if the type is not incomplete and is not a variable length
1854 24 Array, function, and pointer types are collectively called derived declarator types. A
1855 declarator type derivation from a type T is the construction of a derived declarator type
1856 from T by the application of an array-type, a function-type, or a pointer-type derivation to
1858 25 A type is characterized by its type category, which is either the outermost derivation of a
1859 derived type (as noted above in the construction of derived types), or the type itself if the
1860 type consists of no derived types.
1861 26 Any type so far mentioned is an unqualified type. Each unqualified type has several
1862 qualified versions of its type,38) corresponding to the combinations of one, two, or all
1863 three of the const, volatile, and restrict qualifiers. The qualified or unqualified
1864 versions of a type are distinct types that belong to the same type category and have the
1865 same representation and alignment requirements.39) A derived type is not qualified by the
1866 qualifiers (if any) of the type from which it is derived.
1867 27 A pointer to void shall have the same representation and alignment requirements as a
1868 pointer to a character type.39) Similarly, pointers to qualified or unqualified versions of
1869 compatible types shall have the same representation and alignment requirements. All
1872 37) Note that aggregate type does not include union type because an object with union type can only
1873 contain one member at a time.
1874 38) See 6.7.3 regarding qualified array and function types.
1875 39) The same representation and alignment requirements are meant to imply interchangeability as
1876 arguments to functions, return values from functions, and members of unions.
1880 pointers to structure types shall have the same representation and alignment requirements
1881 as each other. All pointers to union types shall have the same representation and
1882 alignment requirements as each other. Pointers to other types need not have the same
1883 representation or alignment requirements.
1884 28 EXAMPLE 1 The type designated as ''float *'' has type ''pointer to float''. Its type category is
1885 pointer, not a floating type. The const-qualified version of this type is designated as ''float * const''
1886 whereas the type designated as ''const float *'' is not a qualified type -- its type is ''pointer to const-
1887 qualified float'' and is a pointer to a qualified type.
1889 29 EXAMPLE 2 The type designated as ''struct tag (*[5])(float)'' has type ''array of pointer to
1890 function returning struct tag''. The array has length five and the function has a single parameter of type
1891 float. Its type category is array.
1893 Forward references: compatible type and composite type (6.2.7), declarations (6.7).
1894 6.2.6 Representations of types
1896 1 The representations of all types are unspecified except as stated in this subclause.
1897 2 Except for bit-fields, objects are composed of contiguous sequences of one or more bytes,
1898 the number, order, and encoding of which are either explicitly specified or
1899 implementation-defined.
1900 3 Values stored in unsigned bit-fields and objects of type unsigned char shall be
1901 represented using a pure binary notation.40)
1902 4 Values stored in non-bit-field objects of any other object type consist of n x CHAR_BIT
1903 bits, where n is the size of an object of that type, in bytes. The value may be copied into
1904 an object of type unsigned char [n] (e.g., by memcpy); the resulting set of bytes is
1905 called the object representation of the value. Values stored in bit-fields consist of m bits,
1906 where m is the size specified for the bit-field. The object representation is the set of m
1907 bits the bit-field comprises in the addressable storage unit holding it. Two values (other
1908 than NaNs) with the same object representation compare equal, but values that compare
1909 equal may have different object representations.
1910 5 Certain object representations need not represent a value of the object type. If the stored
1911 value of an object has such a representation and is read by an lvalue expression that does
1912 not have character type, the behavior is undefined. If such a representation is produced
1913 by a side effect that modifies all or any part of the object by an lvalue expression that
1914 does not have character type, the behavior is undefined.41) Such a representation is called
1916 40) A positional representation for integers that uses the binary digits 0 and 1, in which the values
1917 represented by successive bits are additive, begin with 1, and are multiplied by successive integral
1918 powers of 2, except perhaps the bit with the highest position. (Adapted from the American National
1919 Dictionary for Information Processing Systems.) A byte contains CHAR_BIT bits, and the values of
1920 type unsigned char range from 0 to 2
1926 a trap representation.
1927 6 When a value is stored in an object of structure or union type, including in a member
1928 object, the bytes of the object representation that correspond to any padding bytes take
1929 unspecified values.42) The value of a structure or union object is never a trap
1930 representation, even though the value of a member of the structure or union object may be
1931 a trap representation.
1932 7 When a value is stored in a member of an object of union type, the bytes of the object
1933 representation that do not correspond to that member but do correspond to other members
1934 take unspecified values.
1935 8 Where an operator is applied to a value that has more than one object representation,
1936 which object representation is used shall not affect the value of the result.43) Where a
1937 value is stored in an object using a type that has more than one object representation for
1938 that value, it is unspecified which representation is used, but a trap representation shall
1940 Forward references: declarations (6.7), expressions (6.5), lvalues, arrays, and function
1941 designators (6.3.2.1).
1942 6.2.6.2 Integer types
1943 1 For unsigned integer types other than unsigned char, the bits of the object
1944 representation shall be divided into two groups: value bits and padding bits (there need
1945 not be any of the latter). If there are N value bits, each bit shall represent a different
1946 power of 2 between 1 and 2 N -1 , so that objects of that type shall be capable of
1947 representing values from 0 to 2 N - 1 using a pure binary representation; this shall be
1948 known as the value representation. The values of any padding bits are unspecified.44)
1949 2 For signed integer types, the bits of the object representation shall be divided into three
1950 groups: value bits, padding bits, and the sign bit. There need not be any padding bits;
1952 41) Thus, an automatic variable can be initialized to a trap representation without causing undefined
1953 behavior, but the value of the variable cannot be used until a proper value is stored in it.
1954 42) Thus, for example, structure assignment need not copy any padding bits.
1955 43) It is possible for objects x and y with the same effective type T to have the same value when they are
1956 accessed as objects of type T, but to have different values in other contexts. In particular, if == is
1957 defined for type T, then x == y does not imply that memcmp(&x, &y, sizeof (T)) == 0.
1958 Furthermore, x == y does not necessarily imply that x and y have the same value; other operations
1959 on values of type T may distinguish between them.
1960 44) Some combinations of padding bits might generate trap representations, for example, if one padding
1961 bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap
1962 representation other than as part of an exceptional condition such as an overflow, and this cannot occur
1963 with unsigned types. All other combinations of padding bits are alternative object representations of
1964 the value specified by the value bits.
1968 there shall be exactly one sign bit. Each bit that is a value bit shall have the same value as
1969 the same bit in the object representation of the corresponding unsigned type (if there are
1970 M value bits in the signed type and N in the unsigned type, then M <= N ). If the sign bit
1971 is zero, it shall not affect the resulting value. If the sign bit is one, the value shall be
1972 modified in one of the following ways:
1973 -- the corresponding value with sign bit 0 is negated (sign and magnitude);
1974 -- the sign bit has the value -(2 N ) (two's complement);
1975 -- the sign bit has the value -(2 N - 1) (ones' complement ).
1976 Which of these applies is implementation-defined, as is whether the value with sign bit 1
1977 and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones'
1978 complement), is a trap representation or a normal value. In the case of sign and
1979 magnitude and ones' complement, if this representation is a normal value it is called a
1981 3 If the implementation supports negative zeros, they shall be generated only by:
1982 -- the &, |, ^, ~, <<, and >> operators with arguments that produce such a value;
1983 -- the +, -, *, /, and % operators where one argument is a negative zero and the result is
1985 -- compound assignment operators based on the above cases.
1986 It is unspecified whether these cases actually generate a negative zero or a normal zero,
1987 and whether a negative zero becomes a normal zero when stored in an object.
1988 4 If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<,
1989 and >> operators with arguments that would produce such a value is undefined.
1990 5 The values of any padding bits are unspecified.45) A valid (non-trap) object representation
1991 of a signed integer type where the sign bit is zero is a valid object representation of the
1992 corresponding unsigned type, and shall represent the same value. For any integer type,
1993 the object representation where all the bits are zero shall be a representation of the value
1995 6 The precision of an integer type is the number of bits it uses to represent values,
1996 excluding any sign and padding bits. The width of an integer type is the same but
1997 including any sign bit; thus for unsigned integer types the two values are the same, while
2000 45) Some combinations of padding bits might generate trap representations, for example, if one padding
2001 bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap
2002 representation other than as part of an exceptional condition such as an overflow. All other
2003 combinations of padding bits are alternative object representations of the value specified by the value
2008 for signed integer types the width is one greater than the precision.
2009 6.2.7 Compatible type and composite type
2010 1 Two types have compatible type if their types are the same. Additional rules for
2011 determining whether two types are compatible are described in 6.7.2 for type specifiers,
2012 in 6.7.3 for type qualifiers, and in 6.7.5 for declarators.46) Moreover, two structure,
2013 union, or enumerated types declared in separate translation units are compatible if their
2014 tags and members satisfy the following requirements: If one is declared with a tag, the
2015 other shall be declared with the same tag. If both are complete types, then the following
2016 additional requirements apply: there shall be a one-to-one correspondence between their
2017 members such that each pair of corresponding members are declared with compatible
2018 types, and such that if one member of a corresponding pair is declared with a name, the
2019 other member is declared with the same name. For two structures, corresponding
2020 members shall be declared in the same order. For two structures or unions, corresponding
2021 bit-fields shall have the same widths. For two enumerations, corresponding members
2022 shall have the same values.
2023 2 All declarations that refer to the same object or function shall have compatible type;
2024 otherwise, the behavior is undefined.
2025 3 A composite type can be constructed from two types that are compatible; it is a type that
2026 is compatible with both of the two types and satisfies the following conditions:
2027 -- If one type is an array of known constant size, the composite type is an array of that
2028 size; otherwise, if one type is a variable length array, the composite type is that type.
2029 -- If only one type is a function type with a parameter type list (a function prototype),
2030 the composite type is a function prototype with the parameter type list.
2031 -- If both types are function types with parameter type lists, the type of each parameter
2032 in the composite parameter type list is the composite type of the corresponding
2034 These rules apply recursively to the types from which the two types are derived.
2035 4 For an identifier with internal or external linkage declared in a scope in which a prior
2036 declaration of that identifier is visible,47) if the prior declaration specifies internal or
2037 external linkage, the type of the identifier at the later declaration becomes the composite
2043 46) Two types need not be identical to be compatible.
2044 47) As specified in 6.2.1, the later declaration might hide the prior declaration.
2048 5 EXAMPLE Given the following two file scope declarations:
2049 int f(int (*)(), double (*)[3]);
2050 int f(int (*)(char *), double (*)[]);
2051 The resulting composite type for the function is:
2052 int f(int (*)(char *), double (*)[3]);
2060 1 Several operators convert operand values from one type to another automatically. This
2061 subclause specifies the result required from such an implicit conversion, as well as those
2062 that result from a cast operation (an explicit conversion). The list in 6.3.1.8 summarizes
2063 the conversions performed by most ordinary operators; it is supplemented as required by
2064 the discussion of each operator in 6.5.
2065 2 Conversion of an operand value to a compatible type causes no change to the value or the
2067 Forward references: cast operators (6.5.4).
2068 6.3.1 Arithmetic operands
2069 6.3.1.1 Boolean, characters, and integers
2070 1 Every integer type has an integer conversion rank defined as follows:
2071 -- No two signed integer types shall have the same rank, even if they have the same
2073 -- The rank of a signed integer type shall be greater than the rank of any signed integer
2074 type with less precision.
2075 -- The rank of long long int shall be greater than the rank of long int, which
2076 shall be greater than the rank of int, which shall be greater than the rank of short
2077 int, which shall be greater than the rank of signed char.
2078 -- The rank of any unsigned integer type shall equal the rank of the corresponding
2079 signed integer type, if any.
2080 -- The rank of any standard integer type shall be greater than the rank of any extended
2081 integer type with the same width.
2082 -- The rank of char shall equal the rank of signed char and unsigned char.
2083 -- The rank of _Bool shall be less than the rank of all other standard integer types.
2084 -- The rank of any enumerated type shall equal the rank of the compatible integer type
2086 -- The rank of any extended signed integer type relative to another extended signed
2087 integer type with the same precision is implementation-defined, but still subject to the
2088 other rules for determining the integer conversion rank.
2089 -- For all integer types T1, T2, and T3, if T1 has greater rank than T2 and T2 has
2090 greater rank than T3, then T1 has greater rank than T3.
2091 2 The following may be used in an expression wherever an int or unsigned int may
2096 -- An object or expression with an integer type whose integer conversion rank is less
2097 than or equal to the rank of int and unsigned int.
2098 -- A bit-field of type _Bool, int, signed int, or unsigned int.
2099 If an int can represent all values of the original type, the value is converted to an int;
2100 otherwise, it is converted to an unsigned int. These are called the integer
2101 promotions.48) All other types are unchanged by the integer promotions.
2102 3 The integer promotions preserve value including sign. As discussed earlier, whether a
2103 ''plain'' char is treated as signed is implementation-defined.
2104 Forward references: enumeration specifiers (6.7.2.2), structure and union specifiers
2106 6.3.1.2 Boolean type
2107 1 When any scalar value is converted to _Bool, the result is 0 if the value compares equal
2108 to 0; otherwise, the result is 1.
2109 6.3.1.3 Signed and unsigned integers
2110 1 When a value with integer type is converted to another integer type other than _Bool, if
2111 the value can be represented by the new type, it is unchanged.
2112 2 Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or
2113 subtracting one more than the maximum value that can be represented in the new type
2114 until the value is in the range of the new type.49)
2115 3 Otherwise, the new type is signed and the value cannot be represented in it; either the
2116 result is implementation-defined or an implementation-defined signal is raised.
2117 6.3.1.4 Real floating and integer
2118 1 When a finite value of real floating type is converted to an integer type other than _Bool,
2119 the fractional part is discarded (i.e., the value is truncated toward zero). If the value of
2120 the integral part cannot be represented by the integer type, the behavior is undefined.50)
2121 2 When a value of integer type is converted to a real floating type, if the value being
2122 converted can be represented exactly in the new type, it is unchanged. If the value being
2123 converted is in the range of values that can be represented but cannot be represented
2125 48) The integer promotions are applied only: as part of the usual arithmetic conversions, to certain
2126 argument expressions, to the operands of the unary +, -, and ~ operators, and to both operands of the
2127 shift operators, as specified by their respective subclauses.
2128 49) The rules describe arithmetic on the mathematical value, not the value of a given type of expression.
2129 50) The remaindering operation performed when a value of integer type is converted to unsigned type
2130 need not be performed when a value of real floating type is converted to unsigned type. Thus, the
2131 range of portable real floating values is (-1, Utype_MAX+1).
2135 exactly, the result is either the nearest higher or nearest lower representable value, chosen
2136 in an implementation-defined manner. If the value being converted is outside the range of
2137 values that can be represented, the behavior is undefined.
2138 6.3.1.5 Real floating types
2139 1 When a float is promoted to double or long double, or a double is promoted
2140 to long double, its value is unchanged (if the source value is represented in the
2141 precision and range of its type).
2142 2 When a double is demoted to float, a long double is demoted to double or
2143 float, or a value being represented in greater precision and range than required by its
2144 semantic type (see 6.3.1.8) is explicitly converted (including to its own type), if the value
2145 being converted can be represented exactly in the new type, it is unchanged. If the value
2146 being converted is in the range of values that can be represented but cannot be
2147 represented exactly, the result is either the nearest higher or nearest lower representable
2148 value, chosen in an implementation-defined manner. If the value being converted is
2149 outside the range of values that can be represented, the behavior is undefined.
2150 6.3.1.6 Complex types
2151 1 When a value of complex type is converted to another complex type, both the real and
2152 imaginary parts follow the conversion rules for the corresponding real types.
2153 6.3.1.7 Real and complex
2154 1 When a value of real type is converted to a complex type, the real part of the complex
2155 result value is determined by the rules of conversion to the corresponding real type and
2156 the imaginary part of the complex result value is a positive zero or an unsigned zero.
2157 2 When a value of complex type is converted to a real type, the imaginary part of the
2158 complex value is discarded and the value of the real part is converted according to the
2159 conversion rules for the corresponding real type.
2160 6.3.1.8 Usual arithmetic conversions
2161 1 Many operators that expect operands of arithmetic type cause conversions and yield result
2162 types in a similar way. The purpose is to determine a common real type for the operands
2163 and result. For the specified operands, each operand is converted, without change of type
2164 domain, to a type whose corresponding real type is the common real type. Unless
2165 explicitly stated otherwise, the common real type is also the corresponding real type of
2166 the result, whose type domain is the type domain of the operands if they are the same,
2167 and complex otherwise. This pattern is called the usual arithmetic conversions:
2168 First, if the corresponding real type of either operand is long double, the other
2169 operand is converted, without change of type domain, to a type whose
2170 corresponding real type is long double.
2174 Otherwise, if the corresponding real type of either operand is double, the other
2175 operand is converted, without change of type domain, to a type whose
2176 corresponding real type is double.
2177 Otherwise, if the corresponding real type of either operand is float, the other
2178 operand is converted, without change of type domain, to a type whose
2179 corresponding real type is float.51)
2180 Otherwise, the integer promotions are performed on both operands. Then the
2181 following rules are applied to the promoted operands:
2182 If both operands have the same type, then no further conversion is needed.
2183 Otherwise, if both operands have signed integer types or both have unsigned
2184 integer types, the operand with the type of lesser integer conversion rank is
2185 converted to the type of the operand with greater rank.
2186 Otherwise, if the operand that has unsigned integer type has rank greater or
2187 equal to the rank of the type of the other operand, then the operand with
2188 signed integer type is converted to the type of the operand with unsigned
2190 Otherwise, if the type of the operand with signed integer type can represent
2191 all of the values of the type of the operand with unsigned integer type, then
2192 the operand with unsigned integer type is converted to the type of the
2193 operand with signed integer type.
2194 Otherwise, both operands are converted to the unsigned integer type
2195 corresponding to the type of the operand with signed integer type.
2196 2 The values of floating operands and of the results of floating expressions may be
2197 represented in greater precision and range than that required by the type; the types are not
2203 51) For example, addition of a double _Complex and a float entails just the conversion of the
2204 float operand to double (and yields a double _Complex result).
2205 52) The cast and assignment operators are still required to perform their specified conversions as
2206 described in 6.3.1.4 and 6.3.1.5.
2210 6.3.2 Other operands
2211 6.3.2.1 Lvalues, arrays, and function designators
2212 1 An lvalue is an expression with an object type or an incomplete type other than void;53)
2213 if an lvalue does not designate an object when it is evaluated, the behavior is undefined.
2214 When an object is said to have a particular type, the type is specified by the lvalue used to
2215 designate the object. A modifiable lvalue is an lvalue that does not have array type, does
2216 not have an incomplete type, does not have a const-qualified type, and if it is a structure
2217 or union, does not have any member (including, recursively, any member or element of
2218 all contained aggregates or unions) with a const-qualified type.
2219 2 Except when it is the operand of the sizeof operator, the unary & operator, the ++
2220 operator, the -- operator, or the left operand of the . operator or an assignment operator,
2221 an lvalue that does not have array type is converted to the value stored in the designated
2222 object (and is no longer an lvalue). If the lvalue has qualified type, the value has the
2223 unqualified version of the type of the lvalue; otherwise, the value has the type of the
2224 lvalue. If the lvalue has an incomplete type and does not have array type, the behavior is
2226 3 Except when it is the operand of the sizeof operator or the unary & operator, or is a
2227 string literal used to initialize an array, an expression that has type ''array of type'' is
2228 converted to an expression with type ''pointer to type'' that points to the initial element of
2229 the array object and is not an lvalue. If the array object has register storage class, the
2230 behavior is undefined.
2231 4 A function designator is an expression that has function type. Except when it is the
2232 operand of the sizeof operator54) or the unary & operator, a function designator with
2233 type ''function returning type'' is converted to an expression that has type ''pointer to
2234 function returning type''.
2235 Forward references: address and indirection operators (6.5.3.2), assignment operators
2236 (6.5.16), common definitions <stddef.h> (7.17), initialization (6.7.8), postfix
2237 increment and decrement operators (6.5.2.4), prefix increment and decrement operators
2238 (6.5.3.1), the sizeof operator (6.5.3.4), structure and union members (6.5.2.3).
2241 53) The name ''lvalue'' comes originally from the assignment expression E1 = E2, in which the left
2242 operand E1 is required to be a (modifiable) lvalue. It is perhaps better considered as representing an
2243 object ''locator value''. What is sometimes called ''rvalue'' is in this International Standard described
2244 as the ''value of an expression''.
2245 An obvious example of an lvalue is an identifier of an object. As a further example, if E is a unary
2246 expression that is a pointer to an object, *E is an lvalue that designates the object to which E points.
2247 54) Because this conversion does not occur, the operand of the sizeof operator remains a function
2248 designator and violates the constraint in 6.5.3.4.
2253 1 The (nonexistent) value of a void expression (an expression that has type void) shall not
2254 be used in any way, and implicit or explicit conversions (except to void) shall not be
2255 applied to such an expression. If an expression of any other type is evaluated as a void
2256 expression, its value or designator is discarded. (A void expression is evaluated for its
2259 1 A pointer to void may be converted to or from a pointer to any incomplete or object
2260 type. A pointer to any incomplete or object type may be converted to a pointer to void
2261 and back again; the result shall compare equal to the original pointer.
2262 2 For any qualifier q, a pointer to a non-q-qualified type may be converted to a pointer to
2263 the q-qualified version of the type; the values stored in the original and converted pointers
2264 shall compare equal.
2265 3 An integer constant expression with the value 0, or such an expression cast to type
2266 void *, is called a null pointer constant.55) If a null pointer constant is converted to a
2267 pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal
2268 to a pointer to any object or function.
2269 4 Conversion of a null pointer to another pointer type yields a null pointer of that type.
2270 Any two null pointers shall compare equal.
2271 5 An integer may be converted to any pointer type. Except as previously specified, the
2272 result is implementation-defined, might not be correctly aligned, might not point to an
2273 entity of the referenced type, and might be a trap representation.56)
2274 6 Any pointer type may be converted to an integer type. Except as previously specified, the
2275 result is implementation-defined. If the result cannot be represented in the integer type,
2276 the behavior is undefined. The result need not be in the range of values of any integer
2278 7 A pointer to an object or incomplete type may be converted to a pointer to a different
2279 object or incomplete type. If the resulting pointer is not correctly aligned57) for the
2280 pointed-to type, the behavior is undefined. Otherwise, when converted back again, the
2281 result shall compare equal to the original pointer. When a pointer to an object is
2284 55) The macro NULL is defined in <stddef.h> (and other headers) as a null pointer constant; see 7.17.
2285 56) The mapping functions for converting a pointer to an integer or an integer to a pointer are intended to
2286 be consistent with the addressing structure of the execution environment.
2287 57) In general, the concept ''correctly aligned'' is transitive: if a pointer to type A is correctly aligned for a
2288 pointer to type B, which in turn is correctly aligned for a pointer to type C, then a pointer to type A is
2289 correctly aligned for a pointer to type C.
2293 converted to a pointer to a character type, the result points to the lowest addressed byte of
2294 the object. Successive increments of the result, up to the size of the object, yield pointers
2295 to the remaining bytes of the object.
2296 8 A pointer to a function of one type may be converted to a pointer to a function of another
2297 type and back again; the result shall compare equal to the original pointer. If a converted
2298 pointer is used to call a function whose type is not compatible with the pointed-to type,
2299 the behavior is undefined.
2300 Forward references: cast operators (6.5.4), equality operators (6.5.9), integer types
2301 capable of holding object pointers (7.18.1.4), simple assignment (6.5.16.1).
2308 6.4 Lexical elements
2316 preprocessing-token:
2323 each non-white-space character that cannot be one of the above
2325 2 Each preprocessing token that is converted to a token shall have the lexical form of a
2326 keyword, an identifier, a constant, a string literal, or a punctuator.
2328 3 A token is the minimal lexical element of the language in translation phases 7 and 8. The
2329 categories of tokens are: keywords, identifiers, constants, string literals, and punctuators.
2330 A preprocessing token is the minimal lexical element of the language in translation
2331 phases 3 through 6. The categories of preprocessing tokens are: header names,
2332 identifiers, preprocessing numbers, character constants, string literals, punctuators, and
2333 single non-white-space characters that do not lexically match the other preprocessing
2334 token categories.58) If a ' or a " character matches the last category, the behavior is
2335 undefined. Preprocessing tokens can be separated by white space; this consists of
2336 comments (described later), or white-space characters (space, horizontal tab, new-line,
2337 vertical tab, and form-feed), or both. As described in 6.10, in certain circumstances
2338 during translation phase 4, white space (or the absence thereof) serves as more than
2339 preprocessing token separation. White space may appear within a preprocessing token
2340 only as part of a header name or between the quotation characters in a character constant
2345 58) An additional category, placemarkers, is used internally in translation phase 4 (see 6.10.3.3); it cannot
2346 occur in source files.
2350 4 If the input stream has been parsed into preprocessing tokens up to a given character, the
2351 next preprocessing token is the longest sequence of characters that could constitute a
2352 preprocessing token. There is one exception to this rule: header name preprocessing
2353 tokens are recognized only within #include preprocessing directives and in
2354 implementation-defined locations within #pragma directives. In such contexts, a
2355 sequence of characters that could be either a header name or a string literal is recognized
2357 5 EXAMPLE 1 The program fragment 1Ex is parsed as a preprocessing number token (one that is not a
2358 valid floating or integer constant token), even though a parse as the pair of preprocessing tokens 1 and Ex
2359 might produce a valid expression (for example, if Ex were a macro defined as +1). Similarly, the program
2360 fragment 1E1 is parsed as a preprocessing number (one that is a valid floating constant token), whether or
2361 not E is a macro name.
2363 6 EXAMPLE 2 The program fragment x+++++y is parsed as x ++ ++ + y, which violates a constraint on
2364 increment operators, even though the parse x ++ + ++ y might yield a correct expression.
2366 Forward references: character constants (6.4.4.4), comments (6.4.9), expressions (6.5),
2367 floating constants (6.4.4.2), header names (6.4.7), macro replacement (6.10.3), postfix
2368 increment and decrement operators (6.5.2.4), prefix increment and decrement operators
2369 (6.5.3.1), preprocessing directives (6.10), preprocessing numbers (6.4.8), string literals
2374 auto enum restrict unsigned
2375 break extern return void
2376 case float short volatile
2377 char for signed while
2378 const goto sizeof _Bool
2379 continue if static _Complex
2380 default inline struct _Imaginary
2385 2 The above tokens (case sensitive) are reserved (in translation phases 7 and 8) for use as
2386 keywords, and shall not be used otherwise. The keyword _Imaginary is reserved for
2387 specifying imaginary types.59)
2391 59) One possible specification for imaginary types appears in annex G.
2400 identifier identifier-nondigit
2402 identifier-nondigit:
2404 universal-character-name
2405 other implementation-defined characters
2407 _ a b c d e f g h i j k l m
2408 n o p q r s t u v w x y z
2409 A B C D E F G H I J K L M
2410 N O P Q R S T U V W X Y Z
2414 2 An identifier is a sequence of nondigit characters (including the underscore _, the
2415 lowercase and uppercase Latin letters, and other characters) and digits, which designates
2416 one or more entities as described in 6.2.1. Lowercase and uppercase letters are distinct.
2417 There is no specific limit on the maximum length of an identifier.
2418 3 Each universal character name in an identifier shall designate a character whose encoding
2419 in ISO/IEC 10646 falls into one of the ranges specified in annex D.60) The initial
2420 character shall not be a universal character name designating a digit. An implementation
2421 may allow multibyte characters that are not part of the basic source character set to
2422 appear in identifiers; which characters and their correspondence to universal character
2423 names is implementation-defined.
2424 4 When preprocessing tokens are converted to tokens during translation phase 7, if a
2425 preprocessing token could be converted to either a keyword or an identifier, it is converted
2429 60) On systems in which linkers cannot accept extended characters, an encoding of the universal character
2430 name may be used in forming valid external identifiers. For example, some otherwise unused
2431 character or sequence of characters may be used to encode the \u in a universal character name.
2432 Extended characters may produce a long external identifier.
2436 Implementation limits
2437 5 As discussed in 5.2.4.1, an implementation may limit the number of significant initial
2438 characters in an identifier; the limit for an external name (an identifier that has external
2439 linkage) may be more restrictive than that for an internal name (a macro name or an
2440 identifier that does not have external linkage). The number of significant characters in an
2441 identifier is implementation-defined.
2442 6 Any identifiers that differ in a significant character are different identifiers. If two
2443 identifiers differ only in nonsignificant characters, the behavior is undefined.
2444 Forward references: universal character names (6.4.3), macro replacement (6.10.3).
2445 6.4.2.2 Predefined identifiers
2447 1 The identifier __func__ shall be implicitly declared by the translator as if,
2448 immediately following the opening brace of each function definition, the declaration
2449 static const char __func__[] = "function-name";
2450 appeared, where function-name is the name of the lexically-enclosing function.61)
2451 2 This name is encoded as if the implicit declaration had been written in the source
2452 character set and then translated into the execution character set as indicated in translation
2454 3 EXAMPLE Consider the code fragment:
2458 printf("%s\n", __func__);
2461 Each time the function is called, it will print to the standard output stream:
2464 Forward references: function definitions (6.9.1).
2469 61) Since the name __func__ is reserved for any use by the implementation (7.1.3), if any other
2470 identifier is explicitly declared using the name __func__, the behavior is undefined.
2474 6.4.3 Universal character names
2476 1 universal-character-name:
2478 \U hex-quad hex-quad
2480 hexadecimal-digit hexadecimal-digit
2481 hexadecimal-digit hexadecimal-digit
2483 2 A universal character name shall not specify a character whose short identifier is less than
2484 00A0 other than 0024 ($), 0040 (@), or 0060 ('), nor one in the range D800 through
2487 3 Universal character names may be used in identifiers, character constants, and string
2488 literals to designate characters that are not in the basic character set.
2490 4 The universal character name \Unnnnnnnn designates the character whose eight-digit
2491 short identifier (as specified by ISO/IEC 10646) is nnnnnnnn.63) Similarly, the universal
2492 character name \unnnn designates the character whose four-digit short identifier is nnnn
2493 (and whose eight-digit short identifier is 0000nnnn).
2498 62) The disallowed characters are the characters in the basic character set and the code positions reserved
2499 by ISO/IEC 10646 for control characters, the character DELETE, and the S-zone (reserved for use by
2501 63) Short identifiers for characters were first specified in ISO/IEC 10646-1/AMD9:1997.
2510 enumeration-constant
2513 2 Each constant shall have a type and the value of a constant shall be in the range of
2514 representable values for its type.
2516 3 Each constant has a type, determined by its form and value, as detailed later.
2517 6.4.4.1 Integer constants
2520 decimal-constant integer-suffixopt
2521 octal-constant integer-suffixopt
2522 hexadecimal-constant integer-suffixopt
2525 decimal-constant digit
2528 octal-constant octal-digit
2529 hexadecimal-constant:
2530 hexadecimal-prefix hexadecimal-digit
2531 hexadecimal-constant hexadecimal-digit
2532 hexadecimal-prefix: one of
2534 nonzero-digit: one of
2544 hexadecimal-digit: one of
2549 unsigned-suffix long-suffixopt
2550 unsigned-suffix long-long-suffix
2551 long-suffix unsigned-suffixopt
2552 long-long-suffix unsigned-suffixopt
2553 unsigned-suffix: one of
2557 long-long-suffix: one of
2560 2 An integer constant begins with a digit, but has no period or exponent part. It may have a
2561 prefix that specifies its base and a suffix that specifies its type.
2562 3 A decimal constant begins with a nonzero digit and consists of a sequence of decimal
2563 digits. An octal constant consists of the prefix 0 optionally followed by a sequence of the
2564 digits 0 through 7 only. A hexadecimal constant consists of the prefix 0x or 0X followed
2565 by a sequence of the decimal digits and the letters a (or A) through f (or F) with values
2566 10 through 15 respectively.
2568 4 The value of a decimal constant is computed base 10; that of an octal constant, base 8;
2569 that of a hexadecimal constant, base 16. The lexically first digit is the most significant.
2570 5 The type of an integer constant is the first of the corresponding list in which its value can
2578 Octal or Hexadecimal
2579 Suffix Decimal Constant Constant
2582 long int unsigned int
2583 long long int long int
2586 unsigned long long int
2588 u or U unsigned int unsigned int
2589 unsigned long int unsigned long int
2590 unsigned long long int unsigned long long int
2592 l or L long int long int
2593 long long int unsigned long int
2595 unsigned long long int
2597 Both u or U unsigned long int unsigned long int
2598 and l or L unsigned long long int unsigned long long int
2600 ll or LL long long int long long int
2601 unsigned long long int
2603 Both u or U unsigned long long int unsigned long long int
2605 6 If an integer constant cannot be represented by any type in its list, it may have an
2606 extended integer type, if the extended integer type can represent its value. If all of the
2607 types in the list for the constant are signed, the extended integer type shall be signed. If
2608 all of the types in the list for the constant are unsigned, the extended integer type shall be
2609 unsigned. If the list contains both signed and unsigned types, the extended integer type
2610 may be signed or unsigned. If an integer constant cannot be represented by any type in
2611 its list and has no extended integer type, then the integer constant has no type.
2618 6.4.4.2 Floating constants
2620 1 floating-constant:
2621 decimal-floating-constant
2622 hexadecimal-floating-constant
2623 decimal-floating-constant:
2624 fractional-constant exponent-partopt floating-suffixopt
2625 digit-sequence exponent-part floating-suffixopt
2626 hexadecimal-floating-constant:
2627 hexadecimal-prefix hexadecimal-fractional-constant
2628 binary-exponent-part floating-suffixopt
2629 hexadecimal-prefix hexadecimal-digit-sequence
2630 binary-exponent-part floating-suffixopt
2631 fractional-constant:
2632 digit-sequenceopt . digit-sequence
2635 e signopt digit-sequence
2636 E signopt digit-sequence
2641 digit-sequence digit
2642 hexadecimal-fractional-constant:
2643 hexadecimal-digit-sequenceopt .
2644 hexadecimal-digit-sequence
2645 hexadecimal-digit-sequence .
2646 binary-exponent-part:
2647 p signopt digit-sequence
2648 P signopt digit-sequence
2649 hexadecimal-digit-sequence:
2651 hexadecimal-digit-sequence hexadecimal-digit
2652 floating-suffix: one of
2658 2 A floating constant has a significand part that may be followed by an exponent part and a
2659 suffix that specifies its type. The components of the significand part may include a digit
2660 sequence representing the whole-number part, followed by a period (.), followed by a
2661 digit sequence representing the fraction part. The components of the exponent part are an
2662 e, E, p, or P followed by an exponent consisting of an optionally signed digit sequence.
2663 Either the whole-number part or the fraction part has to be present; for decimal floating
2664 constants, either the period or the exponent part has to be present.
2666 3 The significand part is interpreted as a (decimal or hexadecimal) rational number; the
2667 digit sequence in the exponent part is interpreted as a decimal integer. For decimal
2668 floating constants, the exponent indicates the power of 10 by which the significand part is
2669 to be scaled. For hexadecimal floating constants, the exponent indicates the power of 2
2670 by which the significand part is to be scaled. For decimal floating constants, and also for
2671 hexadecimal floating constants when FLT_RADIX is not a power of 2, the result is either
2672 the nearest representable value, or the larger or smaller representable value immediately
2673 adjacent to the nearest representable value, chosen in an implementation-defined manner.
2674 For hexadecimal floating constants when FLT_RADIX is a power of 2, the result is
2676 4 An unsuffixed floating constant has type double. If suffixed by the letter f or F, it has
2677 type float. If suffixed by the letter l or L, it has type long double.
2678 5 Floating constants are converted to internal format as if at translation-time. The
2679 conversion of a floating constant shall not raise an exceptional condition or a floating-
2680 point exception at execution time.
2681 Recommended practice
2682 6 The implementation should produce a diagnostic message if a hexadecimal constant
2683 cannot be represented exactly in its evaluation format; the implementation should then
2684 proceed with the translation of the program.
2685 7 The translation-time conversion of floating constants should match the execution-time
2686 conversion of character strings by library functions, such as strtod, given matching
2687 inputs suitable for both conversions, the same result format, and default execution-time
2693 64) The specification for the library functions recommends more accurate conversion than required for
2694 floating constants (see 7.20.1.3).
2698 6.4.4.3 Enumeration constants
2700 1 enumeration-constant:
2703 2 An identifier declared as an enumeration constant has type int.
2704 Forward references: enumeration specifiers (6.7.2.2).
2705 6.4.4.4 Character constants
2707 1 character-constant:
2709 L' c-char-sequence '
2712 c-char-sequence c-char
2714 any member of the source character set except
2715 the single-quote ', backslash \, or new-line character
2718 simple-escape-sequence
2719 octal-escape-sequence
2720 hexadecimal-escape-sequence
2721 universal-character-name
2722 simple-escape-sequence: one of
2724 \a \b \f \n \r \t \v
2725 octal-escape-sequence:
2727 \ octal-digit octal-digit
2728 \ octal-digit octal-digit octal-digit
2729 hexadecimal-escape-sequence:
2730 \x hexadecimal-digit
2731 hexadecimal-escape-sequence hexadecimal-digit
2738 2 An integer character constant is a sequence of one or more multibyte characters enclosed
2739 in single-quotes, as in 'x'. A wide character constant is the same, except prefixed by the
2740 letter L. With a few exceptions detailed later, the elements of the sequence are any
2741 members of the source character set; they are mapped in an implementation-defined
2742 manner to members of the execution character set.
2743 3 The single-quote ', the double-quote ", the question-mark ?, the backslash \, and
2744 arbitrary integer values are representable according to the following table of escape
2750 octal character \octal digits
2751 hexadecimal character \x hexadecimal digits
2752 4 The double-quote " and question-mark ? are representable either by themselves or by the
2753 escape sequences \" and \?, respectively, but the single-quote ' and the backslash \
2754 shall be represented, respectively, by the escape sequences \' and \\.
2755 5 The octal digits that follow the backslash in an octal escape sequence are taken to be part
2756 of the construction of a single character for an integer character constant or of a single
2757 wide character for a wide character constant. The numerical value of the octal integer so
2758 formed specifies the value of the desired character or wide character.
2759 6 The hexadecimal digits that follow the backslash and the letter x in a hexadecimal escape
2760 sequence are taken to be part of the construction of a single character for an integer
2761 character constant or of a single wide character for a wide character constant. The
2762 numerical value of the hexadecimal integer so formed specifies the value of the desired
2763 character or wide character.
2764 7 Each octal or hexadecimal escape sequence is the longest sequence of characters that can
2765 constitute the escape sequence.
2766 8 In addition, characters not in the basic character set are representable by universal
2767 character names and certain nongraphic characters are representable by escape sequences
2768 consisting of the backslash \ followed by a lowercase letter: \a, \b, \f, \n, \r, \t,
2774 65) The semantics of these characters were discussed in 5.2.2. If any other character follows a backslash,
2775 the result is not a token and a diagnostic is required. See ''future language directions'' (6.11.4).
2780 9 The value of an octal or hexadecimal escape sequence shall be in the range of
2781 representable values for the type unsigned char for an integer character constant, or
2782 the unsigned type corresponding to wchar_t for a wide character constant.
2784 10 An integer character constant has type int. The value of an integer character constant
2785 containing a single character that maps to a single-byte execution character is the
2786 numerical value of the representation of the mapped character interpreted as an integer.
2787 The value of an integer character constant containing more than one character (e.g.,
2788 'ab'), or containing a character or escape sequence that does not map to a single-byte
2789 execution character, is implementation-defined. If an integer character constant contains
2790 a single character or escape sequence, its value is the one that results when an object with
2791 type char whose value is that of the single character or escape sequence is converted to
2793 11 A wide character constant has type wchar_t, an integer type defined in the
2794 <stddef.h> header. The value of a wide character constant containing a single
2795 multibyte character that maps to a member of the extended execution character set is the
2796 wide character corresponding to that multibyte character, as defined by the mbtowc
2797 function, with an implementation-defined current locale. The value of a wide character
2798 constant containing more than one multibyte character, or containing a multibyte
2799 character or escape sequence not represented in the extended execution character set, is
2800 implementation-defined.
2801 12 EXAMPLE 1 The construction '\0' is commonly used to represent the null character.
2803 13 EXAMPLE 2 Consider implementations that use two's-complement representation for integers and eight
2804 bits for objects that have type char. In an implementation in which type char has the same range of
2805 values as signed char, the integer character constant '\xFF' has the value -1; if type char has the
2806 same range of values as unsigned char, the character constant '\xFF' has the value +255.
2808 14 EXAMPLE 3 Even if eight bits are used for objects that have type char, the construction '\x123'
2809 specifies an integer character constant containing only one character, since a hexadecimal escape sequence
2810 is terminated only by a non-hexadecimal character. To specify an integer character constant containing the
2811 two characters whose values are '\x12' and '3', the construction '\0223' may be used, since an octal
2812 escape sequence is terminated after three octal digits. (The value of this two-character integer character
2813 constant is implementation-defined.)
2815 15 EXAMPLE 4 Even if 12 or more bits are used for objects that have type wchar_t, the construction
2816 L'\1234' specifies the implementation-defined value that results from the combination of the values
2819 Forward references: common definitions <stddef.h> (7.17), the mbtowc function
2827 6.4.5 String literals
2830 " s-char-sequenceopt "
2831 L" s-char-sequenceopt "
2834 s-char-sequence s-char
2836 any member of the source character set except
2837 the double-quote ", backslash \, or new-line character
2840 2 A character string literal is a sequence of zero or more multibyte characters enclosed in
2841 double-quotes, as in "xyz". A wide string literal is the same, except prefixed by the
2843 3 The same considerations apply to each element of the sequence in a character string
2844 literal or a wide string literal as if it were in an integer character constant or a wide
2845 character constant, except that the single-quote ' is representable either by itself or by the
2846 escape sequence \', but the double-quote " shall be represented by the escape sequence
2849 4 In translation phase 6, the multibyte character sequences specified by any sequence of
2850 adjacent character and wide string literal tokens are concatenated into a single multibyte
2851 character sequence. If any of the tokens are wide string literal tokens, the resulting
2852 multibyte character sequence is treated as a wide string literal; otherwise, it is treated as a
2853 character string literal.
2854 5 In translation phase 7, a byte or code of value zero is appended to each multibyte
2855 character sequence that results from a string literal or literals.66) The multibyte character
2856 sequence is then used to initialize an array of static storage duration and length just
2857 sufficient to contain the sequence. For character string literals, the array elements have
2858 type char, and are initialized with the individual bytes of the multibyte character
2859 sequence; for wide string literals, the array elements have type wchar_t, and are
2860 initialized with the sequence of wide characters corresponding to the multibyte character
2862 66) A character string literal need not be a string (see 7.1.1), because a null character may be embedded in
2863 it by a \0 escape sequence.
2867 sequence, as defined by the mbstowcs function with an implementation-defined current
2868 locale. The value of a string literal containing a multibyte character or escape sequence
2869 not represented in the execution character set is implementation-defined.
2870 6 It is unspecified whether these arrays are distinct provided their elements have the
2871 appropriate values. If the program attempts to modify such an array, the behavior is
2873 7 EXAMPLE This pair of adjacent character string literals
2875 produces a single character string literal containing the two characters whose values are '\x12' and '3',
2876 because escape sequences are converted into single members of the execution character set just prior to
2877 adjacent string literal concatenation.
2879 Forward references: common definitions <stddef.h> (7.17), the mbstowcs
2880 function (7.20.8.1).
2883 1 punctuator: one of
2886 / % << >> < > <= >= == != ^ | && ||
2888 = *= /= %= += -= <<= >>= &= ^= |=
2892 2 A punctuator is a symbol that has independent syntactic and semantic significance.
2893 Depending on context, it may specify an operation to be performed (which in turn may
2894 yield a value or a function designator, produce a side effect, or some combination thereof)
2895 in which case it is known as an operator (other forms of operator also exist in some
2896 contexts). An operand is an entity on which an operator acts.
2903 3 In all aspects of the language, the six tokens67)
2905 behave, respectively, the same as the six tokens
2907 except for their spelling.68)
2908 Forward references: expressions (6.5), declarations (6.7), preprocessing directives
2909 (6.10), statements (6.8).
2917 h-char-sequence h-char
2919 any member of the source character set except
2920 the new-line character and >
2923 q-char-sequence q-char
2925 any member of the source character set except
2926 the new-line character and "
2928 2 The sequences in both forms of header names are mapped in an implementation-defined
2929 manner to headers or external source file names as specified in 6.10.2.
2930 3 If the characters ', \, ", //, or /* occur in the sequence between the < and > delimiters,
2931 the behavior is undefined. Similarly, if the characters ', \, //, or /* occur in the
2936 67) These tokens are sometimes called ''digraphs''.
2937 68) Thus [ and <: behave differently when ''stringized'' (see 6.10.3.2), but can otherwise be freely
2942 sequence between the " delimiters, the behavior is undefined.69) Header name
2943 preprocessing tokens are recognized only within #include preprocessing directives and
2944 in implementation-defined locations within #pragma directives.70)
2945 4 EXAMPLE The following sequence of characters:
2948 #define const.member@$
2949 forms the following sequence of preprocessing tokens (with each individual preprocessing token delimited
2950 by a { on the left and a } on the right).
2951 {0x3}{<}{1}{/}{a}{.}{h}{>}{1e2}
2952 {#}{include} {<1/a.h>}
2953 {#}{define} {const}{.}{member}{@}{$}
2955 Forward references: source file inclusion (6.10.2).
2956 6.4.8 Preprocessing numbers
2962 pp-number identifier-nondigit
2969 2 A preprocessing number begins with a digit optionally preceded by a period (.) and may
2970 be followed by valid identifier characters and the character sequences e+, e-, E+, E-,
2972 3 Preprocessing number tokens lexically include all floating and integer constant tokens.
2974 4 A preprocessing number does not have type or a value; it acquires both after a successful
2975 conversion (as part of translation phase 7) to a floating constant token or an integer
2979 69) Thus, sequences of characters that resemble escape sequences cause undefined behavior.
2980 70) For an example of a header name preprocessing token used in a #pragma directive, see 6.10.9.
2985 1 Except within a character constant, a string literal, or a comment, the characters /*
2986 introduce a comment. The contents of such a comment are examined only to identify
2987 multibyte characters and to find the characters */ that terminate it.71)
2988 2 Except within a character constant, a string literal, or a comment, the characters //
2989 introduce a comment that includes all multibyte characters up to, but not including, the
2990 next new-line character. The contents of such a comment are examined only to identify
2991 multibyte characters and to find the terminating new-line character.
2993 "a//b" // four-character string literal
2994 #include "//e" // undefined behavior
2995 // */ // comment, not syntax error
2996 f = g/**//h; // equivalent to f = g / h;
2998 i(); // part of a two-line comment
3000 / j(); // part of a two-line comment
3001 #define glue(x,y) x##y
3002 glue(/,/) k(); // syntax error, not comment
3003 /*//*/ l(); // equivalent to l();
3005 + p; // equivalent to m = n + p;
3010 71) Thus, /* ... */ comments do not nest.
3015 1 An expression is a sequence of operators and operands that specifies computation of a
3016 value, or that designates an object or a function, or that generates side effects, or that
3017 performs a combination thereof.
3018 2 Between the previous and next sequence point an object shall have its stored value
3019 modified at most once by the evaluation of an expression.72) Furthermore, the prior value
3020 shall be read only to determine the value to be stored.73)
3021 3 The grouping of operators and operands is indicated by the syntax.74) Except as specified
3022 later (for the function-call (), &&, ||, ?:, and comma operators), the order of evaluation
3023 of subexpressions and the order in which side effects take place are both unspecified.
3024 4 Some operators (the unary operator ~, and the binary operators <<, >>, &, ^, and |,
3025 collectively described as bitwise operators) are required to have operands that have
3026 integer type. These operators yield values that depend on the internal representations of
3027 integers, and have implementation-defined and undefined aspects for signed types.
3028 5 If an exceptional condition occurs during the evaluation of an expression (that is, if the
3029 result is not mathematically defined or not in the range of representable values for its
3030 type), the behavior is undefined.
3031 6 The effective type of an object for an access to its stored value is the declared type of the
3032 object, if any.75) If a value is stored into an object having no declared type through an
3033 lvalue having a type that is not a character type, then the type of the lvalue becomes the
3036 72) A floating-point status flag is not an object and can be set more than once within an expression.
3037 73) This paragraph renders undefined statement expressions such as
3044 74) The syntax specifies the precedence of operators in the evaluation of an expression, which is the same
3045 as the order of the major subclauses of this subclause, highest precedence first. Thus, for example, the
3046 expressions allowed as the operands of the binary + operator (6.5.6) are those expressions defined in
3047 6.5.1 through 6.5.6. The exceptions are cast expressions (6.5.4) as operands of unary operators
3048 (6.5.3), and an operand contained between any of the following pairs of operators: grouping
3049 parentheses () (6.5.1), subscripting brackets [] (6.5.2.1), function-call parentheses () (6.5.2.2), and
3050 the conditional operator ?: (6.5.15).
3051 Within each major subclause, the operators have the same precedence. Left- or right-associativity is
3052 indicated in each subclause by the syntax for the expressions discussed therein.
3053 75) Allocated objects have no declared type.
3057 effective type of the object for that access and for subsequent accesses that do not modify
3058 the stored value. If a value is copied into an object having no declared type using
3059 memcpy or memmove, or is copied as an array of character type, then the effective type
3060 of the modified object for that access and for subsequent accesses that do not modify the
3061 value is the effective type of the object from which the value is copied, if it has one. For
3062 all other accesses to an object having no declared type, the effective type of the object is
3063 simply the type of the lvalue used for the access.
3064 7 An object shall have its stored value accessed only by an lvalue expression that has one of
3065 the following types:76)
3066 -- a type compatible with the effective type of the object,
3067 -- a qualified version of a type compatible with the effective type of the object,
3068 -- a type that is the signed or unsigned type corresponding to the effective type of the
3070 -- a type that is the signed or unsigned type corresponding to a qualified version of the
3071 effective type of the object,
3072 -- an aggregate or union type that includes one of the aforementioned types among its
3073 members (including, recursively, a member of a subaggregate or contained union), or
3074 -- a character type.
3075 8 A floating expression may be contracted, that is, evaluated as though it were an atomic
3076 operation, thereby omitting rounding errors implied by the source code and the
3077 expression evaluation method.77) The FP_CONTRACT pragma in <math.h> provides a
3078 way to disallow contracted expressions. Otherwise, whether and how expressions are
3079 contracted is implementation-defined.78)
3080 Forward references: the FP_CONTRACT pragma (7.12.2), copying functions (7.21.2).
3085 76) The intent of this list is to specify those circumstances in which an object may or may not be aliased.
3086 77) A contracted expression might also omit the raising of floating-point exceptions.
3087 78) This license is specifically intended to allow implementations to exploit fast machine instructions that
3088 combine multiple C operators. As contractions potentially undermine predictability, and can even
3089 decrease accuracy for containing expressions, their use needs to be well-defined and clearly
3094 6.5.1 Primary expressions
3096 1 primary-expression:
3102 2 An identifier is a primary expression, provided it has been declared as designating an
3103 object (in which case it is an lvalue) or a function (in which case it is a function
3105 3 A constant is a primary expression. Its type depends on its form and value, as detailed in
3107 4 A string literal is a primary expression. It is an lvalue with type as detailed in 6.4.5.
3108 5 A parenthesized expression is a primary expression. Its type and value are identical to
3109 those of the unparenthesized expression. It is an lvalue, a function designator, or a void
3110 expression if the unparenthesized expression is, respectively, an lvalue, a function
3111 designator, or a void expression.
3112 Forward references: declarations (6.7).
3113 6.5.2 Postfix operators
3115 1 postfix-expression:
3117 postfix-expression [ expression ]
3118 postfix-expression ( argument-expression-listopt )
3119 postfix-expression . identifier
3120 postfix-expression -> identifier
3121 postfix-expression ++
3122 postfix-expression --
3123 ( type-name ) { initializer-list }
3124 ( type-name ) { initializer-list , }
3129 79) Thus, an undeclared identifier is a violation of the syntax.
3133 argument-expression-list:
3134 assignment-expression
3135 argument-expression-list , assignment-expression
3136 6.5.2.1 Array subscripting
3138 1 One of the expressions shall have type ''pointer to object type'', the other expression shall
3139 have integer type, and the result has type ''type''.
3141 2 A postfix expression followed by an expression in square brackets [] is a subscripted
3142 designation of an element of an array object. The definition of the subscript operator []
3143 is that E1[E2] is identical to (*((E1)+(E2))). Because of the conversion rules that
3144 apply to the binary + operator, if E1 is an array object (equivalently, a pointer to the
3145 initial element of an array object) and E2 is an integer, E1[E2] designates the E2-th
3146 element of E1 (counting from zero).
3147 3 Successive subscript operators designate an element of a multidimensional array object.
3148 If E is an n-dimensional array (n >= 2) with dimensions i x j x . . . x k, then E (used as
3149 other than an lvalue) is converted to a pointer to an (n - 1)-dimensional array with
3150 dimensions j x . . . x k. If the unary * operator is applied to this pointer explicitly, or
3151 implicitly as a result of subscripting, the result is the pointed-to (n - 1)-dimensional array,
3152 which itself is converted into a pointer if used as other than an lvalue. It follows from this
3153 that arrays are stored in row-major order (last subscript varies fastest).
3154 4 EXAMPLE Consider the array object defined by the declaration
3156 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
3157 array of five ints. In the expression x[i], which is equivalent to (*((x)+(i))), x is first converted to
3158 a pointer to the initial array of five ints. Then i is adjusted according to the type of x, which conceptually
3159 entails multiplying i by the size of the object to which the pointer points, namely an array of five int
3160 objects. The results are added and indirection is applied to yield an array of five ints. When used in the
3161 expression x[i][j], that array is in turn converted to a pointer to the first of the ints, so x[i][j]
3164 Forward references: additive operators (6.5.6), address and indirection operators
3165 (6.5.3.2), array declarators (6.7.5.2).
3172 6.5.2.2 Function calls
3174 1 The expression that denotes the called function80) shall have type pointer to function
3175 returning void or returning an object type other than an array type.
3176 2 If the expression that denotes the called function has a type that includes a prototype, the
3177 number of arguments shall agree with the number of parameters. Each argument shall
3178 have a type such that its value may be assigned to an object with the unqualified version
3179 of the type of its corresponding parameter.
3181 3 A postfix expression followed by parentheses () containing a possibly empty, comma-
3182 separated list of expressions is a function call. The postfix expression denotes the called
3183 function. The list of expressions specifies the arguments to the function.
3184 4 An argument may be an expression of any object type. In preparing for the call to a
3185 function, the arguments are evaluated, and each parameter is assigned the value of the
3186 corresponding argument.81)
3187 5 If the expression that denotes the called function has type pointer to function returning an
3188 object type, the function call expression has the same type as that object type, and has the
3189 value determined as specified in 6.8.6.4. Otherwise, the function call has type void. If
3190 an attempt is made to modify the result of a function call or to access it after the next
3191 sequence point, the behavior is undefined.
3192 6 If the expression that denotes the called function has a type that does not include a
3193 prototype, the integer promotions are performed on each argument, and arguments that
3194 have type float are promoted to double. These are called the default argument
3195 promotions. If the number of arguments does not equal the number of parameters, the
3196 behavior is undefined. If the function is defined with a type that includes a prototype, and
3197 either the prototype ends with an ellipsis (, ...) or the types of the arguments after
3198 promotion are not compatible with the types of the parameters, the behavior is undefined.
3199 If the function is defined with a type that does not include a prototype, and the types of
3200 the arguments after promotion are not compatible with those of the parameters after
3201 promotion, the behavior is undefined, except for the following cases:
3206 80) Most often, this is the result of converting an identifier that is a function designator.
3207 81) A function may change the values of its parameters, but these changes cannot affect the values of the
3208 arguments. On the other hand, it is possible to pass a pointer to an object, and the function may
3209 change the value of the object pointed to. A parameter declared to have array or function type is
3210 adjusted to have a pointer type as described in 6.9.1.
3214 -- one promoted type is a signed integer type, the other promoted type is the
3215 corresponding unsigned integer type, and the value is representable in both types;
3216 -- both types are pointers to qualified or unqualified versions of a character type or
3218 7 If the expression that denotes the called function has a type that does include a prototype,
3219 the arguments are implicitly converted, as if by assignment, to the types of the
3220 corresponding parameters, taking the type of each parameter to be the unqualified version
3221 of its declared type. The ellipsis notation in a function prototype declarator causes
3222 argument type conversion to stop after the last declared parameter. The default argument
3223 promotions are performed on trailing arguments.
3224 8 No other conversions are performed implicitly; in particular, the number and types of
3225 arguments are not compared with those of the parameters in a function definition that
3226 does not include a function prototype declarator.
3227 9 If the function is defined with a type that is not compatible with the type (of the
3228 expression) pointed to by the expression that denotes the called function, the behavior is
3230 10 The order of evaluation of the function designator, the actual arguments, and
3231 subexpressions within the actual arguments is unspecified, but there is a sequence point
3232 before the actual call.
3233 11 Recursive function calls shall be permitted, both directly and indirectly through any chain
3235 12 EXAMPLE In the function call
3236 (*pf[f1()]) (f2(), f3() + f4())
3237 the functions f1, f2, f3, and f4 may be called in any order. All side effects have to be completed before
3238 the function pointed to by pf[f1()] is called.
3240 Forward references: function declarators (including prototypes) (6.7.5.3), function
3241 definitions (6.9.1), the return statement (6.8.6.4), simple assignment (6.5.16.1).
3242 6.5.2.3 Structure and union members
3244 1 The first operand of the . operator shall have a qualified or unqualified structure or union
3245 type, and the second operand shall name a member of that type.
3246 2 The first operand of the -> operator shall have type ''pointer to qualified or unqualified
3247 structure'' or ''pointer to qualified or unqualified union'', and the second operand shall
3248 name a member of the type pointed to.
3256 3 A postfix expression followed by the . operator and an identifier designates a member of
3257 a structure or union object. The value is that of the named member,82) and is an lvalue if
3258 the first expression is an lvalue. If the first expression has qualified type, the result has
3259 the so-qualified version of the type of the designated member.
3260 4 A postfix expression followed by the -> operator and an identifier designates a member
3261 of a structure or union object. The value is that of the named member of the object to
3262 which the first expression points, and is an lvalue.83) If the first expression is a pointer to
3263 a qualified type, the result has the so-qualified version of the type of the designated
3265 5 One special guarantee is made in order to simplify the use of unions: if a union contains
3266 several structures that share a common initial sequence (see below), and if the union
3267 object currently contains one of these structures, it is permitted to inspect the common
3268 initial part of any of them anywhere that a declaration of the complete type of the union is
3269 visible. Two structures share a common initial sequence if corresponding members have
3270 compatible types (and, for bit-fields, the same widths) for a sequence of one or more
3272 6 EXAMPLE 1 If f is a function returning a structure or union, and x is a member of that structure or
3273 union, f().x is a valid postfix expression but is not an lvalue.
3276 struct s { int i; const int ci; };
3279 volatile struct s vs;
3280 the various members have the types:
3286 vs.ci volatile const int
3291 82) If the member used to access the contents of a union object is not the same as the member last used to
3292 store a value in the object, the appropriate part of the object representation of the value is reinterpreted
3293 as an object representation in the new type as described in 6.2.6 (a process sometimes called "type
3294 punning"). This might be a trap representation.
3295 83) If &E is a valid pointer expression (where & is the ''address-of '' operator, which generates a pointer to
3296 its operand), the expression (&E)->MOS is the same as E.MOS.
3300 8 EXAMPLE 3 The following is a valid fragment:
3315 u.nf.doublenode = 3.14;
3317 if (u.n.alltypes == 1)
3318 if (sin(u.nf.doublenode) == 0.0)
3320 The following is not a valid fragment (because the union type is not visible within function f):
3321 struct t1 { int m; };
3322 struct t2 { int m; };
3323 int f(struct t1 *p1, struct t2 *p2)
3336 return f(&u.s1, &u.s2);
3339 Forward references: address and indirection operators (6.5.3.2), structure and union
3340 specifiers (6.7.2.1).
3347 6.5.2.4 Postfix increment and decrement operators
3349 1 The operand of the postfix increment or decrement operator shall have qualified or
3350 unqualified real or pointer type and shall be a modifiable lvalue.
3352 2 The result of the postfix ++ operator is the value of the operand. After the result is
3353 obtained, the value of the operand is incremented. (That is, the value 1 of the appropriate
3354 type is added to it.) See the discussions of additive operators and compound assignment
3355 for information on constraints, types, and conversions and the effects of operations on
3356 pointers. The side effect of updating the stored value of the operand shall occur between
3357 the previous and the next sequence point.
3358 3 The postfix -- operator is analogous to the postfix ++ operator, except that the value of
3359 the operand is decremented (that is, the value 1 of the appropriate type is subtracted from
3361 Forward references: additive operators (6.5.6), compound assignment (6.5.16.2).
3362 6.5.2.5 Compound literals
3364 1 The type name shall specify an object type or an array of unknown size, but not a variable
3366 2 No initializer shall attempt to provide a value for an object not contained within the entire
3367 unnamed object specified by the compound literal.
3368 3 If the compound literal occurs outside the body of a function, the initializer list shall
3369 consist of constant expressions.
3371 4 A postfix expression that consists of a parenthesized type name followed by a brace-
3372 enclosed list of initializers is a compound literal. It provides an unnamed object whose
3373 value is given by the initializer list.84)
3374 5 If the type name specifies an array of unknown size, the size is determined by the
3375 initializer list as specified in 6.7.8, and the type of the compound literal is that of the
3376 completed array type. Otherwise (when the type name specifies an object type), the type
3377 of the compound literal is that specified by the type name. In either case, the result is an
3381 84) Note that this differs from a cast expression. For example, a cast specifies a conversion to scalar types
3382 or void only, and the result of a cast expression is not an lvalue.
3386 6 The value of the compound literal is that of an unnamed object initialized by the
3387 initializer list. If the compound literal occurs outside the body of a function, the object
3388 has static storage duration; otherwise, it has automatic storage duration associated with
3389 the enclosing block.
3390 7 All the semantic rules and constraints for initializer lists in 6.7.8 are applicable to
3391 compound literals.85)
3392 8 String literals, and compound literals with const-qualified types, need not designate
3393 distinct objects.86)
3394 9 EXAMPLE 1 The file scope definition
3395 int *p = (int []){2, 4};
3396 initializes p to point to the first element of an array of two ints, the first having the value two and the
3397 second, four. The expressions in this compound literal are required to be constant. The unnamed object
3398 has static storage duration.
3400 10 EXAMPLE 2 In contrast, in
3408 p is assigned the address of the first element of an array of two ints, the first having the value previously
3409 pointed to by p and the second, zero. The expressions in this compound literal need not be constant. The
3410 unnamed object has automatic storage duration.
3412 11 EXAMPLE 3 Initializers with designations can be combined with compound literals. Structure objects
3413 created using compound literals can be passed to functions without depending on member order:
3414 drawline((struct point){.x=1, .y=1},
3415 (struct point){.x=3, .y=4});
3416 Or, if drawline instead expected pointers to struct point:
3417 drawline(&(struct point){.x=1, .y=1},
3418 &(struct point){.x=3, .y=4});
3420 12 EXAMPLE 4 A read-only compound literal can be specified through constructions like:
3421 (const float []){1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6}
3426 85) For example, subobjects without explicit initializers are initialized to zero.
3427 86) This allows implementations to share storage for string literals and constant compound literals with
3428 the same or overlapping representations.
3432 13 EXAMPLE 5 The following three expressions have different meanings:
3434 (char []){"/tmp/fileXXXXXX"}
3435 (const char []){"/tmp/fileXXXXXX"}
3436 The first always has static storage duration and has type array of char, but need not be modifiable; the last
3437 two have automatic storage duration when they occur within the body of a function, and the first of these
3440 14 EXAMPLE 6 Like string literals, const-qualified compound literals can be placed into read-only memory
3441 and can even be shared. For example,
3442 (const char []){"abc"} == "abc"
3443 might yield 1 if the literals' storage is shared.
3445 15 EXAMPLE 7 Since compound literals are unnamed, a single compound literal cannot specify a circularly
3446 linked object. For example, there is no way to write a self-referential compound literal that could be used
3447 as the function argument in place of the named object endless_zeros below:
3448 struct int_list { int car; struct int_list *cdr; };
3449 struct int_list endless_zeros = {0, &endless_zeros};
3450 eval(endless_zeros);
3452 16 EXAMPLE 8 Each compound literal creates only a single object in a given scope:
3453 struct s { int i; };
3456 struct s *p = 0, *q;
3459 q = p, p = &((struct s){ j++ });
3460 if (j < 2) goto again;
3461 return p == q && q->i == 1;
3463 The function f() always returns the value 1.
3464 17 Note that if an iteration statement were used instead of an explicit goto and a labeled statement, the
3465 lifetime of the unnamed object would be the body of the loop only, and on entry next time around p would
3466 have an indeterminate value, which would result in undefined behavior.
3468 Forward references: type names (6.7.6), initialization (6.7.8).
3475 6.5.3 Unary operators
3481 unary-operator cast-expression
3482 sizeof unary-expression
3483 sizeof ( type-name )
3484 unary-operator: one of
3486 6.5.3.1 Prefix increment and decrement operators
3488 1 The operand of the prefix increment or decrement operator shall have qualified or
3489 unqualified real or pointer type and shall be a modifiable lvalue.
3491 2 The value of the operand of the prefix ++ operator is incremented. The result is the new
3492 value of the operand after incrementation. The expression ++E is equivalent to (E+=1).
3493 See the discussions of additive operators and compound assignment for information on
3494 constraints, types, side effects, and conversions and the effects of operations on pointers.
3495 3 The prefix -- operator is analogous to the prefix ++ operator, except that the value of the
3496 operand is decremented.
3497 Forward references: additive operators (6.5.6), compound assignment (6.5.16.2).
3498 6.5.3.2 Address and indirection operators
3500 1 The operand of the unary & operator shall be either a function designator, the result of a
3501 [] or unary * operator, or an lvalue that designates an object that is not a bit-field and is
3502 not declared with the register storage-class specifier.
3503 2 The operand of the unary * operator shall have pointer type.
3505 3 The unary & operator yields the address of its operand. If the operand has type ''type'',
3506 the result has type ''pointer to type''. If the operand is the result of a unary * operator,
3507 neither that operator nor the & operator is evaluated and the result is as if both were
3508 omitted, except that the constraints on the operators still apply and the result is not an
3509 lvalue. Similarly, if the operand is the result of a [] operator, neither the & operator nor
3513 the unary * that is implied by the [] is evaluated and the result is as if the & operator
3514 were removed and the [] operator were changed to a + operator. Otherwise, the result is
3515 a pointer to the object or function designated by its operand.
3516 4 The unary * operator denotes indirection. If the operand points to a function, the result is
3517 a function designator; if it points to an object, the result is an lvalue designating the
3518 object. If the operand has type ''pointer to type'', the result has type ''type''. If an
3519 invalid value has been assigned to the pointer, the behavior of the unary * operator is
3521 Forward references: storage-class specifiers (6.7.1), structure and union specifiers
3523 6.5.3.3 Unary arithmetic operators
3525 1 The operand of the unary + or - operator shall have arithmetic type; of the ~ operator,
3526 integer type; of the ! operator, scalar type.
3528 2 The result of the unary + operator is the value of its (promoted) operand. The integer
3529 promotions are performed on the operand, and the result has the promoted type.
3530 3 The result of the unary - operator is the negative of its (promoted) operand. The integer
3531 promotions are performed on the operand, and the result has the promoted type.
3532 4 The result of the ~ operator is the bitwise complement of its (promoted) operand (that is,
3533 each bit in the result is set if and only if the corresponding bit in the converted operand is
3534 not set). The integer promotions are performed on the operand, and the result has the
3535 promoted type. If the promoted type is an unsigned type, the expression ~E is equivalent
3536 to the maximum value representable in that type minus E.
3537 5 The result of the logical negation operator ! is 0 if the value of its operand compares
3538 unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int.
3539 The expression !E is equivalent to (0==E).
3544 87) Thus, &*E is equivalent to E (even if E is a null pointer), and &(E1[E2]) to ((E1)+(E2)). It is
3545 always true that if E is a function designator or an lvalue that is a valid operand of the unary &
3546 operator, *&E is a function designator or an lvalue equal to E. If *P is an lvalue and T is the name of
3547 an object pointer type, *(T)P is an lvalue that has a type compatible with that to which T points.
3548 Among the invalid values for dereferencing a pointer by the unary * operator are a null pointer, an
3549 address inappropriately aligned for the type of object pointed to, and the address of an object after the
3550 end of its lifetime.
3554 6.5.3.4 The sizeof operator
3556 1 The sizeof operator shall not be applied to an expression that has function type or an
3557 incomplete type, to the parenthesized name of such a type, or to an expression that
3558 designates a bit-field member.
3560 2 The sizeof operator yields the size (in bytes) of its operand, which may be an
3561 expression or the parenthesized name of a type. The size is determined from the type of
3562 the operand. The result is an integer. If the type of the operand is a variable length array
3563 type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an
3565 3 When applied to an operand that has type char, unsigned char, or signed char,
3566 (or a qualified version thereof) the result is 1. When applied to an operand that has array
3567 type, the result is the total number of bytes in the array.88) When applied to an operand
3568 that has structure or union type, the result is the total number of bytes in such an object,
3569 including internal and trailing padding.
3570 4 The value of the result is implementation-defined, and its type (an unsigned integer type)
3571 is size_t, defined in <stddef.h> (and other headers).
3572 5 EXAMPLE 1 A principal use of the sizeof operator is in communication with routines such as storage
3573 allocators and I/O systems. A storage-allocation function might accept a size (in bytes) of an object to
3574 allocate and return a pointer to void. For example:
3575 extern void *alloc(size_t);
3576 double *dp = alloc(sizeof *dp);
3577 The implementation of the alloc function should ensure that its return value is aligned suitably for
3578 conversion to a pointer to double.
3580 6 EXAMPLE 2 Another use of the sizeof operator is to compute the number of elements in an array:
3581 sizeof array / sizeof array[0]
3583 7 EXAMPLE 3 In this example, the size of a variable length array is computed and returned from a
3586 size_t fsize3(int n)
3588 char b[n+3]; // variable length array
3589 return sizeof b; // execution time sizeof
3594 88) When applied to a parameter declared to have array or function type, the sizeof operator yields the
3595 size of the adjusted (pointer) type (see 6.9.1).
3602 size = fsize3(10); // fsize3 returns 13
3606 Forward references: common definitions <stddef.h> (7.17), declarations (6.7),
3607 structure and union specifiers (6.7.2.1), type names (6.7.6), array declarators (6.7.5.2).
3608 6.5.4 Cast operators
3612 ( type-name ) cast-expression
3614 2 Unless the type name specifies a void type, the type name shall specify qualified or
3615 unqualified scalar type and the operand shall have scalar type.
3616 3 Conversions that involve pointers, other than where permitted by the constraints of
3617 6.5.16.1, shall be specified by means of an explicit cast.
3619 4 Preceding an expression by a parenthesized type name converts the value of the
3620 expression to the named type. This construction is called a cast.89) A cast that specifies
3621 no conversion has no effect on the type or value of an expression.
3622 5 If the value of the expression is represented with greater precision or range than required
3623 by the type named by the cast (6.3.1.8), then the cast specifies a conversion even if the
3624 type of the expression is the same as the named type.
3625 Forward references: equality operators (6.5.9), function declarators (including
3626 prototypes) (6.7.5.3), simple assignment (6.5.16.1), type names (6.7.6).
3631 89) A cast does not yield an lvalue. Thus, a cast to a qualified type has the same effect as a cast to the
3632 unqualified version of the type.
3636 6.5.5 Multiplicative operators
3638 1 multiplicative-expression:
3640 multiplicative-expression * cast-expression
3641 multiplicative-expression / cast-expression
3642 multiplicative-expression % cast-expression
3644 2 Each of the operands shall have arithmetic type. The operands of the % operator shall
3647 3 The usual arithmetic conversions are performed on the operands.
3648 4 The result of the binary * operator is the product of the operands.
3649 5 The result of the / operator is the quotient from the division of the first operand by the
3650 second; the result of the % operator is the remainder. In both operations, if the value of
3651 the second operand is zero, the behavior is undefined.
3652 6 When integers are divided, the result of the / operator is the algebraic quotient with any
3653 fractional part discarded.90) If the quotient a/b is representable, the expression
3654 (a/b)*b + a%b shall equal a.
3655 6.5.6 Additive operators
3657 1 additive-expression:
3658 multiplicative-expression
3659 additive-expression + multiplicative-expression
3660 additive-expression - multiplicative-expression
3662 2 For addition, either both operands shall have arithmetic type, or one operand shall be a
3663 pointer to an object type and the other shall have integer type. (Incrementing is
3664 equivalent to adding 1.)
3665 3 For subtraction, one of the following shall hold:
3666 -- both operands have arithmetic type;
3670 90) This is often called ''truncation toward zero''.
3674 -- both operands are pointers to qualified or unqualified versions of compatible object
3676 -- the left operand is a pointer to an object type and the right operand has integer type.
3677 (Decrementing is equivalent to subtracting 1.)
3679 4 If both operands have arithmetic type, the usual arithmetic conversions are performed on
3681 5 The result of the binary + operator is the sum of the operands.
3682 6 The result of the binary - operator is the difference resulting from the subtraction of the
3683 second operand from the first.
3684 7 For the purposes of these operators, a pointer to an object that is not an element of an
3685 array behaves the same as a pointer to the first element of an array of length one with the
3686 type of the object as its element type.
3687 8 When an expression that has integer type is added to or subtracted from a pointer, the
3688 result has the type of the pointer operand. If the pointer operand points to an element of
3689 an array object, and the array is large enough, the result points to an element offset from
3690 the original element such that the difference of the subscripts of the resulting and original
3691 array elements equals the integer expression. In other words, if the expression P points to
3692 the i-th element of an array object, the expressions (P)+N (equivalently, N+(P)) and
3693 (P)-N (where N has the value n) point to, respectively, the i+n-th and i-n-th elements of
3694 the array object, provided they exist. Moreover, if the expression P points to the last
3695 element of an array object, the expression (P)+1 points one past the last element of the
3696 array object, and if the expression Q points one past the last element of an array object,
3697 the expression (Q)-1 points to the last element of the array object. If both the pointer
3698 operand and the result point to elements of the same array object, or one past the last
3699 element of the array object, the evaluation shall not produce an overflow; otherwise, the
3700 behavior is undefined. If the result points one past the last element of the array object, it
3701 shall not be used as the operand of a unary * operator that is evaluated.
3702 9 When two pointers are subtracted, both shall point to elements of the same array object,
3703 or one past the last element of the array object; the result is the difference of the
3704 subscripts of the two array elements. The size of the result is implementation-defined,
3705 and its type (a signed integer type) is ptrdiff_t defined in the <stddef.h> header.
3706 If the result is not representable in an object of that type, the behavior is undefined. In
3707 other words, if the expressions P and Q point to, respectively, the i-th and j-th elements of
3708 an array object, the expression (P)-(Q) has the value i-j provided the value fits in an
3709 object of type ptrdiff_t. Moreover, if the expression P points either to an element of
3710 an array object or one past the last element of an array object, and the expression Q points
3711 to the last element of the same array object, the expression ((Q)+1)-(P) has the same
3714 value as ((Q)-(P))+1 and as -((P)-((Q)+1)), and has the value zero if the
3715 expression P points one past the last element of the array object, even though the
3716 expression (Q)+1 does not point to an element of the array object.91)
3717 10 EXAMPLE Pointer arithmetic is well defined with pointers to variable length array types.
3721 int (*p)[m] = a; // p == &a[0]
3722 p += 1; // p == &a[1]
3723 (*p)[2] = 99; // a[1][2] == 99
3724 n = p - a; // n == 1
3726 11 If array a in the above example were declared to be an array of known constant size, and pointer p were
3727 declared to be a pointer to an array of the same known constant size (pointing to a), the results would be
3730 Forward references: array declarators (6.7.5.2), common definitions <stddef.h>
3732 6.5.7 Bitwise shift operators
3736 shift-expression << additive-expression
3737 shift-expression >> additive-expression
3739 2 Each of the operands shall have integer type.
3741 3 The integer promotions are performed on each of the operands. The type of the result is
3742 that of the promoted left operand. If the value of the right operand is negative or is
3743 greater than or equal to the width of the promoted left operand, the behavior is undefined.
3748 91) Another way to approach pointer arithmetic is first to convert the pointer(s) to character pointer(s): In
3749 this scheme the integer expression added to or subtracted from the converted pointer is first multiplied
3750 by the size of the object originally pointed to, and the resulting pointer is converted back to the
3751 original type. For pointer subtraction, the result of the difference between the character pointers is
3752 similarly divided by the size of the object originally pointed to.
3753 When viewed in this way, an implementation need only provide one extra byte (which may overlap
3754 another object in the program) just after the end of the object in order to satisfy the ''one past the last
3755 element'' requirements.
3759 4 The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with
3760 zeros. If E1 has an unsigned type, the value of the result is E1 x 2E2 , reduced modulo
3761 one more than the maximum value representable in the result type. If E1 has a signed
3762 type and nonnegative value, and E1 x 2E2 is representable in the result type, then that is
3763 the resulting value; otherwise, the behavior is undefined.
3764 5 The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type
3765 or if E1 has a signed type and a nonnegative value, the value of the result is the integral
3766 part of the quotient of E1 / 2E2 . If E1 has a signed type and a negative value, the
3767 resulting value is implementation-defined.
3768 6.5.8 Relational operators
3770 1 relational-expression:
3772 relational-expression < shift-expression
3773 relational-expression > shift-expression
3774 relational-expression <= shift-expression
3775 relational-expression >= shift-expression
3777 2 One of the following shall hold:
3778 -- both operands have real type;
3779 -- both operands are pointers to qualified or unqualified versions of compatible object
3781 -- both operands are pointers to qualified or unqualified versions of compatible
3784 3 If both of the operands have arithmetic type, the usual arithmetic conversions are
3786 4 For the purposes of these operators, a pointer to an object that is not an element of an
3787 array behaves the same as a pointer to the first element of an array of length one with the
3788 type of the object as its element type.
3789 5 When two pointers are compared, the result depends on the relative locations in the
3790 address space of the objects pointed to. If two pointers to object or incomplete types both
3791 point to the same object, or both point one past the last element of the same array object,
3792 they compare equal. If the objects pointed to are members of the same aggregate object,
3793 pointers to structure members declared later compare greater than pointers to members
3794 declared earlier in the structure, and pointers to array elements with larger subscript
3798 values compare greater than pointers to elements of the same array with lower subscript
3799 values. All pointers to members of the same union object compare equal. If the
3800 expression P points to an element of an array object and the expression Q points to the
3801 last element of the same array object, the pointer expression Q+1 compares greater than
3802 P. In all other cases, the behavior is undefined.
3803 6 Each of the operators < (less than), > (greater than), <= (less than or equal to), and >=
3804 (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false.92)
3805 The result has type int.
3806 6.5.9 Equality operators
3808 1 equality-expression:
3809 relational-expression
3810 equality-expression == relational-expression
3811 equality-expression != relational-expression
3813 2 One of the following shall hold:
3814 -- both operands have arithmetic type;
3815 -- both operands are pointers to qualified or unqualified versions of compatible types;
3816 -- one operand is a pointer to an object or incomplete type and the other is a pointer to a
3817 qualified or unqualified version of void; or
3818 -- one operand is a pointer and the other is a null pointer constant.
3820 3 The == (equal to) and != (not equal to) operators are analogous to the relational
3821 operators except for their lower precedence.93) Each of the operators yields 1 if the
3822 specified relation is true and 0 if it is false. The result has type int. For any pair of
3823 operands, exactly one of the relations is true.
3824 4 If both of the operands have arithmetic type, the usual arithmetic conversions are
3825 performed. Values of complex types are equal if and only if both their real parts are equal
3826 and also their imaginary parts are equal. Any two values of arithmetic types from
3827 different type domains are equal if and only if the results of their conversions to the
3828 (complex) result type determined by the usual arithmetic conversions are equal.
3831 92) The expression a<b<c is not interpreted as in ordinary mathematics. As the syntax indicates, it
3832 means (a<b)<c; in other words, ''if a is less than b, compare 1 to c; otherwise, compare 0 to c''.
3833 93) Because of the precedences, a<b == c<d is 1 whenever a<b and c<d have the same truth-value.
3837 5 Otherwise, at least one operand is a pointer. If one operand is a pointer and the other is a
3838 null pointer constant, the null pointer constant is converted to the type of the pointer. If
3839 one operand is a pointer to an object or incomplete type and the other is a pointer to a
3840 qualified or unqualified version of void, the former is converted to the type of the latter.
3841 6 Two pointers compare equal if and only if both are null pointers, both are pointers to the
3842 same object (including a pointer to an object and a subobject at its beginning) or function,
3843 both are pointers to one past the last element of the same array object, or one is a pointer
3844 to one past the end of one array object and the other is a pointer to the start of a different
3845 array object that happens to immediately follow the first array object in the address
3847 7 For the purposes of these operators, a pointer to an object that is not an element of an
3848 array behaves the same as a pointer to the first element of an array of length one with the
3849 type of the object as its element type.
3850 6.5.10 Bitwise AND operator
3854 AND-expression & equality-expression
3856 2 Each of the operands shall have integer type.
3858 3 The usual arithmetic conversions are performed on the operands.
3859 4 The result of the binary & operator is the bitwise AND of the operands (that is, each bit in
3860 the result is set if and only if each of the corresponding bits in the converted operands is
3866 94) Two objects may be adjacent in memory because they are adjacent elements of a larger array or
3867 adjacent members of a structure with no padding between them, or because the implementation chose
3868 to place them so, even though they are unrelated. If prior invalid pointer operations (such as accesses
3869 outside array bounds) produced undefined behavior, subsequent comparisons also produce undefined
3874 6.5.11 Bitwise exclusive OR operator
3876 1 exclusive-OR-expression:
3878 exclusive-OR-expression ^ AND-expression
3880 2 Each of the operands shall have integer type.
3882 3 The usual arithmetic conversions are performed on the operands.
3883 4 The result of the ^ operator is the bitwise exclusive OR of the operands (that is, each bit
3884 in the result is set if and only if exactly one of the corresponding bits in the converted
3886 6.5.12 Bitwise inclusive OR operator
3888 1 inclusive-OR-expression:
3889 exclusive-OR-expression
3890 inclusive-OR-expression | exclusive-OR-expression
3892 2 Each of the operands shall have integer type.
3894 3 The usual arithmetic conversions are performed on the operands.
3895 4 The result of the | operator is the bitwise inclusive OR of the operands (that is, each bit in
3896 the result is set if and only if at least one of the corresponding bits in the converted
3904 6.5.13 Logical AND operator
3906 1 logical-AND-expression:
3907 inclusive-OR-expression
3908 logical-AND-expression && inclusive-OR-expression
3910 2 Each of the operands shall have scalar type.
3912 3 The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it
3913 yields 0. The result has type int.
3914 4 Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation;
3915 there is a sequence point after the evaluation of the first operand. If the first operand
3916 compares equal to 0, the second operand is not evaluated.
3917 6.5.14 Logical OR operator
3919 1 logical-OR-expression:
3920 logical-AND-expression
3921 logical-OR-expression || logical-AND-expression
3923 2 Each of the operands shall have scalar type.
3925 3 The || operator shall yield 1 if either of its operands compare unequal to 0; otherwise, it
3926 yields 0. The result has type int.
3927 4 Unlike the bitwise | operator, the || operator guarantees left-to-right evaluation; there is
3928 a sequence point after the evaluation of the first operand. If the first operand compares
3929 unequal to 0, the second operand is not evaluated.
3936 6.5.15 Conditional operator
3938 1 conditional-expression:
3939 logical-OR-expression
3940 logical-OR-expression ? expression : conditional-expression
3942 2 The first operand shall have scalar type.
3943 3 One of the following shall hold for the second and third operands:
3944 -- both operands have arithmetic type;
3945 -- both operands have the same structure or union type;
3946 -- both operands have void type;
3947 -- both operands are pointers to qualified or unqualified versions of compatible types;
3948 -- one operand is a pointer and the other is a null pointer constant; or
3949 -- one operand is a pointer to an object or incomplete type and the other is a pointer to a
3950 qualified or unqualified version of void.
3952 4 The first operand is evaluated; there is a sequence point after its evaluation. The second
3953 operand is evaluated only if the first compares unequal to 0; the third operand is evaluated
3954 only if the first compares equal to 0; the result is the value of the second or third operand
3955 (whichever is evaluated), converted to the type described below.95) If an attempt is made
3956 to modify the result of a conditional operator or to access it after the next sequence point,
3957 the behavior is undefined.
3958 5 If both the second and third operands have arithmetic type, the result type that would be
3959 determined by the usual arithmetic conversions, were they applied to those two operands,
3960 is the type of the result. If both the operands have structure or union type, the result has
3961 that type. If both operands have void type, the result has void type.
3962 6 If both the second and third operands are pointers or one is a null pointer constant and the
3963 other is a pointer, the result type is a pointer to a type qualified with all the type qualifiers
3964 of the types pointed-to by both operands. Furthermore, if both operands are pointers to
3965 compatible types or to differently qualified versions of compatible types, the result type is
3966 a pointer to an appropriately qualified version of the composite type; if one operand is a
3967 null pointer constant, the result has the type of the other operand; otherwise, one operand
3968 is a pointer to void or a qualified version of void, in which case the result type is a
3970 95) A conditional expression does not yield an lvalue.
3974 pointer to an appropriately qualified version of void.
3975 7 EXAMPLE The common type that results when the second and third operands are pointers is determined
3976 in two independent stages. The appropriate qualifiers, for example, do not depend on whether the two
3977 pointers have compatible types.
3978 8 Given the declarations
3985 the third column in the following table is the common type that is the result of a conditional expression in
3986 which the first two columns are the second and third operands (in either order):
3987 c_vp c_ip const void *
3988 v_ip 0 volatile int *
3989 c_ip v_ip const volatile int *
3990 vp c_cp const void *
3994 6.5.16 Assignment operators
3996 1 assignment-expression:
3997 conditional-expression
3998 unary-expression assignment-operator assignment-expression
3999 assignment-operator: one of
4000 = *= /= %= += -= <<= >>= &= ^= |=
4002 2 An assignment operator shall have a modifiable lvalue as its left operand.
4004 3 An assignment operator stores a value in the object designated by the left operand. An
4005 assignment expression has the value of the left operand after the assignment, but is not an
4006 lvalue. The type of an assignment expression is the type of the left operand unless the
4007 left operand has qualified type, in which case it is the unqualified version of the type of
4008 the left operand. The side effect of updating the stored value of the left operand shall
4009 occur between the previous and the next sequence point.
4010 4 The order of evaluation of the operands is unspecified. If an attempt is made to modify
4011 the result of an assignment operator or to access it after the next sequence point, the
4012 behavior is undefined.
4017 6.5.16.1 Simple assignment
4019 1 One of the following shall hold:96)
4020 -- the left operand has qualified or unqualified arithmetic type and the right has
4022 -- the left operand has a qualified or unqualified version of a structure or union type
4023 compatible with the type of the right;
4024 -- both operands are pointers to qualified or unqualified versions of compatible types,
4025 and the type pointed to by the left has all the qualifiers of the type pointed to by the
4027 -- one operand is a pointer to an object or incomplete type and the other is a pointer to a
4028 qualified or unqualified version of void, and the type pointed to by the left has all
4029 the qualifiers of the type pointed to by the right;
4030 -- the left operand is a pointer and the right is a null pointer constant; or
4031 -- the left operand has type _Bool and the right is a pointer.
4033 2 In simple assignment (=), the value of the right operand is converted to the type of the
4034 assignment expression and replaces the value stored in the object designated by the left
4036 3 If the value being stored in an object is read from another object that overlaps in any way
4037 the storage of the first object, then the overlap shall be exact and the two objects shall
4038 have qualified or unqualified versions of a compatible type; otherwise, the behavior is
4040 4 EXAMPLE 1 In the program fragment
4044 if ((c = f()) == -1)
4046 the int value returned by the function may be truncated when stored in the char, and then converted back
4047 to int width prior to the comparison. In an implementation in which ''plain'' char has the same range of
4048 values as unsigned char (and char is narrower than int), the result of the conversion cannot be
4052 96) The asymmetric appearance of these constraints with respect to type qualifiers is due to the conversion
4053 (specified in 6.3.2.1) that changes lvalues to ''the value of the expression'' and thus removes any type
4054 qualifiers that were applied to the type category of the expression (for example, it removes const but
4055 not volatile from the type int volatile * const).
4059 negative, so the operands of the comparison can never compare equal. Therefore, for full portability, the
4060 variable c should be declared as int.
4062 5 EXAMPLE 2 In the fragment:
4067 the value of i is converted to the type of the assignment expression c = i, that is, char type. The value
4068 of the expression enclosed in parentheses is then converted to the type of the outer assignment expression,
4069 that is, long int type.
4071 6 EXAMPLE 3 Consider the fragment:
4075 cpp = &p; // constraint violation
4078 The first assignment is unsafe because it would allow the following valid code to attempt to change the
4079 value of the const object c.
4081 6.5.16.2 Compound assignment
4083 1 For the operators += and -= only, either the left operand shall be a pointer to an object
4084 type and the right shall have integer type, or the left operand shall have qualified or
4085 unqualified arithmetic type and the right shall have arithmetic type.
4086 2 For the other operators, each operand shall have arithmetic type consistent with those
4087 allowed by the corresponding binary operator.
4089 3 A compound assignment of the form E1 op = E2 differs from the simple assignment
4090 expression E1 = E1 op (E2) only in that the lvalue E1 is evaluated only once.
4097 6.5.17 Comma operator
4100 assignment-expression
4101 expression , assignment-expression
4103 2 The left operand of a comma operator is evaluated as a void expression; there is a
4104 sequence point after its evaluation. Then the right operand is evaluated; the result has its
4105 type and value.97) If an attempt is made to modify the result of a comma operator or to
4106 access it after the next sequence point, the behavior is undefined.
4107 3 EXAMPLE As indicated by the syntax, the comma operator (as described in this subclause) cannot
4108 appear in contexts where a comma is used to separate items in a list (such as arguments to functions or lists
4109 of initializers). On the other hand, it can be used within a parenthesized expression or within the second
4110 expression of a conditional operator in such contexts. In the function call
4112 the function has three arguments, the second of which has the value 5.
4114 Forward references: initialization (6.7.8).
4119 97) A comma operator does not yield an lvalue.
4123 6.6 Constant expressions
4125 1 constant-expression:
4126 conditional-expression
4128 2 A constant expression can be evaluated during translation rather than runtime, and
4129 accordingly may be used in any place that a constant may be.
4131 3 Constant expressions shall not contain assignment, increment, decrement, function-call,
4132 or comma operators, except when they are contained within a subexpression that is not
4134 4 Each constant expression shall evaluate to a constant that is in the range of representable
4135 values for its type.
4137 5 An expression that evaluates to a constant is required in several contexts. If a floating
4138 expression is evaluated in the translation environment, the arithmetic precision and range
4139 shall be at least as great as if the expression were being evaluated in the execution
4141 6 An integer constant expression99) shall have integer type and shall only have operands
4142 that are integer constants, enumeration constants, character constants, sizeof
4143 expressions whose results are integer constants, and floating constants that are the
4144 immediate operands of casts. Cast operators in an integer constant expression shall only
4145 convert arithmetic types to integer types, except as part of an operand to the sizeof
4147 7 More latitude is permitted for constant expressions in initializers. Such a constant
4148 expression shall be, or evaluate to, one of the following:
4149 -- an arithmetic constant expression,
4150 -- a null pointer constant,
4155 98) The operand of a sizeof operator is usually not evaluated (6.5.3.4).
4156 99) An integer constant expression is used to specify the size of a bit-field member of a structure, the
4157 value of an enumeration constant, the size of an array, or the value of a case constant. Further
4158 constraints that apply to the integer constant expressions used in conditional-inclusion preprocessing
4159 directives are discussed in 6.10.1.
4163 -- an address constant, or
4164 -- an address constant for an object type plus or minus an integer constant expression.
4165 8 An arithmetic constant expression shall have arithmetic type and shall only have
4166 operands that are integer constants, floating constants, enumeration constants, character
4167 constants, and sizeof expressions. Cast operators in an arithmetic constant expression
4168 shall only convert arithmetic types to arithmetic types, except as part of an operand to a
4169 sizeof operator whose result is an integer constant.
4170 9 An address constant is a null pointer, a pointer to an lvalue designating an object of static
4171 storage duration, or a pointer to a function designator; it shall be created explicitly using
4172 the unary & operator or an integer constant cast to pointer type, or implicitly by the use of
4173 an expression of array or function type. The array-subscript [] and member-access .
4174 and -> operators, the address & and indirection * unary operators, and pointer casts may
4175 be used in the creation of an address constant, but the value of an object shall not be
4176 accessed by use of these operators.
4177 10 An implementation may accept other forms of constant expressions.
4178 11 The semantic rules for the evaluation of a constant expression are the same as for
4179 nonconstant expressions.100)
4180 Forward references: array declarators (6.7.5.2), initialization (6.7.8).
4185 100) Thus, in the following initialization,
4186 static int i = 2 || 1 / 0;
4187 the expression is a valid integer constant expression with value one.
4194 declaration-specifiers init-declarator-listopt ;
4195 declaration-specifiers:
4196 storage-class-specifier declaration-specifiersopt
4197 type-specifier declaration-specifiersopt
4198 type-qualifier declaration-specifiersopt
4199 function-specifier declaration-specifiersopt
4200 init-declarator-list:
4202 init-declarator-list , init-declarator
4205 declarator = initializer
4207 2 A declaration shall declare at least a declarator (other than the parameters of a function or
4208 the members of a structure or union), a tag, or the members of an enumeration.
4209 3 If an identifier has no linkage, there shall be no more than one declaration of the identifier
4210 (in a declarator or type specifier) with the same scope and in the same name space, except
4211 for tags as specified in 6.7.2.3.
4212 4 All declarations in the same scope that refer to the same object or function shall specify
4215 5 A declaration specifies the interpretation and attributes of a set of identifiers. A definition
4216 of an identifier is a declaration for that identifier that:
4217 -- for an object, causes storage to be reserved for that object;
4218 -- for a function, includes the function body;101)
4219 -- for an enumeration constant or typedef name, is the (only) declaration of the
4221 6 The declaration specifiers consist of a sequence of specifiers that indicate the linkage,
4222 storage duration, and part of the type of the entities that the declarators denote. The init-
4223 declarator-list is a comma-separated sequence of declarators, each of which may have
4225 101) Function definitions have a different syntax, described in 6.9.1.
4229 additional type information, or an initializer, or both. The declarators contain the
4230 identifiers (if any) being declared.
4231 7 If an identifier for an object is declared with no linkage, the type for the object shall be
4232 complete by the end of its declarator, or by the end of its init-declarator if it has an
4233 initializer; in the case of function parameters (including in prototypes), it is the adjusted
4234 type (see 6.7.5.3) that is required to be complete.
4235 Forward references: declarators (6.7.5), enumeration specifiers (6.7.2.2), initialization
4237 6.7.1 Storage-class specifiers
4239 1 storage-class-specifier:
4246 2 At most, one storage-class specifier may be given in the declaration specifiers in a
4249 3 The typedef specifier is called a ''storage-class specifier'' for syntactic convenience
4250 only; it is discussed in 6.7.7. The meanings of the various linkages and storage durations
4251 were discussed in 6.2.2 and 6.2.4.
4252 4 A declaration of an identifier for an object with storage-class specifier register
4253 suggests that access to the object be as fast as possible. The extent to which such
4254 suggestions are effective is implementation-defined.103)
4255 5 The declaration of an identifier for a function that has block scope shall have no explicit
4256 storage-class specifier other than extern.
4260 102) See ''future language directions'' (6.11.5).
4261 103) The implementation may treat any register declaration simply as an auto declaration. However,
4262 whether or not addressable storage is actually used, the address of any part of an object declared with
4263 storage-class specifier register cannot be computed, either explicitly (by use of the unary &
4264 operator as discussed in 6.5.3.2) or implicitly (by converting an array name to a pointer as discussed in
4265 6.3.2.1). Thus, the only operator that can be applied to an array declared with storage-class specifier
4270 6 If an aggregate or union object is declared with a storage-class specifier other than
4271 typedef, the properties resulting from the storage-class specifier, except with respect to
4272 linkage, also apply to the members of the object, and so on recursively for any aggregate
4273 or union member objects.
4274 Forward references: type definitions (6.7.7).
4275 6.7.2 Type specifiers
4289 struct-or-union-specifier *
4293 2 At least one type specifier shall be given in the declaration specifiers in each declaration,
4294 and in the specifier-qualifier list in each struct declaration and type name. Each list of
4295 type specifiers shall be one of the following sets (delimited by commas, when there is
4296 more than one set on a line); the type specifiers may occur in any order, possibly
4297 intermixed with the other declaration specifiers.
4302 -- short, signed short, short int, or signed short int
4303 -- unsigned short, or unsigned short int
4304 -- int, signed, or signed int
4309 -- unsigned, or unsigned int
4310 -- long, signed long, long int, or signed long int
4311 -- unsigned long, or unsigned long int
4312 -- long long, signed long long, long long int, or
4313 signed long long int
4314 -- unsigned long long, or unsigned long long int
4321 -- long double _Complex
4322 -- struct or union specifier *
4325 3 The type specifier _Complex shall not be used if the implementation does not provide
4328 4 Specifiers for structures, unions, and enumerations are discussed in 6.7.2.1 through
4329 6.7.2.3. Declarations of typedef names are discussed in 6.7.7. The characteristics of the
4330 other types are discussed in 6.2.5.
4331 5 Each of the comma-separated sets designates the same type, except that for bit-fields, it is
4332 implementation-defined whether the specifier int designates the same type as signed
4333 int or the same type as unsigned int.
4334 Forward references: enumeration specifiers (6.7.2.2), structure and union specifiers
4335 (6.7.2.1), tags (6.7.2.3), type definitions (6.7.7).
4340 104) Freestanding implementations are not required to provide complex types. *
4344 6.7.2.1 Structure and union specifiers
4346 1 struct-or-union-specifier:
4347 struct-or-union identifieropt { struct-declaration-list }
4348 struct-or-union identifier
4352 struct-declaration-list:
4354 struct-declaration-list struct-declaration
4356 specifier-qualifier-list struct-declarator-list ;
4357 specifier-qualifier-list:
4358 type-specifier specifier-qualifier-listopt
4359 type-qualifier specifier-qualifier-listopt
4360 struct-declarator-list:
4362 struct-declarator-list , struct-declarator
4365 declaratoropt : constant-expression
4367 2 A structure or union shall not contain a member with incomplete or function type (hence,
4368 a structure shall not contain an instance of itself, but may contain a pointer to an instance
4369 of itself), except that the last member of a structure with more than one named member
4370 may have incomplete array type; such a structure (and any union containing, possibly
4371 recursively, a member that is such a structure) shall not be a member of a structure or an
4372 element of an array.
4373 3 The expression that specifies the width of a bit-field shall be an integer constant
4374 expression with a nonnegative value that does not exceed the width of an object of the
4375 type that would be specified were the colon and expression omitted. If the value is zero,
4376 the declaration shall have no declarator.
4377 4 A bit-field shall have a type that is a qualified or unqualified version of _Bool, signed
4378 int, unsigned int, or some other implementation-defined type.
4384 5 As discussed in 6.2.5, a structure is a type consisting of a sequence of members, whose
4385 storage is allocated in an ordered sequence, and a union is a type consisting of a sequence
4386 of members whose storage overlap.
4387 6 Structure and union specifiers have the same form. The keywords struct and union
4388 indicate that the type being specified is, respectively, a structure type or a union type.
4389 7 The presence of a struct-declaration-list in a struct-or-union-specifier declares a new type,
4390 within a translation unit. The struct-declaration-list is a sequence of declarations for the
4391 members of the structure or union. If the struct-declaration-list contains no named
4392 members, the behavior is undefined. The type is incomplete until after the } that
4393 terminates the list.
4394 8 A member of a structure or union may have any object type other than a variably
4395 modified type.105) In addition, a member may be declared to consist of a specified
4396 number of bits (including a sign bit, if any). Such a member is called a bit-field;106) its
4397 width is preceded by a colon.
4398 9 A bit-field is interpreted as a signed or unsigned integer type consisting of the specified
4399 number of bits.107) If the value 0 or 1 is stored into a nonzero-width bit-field of type
4400 _Bool, the value of the bit-field shall compare equal to the value stored.
4401 10 An implementation may allocate any addressable storage unit large enough to hold a bit-
4402 field. If enough space remains, a bit-field that immediately follows another bit-field in a
4403 structure shall be packed into adjacent bits of the same unit. If insufficient space remains,
4404 whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is
4405 implementation-defined. The order of allocation of bit-fields within a unit (high-order to
4406 low-order or low-order to high-order) is implementation-defined. The alignment of the
4407 addressable storage unit is unspecified.
4408 11 A bit-field declaration with no declarator, but only a colon and a width, indicates an
4409 unnamed bit-field.108) As a special case, a bit-field structure member with a width of 0
4410 indicates that no further bit-field is to be packed into the unit in which the previous bit-
4411 field, if any, was placed.
4414 105) A structure or union can not contain a member with a variably modified type because member names
4415 are not ordinary identifiers as defined in 6.2.3.
4416 106) The unary & (address-of) operator cannot be applied to a bit-field object; thus, there are no pointers to
4417 or arrays of bit-field objects.
4418 107) As specified in 6.7.2 above, if the actual type specifier used is int or a typedef-name defined as int,
4419 then it is implementation-defined whether the bit-field is signed or unsigned.
4420 108) An unnamed bit-field structure member is useful for padding to conform to externally imposed
4425 12 Each non-bit-field member of a structure or union object is aligned in an implementation-
4426 defined manner appropriate to its type.
4427 13 Within a structure object, the non-bit-field members and the units in which bit-fields
4428 reside have addresses that increase in the order in which they are declared. A pointer to a
4429 structure object, suitably converted, points to its initial member (or if that member is a
4430 bit-field, then to the unit in which it resides), and vice versa. There may be unnamed
4431 padding within a structure object, but not at its beginning.
4432 14 The size of a union is sufficient to contain the largest of its members. The value of at
4433 most one of the members can be stored in a union object at any time. A pointer to a
4434 union object, suitably converted, points to each of its members (or if a member is a bit-
4435 field, then to the unit in which it resides), and vice versa.
4436 15 There may be unnamed padding at the end of a structure or union.
4437 16 As a special case, the last element of a structure with more than one named member may
4438 have an incomplete array type; this is called a flexible array member. In most situations,
4439 the flexible array member is ignored. In particular, the size of the structure is as if the
4440 flexible array member were omitted except that it may have more trailing padding than
4441 the omission would imply. However, when a . (or ->) operator has a left operand that is
4442 (a pointer to) a structure with a flexible array member and the right operand names that
4443 member, it behaves as if that member were replaced with the longest array (with the same
4444 element type) that would not make the structure larger than the object being accessed; the
4445 offset of the array shall remain that of the flexible array member, even if this would differ
4446 from that of the replacement array. If this array would have no elements, it behaves as if
4447 it had one element but the behavior is undefined if any attempt is made to access that
4448 element or to generate a pointer one past it.
4449 17 EXAMPLE After the declaration:
4450 struct s { int n; double d[]; };
4451 the structure struct s has a flexible array member d. A typical way to use this is:
4452 int m = /* some value */;
4453 struct s *p = malloc(sizeof (struct s) + sizeof (double [m]));
4454 and assuming that the call to malloc succeeds, the object pointed to by p behaves, for most purposes, as if
4455 p had been declared as:
4456 struct { int n; double d[m]; } *p;
4457 (there are circumstances in which this equivalence is broken; in particular, the offsets of member d might
4459 18 Following the above declaration:
4466 struct s t1 = { 0 }; // valid
4467 struct s t2 = { 1, { 4.2 }}; // invalid
4469 t1.d[0] = 4.2; // might be undefined behavior
4470 The initialization of t2 is invalid (and violates a constraint) because struct s is treated as if it did not
4471 contain member d. The assignment to t1.d[0] is probably undefined behavior, but it is possible that
4472 sizeof (struct s) >= offsetof(struct s, d) + sizeof (double)
4473 in which case the assignment would be legitimate. Nevertheless, it cannot appear in strictly conforming
4475 19 After the further declaration:
4476 struct ss { int n; };
4478 sizeof (struct s) >= sizeof (struct ss)
4479 sizeof (struct s) >= offsetof(struct s, d)
4480 are always equal to 1.
4481 20 If sizeof (double) is 8, then after the following code is executed:
4484 s1 = malloc(sizeof (struct s) + 64);
4485 s2 = malloc(sizeof (struct s) + 46);
4486 and assuming that the calls to malloc succeed, the objects pointed to by s1 and s2 behave, for most
4487 purposes, as if the identifiers had been declared as:
4488 struct { int n; double d[8]; } *s1;
4489 struct { int n; double d[5]; } *s2;
4490 21 Following the further successful assignments:
4491 s1 = malloc(sizeof (struct s) + 10);
4492 s2 = malloc(sizeof (struct s) + 6);
4493 they then behave as if the declarations were:
4494 struct { int n; double d[1]; } *s1, *s2;
4497 dp = &(s1->d[0]); // valid
4499 dp = &(s2->d[0]); // valid
4500 *dp = 42; // undefined behavior
4503 only copies the member n; if any of the array elements are within the first sizeof (struct s) bytes
4504 of the structure, they might be copied or simply overwritten with indeterminate values.
4506 Forward references: tags (6.7.2.3).
4510 6.7.2.2 Enumeration specifiers
4513 enum identifieropt { enumerator-list }
4514 enum identifieropt { enumerator-list , }
4518 enumerator-list , enumerator
4520 enumeration-constant
4521 enumeration-constant = constant-expression
4523 2 The expression that defines the value of an enumeration constant shall be an integer
4524 constant expression that has a value representable as an int.
4526 3 The identifiers in an enumerator list are declared as constants that have type int and
4527 may appear wherever such are permitted.109) An enumerator with = defines its
4528 enumeration constant as the value of the constant expression. If the first enumerator has
4529 no =, the value of its enumeration constant is 0. Each subsequent enumerator with no =
4530 defines its enumeration constant as the value of the constant expression obtained by
4531 adding 1 to the value of the previous enumeration constant. (The use of enumerators with
4532 = may produce enumeration constants with values that duplicate other values in the same
4533 enumeration.) The enumerators of an enumeration are also known as its members.
4534 4 Each enumerated type shall be compatible with char, a signed integer type, or an
4535 unsigned integer type. The choice of type is implementation-defined,110) but shall be
4536 capable of representing the values of all the members of the enumeration. The
4537 enumerated type is incomplete until after the } that terminates the list of enumerator
4543 109) Thus, the identifiers of enumeration constants declared in the same scope shall all be distinct from
4544 each other and from other identifiers declared in ordinary declarators.
4545 110) An implementation may delay the choice of which integer type until all enumeration constants have
4550 5 EXAMPLE The following fragment:
4551 enum hue { chartreuse, burgundy, claret=20, winedark };
4555 if (*cp != burgundy)
4557 makes hue the tag of an enumeration, and then declares col as an object that has that type and cp as a
4558 pointer to an object that has that type. The enumerated values are in the set { 0, 1, 20, 21 }.
4560 Forward references: tags (6.7.2.3).
4563 1 A specific type shall have its content defined at most once.
4564 2 Where two declarations that use the same tag declare the same type, they shall both use
4565 the same choice of struct, union, or enum.
4566 3 A type specifier of the form
4568 without an enumerator list shall only appear after the type it specifies is complete.
4570 4 All declarations of structure, union, or enumerated types that have the same scope and
4571 use the same tag declare the same type. The type is incomplete111) until the closing brace
4572 of the list defining the content, and complete thereafter.
4573 5 Two declarations of structure, union, or enumerated types which are in different scopes or
4574 use different tags declare distinct types. Each declaration of a structure, union, or
4575 enumerated type which does not include a tag declares a distinct type.
4576 6 A type specifier of the form
4577 struct-or-union identifieropt { struct-declaration-list }
4579 enum identifier { enumerator-list }
4581 enum identifier { enumerator-list , }
4582 declares a structure, union, or enumerated type. The list defines the structure content,
4584 111) An incomplete type may only by used when the size of an object of that type is not needed. It is not
4585 needed, for example, when a typedef name is declared to be a specifier for a structure or union, or
4586 when a pointer to or a function returning a structure or union is being declared. (See incomplete types
4587 in 6.2.5.) The specification has to be complete before such a function is called or defined.
4591 union content, or enumeration content. If an identifier is provided,112) the type specifier
4592 also declares the identifier to be the tag of that type.
4593 7 A declaration of the form
4594 struct-or-union identifier ;
4595 specifies a structure or union type and declares the identifier as a tag of that type.113)
4596 8 If a type specifier of the form
4597 struct-or-union identifier
4598 occurs other than as part of one of the above forms, and no other declaration of the
4599 identifier as a tag is visible, then it declares an incomplete structure or union type, and
4600 declares the identifier as the tag of that type.113)
4601 9 If a type specifier of the form
4602 struct-or-union identifier
4605 occurs other than as part of one of the above forms, and a declaration of the identifier as a
4606 tag is visible, then it specifies the same type as that other declaration, and does not
4608 10 EXAMPLE 1 This mechanism allows declaration of a self-referential structure.
4611 struct tnode *left, *right;
4613 specifies a structure that contains an integer and two pointers to objects of the same type. Once this
4614 declaration has been given, the declaration
4615 struct tnode s, *sp;
4616 declares s to be an object of the given type and sp to be a pointer to an object of the given type. With
4617 these declarations, the expression sp->left refers to the left struct tnode pointer of the object to
4618 which sp points; the expression s.right->count designates the count member of the right struct
4619 tnode pointed to from s.
4620 11 The following alternative formulation uses the typedef mechanism:
4625 112) If there is no identifier, the type can, within the translation unit, only be referred to by the declaration
4626 of which it is a part. Of course, when the declaration is of a typedef name, subsequent declarations
4627 can make use of that typedef name to declare objects having the specified structure, union, or
4629 113) A similar construction with enum does not exist.
4633 typedef struct tnode TNODE;
4636 TNODE *left, *right;
4640 12 EXAMPLE 2 To illustrate the use of prior declaration of a tag to specify a pair of mutually referential
4641 structures, the declarations
4642 struct s1 { struct s2 *s2p; /* ... */ }; // D1
4643 struct s2 { struct s1 *s1p; /* ... */ }; // D2
4644 specify a pair of structures that contain pointers to each other. Note, however, that if s2 were already
4645 declared as a tag in an enclosing scope, the declaration D1 would refer to it, not to the tag s2 declared in
4646 D2. To eliminate this context sensitivity, the declaration
4648 may be inserted ahead of D1. This declares a new tag s2 in the inner scope; the declaration D2 then
4649 completes the specification of the new type.
4651 Forward references: declarators (6.7.5), array declarators (6.7.5.2), type definitions
4653 6.7.3 Type qualifiers
4660 2 Types other than pointer types derived from object or incomplete types shall not be
4663 3 The properties associated with qualified types are meaningful only for expressions that
4665 4 If the same qualifier appears more than once in the same specifier-qualifier-list, either
4666 directly or via one or more typedefs, the behavior is the same as if it appeared only
4672 114) The implementation may place a const object that is not volatile in a read-only region of
4673 storage. Moreover, the implementation need not allocate storage for such an object if its address is
4678 5 If an attempt is made to modify an object defined with a const-qualified type through use
4679 of an lvalue with non-const-qualified type, the behavior is undefined. If an attempt is
4680 made to refer to an object defined with a volatile-qualified type through use of an lvalue
4681 with non-volatile-qualified type, the behavior is undefined.115)
4682 6 An object that has volatile-qualified type may be modified in ways unknown to the
4683 implementation or have other unknown side effects. Therefore any expression referring
4684 to such an object shall be evaluated strictly according to the rules of the abstract machine,
4685 as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the
4686 object shall agree with that prescribed by the abstract machine, except as modified by the
4687 unknown factors mentioned previously.116) What constitutes an access to an object that
4688 has volatile-qualified type is implementation-defined.
4689 7 An object that is accessed through a restrict-qualified pointer has a special association
4690 with that pointer. This association, defined in 6.7.3.1 below, requires that all accesses to
4691 that object use, directly or indirectly, the value of that particular pointer.117) The intended
4692 use of the restrict qualifier (like the register storage class) is to promote
4693 optimization, and deleting all instances of the qualifier from all preprocessing translation
4694 units composing a conforming program does not change its meaning (i.e., observable
4696 8 If the specification of an array type includes any type qualifiers, the element type is so-
4697 qualified, not the array type. If the specification of a function type includes any type
4698 qualifiers, the behavior is undefined.118)
4699 9 For two qualified types to be compatible, both shall have the identically qualified version
4700 of a compatible type; the order of type qualifiers within a list of specifiers or qualifiers
4701 does not affect the specified type.
4702 10 EXAMPLE 1 An object declared
4703 extern const volatile int real_time_clock;
4704 may be modifiable by hardware, but cannot be assigned to, incremented, or decremented.
4709 115) This applies to those objects that behave as if they were defined with qualified types, even if they are
4710 never actually defined as objects in the program (such as an object at a memory-mapped input/output
4712 116) A volatile declaration may be used to describe an object corresponding to a memory-mapped
4713 input/output port or an object accessed by an asynchronously interrupting function. Actions on
4714 objects so declared shall not be ''optimized out'' by an implementation or reordered except as
4715 permitted by the rules for evaluating expressions.
4716 117) For example, a statement that assigns a value returned by malloc to a single pointer establishes this
4717 association between the allocated object and the pointer.
4718 118) Both of these can occur through the use of typedefs.
4722 11 EXAMPLE 2 The following declarations and expressions illustrate the behavior when type qualifiers
4723 modify an aggregate type:
4724 const struct s { int mem; } cs = { 1 };
4725 struct s ncs; // the object ncs is modifiable
4726 typedef int A[2][3];
4727 const A a = {{4, 5, 6}, {7, 8, 9}}; // array of array of const int
4731 cs = ncs; // violates modifiable lvalue constraint for =
4732 pi = &ncs.mem; // valid
4733 pi = &cs.mem; // violates type constraints for =
4734 pci = &cs.mem; // valid
4735 pi = a[0]; // invalid: a[0] has type ''const int *''
4737 6.7.3.1 Formal definition of restrict
4738 1 Let D be a declaration of an ordinary identifier that provides a means of designating an
4739 object P as a restrict-qualified pointer to type T.
4740 2 If D appears inside a block and does not have storage class extern, let B denote the
4741 block. If D appears in the list of parameter declarations of a function definition, let B
4742 denote the associated block. Otherwise, let B denote the block of main (or the block of
4743 whatever function is called at program startup in a freestanding environment).
4744 3 In what follows, a pointer expression E is said to be based on object P if (at some
4745 sequence point in the execution of B prior to the evaluation of E) modifying P to point to
4746 a copy of the array object into which it formerly pointed would change the value of E.119)
4747 Note that ''based'' is defined only for expressions with pointer types.
4748 4 During each execution of B, let L be any lvalue that has &L based on P. If L is used to
4749 access the value of the object X that it designates, and X is also modified (by any means),
4750 then the following requirements apply: T shall not be const-qualified. Every other lvalue
4751 used to access the value of X shall also have its address based on P. Every access that
4752 modifies X shall be considered also to modify P, for the purposes of this subclause. If P
4753 is assigned the value of a pointer expression E that is based on another restricted pointer
4754 object P2, associated with block B2, then either the execution of B2 shall begin before
4755 the execution of B, or the execution of B2 shall end prior to the assignment. If these
4756 requirements are not met, then the behavior is undefined.
4757 5 Here an execution of B means that portion of the execution of the program that would
4758 correspond to the lifetime of an object with scalar type and automatic storage duration
4760 119) In other words, E depends on the value of P itself rather than on the value of an object referenced
4761 indirectly through P. For example, if identifier p has type (int **restrict), then the pointer
4762 expressions p and p+1 are based on the restricted pointer object designated by p, but the pointer
4763 expressions *p and p[1] are not.
4768 6 A translator is free to ignore any or all aliasing implications of uses of restrict.
4769 7 EXAMPLE 1 The file scope declarations
4773 assert that if an object is accessed using one of a, b, or c, and that object is modified anywhere in the
4774 program, then it is never accessed using either of the other two.
4776 8 EXAMPLE 2 The function parameter declarations in the following example
4777 void f(int n, int * restrict p, int * restrict q)
4782 assert that, during each execution of the function, if an object is accessed through one of the pointer
4783 parameters, then it is not also accessed through the other.
4784 9 The benefit of the restrict qualifiers is that they enable a translator to make an effective dependence
4785 analysis of function f without examining any of the calls of f in the program. The cost is that the
4786 programmer has to examine all of those calls to ensure that none give undefined behavior. For example, the
4787 second call of f in g has undefined behavior because each of d[1] through d[49] is accessed through
4792 f(50, d + 50, d); // valid
4793 f(50, d + 1, d); // undefined behavior
4796 10 EXAMPLE 3 The function parameter declarations
4797 void h(int n, int * restrict p, int * restrict q, int * restrict r)
4800 for (i = 0; i < n; i++)
4803 illustrate how an unmodified object can be aliased through two restricted pointers. In particular, if a and b
4804 are disjoint arrays, a call of the form h(100, a, b, b) has defined behavior, because array b is not
4805 modified within function h.
4807 11 EXAMPLE 4 The rule limiting assignments between restricted pointers does not distinguish between a
4808 function call and an equivalent nested block. With one exception, only ''outer-to-inner'' assignments
4809 between restricted pointers declared in nested blocks have defined behavior.
4819 p1 = q1; // undefined behavior
4821 int * restrict p2 = p1; // valid
4822 int * restrict q2 = q1; // valid
4823 p1 = q2; // undefined behavior
4824 p2 = q2; // undefined behavior
4827 12 The one exception allows the value of a restricted pointer to be carried out of the block in which it (or, more
4828 precisely, the ordinary identifier used to designate it) is declared when that block finishes execution. For
4829 example, this permits new_vector to return a vector.
4830 typedef struct { int n; float * restrict v; } vector;
4831 vector new_vector(int n)
4835 t.v = malloc(n * sizeof (float));
4839 6.7.4 Function specifiers
4841 1 function-specifier:
4844 2 Function specifiers shall be used only in the declaration of an identifier for a function.
4845 3 An inline definition of a function with external linkage shall not contain a definition of a
4846 modifiable object with static storage duration, and shall not contain a reference to an
4847 identifier with internal linkage.
4848 4 In a hosted environment, the inline function specifier shall not appear in a declaration
4851 5 A function declared with an inline function specifier is an inline function. The
4852 function specifier may appear more than once; the behavior is the same as if it appeared
4853 only once. Making a function an inline function suggests that calls to the function be as
4854 fast as possible.120) The extent to which such suggestions are effective is
4855 implementation-defined.121)
4856 6 Any function with internal linkage can be an inline function. For a function with external
4857 linkage, the following restrictions apply: If a function is declared with an inline
4860 function specifier, then it shall also be defined in the same translation unit. If all of the
4861 file scope declarations for a function in a translation unit include the inline function
4862 specifier without extern, then the definition in that translation unit is an inline
4863 definition. An inline definition does not provide an external definition for the function,
4864 and does not forbid an external definition in another translation unit. An inline definition
4865 provides an alternative to an external definition, which a translator may use to implement
4866 any call to the function in the same translation unit. It is unspecified whether a call to the
4867 function uses the inline definition or the external definition.122)
4868 7 EXAMPLE The declaration of an inline function with external linkage can result in either an external
4869 definition, or a definition available for use only within the translation unit. A file scope declaration with
4870 extern creates an external definition. The following example shows an entire translation unit.
4871 inline double fahr(double t)
4873 return (9.0 * t) / 5.0 + 32.0;
4875 inline double cels(double t)
4877 return (5.0 * (t - 32.0)) / 9.0;
4879 extern double fahr(double); // creates an external definition
4880 double convert(int is_fahr, double temp)
4882 /* A translator may perform inline substitutions */
4883 return is_fahr ? cels(temp) : fahr(temp);
4885 8 Note that the definition of fahr is an external definition because fahr is also declared with extern, but
4886 the definition of cels is an inline definition. Because cels has external linkage and is referenced, an
4887 external definition has to appear in another translation unit (see 6.9); the inline definition and the external
4888 definition are distinct and either may be used for the call.
4890 Forward references: function definitions (6.9.1).
4893 120) By using, for example, an alternative to the usual function call mechanism, such as ''inline
4894 substitution''. Inline substitution is not textual substitution, nor does it create a new function.
4895 Therefore, for example, the expansion of a macro used within the body of the function uses the
4896 definition it had at the point the function body appears, and not where the function is called; and
4897 identifiers refer to the declarations in scope where the body occurs. Likewise, the function has a
4898 single address, regardless of the number of inline definitions that occur in addition to the external
4900 121) For example, an implementation might never perform inline substitution, or might only perform inline
4901 substitutions to calls in the scope of an inline declaration.
4902 122) Since an inline definition is distinct from the corresponding external definition and from any other
4903 corresponding inline definitions in other translation units, all corresponding objects with static storage
4904 duration are also distinct in each of the definitions.
4911 pointeropt direct-declarator
4915 direct-declarator [ type-qualifier-listopt assignment-expressionopt ]
4916 direct-declarator [ static type-qualifier-listopt assignment-expression ]
4917 direct-declarator [ type-qualifier-list static assignment-expression ]
4918 direct-declarator [ type-qualifier-listopt * ]
4919 direct-declarator ( parameter-type-list )
4920 direct-declarator ( identifier-listopt )
4922 * type-qualifier-listopt
4923 * type-qualifier-listopt pointer
4924 type-qualifier-list:
4926 type-qualifier-list type-qualifier
4927 parameter-type-list:
4929 parameter-list , ...
4931 parameter-declaration
4932 parameter-list , parameter-declaration
4933 parameter-declaration:
4934 declaration-specifiers declarator
4935 declaration-specifiers abstract-declaratoropt
4938 identifier-list , identifier
4940 2 Each declarator declares one identifier, and asserts that when an operand of the same
4941 form as the declarator appears in an expression, it designates a function or object with the
4942 scope, storage duration, and type indicated by the declaration specifiers.
4943 3 A full declarator is a declarator that is not part of another declarator. The end of a full
4944 declarator is a sequence point. If, in the nested sequence of declarators in a full
4947 declarator, there is a declarator specifying a variable length array type, the type specified
4948 by the full declarator is said to be variably modified. Furthermore, any type derived by
4949 declarator type derivation from a variably modified type is itself variably modified.
4950 4 In the following subclauses, consider a declaration
4952 where T contains the declaration specifiers that specify a type T (such as int) and D1 is
4953 a declarator that contains an identifier ident. The type specified for the identifier ident in
4954 the various forms of declarator is described inductively using this notation.
4955 5 If, in the declaration ''T D1'', D1 has the form
4957 then the type specified for ident is T .
4958 6 If, in the declaration ''T D1'', D1 has the form
4960 then ident has the type specified by the declaration ''T D''. Thus, a declarator in
4961 parentheses is identical to the unparenthesized declarator, but the binding of complicated
4962 declarators may be altered by parentheses.
4963 Implementation limits
4964 7 As discussed in 5.2.4.1, an implementation may limit the number of pointer, array, and
4965 function declarators that modify an arithmetic, structure, union, or incomplete type, either
4966 directly or via one or more typedefs.
4967 Forward references: array declarators (6.7.5.2), type definitions (6.7.7).
4968 6.7.5.1 Pointer declarators
4970 1 If, in the declaration ''T D1'', D1 has the form
4971 * type-qualifier-listopt D
4972 and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
4973 T '', then the type specified for ident is ''derived-declarator-type-list type-qualifier-list
4974 pointer to T ''. For each type qualifier in the list, ident is a so-qualified pointer.
4975 2 For two pointer types to be compatible, both shall be identically qualified and both shall
4976 be pointers to compatible types.
4977 3 EXAMPLE The following pair of declarations demonstrates the difference between a ''variable pointer
4978 to a constant value'' and a ''constant pointer to a variable value''.
4985 const int *ptr_to_constant;
4986 int *const constant_ptr;
4987 The contents of any object pointed to by ptr_to_constant shall not be modified through that pointer,
4988 but ptr_to_constant itself may be changed to point to another object. Similarly, the contents of the
4989 int pointed to by constant_ptr may be modified, but constant_ptr itself shall always point to the
4991 4 The declaration of the constant pointer constant_ptr may be clarified by including a definition for the
4992 type ''pointer to int''.
4993 typedef int *int_ptr;
4994 const int_ptr constant_ptr;
4995 declares constant_ptr as an object that has type ''const-qualified pointer to int''.
4997 6.7.5.2 Array declarators
4999 1 In addition to optional type qualifiers and the keyword static, the [ and ] may delimit
5000 an expression or *. If they delimit an expression (which specifies the size of an array), the
5001 expression shall have an integer type. If the expression is a constant expression, it shall
5002 have a value greater than zero. The element type shall not be an incomplete or function
5003 type. The optional type qualifiers and the keyword static shall appear only in a
5004 declaration of a function parameter with an array type, and then only in the outermost
5005 array type derivation.
5006 2 An ordinary identifier (as defined in 6.2.3) that has a variably modified type shall have
5007 either block scope and no linkage or function prototype scope. If an identifier is declared
5008 to be an object with static storage duration, it shall not have a variable length array type.
5010 3 If, in the declaration ''T D1'', D1 has one of the forms:
5011 D[ type-qualifier-listopt assignment-expressionopt ]
5012 D[ static type-qualifier-listopt assignment-expression ]
5013 D[ type-qualifier-list static assignment-expression ]
5014 D[ type-qualifier-listopt * ]
5015 and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
5016 T '', then the type specified for ident is ''derived-declarator-type-list array of T ''.123)
5017 (See 6.7.5.3 for the meaning of the optional type qualifiers and the keyword static.)
5018 4 If the size is not present, the array type is an incomplete type. If the size is * instead of
5019 being an expression, the array type is a variable length array type of unspecified size,
5020 which can only be used in declarations with function prototype scope;124) such arrays are
5021 nonetheless complete types. If the size is an integer constant expression and the element
5023 123) When several ''array of'' specifications are adjacent, a multidimensional array is declared.
5027 type has a known constant size, the array type is not a variable length array type;
5028 otherwise, the array type is a variable length array type.
5029 5 If the size is an expression that is not an integer constant expression: if it occurs in a
5030 declaration at function prototype scope, it is treated as if it were replaced by *; otherwise,
5031 each time it is evaluated it shall have a value greater than zero. The size of each instance
5032 of a variable length array type does not change during its lifetime. Where a size
5033 expression is part of the operand of a sizeof operator and changing the value of the
5034 size expression would not affect the result of the operator, it is unspecified whether or not
5035 the size expression is evaluated.
5036 6 For two array types to be compatible, both shall have compatible element types, and if
5037 both size specifiers are present, and are integer constant expressions, then both size
5038 specifiers shall have the same constant value. If the two array types are used in a context
5039 which requires them to be compatible, it is undefined behavior if the two size specifiers
5040 evaluate to unequal values.
5042 float fa[11], *afp[17];
5043 declares an array of float numbers and an array of pointers to float numbers.
5045 8 EXAMPLE 2 Note the distinction between the declarations
5048 The first declares x to be a pointer to int; the second declares y to be an array of int of unspecified size
5049 (an incomplete type), the storage for which is defined elsewhere.
5051 9 EXAMPLE 3 The following declarations demonstrate the compatibility rules for variably modified types.
5059 int (*r)[n][n][n+1];
5060 p = a; // invalid: not compatible because 4 != 6
5061 r = c; // compatible, but defined behavior only if
5062 // n == 6 and m == n+1
5068 124) Thus, * can be used only in function declarations that are not definitions (see 6.7.5.3).
5072 10 EXAMPLE 4 All declarations of variably modified (VM) types have to be at either block scope or
5073 function prototype scope. Array objects declared with the static or extern storage-class specifier
5074 cannot have a variable length array (VLA) type. However, an object declared with the static storage-
5075 class specifier can have a VM type (that is, a pointer to a VLA type). Finally, all identifiers declared with a
5076 VM type have to be ordinary identifiers and cannot, therefore, be members of structures or unions.
5078 int A[n]; // invalid: file scope VLA
5079 extern int (*p2)[n]; // invalid: file scope VM
5080 int B[100]; // valid: file scope but not VM
5081 void fvla(int m, int C[m][m]); // valid: VLA with prototype scope
5082 void fvla(int m, int C[m][m]) // valid: adjusted to auto pointer to VLA
5084 typedef int VLA[m][m]; // valid: block scope typedef VLA
5086 int (*y)[n]; // invalid: y not ordinary identifier
5087 int z[n]; // invalid: z not ordinary identifier
5089 int D[m]; // valid: auto VLA
5090 static int E[m]; // invalid: static block scope VLA
5091 extern int F[m]; // invalid: F has linkage and is VLA
5092 int (*s)[m]; // valid: auto pointer to VLA
5093 extern int (*r)[m]; // invalid: r has linkage and points to VLA
5094 static int (*q)[m] = &B; // valid: q is a static block pointer to VLA
5097 Forward references: function declarators (6.7.5.3), function definitions (6.9.1),
5098 initialization (6.7.8).
5099 6.7.5.3 Function declarators (including prototypes)
5101 1 A function declarator shall not specify a return type that is a function type or an array
5103 2 The only storage-class specifier that shall occur in a parameter declaration is register.
5104 3 An identifier list in a function declarator that is not part of a definition of that function
5106 4 After adjustment, the parameters in a parameter type list in a function declarator that is
5107 part of a definition of that function shall not have incomplete type.
5109 5 If, in the declaration ''T D1'', D1 has the form
5110 D( parameter-type-list )
5112 D( identifier-listopt )
5116 and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
5117 T '', then the type specified for ident is ''derived-declarator-type-list function returning
5119 6 A parameter type list specifies the types of, and may declare identifiers for, the
5120 parameters of the function.
5121 7 A declaration of a parameter as ''array of type'' shall be adjusted to ''qualified pointer to
5122 type'', where the type qualifiers (if any) are those specified within the [ and ] of the
5123 array type derivation. If the keyword static also appears within the [ and ] of the
5124 array type derivation, then for each call to the function, the value of the corresponding
5125 actual argument shall provide access to the first element of an array with at least as many
5126 elements as specified by the size expression.
5127 8 A declaration of a parameter as ''function returning type'' shall be adjusted to ''pointer to
5128 function returning type'', as in 6.3.2.1.
5129 9 If the list terminates with an ellipsis (, ...), no information about the number or types
5130 of the parameters after the comma is supplied.125)
5131 10 The special case of an unnamed parameter of type void as the only item in the list
5132 specifies that the function has no parameters.
5133 11 If, in a parameter declaration, an identifier can be treated either as a typedef name or as a
5134 parameter name, it shall be taken as a typedef name.
5135 12 If the function declarator is not part of a definition of that function, parameters may have
5136 incomplete type and may use the [*] notation in their sequences of declarator specifiers
5137 to specify variable length array types.
5138 13 The storage-class specifier in the declaration specifiers for a parameter declaration, if
5139 present, is ignored unless the declared parameter is one of the members of the parameter
5140 type list for a function definition.
5141 14 An identifier list declares only the identifiers of the parameters of the function. An empty
5142 list in a function declarator that is part of a definition of that function specifies that the
5143 function has no parameters. The empty list in a function declarator that is not part of a
5144 definition of that function specifies that no information about the number or types of the
5145 parameters is supplied.126)
5146 15 For two function types to be compatible, both shall specify compatible return types.127)
5149 125) The macros defined in the <stdarg.h> header (7.15) may be used to access arguments that
5150 correspond to the ellipsis.
5151 126) See ''future language directions'' (6.11.6).
5152 127) If both function types are ''old style'', parameter types are not compared.
5156 Moreover, the parameter type lists, if both are present, shall agree in the number of
5157 parameters and in use of the ellipsis terminator; corresponding parameters shall have
5158 compatible types. If one type has a parameter type list and the other type is specified by a
5159 function declarator that is not part of a function definition and that contains an empty
5160 identifier list, the parameter list shall not have an ellipsis terminator and the type of each
5161 parameter shall be compatible with the type that results from the application of the
5162 default argument promotions. If one type has a parameter type list and the other type is
5163 specified by a function definition that contains a (possibly empty) identifier list, both shall
5164 agree in the number of parameters, and the type of each prototype parameter shall be
5165 compatible with the type that results from the application of the default argument
5166 promotions to the type of the corresponding identifier. (In the determination of type
5167 compatibility and of a composite type, each parameter declared with function or array
5168 type is taken as having the adjusted type and each parameter declared with qualified type
5169 is taken as having the unqualified version of its declared type.)
5170 16 EXAMPLE 1 The declaration
5171 int f(void), *fip(), (*pfi)();
5172 declares a function f with no parameters returning an int, a function fip with no parameter specification
5173 returning a pointer to an int, and a pointer pfi to a function with no parameter specification returning an
5174 int. It is especially useful to compare the last two. The binding of *fip() is *(fip()), so that the
5175 declaration suggests, and the same construction in an expression requires, the calling of a function fip,
5176 and then using indirection through the pointer result to yield an int. In the declarator (*pfi)(), the
5177 extra parentheses are necessary to indicate that indirection through a pointer to a function yields a function
5178 designator, which is then used to call the function; it returns an int.
5179 17 If the declaration occurs outside of any function, the identifiers have file scope and external linkage. If the
5180 declaration occurs inside a function, the identifiers of the functions f and fip have block scope and either
5181 internal or external linkage (depending on what file scope declarations for these identifiers are visible), and
5182 the identifier of the pointer pfi has block scope and no linkage.
5184 18 EXAMPLE 2 The declaration
5185 int (*apfi[3])(int *x, int *y);
5186 declares an array apfi of three pointers to functions returning int. Each of these functions has two
5187 parameters that are pointers to int. The identifiers x and y are declared for descriptive purposes only and
5188 go out of scope at the end of the declaration of apfi.
5190 19 EXAMPLE 3 The declaration
5191 int (*fpfi(int (*)(long), int))(int, ...);
5192 declares a function fpfi that returns a pointer to a function returning an int. The function fpfi has two
5193 parameters: a pointer to a function returning an int (with one parameter of type long int), and an int.
5194 The pointer returned by fpfi points to a function that has one int parameter and accepts zero or more
5195 additional arguments of any type.
5202 20 EXAMPLE 4 The following prototype has a variably modified parameter.
5203 void addscalar(int n, int m,
5204 double a[n][n*m+300], double x);
5208 addscalar(4, 2, b, 2.17);
5211 void addscalar(int n, int m,
5212 double a[n][n*m+300], double x)
5214 for (int i = 0; i < n; i++)
5215 for (int j = 0, k = n*m+300; j < k; j++)
5216 // a is a pointer to a VLA with n*m+300 elements
5220 21 EXAMPLE 5 The following are all compatible function prototype declarators.
5221 double maximum(int n, int m, double a[n][m]);
5222 double maximum(int n, int m, double a[*][*]);
5223 double maximum(int n, int m, double a[ ][*]);
5224 double maximum(int n, int m, double a[ ][m]);
5226 void f(double (* restrict a)[5]);
5227 void f(double a[restrict][5]);
5228 void f(double a[restrict 3][5]);
5229 void f(double a[restrict static 3][5]);
5230 (Note that the last declaration also specifies that the argument corresponding to a in any call to f must be a
5231 non-null pointer to the first of at least three arrays of 5 doubles, which the others do not.)
5233 Forward references: function definitions (6.9.1), type names (6.7.6).
5243 specifier-qualifier-list abstract-declaratoropt
5244 abstract-declarator:
5246 pointeropt direct-abstract-declarator
5247 direct-abstract-declarator:
5248 ( abstract-declarator )
5249 direct-abstract-declaratoropt [ type-qualifier-listopt
5250 assignment-expressionopt ]
5251 direct-abstract-declaratoropt [ static type-qualifier-listopt
5252 assignment-expression ]
5253 direct-abstract-declaratoropt [ type-qualifier-list static
5254 assignment-expression ]
5255 direct-abstract-declaratoropt [ * ]
5256 direct-abstract-declaratoropt ( parameter-type-listopt )
5258 2 In several contexts, it is necessary to specify a type. This is accomplished using a type
5259 name, which is syntactically a declaration for a function or an object of that type that
5260 omits the identifier.128)
5261 3 EXAMPLE The constructions
5269 (h) int (*const [])(unsigned int, ...)
5270 name respectively the types (a) int, (b) pointer to int, (c) array of three pointers to int, (d) pointer to an
5271 array of three ints, (e) pointer to a variable length array of an unspecified number of ints, (f) function
5272 with no parameter specification returning a pointer to int, (g) pointer to function with no parameters
5273 returning an int, and (h) array of an unspecified number of constant pointers to functions, each with one
5274 parameter that has type unsigned int and an unspecified number of other parameters, returning an
5280 128) As indicated by the syntax, empty parentheses in a type name are interpreted as ''function with no
5281 parameter specification'', rather than redundant parentheses around the omitted identifier.
5285 6.7.7 Type definitions
5290 2 If a typedef name specifies a variably modified type then it shall have block scope.
5292 3 In a declaration whose storage-class specifier is typedef, each declarator defines an
5293 identifier to be a typedef name that denotes the type specified for the identifier in the way
5294 described in 6.7.5. Any array size expressions associated with variable length array
5295 declarators are evaluated each time the declaration of the typedef name is reached in the
5296 order of execution. A typedef declaration does not introduce a new type, only a
5297 synonym for the type so specified. That is, in the following declarations:
5298 typedef T type_ident;
5300 type_ident is defined as a typedef name with the type specified by the declaration
5301 specifiers in T (known as T ), and the identifier in D has the type ''derived-declarator-
5302 type-list T '' where the derived-declarator-type-list is specified by the declarators of D. A
5303 typedef name shares the same name space as other identifiers declared in ordinary
5306 typedef int MILES, KLICKSP();
5307 typedef struct { double hi, lo; } range;
5310 extern KLICKSP *metricp;
5313 are all valid declarations. The type of distance is int, that of metricp is ''pointer to function with no
5314 parameter specification returning int'', and that of x and z is the specified structure; zp is a pointer to
5315 such a structure. The object distance has a type compatible with any other int object.
5317 5 EXAMPLE 2 After the declarations
5318 typedef struct s1 { int x; } t1, *tp1;
5319 typedef struct s2 { int x; } t2, *tp2;
5320 type t1 and the type pointed to by tp1 are compatible. Type t1 is also compatible with type struct
5321 s1, but not compatible with the types struct s2, t2, the type pointed to by tp2, or int.
5328 6 EXAMPLE 3 The following obscure constructions
5329 typedef signed int t;
5336 declare a typedef name t with type signed int, a typedef name plain with type int, and a structure
5337 with three bit-field members, one named t that contains values in the range [0, 15], an unnamed const-
5338 qualified bit-field which (if it could be accessed) would contain values in either the range [-15, +15] or
5339 [-16, +15], and one named r that contains values in one of the ranges [0, 31], [-15, +15], or [-16, +15].
5340 (The choice of range is implementation-defined.) The first two bit-field declarations differ in that
5341 unsigned is a type specifier (which forces t to be the name of a structure member), while const is a
5342 type qualifier (which modifies t which is still visible as a typedef name). If these declarations are followed
5343 in an inner scope by
5346 then a function f is declared with type ''function returning signed int with one unnamed parameter
5347 with type pointer to function returning signed int with one unnamed parameter with type signed
5348 int'', and an identifier t with type long int.
5350 7 EXAMPLE 4 On the other hand, typedef names can be used to improve code readability. All three of the
5351 following declarations of the signal function specify exactly the same type, the first without making use
5352 of any typedef names.
5353 typedef void fv(int), (*pfv)(int);
5354 void (*signal(int, void (*)(int)))(int);
5355 fv *signal(int, fv *);
5356 pfv signal(int, pfv);
5358 8 EXAMPLE 5 If a typedef name denotes a variable length array type, the length of the array is fixed at the
5359 time the typedef name is defined, not each time it is used:
5362 typedef int B[n]; // B is n ints, n evaluated now
5364 B a; // a is n ints, n without += 1
5365 int b[n]; // a and b are different sizes
5366 for (int i = 1; i < n; i++)
5375 6.7.8 Initialization
5378 assignment-expression
5379 { initializer-list }
5380 { initializer-list , }
5382 designationopt initializer
5383 initializer-list , designationopt initializer
5388 designator-list designator
5390 [ constant-expression ]
5393 2 No initializer shall attempt to provide a value for an object not contained within the entity
5395 3 The type of the entity to be initialized shall be an array of unknown size or an object type
5396 that is not a variable length array type.
5397 4 All the expressions in an initializer for an object that has static storage duration shall be
5398 constant expressions or string literals.
5399 5 If the declaration of an identifier has block scope, and the identifier has external or
5400 internal linkage, the declaration shall have no initializer for the identifier.
5401 6 If a designator has the form
5402 [ constant-expression ]
5403 then the current object (defined below) shall have array type and the expression shall be
5404 an integer constant expression. If the array is of unknown size, any nonnegative value is
5406 7 If a designator has the form
5408 then the current object (defined below) shall have structure or union type and the
5409 identifier shall be the name of a member of that type.
5413 8 An initializer specifies the initial value stored in an object.
5414 9 Except where explicitly stated otherwise, for the purposes of this subclause unnamed
5415 members of objects of structure and union type do not participate in initialization.
5416 Unnamed members of structure objects have indeterminate value even after initialization.
5417 10 If an object that has automatic storage duration is not initialized explicitly, its value is
5418 indeterminate. If an object that has static storage duration is not initialized explicitly,
5420 -- if it has pointer type, it is initialized to a null pointer;
5421 -- if it has arithmetic type, it is initialized to (positive or unsigned) zero;
5422 -- if it is an aggregate, every member is initialized (recursively) according to these rules;
5423 -- if it is a union, the first named member is initialized (recursively) according to these
5425 11 The initializer for a scalar shall be a single expression, optionally enclosed in braces. The
5426 initial value of the object is that of the expression (after conversion); the same type
5427 constraints and conversions as for simple assignment apply, taking the type of the scalar
5428 to be the unqualified version of its declared type.
5429 12 The rest of this subclause deals with initializers for objects that have aggregate or union
5431 13 The initializer for a structure or union object that has automatic storage duration shall be
5432 either an initializer list as described below, or a single expression that has compatible
5433 structure or union type. In the latter case, the initial value of the object, including
5434 unnamed members, is that of the expression.
5435 14 An array of character type may be initialized by a character string literal, optionally
5436 enclosed in braces. Successive characters of the character string literal (including the
5437 terminating null character if there is room or if the array is of unknown size) initialize the
5438 elements of the array.
5439 15 An array with element type compatible with wchar_t may be initialized by a wide
5440 string literal, optionally enclosed in braces. Successive wide characters of the wide string
5441 literal (including the terminating null wide character if there is room or if the array is of
5442 unknown size) initialize the elements of the array.
5443 16 Otherwise, the initializer for an object that has aggregate or union type shall be a brace-
5444 enclosed list of initializers for the elements or named members.
5445 17 Each brace-enclosed initializer list has an associated current object. When no
5446 designations are present, subobjects of the current object are initialized in order according
5447 to the type of the current object: array elements in increasing subscript order, structure
5450 members in declaration order, and the first named member of a union.129) In contrast, a
5451 designation causes the following initializer to begin initialization of the subobject
5452 described by the designator. Initialization then continues forward in order, beginning
5453 with the next subobject after that described by the designator.130)
5454 18 Each designator list begins its description with the current object associated with the
5455 closest surrounding brace pair. Each item in the designator list (in order) specifies a
5456 particular member of its current object and changes the current object for the next
5457 designator (if any) to be that member.131) The current object that results at the end of the
5458 designator list is the subobject to be initialized by the following initializer.
5459 19 The initialization shall occur in initializer list order, each initializer provided for a
5460 particular subobject overriding any previously listed initializer for the same subobject;132)
5461 all subobjects that are not initialized explicitly shall be initialized implicitly the same as
5462 objects that have static storage duration.
5463 20 If the aggregate or union contains elements or members that are aggregates or unions,
5464 these rules apply recursively to the subaggregates or contained unions. If the initializer of
5465 a subaggregate or contained union begins with a left brace, the initializers enclosed by
5466 that brace and its matching right brace initialize the elements or members of the
5467 subaggregate or the contained union. Otherwise, only enough initializers from the list are
5468 taken to account for the elements or members of the subaggregate or the first member of
5469 the contained union; any remaining initializers are left to initialize the next element or
5470 member of the aggregate of which the current subaggregate or contained union is a part.
5471 21 If there are fewer initializers in a brace-enclosed list than there are elements or members
5472 of an aggregate, or fewer characters in a string literal used to initialize an array of known
5473 size than there are elements in the array, the remainder of the aggregate shall be
5474 initialized implicitly the same as objects that have static storage duration.
5475 22 If an array of unknown size is initialized, its size is determined by the largest indexed
5476 element with an explicit initializer. At the end of its initializer list, the array no longer
5477 has incomplete type.
5481 129) If the initializer list for a subaggregate or contained union does not begin with a left brace, its
5482 subobjects are initialized as usual, but the subaggregate or contained union does not become the
5483 current object: current objects are associated only with brace-enclosed initializer lists.
5484 130) After a union member is initialized, the next object is not the next member of the union; instead, it is
5485 the next subobject of an object containing the union.
5486 131) Thus, a designator can only specify a strict subobject of the aggregate or union that is associated with
5487 the surrounding brace pair. Note, too, that each separate designator list is independent.
5488 132) Any initializer for the subobject which is overridden and so not used to initialize that subobject might
5489 not be evaluated at all.
5493 23 The order in which any side effects occur among the initialization list expressions is
5495 24 EXAMPLE 1 Provided that <complex.h> has been #included, the declarations
5497 double complex c = 5 + 3 * I;
5498 define and initialize i with the value 3 and c with the value 5.0 + i3.0.
5500 25 EXAMPLE 2 The declaration
5501 int x[] = { 1, 3, 5 };
5502 defines and initializes x as a one-dimensional array object that has three elements, as no size was specified
5503 and there are three initializers.
5505 26 EXAMPLE 3 The declaration
5511 is a definition with a fully bracketed initialization: 1, 3, and 5 initialize the first row of y (the array object
5512 y[0]), namely y[0][0], y[0][1], and y[0][2]. Likewise the next two lines initialize y[1] and
5513 y[2]. The initializer ends early, so y[3] is initialized with zeros. Precisely the same effect could have
5516 1, 3, 5, 2, 4, 6, 3, 5, 7
5518 The initializer for y[0] does not begin with a left brace, so three items from the list are used. Likewise the
5519 next three are taken successively for y[1] and y[2].
5521 27 EXAMPLE 4 The declaration
5523 { 1 }, { 2 }, { 3 }, { 4 }
5525 initializes the first column of z as specified and initializes the rest with zeros.
5527 28 EXAMPLE 5 The declaration
5528 struct { int a[3], b; } w[] = { { 1 }, 2 };
5529 is a definition with an inconsistently bracketed initialization. It defines an array with two element
5530 structures: w[0].a[0] is 1 and w[1].a[0] is 2; all the other elements are zero.
5535 133) In particular, the evaluation order need not be the same as the order of subobject initialization.
5539 29 EXAMPLE 6 The declaration
5540 short q[4][3][2] = {
5545 contains an incompletely but consistently bracketed initialization. It defines a three-dimensional array
5546 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
5547 q[2][0][0], q[2][0][1], and q[2][1][0], respectively; all the rest are zero. The initializer for
5548 q[0][0] does not begin with a left brace, so up to six items from the current list may be used. There is
5549 only one, so the values for the remaining five elements are initialized with zero. Likewise, the initializers
5550 for q[1][0] and q[2][0] do not begin with a left brace, so each uses up to six items, initializing their
5551 respective two-dimensional subaggregates. If there had been more than six items in any of the lists, a
5552 diagnostic message would have been issued. The same initialization result could have been achieved by:
5553 short q[4][3][2] = {
5559 short q[4][3][2] = {
5571 in a fully bracketed form.
5572 30 Note that the fully bracketed and minimally bracketed forms of initialization are, in general, less likely to
5575 31 EXAMPLE 7 One form of initialization that completes array types involves typedef names. Given the
5577 typedef int A[]; // OK - declared with block scope
5579 A a = { 1, 2 }, b = { 3, 4, 5 };
5581 int a[] = { 1, 2 }, b[] = { 3, 4, 5 };
5582 due to the rules for incomplete types.
5588 32 EXAMPLE 8 The declaration
5589 char s[] = "abc", t[3] = "abc";
5590 defines ''plain'' char array objects s and t whose elements are initialized with character string literals.
5591 This declaration is identical to
5592 char s[] = { 'a', 'b', 'c', '\0' },
5593 t[] = { 'a', 'b', 'c' };
5594 The contents of the arrays are modifiable. On the other hand, the declaration
5596 defines p with type ''pointer to char'' and initializes it to point to an object with type ''array of char''
5597 with length 4 whose elements are initialized with a character string literal. If an attempt is made to use p to
5598 modify the contents of the array, the behavior is undefined.
5600 33 EXAMPLE 9 Arrays can be initialized to correspond to the elements of an enumeration by using
5602 enum { member_one, member_two };
5603 const char *nm[] = {
5604 [member_two] = "member two",
5605 [member_one] = "member one",
5608 34 EXAMPLE 10 Structure members can be initialized to nonzero values without depending on their order:
5609 div_t answer = { .quot = 2, .rem = -1 };
5611 35 EXAMPLE 11 Designators can be used to provide explicit initialization when unadorned initializer lists
5612 might be misunderstood:
5613 struct { int a[3], b; } w[] =
5614 { [0].a = {1}, [1].a[0] = 2 };
5616 36 EXAMPLE 12 Space can be ''allocated'' from both ends of an array by using a single designator:
5618 1, 3, 5, 7, 9, [MAX-5] = 8, 6, 4, 2, 0
5620 37 In the above, if MAX is greater than ten, there will be some zero-valued elements in the middle; if it is less
5621 than ten, some of the values provided by the first five initializers will be overridden by the second five.
5623 38 EXAMPLE 13 Any member of a union can be initialized:
5624 union { /* ... */ } u = { .any_member = 42 };
5626 Forward references: common definitions <stddef.h> (7.17).
5633 6.8 Statements and blocks
5638 expression-statement
5643 2 A statement specifies an action to be performed. Except as indicated, statements are
5644 executed in sequence.
5645 3 A block allows a set of declarations and statements to be grouped into one syntactic unit.
5646 The initializers of objects that have automatic storage duration, and the variable length
5647 array declarators of ordinary identifiers with block scope, are evaluated and the values are
5648 stored in the objects (including storing an indeterminate value in objects without an
5649 initializer) each time the declaration is reached in the order of execution, as if it were a
5650 statement, and within each declaration in the order that declarators appear.
5651 4 A full expression is an expression that is not part of another expression or of a declarator.
5652 Each of the following is a full expression: an initializer; the expression in an expression
5653 statement; the controlling expression of a selection statement (if or switch); the
5654 controlling expression of a while or do statement; each of the (optional) expressions of
5655 a for statement; the (optional) expression in a return statement. The end of a full
5656 expression is a sequence point.
5657 Forward references: expression and null statements (6.8.3), selection statements
5658 (6.8.4), iteration statements (6.8.5), the return statement (6.8.6.4).
5659 6.8.1 Labeled statements
5661 1 labeled-statement:
5662 identifier : statement
5663 case constant-expression : statement
5666 2 A case or default label shall appear only in a switch statement. Further
5667 constraints on such labels are discussed under the switch statement.
5672 3 Label names shall be unique within a function.
5674 4 Any statement may be preceded by a prefix that declares an identifier as a label name.
5675 Labels in themselves do not alter the flow of control, which continues unimpeded across
5677 Forward references: the goto statement (6.8.6.1), the switch statement (6.8.4.2).
5678 6.8.2 Compound statement
5680 1 compound-statement:
5681 { block-item-listopt }
5684 block-item-list block-item
5689 2 A compound statement is a block.
5690 6.8.3 Expression and null statements
5692 1 expression-statement:
5695 2 The expression in an expression statement is evaluated as a void expression for its side
5697 3 A null statement (consisting of just a semicolon) performs no operations.
5698 4 EXAMPLE 1 If a function call is evaluated as an expression statement for its side effects only, the
5699 discarding of its value may be made explicit by converting the expression to a void expression by means of
5707 134) Such as assignments, and function calls which have side effects.
5711 5 EXAMPLE 2 In the program fragment
5714 while (*s++ != '\0')
5716 a null statement is used to supply an empty loop body to the iteration statement.
5718 6 EXAMPLE 3 A null statement may also be used to carry a label just before the closing } of a compound
5732 Forward references: iteration statements (6.8.5).
5733 6.8.4 Selection statements
5735 1 selection-statement:
5736 if ( expression ) statement
5737 if ( expression ) statement else statement
5738 switch ( expression ) statement
5740 2 A selection statement selects among a set of statements depending on the value of a
5741 controlling expression.
5742 3 A selection statement is a block whose scope is a strict subset of the scope of its
5743 enclosing block. Each associated substatement is also a block whose scope is a strict
5744 subset of the scope of the selection statement.
5745 6.8.4.1 The if statement
5747 1 The controlling expression of an if statement shall have scalar type.
5749 2 In both forms, the first substatement is executed if the expression compares unequal to 0.
5750 In the else form, the second substatement is executed if the expression compares equal
5754 to 0. If the first substatement is reached via a label, the second substatement is not
5756 3 An else is associated with the lexically nearest preceding if that is allowed by the
5758 6.8.4.2 The switch statement
5760 1 The controlling expression of a switch statement shall have integer type.
5761 2 If a switch statement has an associated case or default label within the scope of an
5762 identifier with a variably modified type, the entire switch statement shall be within the
5763 scope of that identifier.135)
5764 3 The expression of each case label shall be an integer constant expression and no two of
5765 the case constant expressions in the same switch statement shall have the same value
5766 after conversion. There may be at most one default label in a switch statement.
5767 (Any enclosed switch statement may have a default label or case constant
5768 expressions with values that duplicate case constant expressions in the enclosing
5771 4 A switch statement causes control to jump to, into, or past the statement that is the
5772 switch body, depending on the value of a controlling expression, and on the presence of a
5773 default label and the values of any case labels on or in the switch body. A case or
5774 default label is accessible only within the closest enclosing switch statement.
5775 5 The integer promotions are performed on the controlling expression. The constant
5776 expression in each case label is converted to the promoted type of the controlling
5777 expression. If a converted value matches that of the promoted controlling expression,
5778 control jumps to the statement following the matched case label. Otherwise, if there is
5779 a default label, control jumps to the labeled statement. If no converted case constant
5780 expression matches and there is no default label, no part of the switch body is
5782 Implementation limits
5783 6 As discussed in 5.2.4.1, the implementation may limit the number of case values in a
5789 135) That is, the declaration either precedes the switch statement, or it follows the last case or
5790 default label associated with the switch that is in the block containing the declaration.
5794 7 EXAMPLE In the artificial program fragment
5801 /* falls through into default code */
5805 the object whose identifier is i exists with automatic storage duration (within the block) but is never
5806 initialized, and thus if the controlling expression has a nonzero value, the call to the printf function will
5807 access an indeterminate value. Similarly, the call to the function f cannot be reached.
5809 6.8.5 Iteration statements
5811 1 iteration-statement:
5812 while ( expression ) statement
5813 do statement while ( expression ) ;
5814 for ( expressionopt ; expressionopt ; expressionopt ) statement
5815 for ( declaration expressionopt ; expressionopt ) statement
5817 2 The controlling expression of an iteration statement shall have scalar type.
5818 3 The declaration part of a for statement shall only declare identifiers for objects having
5819 storage class auto or register.
5821 4 An iteration statement causes a statement called the loop body to be executed repeatedly
5822 until the controlling expression compares equal to 0. The repetition occurs regardless of
5823 whether the loop body is entered from the iteration statement or by a jump.136)
5824 5 An iteration statement is a block whose scope is a strict subset of the scope of its
5825 enclosing block. The loop body is also a block whose scope is a strict subset of the scope
5826 of the iteration statement.
5831 136) Code jumped over is not executed. In particular, the controlling expression of a for or while
5832 statement is not evaluated before entering the loop body, nor is clause-1 of a for statement.
5836 6.8.5.1 The while statement
5837 1 The evaluation of the controlling expression takes place before each execution of the loop
5839 6.8.5.2 The do statement
5840 1 The evaluation of the controlling expression takes place after each execution of the loop
5842 6.8.5.3 The for statement
5844 for ( clause-1 ; expression-2 ; expression-3 ) statement
5845 behaves as follows: The expression expression-2 is the controlling expression that is
5846 evaluated before each execution of the loop body. The expression expression-3 is
5847 evaluated as a void expression after each execution of the loop body. If clause-1 is a
5848 declaration, the scope of any identifiers it declares is the remainder of the declaration and
5849 the entire loop, including the other two expressions; it is reached in the order of execution
5850 before the first evaluation of the controlling expression. If clause-1 is an expression, it is
5851 evaluated as a void expression before the first evaluation of the controlling expression.137)
5852 2 Both clause-1 and expression-3 can be omitted. An omitted expression-2 is replaced by a
5854 6.8.6 Jump statements
5860 return expressionopt ;
5862 2 A jump statement causes an unconditional jump to another place.
5867 137) Thus, clause-1 specifies initialization for the loop, possibly declaring one or more variables for use in
5868 the loop; the controlling expression, expression-2, specifies an evaluation made before each iteration,
5869 such that execution of the loop continues until the expression compares equal to 0; and expression-3
5870 specifies an operation (such as incrementing) that is performed after each iteration.
5874 6.8.6.1 The goto statement
5876 1 The identifier in a goto statement shall name a label located somewhere in the enclosing
5877 function. A goto statement shall not jump from outside the scope of an identifier having
5878 a variably modified type to inside the scope of that identifier.
5880 2 A goto statement causes an unconditional jump to the statement prefixed by the named
5881 label in the enclosing function.
5882 3 EXAMPLE 1 It is sometimes convenient to jump into the middle of a complicated set of statements. The
5883 following outline presents one possible approach to a problem based on these three assumptions:
5884 1. The general initialization code accesses objects only visible to the current function.
5885 2. The general initialization code is too large to warrant duplication.
5886 3. The code to determine the next operation is at the head of the loop. (To allow it to be reached by
5887 continue statements, for example.)
5891 // determine next operation
5893 if (need to reinitialize) {
5894 // reinitialize-only code
5897 // general initialization code
5901 // handle other operations
5910 4 EXAMPLE 2 A goto statement is not allowed to jump past any declarations of objects with variably
5911 modified types. A jump within the scope, however, is permitted.
5912 goto lab3; // invalid: going INTO scope of VLA.
5918 goto lab4; // valid: going WITHIN scope of VLA.
5923 goto lab4; // invalid: going INTO scope of VLA.
5925 6.8.6.2 The continue statement
5927 1 A continue statement shall appear only in or as a loop body.
5929 2 A continue statement causes a jump to the loop-continuation portion of the smallest
5930 enclosing iteration statement; that is, to the end of the loop body. More precisely, in each
5932 while (/* ... */) { do { for (/* ... */) {
5933 /* ... */ /* ... */ /* ... */
5934 continue; continue; continue;
5935 /* ... */ /* ... */ /* ... */
5936 contin: ; contin: ; contin: ;
5937 } } while (/* ... */); }
5938 unless the continue statement shown is in an enclosed iteration statement (in which
5939 case it is interpreted within that statement), it is equivalent to goto contin;.138)
5940 6.8.6.3 The break statement
5942 1 A break statement shall appear only in or as a switch body or loop body.
5944 2 A break statement terminates execution of the smallest enclosing switch or iteration
5949 138) Following the contin: label is a null statement.
5953 6.8.6.4 The return statement
5955 1 A return statement with an expression shall not appear in a function whose return type
5956 is void. A return statement without an expression shall only appear in a function
5957 whose return type is void.
5959 2 A return statement terminates execution of the current function and returns control to
5960 its caller. A function may have any number of return statements.
5961 3 If a return statement with an expression is executed, the value of the expression is
5962 returned to the caller as the value of the function call expression. If the expression has a
5963 type different from the return type of the function in which it appears, the value is
5964 converted as if by assignment to an object having the return type of the function.139)
5966 struct s { double i; } f(void);
5983 there is no undefined behavior, although there would be if the assignment were done directly (without using
5984 a function call to fetch the value).
5989 139) The return statement is not an assignment. The overlap restriction of subclause 6.5.16.1 does not
5990 apply to the case of function return. The representation of floating-point values may have wider range
5991 or precision and is determined by FLT_EVAL_METHOD. A cast may be used to remove this extra
5992 range and precision.
5996 6.9 External definitions
5999 external-declaration
6000 translation-unit external-declaration
6001 external-declaration:
6005 2 The storage-class specifiers auto and register shall not appear in the declaration
6006 specifiers in an external declaration.
6007 3 There shall be no more than one external definition for each identifier declared with
6008 internal linkage in a translation unit. Moreover, if an identifier declared with internal
6009 linkage is used in an expression (other than as a part of the operand of a sizeof
6010 operator whose result is an integer constant), there shall be exactly one external definition
6011 for the identifier in the translation unit.
6013 4 As discussed in 5.1.1.1, the unit of program text after preprocessing is a translation unit,
6014 which consists of a sequence of external declarations. These are described as ''external''
6015 because they appear outside any function (and hence have file scope). As discussed in
6016 6.7, a declaration that also causes storage to be reserved for an object or a function named
6017 by the identifier is a definition.
6018 5 An external definition is an external declaration that is also a definition of a function
6019 (other than an inline definition) or an object. If an identifier declared with external
6020 linkage is used in an expression (other than as part of the operand of a sizeof operator
6021 whose result is an integer constant), somewhere in the entire program there shall be
6022 exactly one external definition for the identifier; otherwise, there shall be no more than
6028 140) Thus, if an identifier declared with external linkage is not used in an expression, there need be no
6029 external definition for it.
6033 6.9.1 Function definitions
6035 1 function-definition:
6036 declaration-specifiers declarator declaration-listopt compound-statement
6039 declaration-list declaration
6041 2 The identifier declared in a function definition (which is the name of the function) shall
6042 have a function type, as specified by the declarator portion of the function definition.141)
6043 3 The return type of a function shall be void or an object type other than array type.
6044 4 The storage-class specifier, if any, in the declaration specifiers shall be either extern or
6046 5 If the declarator includes a parameter type list, the declaration of each parameter shall
6047 include an identifier, except for the special case of a parameter list consisting of a single
6048 parameter of type void, in which case there shall not be an identifier. No declaration list
6050 6 If the declarator includes an identifier list, each declaration in the declaration list shall
6051 have at least one declarator, those declarators shall declare only identifiers from the
6052 identifier list, and every identifier in the identifier list shall be declared. An identifier
6053 declared as a typedef name shall not be redeclared as a parameter. The declarations in the
6054 declaration list shall contain no storage-class specifier other than register and no
6060 141) The intent is that the type category in a function definition cannot be inherited from a typedef:
6061 typedef int F(void); // type F is ''function with no parameters
6063 F f, g; // f and g both have type compatible with F
6064 F f { /* ... */ } // WRONG: syntax/constraint error
6065 F g() { /* ... */ } // WRONG: declares that g returns a function
6066 int f(void) { /* ... */ } // RIGHT: f has type compatible with F
6067 int g() { /* ... */ } // RIGHT: g has type compatible with F
6068 F *e(void) { /* ... */ } // e returns a pointer to a function
6069 F *((e))(void) { /* ... */ } // same: parentheses irrelevant
6070 int (*fp)(void); // fp points to a function that has type F
6071 F *Fp; // Fp points to a function that has type F
6077 7 The declarator in a function definition specifies the name of the function being defined
6078 and the identifiers of its parameters. If the declarator includes a parameter type list, the
6079 list also specifies the types of all the parameters; such a declarator also serves as a
6080 function prototype for later calls to the same function in the same translation unit. If the
6081 declarator includes an identifier list,142) the types of the parameters shall be declared in a
6082 following declaration list. In either case, the type of each parameter is adjusted as
6083 described in 6.7.5.3 for a parameter type list; the resulting type shall be an object type.
6084 8 If a function that accepts a variable number of arguments is defined without a parameter
6085 type list that ends with the ellipsis notation, the behavior is undefined.
6086 9 Each parameter has automatic storage duration. Its identifier is an lvalue, which is in
6087 effect declared at the head of the compound statement that constitutes the function body
6088 (and therefore cannot be redeclared in the function body except in an enclosed block).
6089 The layout of the storage for parameters is unspecified.
6090 10 On entry to the function, the size expressions of each variably modified parameter are
6091 evaluated and the value of each argument expression is converted to the type of the
6092 corresponding parameter as if by assignment. (Array expressions and function
6093 designators as arguments were converted to pointers before the call.)
6094 11 After all parameters have been assigned, the compound statement that constitutes the
6095 body of the function definition is executed.
6096 12 If the } that terminates a function is reached, and the value of the function call is used by
6097 the caller, the behavior is undefined.
6098 13 EXAMPLE 1 In the following:
6099 extern int max(int a, int b)
6101 return a > b ? a : b;
6103 extern is the storage-class specifier and int is the type specifier; max(int a, int b) is the
6104 function declarator; and
6105 { return a > b ? a : b; }
6106 is the function body. The following similar definition uses the identifier-list form for the parameter
6112 142) See ''future language directions'' (6.11.7).
6116 extern int max(a, b)
6119 return a > b ? a : b;
6121 Here int a, b; is the declaration list for the parameters. The difference between these two definitions is
6122 that the first form acts as a prototype declaration that forces conversion of the arguments of subsequent calls
6123 to the function, whereas the second form does not.
6125 14 EXAMPLE 2 To pass one function to another, one might say
6129 Then the definition of g might read
6130 void g(int (*funcp)(void))
6133 (*funcp)(); /* or funcp(); ... */
6136 void g(int func(void))
6139 func(); /* or (*func)(); ... */
6142 6.9.2 External object definitions
6144 1 If the declaration of an identifier for an object has file scope and an initializer, the
6145 declaration is an external definition for the identifier.
6146 2 A declaration of an identifier for an object that has file scope without an initializer, and
6147 without a storage-class specifier or with the storage-class specifier static, constitutes a
6148 tentative definition. If a translation unit contains one or more tentative definitions for an
6149 identifier, and the translation unit contains no external definition for that identifier, then
6150 the behavior is exactly as if the translation unit contains a file scope declaration of that
6151 identifier, with the composite type as of the end of the translation unit, with an initializer
6153 3 If the declaration of an identifier for an object is a tentative definition and has internal
6154 linkage, the declared type shall not be an incomplete type.
6162 int i1 = 1; // definition, external linkage
6163 static int i2 = 2; // definition, internal linkage
6164 extern int i3 = 3; // definition, external linkage
6165 int i4; // tentative definition, external linkage
6166 static int i5; // tentative definition, internal linkage
6167 int i1; // valid tentative definition, refers to previous
6168 int i2; // 6.2.2 renders undefined, linkage disagreement
6169 int i3; // valid tentative definition, refers to previous
6170 int i4; // valid tentative definition, refers to previous
6171 int i5; // 6.2.2 renders undefined, linkage disagreement
6172 extern int i1; // refers to previous, whose linkage is external
6173 extern int i2; // refers to previous, whose linkage is internal
6174 extern int i3; // refers to previous, whose linkage is external
6175 extern int i4; // refers to previous, whose linkage is external
6176 extern int i5; // refers to previous, whose linkage is internal
6178 5 EXAMPLE 2 If at the end of the translation unit containing
6180 the array i still has incomplete type, the implicit initializer causes it to have one element, which is set to
6181 zero on program startup.
6188 6.10 Preprocessing directives
6190 1 preprocessing-file:
6201 if-group elif-groupsopt else-groupopt endif-line
6203 # if constant-expression new-line groupopt
6204 # ifdef identifier new-line groupopt
6205 # ifndef identifier new-line groupopt
6208 elif-groups elif-group
6210 # elif constant-expression new-line groupopt
6212 # else new-line groupopt
6222 # include pp-tokens new-line
6223 # define identifier replacement-list new-line
6224 # define identifier lparen identifier-listopt )
6225 replacement-list new-line
6226 # define identifier lparen ... ) replacement-list new-line
6227 # define identifier lparen identifier-list , ... )
6228 replacement-list new-line
6229 # undef identifier new-line
6230 # line pp-tokens new-line
6231 # error pp-tokensopt new-line
6232 # pragma pp-tokensopt new-line
6235 pp-tokensopt new-line
6239 a ( character not immediately preceded by white-space
6244 pp-tokens preprocessing-token
6246 the new-line character
6248 2 A preprocessing directive consists of a sequence of preprocessing tokens that satisfies the
6249 following constraints: The first token in the sequence is a # preprocessing token that (at
6250 the start of translation phase 4) is either the first character in the source file (optionally
6251 after white space containing no new-line characters) or that follows white space
6252 containing at least one new-line character. The last token in the sequence is the first new-
6253 line character that follows the first token in the sequence.143) A new-line character ends
6254 the preprocessing directive even if it occurs within what would otherwise be an
6256 143) Thus, preprocessing directives are commonly called ''lines''. These ''lines'' have no other syntactic
6257 significance, as all white space is equivalent except in certain situations during preprocessing (see the
6258 # character string literal creation operator in 6.10.3.2, for example).
6262 invocation of a function-like macro.
6263 3 A text line shall not begin with a # preprocessing token. A non-directive shall not begin
6264 with any of the directive names appearing in the syntax.
6265 4 When in a group that is skipped (6.10.1), the directive syntax is relaxed to allow any
6266 sequence of preprocessing tokens to occur between the directive name and the following
6269 5 The only white-space characters that shall appear between preprocessing tokens within a
6270 preprocessing directive (from just after the introducing # preprocessing token through
6271 just before the terminating new-line character) are space and horizontal-tab (including
6272 spaces that have replaced comments or possibly other white-space characters in
6273 translation phase 3).
6275 6 The implementation can process and skip sections of source files conditionally, include
6276 other source files, and replace macros. These capabilities are called preprocessing,
6277 because conceptually they occur before translation of the resulting translation unit.
6278 7 The preprocessing tokens within a preprocessing directive are not subject to macro
6279 expansion unless otherwise stated.
6282 EMPTY # include <file.h>
6283 the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not
6284 begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been
6287 6.10.1 Conditional inclusion
6289 1 The expression that controls conditional inclusion shall be an integer constant expression
6290 except that: it shall not contain a cast; identifiers (including those lexically identical to
6291 keywords) are interpreted as described below;144) and it may contain unary operator
6292 expressions of the form
6297 144) Because the controlling constant expression is evaluated during translation phase 4, all identifiers
6298 either are or are not macro names -- there simply are no keywords, enumeration constants, etc.
6304 defined ( identifier )
6305 which evaluate to 1 if the identifier is currently defined as a macro name (that is, if it is
6306 predefined or if it has been the subject of a #define preprocessing directive without an
6307 intervening #undef directive with the same subject identifier), 0 if it is not.
6308 2 Each preprocessing token that remains (in the list of preprocessing tokens that will
6309 become the controlling expression) after all macro replacements have occurred shall be in
6310 the lexical form of a token (6.4).
6312 3 Preprocessing directives of the forms
6313 # if constant-expression new-line groupopt
6314 # elif constant-expression new-line groupopt
6315 check whether the controlling constant expression evaluates to nonzero.
6316 4 Prior to evaluation, macro invocations in the list of preprocessing tokens that will become
6317 the controlling constant expression are replaced (except for those macro names modified
6318 by the defined unary operator), just as in normal text. If the token defined is
6319 generated as a result of this replacement process or use of the defined unary operator
6320 does not match one of the two specified forms prior to macro replacement, the behavior is
6321 undefined. After all replacements due to macro expansion and the defined unary
6322 operator have been performed, all remaining identifiers (including those lexically
6323 identical to keywords) are replaced with the pp-number 0, and then each preprocessing
6324 token is converted into a token. The resulting tokens compose the controlling constant
6325 expression which is evaluated according to the rules of 6.6. For the purposes of this
6326 token conversion and evaluation, all signed integer types and all unsigned integer types
6327 act as if they have the same representation as, respectively, the types intmax_t and
6328 uintmax_t defined in the header <stdint.h>.145) This includes interpreting
6329 character constants, which may involve converting escape sequences into execution
6330 character set members. Whether the numeric value for these character constants matches
6331 the value obtained when an identical character constant occurs in an expression (other
6332 than within a #if or #elif directive) is implementation-defined.146) Also, whether a
6333 single-character character constant may have a negative value is implementation-defined.
6334 5 Preprocessing directives of the forms
6338 145) Thus, on an implementation where INT_MAX is 0x7FFF and UINT_MAX is 0xFFFF, the constant
6339 0x8000 is signed and positive within a #if expression even though it would be unsigned in
6340 translation phase 7.
6344 # ifdef identifier new-line groupopt
6345 # ifndef identifier new-line groupopt
6346 check whether the identifier is or is not currently defined as a macro name. Their
6347 conditions are equivalent to #if defined identifier and #if !defined identifier
6349 6 Each directive's condition is checked in order. If it evaluates to false (zero), the group
6350 that it controls is skipped: directives are processed only through the name that determines
6351 the directive in order to keep track of the level of nested conditionals; the rest of the
6352 directives' preprocessing tokens are ignored, as are the other preprocessing tokens in the
6353 group. Only the first group whose control condition evaluates to true (nonzero) is
6354 processed. If none of the conditions evaluates to true, and there is a #else directive, the
6355 group controlled by the #else is processed; lacking a #else directive, all the groups
6356 until the #endif are skipped.147)
6357 Forward references: macro replacement (6.10.3), source file inclusion (6.10.2), largest
6358 integer types (7.18.1.5).
6359 6.10.2 Source file inclusion
6361 1 A #include directive shall identify a header or source file that can be processed by the
6364 2 A preprocessing directive of the form
6365 # include <h-char-sequence> new-line
6366 searches a sequence of implementation-defined places for a header identified uniquely by
6367 the specified sequence between the < and > delimiters, and causes the replacement of that
6368 directive by the entire contents of the header. How the places are specified or the header
6369 identified is implementation-defined.
6370 3 A preprocessing directive of the form
6374 146) Thus, the constant expression in the following #if directive and if statement is not guaranteed to
6375 evaluate to the same value in these two contexts.
6377 if ('z' - 'a' == 25)
6379 147) As indicated by the syntax, a preprocessing token shall not follow a #else or #endif directive
6380 before the terminating new-line character. However, comments may appear anywhere in a source file,
6381 including within a preprocessing directive.
6385 # include "q-char-sequence" new-line
6386 causes the replacement of that directive by the entire contents of the source file identified
6387 by the specified sequence between the " delimiters. The named source file is searched
6388 for in an implementation-defined manner. If this search is not supported, or if the search
6389 fails, the directive is reprocessed as if it read
6390 # include <h-char-sequence> new-line
6391 with the identical contained sequence (including > characters, if any) from the original
6393 4 A preprocessing directive of the form
6394 # include pp-tokens new-line
6395 (that does not match one of the two previous forms) is permitted. The preprocessing
6396 tokens after include in the directive are processed just as in normal text. (Each
6397 identifier currently defined as a macro name is replaced by its replacement list of
6398 preprocessing tokens.) The directive resulting after all replacements shall match one of
6399 the two previous forms.148) The method by which a sequence of preprocessing tokens
6400 between a < and a > preprocessing token pair or a pair of " characters is combined into a
6401 single header name preprocessing token is implementation-defined.
6402 5 The implementation shall provide unique mappings for sequences consisting of one or
6403 more nondigits or digits (6.4.2.1) followed by a period (.) and a single nondigit. The
6404 first character shall not be a digit. The implementation may ignore distinctions of
6405 alphabetical case and restrict the mapping to eight significant characters before the
6407 6 A #include preprocessing directive may appear in a source file that has been read
6408 because of a #include directive in another file, up to an implementation-defined
6409 nesting limit (see 5.2.4.1).
6410 7 EXAMPLE 1 The most common uses of #include preprocessing directives are as in the following:
6414 8 EXAMPLE 2 This illustrates macro-replaced #include directives:
6419 148) Note that adjacent string literals are not concatenated into a single string literal (see the translation
6420 phases in 5.1.1.2); thus, an expansion that results in two string literals is an invalid directive.
6425 #define INCFILE "vers1.h"
6427 #define INCFILE "vers2.h" // and so on
6429 #define INCFILE "versN.h"
6433 Forward references: macro replacement (6.10.3).
6434 6.10.3 Macro replacement
6436 1 Two replacement lists are identical if and only if the preprocessing tokens in both have
6437 the same number, ordering, spelling, and white-space separation, where all white-space
6438 separations are considered identical.
6439 2 An identifier currently defined as an object-like macro shall not be redefined by another
6440 #define preprocessing directive unless the second definition is an object-like macro
6441 definition and the two replacement lists are identical. Likewise, an identifier currently
6442 defined as a function-like macro shall not be redefined by another #define
6443 preprocessing directive unless the second definition is a function-like macro definition
6444 that has the same number and spelling of parameters, and the two replacement lists are
6446 3 There shall be white-space between the identifier and the replacement list in the definition
6447 of an object-like macro.
6448 4 If the identifier-list in the macro definition does not end with an ellipsis, the number of
6449 arguments (including those arguments consisting of no preprocessing tokens) in an
6450 invocation of a function-like macro shall equal the number of parameters in the macro
6451 definition. Otherwise, there shall be more arguments in the invocation than there are
6452 parameters in the macro definition (excluding the ...). There shall exist a )
6453 preprocessing token that terminates the invocation.
6454 5 The identifier __VA_ARGS__ shall occur only in the replacement-list of a function-like
6455 macro that uses the ellipsis notation in the parameters.
6456 6 A parameter identifier in a function-like macro shall be uniquely declared within its
6459 7 The identifier immediately following the define is called the macro name. There is one
6460 name space for macro names. Any white-space characters preceding or following the
6461 replacement list of preprocessing tokens are not considered part of the replacement list
6462 for either form of macro.
6466 8 If a # preprocessing token, followed by an identifier, occurs lexically at the point at which
6467 a preprocessing directive could begin, the identifier is not subject to macro replacement.
6468 9 A preprocessing directive of the form
6469 # define identifier replacement-list new-line
6470 defines an object-like macro that causes each subsequent instance of the macro name149)
6471 to be replaced by the replacement list of preprocessing tokens that constitute the
6472 remainder of the directive. The replacement list is then rescanned for more macro names
6474 10 A preprocessing directive of the form
6475 # define identifier lparen identifier-listopt ) replacement-list new-line
6476 # define identifier lparen ... ) replacement-list new-line
6477 # define identifier lparen identifier-list , ... ) replacement-list new-line
6478 defines a function-like macro with parameters, whose use is similar syntactically to a
6479 function call. The parameters are specified by the optional list of identifiers, whose scope
6480 extends from their declaration in the identifier list until the new-line character that
6481 terminates the #define preprocessing directive. Each subsequent instance of the
6482 function-like macro name followed by a ( as the next preprocessing token introduces the
6483 sequence of preprocessing tokens that is replaced by the replacement list in the definition
6484 (an invocation of the macro). The replaced sequence of preprocessing tokens is
6485 terminated by the matching ) preprocessing token, skipping intervening matched pairs of
6486 left and right parenthesis preprocessing tokens. Within the sequence of preprocessing
6487 tokens making up an invocation of a function-like macro, new-line is considered a normal
6488 white-space character.
6489 11 The sequence of preprocessing tokens bounded by the outside-most matching parentheses
6490 forms the list of arguments for the function-like macro. The individual arguments within
6491 the list are separated by comma preprocessing tokens, but comma preprocessing tokens
6492 between matching inner parentheses do not separate arguments. If there are sequences of
6493 preprocessing tokens within the list of arguments that would otherwise act as
6494 preprocessing directives,150) the behavior is undefined.
6495 12 If there is a ... in the identifier-list in the macro definition, then the trailing arguments,
6496 including any separating comma preprocessing tokens, are merged to form a single item:
6497 the variable arguments. The number of arguments so combined is such that, following
6500 149) Since, by macro-replacement time, all character constants and string literals are preprocessing tokens,
6501 not sequences possibly containing identifier-like subsequences (see 5.1.1.2, translation phases), they
6502 are never scanned for macro names or parameters.
6503 150) Despite the name, a non-directive is a preprocessing directive.
6507 merger, the number of arguments is one more than the number of parameters in the macro
6508 definition (excluding the ...).
6509 6.10.3.1 Argument substitution
6510 1 After the arguments for the invocation of a function-like macro have been identified,
6511 argument substitution takes place. A parameter in the replacement list, unless preceded
6512 by a # or ## preprocessing token or followed by a ## preprocessing token (see below), is
6513 replaced by the corresponding argument after all macros contained therein have been
6514 expanded. Before being substituted, each argument's preprocessing tokens are
6515 completely macro replaced as if they formed the rest of the preprocessing file; no other
6516 preprocessing tokens are available.
6517 2 An identifier __VA_ARGS__ that occurs in the replacement list shall be treated as if it
6518 were a parameter, and the variable arguments shall form the preprocessing tokens used to
6520 6.10.3.2 The # operator
6522 1 Each # preprocessing token in the replacement list for a function-like macro shall be
6523 followed by a parameter as the next preprocessing token in the replacement list.
6525 2 If, in the replacement list, a parameter is immediately preceded by a # preprocessing
6526 token, both are replaced by a single character string literal preprocessing token that
6527 contains the spelling of the preprocessing token sequence for the corresponding
6528 argument. Each occurrence of white space between the argument's preprocessing tokens
6529 becomes a single space character in the character string literal. White space before the
6530 first preprocessing token and after the last preprocessing token composing the argument
6531 is deleted. Otherwise, the original spelling of each preprocessing token in the argument
6532 is retained in the character string literal, except for special handling for producing the
6533 spelling of string literals and character constants: a \ character is inserted before each "
6534 and \ character of a character constant or string literal (including the delimiting "
6535 characters), except that it is implementation-defined whether a \ character is inserted
6536 before the \ character beginning a universal character name. If the replacement that
6537 results is not a valid character string literal, the behavior is undefined. The character
6538 string literal corresponding to an empty argument is "". The order of evaluation of # and
6539 ## operators is unspecified.
6546 6.10.3.3 The ## operator
6548 1 A ## preprocessing token shall not occur at the beginning or at the end of a replacement
6549 list for either form of macro definition.
6551 2 If, in the replacement list of a function-like macro, a parameter is immediately preceded
6552 or followed by a ## preprocessing token, the parameter is replaced by the corresponding
6553 argument's preprocessing token sequence; however, if an argument consists of no
6554 preprocessing tokens, the parameter is replaced by a placemarker preprocessing token
6556 3 For both object-like and function-like macro invocations, before the replacement list is
6557 reexamined for more macro names to replace, each instance of a ## preprocessing token
6558 in the replacement list (not from an argument) is deleted and the preceding preprocessing
6559 token is concatenated with the following preprocessing token. Placemarker
6560 preprocessing tokens are handled specially: concatenation of two placemarkers results in
6561 a single placemarker preprocessing token, and concatenation of a placemarker with a
6562 non-placemarker preprocessing token results in the non-placemarker preprocessing token.
6563 If the result is not a valid preprocessing token, the behavior is undefined. The resulting
6564 token is available for further macro replacement. The order of evaluation of ## operators
6566 4 EXAMPLE In the following fragment:
6567 #define hash_hash # ## #
6568 #define mkstr(a) # a
6569 #define in_between(a) mkstr(a)
6570 #define join(c, d) in_between(c hash_hash d)
6571 char p[] = join(x, y); // equivalent to
6572 // char p[] = "x ## y";
6573 The expansion produces, at various stages:
6575 in_between(x hash_hash y)
6579 In other words, expanding hash_hash produces a new token, consisting of two adjacent sharp signs, but
6580 this new token is not the ## operator.
6583 151) Placemarker preprocessing tokens do not appear in the syntax because they are temporary entities that
6584 exist only within translation phase 4.
6588 6.10.3.4 Rescanning and further replacement
6589 1 After all parameters in the replacement list have been substituted and # and ##
6590 processing has taken place, all placemarker preprocessing tokens are removed. Then, the
6591 resulting preprocessing token sequence is rescanned, along with all subsequent
6592 preprocessing tokens of the source file, for more macro names to replace.
6593 2 If the name of the macro being replaced is found during this scan of the replacement list
6594 (not including the rest of the source file's preprocessing tokens), it is not replaced.
6595 Furthermore, if any nested replacements encounter the name of the macro being replaced,
6596 it is not replaced. These nonreplaced macro name preprocessing tokens are no longer
6597 available for further replacement even if they are later (re)examined in contexts in which
6598 that macro name preprocessing token would otherwise have been replaced.
6599 3 The resulting completely macro-replaced preprocessing token sequence is not processed
6600 as a preprocessing directive even if it resembles one, but all pragma unary operator
6601 expressions within it are then processed as specified in 6.10.9 below.
6602 6.10.3.5 Scope of macro definitions
6603 1 A macro definition lasts (independent of block structure) until a corresponding #undef
6604 directive is encountered or (if none is encountered) until the end of the preprocessing
6605 translation unit. Macro definitions have no significance after translation phase 4.
6606 2 A preprocessing directive of the form
6607 # undef identifier new-line
6608 causes the specified identifier no longer to be defined as a macro name. It is ignored if
6609 the specified identifier is not currently defined as a macro name.
6610 3 EXAMPLE 1 The simplest use of this facility is to define a ''manifest constant'', as in
6614 4 EXAMPLE 2 The following defines a function-like macro whose value is the maximum of its arguments.
6615 It has the advantages of working for any compatible types of the arguments and of generating in-line code
6616 without the overhead of function calling. It has the disadvantages of evaluating one or the other of its
6617 arguments a second time (including side effects) and generating more code than a function if invoked
6618 several times. It also cannot have its address taken, as it has none.
6619 #define max(a, b) ((a) > (b) ? (a) : (b))
6620 The parentheses ensure that the arguments and the resulting expression are bound properly.
6627 5 EXAMPLE 3 To illustrate the rules for redefinition and reexamination, the sequence
6629 #define f(a) f(x * (a))
6640 #define r(x,y) x ## y
6642 f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
6643 g(x+(3,4)-w) | h 5) & m
6645 p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
6646 char c[2][6] = { str(hello), str() };
6648 f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
6649 f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
6650 int i[] = { 1, 23, 4, 5, };
6651 char c[2][6] = { "hello", "" };
6653 6 EXAMPLE 4 To illustrate the rules for creating character string literals and concatenating tokens, the
6656 #define xstr(s) str(s)
6657 #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \
6659 #define INCFILE(n) vers ## n
6660 #define glue(a, b) a ## b
6661 #define xglue(a, b) glue(a, b)
6662 #define HIGHLOW "hello"
6663 #define LOW LOW ", world"
6665 fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away
6666 == 0) str(: @\n), s);
6667 #include xstr(INCFILE(2).h)
6677 printf("x" "1" "= %d, x" "2" "= %s", x1, x2);
6679 "strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n",
6681 #include "vers2.h" (after macro replacement, before file access)
6684 or, after concatenation of the character string literals,
6685 printf("x1= %d, x2= %s", x1, x2);
6687 "strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: @\n",
6689 #include "vers2.h" (after macro replacement, before file access)
6692 Space around the # and ## tokens in the macro definition is optional.
6694 7 EXAMPLE 5 To illustrate the rules for placemarker preprocessing tokens, the sequence
6695 #define t(x,y,z) x ## y ## z
6696 int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
6697 t(10,,), t(,11,), t(,,12), t(,,) };
6699 int j[] = { 123, 45, 67, 89,
6702 8 EXAMPLE 6 To demonstrate the redefinition rules, the following sequence is valid.
6703 #define OBJ_LIKE (1-1)
6704 #define OBJ_LIKE /* white space */ (1-1) /* other */
6705 #define FUNC_LIKE(a) ( a )
6706 #define FUNC_LIKE( a )( /* note the white space */ \
6707 a /* other stuff on this line
6709 But the following redefinitions are invalid:
6710 #define OBJ_LIKE (0) // different token sequence
6711 #define OBJ_LIKE (1 - 1) // different white space
6712 #define FUNC_LIKE(b) ( a ) // different parameter usage
6713 #define FUNC_LIKE(b) ( b ) // different parameter spelling
6715 9 EXAMPLE 7 Finally, to show the variable argument list macro facilities:
6716 #define debug(...) fprintf(stderr, __VA_ARGS__)
6717 #define showlist(...) puts(#__VA_ARGS__)
6718 #define report(test, ...) ((test)?puts(#test):\
6719 printf(__VA_ARGS__))
6721 debug("X = %d\n", x);
6722 showlist(The first, second, and third items.);
6723 report(x>y, "x is %d but y is %d", x, y);
6729 fprintf(stderr, "Flag" );
6730 fprintf(stderr, "X = %d\n", x );
6731 puts( "The first, second, and third items." );
6733 printf("x is %d but y is %d", x, y));
6737 1 The string literal of a #line directive, if present, shall be a character string literal.
6739 2 The line number of the current source line is one greater than the number of new-line
6740 characters read or introduced in translation phase 1 (5.1.1.2) while processing the source
6741 file to the current token.
6742 3 A preprocessing directive of the form
6743 # line digit-sequence new-line
6744 causes the implementation to behave as if the following sequence of source lines begins
6745 with a source line that has a line number as specified by the digit sequence (interpreted as
6746 a decimal integer). The digit sequence shall not specify zero, nor a number greater than
6748 4 A preprocessing directive of the form
6749 # line digit-sequence "s-char-sequenceopt" new-line
6750 sets the presumed line number similarly and changes the presumed name of the source
6751 file to be the contents of the character string literal.
6752 5 A preprocessing directive of the form
6753 # line pp-tokens new-line
6754 (that does not match one of the two previous forms) is permitted. The preprocessing
6755 tokens after line on the directive are processed just as in normal text (each identifier
6756 currently defined as a macro name is replaced by its replacement list of preprocessing
6757 tokens). The directive resulting after all replacements shall match one of the two
6758 previous forms and is then processed as appropriate.
6765 6.10.5 Error directive
6767 1 A preprocessing directive of the form
6768 # error pp-tokensopt new-line
6769 causes the implementation to produce a diagnostic message that includes the specified
6770 sequence of preprocessing tokens.
6771 6.10.6 Pragma directive
6773 1 A preprocessing directive of the form
6774 # pragma pp-tokensopt new-line
6775 where the preprocessing token STDC does not immediately follow pragma in the
6776 directive (prior to any macro replacement)152) causes the implementation to behave in an
6777 implementation-defined manner. The behavior might cause translation to fail or cause the
6778 translator or the resulting program to behave in a non-conforming manner. Any such
6779 pragma that is not recognized by the implementation is ignored.
6780 2 If the preprocessing token STDC does immediately follow pragma in the directive (prior
6781 to any macro replacement), then no macro replacement is performed on the directive, and
6782 the directive shall have one of the following forms153) whose meanings are described
6784 #pragma STDC FP_CONTRACT on-off-switch
6785 #pragma STDC FENV_ACCESS on-off-switch
6786 #pragma STDC CX_LIMITED_RANGE on-off-switch
6787 on-off-switch: one of
6789 Forward references: the FP_CONTRACT pragma (7.12.2), the FENV_ACCESS pragma
6790 (7.6.1), the CX_LIMITED_RANGE pragma (7.3.4).
6795 152) An implementation is not required to perform macro replacement in pragmas, but it is permitted
6796 except for in standard pragmas (where STDC immediately follows pragma). If the result of macro
6797 replacement in a non-standard pragma has the same form as a standard pragma, the behavior is still
6798 implementation-defined; an implementation is permitted to behave as if it were the standard pragma,
6799 but is not required to.
6800 153) See ''future language directions'' (6.11.8).
6804 6.10.7 Null directive
6806 1 A preprocessing directive of the form
6809 6.10.8 Predefined macro names
6810 1 The following macro names154) shall be defined by the implementation:
6811 __DATE__ The date of translation of the preprocessing translation unit: a character
6812 string literal of the form "Mmm dd yyyy", where the names of the
6813 months are the same as those generated by the asctime function, and the
6814 first character of dd is a space character if the value is less than 10. If the
6815 date of translation is not available, an implementation-defined valid date
6817 __FILE__ The presumed name of the current source file (a character string literal).155)
6818 __LINE__ The presumed line number (within the current source file) of the current
6819 source line (an integer constant).155)
6820 __STDC__ The integer constant 1, intended to indicate a conforming implementation.
6821 __STDC_HOSTED__ The integer constant 1 if the implementation is a hosted
6822 implementation or the integer constant 0 if it is not.
6823 __STDC_MB_MIGHT_NEQ_WC__ The integer constant 1, intended to indicate that, in
6824 the encoding for wchar_t, a member of the basic character set need not
6825 have a code value equal to its value when used as the lone character in an
6826 integer character constant.
6827 __STDC_VERSION__ The integer constant 199901L.156)
6828 __TIME__ The time of translation of the preprocessing translation unit: a character
6829 string literal of the form "hh:mm:ss" as in the time generated by the
6830 asctime function. If the time of translation is not available, an
6831 implementation-defined valid time shall be supplied.
6835 154) See ''future language directions'' (6.11.9).
6836 155) The presumed source file name and line number can be changed by the #line directive.
6837 156) This macro was not specified in ISO/IEC 9899:1990 and was specified as 199409L in
6838 ISO/IEC 9899/AMD1:1995. The intention is that this will remain an integer constant of type long
6839 int that is increased with each revision of this International Standard.
6843 2 The following macro names are conditionally defined by the implementation:
6844 __STDC_IEC_559__ The integer constant 1, intended to indicate conformance to the
6845 specifications in annex F (IEC 60559 floating-point arithmetic).
6846 __STDC_IEC_559_COMPLEX__ The integer constant 1, intended to indicate
6847 adherence to the specifications in informative annex G (IEC 60559
6848 compatible complex arithmetic).
6849 __STDC_ISO_10646__ An integer constant of the form yyyymmL (for example,
6850 199712L). If this symbol is defined, then every character in the Unicode
6851 required set, when stored in an object of type wchar_t, has the same
6852 value as the short identifier of that character. The Unicode required set
6853 consists of all the characters that are defined by ISO/IEC 10646, along with
6854 all amendments and technical corrigenda, as of the specified year and
6856 3 The values of the predefined macros (except for __FILE__ and __LINE__) remain
6857 constant throughout the translation unit.
6858 4 None of these macro names, nor the identifier defined, shall be the subject of a
6859 #define or a #undef preprocessing directive. Any other predefined macro names
6860 shall begin with a leading underscore followed by an uppercase letter or a second
6862 5 The implementation shall not predefine the macro __cplusplus, nor shall it define it
6863 in any standard header.
6864 Forward references: the asctime function (7.23.3.1), standard headers (7.1.2).
6865 6.10.9 Pragma operator
6867 1 A unary operator expression of the form:
6868 _Pragma ( string-literal )
6869 is processed as follows: The string literal is destringized by deleting the L prefix, if
6870 present, deleting the leading and trailing double-quotes, replacing each escape sequence
6871 \" by a double-quote, and replacing each escape sequence \\ by a single backslash. The
6872 resulting sequence of characters is processed through translation phase 3 to produce
6873 preprocessing tokens that are executed as if they were the pp-tokens in a pragma
6874 directive. The original four preprocessing tokens in the unary operator expression are
6876 2 EXAMPLE A directive of the form:
6877 #pragma listing on "..\listing.dir"
6878 can also be expressed as:
6881 _Pragma ( "listing on \"..\\listing.dir\"" )
6882 The latter form is processed in the same way whether it appears literally as shown, or results from macro
6884 #define LISTING(x) PRAGMA(listing on #x)
6885 #define PRAGMA(x) _Pragma(#x)
6886 LISTING ( ..\listing.dir )
6893 6.11 Future language directions
6894 6.11.1 Floating types
6895 1 Future standardization may include additional floating-point types, including those with
6896 greater range, precision, or both than long double.
6897 6.11.2 Linkages of identifiers
6898 1 Declaring an identifier with internal linkage at file scope without the static storage-
6899 class specifier is an obsolescent feature.
6900 6.11.3 External names
6901 1 Restriction of the significance of an external name to fewer than 255 characters
6902 (considering each universal character name or extended source character as a single
6903 character) is an obsolescent feature that is a concession to existing implementations.
6904 6.11.4 Character escape sequences
6905 1 Lowercase letters as escape sequences are reserved for future standardization. Other
6906 characters may be used in extensions.
6907 6.11.5 Storage-class specifiers
6908 1 The placement of a storage-class specifier other than at the beginning of the declaration
6909 specifiers in a declaration is an obsolescent feature.
6910 6.11.6 Function declarators
6911 1 The use of function declarators with empty parentheses (not prototype-format parameter
6912 type declarators) is an obsolescent feature.
6913 6.11.7 Function definitions
6914 1 The use of function definitions with separate parameter identifier and declaration lists
6915 (not prototype-format parameter type and identifier declarators) is an obsolescent feature.
6916 6.11.8 Pragma directives
6917 1 Pragmas whose first preprocessing token is STDC are reserved for future standardization.
6918 6.11.9 Predefined macro names
6919 1 Macro names beginning with __STDC_ are reserved for future standardization.
6930 7.1.1 Definitions of terms
6931 1 A string is a contiguous sequence of characters terminated by and including the first null
6932 character. The term multibyte string is sometimes used instead to emphasize special
6933 processing given to multibyte characters contained in the string or to avoid confusion
6934 with a wide string. A pointer to a string is a pointer to its initial (lowest addressed)
6935 character. The length of a string is the number of bytes preceding the null character and
6936 the value of a string is the sequence of the values of the contained characters, in order.
6937 2 The decimal-point character is the character used by functions that convert floating-point
6938 numbers to or from character sequences to denote the beginning of the fractional part of
6939 such character sequences.157) It is represented in the text and examples by a period, but
6940 may be changed by the setlocale function.
6941 3 A null wide character is a wide character with code value zero.
6942 4 A wide string is a contiguous sequence of wide characters terminated by and including
6943 the first null wide character. A pointer to a wide string is a pointer to its initial (lowest
6944 addressed) wide character. The length of a wide string is the number of wide characters
6945 preceding the null wide character and the value of a wide string is the sequence of code
6946 values of the contained wide characters, in order.
6947 5 A shift sequence is a contiguous sequence of bytes within a multibyte string that
6948 (potentially) causes a change in shift state (see 5.2.1.2). A shift sequence shall not have a
6949 corresponding wide character; it is instead taken to be an adjunct to an adjacent multibyte
6951 Forward references: character handling (7.4), the setlocale function (7.11.1.1).
6956 157) The functions that make use of the decimal-point character are the numeric conversion functions
6957 (7.20.1, 7.24.4.1) and the formatted input/output functions (7.19.6, 7.24.2).
6958 158) For state-dependent encodings, the values for MB_CUR_MAX and MB_LEN_MAX shall thus be large
6959 enough to count all the bytes in any complete multibyte character plus at least one adjacent shift
6960 sequence of maximum length. Whether these counts provide for more than one shift sequence is the
6961 implementation's choice.
6965 7.1.2 Standard headers
6966 1 Each library function is declared, with a type that includes a prototype, in a header,159)
6967 whose contents are made available by the #include preprocessing directive. The
6968 header declares a set of related functions, plus any necessary types and additional macros
6969 needed to facilitate their use. Declarations of types described in this clause shall not
6970 include type qualifiers, unless explicitly stated otherwise.
6971 2 The standard headers are
6972 <assert.h> <inttypes.h> <signal.h> <stdlib.h>
6973 <complex.h> <iso646.h> <stdarg.h> <string.h>
6974 <ctype.h> <limits.h> <stdbool.h> <tgmath.h>
6975 <errno.h> <locale.h> <stddef.h> <time.h>
6976 <fenv.h> <math.h> <stdint.h> <wchar.h>
6977 <float.h> <setjmp.h> <stdio.h> <wctype.h>
6978 3 If a file with the same name as one of the above < and > delimited sequences, not
6979 provided as part of the implementation, is placed in any of the standard places that are
6980 searched for included source files, the behavior is undefined.
6981 4 Standard headers may be included in any order; each may be included more than once in
6982 a given scope, with no effect different from being included only once, except that the
6983 effect of including <assert.h> depends on the definition of NDEBUG (see 7.2). If
6984 used, a header shall be included outside of any external declaration or definition, and it
6985 shall first be included before the first reference to any of the functions or objects it
6986 declares, or to any of the types or macros it defines. However, if an identifier is declared
6987 or defined in more than one header, the second and subsequent associated headers may be
6988 included after the initial reference to the identifier. The program shall not have any
6989 macros with names lexically identical to keywords currently defined prior to the
6991 5 Any definition of an object-like macro described in this clause shall expand to code that is
6992 fully protected by parentheses where necessary, so that it groups in an arbitrary
6993 expression as if it were a single identifier.
6994 6 Any declaration of a library function shall have external linkage.
6995 7 A summary of the contents of the standard headers is given in annex B.
6996 Forward references: diagnostics (7.2).
7001 159) A header is not necessarily a source file, nor are the < and > delimited sequences in header names
7002 necessarily valid source file names.
7006 7.1.3 Reserved identifiers
7007 1 Each header declares or defines all identifiers listed in its associated subclause, and
7008 optionally declares or defines identifiers listed in its associated future library directions
7009 subclause and identifiers which are always reserved either for any use or for use as file
7011 -- All identifiers that begin with an underscore and either an uppercase letter or another
7012 underscore are always reserved for any use.
7013 -- All identifiers that begin with an underscore are always reserved for use as identifiers
7014 with file scope in both the ordinary and tag name spaces.
7015 -- Each macro name in any of the following subclauses (including the future library
7016 directions) is reserved for use as specified if any of its associated headers is included;
7017 unless explicitly stated otherwise (see 7.1.4).
7018 -- All identifiers with external linkage in any of the following subclauses (including the
7019 future library directions) are always reserved for use as identifiers with external
7021 -- Each identifier with file scope listed in any of the following subclauses (including the
7022 future library directions) is reserved for use as a macro name and as an identifier with
7023 file scope in the same name space if any of its associated headers is included.
7024 2 No other identifiers are reserved. If the program declares or defines an identifier in a
7025 context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved
7026 identifier as a macro name, the behavior is undefined.
7027 3 If the program removes (with #undef) any macro definition of an identifier in the first
7028 group listed above, the behavior is undefined.
7029 7.1.4 Use of library functions
7030 1 Each of the following statements applies unless explicitly stated otherwise in the detailed
7031 descriptions that follow: If an argument to a function has an invalid value (such as a value
7032 outside the domain of the function, or a pointer outside the address space of the program,
7033 or a null pointer, or a pointer to non-modifiable storage when the corresponding
7034 parameter is not const-qualified) or a type (after promotion) not expected by a function
7035 with variable number of arguments, the behavior is undefined. If a function argument is
7036 described as being an array, the pointer actually passed to the function shall have a value
7037 such that all address computations and accesses to objects (that would be valid if the
7038 pointer did point to the first element of such an array) are in fact valid. Any function
7039 declared in a header may be additionally implemented as a function-like macro defined in
7041 160) The list of reserved identifiers with external linkage includes errno, math_errhandling,
7046 the header, so if a library function is declared explicitly when its header is included, one
7047 of the techniques shown below can be used to ensure the declaration is not affected by
7048 such a macro. Any macro definition of a function can be suppressed locally by enclosing
7049 the name of the function in parentheses, because the name is then not followed by the left
7050 parenthesis that indicates expansion of a macro function name. For the same syntactic
7051 reason, it is permitted to take the address of a library function even if it is also defined as
7052 a macro.161) The use of #undef to remove any macro definition will also ensure that an
7053 actual function is referred to. Any invocation of a library function that is implemented as
7054 a macro shall expand to code that evaluates each of its arguments exactly once, fully
7055 protected by parentheses where necessary, so it is generally safe to use arbitrary
7056 expressions as arguments.162) Likewise, those function-like macros described in the
7057 following subclauses may be invoked in an expression anywhere a function with a
7058 compatible return type could be called.163) All object-like macros listed as expanding to
7059 integer constant expressions shall additionally be suitable for use in #if preprocessing
7061 2 Provided that a library function can be declared without reference to any type defined in a
7062 header, it is also permissible to declare the function and use it without including its
7064 3 There is a sequence point immediately before a library function returns.
7065 4 The functions in the standard library are not guaranteed to be reentrant and may modify
7066 objects with static storage duration.164)
7070 161) This means that an implementation shall provide an actual function for each library function, even if it
7071 also provides a macro for that function.
7072 162) Such macros might not contain the sequence points that the corresponding function calls do.
7073 163) Because external identifiers and some macro names beginning with an underscore are reserved,
7074 implementations may provide special semantics for such names. For example, the identifier
7075 _BUILTIN_abs could be used to indicate generation of in-line code for the abs function. Thus, the
7076 appropriate header could specify
7077 #define abs(x) _BUILTIN_abs(x)
7078 for a compiler whose code generator will accept it.
7079 In this manner, a user desiring to guarantee that a given library function such as abs will be a genuine
7082 whether the implementation's header provides a macro implementation of abs or a built-in
7083 implementation. The prototype for the function, which precedes and is hidden by any macro
7084 definition, is thereby revealed also.
7085 164) Thus, a signal handler cannot, in general, call standard library functions.
7089 5 EXAMPLE The function atoi may be used in any of several ways:
7090 -- by use of its associated header (possibly generating a macro expansion)
7095 -- by use of its associated header (assuredly generating a true function reference)
7106 -- by explicit declaration
7107 extern int atoi(const char *);
7117 7.2 Diagnostics <assert.h>
7118 1 The header <assert.h> defines the assert macro and refers to another macro,
7120 which is not defined by <assert.h>. If NDEBUG is defined as a macro name at the
7121 point in the source file where <assert.h> is included, the assert macro is defined
7123 #define assert(ignore) ((void)0)
7124 The assert macro is redefined according to the current state of NDEBUG each time that
7125 <assert.h> is included.
7126 2 The assert macro shall be implemented as a macro, not as an actual function. If the
7127 macro definition is suppressed in order to access an actual function, the behavior is
7129 7.2.1 Program diagnostics
7130 7.2.1.1 The assert macro
7132 1 #include <assert.h>
7133 void assert(scalar expression);
7135 2 The assert macro puts diagnostic tests into programs; it expands to a void expression.
7136 When it is executed, if expression (which shall have a scalar type) is false (that is,
7137 compares equal to 0), the assert macro writes information about the particular call that
7138 failed (including the text of the argument, the name of the source file, the source line
7139 number, and the name of the enclosing function -- the latter are respectively the values of
7140 the preprocessing macros __FILE__ and __LINE__ and of the identifier
7141 __func__) on the standard error stream in an implementation-defined format.165) It
7142 then calls the abort function.
7144 3 The assert macro returns no value.
7145 Forward references: the abort function (7.20.4.1).
7150 165) The message written might be of the form:
7151 Assertion failed: expression, function abc, file xyz, line nnn.
7156 7.3 Complex arithmetic <complex.h>
7158 1 The header <complex.h> defines macros and declares functions that support complex
7159 arithmetic.166) Each synopsis specifies a family of functions consisting of a principal
7160 function with one or more double complex parameters and a double complex or
7161 double return value; and other functions with the same name but with f and l suffixes
7162 which are corresponding functions with float and long double parameters and
7166 expands to _Complex; the macro
7168 expands to a constant expression of type const float _Complex, with the value of
7169 the imaginary unit.167)
7174 are defined if and only if the implementation supports imaginary types;168) if defined,
7175 they expand to _Imaginary and a constant expression of type const float
7176 _Imaginary with the value of the imaginary unit.
7179 expands to either _Imaginary_I or _Complex_I. If _Imaginary_I is not
7180 defined, I shall expand to _Complex_I.
7181 5 Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then
7182 redefine the macros complex, imaginary, and I.
7183 Forward references: IEC 60559-compatible complex arithmetic (annex G).
7187 166) See ''future library directions'' (7.26.1).
7188 167) The imaginary unit is a number i such that i 2 = -1.
7189 168) A specification for imaginary types is in informative annex G.
7194 1 Values are interpreted as radians, not degrees. An implementation may set errno but is
7197 1 Some of the functions below have branch cuts, across which the function is
7198 discontinuous. For implementations with a signed zero (including all IEC 60559
7199 implementations) that follow the specifications of annex G, the sign of zero distinguishes
7200 one side of a cut from another so the function is continuous (except for format
7201 limitations) as the cut is approached from either side. For example, for the square root
7202 function, which has a branch cut along the negative real axis, the top of the cut, with
7203 imaginary part +0, maps to the positive imaginary axis, and the bottom of the cut, with
7204 imaginary part -0, maps to the negative imaginary axis.
7205 2 Implementations that do not support a signed zero (see annex F) cannot distinguish the
7206 sides of branch cuts. These implementations shall map a cut so the function is continuous
7207 as the cut is approached coming around the finite endpoint of the cut in a counter
7208 clockwise direction. (Branch cuts for the functions specified here have just one finite
7209 endpoint.) For example, for the square root function, coming counter clockwise around
7210 the finite endpoint of the cut along the negative real axis approaches the cut from above,
7211 so the cut maps to the positive imaginary axis.
7212 7.3.4 The CX_LIMITED_RANGE pragma
7214 1 #include <complex.h>
7215 #pragma STDC CX_LIMITED_RANGE on-off-switch
7217 2 The usual mathematical formulas for complex multiply, divide, and absolute value are
7218 problematic because of their treatment of infinities and because of undue overflow and
7219 underflow. The CX_LIMITED_RANGE pragma can be used to inform the
7220 implementation that (where the state is ''on'') the usual mathematical formulas are
7221 acceptable.169) The pragma can occur either outside external declarations or preceding all
7222 explicit declarations and statements inside a compound statement. When outside external
7224 169) The purpose of the pragma is to allow the implementation to use the formulas:
7225 (x + iy) x (u + iv) = (xu - yv) + i(yu + xv)
7226 (x + iy) / (u + iv) = [(xu + yv) + i(yu - xv)]/(u2 + v 2 )
7227 | x + iy | = sqrt: x 2 + y 2
7229 where the programmer can determine they are safe.
7233 declarations, the pragma takes effect from its occurrence until another
7234 CX_LIMITED_RANGE pragma is encountered, or until the end of the translation unit.
7235 When inside a compound statement, the pragma takes effect from its occurrence until
7236 another CX_LIMITED_RANGE pragma is encountered (including within a nested
7237 compound statement), or until the end of the compound statement; at the end of a
7238 compound statement the state for the pragma is restored to its condition just before the
7239 compound statement. If this pragma is used in any other context, the behavior is
7240 undefined. The default state for the pragma is ''off''.
7241 7.3.5 Trigonometric functions
7242 7.3.5.1 The cacos functions
7244 1 #include <complex.h>
7245 double complex cacos(double complex z);
7246 float complex cacosf(float complex z);
7247 long double complex cacosl(long double complex z);
7249 2 The cacos functions compute the complex arc cosine of z, with branch cuts outside the
7250 interval [-1, +1] along the real axis.
7252 3 The cacos functions return the complex arc cosine value, in the range of a strip
7253 mathematically unbounded along the imaginary axis and in the interval [0, pi ] along the
7255 7.3.5.2 The casin functions
7257 1 #include <complex.h>
7258 double complex casin(double complex z);
7259 float complex casinf(float complex z);
7260 long double complex casinl(long double complex z);
7262 2 The casin functions compute the complex arc sine of z, with branch cuts outside the
7263 interval [-1, +1] along the real axis.
7265 3 The casin functions return the complex arc sine value, in the range of a strip
7266 mathematically unbounded along the imaginary axis and in the interval [-pi /2, +pi /2]
7267 along the real axis.
7271 7.3.5.3 The catan functions
7273 1 #include <complex.h>
7274 double complex catan(double complex z);
7275 float complex catanf(float complex z);
7276 long double complex catanl(long double complex z);
7278 2 The catan functions compute the complex arc tangent of z, with branch cuts outside the
7279 interval [-i, +i] along the imaginary axis.
7281 3 The catan functions return the complex arc tangent value, in the range of a strip
7282 mathematically unbounded along the imaginary axis and in the interval [-pi /2, +pi /2]
7283 along the real axis.
7284 7.3.5.4 The ccos functions
7286 1 #include <complex.h>
7287 double complex ccos(double complex z);
7288 float complex ccosf(float complex z);
7289 long double complex ccosl(long double complex z);
7291 2 The ccos functions compute the complex cosine of z.
7293 3 The ccos functions return the complex cosine value.
7294 7.3.5.5 The csin functions
7296 1 #include <complex.h>
7297 double complex csin(double complex z);
7298 float complex csinf(float complex z);
7299 long double complex csinl(long double complex z);
7301 2 The csin functions compute the complex sine of z.
7303 3 The csin functions return the complex sine value.
7307 7.3.5.6 The ctan functions
7309 1 #include <complex.h>
7310 double complex ctan(double complex z);
7311 float complex ctanf(float complex z);
7312 long double complex ctanl(long double complex z);
7314 2 The ctan functions compute the complex tangent of z.
7316 3 The ctan functions return the complex tangent value.
7317 7.3.6 Hyperbolic functions
7318 7.3.6.1 The cacosh functions
7320 1 #include <complex.h>
7321 double complex cacosh(double complex z);
7322 float complex cacoshf(float complex z);
7323 long double complex cacoshl(long double complex z);
7325 2 The cacosh functions compute the complex arc hyperbolic cosine of z, with a branch
7326 cut at values less than 1 along the real axis.
7328 3 The cacosh functions return the complex arc hyperbolic cosine value, in the range of a
7329 half-strip of non-negative values along the real axis and in the interval [-ipi , +ipi ] along
7331 7.3.6.2 The casinh functions
7333 1 #include <complex.h>
7334 double complex casinh(double complex z);
7335 float complex casinhf(float complex z);
7336 long double complex casinhl(long double complex z);
7338 2 The casinh functions compute the complex arc hyperbolic sine of z, with branch cuts
7339 outside the interval [-i, +i] along the imaginary axis.
7345 3 The casinh functions return the complex arc hyperbolic sine value, in the range of a
7346 strip mathematically unbounded along the real axis and in the interval [-ipi /2, +ipi /2]
7347 along the imaginary axis.
7348 7.3.6.3 The catanh functions
7350 1 #include <complex.h>
7351 double complex catanh(double complex z);
7352 float complex catanhf(float complex z);
7353 long double complex catanhl(long double complex z);
7355 2 The catanh functions compute the complex arc hyperbolic tangent of z, with branch
7356 cuts outside the interval [-1, +1] along the real axis.
7358 3 The catanh functions return the complex arc hyperbolic tangent value, in the range of a
7359 strip mathematically unbounded along the real axis and in the interval [-ipi /2, +ipi /2]
7360 along the imaginary axis.
7361 7.3.6.4 The ccosh functions
7363 1 #include <complex.h>
7364 double complex ccosh(double complex z);
7365 float complex ccoshf(float complex z);
7366 long double complex ccoshl(long double complex z);
7368 2 The ccosh functions compute the complex hyperbolic cosine of z.
7370 3 The ccosh functions return the complex hyperbolic cosine value.
7371 7.3.6.5 The csinh functions
7373 1 #include <complex.h>
7374 double complex csinh(double complex z);
7375 float complex csinhf(float complex z);
7376 long double complex csinhl(long double complex z);
7382 2 The csinh functions compute the complex hyperbolic sine of z.
7384 3 The csinh functions return the complex hyperbolic sine value.
7385 7.3.6.6 The ctanh functions
7387 1 #include <complex.h>
7388 double complex ctanh(double complex z);
7389 float complex ctanhf(float complex z);
7390 long double complex ctanhl(long double complex z);
7392 2 The ctanh functions compute the complex hyperbolic tangent of z.
7394 3 The ctanh functions return the complex hyperbolic tangent value.
7395 7.3.7 Exponential and logarithmic functions
7396 7.3.7.1 The cexp functions
7398 1 #include <complex.h>
7399 double complex cexp(double complex z);
7400 float complex cexpf(float complex z);
7401 long double complex cexpl(long double complex z);
7403 2 The cexp functions compute the complex base-e exponential of z.
7405 3 The cexp functions return the complex base-e exponential value.
7406 7.3.7.2 The clog functions
7408 1 #include <complex.h>
7409 double complex clog(double complex z);
7410 float complex clogf(float complex z);
7411 long double complex clogl(long double complex z);
7418 2 The clog functions compute the complex natural (base-e) logarithm of z, with a branch
7419 cut along the negative real axis.
7421 3 The clog functions return the complex natural logarithm value, in the range of a strip
7422 mathematically unbounded along the real axis and in the interval [-ipi , +ipi ] along the
7424 7.3.8 Power and absolute-value functions
7425 7.3.8.1 The cabs functions
7427 1 #include <complex.h>
7428 double cabs(double complex z);
7429 float cabsf(float complex z);
7430 long double cabsl(long double complex z);
7432 2 The cabs functions compute the complex absolute value (also called norm, modulus, or
7435 3 The cabs functions return the complex absolute value.
7436 7.3.8.2 The cpow functions
7438 1 #include <complex.h>
7439 double complex cpow(double complex x, double complex y);
7440 float complex cpowf(float complex x, float complex y);
7441 long double complex cpowl(long double complex x,
7442 long double complex y);
7444 2 The cpow functions compute the complex power function xy , with a branch cut for the
7445 first parameter along the negative real axis.
7447 3 The cpow functions return the complex power function value.
7454 7.3.8.3 The csqrt functions
7456 1 #include <complex.h>
7457 double complex csqrt(double complex z);
7458 float complex csqrtf(float complex z);
7459 long double complex csqrtl(long double complex z);
7461 2 The csqrt functions compute the complex square root of z, with a branch cut along the
7464 3 The csqrt functions return the complex square root value, in the range of the right half-
7465 plane (including the imaginary axis).
7466 7.3.9 Manipulation functions
7467 7.3.9.1 The carg functions
7469 1 #include <complex.h>
7470 double carg(double complex z);
7471 float cargf(float complex z);
7472 long double cargl(long double complex z);
7474 2 The carg functions compute the argument (also called phase angle) of z, with a branch
7475 cut along the negative real axis.
7477 3 The carg functions return the value of the argument in the interval [-pi , +pi ].
7478 7.3.9.2 The cimag functions
7480 1 #include <complex.h>
7481 double cimag(double complex z);
7482 float cimagf(float complex z);
7483 long double cimagl(long double complex z);
7491 2 The cimag functions compute the imaginary part of z.170)
7493 3 The cimag functions return the imaginary part value (as a real).
7494 7.3.9.3 The conj functions
7496 1 #include <complex.h>
7497 double complex conj(double complex z);
7498 float complex conjf(float complex z);
7499 long double complex conjl(long double complex z);
7501 2 The conj functions compute the complex conjugate of z, by reversing the sign of its
7504 3 The conj functions return the complex conjugate value.
7505 7.3.9.4 The cproj functions
7507 1 #include <complex.h>
7508 double complex cproj(double complex z);
7509 float complex cprojf(float complex z);
7510 long double complex cprojl(long double complex z);
7512 2 The cproj functions compute a projection of z onto the Riemann sphere: z projects to
7513 z except that all complex infinities (even those with one infinite part and one NaN part)
7514 project to positive infinity on the real axis. If z has an infinite part, then cproj(z) is
7516 INFINITY + I * copysign(0.0, cimag(z))
7518 3 The cproj functions return the value of the projection onto the Riemann sphere.
7523 170) For a variable z of complex type, z == creal(z) + cimag(z)*I.
7527 7.3.9.5 The creal functions
7529 1 #include <complex.h>
7530 double creal(double complex z);
7531 float crealf(float complex z);
7532 long double creall(long double complex z);
7534 2 The creal functions compute the real part of z.171)
7536 3 The creal functions return the real part value.
7541 171) For a variable z of complex type, z == creal(z) + cimag(z)*I.
7545 7.4 Character handling <ctype.h>
7546 1 The header <ctype.h> declares several functions useful for classifying and mapping
7547 characters.172) In all cases the argument is an int, the value of which shall be
7548 representable as an unsigned char or shall equal the value of the macro EOF. If the
7549 argument has any other value, the behavior is undefined.
7550 2 The behavior of these functions is affected by the current locale. Those functions that
7551 have locale-specific aspects only when not in the "C" locale are noted below.
7552 3 The term printing character refers to a member of a locale-specific set of characters, each
7553 of which occupies one printing position on a display device; the term control character
7554 refers to a member of a locale-specific set of characters that are not printing
7555 characters.173) All letters and digits are printing characters.
7556 Forward references: EOF (7.19.1), localization (7.11).
7557 7.4.1 Character classification functions
7558 1 The functions in this subclause return nonzero (true) if and only if the value of the
7559 argument c conforms to that in the description of the function.
7560 7.4.1.1 The isalnum function
7562 1 #include <ctype.h>
7565 2 The isalnum function tests for any character for which isalpha or isdigit is true.
7566 7.4.1.2 The isalpha function
7568 1 #include <ctype.h>
7571 2 The isalpha function tests for any character for which isupper or islower is true,
7572 or any character that is one of a locale-specific set of alphabetic characters for which
7576 172) See ''future library directions'' (7.26.2).
7577 173) In an implementation that uses the seven-bit US ASCII character set, the printing characters are those
7578 whose values lie from 0x20 (space) through 0x7E (tilde); the control characters are those whose
7579 values lie from 0 (NUL) through 0x1F (US), and the character 0x7F (DEL).
7583 none of iscntrl, isdigit, ispunct, or isspace is true.174) In the "C" locale,
7584 isalpha returns true only for the characters for which isupper or islower is true.
7585 7.4.1.3 The isblank function
7587 1 #include <ctype.h>
7590 2 The isblank function tests for any character that is a standard blank character or is one
7591 of a locale-specific set of characters for which isspace is true and that is used to
7592 separate words within a line of text. The standard blank characters are the following:
7593 space (' '), and horizontal tab ('\t'). In the "C" locale, isblank returns true only
7594 for the standard blank characters.
7595 7.4.1.4 The iscntrl function
7597 1 #include <ctype.h>
7600 2 The iscntrl function tests for any control character.
7601 7.4.1.5 The isdigit function
7603 1 #include <ctype.h>
7606 2 The isdigit function tests for any decimal-digit character (as defined in 5.2.1).
7607 7.4.1.6 The isgraph function
7609 1 #include <ctype.h>
7615 174) The functions islower and isupper test true or false separately for each of these additional
7616 characters; all four combinations are possible.
7621 2 The isgraph function tests for any printing character except space (' ').
7622 7.4.1.7 The islower function
7624 1 #include <ctype.h>
7627 2 The islower function tests for any character that is a lowercase letter or is one of a
7628 locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or
7629 isspace is true. In the "C" locale, islower returns true only for the lowercase
7630 letters (as defined in 5.2.1).
7631 7.4.1.8 The isprint function
7633 1 #include <ctype.h>
7636 2 The isprint function tests for any printing character including space (' ').
7637 7.4.1.9 The ispunct function
7639 1 #include <ctype.h>
7642 2 The ispunct function tests for any printing character that is one of a locale-specific set
7643 of punctuation characters for which neither isspace nor isalnum is true. In the "C"
7644 locale, ispunct returns true for every printing character for which neither isspace
7645 nor isalnum is true.
7646 7.4.1.10 The isspace function
7648 1 #include <ctype.h>
7651 2 The isspace function tests for any character that is a standard white-space character or
7652 is one of a locale-specific set of characters for which isalnum is false. The standard
7656 white-space characters are the following: space (' '), form feed ('\f'), new-line
7657 ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). In the
7658 "C" locale, isspace returns true only for the standard white-space characters.
7659 7.4.1.11 The isupper function
7661 1 #include <ctype.h>
7664 2 The isupper function tests for any character that is an uppercase letter or is one of a
7665 locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or
7666 isspace is true. In the "C" locale, isupper returns true only for the uppercase
7667 letters (as defined in 5.2.1).
7668 7.4.1.12 The isxdigit function
7670 1 #include <ctype.h>
7671 int isxdigit(int c);
7673 2 The isxdigit function tests for any hexadecimal-digit character (as defined in 6.4.4.1).
7674 7.4.2 Character case mapping functions
7675 7.4.2.1 The tolower function
7677 1 #include <ctype.h>
7680 2 The tolower function converts an uppercase letter to a corresponding lowercase letter.
7682 3 If the argument is a character for which isupper is true and there are one or more
7683 corresponding characters, as specified by the current locale, for which islower is true,
7684 the tolower function returns one of the corresponding characters (always the same one
7685 for any given locale); otherwise, the argument is returned unchanged.
7692 7.4.2.2 The toupper function
7694 1 #include <ctype.h>
7697 2 The toupper function converts a lowercase letter to a corresponding uppercase letter.
7699 3 If the argument is a character for which islower is true and there are one or more
7700 corresponding characters, as specified by the current locale, for which isupper is true,
7701 the toupper function returns one of the corresponding characters (always the same one
7702 for any given locale); otherwise, the argument is returned unchanged.
7709 7.5 Errors <errno.h>
7710 1 The header <errno.h> defines several macros, all relating to the reporting of error
7716 which expand to integer constant expressions with type int, distinct positive values, and
7717 which are suitable for use in #if preprocessing directives; and
7719 which expands to a modifiable lvalue175) that has type int, the value of which is set to a
7720 positive error number by several library functions. It is unspecified whether errno is a
7721 macro or an identifier declared with external linkage. If a macro definition is suppressed
7722 in order to access an actual object, or a program defines an identifier with the name
7723 errno, the behavior is undefined.
7724 3 The value of errno is zero at program startup, but is never set to zero by any library
7725 function.176) The value of errno may be set to nonzero by a library function call
7726 whether or not there is an error, provided the use of errno is not documented in the
7727 description of the function in this International Standard.
7728 4 Additional macro definitions, beginning with E and a digit or E and an uppercase
7729 letter,177) may also be specified by the implementation.
7734 175) The macro errno need not be the identifier of an object. It might expand to a modifiable lvalue
7735 resulting from a function call (for example, *errno()).
7736 176) Thus, a program that uses errno for error checking should set it to zero before a library function call,
7737 then inspect it before a subsequent library function call. Of course, a library function can save the
7738 value of errno on entry and then set it to zero, as long as the original value is restored if errno's
7739 value is still zero just before the return.
7740 177) See ''future library directions'' (7.26.3).
7744 7.6 Floating-point environment <fenv.h>
7745 1 The header <fenv.h> declares two types and several macros and functions to provide
7746 access to the floating-point environment. The floating-point environment refers
7747 collectively to any floating-point status flags and control modes supported by the
7748 implementation.178) A floating-point status flag is a system variable whose value is set
7749 (but never cleared) when a floating-point exception is raised, which occurs as a side effect
7750 of exceptional floating-point arithmetic to provide auxiliary information.179) A floating-
7751 point control mode is a system variable whose value may be set by the user to affect the
7752 subsequent behavior of floating-point arithmetic.
7753 2 Certain programming conventions support the intended model of use for the floating-
7754 point environment:180)
7755 -- a function call does not alter its caller's floating-point control modes, clear its caller's
7756 floating-point status flags, nor depend on the state of its caller's floating-point status
7757 flags unless the function is so documented;
7758 -- a function call is assumed to require default floating-point control modes, unless its
7759 documentation promises otherwise;
7760 -- a function call is assumed to have the potential for raising floating-point exceptions,
7761 unless its documentation promises otherwise.
7764 represents the entire floating-point environment.
7767 represents the floating-point status flags collectively, including any status the
7768 implementation associates with the flags.
7773 178) This header is designed to support the floating-point exception status flags and directed-rounding
7774 control modes required by IEC 60559, and other similar floating-point state information. Also it is
7775 designed to facilitate code portability among all systems.
7776 179) A floating-point status flag is not an object and can be set more than once within an expression.
7777 180) With these conventions, a programmer can safely assume default floating-point control modes (or be
7778 unaware of them). The responsibilities associated with accessing the floating-point environment fall
7779 on the programmer or program that does so explicitly.
7783 5 Each of the macros
7789 is defined if and only if the implementation supports the floating-point exception by
7790 means of the functions in 7.6.2.181) Additional implementation-defined floating-point
7791 exceptions, with macro definitions beginning with FE_ and an uppercase letter, may also
7792 be specified by the implementation. The defined macros expand to integer constant
7793 expressions with values such that bitwise ORs of all combinations of the macros result in
7794 distinct values, and furthermore, bitwise ANDs of all combinations of the macros result in
7798 is simply the bitwise OR of all floating-point exception macros defined by the
7799 implementation. If no such macros are defined, FE_ALL_EXCEPT shall be defined as 0.
7800 7 Each of the macros
7805 is defined if and only if the implementation supports getting and setting the represented
7806 rounding direction by means of the fegetround and fesetround functions.
7807 Additional implementation-defined rounding directions, with macro definitions beginning
7808 with FE_ and an uppercase letter, may also be specified by the implementation. The
7809 defined macros expand to integer constant expressions whose values are distinct
7810 nonnegative values.183)
7815 181) The implementation supports an exception if there are circumstances where a call to at least one of the
7816 functions in 7.6.2, using the macro as the appropriate argument, will succeed. It is not necessary for
7817 all the functions to succeed all the time.
7818 182) The macros should be distinct powers of two.
7819 183) Even though the rounding direction macros may expand to constants corresponding to the values of
7820 FLT_ROUNDS, they are not required to do so.
7825 represents the default floating-point environment -- the one installed at program startup
7826 -- and has type ''pointer to const-qualified fenv_t''. It can be used as an argument to
7827 <fenv.h> functions that manage the floating-point environment.
7828 9 Additional implementation-defined environments, with macro definitions beginning with
7829 FE_ and an uppercase letter, and having type ''pointer to const-qualified fenv_t'', may
7830 also be specified by the implementation.
7831 7.6.1 The FENV_ACCESS pragma
7834 #pragma STDC FENV_ACCESS on-off-switch
7836 2 The FENV_ACCESS pragma provides a means to inform the implementation when a
7837 program might access the floating-point environment to test floating-point status flags or
7838 run under non-default floating-point control modes.184) The pragma shall occur either
7839 outside external declarations or preceding all explicit declarations and statements inside a
7840 compound statement. When outside external declarations, the pragma takes effect from
7841 its occurrence until another FENV_ACCESS pragma is encountered, or until the end of
7842 the translation unit. When inside a compound statement, the pragma takes effect from its
7843 occurrence until another FENV_ACCESS pragma is encountered (including within a
7844 nested compound statement), or until the end of the compound statement; at the end of a
7845 compound statement the state for the pragma is restored to its condition just before the
7846 compound statement. If this pragma is used in any other context, the behavior is
7847 undefined. If part of a program tests floating-point status flags, sets floating-point control
7848 modes, or runs under non-default mode settings, but was translated with the state for the
7849 FENV_ACCESS pragma ''off'', the behavior is undefined. The default state (''on'' or
7850 ''off'') for the pragma is implementation-defined. (When execution passes from a part of
7851 the program translated with FENV_ACCESS ''off'' to a part translated with
7852 FENV_ACCESS ''on'', the state of the floating-point status flags is unspecified and the
7853 floating-point control modes have their default settings.)
7858 184) The purpose of the FENV_ACCESS pragma is to allow certain optimizations that could subvert flag
7859 tests and mode changes (e.g., global common subexpression elimination, code motion, and constant
7860 folding). In general, if the state of FENV_ACCESS is ''off'', the translator can assume that default
7861 modes are in effect and the flags are not tested.
7869 #pragma STDC FENV_ACCESS ON
7877 4 If the function g might depend on status flags set as a side effect of the first x + 1, or if the second
7878 x + 1 might depend on control modes set as a side effect of the call to function g, then the program shall
7879 contain an appropriately placed invocation of #pragma STDC FENV_ACCESS ON.185)
7881 7.6.2 Floating-point exceptions
7882 1 The following functions provide access to the floating-point status flags.186) The int
7883 input argument for the functions represents a subset of floating-point exceptions, and can
7884 be zero or the bitwise OR of one or more floating-point exception macros, for example
7885 FE_OVERFLOW | FE_INEXACT. For other argument values the behavior of these
7886 functions is undefined.
7887 7.6.2.1 The feclearexcept function
7890 int feclearexcept(int excepts);
7892 2 The feclearexcept function attempts to clear the supported floating-point exceptions
7893 represented by its argument.
7895 3 The feclearexcept function returns zero if the excepts argument is zero or if all
7896 the specified exceptions were successfully cleared. Otherwise, it returns a nonzero value.
7899 185) The side effects impose a temporal ordering that requires two evaluations of x + 1. On the other
7900 hand, without the #pragma STDC FENV_ACCESS ON pragma, and assuming the default state is
7901 ''off'', just one evaluation of x + 1 would suffice.
7902 186) The functions fetestexcept, feraiseexcept, and feclearexcept support the basic
7903 abstraction of flags that are either set or clear. An implementation may endow floating-point status
7904 flags with more information -- for example, the address of the code which first raised the floating-
7905 point exception; the functions fegetexceptflag and fesetexceptflag deal with the full
7910 7.6.2.2 The fegetexceptflag function
7913 int fegetexceptflag(fexcept_t *flagp,
7916 2 The fegetexceptflag function attempts to store an implementation-defined
7917 representation of the states of the floating-point status flags indicated by the argument
7918 excepts in the object pointed to by the argument flagp.
7920 3 The fegetexceptflag function returns zero if the representation was successfully
7921 stored. Otherwise, it returns a nonzero value.
7922 7.6.2.3 The feraiseexcept function
7925 int feraiseexcept(int excepts);
7927 2 The feraiseexcept function attempts to raise the supported floating-point exceptions
7928 represented by its argument.187) The order in which these floating-point exceptions are
7929 raised is unspecified, except as stated in F.7.6. Whether the feraiseexcept function
7930 additionally raises the ''inexact'' floating-point exception whenever it raises the
7931 ''overflow'' or ''underflow'' floating-point exception is implementation-defined.
7933 3 The feraiseexcept function returns zero if the excepts argument is zero or if all
7934 the specified exceptions were successfully raised. Otherwise, it returns a nonzero value.
7939 187) The effect is intended to be similar to that of floating-point exceptions raised by arithmetic operations.
7940 Hence, enabled traps for floating-point exceptions raised by this function are taken. The specification
7941 in F.7.6 is in the same spirit.
7945 7.6.2.4 The fesetexceptflag function
7948 int fesetexceptflag(const fexcept_t *flagp,
7951 2 The fesetexceptflag function attempts to set the floating-point status flags
7952 indicated by the argument excepts to the states stored in the object pointed to by
7953 flagp. The value of *flagp shall have been set by a previous call to
7954 fegetexceptflag whose second argument represented at least those floating-point
7955 exceptions represented by the argument excepts. This function does not raise floating-
7956 point exceptions, but only sets the state of the flags.
7958 3 The fesetexceptflag function returns zero if the excepts argument is zero or if
7959 all the specified flags were successfully set to the appropriate state. Otherwise, it returns
7961 7.6.2.5 The fetestexcept function
7964 int fetestexcept(int excepts);
7966 2 The fetestexcept function determines which of a specified subset of the floating-
7967 point exception flags are currently set. The excepts argument specifies the floating-
7968 point status flags to be queried.188)
7970 3 The fetestexcept function returns the value of the bitwise OR of the floating-point
7971 exception macros corresponding to the currently set floating-point exceptions included in
7973 4 EXAMPLE Call f if ''invalid'' is set, then g if ''overflow'' is set:
7978 188) This mechanism allows testing several floating-point exceptions with just one function call.
7985 #pragma STDC FENV_ACCESS ON
7987 feclearexcept(FE_INVALID | FE_OVERFLOW);
7988 // maybe raise exceptions
7989 set_excepts = fetestexcept(FE_INVALID | FE_OVERFLOW);
7990 if (set_excepts & FE_INVALID) f();
7991 if (set_excepts & FE_OVERFLOW) g();
7996 1 The fegetround and fesetround functions provide control of rounding direction
7998 7.6.3.1 The fegetround function
8001 int fegetround(void);
8003 2 The fegetround function gets the current rounding direction.
8005 3 The fegetround function returns the value of the rounding direction macro
8006 representing the current rounding direction or a negative value if there is no such
8007 rounding direction macro or the current rounding direction is not determinable.
8008 7.6.3.2 The fesetround function
8011 int fesetround(int round);
8013 2 The fesetround function establishes the rounding direction represented by its
8014 argument round. If the argument is not equal to the value of a rounding direction macro,
8015 the rounding direction is not changed.
8017 3 The fesetround function returns zero if and only if the requested rounding direction
8023 4 EXAMPLE Save, set, and restore the rounding direction. Report an error and abort if setting the
8024 rounding direction fails.
8027 void f(int round_dir)
8029 #pragma STDC FENV_ACCESS ON
8032 save_round = fegetround();
8033 setround_ok = fesetround(round_dir);
8034 assert(setround_ok == 0);
8036 fesetround(save_round);
8041 1 The functions in this section manage the floating-point environment -- status flags and
8042 control modes -- as one entity.
8043 7.6.4.1 The fegetenv function
8046 int fegetenv(fenv_t *envp);
8048 2 The fegetenv function attempts to store the current floating-point environment in the
8049 object pointed to by envp.
8051 3 The fegetenv function returns zero if the environment was successfully stored.
8052 Otherwise, it returns a nonzero value.
8053 7.6.4.2 The feholdexcept function
8056 int feholdexcept(fenv_t *envp);
8058 2 The feholdexcept function saves the current floating-point environment in the object
8059 pointed to by envp, clears the floating-point status flags, and then installs a non-stop
8060 (continue on floating-point exceptions) mode, if available, for all floating-point
8066 3 The feholdexcept function returns zero if and only if non-stop floating-point
8067 exception handling was successfully installed.
8068 7.6.4.3 The fesetenv function
8071 int fesetenv(const fenv_t *envp);
8073 2 The fesetenv function attempts to establish the floating-point environment represented
8074 by the object pointed to by envp. The argument envp shall point to an object set by a
8075 call to fegetenv or feholdexcept, or equal a floating-point environment macro.
8076 Note that fesetenv merely installs the state of the floating-point status flags
8077 represented through its argument, and does not raise these floating-point exceptions.
8079 3 The fesetenv function returns zero if the environment was successfully established.
8080 Otherwise, it returns a nonzero value.
8081 7.6.4.4 The feupdateenv function
8084 int feupdateenv(const fenv_t *envp);
8086 2 The feupdateenv function attempts to save the currently raised floating-point
8087 exceptions in its automatic storage, install the floating-point environment represented by
8088 the object pointed to by envp, and then raise the saved floating-point exceptions. The
8089 argument envp shall point to an object set by a call to feholdexcept or fegetenv,
8090 or equal a floating-point environment macro.
8092 3 The feupdateenv function returns zero if all the actions were successfully carried out.
8093 Otherwise, it returns a nonzero value.
8098 189) IEC 60559 systems have a default non-stop mode, and typically at least one other mode for trap
8099 handling or aborting; if the system provides only the non-stop mode then installing it is trivial. For
8100 such systems, the feholdexcept function can be used in conjunction with the feupdateenv
8101 function to write routines that hide spurious floating-point exceptions from their callers.
8105 4 EXAMPLE Hide spurious underflow floating-point exceptions:
8109 #pragma STDC FENV_ACCESS ON
8112 if (feholdexcept(&save_env))
8113 return /* indication of an environmental problem */;
8115 if (/* test spurious underflow */)
8116 if (feclearexcept(FE_UNDERFLOW))
8117 return /* indication of an environmental problem */;
8118 if (feupdateenv(&save_env))
8119 return /* indication of an environmental problem */;
8128 7.7 Characteristics of floating types <float.h>
8129 1 The header <float.h> defines several macros that expand to various limits and
8130 parameters of the standard floating-point types.
8131 2 The macros, their meanings, and the constraints (or restrictions) on their values are listed
8139 7.8 Format conversion of integer types <inttypes.h>
8140 1 The header <inttypes.h> includes the header <stdint.h> and extends it with
8141 additional facilities provided by hosted implementations.
8142 2 It declares functions for manipulating greatest-width integers and converting numeric
8143 character strings to greatest-width integers, and it declares the type
8145 which is a structure type that is the type of the value returned by the imaxdiv function.
8146 For each type declared in <stdint.h>, it defines corresponding macros for conversion
8147 specifiers for use with the formatted input/output functions.190)
8148 Forward references: integer types <stdint.h> (7.18), formatted input/output
8149 functions (7.19.6), formatted wide character input/output functions (7.24.2).
8150 7.8.1 Macros for format specifiers
8151 1 Each of the following object-like macros191) expands to a character string literal
8152 containing a conversion specifier, possibly modified by a length modifier, suitable for use
8153 within the format argument of a formatted input/output function when converting the
8154 corresponding integer type. These macro names have the general form of PRI (character
8155 string literals for the fprintf and fwprintf family) or SCN (character string literals
8156 for the fscanf and fwscanf family),192) followed by the conversion specifier,
8157 followed by a name corresponding to a similar type name in 7.18.1. In these names, N
8158 represents the width of the type as described in 7.18.1. For example, PRIdFAST32 can
8159 be used in a format string to print the value of an integer of type int_fast32_t.
8160 2 The fprintf macros for signed integers are:
8161 PRIdN PRIdLEASTN PRIdFASTN PRIdMAX PRIdPTR
8162 PRIiN PRIiLEASTN PRIiFASTN PRIiMAX PRIiPTR
8167 190) See ''future library directions'' (7.26.4).
8168 191) C++ implementations should define these macros only when __STDC_FORMAT_MACROS is defined
8169 before <inttypes.h> is included.
8170 192) Separate macros are given for use with fprintf and fscanf functions because, in the general case,
8171 different format specifiers may be required for fprintf and fscanf, even when the type is the
8176 3 The fprintf macros for unsigned integers are:
8177 PRIoN PRIoLEASTN PRIoFASTN PRIoMAX PRIoPTR
8178 PRIuN PRIuLEASTN PRIuFASTN PRIuMAX PRIuPTR
8179 PRIxN PRIxLEASTN PRIxFASTN PRIxMAX PRIxPTR
8180 PRIXN PRIXLEASTN PRIXFASTN PRIXMAX PRIXPTR
8181 4 The fscanf macros for signed integers are:
8182 SCNdN SCNdLEASTN SCNdFASTN SCNdMAX SCNdPTR
8183 SCNiN SCNiLEASTN SCNiFASTN SCNiMAX SCNiPTR
8184 5 The fscanf macros for unsigned integers are:
8185 SCNoN SCNoLEASTN SCNoFASTN SCNoMAX SCNoPTR
8186 SCNuN SCNuLEASTN SCNuFASTN SCNuMAX SCNuPTR
8187 SCNxN SCNxLEASTN SCNxFASTN SCNxMAX SCNxPTR
8188 6 For each type that the implementation provides in <stdint.h>, the corresponding
8189 fprintf macros shall be defined and the corresponding fscanf macros shall be
8190 defined unless the implementation does not have a suitable fscanf length modifier for
8193 #include <inttypes.h>
8197 uintmax_t i = UINTMAX_MAX; // this type always exists
8198 wprintf(L"The largest integer value is %020"
8203 7.8.2 Functions for greatest-width integer types
8204 7.8.2.1 The imaxabs function
8206 1 #include <inttypes.h>
8207 intmax_t imaxabs(intmax_t j);
8209 2 The imaxabs function computes the absolute value of an integer j. If the result cannot
8210 be represented, the behavior is undefined.193)
8214 193) The absolute value of the most negative number cannot be represented in two's complement.
8219 3 The imaxabs function returns the absolute value.
8220 7.8.2.2 The imaxdiv function
8222 1 #include <inttypes.h>
8223 imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
8225 2 The imaxdiv function computes numer / denom and numer % denom in a single
8228 3 The imaxdiv function returns a structure of type imaxdiv_t comprising both the
8229 quotient and the remainder. The structure shall contain (in either order) the members
8230 quot (the quotient) and rem (the remainder), each of which has type intmax_t. If
8231 either part of the result cannot be represented, the behavior is undefined.
8232 7.8.2.3 The strtoimax and strtoumax functions
8234 1 #include <inttypes.h>
8235 intmax_t strtoimax(const char * restrict nptr,
8236 char ** restrict endptr, int base);
8237 uintmax_t strtoumax(const char * restrict nptr,
8238 char ** restrict endptr, int base);
8240 2 The strtoimax and strtoumax functions are equivalent to the strtol, strtoll,
8241 strtoul, and strtoull functions, except that the initial portion of the string is
8242 converted to intmax_t and uintmax_t representation, respectively.
8244 3 The strtoimax and strtoumax functions return the converted value, if any. If no
8245 conversion could be performed, zero is returned. If the correct value is outside the range
8246 of representable values, INTMAX_MAX, INTMAX_MIN, or UINTMAX_MAX is returned
8247 (according to the return type and sign of the value, if any), and the value of the macro
8248 ERANGE is stored in errno.
8249 Forward references: the strtol, strtoll, strtoul, and strtoull functions
8256 7.8.2.4 The wcstoimax and wcstoumax functions
8258 1 #include <stddef.h> // for wchar_t
8259 #include <inttypes.h>
8260 intmax_t wcstoimax(const wchar_t * restrict nptr,
8261 wchar_t ** restrict endptr, int base);
8262 uintmax_t wcstoumax(const wchar_t * restrict nptr,
8263 wchar_t ** restrict endptr, int base);
8265 2 The wcstoimax and wcstoumax functions are equivalent to the wcstol, wcstoll,
8266 wcstoul, and wcstoull functions except that the initial portion of the wide string is
8267 converted to intmax_t and uintmax_t representation, respectively.
8269 3 The wcstoimax function returns the converted value, if any. If no conversion could be
8270 performed, zero is returned. If the correct value is outside the range of representable
8271 values, INTMAX_MAX, INTMAX_MIN, or UINTMAX_MAX is returned (according to the
8272 return type and sign of the value, if any), and the value of the macro ERANGE is stored in
8274 Forward references: the wcstol, wcstoll, wcstoul, and wcstoull functions
8282 7.9 Alternative spellings <iso646.h>
8283 1 The header <iso646.h> defines the following eleven macros (on the left) that expand
8284 to the corresponding tokens (on the right):
8302 7.10 Sizes of integer types <limits.h>
8303 1 The header <limits.h> defines several macros that expand to various limits and
8304 parameters of the standard integer types.
8305 2 The macros, their meanings, and the constraints (or restrictions) on their values are listed
8313 7.11 Localization <locale.h>
8314 1 The header <locale.h> declares two functions, one type, and defines several macros.
8317 which contains members related to the formatting of numeric values. The structure shall
8318 contain at least the following members, in any order. The semantics of the members and
8319 their normal ranges are explained in 7.11.2.1. In the "C" locale, the members shall have
8320 the values specified in the comments.
8321 char *decimal_point; // "."
8322 char *thousands_sep; // ""
8323 char *grouping; // ""
8324 char *mon_decimal_point; // ""
8325 char *mon_thousands_sep; // ""
8326 char *mon_grouping; // ""
8327 char *positive_sign; // ""
8328 char *negative_sign; // ""
8329 char *currency_symbol; // ""
8330 char frac_digits; // CHAR_MAX
8331 char p_cs_precedes; // CHAR_MAX
8332 char n_cs_precedes; // CHAR_MAX
8333 char p_sep_by_space; // CHAR_MAX
8334 char n_sep_by_space; // CHAR_MAX
8335 char p_sign_posn; // CHAR_MAX
8336 char n_sign_posn; // CHAR_MAX
8337 char *int_curr_symbol; // ""
8338 char int_frac_digits; // CHAR_MAX
8339 char int_p_cs_precedes; // CHAR_MAX
8340 char int_n_cs_precedes; // CHAR_MAX
8341 char int_p_sep_by_space; // CHAR_MAX
8342 char int_n_sep_by_space; // CHAR_MAX
8343 char int_p_sign_posn; // CHAR_MAX
8344 char int_n_sign_posn; // CHAR_MAX
8351 3 The macros defined are NULL (described in 7.17); and
8358 which expand to integer constant expressions with distinct values, suitable for use as the
8359 first argument to the setlocale function.194) Additional macro definitions, beginning
8360 with the characters LC_ and an uppercase letter,195) may also be specified by the
8362 7.11.1 Locale control
8363 7.11.1.1 The setlocale function
8365 1 #include <locale.h>
8366 char *setlocale(int category, const char *locale);
8368 2 The setlocale function selects the appropriate portion of the program's locale as
8369 specified by the category and locale arguments. The setlocale function may be
8370 used to change or query the program's entire current locale or portions thereof. The value
8371 LC_ALL for category names the program's entire locale; the other values for
8372 category name only a portion of the program's locale. LC_COLLATE affects the
8373 behavior of the strcoll and strxfrm functions. LC_CTYPE affects the behavior of
8374 the character handling functions196) and the multibyte and wide character functions.
8375 LC_MONETARY affects the monetary formatting information returned by the
8376 localeconv function. LC_NUMERIC affects the decimal-point character for the
8377 formatted input/output functions and the string conversion functions, as well as the
8378 nonmonetary formatting information returned by the localeconv function. LC_TIME
8379 affects the behavior of the strftime and wcsftime functions.
8380 3 A value of "C" for locale specifies the minimal environment for C translation; a value
8381 of "" for locale specifies the locale-specific native environment. Other
8382 implementation-defined strings may be passed as the second argument to setlocale.
8384 194) ISO/IEC 9945-2 specifies locale and charmap formats that may be used to specify locales for C.
8385 195) See ''future library directions'' (7.26.5).
8386 196) The only functions in 7.4 whose behavior is not affected by the current locale are isdigit and
8391 4 At program startup, the equivalent of
8392 setlocale(LC_ALL, "C");
8394 5 The implementation shall behave as if no library function calls the setlocale function.
8396 6 If a pointer to a string is given for locale and the selection can be honored, the
8397 setlocale function returns a pointer to the string associated with the specified
8398 category for the new locale. If the selection cannot be honored, the setlocale
8399 function returns a null pointer and the program's locale is not changed.
8400 7 A null pointer for locale causes the setlocale function to return a pointer to the
8401 string associated with the category for the program's current locale; the program's
8402 locale is not changed.197)
8403 8 The pointer to string returned by the setlocale function is such that a subsequent call
8404 with that string value and its associated category will restore that part of the program's
8405 locale. The string pointed to shall not be modified by the program, but may be
8406 overwritten by a subsequent call to the setlocale function.
8407 Forward references: formatted input/output functions (7.19.6), multibyte/wide
8408 character conversion functions (7.20.7), multibyte/wide string conversion functions
8409 (7.20.8), numeric conversion functions (7.20.1), the strcoll function (7.21.4.3), the
8410 strftime function (7.23.3.5), the strxfrm function (7.21.4.5).
8411 7.11.2 Numeric formatting convention inquiry
8412 7.11.2.1 The localeconv function
8414 1 #include <locale.h>
8415 struct lconv *localeconv(void);
8417 2 The localeconv function sets the components of an object with type struct lconv
8418 with values appropriate for the formatting of numeric quantities (monetary and otherwise)
8419 according to the rules of the current locale.
8420 3 The members of the structure with type char * are pointers to strings, any of which
8421 (except decimal_point) can point to "", to indicate that the value is not available in
8422 the current locale or is of zero length. Apart from grouping and mon_grouping, the
8424 197) The implementation shall arrange to encode in a string the various categories due to a heterogeneous
8425 locale when category has the value LC_ALL.
8429 strings shall start and end in the initial shift state. The members with type char are
8430 nonnegative numbers, any of which can be CHAR_MAX to indicate that the value is not
8431 available in the current locale. The members include the following:
8433 The decimal-point character used to format nonmonetary quantities.
8435 The character used to separate groups of digits before the decimal-point
8436 character in formatted nonmonetary quantities.
8438 A string whose elements indicate the size of each group of digits in
8439 formatted nonmonetary quantities.
8440 char *mon_decimal_point
8441 The decimal-point used to format monetary quantities.
8442 char *mon_thousands_sep
8443 The separator for groups of digits before the decimal-point in formatted
8444 monetary quantities.
8446 A string whose elements indicate the size of each group of digits in
8447 formatted monetary quantities.
8449 The string used to indicate a nonnegative-valued formatted monetary
8452 The string used to indicate a negative-valued formatted monetary quantity.
8453 char *currency_symbol
8454 The local currency symbol applicable to the current locale.
8456 The number of fractional digits (those after the decimal-point) to be
8457 displayed in a locally formatted monetary quantity.
8459 Set to 1 or 0 if the currency_symbol respectively precedes or
8460 succeeds the value for a nonnegative locally formatted monetary quantity.
8462 Set to 1 or 0 if the currency_symbol respectively precedes or
8463 succeeds the value for a negative locally formatted monetary quantity.
8469 Set to a value indicating the separation of the currency_symbol, the
8470 sign string, and the value for a nonnegative locally formatted monetary
8473 Set to a value indicating the separation of the currency_symbol, the
8474 sign string, and the value for a negative locally formatted monetary
8477 Set to a value indicating the positioning of the positive_sign for a
8478 nonnegative locally formatted monetary quantity.
8480 Set to a value indicating the positioning of the negative_sign for a
8481 negative locally formatted monetary quantity.
8482 char *int_curr_symbol
8483 The international currency symbol applicable to the current locale. The
8484 first three characters contain the alphabetic international currency symbol
8485 in accordance with those specified in ISO 4217. The fourth character
8486 (immediately preceding the null character) is the character used to separate
8487 the international currency symbol from the monetary quantity.
8488 char int_frac_digits
8489 The number of fractional digits (those after the decimal-point) to be
8490 displayed in an internationally formatted monetary quantity.
8491 char int_p_cs_precedes
8492 Set to 1 or 0 if the int_curr_symbol respectively precedes or
8493 succeeds the value for a nonnegative internationally formatted monetary
8495 char int_n_cs_precedes
8496 Set to 1 or 0 if the int_curr_symbol respectively precedes or
8497 succeeds the value for a negative internationally formatted monetary
8499 char int_p_sep_by_space
8500 Set to a value indicating the separation of the int_curr_symbol, the
8501 sign string, and the value for a nonnegative internationally formatted
8509 char int_n_sep_by_space
8510 Set to a value indicating the separation of the int_curr_symbol, the
8511 sign string, and the value for a negative internationally formatted monetary
8513 char int_p_sign_posn
8514 Set to a value indicating the positioning of the positive_sign for a
8515 nonnegative internationally formatted monetary quantity.
8516 char int_n_sign_posn
8517 Set to a value indicating the positioning of the negative_sign for a
8518 negative internationally formatted monetary quantity.
8519 4 The elements of grouping and mon_grouping are interpreted according to the
8521 CHAR_MAX No further grouping is to be performed.
8522 0 The previous element is to be repeatedly used for the remainder of the
8524 other The integer value is the number of digits that compose the current group.
8525 The next element is examined to determine the size of the next group of
8526 digits before the current group.
8527 5 The values of p_sep_by_space, n_sep_by_space, int_p_sep_by_space,
8528 and int_n_sep_by_space are interpreted according to the following:
8529 0 No space separates the currency symbol and value.
8530 1 If the currency symbol and sign string are adjacent, a space separates them from the
8531 value; otherwise, a space separates the currency symbol from the value.
8532 2 If the currency symbol and sign string are adjacent, a space separates them;
8533 otherwise, a space separates the sign string from the value.
8534 For int_p_sep_by_space and int_n_sep_by_space, the fourth character of
8535 int_curr_symbol is used instead of a space.
8536 6 The values of p_sign_posn, n_sign_posn, int_p_sign_posn, and
8537 int_n_sign_posn are interpreted according to the following:
8538 0 Parentheses surround the quantity and currency symbol.
8539 1 The sign string precedes the quantity and currency symbol.
8540 2 The sign string succeeds the quantity and currency symbol.
8541 3 The sign string immediately precedes the currency symbol.
8542 4 The sign string immediately succeeds the currency symbol.
8547 7 The implementation shall behave as if no library function calls the localeconv
8550 8 The localeconv function returns a pointer to the filled-in object. The structure
8551 pointed to by the return value shall not be modified by the program, but may be
8552 overwritten by a subsequent call to the localeconv function. In addition, calls to the
8553 setlocale function with categories LC_ALL, LC_MONETARY, or LC_NUMERIC may
8554 overwrite the contents of the structure.
8555 9 EXAMPLE 1 The following table illustrates rules which may well be used by four countries to format
8556 monetary quantities.
8557 Local format International format
8559 Country Positive Negative Positive Negative
8561 Country1 1.234,56 mk -1.234,56 mk FIM 1.234,56 FIM -1.234,56
8562 Country2 L.1.234 -L.1.234 ITL 1.234 -ITL 1.234
8563 Country3 fl. 1.234,56 fl. -1.234,56 NLG 1.234,56 NLG -1.234,56
8564 Country4 SFrs.1,234.56 SFrs.1,234.56C CHF 1,234.56 CHF 1,234.56C
8565 10 For these four countries, the respective values for the monetary members of the structure returned by
8566 localeconv could be:
8567 Country1 Country2 Country3 Country4
8569 mon_decimal_point "," "" "," "."
8570 mon_thousands_sep "." "." "." ","
8571 mon_grouping "\3" "\3" "\3" "\3"
8572 positive_sign "" "" "" ""
8573 negative_sign "-" "-" "-" "C"
8574 currency_symbol "mk" "L." "\u0192" "SFrs."
8576 p_cs_precedes 0 1 1 1
8577 n_cs_precedes 0 1 1 1
8578 p_sep_by_space 1 0 1 0
8579 n_sep_by_space 1 0 2 0
8582 int_curr_symbol "FIM " "ITL " "NLG " "CHF "
8583 int_frac_digits 2 0 2 2
8584 int_p_cs_precedes 1 1 1 1
8585 int_n_cs_precedes 1 1 1 1
8586 int_p_sep_by_space 1 1 1 1
8587 int_n_sep_by_space 2 1 2 1
8588 int_p_sign_posn 1 1 1 1
8589 int_n_sign_posn 4 1 4 2
8596 11 EXAMPLE 2 The following table illustrates how the cs_precedes, sep_by_space, and sign_posn members
8597 affect the formatted value.
8600 p_cs_precedes p_sign_posn 0 1 2
8602 0 0 (1.25$) (1.25 $) (1.25$)
8603 1 +1.25$ +1.25 $ + 1.25$
8604 2 1.25$+ 1.25 $+ 1.25$ +
8605 3 1.25+$ 1.25 +$ 1.25+ $
8606 4 1.25$+ 1.25 $+ 1.25$ +
8608 1 0 ($1.25) ($ 1.25) ($1.25)
8609 1 +$1.25 +$ 1.25 + $1.25
8610 2 $1.25+ $ 1.25+ $1.25 +
8611 3 +$1.25 +$ 1.25 + $1.25
8612 4 $+1.25 $+ 1.25 $ +1.25
8619 7.12 Mathematics <math.h>
8620 1 The header <math.h> declares two types and many mathematical functions and defines
8621 several macros. Most synopses specify a family of functions consisting of a principal
8622 function with one or more double parameters, a double return value, or both; and
8623 other functions with the same name but with f and l suffixes, which are corresponding
8624 functions with float and long double parameters, return values, or both.198)
8625 Integer arithmetic functions and conversion functions are discussed later.
8629 are floating types at least as wide as float and double, respectively, and such that
8630 double_t is at least as wide as float_t. If FLT_EVAL_METHOD equals 0,
8631 float_t and double_t are float and double, respectively; if
8632 FLT_EVAL_METHOD equals 1, they are both double; if FLT_EVAL_METHOD equals
8633 2, they are both long double; and for other values of FLT_EVAL_METHOD, they are
8634 otherwise implementation-defined.199)
8637 expands to a positive double constant expression, not necessarily representable as a
8641 are respectively float and long double analogs of HUGE_VAL.200)
8644 expands to a constant expression of type float representing positive or unsigned
8645 infinity, if available; else to a positive constant of type float that overflows at
8649 198) Particularly on systems with wide expression evaluation, a <math.h> function might pass arguments
8650 and return values in wider format than the synopsis prototype indicates.
8651 199) The types float_t and double_t are intended to be the implementation's most efficient types at
8652 least as wide as float and double, respectively. For FLT_EVAL_METHOD equal 0, 1, or 2, the
8653 type float_t is the narrowest type used by the implementation to evaluate floating expressions.
8654 200) HUGE_VAL, HUGE_VALF, and HUGE_VALL can be positive infinities in an implementation that
8655 supports infinities.
8659 translation time.201)
8662 is defined if and only if the implementation supports quiet NaNs for the float type. It
8663 expands to a constant expression of type float representing a quiet NaN.
8664 6 The number classification macros
8670 represent the mutually exclusive kinds of floating-point values. They expand to integer
8671 constant expressions with distinct values. Additional implementation-defined floating-
8672 point classifications, with macro definitions beginning with FP_ and an uppercase letter,
8673 may also be specified by the implementation.
8676 is optionally defined. If defined, it indicates that the fma function generally executes
8677 about as fast as, or faster than, a multiply and an add of double operands.202) The
8681 are, respectively, float and long double analogs of FP_FAST_FMA. If defined,
8682 these macros expand to the integer constant 1.
8686 expand to integer constant expressions whose values are returned by ilogb(x) if x is
8687 zero or NaN, respectively. The value of FP_ILOGB0 shall be either INT_MIN or
8688 -INT_MAX. The value of FP_ILOGBNAN shall be either INT_MAX or INT_MIN.
8691 201) In this case, using INFINITY will violate the constraint in 6.4.4 and thus require a diagnostic.
8692 202) Typically, the FP_FAST_FMA macro is defined if and only if the fma function is implemented
8693 directly with a hardware multiply-add instruction. Software implementations are expected to be
8694 substantially slower.
8701 expand to the integer constants 1 and 2, respectively; the macro
8703 expands to an expression that has type int and the value MATH_ERRNO,
8704 MATH_ERREXCEPT, or the bitwise OR of both. The value of math_errhandling is
8705 constant for the duration of the program. It is unspecified whether
8706 math_errhandling is a macro or an identifier with external linkage. If a macro
8707 definition is suppressed or a program defines an identifier with the name
8708 math_errhandling, the behavior is undefined. If the expression
8709 math_errhandling & MATH_ERREXCEPT can be nonzero, the implementation
8710 shall define the macros FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in
8712 7.12.1 Treatment of error conditions
8713 1 The behavior of each of the functions in <math.h> is specified for all representable
8714 values of its input arguments, except where stated otherwise. Each function shall execute
8715 as if it were a single operation without generating any externally visible exceptional
8717 2 For all functions, a domain error occurs if an input argument is outside the domain over
8718 which the mathematical function is defined. The description of each function lists any
8719 required domain errors; an implementation may define additional domain errors, provided
8720 that such errors are consistent with the mathematical definition of the function.203) On a
8721 domain error, the function returns an implementation-defined value; if the integer
8722 expression math_errhandling & MATH_ERRNO is nonzero, the integer expression
8723 errno acquires the value EDOM; if the integer expression math_errhandling &
8724 MATH_ERREXCEPT is nonzero, the ''invalid'' floating-point exception is raised.
8725 3 Similarly, a range error occurs if the mathematical result of the function cannot be
8726 represented in an object of the specified type, due to extreme magnitude.
8727 4 A floating result overflows if the magnitude of the mathematical result is finite but so
8728 large that the mathematical result cannot be represented without extraordinary roundoff
8729 error in an object of the specified type. If a floating result overflows and default rounding
8730 is in effect, or if the mathematical result is an exact infinity from finite arguments (for
8731 example log(0.0)), then the function returns the value of the macro HUGE_VAL,
8734 203) In an implementation that supports infinities, this allows an infinity as an argument to be a domain
8735 error if the mathematical domain of the function does not include the infinity.
8739 HUGE_VALF, or HUGE_VALL according to the return type, with the same sign as the
8740 correct value of the function; if the integer expression math_errhandling &
8741 MATH_ERRNO is nonzero, the integer expression errno acquires the value ERANGE; if
8742 the integer expression math_errhandling & MATH_ERREXCEPT is nonzero, the
8743 ''divide-by-zero'' floating-point exception is raised if the mathematical result is an exact
8744 infinity and the ''overflow'' floating-point exception is raised otherwise.
8745 5 The result underflows if the magnitude of the mathematical result is so small that the
8746 mathematical result cannot be represented, without extraordinary roundoff error, in an
8747 object of the specified type.204) If the result underflows, the function returns an
8748 implementation-defined value whose magnitude is no greater than the smallest
8749 normalized positive number in the specified type; if the integer expression
8750 math_errhandling & MATH_ERRNO is nonzero, whether errno acquires the
8751 value ERANGE is implementation-defined; if the integer expression
8752 math_errhandling & MATH_ERREXCEPT is nonzero, whether the ''underflow''
8753 floating-point exception is raised is implementation-defined.
8754 7.12.2 The FP_CONTRACT pragma
8757 #pragma STDC FP_CONTRACT on-off-switch
8759 2 The FP_CONTRACT pragma can be used to allow (if the state is ''on'') or disallow (if the
8760 state is ''off'') the implementation to contract expressions (6.5). Each pragma can occur
8761 either outside external declarations or preceding all explicit declarations and statements
8762 inside a compound statement. When outside external declarations, the pragma takes
8763 effect from its occurrence until another FP_CONTRACT pragma is encountered, or until
8764 the end of the translation unit. When inside a compound statement, the pragma takes
8765 effect from its occurrence until another FP_CONTRACT pragma is encountered
8766 (including within a nested compound statement), or until the end of the compound
8767 statement; at the end of a compound statement the state for the pragma is restored to its
8768 condition just before the compound statement. If this pragma is used in any other
8769 context, the behavior is undefined. The default state (''on'' or ''off'') for the pragma is
8770 implementation-defined.
8775 204) The term underflow here is intended to encompass both ''gradual underflow'' as in IEC 60559 and
8776 also ''flush-to-zero'' underflow.
8780 7.12.3 Classification macros
8781 1 In the synopses in this subclause, real-floating indicates that the argument shall be an
8782 expression of real floating type.
8783 7.12.3.1 The fpclassify macro
8786 int fpclassify(real-floating x);
8788 2 The fpclassify macro classifies its argument value as NaN, infinite, normal,
8789 subnormal, zero, or into another implementation-defined category. First, an argument
8790 represented in a format wider than its semantic type is converted to its semantic type.
8791 Then classification is based on the type of the argument.205)
8793 3 The fpclassify macro returns the value of the number classification macro
8794 appropriate to the value of its argument.
8795 4 EXAMPLE The fpclassify macro might be implemented in terms of ordinary functions as
8796 #define fpclassify(x) \
8797 ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) : \
8798 (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) : \
8801 7.12.3.2 The isfinite macro
8804 int isfinite(real-floating x);
8806 2 The isfinite macro determines whether its argument has a finite value (zero,
8807 subnormal, or normal, and not infinite or NaN). First, an argument represented in a
8808 format wider than its semantic type is converted to its semantic type. Then determination
8809 is based on the type of the argument.
8814 205) Since an expression can be evaluated with more range and precision than its type has, it is important to
8815 know the type that classification is based on. For example, a normal long double value might
8816 become subnormal when converted to double, and zero when converted to float.
8821 3 The isfinite macro returns a nonzero value if and only if its argument has a finite
8823 7.12.3.3 The isinf macro
8826 int isinf(real-floating x);
8828 2 The isinf macro determines whether its argument value is an infinity (positive or
8829 negative). First, an argument represented in a format wider than its semantic type is
8830 converted to its semantic type. Then determination is based on the type of the argument.
8832 3 The isinf macro returns a nonzero value if and only if its argument has an infinite
8834 7.12.3.4 The isnan macro
8837 int isnan(real-floating x);
8839 2 The isnan macro determines whether its argument value is a NaN. First, an argument
8840 represented in a format wider than its semantic type is converted to its semantic type.
8841 Then determination is based on the type of the argument.206)
8843 3 The isnan macro returns a nonzero value if and only if its argument has a NaN value.
8844 7.12.3.5 The isnormal macro
8847 int isnormal(real-floating x);
8852 206) For the isnan macro, the type for determination does not matter unless the implementation supports
8853 NaNs in the evaluation type but not in the semantic type.
8858 2 The isnormal macro determines whether its argument value is normal (neither zero,
8859 subnormal, infinite, nor NaN). First, an argument represented in a format wider than its
8860 semantic type is converted to its semantic type. Then determination is based on the type
8863 3 The isnormal macro returns a nonzero value if and only if its argument has a normal
8865 7.12.3.6 The signbit macro
8868 int signbit(real-floating x);
8870 2 The signbit macro determines whether the sign of its argument value is negative.207)
8872 3 The signbit macro returns a nonzero value if and only if the sign of its argument value
8874 7.12.4 Trigonometric functions
8875 7.12.4.1 The acos functions
8878 double acos(double x);
8879 float acosf(float x);
8880 long double acosl(long double x);
8882 2 The acos functions compute the principal value of the arc cosine of x. A domain error
8883 occurs for arguments not in the interval [-1, +1].
8885 3 The acos functions return arccos x in the interval [0, pi ] radians.
8890 207) The signbit macro reports the sign of all values, including infinities, zeros, and NaNs. If zero is
8891 unsigned, it is treated as positive.
8895 7.12.4.2 The asin functions
8898 double asin(double x);
8899 float asinf(float x);
8900 long double asinl(long double x);
8902 2 The asin functions compute the principal value of the arc sine of x. A domain error
8903 occurs for arguments not in the interval [-1, +1].
8905 3 The asin functions return arcsin x in the interval [-pi /2, +pi /2] radians.
8906 7.12.4.3 The atan functions
8909 double atan(double x);
8910 float atanf(float x);
8911 long double atanl(long double x);
8913 2 The atan functions compute the principal value of the arc tangent of x.
8915 3 The atan functions return arctan x in the interval [-pi /2, +pi /2] radians.
8916 7.12.4.4 The atan2 functions
8919 double atan2(double y, double x);
8920 float atan2f(float y, float x);
8921 long double atan2l(long double y, long double x);
8923 2 The atan2 functions compute the value of the arc tangent of y/x, using the signs of both
8924 arguments to determine the quadrant of the return value. A domain error may occur if
8925 both arguments are zero.
8927 3 The atan2 functions return arctan y/x in the interval [-pi , +pi ] radians.
8932 7.12.4.5 The cos functions
8935 double cos(double x);
8936 float cosf(float x);
8937 long double cosl(long double x);
8939 2 The cos functions compute the cosine of x (measured in radians).
8941 3 The cos functions return cos x.
8942 7.12.4.6 The sin functions
8945 double sin(double x);
8946 float sinf(float x);
8947 long double sinl(long double x);
8949 2 The sin functions compute the sine of x (measured in radians).
8951 3 The sin functions return sin x.
8952 7.12.4.7 The tan functions
8955 double tan(double x);
8956 float tanf(float x);
8957 long double tanl(long double x);
8959 2 The tan functions return the tangent of x (measured in radians).
8961 3 The tan functions return tan x.
8968 7.12.5 Hyperbolic functions
8969 7.12.5.1 The acosh functions
8972 double acosh(double x);
8973 float acoshf(float x);
8974 long double acoshl(long double x);
8976 2 The acosh functions compute the (nonnegative) arc hyperbolic cosine of x. A domain
8977 error occurs for arguments less than 1.
8979 3 The acosh functions return arcosh x in the interval [0, +(inf)].
8980 7.12.5.2 The asinh functions
8983 double asinh(double x);
8984 float asinhf(float x);
8985 long double asinhl(long double x);
8987 2 The asinh functions compute the arc hyperbolic sine of x.
8989 3 The asinh functions return arsinh x.
8990 7.12.5.3 The atanh functions
8993 double atanh(double x);
8994 float atanhf(float x);
8995 long double atanhl(long double x);
8997 2 The atanh functions compute the arc hyperbolic tangent of x. A domain error occurs
8998 for arguments not in the interval [-1, +1]. A range error may occur if the argument
9006 3 The atanh functions return artanh x.
9007 7.12.5.4 The cosh functions
9010 double cosh(double x);
9011 float coshf(float x);
9012 long double coshl(long double x);
9014 2 The cosh functions compute the hyperbolic cosine of x. A range error occurs if the
9015 magnitude of x is too large.
9017 3 The cosh functions return cosh x.
9018 7.12.5.5 The sinh functions
9021 double sinh(double x);
9022 float sinhf(float x);
9023 long double sinhl(long double x);
9025 2 The sinh functions compute the hyperbolic sine of x. A range error occurs if the
9026 magnitude of x is too large.
9028 3 The sinh functions return sinh x.
9029 7.12.5.6 The tanh functions
9032 double tanh(double x);
9033 float tanhf(float x);
9034 long double tanhl(long double x);
9036 2 The tanh functions compute the hyperbolic tangent of x.
9043 3 The tanh functions return tanh x.
9044 7.12.6 Exponential and logarithmic functions
9045 7.12.6.1 The exp functions
9048 double exp(double x);
9049 float expf(float x);
9050 long double expl(long double x);
9052 2 The exp functions compute the base-e exponential of x. A range error occurs if the
9053 magnitude of x is too large.
9055 3 The exp functions return ex .
9056 7.12.6.2 The exp2 functions
9059 double exp2(double x);
9060 float exp2f(float x);
9061 long double exp2l(long double x);
9063 2 The exp2 functions compute the base-2 exponential of x. A range error occurs if the
9064 magnitude of x is too large.
9066 3 The exp2 functions return 2x .
9067 7.12.6.3 The expm1 functions
9070 double expm1(double x);
9071 float expm1f(float x);
9072 long double expm1l(long double x);
9080 2 The expm1 functions compute the base-e exponential of the argument, minus 1. A range
9081 error occurs if x is too large.208)
9083 3 The expm1 functions return ex - 1.
9084 7.12.6.4 The frexp functions
9087 double frexp(double value, int *exp);
9088 float frexpf(float value, int *exp);
9089 long double frexpl(long double value, int *exp);
9091 2 The frexp functions break a floating-point number into a normalized fraction and an
9092 integral power of 2. They store the integer in the int object pointed to by exp.
9094 3 If value is not a floating-point number, the results are unspecified. Otherwise, the
9095 frexp functions return the value x, such that x has a magnitude in the interval [1/2, 1) or
9096 zero, and value equals x x 2*exp . If value is zero, both parts of the result are zero.
9097 7.12.6.5 The ilogb functions
9100 int ilogb(double x);
9101 int ilogbf(float x);
9102 int ilogbl(long double x);
9104 2 The ilogb functions extract the exponent of x as a signed int value. If x is zero they
9105 compute the value FP_ILOGB0; if x is infinite they compute the value INT_MAX; if x is
9106 a NaN they compute the value FP_ILOGBNAN; otherwise, they are equivalent to calling
9107 the corresponding logb function and casting the returned value to type int. A domain
9108 error or range error may occur if x is zero, infinite, or NaN. If the correct value is outside
9109 the range of the return type, the numeric result is unspecified.
9114 208) For small magnitude x, expm1(x) is expected to be more accurate than exp(x) - 1.
9119 3 The ilogb functions return the exponent of x as a signed int value.
9120 Forward references: the logb functions (7.12.6.11).
9121 7.12.6.6 The ldexp functions
9124 double ldexp(double x, int exp);
9125 float ldexpf(float x, int exp);
9126 long double ldexpl(long double x, int exp);
9128 2 The ldexp functions multiply a floating-point number by an integral power of 2. A
9129 range error may occur.
9131 3 The ldexp functions return x x 2exp .
9132 7.12.6.7 The log functions
9135 double log(double x);
9136 float logf(float x);
9137 long double logl(long double x);
9139 2 The log functions compute the base-e (natural) logarithm of x. A domain error occurs if
9140 the argument is negative. A range error may occur if the argument is zero.
9142 3 The log functions return loge x.
9143 7.12.6.8 The log10 functions
9146 double log10(double x);
9147 float log10f(float x);
9148 long double log10l(long double x);
9156 2 The log10 functions compute the base-10 (common) logarithm of x. A domain error
9157 occurs if the argument is negative. A range error may occur if the argument is zero.
9159 3 The log10 functions return log10 x.
9160 7.12.6.9 The log1p functions
9163 double log1p(double x);
9164 float log1pf(float x);
9165 long double log1pl(long double x);
9167 2 The log1p functions compute the base-e (natural) logarithm of 1 plus the argument.209)
9168 A domain error occurs if the argument is less than -1. A range error may occur if the
9171 3 The log1p functions return loge (1 + x).
9172 7.12.6.10 The log2 functions
9175 double log2(double x);
9176 float log2f(float x);
9177 long double log2l(long double x);
9179 2 The log2 functions compute the base-2 logarithm of x. A domain error occurs if the
9180 argument is less than zero. A range error may occur if the argument is zero.
9182 3 The log2 functions return log2 x.
9187 209) For small magnitude x, log1p(x) is expected to be more accurate than log(1 + x).
9191 7.12.6.11 The logb functions
9194 double logb(double x);
9195 float logbf(float x);
9196 long double logbl(long double x);
9198 2 The logb functions extract the exponent of x, as a signed integer value in floating-point
9199 format. If x is subnormal it is treated as though it were normalized; thus, for positive
9201 1 <= x x FLT_RADIX-logb(x) < FLT_RADIX
9202 A domain error or range error may occur if the argument is zero.
9204 3 The logb functions return the signed exponent of x.
9205 7.12.6.12 The modf functions
9208 double modf(double value, double *iptr);
9209 float modff(float value, float *iptr);
9210 long double modfl(long double value, long double *iptr);
9212 2 The modf functions break the argument value into integral and fractional parts, each of
9213 which has the same type and sign as the argument. They store the integral part (in
9214 floating-point format) in the object pointed to by iptr.
9216 3 The modf functions return the signed fractional part of value.
9223 7.12.6.13 The scalbn and scalbln functions
9226 double scalbn(double x, int n);
9227 float scalbnf(float x, int n);
9228 long double scalbnl(long double x, int n);
9229 double scalbln(double x, long int n);
9230 float scalblnf(float x, long int n);
9231 long double scalblnl(long double x, long int n);
9233 2 The scalbn and scalbln functions compute x x FLT_RADIXn efficiently, not
9234 normally by computing FLT_RADIXn explicitly. A range error may occur.
9236 3 The scalbn and scalbln functions return x x FLT_RADIXn .
9237 7.12.7 Power and absolute-value functions
9238 7.12.7.1 The cbrt functions
9241 double cbrt(double x);
9242 float cbrtf(float x);
9243 long double cbrtl(long double x);
9245 2 The cbrt functions compute the real cube root of x.
9247 3 The cbrt functions return x1/3 .
9248 7.12.7.2 The fabs functions
9251 double fabs(double x);
9252 float fabsf(float x);
9253 long double fabsl(long double x);
9255 2 The fabs functions compute the absolute value of a floating-point number x.
9261 3 The fabs functions return | x |.
9262 7.12.7.3 The hypot functions
9265 double hypot(double x, double y);
9266 float hypotf(float x, float y);
9267 long double hypotl(long double x, long double y);
9269 2 The hypot functions compute the square root of the sum of the squares of x and y,
9270 without undue overflow or underflow. A range error may occur.
9272 4 The hypot functions return sqrt:x2 + y2 .
9275 7.12.7.4 The pow functions
9278 double pow(double x, double y);
9279 float powf(float x, float y);
9280 long double powl(long double x, long double y);
9282 2 The pow functions compute x raised to the power y. A domain error occurs if x is finite
9283 and negative and y is finite and not an integer value. A range error may occur. A domain
9284 error may occur if x is zero and y is zero. A domain error or range error may occur if x
9285 is zero and y is less than zero.
9287 3 The pow functions return xy .
9288 7.12.7.5 The sqrt functions
9291 double sqrt(double x);
9292 float sqrtf(float x);
9293 long double sqrtl(long double x);
9301 2 The sqrt functions compute the nonnegative square root of x. A domain error occurs if
9302 the argument is less than zero.
9304 3 The sqrt functions return sqrt:x.
9307 7.12.8 Error and gamma functions
9308 7.12.8.1 The erf functions
9311 double erf(double x);
9312 float erff(float x);
9313 long double erfl(long double x);
9315 2 The erf functions compute the error function of x.
9320 The erf functions return erf x = e-t dt.
9328 7.12.8.2 The erfc functions
9331 double erfc(double x);
9332 float erfcf(float x);
9333 long double erfcl(long double x);
9335 2 The erfc functions compute the complementary error function of x. A range error
9336 occurs if x is too large.
9341 The erfc functions return erfc x = 1 - erf x = e-t dt.
9354 7.12.8.3 The lgamma functions
9357 double lgamma(double x);
9358 float lgammaf(float x);
9359 long double lgammal(long double x);
9361 2 The lgamma functions compute the natural logarithm of the absolute value of gamma of
9362 x. A range error occurs if x is too large. A range error may occur if x is a negative
9365 3 The lgamma functions return loge | (Gamma)(x) |.
9366 7.12.8.4 The tgamma functions
9369 double tgamma(double x);
9370 float tgammaf(float x);
9371 long double tgammal(long double x);
9373 2 The tgamma functions compute the gamma function of x. A domain error or range error
9374 may occur if x is a negative integer or zero. A range error may occur if the magnitude of
9375 x is too large or too small.
9377 3 The tgamma functions return (Gamma)(x).
9378 7.12.9 Nearest integer functions
9379 7.12.9.1 The ceil functions
9382 double ceil(double x);
9383 float ceilf(float x);
9384 long double ceill(long double x);
9386 2 The ceil functions compute the smallest integer value not less than x.
9392 3 The ceil functions return ???x???, expressed as a floating-point number.
9393 7.12.9.2 The floor functions
9396 double floor(double x);
9397 float floorf(float x);
9398 long double floorl(long double x);
9400 2 The floor functions compute the largest integer value not greater than x.
9402 3 The floor functions return ???x???, expressed as a floating-point number.
9403 7.12.9.3 The nearbyint functions
9406 double nearbyint(double x);
9407 float nearbyintf(float x);
9408 long double nearbyintl(long double x);
9410 2 The nearbyint functions round their argument to an integer value in floating-point
9411 format, using the current rounding direction and without raising the ''inexact'' floating-
9414 3 The nearbyint functions return the rounded integer value.
9415 7.12.9.4 The rint functions
9418 double rint(double x);
9419 float rintf(float x);
9420 long double rintl(long double x);
9422 2 The rint functions differ from the nearbyint functions (7.12.9.3) only in that the
9423 rint functions may raise the ''inexact'' floating-point exception if the result differs in
9424 value from the argument.
9428 3 The rint functions return the rounded integer value.
9429 7.12.9.5 The lrint and llrint functions
9432 long int lrint(double x);
9433 long int lrintf(float x);
9434 long int lrintl(long double x);
9435 long long int llrint(double x);
9436 long long int llrintf(float x);
9437 long long int llrintl(long double x);
9439 2 The lrint and llrint functions round their argument to the nearest integer value,
9440 rounding according to the current rounding direction. If the rounded value is outside the
9441 range of the return type, the numeric result is unspecified and a domain error or range
9444 3 The lrint and llrint functions return the rounded integer value.
9445 7.12.9.6 The round functions
9448 double round(double x);
9449 float roundf(float x);
9450 long double roundl(long double x);
9452 2 The round functions round their argument to the nearest integer value in floating-point
9453 format, rounding halfway cases away from zero, regardless of the current rounding
9456 3 The round functions return the rounded integer value.
9463 7.12.9.7 The lround and llround functions
9466 long int lround(double x);
9467 long int lroundf(float x);
9468 long int lroundl(long double x);
9469 long long int llround(double x);
9470 long long int llroundf(float x);
9471 long long int llroundl(long double x);
9473 2 The lround and llround functions round their argument to the nearest integer value,
9474 rounding halfway cases away from zero, regardless of the current rounding direction. If
9475 the rounded value is outside the range of the return type, the numeric result is unspecified
9476 and a domain error or range error may occur.
9478 3 The lround and llround functions return the rounded integer value.
9479 7.12.9.8 The trunc functions
9482 double trunc(double x);
9483 float truncf(float x);
9484 long double truncl(long double x);
9486 2 The trunc functions round their argument to the integer value, in floating format,
9487 nearest to but no larger in magnitude than the argument.
9489 3 The trunc functions return the truncated integer value.
9496 7.12.10 Remainder functions
9497 7.12.10.1 The fmod functions
9500 double fmod(double x, double y);
9501 float fmodf(float x, float y);
9502 long double fmodl(long double x, long double y);
9504 2 The fmod functions compute the floating-point remainder of x/y.
9506 3 The fmod functions return the value x - ny, for some integer n such that, if y is nonzero,
9507 the result has the same sign as x and magnitude less than the magnitude of y. If y is zero,
9508 whether a domain error occurs or the fmod functions return zero is implementation-
9510 7.12.10.2 The remainder functions
9513 double remainder(double x, double y);
9514 float remainderf(float x, float y);
9515 long double remainderl(long double x, long double y);
9517 2 The remainder functions compute the remainder x REM y required by IEC 60559.210)
9519 3 The remainder functions return x REM y. If y is zero, whether a domain error occurs
9520 or the functions return zero is implementation defined.
9525 210) ''When y != 0, the remainder r = x REM y is defined regardless of the rounding mode by the
9526 mathematical relation r = x - ny, where n is the integer nearest the exact value of x/y; whenever
9527 | n - x/y | = 1/2, then n is even. Thus, the remainder is always exact. If r = 0, its sign shall be that of
9528 x.'' This definition is applicable for all implementations.
9532 7.12.10.3 The remquo functions
9535 double remquo(double x, double y, int *quo);
9536 float remquof(float x, float y, int *quo);
9537 long double remquol(long double x, long double y,
9540 2 The remquo functions compute the same remainder as the remainder functions. In
9541 the object pointed to by quo they store a value whose sign is the sign of x/y and whose
9542 magnitude is congruent modulo 2n to the magnitude of the integral quotient of x/y, where
9543 n is an implementation-defined integer greater than or equal to 3.
9545 3 The remquo functions return x REM y. If y is zero, the value stored in the object
9546 pointed to by quo is unspecified and whether a domain error occurs or the functions
9547 return zero is implementation defined.
9548 7.12.11 Manipulation functions
9549 7.12.11.1 The copysign functions
9552 double copysign(double x, double y);
9553 float copysignf(float x, float y);
9554 long double copysignl(long double x, long double y);
9556 2 The copysign functions produce a value with the magnitude of x and the sign of y.
9557 They produce a NaN (with the sign of y) if x is a NaN. On implementations that
9558 represent a signed zero but do not treat negative zero consistently in arithmetic
9559 operations, the copysign functions regard the sign of zero as positive.
9561 3 The copysign functions return a value with the magnitude of x and the sign of y.
9568 7.12.11.2 The nan functions
9571 double nan(const char *tagp);
9572 float nanf(const char *tagp);
9573 long double nanl(const char *tagp);
9575 2 The call nan("n-char-sequence") is equivalent to strtod("NAN(n-char-
9576 sequence)", (char**) NULL); the call nan("") is equivalent to
9577 strtod("NAN()", (char**) NULL). If tagp does not point to an n-char
9578 sequence or an empty string, the call is equivalent to strtod("NAN", (char**)
9579 NULL). Calls to nanf and nanl are equivalent to the corresponding calls to strtof
9582 3 The nan functions return a quiet NaN, if available, with content indicated through tagp.
9583 If the implementation does not support quiet NaNs, the functions return zero.
9584 Forward references: the strtod, strtof, and strtold functions (7.20.1.3).
9585 7.12.11.3 The nextafter functions
9588 double nextafter(double x, double y);
9589 float nextafterf(float x, float y);
9590 long double nextafterl(long double x, long double y);
9592 2 The nextafter functions determine the next representable value, in the type of the
9593 function, after x in the direction of y, where x and y are first converted to the type of the
9594 function.211) The nextafter functions return y if x equals y. A range error may occur
9595 if the magnitude of x is the largest finite value representable in the type and the result is
9596 infinite or not representable in the type.
9598 3 The nextafter functions return the next representable value in the specified format
9599 after x in the direction of y.
9602 211) The argument values are converted to the type of the function, even by a macro implementation of the
9607 7.12.11.4 The nexttoward functions
9610 double nexttoward(double x, long double y);
9611 float nexttowardf(float x, long double y);
9612 long double nexttowardl(long double x, long double y);
9614 2 The nexttoward functions are equivalent to the nextafter functions except that the
9615 second parameter has type long double and the functions return y converted to the
9616 type of the function if x equals y.212)
9617 7.12.12 Maximum, minimum, and positive difference functions
9618 7.12.12.1 The fdim functions
9621 double fdim(double x, double y);
9622 float fdimf(float x, float y);
9623 long double fdiml(long double x, long double y);
9625 2 The fdim functions determine the positive difference between their arguments:
9629 A range error may occur.
9631 3 The fdim functions return the positive difference value.
9632 7.12.12.2 The fmax functions
9635 double fmax(double x, double y);
9636 float fmaxf(float x, float y);
9637 long double fmaxl(long double x, long double y);
9641 212) The result of the nexttoward functions is determined in the type of the function, without loss of
9642 range or precision in a floating second argument.
9647 2 The fmax functions determine the maximum numeric value of their arguments.213)
9649 3 The fmax functions return the maximum numeric value of their arguments.
9650 7.12.12.3 The fmin functions
9653 double fmin(double x, double y);
9654 float fminf(float x, float y);
9655 long double fminl(long double x, long double y);
9657 2 The fmin functions determine the minimum numeric value of their arguments.214)
9659 3 The fmin functions return the minimum numeric value of their arguments.
9660 7.12.13 Floating multiply-add
9661 7.12.13.1 The fma functions
9664 double fma(double x, double y, double z);
9665 float fmaf(float x, float y, float z);
9666 long double fmal(long double x, long double y,
9669 2 The fma functions compute (x x y) + z, rounded as one ternary operation: they compute
9670 the value (as if) to infinite precision and round once to the result format, according to the
9671 current rounding mode. A range error may occur.
9673 3 The fma functions return (x x y) + z, rounded as one ternary operation.
9678 213) NaN arguments are treated as missing data: if one argument is a NaN and the other numeric, then the
9679 fmax functions choose the numeric value. See F.9.9.2.
9680 214) The fmin functions are analogous to the fmax functions in their treatment of NaNs.
9684 7.12.14 Comparison macros
9685 1 The relational and equality operators support the usual mathematical relationships
9686 between numeric values. For any ordered pair of numeric values exactly one of the
9687 relationships -- less, greater, and equal -- is true. Relational operators may raise the
9688 ''invalid'' floating-point exception when argument values are NaNs. For a NaN and a
9689 numeric value, or for two NaNs, just the unordered relationship is true.215) The following
9690 subclauses provide macros that are quiet (non floating-point exception raising) versions
9691 of the relational operators, and other comparison macros that facilitate writing efficient
9692 code that accounts for NaNs without suffering the ''invalid'' floating-point exception. In
9693 the synopses in this subclause, real-floating indicates that the argument shall be an
9694 expression of real floating type.
9695 7.12.14.1 The isgreater macro
9698 int isgreater(real-floating x, real-floating y);
9700 2 The isgreater macro determines whether its first argument is greater than its second
9701 argument. The value of isgreater(x, y) is always equal to (x) > (y); however,
9702 unlike (x) > (y), isgreater(x, y) does not raise the ''invalid'' floating-point
9703 exception when x and y are unordered.
9705 3 The isgreater macro returns the value of (x) > (y).
9706 7.12.14.2 The isgreaterequal macro
9709 int isgreaterequal(real-floating x, real-floating y);
9711 2 The isgreaterequal macro determines whether its first argument is greater than or
9712 equal to its second argument. The value of isgreaterequal(x, y) is always equal
9713 to (x) >= (y); however, unlike (x) >= (y), isgreaterequal(x, y) does
9714 not raise the ''invalid'' floating-point exception when x and y are unordered.
9718 215) IEC 60559 requires that the built-in relational operators raise the ''invalid'' floating-point exception if
9719 the operands compare unordered, as an error indicator for programs written without consideration of
9720 NaNs; the result in these cases is false.
9725 3 The isgreaterequal macro returns the value of (x) >= (y).
9726 7.12.14.3 The isless macro
9729 int isless(real-floating x, real-floating y);
9731 2 The isless macro determines whether its first argument is less than its second
9732 argument. The value of isless(x, y) is always equal to (x) < (y); however,
9733 unlike (x) < (y), isless(x, y) does not raise the ''invalid'' floating-point
9734 exception when x and y are unordered.
9736 3 The isless macro returns the value of (x) < (y).
9737 7.12.14.4 The islessequal macro
9740 int islessequal(real-floating x, real-floating y);
9742 2 The islessequal macro determines whether its first argument is less than or equal to
9743 its second argument. The value of islessequal(x, y) is always equal to
9744 (x) <= (y); however, unlike (x) <= (y), islessequal(x, y) does not raise
9745 the ''invalid'' floating-point exception when x and y are unordered.
9747 3 The islessequal macro returns the value of (x) <= (y).
9748 7.12.14.5 The islessgreater macro
9751 int islessgreater(real-floating x, real-floating y);
9753 2 The islessgreater macro determines whether its first argument is less than or
9754 greater than its second argument. The islessgreater(x, y) macro is similar to
9755 (x) < (y) || (x) > (y); however, islessgreater(x, y) does not raise
9756 the ''invalid'' floating-point exception when x and y are unordered (nor does it evaluate x
9761 3 The islessgreater macro returns the value of (x) < (y) || (x) > (y).
9762 7.12.14.6 The isunordered macro
9765 int isunordered(real-floating x, real-floating y);
9767 2 The isunordered macro determines whether its arguments are unordered.
9769 3 The isunordered macro returns 1 if its arguments are unordered and 0 otherwise.
9776 7.13 Nonlocal jumps <setjmp.h>
9777 1 The header <setjmp.h> defines the macro setjmp, and declares one function and
9778 one type, for bypassing the normal function call and return discipline.216)
9779 2 The type declared is
9781 which is an array type suitable for holding the information needed to restore a calling
9782 environment. The environment of a call to the setjmp macro consists of information
9783 sufficient for a call to the longjmp function to return execution to the correct block and
9784 invocation of that block, were it called recursively. It does not include the state of the
9785 floating-point status flags, of open files, or of any other component of the abstract
9787 3 It is unspecified whether setjmp is a macro or an identifier declared with external
9788 linkage. If a macro definition is suppressed in order to access an actual function, or a
9789 program defines an external identifier with the name setjmp, the behavior is undefined.
9790 7.13.1 Save calling environment
9791 7.13.1.1 The setjmp macro
9793 1 #include <setjmp.h>
9794 int setjmp(jmp_buf env);
9796 2 The setjmp macro saves its calling environment in its jmp_buf argument for later use
9797 by the longjmp function.
9799 3 If the return is from a direct invocation, the setjmp macro returns the value zero. If the
9800 return is from a call to the longjmp function, the setjmp macro returns a nonzero
9802 Environmental limits
9803 4 An invocation of the setjmp macro shall appear only in one of the following contexts:
9804 -- the entire controlling expression of a selection or iteration statement;
9805 -- one operand of a relational or equality operator with the other operand an integer
9806 constant expression, with the resulting expression being the entire controlling
9809 216) These functions are useful for dealing with unusual conditions encountered in a low-level function of
9814 expression of a selection or iteration statement;
9815 -- the operand of a unary ! operator with the resulting expression being the entire
9816 controlling expression of a selection or iteration statement; or
9817 -- the entire expression of an expression statement (possibly cast to void).
9818 5 If the invocation appears in any other context, the behavior is undefined.
9819 7.13.2 Restore calling environment
9820 7.13.2.1 The longjmp function
9822 1 #include <setjmp.h>
9823 void longjmp(jmp_buf env, int val);
9825 2 The longjmp function restores the environment saved by the most recent invocation of
9826 the setjmp macro in the same invocation of the program with the corresponding
9827 jmp_buf argument. If there has been no such invocation, or if the function containing
9828 the invocation of the setjmp macro has terminated execution217) in the interim, or if the
9829 invocation of the setjmp macro was within the scope of an identifier with variably
9830 modified type and execution has left that scope in the interim, the behavior is undefined.
9831 3 All accessible objects have values, and all other components of the abstract machine218)
9832 have state, as of the time the longjmp function was called, except that the values of
9833 objects of automatic storage duration that are local to the function containing the
9834 invocation of the corresponding setjmp macro that do not have volatile-qualified type
9835 and have been changed between the setjmp invocation and longjmp call are
9838 4 After longjmp is completed, program execution continues as if the corresponding
9839 invocation of the setjmp macro had just returned the value specified by val. The
9840 longjmp function cannot cause the setjmp macro to return the value 0; if val is 0,
9841 the setjmp macro returns the value 1.
9842 5 EXAMPLE The longjmp function that returns control back to the point of the setjmp invocation
9843 might cause memory associated with a variable length array object to be squandered.
9848 217) For example, by executing a return statement or because another longjmp call has caused a
9849 transfer to a setjmp invocation in a function earlier in the set of nested calls.
9850 218) This includes, but is not limited to, the floating-point status flags and the state of open files.
9861 int x[n]; // valid: f is not terminated
9867 int a[n]; // a may remain allocated
9872 int b[n]; // b may remain allocated
9873 longjmp(buf, 2); // might cause memory loss
9881 7.14 Signal handling <signal.h>
9882 1 The header <signal.h> declares a type and two functions and defines several macros,
9883 for handling various signals (conditions that may be reported during program execution).
9884 2 The type defined is
9886 which is the (possibly volatile-qualified) integer type of an object that can be accessed as
9887 an atomic entity, even in the presence of asynchronous interrupts.
9888 3 The macros defined are
9892 which expand to constant expressions with distinct values that have type compatible with
9893 the second argument to, and the return value of, the signal function, and whose values
9894 compare unequal to the address of any declarable function; and the following, which
9895 expand to positive integer constant expressions with type int and distinct values that are
9896 the signal numbers, each corresponding to the specified condition:
9897 SIGABRT abnormal termination, such as is initiated by the abort function
9898 SIGFPE an erroneous arithmetic operation, such as zero divide or an operation
9899 resulting in overflow
9900 SIGILL detection of an invalid function image, such as an invalid instruction
9901 SIGINT receipt of an interactive attention signal
9902 SIGSEGV an invalid access to storage
9903 SIGTERM a termination request sent to the program
9904 4 An implementation need not generate any of these signals, except as a result of explicit
9905 calls to the raise function. Additional signals and pointers to undeclarable functions,
9906 with macro definitions beginning, respectively, with the letters SIG and an uppercase
9907 letter or with SIG_ and an uppercase letter,219) may also be specified by the
9908 implementation. The complete set of signals, their semantics, and their default handling
9909 is implementation-defined; all signal numbers shall be positive.
9914 219) See ''future library directions'' (7.26.9). The names of the signal numbers reflect the following terms
9915 (respectively): abort, floating-point exception, illegal instruction, interrupt, segmentation violation,
9920 7.14.1 Specify signal handling
9921 7.14.1.1 The signal function
9923 1 #include <signal.h>
9924 void (*signal(int sig, void (*func)(int)))(int);
9926 2 The signal function chooses one of three ways in which receipt of the signal number
9927 sig is to be subsequently handled. If the value of func is SIG_DFL, default handling
9928 for that signal will occur. If the value of func is SIG_IGN, the signal will be ignored.
9929 Otherwise, func shall point to a function to be called when that signal occurs. An
9930 invocation of such a function because of a signal, or (recursively) of any further functions
9931 called by that invocation (other than functions in the standard library), is called a signal
9933 3 When a signal occurs and func points to a function, it is implementation-defined
9934 whether the equivalent of signal(sig, SIG_DFL); is executed or the
9935 implementation prevents some implementation-defined set of signals (at least including
9936 sig) from occurring until the current signal handling has completed; in the case of
9937 SIGILL, the implementation may alternatively define that no action is taken. Then the
9938 equivalent of (*func)(sig); is executed. If and when the function returns, if the
9939 value of sig is SIGFPE, SIGILL, SIGSEGV, or any other implementation-defined
9940 value corresponding to a computational exception, the behavior is undefined; otherwise
9941 the program will resume execution at the point it was interrupted.
9942 4 If the signal occurs as the result of calling the abort or raise function, the signal
9943 handler shall not call the raise function.
9944 5 If the signal occurs other than as the result of calling the abort or raise function, the
9945 behavior is undefined if the signal handler refers to any object with static storage duration
9946 other than by assigning a value to an object declared as volatile sig_atomic_t, or
9947 the signal handler calls any function in the standard library other than the abort
9948 function, the _Exit function, or the signal function with the first argument equal to
9949 the signal number corresponding to the signal that caused the invocation of the handler.
9950 Furthermore, if such a call to the signal function results in a SIG_ERR return, the
9951 value of errno is indeterminate.220)
9952 6 At program startup, the equivalent of
9953 signal(sig, SIG_IGN);
9956 220) If any signal is generated by an asynchronous signal handler, the behavior is undefined.
9960 may be executed for some signals selected in an implementation-defined manner; the
9962 signal(sig, SIG_DFL);
9963 is executed for all other signals defined by the implementation.
9964 7 The implementation shall behave as if no library function calls the signal function.
9966 8 If the request can be honored, the signal function returns the value of func for the
9967 most recent successful call to signal for the specified signal sig. Otherwise, a value of
9968 SIG_ERR is returned and a positive value is stored in errno.
9969 Forward references: the abort function (7.20.4.1), the exit function (7.20.4.3), the
9970 _Exit function (7.20.4.4).
9972 7.14.2.1 The raise function
9974 1 #include <signal.h>
9977 2 The raise function carries out the actions described in 7.14.1.1 for the signal sig. If a
9978 signal handler is called, the raise function shall not return until after the signal handler
9981 3 The raise function returns zero if successful, nonzero if unsuccessful.
9988 7.15 Variable arguments <stdarg.h>
9989 1 The header <stdarg.h> declares a type and defines four macros, for advancing
9990 through a list of arguments whose number and types are not known to the called function
9991 when it is translated.
9992 2 A function may be called with a variable number of arguments of varying types. As
9993 described in 6.9.1, its parameter list contains one or more parameters. The rightmost
9994 parameter plays a special role in the access mechanism, and will be designated parmN in
9996 3 The type declared is
9998 which is an object type suitable for holding information needed by the macros
9999 va_start, va_arg, va_end, and va_copy. If access to the varying arguments is
10000 desired, the called function shall declare an object (generally referred to as ap in this
10001 subclause) having type va_list. The object ap may be passed as an argument to
10002 another function; if that function invokes the va_arg macro with parameter ap, the
10003 value of ap in the calling function is indeterminate and shall be passed to the va_end
10004 macro prior to any further reference to ap.221)
10005 7.15.1 Variable argument list access macros
10006 1 The va_start and va_arg macros described in this subclause shall be implemented
10007 as macros, not functions. It is unspecified whether va_copy and va_end are macros or
10008 identifiers declared with external linkage. If a macro definition is suppressed in order to
10009 access an actual function, or a program defines an external identifier with the same name,
10010 the behavior is undefined. Each invocation of the va_start and va_copy macros
10011 shall be matched by a corresponding invocation of the va_end macro in the same
10013 7.15.1.1 The va_arg macro
10015 1 #include <stdarg.h>
10016 type va_arg(va_list ap, type);
10018 2 The va_arg macro expands to an expression that has the specified type and the value of
10019 the next argument in the call. The parameter ap shall have been initialized by the
10020 va_start or va_copy macro (without an intervening invocation of the va_end
10022 221) It is permitted to create a pointer to a va_list and pass that pointer to another function, in which
10023 case the original function may make further use of the original list after the other function returns.
10027 macro for the same ap). Each invocation of the va_arg macro modifies ap so that the
10028 values of successive arguments are returned in turn. The parameter type shall be a type
10029 name specified such that the type of a pointer to an object that has the specified type can
10030 be obtained simply by postfixing a * to type. If there is no actual next argument, or if
10031 type is not compatible with the type of the actual next argument (as promoted according
10032 to the default argument promotions), the behavior is undefined, except for the following
10034 -- one type is a signed integer type, the other type is the corresponding unsigned integer
10035 type, and the value is representable in both types;
10036 -- one type is pointer to void and the other is a pointer to a character type.
10038 3 The first invocation of the va_arg macro after that of the va_start macro returns the
10039 value of the argument after that specified by parmN . Successive invocations return the
10040 values of the remaining arguments in succession.
10041 7.15.1.2 The va_copy macro
10043 1 #include <stdarg.h>
10044 void va_copy(va_list dest, va_list src);
10046 2 The va_copy macro initializes dest as a copy of src, as if the va_start macro had
10047 been applied to dest followed by the same sequence of uses of the va_arg macro as
10048 had previously been used to reach the present state of src. Neither the va_copy nor
10049 va_start macro shall be invoked to reinitialize dest without an intervening
10050 invocation of the va_end macro for the same dest.
10052 3 The va_copy macro returns no value.
10053 7.15.1.3 The va_end macro
10055 1 #include <stdarg.h>
10056 void va_end(va_list ap);
10058 2 The va_end macro facilitates a normal return from the function whose variable
10059 argument list was referred to by the expansion of the va_start macro, or the function
10060 containing the expansion of the va_copy macro, that initialized the va_list ap. The
10061 va_end macro may modify ap so that it is no longer usable (without being reinitialized
10065 by the va_start or va_copy macro). If there is no corresponding invocation of the
10066 va_start or va_copy macro, or if the va_end macro is not invoked before the
10067 return, the behavior is undefined.
10069 3 The va_end macro returns no value.
10070 7.15.1.4 The va_start macro
10072 1 #include <stdarg.h>
10073 void va_start(va_list ap, parmN);
10075 2 The va_start macro shall be invoked before any access to the unnamed arguments.
10076 3 The va_start macro initializes ap for subsequent use by the va_arg and va_end
10077 macros. Neither the va_start nor va_copy macro shall be invoked to reinitialize ap
10078 without an intervening invocation of the va_end macro for the same ap.
10079 4 The parameter parmN is the identifier of the rightmost parameter in the variable
10080 parameter list in the function definition (the one just before the , ...). If the parameter
10081 parmN is declared with the register storage class, with a function or array type, or
10082 with a type that is not compatible with the type that results after application of the default
10083 argument promotions, the behavior is undefined.
10085 5 The va_start macro returns no value.
10086 6 EXAMPLE 1 The function f1 gathers into an array a list of arguments that are pointers to strings (but not
10087 more than MAXARGS arguments), then passes the array as a single argument to function f2. The number of
10088 pointers is specified by the first argument to f1.
10089 #include <stdarg.h>
10091 void f1(int n_ptrs, ...)
10094 char *array[MAXARGS];
10102 if (n_ptrs > MAXARGS)
10104 va_start(ap, n_ptrs);
10105 while (ptr_no < n_ptrs)
10106 array[ptr_no++] = va_arg(ap, char *);
10110 Each call to f1 is required to have visible the definition of the function or a declaration such as
10113 7 EXAMPLE 2 The function f3 is similar, but saves the status of the variable argument list after the
10114 indicated number of arguments; after f2 has been called once with the whole list, the trailing part of the list
10115 is gathered again and passed to function f4.
10116 #include <stdarg.h>
10118 void f3(int n_ptrs, int f4_after, ...)
10120 va_list ap, ap_save;
10121 char *array[MAXARGS];
10123 if (n_ptrs > MAXARGS)
10125 va_start(ap, f4_after);
10126 while (ptr_no < n_ptrs) {
10127 array[ptr_no++] = va_arg(ap, char *);
10128 if (ptr_no == f4_after)
10129 va_copy(ap_save, ap);
10133 // Now process the saved copy.
10134 n_ptrs -= f4_after;
10136 while (ptr_no < n_ptrs)
10137 array[ptr_no++] = va_arg(ap_save, char *);
10147 7.16 Boolean type and values <stdbool.h>
10148 1 The header <stdbool.h> defines four macros.
10152 3 The remaining three macros are suitable for use in #if preprocessing directives. They
10155 which expands to the integer constant 1,
10157 which expands to the integer constant 0, and
10158 __bool_true_false_are_defined
10159 which expands to the integer constant 1.
10160 4 Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then
10161 redefine the macros bool, true, and false.222)
10166 222) See ''future library directions'' (7.26.7).
10170 7.17 Common definitions <stddef.h>
10171 1 The following types and macros are defined in the standard header <stddef.h>. Some
10172 are also defined in other headers, as noted in their respective subclauses.
10175 which is the signed integer type of the result of subtracting two pointers;
10177 which is the unsigned integer type of the result of the sizeof operator; and
10179 which is an integer type whose range of values can represent distinct codes for all
10180 members of the largest extended character set specified among the supported locales; the
10181 null character shall have the code value zero. Each member of the basic character set
10182 shall have a code value equal to its value when used as the lone character in an integer
10183 character constant if an implementation does not define
10184 __STDC_MB_MIGHT_NEQ_WC__.
10187 which expands to an implementation-defined null pointer constant; and
10188 offsetof(type, member-designator)
10189 which expands to an integer constant expression that has type size_t, the value of
10190 which is the offset in bytes, to the structure member (designated by member-designator),
10191 from the beginning of its structure (designated by type). The type and member designator
10192 shall be such that given
10194 then the expression &(t.member-designator) evaluates to an address constant. (If the
10195 specified member is a bit-field, the behavior is undefined.)
10196 Recommended practice
10197 4 The types used for size_t and ptrdiff_t should not have an integer conversion rank
10198 greater than that of signed long int unless the implementation supports objects
10199 large enough to make this necessary.
10200 Forward references: localization (7.11).
10207 7.18 Integer types <stdint.h>
10208 1 The header <stdint.h> declares sets of integer types having specified widths, and
10209 defines corresponding sets of macros.223) It also defines macros that specify limits of
10210 integer types corresponding to types defined in other standard headers.
10211 2 Types are defined in the following categories:
10212 -- integer types having certain exact widths;
10213 -- integer types having at least certain specified widths;
10214 -- fastest integer types having at least certain specified widths;
10215 -- integer types wide enough to hold pointers to objects;
10216 -- integer types having greatest width.
10217 (Some of these types may denote the same type.)
10218 3 Corresponding macros specify limits of the declared types and construct suitable
10220 4 For each type described herein that the implementation provides,224) <stdint.h> shall
10221 declare that typedef name and define the associated macros. Conversely, for each type
10222 described herein that the implementation does not provide, <stdint.h> shall not
10223 declare that typedef name nor shall it define the associated macros. An implementation
10224 shall provide those types described as ''required'', but need not provide any of the others
10225 (described as ''optional'').
10226 7.18.1 Integer types
10227 1 When typedef names differing only in the absence or presence of the initial u are defined,
10228 they shall denote corresponding signed and unsigned types as described in 6.2.5; an
10229 implementation providing one of these corresponding types shall also provide the other.
10230 2 In the following descriptions, the symbol N represents an unsigned decimal integer with
10231 no leading zeros (e.g., 8 or 24, but not 04 or 048).
10236 223) See ''future library directions'' (7.26.8).
10237 224) Some of these types may denote implementation-defined extended integer types.
10241 7.18.1.1 Exact-width integer types
10242 1 The typedef name intN_t designates a signed integer type with width N , no padding
10243 bits, and a two's complement representation. Thus, int8_t denotes a signed integer
10244 type with a width of exactly 8 bits.
10245 2 The typedef name uintN_t designates an unsigned integer type with width N . Thus,
10246 uint24_t denotes an unsigned integer type with a width of exactly 24 bits.
10247 3 These types are optional. However, if an implementation provides integer types with
10248 widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a
10249 two's complement representation, it shall define the corresponding typedef names.
10250 7.18.1.2 Minimum-width integer types
10251 1 The typedef name int_leastN_t designates a signed integer type with a width of at
10252 least N , such that no signed integer type with lesser size has at least the specified width.
10253 Thus, int_least32_t denotes a signed integer type with a width of at least 32 bits.
10254 2 The typedef name uint_leastN_t designates an unsigned integer type with a width
10255 of at least N , such that no unsigned integer type with lesser size has at least the specified
10256 width. Thus, uint_least16_t denotes an unsigned integer type with a width of at
10258 3 The following types are required:
10259 int_least8_t uint_least8_t
10260 int_least16_t uint_least16_t
10261 int_least32_t uint_least32_t
10262 int_least64_t uint_least64_t
10263 All other types of this form are optional.
10264 7.18.1.3 Fastest minimum-width integer types
10265 1 Each of the following types designates an integer type that is usually fastest225) to operate
10266 with among all integer types that have at least the specified width.
10267 2 The typedef name int_fastN_t designates the fastest signed integer type with a width
10268 of at least N . The typedef name uint_fastN_t designates the fastest unsigned integer
10269 type with a width of at least N .
10274 225) The designated type is not guaranteed to be fastest for all purposes; if the implementation has no clear
10275 grounds for choosing one type over another, it will simply pick some integer type satisfying the
10276 signedness and width requirements.
10280 3 The following types are required:
10281 int_fast8_t uint_fast8_t
10282 int_fast16_t uint_fast16_t
10283 int_fast32_t uint_fast32_t
10284 int_fast64_t uint_fast64_t
10285 All other types of this form are optional.
10286 7.18.1.4 Integer types capable of holding object pointers
10287 1 The following type designates a signed integer type with the property that any valid
10288 pointer to void can be converted to this type, then converted back to pointer to void,
10289 and the result will compare equal to the original pointer:
10291 The following type designates an unsigned integer type with the property that any valid
10292 pointer to void can be converted to this type, then converted back to pointer to void,
10293 and the result will compare equal to the original pointer:
10295 These types are optional.
10296 7.18.1.5 Greatest-width integer types
10297 1 The following type designates a signed integer type capable of representing any value of
10298 any signed integer type:
10300 The following type designates an unsigned integer type capable of representing any value
10301 of any unsigned integer type:
10303 These types are required.
10304 7.18.2 Limits of specified-width integer types
10305 1 The following object-like macros226) specify the minimum and maximum limits of the
10306 types declared in <stdint.h>. Each macro name corresponds to a similar type name in
10308 2 Each instance of any defined macro shall be replaced by a constant expression suitable
10309 for use in #if preprocessing directives, and this expression shall have the same type as
10310 would an expression that is an object of the corresponding type converted according to
10312 226) C++ implementations should define these macros only when __STDC_LIMIT_MACROS is defined
10313 before <stdint.h> is included.
10317 the integer promotions. Its implementation-defined value shall be equal to or greater in
10318 magnitude (absolute value) than the corresponding value given below, with the same sign,
10319 except where stated to be exactly the given value.
10320 7.18.2.1 Limits of exact-width integer types
10321 1 -- minimum values of exact-width signed integer types
10322 INTN_MIN exactly -(2 N -1 )
10323 -- maximum values of exact-width signed integer types
10324 INTN_MAX exactly 2 N -1 - 1
10325 -- maximum values of exact-width unsigned integer types
10326 UINTN_MAX exactly 2 N - 1
10327 7.18.2.2 Limits of minimum-width integer types
10328 1 -- minimum values of minimum-width signed integer types
10329 INT_LEASTN_MIN -(2 N -1 - 1)
10330 -- maximum values of minimum-width signed integer types
10331 INT_LEASTN_MAX 2 N -1 - 1
10332 -- maximum values of minimum-width unsigned integer types
10333 UINT_LEASTN_MAX 2N - 1
10334 7.18.2.3 Limits of fastest minimum-width integer types
10335 1 -- minimum values of fastest minimum-width signed integer types
10336 INT_FASTN_MIN -(2 N -1 - 1)
10337 -- maximum values of fastest minimum-width signed integer types
10338 INT_FASTN_MAX 2 N -1 - 1
10339 -- maximum values of fastest minimum-width unsigned integer types
10340 UINT_FASTN_MAX 2N - 1
10341 7.18.2.4 Limits of integer types capable of holding object pointers
10342 1 -- minimum value of pointer-holding signed integer type
10343 INTPTR_MIN -(215 - 1)
10344 -- maximum value of pointer-holding signed integer type
10351 -- maximum value of pointer-holding unsigned integer type
10352 UINTPTR_MAX 216 - 1
10353 7.18.2.5 Limits of greatest-width integer types
10354 1 -- minimum value of greatest-width signed integer type
10355 INTMAX_MIN -(263 - 1)
10356 -- maximum value of greatest-width signed integer type
10358 -- maximum value of greatest-width unsigned integer type
10359 UINTMAX_MAX 264 - 1
10360 7.18.3 Limits of other integer types
10361 1 The following object-like macros227) specify the minimum and maximum limits of
10362 integer types corresponding to types defined in other standard headers.
10363 2 Each instance of these macros shall be replaced by a constant expression suitable for use
10364 in #if preprocessing directives, and this expression shall have the same type as would an
10365 expression that is an object of the corresponding type converted according to the integer
10366 promotions. Its implementation-defined value shall be equal to or greater in magnitude
10367 (absolute value) than the corresponding value given below, with the same sign. An
10368 implementation shall define only the macros corresponding to those typedef names it
10369 actually provides.228)
10370 -- limits of ptrdiff_t
10373 -- limits of sig_atomic_t
10374 SIG_ATOMIC_MIN see below
10375 SIG_ATOMIC_MAX see below
10378 -- limits of wchar_t
10382 227) C++ implementations should define these macros only when __STDC_LIMIT_MACROS is defined
10383 before <stdint.h> is included.
10384 228) A freestanding implementation need not provide all of these types.
10388 WCHAR_MIN see below
10389 WCHAR_MAX see below
10390 -- limits of wint_t
10393 3 If sig_atomic_t (see 7.14) is defined as a signed integer type, the value of
10394 SIG_ATOMIC_MIN shall be no greater than -127 and the value of SIG_ATOMIC_MAX
10395 shall be no less than 127; otherwise, sig_atomic_t is defined as an unsigned integer
10396 type, and the value of SIG_ATOMIC_MIN shall be 0 and the value of
10397 SIG_ATOMIC_MAX shall be no less than 255.
10398 4 If wchar_t (see 7.17) is defined as a signed integer type, the value of WCHAR_MIN
10399 shall be no greater than -127 and the value of WCHAR_MAX shall be no less than 127;
10400 otherwise, wchar_t is defined as an unsigned integer type, and the value of
10401 WCHAR_MIN shall be 0 and the value of WCHAR_MAX shall be no less than 255.229)
10402 5 If wint_t (see 7.24) is defined as a signed integer type, the value of WINT_MIN shall
10403 be no greater than -32767 and the value of WINT_MAX shall be no less than 32767;
10404 otherwise, wint_t is defined as an unsigned integer type, and the value of WINT_MIN
10405 shall be 0 and the value of WINT_MAX shall be no less than 65535.
10406 7.18.4 Macros for integer constants
10407 1 The following function-like macros230) expand to integer constants suitable for
10408 initializing objects that have integer types corresponding to types defined in
10409 <stdint.h>. Each macro name corresponds to a similar type name in 7.18.1.2 or
10411 2 The argument in any instance of these macros shall be an unsuffixed integer constant (as
10412 defined in 6.4.4.1) with a value that does not exceed the limits for the corresponding type.
10413 3 Each invocation of one of these macros shall expand to an integer constant expression
10414 suitable for use in #if preprocessing directives. The type of the expression shall have
10415 the same type as would an expression of the corresponding type converted according to
10416 the integer promotions. The value of the expression shall be that of the argument.
10421 229) The values WCHAR_MIN and WCHAR_MAX do not necessarily correspond to members of the extended
10423 230) C++ implementations should define these macros only when __STDC_CONSTANT_MACROS is
10424 defined before <stdint.h> is included.
10428 7.18.4.1 Macros for minimum-width integer constants
10429 1 The macro INTN_C(value) shall expand to an integer constant expression
10430 corresponding to the type int_leastN_t. The macro UINTN_C(value) shall expand
10431 to an integer constant expression corresponding to the type uint_leastN_t. For
10432 example, if uint_least64_t is a name for the type unsigned long long int,
10433 then UINT64_C(0x123) might expand to the integer constant 0x123ULL.
10434 7.18.4.2 Macros for greatest-width integer constants
10435 1 The following macro expands to an integer constant expression having the value specified
10436 by its argument and the type intmax_t:
10438 The following macro expands to an integer constant expression having the value specified
10439 by its argument and the type uintmax_t:
10447 7.19 Input/output <stdio.h>
10448 7.19.1 Introduction
10449 1 The header <stdio.h> declares three types, several macros, and many functions for
10450 performing input and output.
10451 2 The types declared are size_t (described in 7.17);
10453 which is an object type capable of recording all the information needed to control a
10454 stream, including its file position indicator, a pointer to its associated buffer (if any), an
10455 error indicator that records whether a read/write error has occurred, and an end-of-file
10456 indicator that records whether the end of the file has been reached; and
10458 which is an object type other than an array type capable of recording all the information
10459 needed to specify uniquely every position within a file.
10460 3 The macros are NULL (described in 7.17);
10464 which expand to integer constant expressions with distinct values, suitable for use as the
10465 third argument to the setvbuf function;
10467 which expands to an integer constant expression that is the size of the buffer used by the
10470 which expands to an integer constant expression, with type int and a negative value, that
10471 is returned by several functions to indicate end-of-file, that is, no more input from a
10474 which expands to an integer constant expression that is the minimum number of files that
10475 the implementation guarantees can be open simultaneously;
10477 which expands to an integer constant expression that is the size needed for an array of
10478 char large enough to hold the longest file name string that the implementation
10484 guarantees can be opened;231)
10486 which expands to an integer constant expression that is the size needed for an array of
10487 char large enough to hold a temporary file name string generated by the tmpnam
10492 which expand to integer constant expressions with distinct values, suitable for use as the
10493 third argument to the fseek function;
10495 which expands to an integer constant expression that is the maximum number of unique
10496 file names that can be generated by the tmpnam function;
10500 which are expressions of type ''pointer to FILE'' that point to the FILE objects
10501 associated, respectively, with the standard error, input, and output streams.
10502 4 The header <wchar.h> declares a number of functions useful for wide character input
10503 and output. The wide character input/output functions described in that subclause
10504 provide operations analogous to most of those described here, except that the
10505 fundamental units internal to the program are wide characters. The external
10506 representation (in the file) is a sequence of ''generalized'' multibyte characters, as
10507 described further in 7.19.3.
10508 5 The input/output functions are given the following collective terms:
10509 -- The wide character input functions -- those functions described in 7.24 that perform
10510 input into wide characters and wide strings: fgetwc, fgetws, getwc, getwchar,
10511 fwscanf, wscanf, vfwscanf, and vwscanf.
10512 -- The wide character output functions -- those functions described in 7.24 that perform
10513 output from wide characters and wide strings: fputwc, fputws, putwc,
10514 putwchar, fwprintf, wprintf, vfwprintf, and vwprintf.
10517 231) If the implementation imposes no practical limit on the length of file name strings, the value of
10518 FILENAME_MAX should instead be the recommended size of an array intended to hold a file name
10519 string. Of course, file name string contents are subject to other system-specific constraints; therefore
10520 all possible strings of length FILENAME_MAX cannot be expected to be opened successfully.
10524 -- The wide character input/output functions -- the union of the ungetwc function, the
10525 wide character input functions, and the wide character output functions.
10526 -- The byte input/output functions -- those functions described in this subclause that
10527 perform input/output: fgetc, fgets, fprintf, fputc, fputs, fread,
10528 fscanf, fwrite, getc, getchar, gets, printf, putc, putchar, puts,
10529 scanf, ungetc, vfprintf, vfscanf, vprintf, and vscanf.
10530 Forward references: files (7.19.3), the fseek function (7.19.9.2), streams (7.19.2), the
10531 tmpnam function (7.19.4.4), <wchar.h> (7.24).
10533 1 Input and output, whether to or from physical devices such as terminals and tape drives,
10534 or whether to or from files supported on structured storage devices, are mapped into
10535 logical data streams, whose properties are more uniform than their various inputs and
10536 outputs. Two forms of mapping are supported, for text streams and for binary
10538 2 A text stream is an ordered sequence of characters composed into lines, each line
10539 consisting of zero or more characters plus a terminating new-line character. Whether the
10540 last line requires a terminating new-line character is implementation-defined. Characters
10541 may have to be added, altered, or deleted on input and output to conform to differing
10542 conventions for representing text in the host environment. Thus, there need not be a one-
10543 to-one correspondence between the characters in a stream and those in the external
10544 representation. Data read in from a text stream will necessarily compare equal to the data
10545 that were earlier written out to that stream only if: the data consist only of printing
10546 characters and the control characters horizontal tab and new-line; no new-line character is
10547 immediately preceded by space characters; and the last character is a new-line character.
10548 Whether space characters that are written out immediately before a new-line character
10549 appear when read in is implementation-defined.
10550 3 A binary stream is an ordered sequence of characters that can transparently record
10551 internal data. Data read in from a binary stream shall compare equal to the data that were
10552 earlier written out to that stream, under the same implementation. Such a stream may,
10553 however, have an implementation-defined number of null characters appended to the end
10555 4 Each stream has an orientation. After a stream is associated with an external file, but
10556 before any operations are performed on it, the stream is without orientation. Once a wide
10557 character input/output function has been applied to a stream without orientation, the
10560 232) An implementation need not distinguish between text streams and binary streams. In such an
10561 implementation, there need be no new-line characters in a text stream nor any limit to the length of a
10566 stream becomes a wide-oriented stream. Similarly, once a byte input/output function has
10567 been applied to a stream without orientation, the stream becomes a byte-oriented stream.
10568 Only a call to the freopen function or the fwide function can otherwise alter the
10569 orientation of a stream. (A successful call to freopen removes any orientation.)233)
10570 5 Byte input/output functions shall not be applied to a wide-oriented stream and wide
10571 character input/output functions shall not be applied to a byte-oriented stream. The
10572 remaining stream operations do not affect, and are not affected by, a stream's orientation,
10573 except for the following additional restrictions:
10574 -- Binary wide-oriented streams have the file-positioning restrictions ascribed to both
10575 text and binary streams.
10576 -- For wide-oriented streams, after a successful call to a file-positioning function that
10577 leaves the file position indicator prior to the end-of-file, a wide character output
10578 function can overwrite a partial multibyte character; any file contents beyond the
10579 byte(s) written are henceforth indeterminate.
10580 6 Each wide-oriented stream has an associated mbstate_t object that stores the current
10581 parse state of the stream. A successful call to fgetpos stores a representation of the
10582 value of this mbstate_t object as part of the value of the fpos_t object. A later
10583 successful call to fsetpos using the same stored fpos_t value restores the value of
10584 the associated mbstate_t object as well as the position within the controlled stream.
10585 Environmental limits
10586 7 An implementation shall support text files with lines containing at least 254 characters,
10587 including the terminating new-line character. The value of the macro BUFSIZ shall be at
10589 Forward references: the freopen function (7.19.5.4), the fwide function (7.24.3.5),
10590 mbstate_t (7.25.1), the fgetpos function (7.19.9.1), the fsetpos function
10596 233) The three predefined streams stdin, stdout, and stderr are unoriented at program startup.
10601 1 A stream is associated with an external file (which may be a physical device) by opening
10602 a file, which may involve creating a new file. Creating an existing file causes its former
10603 contents to be discarded, if necessary. If a file can support positioning requests (such as a
10604 disk file, as opposed to a terminal), then a file position indicator associated with the
10605 stream is positioned at the start (character number zero) of the file, unless the file is
10606 opened with append mode in which case it is implementation-defined whether the file
10607 position indicator is initially positioned at the beginning or the end of the file. The file
10608 position indicator is maintained by subsequent reads, writes, and positioning requests, to
10609 facilitate an orderly progression through the file.
10610 2 Binary files are not truncated, except as defined in 7.19.5.3. Whether a write on a text
10611 stream causes the associated file to be truncated beyond that point is implementation-
10613 3 When a stream is unbuffered, characters are intended to appear from the source or at the
10614 destination as soon as possible. Otherwise characters may be accumulated and
10615 transmitted to or from the host environment as a block. When a stream is fully buffered,
10616 characters are intended to be transmitted to or from the host environment as a block when
10617 a buffer is filled. When a stream is line buffered, characters are intended to be
10618 transmitted to or from the host environment as a block when a new-line character is
10619 encountered. Furthermore, characters are intended to be transmitted as a block to the host
10620 environment when a buffer is filled, when input is requested on an unbuffered stream, or
10621 when input is requested on a line buffered stream that requires the transmission of
10622 characters from the host environment. Support for these characteristics is
10623 implementation-defined, and may be affected via the setbuf and setvbuf functions.
10624 4 A file may be disassociated from a controlling stream by closing the file. Output streams
10625 are flushed (any unwritten buffer contents are transmitted to the host environment) before
10626 the stream is disassociated from the file. The value of a pointer to a FILE object is
10627 indeterminate after the associated file is closed (including the standard text streams).
10628 Whether a file of zero length (on which no characters have been written by an output
10629 stream) actually exists is implementation-defined.
10630 5 The file may be subsequently reopened, by the same or another program execution, and
10631 its contents reclaimed or modified (if it can be repositioned at its start). If the main
10632 function returns to its original caller, or if the exit function is called, all open files are
10633 closed (hence all output streams are flushed) before program termination. Other paths to
10634 program termination, such as calling the abort function, need not close all files
10636 6 The address of the FILE object used to control a stream may be significant; a copy of a
10637 FILE object need not serve in place of the original.
10641 7 At program startup, three text streams are predefined and need not be opened explicitly
10642 -- standard input (for reading conventional input), standard output (for writing
10643 conventional output), and standard error (for writing diagnostic output). As initially
10644 opened, the standard error stream is not fully buffered; the standard input and standard
10645 output streams are fully buffered if and only if the stream can be determined not to refer
10646 to an interactive device.
10647 8 Functions that open additional (nontemporary) files require a file name, which is a string.
10648 The rules for composing valid file names are implementation-defined. Whether the same
10649 file can be simultaneously open multiple times is also implementation-defined.
10650 9 Although both text and binary wide-oriented streams are conceptually sequences of wide
10651 characters, the external file associated with a wide-oriented stream is a sequence of
10652 multibyte characters, generalized as follows:
10653 -- Multibyte encodings within files may contain embedded null bytes (unlike multibyte
10654 encodings valid for use internal to the program).
10655 -- A file need not begin nor end in the initial shift state.234)
10656 10 Moreover, the encodings used for multibyte characters may differ among files. Both the
10657 nature and choice of such encodings are implementation-defined.
10658 11 The wide character input functions read multibyte characters from the stream and convert
10659 them to wide characters as if they were read by successive calls to the fgetwc function.
10660 Each conversion occurs as if by a call to the mbrtowc function, with the conversion state
10661 described by the stream's own mbstate_t object. The byte input functions read
10662 characters from the stream as if by successive calls to the fgetc function.
10663 12 The wide character output functions convert wide characters to multibyte characters and
10664 write them to the stream as if they were written by successive calls to the fputwc
10665 function. Each conversion occurs as if by a call to the wcrtomb function, with the
10666 conversion state described by the stream's own mbstate_t object. The byte output
10667 functions write characters to the stream as if by successive calls to the fputc function.
10668 13 In some cases, some of the byte input/output functions also perform conversions between
10669 multibyte characters and wide characters. These conversions also occur as if by calls to
10670 the mbrtowc and wcrtomb functions.
10671 14 An encoding error occurs if the character sequence presented to the underlying
10672 mbrtowc function does not form a valid (generalized) multibyte character, or if the code
10673 value passed to the underlying wcrtomb does not correspond to a valid (generalized)
10676 234) Setting the file position indicator to end-of-file, as with fseek(file, 0, SEEK_END), has
10677 undefined behavior for a binary stream (because of possible trailing null characters) or for any stream
10678 with state-dependent encoding that does not assuredly end in the initial shift state.
10682 multibyte character. The wide character input/output functions and the byte input/output
10683 functions store the value of the macro EILSEQ in errno if and only if an encoding error
10685 Environmental limits
10686 15 The value of FOPEN_MAX shall be at least eight, including the three standard text
10688 Forward references: the exit function (7.20.4.3), the fgetc function (7.19.7.1), the
10689 fopen function (7.19.5.3), the fputc function (7.19.7.3), the setbuf function
10690 (7.19.5.5), the setvbuf function (7.19.5.6), the fgetwc function (7.24.3.1), the
10691 fputwc function (7.24.3.3), conversion state (7.24.6), the mbrtowc function
10692 (7.24.6.3.2), the wcrtomb function (7.24.6.3.3).
10693 7.19.4 Operations on files
10694 7.19.4.1 The remove function
10696 1 #include <stdio.h>
10697 int remove(const char *filename);
10699 2 The remove function causes the file whose name is the string pointed to by filename
10700 to be no longer accessible by that name. A subsequent attempt to open that file using that
10701 name will fail, unless it is created anew. If the file is open, the behavior of the remove
10702 function is implementation-defined.
10704 3 The remove function returns zero if the operation succeeds, nonzero if it fails.
10705 7.19.4.2 The rename function
10707 1 #include <stdio.h>
10708 int rename(const char *old, const char *new);
10710 2 The rename function causes the file whose name is the string pointed to by old to be
10711 henceforth known by the name given by the string pointed to by new. The file named
10712 old is no longer accessible by that name. If a file named by the string pointed to by new
10713 exists prior to the call to the rename function, the behavior is implementation-defined.
10721 3 The rename function returns zero if the operation succeeds, nonzero if it fails,235) in
10722 which case if the file existed previously it is still known by its original name.
10723 7.19.4.3 The tmpfile function
10725 1 #include <stdio.h>
10726 FILE *tmpfile(void);
10728 2 The tmpfile function creates a temporary binary file that is different from any other
10729 existing file and that will automatically be removed when it is closed or at program
10730 termination. If the program terminates abnormally, whether an open temporary file is
10731 removed is implementation-defined. The file is opened for update with "wb+" mode.
10732 Recommended practice
10733 3 It should be possible to open at least TMP_MAX temporary files during the lifetime of the
10734 program (this limit may be shared with tmpnam) and there should be no limit on the
10735 number simultaneously open other than this limit and any limit on the number of open
10738 4 The tmpfile function returns a pointer to the stream of the file that it created. If the file
10739 cannot be created, the tmpfile function returns a null pointer.
10740 Forward references: the fopen function (7.19.5.3).
10741 7.19.4.4 The tmpnam function
10743 1 #include <stdio.h>
10744 char *tmpnam(char *s);
10746 2 The tmpnam function generates a string that is a valid file name and that is not the same
10747 as the name of an existing file.236) The function is potentially capable of generating
10750 235) Among the reasons the implementation may cause the rename function to fail are that the file is open
10751 or that it is necessary to copy its contents to effectuate its renaming.
10752 236) Files created using strings generated by the tmpnam function are temporary only in the sense that
10753 their names should not collide with those generated by conventional naming rules for the
10754 implementation. It is still necessary to use the remove function to remove such files when their use
10755 is ended, and before program termination.
10759 TMP_MAX different strings, but any or all of them may already be in use by existing files
10760 and thus not be suitable return values.
10761 3 The tmpnam function generates a different string each time it is called.
10762 4 The implementation shall behave as if no library function calls the tmpnam function.
10764 5 If no suitable string can be generated, the tmpnam function returns a null pointer.
10765 Otherwise, if the argument is a null pointer, the tmpnam function leaves its result in an
10766 internal static object and returns a pointer to that object (subsequent calls to the tmpnam
10767 function may modify the same object). If the argument is not a null pointer, it is assumed
10768 to point to an array of at least L_tmpnam chars; the tmpnam function writes its result
10769 in that array and returns the argument as its value.
10770 Environmental limits
10771 6 The value of the macro TMP_MAX shall be at least 25.
10772 7.19.5 File access functions
10773 7.19.5.1 The fclose function
10775 1 #include <stdio.h>
10776 int fclose(FILE *stream);
10778 2 A successful call to the fclose function causes the stream pointed to by stream to be
10779 flushed and the associated file to be closed. Any unwritten buffered data for the stream
10780 are delivered to the host environment to be written to the file; any unread buffered data
10781 are discarded. Whether or not the call succeeds, the stream is disassociated from the file
10782 and any buffer set by the setbuf or setvbuf function is disassociated from the stream
10783 (and deallocated if it was automatically allocated).
10785 3 The fclose function returns zero if the stream was successfully closed, or EOF if any
10786 errors were detected.
10787 7.19.5.2 The fflush function
10789 1 #include <stdio.h>
10790 int fflush(FILE *stream);
10798 2 If stream points to an output stream or an update stream in which the most recent
10799 operation was not input, the fflush function causes any unwritten data for that stream
10800 to be delivered to the host environment to be written to the file; otherwise, the behavior is
10802 3 If stream is a null pointer, the fflush function performs this flushing action on all
10803 streams for which the behavior is defined above.
10805 4 The fflush function sets the error indicator for the stream and returns EOF if a write
10806 error occurs, otherwise it returns zero.
10807 Forward references: the fopen function (7.19.5.3).
10808 7.19.5.3 The fopen function
10810 1 #include <stdio.h>
10811 FILE *fopen(const char * restrict filename,
10812 const char * restrict mode);
10814 2 The fopen function opens the file whose name is the string pointed to by filename,
10815 and associates a stream with it.
10816 3 The argument mode points to a string. If the string is one of the following, the file is
10817 open in the indicated mode. Otherwise, the behavior is undefined.237)
10818 r open text file for reading
10819 w truncate to zero length or create text file for writing
10820 a append; open or create text file for writing at end-of-file
10821 rb open binary file for reading
10822 wb truncate to zero length or create binary file for writing
10823 ab append; open or create binary file for writing at end-of-file
10824 r+ open text file for update (reading and writing)
10825 w+ truncate to zero length or create text file for update
10826 a+ append; open or create text file for update, writing at end-of-file
10831 237) If the string begins with one of the above sequences, the implementation might choose to ignore the
10832 remaining characters, or it might use them to select different kinds of a file (some of which might not
10833 conform to the properties in 7.19.2).
10837 r+b or rb+ open binary file for update (reading and writing)
10838 w+b or wb+ truncate to zero length or create binary file for update
10839 a+b or ab+ append; open or create binary file for update, writing at end-of-file
10840 4 Opening a file with read mode ('r' as the first character in the mode argument) fails if
10841 the file does not exist or cannot be read.
10842 5 Opening a file with append mode ('a' as the first character in the mode argument)
10843 causes all subsequent writes to the file to be forced to the then current end-of-file,
10844 regardless of intervening calls to the fseek function. In some implementations, opening
10845 a binary file with append mode ('b' as the second or third character in the above list of
10846 mode argument values) may initially position the file position indicator for the stream
10847 beyond the last data written, because of null character padding.
10848 6 When a file is opened with update mode ('+' as the second or third character in the
10849 above list of mode argument values), both input and output may be performed on the
10850 associated stream. However, output shall not be directly followed by input without an
10851 intervening call to the fflush function or to a file positioning function (fseek,
10852 fsetpos, or rewind), and input shall not be directly followed by output without an
10853 intervening call to a file positioning function, unless the input operation encounters end-
10854 of-file. Opening (or creating) a text file with update mode may instead open (or create) a
10855 binary stream in some implementations.
10856 7 When opened, a stream is fully buffered if and only if it can be determined not to refer to
10857 an interactive device. The error and end-of-file indicators for the stream are cleared.
10859 8 The fopen function returns a pointer to the object controlling the stream. If the open
10860 operation fails, fopen returns a null pointer.
10861 Forward references: file positioning functions (7.19.9).
10862 7.19.5.4 The freopen function
10864 1 #include <stdio.h>
10865 FILE *freopen(const char * restrict filename,
10866 const char * restrict mode,
10867 FILE * restrict stream);
10869 2 The freopen function opens the file whose name is the string pointed to by filename
10870 and associates the stream pointed to by stream with it. The mode argument is used just
10877 as in the fopen function.238)
10878 3 If filename is a null pointer, the freopen function attempts to change the mode of
10879 the stream to that specified by mode, as if the name of the file currently associated with
10880 the stream had been used. It is implementation-defined which changes of mode are
10881 permitted (if any), and under what circumstances.
10882 4 The freopen function first attempts to close any file that is associated with the specified
10883 stream. Failure to close the file is ignored. The error and end-of-file indicators for the
10884 stream are cleared.
10886 5 The freopen function returns a null pointer if the open operation fails. Otherwise,
10887 freopen returns the value of stream.
10888 7.19.5.5 The setbuf function
10890 1 #include <stdio.h>
10891 void setbuf(FILE * restrict stream,
10892 char * restrict buf);
10894 2 Except that it returns no value, the setbuf function is equivalent to the setvbuf
10895 function invoked with the values _IOFBF for mode and BUFSIZ for size, or (if buf
10896 is a null pointer), with the value _IONBF for mode.
10898 3 The setbuf function returns no value.
10899 Forward references: the setvbuf function (7.19.5.6).
10900 7.19.5.6 The setvbuf function
10902 1 #include <stdio.h>
10903 int setvbuf(FILE * restrict stream,
10904 char * restrict buf,
10905 int mode, size_t size);
10910 238) The primary use of the freopen function is to change the file associated with a standard text stream
10911 (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value
10912 returned by the fopen function may be assigned.
10917 2 The setvbuf function may be used only after the stream pointed to by stream has
10918 been associated with an open file and before any other operation (other than an
10919 unsuccessful call to setvbuf) is performed on the stream. The argument mode
10920 determines how stream will be buffered, as follows: _IOFBF causes input/output to be
10921 fully buffered; _IOLBF causes input/output to be line buffered; _IONBF causes
10922 input/output to be unbuffered. If buf is not a null pointer, the array it points to may be
10923 used instead of a buffer allocated by the setvbuf function239) and the argument size
10924 specifies the size of the array; otherwise, size may determine the size of a buffer
10925 allocated by the setvbuf function. The contents of the array at any time are
10928 3 The setvbuf function returns zero on success, or nonzero if an invalid value is given
10929 for mode or if the request cannot be honored.
10930 7.19.6 Formatted input/output functions
10931 1 The formatted input/output functions shall behave as if there is a sequence point after the
10932 actions associated with each specifier.240)
10933 7.19.6.1 The fprintf function
10935 1 #include <stdio.h>
10936 int fprintf(FILE * restrict stream,
10937 const char * restrict format, ...);
10939 2 The fprintf function writes output to the stream pointed to by stream, under control
10940 of the string pointed to by format that specifies how subsequent arguments are
10941 converted for output. If there are insufficient arguments for the format, the behavior is
10942 undefined. If the format is exhausted while arguments remain, the excess arguments are
10943 evaluated (as always) but are otherwise ignored. The fprintf function returns when
10944 the end of the format string is encountered.
10945 3 The format shall be a multibyte character sequence, beginning and ending in its initial
10946 shift state. The format is composed of zero or more directives: ordinary multibyte
10947 characters (not %), which are copied unchanged to the output stream; and conversion
10950 239) The buffer has to have a lifetime at least as great as the open stream, so the stream should be closed
10951 before a buffer that has automatic storage duration is deallocated upon block exit.
10952 240) The fprintf functions perform writes to memory for the %n specifier.
10956 specifications, each of which results in fetching zero or more subsequent arguments,
10957 converting them, if applicable, according to the corresponding conversion specifier, and
10958 then writing the result to the output stream.
10959 4 Each conversion specification is introduced by the character %. After the %, the following
10960 appear in sequence:
10961 -- Zero or more flags (in any order) that modify the meaning of the conversion
10963 -- An optional minimum field width. If the converted value has fewer characters than the
10964 field width, it is padded with spaces (by default) on the left (or right, if the left
10965 adjustment flag, described later, has been given) to the field width. The field width
10966 takes the form of an asterisk * (described later) or a nonnegative decimal integer.241)
10967 -- An optional precision that gives the minimum number of digits to appear for the d, i,
10968 o, u, x, and X conversions, the number of digits to appear after the decimal-point
10969 character for a, A, e, E, f, and F conversions, the maximum number of significant
10970 digits for the g and G conversions, or the maximum number of bytes to be written for
10971 s conversions. The precision takes the form of a period (.) followed either by an
10972 asterisk * (described later) or by an optional decimal integer; if only the period is
10973 specified, the precision is taken as zero. If a precision appears with any other
10974 conversion specifier, the behavior is undefined.
10975 -- An optional length modifier that specifies the size of the argument.
10976 -- A conversion specifier character that specifies the type of conversion to be applied.
10977 5 As noted above, a field width, or precision, or both, may be indicated by an asterisk. In
10978 this case, an int argument supplies the field width or precision. The arguments
10979 specifying field width, or precision, or both, shall appear (in that order) before the
10980 argument (if any) to be converted. A negative field width argument is taken as a - flag
10981 followed by a positive field width. A negative precision argument is taken as if the
10982 precision were omitted.
10983 6 The flag characters and their meanings are:
10984 - The result of the conversion is left-justified within the field. (It is right-justified if
10985 this flag is not specified.)
10986 + The result of a signed conversion always begins with a plus or minus sign. (It
10987 begins with a sign only when a negative value is converted if this flag is not
10992 241) Note that 0 is taken as a flag, not as the beginning of a field width.
10997 space If the first character of a signed conversion is not a sign, or if a signed conversion
10998 results in no characters, a space is prefixed to the result. If the space and + flags
10999 both appear, the space flag is ignored.
11000 # The result is converted to an ''alternative form''. For o conversion, it increases
11001 the precision, if and only if necessary, to force the first digit of the result to be a
11002 zero (if the value and precision are both 0, a single 0 is printed). For x (or X)
11003 conversion, a nonzero result has 0x (or 0X) prefixed to it. For a, A, e, E, f, F, g,
11004 and G conversions, the result of converting a floating-point number always
11005 contains a decimal-point character, even if no digits follow it. (Normally, a
11006 decimal-point character appears in the result of these conversions only if a digit
11007 follows it.) For g and G conversions, trailing zeros are not removed from the
11008 result. For other conversions, the behavior is undefined.
11009 0 For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros
11010 (following any indication of sign or base) are used to pad to the field width rather
11011 than performing space padding, except when converting an infinity or NaN. If the
11012 0 and - flags both appear, the 0 flag is ignored. For d, i, o, u, x, and X
11013 conversions, if a precision is specified, the 0 flag is ignored. For other
11014 conversions, the behavior is undefined.
11015 7 The length modifiers and their meanings are:
11016 hh Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
11017 signed char or unsigned char argument (the argument will have
11018 been promoted according to the integer promotions, but its value shall be
11019 converted to signed char or unsigned char before printing); or that
11020 a following n conversion specifier applies to a pointer to a signed char
11022 h Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
11023 short int or unsigned short int argument (the argument will
11024 have been promoted according to the integer promotions, but its value shall
11025 be converted to short int or unsigned short int before printing);
11026 or that a following n conversion specifier applies to a pointer to a short
11028 l (ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
11029 long int or unsigned long int argument; that a following n
11030 conversion specifier applies to a pointer to a long int argument; that a
11032 242) The results of all floating conversions of a negative zero, and of negative values that round to zero,
11033 include a minus sign.
11037 following c conversion specifier applies to a wint_t argument; that a
11038 following s conversion specifier applies to a pointer to a wchar_t
11039 argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion
11041 ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
11042 long long int or unsigned long long int argument; or that a
11043 following n conversion specifier applies to a pointer to a long long int
11045 j Specifies that a following d, i, o, u, x, or X conversion specifier applies to
11046 an intmax_t or uintmax_t argument; or that a following n conversion
11047 specifier applies to a pointer to an intmax_t argument.
11048 z Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
11049 size_t or the corresponding signed integer type argument; or that a
11050 following n conversion specifier applies to a pointer to a signed integer type
11051 corresponding to size_t argument.
11052 t Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
11053 ptrdiff_t or the corresponding unsigned integer type argument; or that a
11054 following n conversion specifier applies to a pointer to a ptrdiff_t
11056 L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
11057 applies to a long double argument.
11058 If a length modifier appears with any conversion specifier other than as specified above,
11059 the behavior is undefined.
11060 8 The conversion specifiers and their meanings are:
11061 d,i The int argument is converted to signed decimal in the style [-]dddd. The
11062 precision specifies the minimum number of digits to appear; if the value
11063 being converted can be represented in fewer digits, it is expanded with
11064 leading zeros. The default precision is 1. The result of converting a zero
11065 value with a precision of zero is no characters.
11066 o,u,x,X The unsigned int argument is converted to unsigned octal (o), unsigned
11067 decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; the
11068 letters abcdef are used for x conversion and the letters ABCDEF for X
11069 conversion. The precision specifies the minimum number of digits to appear;
11070 if the value being converted can be represented in fewer digits, it is expanded
11071 with leading zeros. The default precision is 1. The result of converting a
11072 zero value with a precision of zero is no characters.
11077 f,F A double argument representing a floating-point number is converted to
11078 decimal notation in the style [-]ddd.ddd, where the number of digits after
11079 the decimal-point character is equal to the precision specification. If the
11080 precision is missing, it is taken as 6; if the precision is zero and the # flag is
11081 not specified, no decimal-point character appears. If a decimal-point
11082 character appears, at least one digit appears before it. The value is rounded to
11083 the appropriate number of digits.
11084 A double argument representing an infinity is converted in one of the styles
11085 [-]inf or [-]infinity -- which style is implementation-defined. A
11086 double argument representing a NaN is converted in one of the styles
11087 [-]nan or [-]nan(n-char-sequence) -- which style, and the meaning of
11088 any n-char-sequence, is implementation-defined. The F conversion specifier
11089 produces INF, INFINITY, or NAN instead of inf, infinity, or nan,
11091 e,E A double argument representing a floating-point number is converted in the
11092 style [-]d.ddd e(+-)dd, where there is one digit (which is nonzero if the
11093 argument is nonzero) before the decimal-point character and the number of
11094 digits after it is equal to the precision; if the precision is missing, it is taken as
11095 6; if the precision is zero and the # flag is not specified, no decimal-point
11096 character appears. The value is rounded to the appropriate number of digits.
11097 The E conversion specifier produces a number with E instead of e
11098 introducing the exponent. The exponent always contains at least two digits,
11099 and only as many more digits as necessary to represent the exponent. If the
11100 value is zero, the exponent is zero.
11101 A double argument representing an infinity or NaN is converted in the style
11102 of an f or F conversion specifier.
11103 g,G A double argument representing a floating-point number is converted in
11104 style f or e (or in style F or E in the case of a G conversion specifier),
11105 depending on the value converted and the precision. Let P equal the
11106 precision if nonzero, 6 if the precision is omitted, or 1 if the precision is zero.
11107 Then, if a conversion with style E would have an exponent of X :
11108 -- if P > X >= -4, the conversion is with style f (or F) and precision
11110 -- otherwise, the conversion is with style e (or E) and precision P - 1.
11111 Finally, unless the # flag is used, any trailing zeros are removed from the
11113 243) When applied to infinite and NaN values, the -, +, and space flag characters have their usual meaning;
11114 the # and 0 flag characters have no effect.
11118 fractional portion of the result and the decimal-point character is removed if
11119 there is no fractional portion remaining.
11120 A double argument representing an infinity or NaN is converted in the style
11121 of an f or F conversion specifier.
11122 a,A A double argument representing a floating-point number is converted in the
11123 style [-]0xh.hhhh p(+-)d, where there is one hexadecimal digit (which is
11124 nonzero if the argument is a normalized floating-point number and is
11125 otherwise unspecified) before the decimal-point character244) and the number
11126 of hexadecimal digits after it is equal to the precision; if the precision is
11127 missing and FLT_RADIX is a power of 2, then the precision is sufficient for
11128 an exact representation of the value; if the precision is missing and
11129 FLT_RADIX is not a power of 2, then the precision is sufficient to
11130 distinguish245) values of type double, except that trailing zeros may be
11131 omitted; if the precision is zero and the # flag is not specified, no decimal-
11132 point character appears. The letters abcdef are used for a conversion and
11133 the letters ABCDEF for A conversion. The A conversion specifier produces a
11134 number with X and P instead of x and p. The exponent always contains at
11135 least one digit, and only as many more digits as necessary to represent the
11136 decimal exponent of 2. If the value is zero, the exponent is zero.
11137 A double argument representing an infinity or NaN is converted in the style
11138 of an f or F conversion specifier.
11139 c If no l length modifier is present, the int argument is converted to an
11140 unsigned char, and the resulting character is written.
11141 If an l length modifier is present, the wint_t argument is converted as if by
11142 an ls conversion specification with no precision and an argument that points
11143 to the initial element of a two-element array of wchar_t, the first element
11144 containing the wint_t argument to the lc conversion specification and the
11145 second a null wide character.
11146 s If no l length modifier is present, the argument shall be a pointer to the initial
11147 element of an array of character type.246) Characters from the array are
11150 244) Binary implementations can choose the hexadecimal digit to the left of the decimal-point character so
11151 that subsequent digits align to nibble (4-bit) boundaries.
11152 245) The precision p is sufficient to distinguish values of the source type if 16 p-1 > b n where b is
11153 FLT_RADIX and n is the number of base-b digits in the significand of the source type. A smaller p
11154 might suffice depending on the implementation's scheme for determining the digit to the left of the
11155 decimal-point character.
11156 246) No special provisions are made for multibyte characters.
11160 written up to (but not including) the terminating null character. If the
11161 precision is specified, no more than that many bytes are written. If the
11162 precision is not specified or is greater than the size of the array, the array shall
11163 contain a null character.
11164 If an l length modifier is present, the argument shall be a pointer to the initial
11165 element of an array of wchar_t type. Wide characters from the array are
11166 converted to multibyte characters (each as if by a call to the wcrtomb
11167 function, with the conversion state described by an mbstate_t object
11168 initialized to zero before the first wide character is converted) up to and
11169 including a terminating null wide character. The resulting multibyte
11170 characters are written up to (but not including) the terminating null character
11171 (byte). If no precision is specified, the array shall contain a null wide
11172 character. If a precision is specified, no more than that many bytes are
11173 written (including shift sequences, if any), and the array shall contain a null
11174 wide character if, to equal the multibyte character sequence length given by
11175 the precision, the function would need to access a wide character one past the
11176 end of the array. In no case is a partial multibyte character written.247)
11177 p The argument shall be a pointer to void. The value of the pointer is
11178 converted to a sequence of printing characters, in an implementation-defined
11180 n The argument shall be a pointer to signed integer into which is written the
11181 number of characters written to the output stream so far by this call to
11182 fprintf. No argument is converted, but one is consumed. If the conversion
11183 specification includes any flags, a field width, or a precision, the behavior is
11185 % A % character is written. No argument is converted. The complete
11186 conversion specification shall be %%.
11187 9 If a conversion specification is invalid, the behavior is undefined.248) If any argument is
11188 not the correct type for the corresponding conversion specification, the behavior is
11190 10 In no case does a nonexistent or small field width cause truncation of a field; if the result
11191 of a conversion is wider than the field width, the field is expanded to contain the
11197 247) Redundant shift sequences may result if multibyte characters have a state-dependent encoding.
11198 248) See ''future library directions'' (7.26.9).
11202 11 For a and A conversions, if FLT_RADIX is a power of 2, the value is correctly rounded
11203 to a hexadecimal floating number with the given precision.
11204 Recommended practice
11205 12 For a and A conversions, if FLT_RADIX is not a power of 2 and the result is not exactly
11206 representable in the given precision, the result should be one of the two adjacent numbers
11207 in hexadecimal floating style with the given precision, with the extra stipulation that the
11208 error should have a correct sign for the current rounding direction.
11209 13 For e, E, f, F, g, and G conversions, if the number of significant decimal digits is at most
11210 DECIMAL_DIG, then the result should be correctly rounded.249) If the number of
11211 significant decimal digits is more than DECIMAL_DIG but the source value is exactly
11212 representable with DECIMAL_DIG digits, then the result should be an exact
11213 representation with trailing zeros. Otherwise, the source value is bounded by two
11214 adjacent decimal strings L < U, both having DECIMAL_DIG significant digits; the value
11215 of the resultant decimal string D should satisfy L <= D <= U, with the extra stipulation that
11216 the error should have a correct sign for the current rounding direction.
11218 14 The fprintf function returns the number of characters transmitted, or a negative value
11219 if an output or encoding error occurred.
11220 Environmental limits
11221 15 The number of characters that can be produced by any single conversion shall be at least
11223 16 EXAMPLE 1 To print a date and time in the form ''Sunday, July 3, 10:02'' followed by pi to five decimal
11228 char *weekday, *month; // pointers to strings
11229 int day, hour, min;
11230 fprintf(stdout, "%s, %s %d, %.2d:%.2d\n",
11231 weekday, month, day, hour, min);
11232 fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0));
11234 17 EXAMPLE 2 In this example, multibyte characters do not have a state-dependent encoding, and the
11235 members of the extended character set that consist of more than one byte each consist of exactly two bytes,
11236 the first of which is denoted here by a and the second by an uppercase letter.
11241 249) For binary-to-decimal conversion, the result format's values are the numbers representable with the
11242 given format specifier. The number of significant digits is determined by the format specifier, and in
11243 the case of fixed-point conversion by the source value as well.
11247 18 Given the following wide string with length seven,
11248 static wchar_t wstr[] = L" X Yabc Z W";
11250 fprintf(stdout, "|1234567890123|\n");
11251 fprintf(stdout, "|%13ls|\n", wstr);
11252 fprintf(stdout, "|%-13.9ls|\n", wstr);
11253 fprintf(stdout, "|%13.10ls|\n", wstr);
11254 fprintf(stdout, "|%13.11ls|\n", wstr);
11255 fprintf(stdout, "|%13.15ls|\n", &wstr[2]);
11256 fprintf(stdout, "|%13lc|\n", (wint_t) wstr[5]);
11257 will print the following seven lines:
11266 Forward references: conversion state (7.24.6), the wcrtomb function (7.24.6.3.3).
11267 7.19.6.2 The fscanf function
11269 1 #include <stdio.h>
11270 int fscanf(FILE * restrict stream,
11271 const char * restrict format, ...);
11273 2 The fscanf function reads input from the stream pointed to by stream, under control
11274 of the string pointed to by format that specifies the admissible input sequences and how
11275 they are to be converted for assignment, using subsequent arguments as pointers to the
11276 objects to receive the converted input. If there are insufficient arguments for the format,
11277 the behavior is undefined. If the format is exhausted while arguments remain, the excess
11278 arguments are evaluated (as always) but are otherwise ignored.
11279 3 The format shall be a multibyte character sequence, beginning and ending in its initial
11280 shift state. The format is composed of zero or more directives: one or more white-space
11281 characters, an ordinary multibyte character (neither % nor a white-space character), or a
11282 conversion specification. Each conversion specification is introduced by the character %.
11283 After the %, the following appear in sequence:
11284 -- An optional assignment-suppressing character *.
11285 -- An optional decimal integer greater than zero that specifies the maximum field width
11290 -- An optional length modifier that specifies the size of the receiving object.
11291 -- A conversion specifier character that specifies the type of conversion to be applied.
11292 4 The fscanf function executes each directive of the format in turn. If a directive fails, as
11293 detailed below, the function returns. Failures are described as input failures (due to the
11294 occurrence of an encoding error or the unavailability of input characters), or matching
11295 failures (due to inappropriate input).
11296 5 A directive composed of white-space character(s) is executed by reading input up to the
11297 first non-white-space character (which remains unread), or until no more characters can
11299 6 A directive that is an ordinary multibyte character is executed by reading the next
11300 characters of the stream. If any of those characters differ from the ones composing the
11301 directive, the directive fails and the differing and subsequent characters remain unread.
11302 Similarly, if end-of-file, an encoding error, or a read error prevents a character from being
11303 read, the directive fails.
11304 7 A directive that is a conversion specification defines a set of matching input sequences, as
11305 described below for each specifier. A conversion specification is executed in the
11307 8 Input white-space characters (as specified by the isspace function) are skipped, unless
11308 the specification includes a [, c, or n specifier.250)
11309 9 An input item is read from the stream, unless the specification includes an n specifier. An
11310 input item is defined as the longest sequence of input characters which does not exceed
11311 any specified field width and which is, or is a prefix of, a matching input sequence.251)
11312 The first character, if any, after the input item remains unread. If the length of the input
11313 item is zero, the execution of the directive fails; this condition is a matching failure unless
11314 end-of-file, an encoding error, or a read error prevented input from the stream, in which
11315 case it is an input failure.
11316 10 Except in the case of a % specifier, the input item (or, in the case of a %n directive, the
11317 count of input characters) is converted to a type appropriate to the conversion specifier. If
11318 the input item is not a matching sequence, the execution of the directive fails: this
11319 condition is a matching failure. Unless assignment suppression was indicated by a *, the
11320 result of the conversion is placed in the object pointed to by the first argument following
11321 the format argument that has not already received a conversion result. If this object
11322 does not have an appropriate type, or if the result of the conversion cannot be represented
11325 250) These white-space characters are not counted against a specified field width.
11326 251) fscanf pushes back at most one input character onto the input stream. Therefore, some sequences
11327 that are acceptable to strtod, strtol, etc., are unacceptable to fscanf.
11331 in the object, the behavior is undefined.
11332 11 The length modifiers and their meanings are:
11333 hh Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11334 to an argument with type pointer to signed char or unsigned char.
11335 h Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11336 to an argument with type pointer to short int or unsigned short
11338 l (ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11339 to an argument with type pointer to long int or unsigned long
11340 int; that a following a, A, e, E, f, F, g, or G conversion specifier applies to
11341 an argument with type pointer to double; or that a following c, s, or [
11342 conversion specifier applies to an argument with type pointer to wchar_t.
11343 ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11344 to an argument with type pointer to long long int or unsigned
11346 j Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11347 to an argument with type pointer to intmax_t or uintmax_t.
11348 z Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11349 to an argument with type pointer to size_t or the corresponding signed
11351 t Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
11352 to an argument with type pointer to ptrdiff_t or the corresponding
11353 unsigned integer type.
11354 L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
11355 applies to an argument with type pointer to long double.
11356 If a length modifier appears with any conversion specifier other than as specified above,
11357 the behavior is undefined.
11358 12 The conversion specifiers and their meanings are:
11359 d Matches an optionally signed decimal integer, whose format is the same as
11360 expected for the subject sequence of the strtol function with the value 10
11361 for the base argument. The corresponding argument shall be a pointer to
11363 i Matches an optionally signed integer, whose format is the same as expected
11364 for the subject sequence of the strtol function with the value 0 for the
11365 base argument. The corresponding argument shall be a pointer to signed
11369 o Matches an optionally signed octal integer, whose format is the same as
11370 expected for the subject sequence of the strtoul function with the value 8
11371 for the base argument. The corresponding argument shall be a pointer to
11373 u Matches an optionally signed decimal integer, whose format is the same as
11374 expected for the subject sequence of the strtoul function with the value 10
11375 for the base argument. The corresponding argument shall be a pointer to
11377 x Matches an optionally signed hexadecimal integer, whose format is the same
11378 as expected for the subject sequence of the strtoul function with the value
11379 16 for the base argument. The corresponding argument shall be a pointer to
11381 a,e,f,g Matches an optionally signed floating-point number, infinity, or NaN, whose
11382 format is the same as expected for the subject sequence of the strtod
11383 function. The corresponding argument shall be a pointer to floating.
11384 c Matches a sequence of characters of exactly the number specified by the field
11385 width (1 if no field width is present in the directive).252)
11386 If no l length modifier is present, the corresponding argument shall be a
11387 pointer to the initial element of a character array large enough to accept the
11388 sequence. No null character is added.
11389 If an l length modifier is present, the input shall be a sequence of multibyte
11390 characters that begins in the initial shift state. Each multibyte character in the
11391 sequence is converted to a wide character as if by a call to the mbrtowc
11392 function, with the conversion state described by an mbstate_t object
11393 initialized to zero before the first multibyte character is converted. The
11394 corresponding argument shall be a pointer to the initial element of an array of
11395 wchar_t large enough to accept the resulting sequence of wide characters.
11396 No null wide character is added.
11397 s Matches a sequence of non-white-space characters.252)
11398 If no l length modifier is present, the corresponding argument shall be a
11399 pointer to the initial element of a character array large enough to accept the
11400 sequence and a terminating null character, which will be added automatically.
11401 If an l length modifier is present, the input shall be a sequence of multibyte
11404 252) No special provisions are made for multibyte characters in the matching rules used by the c, s, and [
11405 conversion specifiers -- the extent of the input field is determined on a byte-by-byte basis. The
11406 resulting field is nevertheless a sequence of multibyte characters that begins in the initial shift state.
11410 characters that begins in the initial shift state. Each multibyte character is
11411 converted to a wide character as if by a call to the mbrtowc function, with
11412 the conversion state described by an mbstate_t object initialized to zero
11413 before the first multibyte character is converted. The corresponding argument
11414 shall be a pointer to the initial element of an array of wchar_t large enough
11415 to accept the sequence and the terminating null wide character, which will be
11416 added automatically.
11417 [ Matches a nonempty sequence of characters from a set of expected characters
11419 If no l length modifier is present, the corresponding argument shall be a
11420 pointer to the initial element of a character array large enough to accept the
11421 sequence and a terminating null character, which will be added automatically.
11422 If an l length modifier is present, the input shall be a sequence of multibyte
11423 characters that begins in the initial shift state. Each multibyte character is
11424 converted to a wide character as if by a call to the mbrtowc function, with
11425 the conversion state described by an mbstate_t object initialized to zero
11426 before the first multibyte character is converted. The corresponding argument
11427 shall be a pointer to the initial element of an array of wchar_t large enough
11428 to accept the sequence and the terminating null wide character, which will be
11429 added automatically.
11430 The conversion specifier includes all subsequent characters in the format
11431 string, up to and including the matching right bracket (]). The characters
11432 between the brackets (the scanlist) compose the scanset, unless the character
11433 after the left bracket is a circumflex (^), in which case the scanset contains all
11434 characters that do not appear in the scanlist between the circumflex and the
11435 right bracket. If the conversion specifier begins with [] or [^], the right
11436 bracket character is in the scanlist and the next following right bracket
11437 character is the matching right bracket that ends the specification; otherwise
11438 the first following right bracket character is the one that ends the
11439 specification. If a - character is in the scanlist and is not the first, nor the
11440 second where the first character is a ^, nor the last character, the behavior is
11441 implementation-defined.
11442 p Matches an implementation-defined set of sequences, which should be the
11443 same as the set of sequences that may be produced by the %p conversion of
11444 the fprintf function. The corresponding argument shall be a pointer to a
11445 pointer to void. The input item is converted to a pointer value in an
11446 implementation-defined manner. If the input item is a value converted earlier
11447 during the same program execution, the pointer that results shall compare
11448 equal to that value; otherwise the behavior of the %p conversion is undefined.
11452 n No input is consumed. The corresponding argument shall be a pointer to
11453 signed integer into which is to be written the number of characters read from
11454 the input stream so far by this call to the fscanf function. Execution of a
11455 %n directive does not increment the assignment count returned at the
11456 completion of execution of the fscanf function. No argument is converted,
11457 but one is consumed. If the conversion specification includes an assignment-
11458 suppressing character or a field width, the behavior is undefined.
11459 % Matches a single % character; no conversion or assignment occurs. The
11460 complete conversion specification shall be %%.
11461 13 If a conversion specification is invalid, the behavior is undefined.253)
11462 14 The conversion specifiers A, E, F, G, and X are also valid and behave the same as,
11463 respectively, a, e, f, g, and x.
11464 15 Trailing white space (including new-line characters) is left unread unless matched by a
11465 directive. The success of literal matches and suppressed assignments is not directly
11466 determinable other than via the %n directive.
11468 16 The fscanf function returns the value of the macro EOF if an input failure occurs
11469 before any conversion. Otherwise, the function returns the number of input items
11470 assigned, which can be fewer than provided for, or even zero, in the event of an early
11472 17 EXAMPLE 1 The call:
11475 int n, i; float x; char name[50];
11476 n = fscanf(stdin, "%d%f%s", &i, &x, name);
11477 with the input line:
11478 25 54.32E-1 thompson
11479 will assign to n the value 3, to i the value 25, to x the value 5.432, and to name the sequence
11482 18 EXAMPLE 2 The call:
11485 int i; float x; char name[50];
11486 fscanf(stdin, "%2d%f%*d %[0123456789]", &i, &x, name);
11491 253) See ''future library directions'' (7.26.9).
11496 will assign to i the value 56 and to x the value 789.0, will skip 0123, and will assign to name the
11497 sequence 56\0. The next character read from the input stream will be a.
11499 19 EXAMPLE 3 To accept repeatedly from stdin a quantity, a unit of measure, and an item name:
11502 int count; float quant; char units[21], item[21];
11504 count = fscanf(stdin, "%f%20s of %20s", &quant, units, item);
11505 fscanf(stdin,"%*[^\n]");
11506 } while (!feof(stdin) && !ferror(stdin));
11507 20 If the stdin stream contains the following lines:
11509 -12.8degrees Celsius
11514 the execution of the above example will be analogous to the following assignments:
11515 quant = 2; strcpy(units, "quarts"); strcpy(item, "oil");
11517 quant = -12.8; strcpy(units, "degrees");
11518 count = 2; // "C" fails to match "o"
11519 count = 0; // "l" fails to match "%f"
11520 quant = 10.0; strcpy(units, "LBS"); strcpy(item, "dirt");
11522 count = 0; // "100e" fails to match "%f"
11528 int d1, d2, n1, n2, i;
11529 i = sscanf("123", "%d%n%n%d", &d1, &n1, &n2, &d2);
11530 the value 123 is assigned to d1 and the value 3 to n1. Because %n can never get an input failure the value
11531 of 3 is also assigned to n2. The value of d2 is not affected. The value 1 is assigned to i.
11533 22 EXAMPLE 5 In these examples, multibyte characters do have a state-dependent encoding, and the
11534 members of the extended character set that consist of more than one byte each consist of exactly two bytes,
11535 the first of which is denoted here by a and the second by an uppercase letter, but are only recognized as
11536 such when in the alternate shift state. The shift sequences are denoted by (uparrow) and (downarrow), in which the first causes
11537 entry into the alternate shift state.
11548 fscanf(stdin, "a%s", str);
11549 with the input line:
11550 a(uparrow) X Y(downarrow) bc
11551 str will contain (uparrow) X Y(downarrow)\0 assuming that none of the bytes of the shift sequences (or of the multibyte
11552 characters, in the more general case) appears to be a single-byte white-space character.
11553 24 In contrast, after the call:
11555 #include <stddef.h>
11558 fscanf(stdin, "a%ls", wstr);
11559 with the same input line, wstr will contain the two wide characters that correspond to X and Y and a
11560 terminating null wide character.
11561 25 However, the call:
11563 #include <stddef.h>
11566 fscanf(stdin, "a(uparrow) X(downarrow)%ls", wstr);
11567 with the same input line will return zero due to a matching failure against the (downarrow) sequence in the format
11569 26 Assuming that the first byte of the multibyte character X is the same as the first byte of the multibyte
11570 character Y, after the call:
11572 #include <stddef.h>
11575 fscanf(stdin, "a(uparrow) Y(downarrow)%ls", wstr);
11576 with the same input line, zero will again be returned, but stdin will be left with a partially consumed
11577 multibyte character.
11579 Forward references: the strtod, strtof, and strtold functions (7.20.1.3), the
11580 strtol, strtoll, strtoul, and strtoull functions (7.20.1.4), conversion state
11581 (7.24.6), the wcrtomb function (7.24.6.3.3).
11588 7.19.6.3 The printf function
11590 1 #include <stdio.h>
11591 int printf(const char * restrict format, ...);
11593 2 The printf function is equivalent to fprintf with the argument stdout interposed
11594 before the arguments to printf.
11596 3 The printf function returns the number of characters transmitted, or a negative value if
11597 an output or encoding error occurred.
11598 7.19.6.4 The scanf function
11600 1 #include <stdio.h>
11601 int scanf(const char * restrict format, ...);
11603 2 The scanf function is equivalent to fscanf with the argument stdin interposed
11604 before the arguments to scanf.
11606 3 The scanf function returns the value of the macro EOF if an input failure occurs before
11607 any conversion. Otherwise, the scanf function returns the number of input items
11608 assigned, which can be fewer than provided for, or even zero, in the event of an early
11610 7.19.6.5 The snprintf function
11612 1 #include <stdio.h>
11613 int snprintf(char * restrict s, size_t n,
11614 const char * restrict format, ...);
11616 2 The snprintf function is equivalent to fprintf, except that the output is written into
11617 an array (specified by argument s) rather than to a stream. If n is zero, nothing is written,
11618 and s may be a null pointer. Otherwise, output characters beyond the n-1st are
11619 discarded rather than being written to the array, and a null character is written at the end
11620 of the characters actually written into the array. If copying takes place between objects
11621 that overlap, the behavior is undefined.
11626 3 The snprintf function returns the number of characters that would have been written
11627 had n been sufficiently large, not counting the terminating null character, or a negative
11628 value if an encoding error occurred. Thus, the null-terminated output has been
11629 completely written if and only if the returned value is nonnegative and less than n.
11630 7.19.6.6 The sprintf function
11632 1 #include <stdio.h>
11633 int sprintf(char * restrict s,
11634 const char * restrict format, ...);
11636 2 The sprintf function is equivalent to fprintf, except that the output is written into
11637 an array (specified by the argument s) rather than to a stream. A null character is written
11638 at the end of the characters written; it is not counted as part of the returned value. If
11639 copying takes place between objects that overlap, the behavior is undefined.
11641 3 The sprintf function returns the number of characters written in the array, not
11642 counting the terminating null character, or a negative value if an encoding error occurred.
11643 7.19.6.7 The sscanf function
11645 1 #include <stdio.h>
11646 int sscanf(const char * restrict s,
11647 const char * restrict format, ...);
11649 2 The sscanf function is equivalent to fscanf, except that input is obtained from a
11650 string (specified by the argument s) rather than from a stream. Reaching the end of the
11651 string is equivalent to encountering end-of-file for the fscanf function. If copying
11652 takes place between objects that overlap, the behavior is undefined.
11654 3 The sscanf function returns the value of the macro EOF if an input failure occurs
11655 before any conversion. Otherwise, the sscanf function returns the number of input
11656 items assigned, which can be fewer than provided for, or even zero, in the event of an
11657 early matching failure.
11664 7.19.6.8 The vfprintf function
11666 1 #include <stdarg.h>
11668 int vfprintf(FILE * restrict stream,
11669 const char * restrict format,
11672 2 The vfprintf function is equivalent to fprintf, with the variable argument list
11673 replaced by arg, which shall have been initialized by the va_start macro (and
11674 possibly subsequent va_arg calls). The vfprintf function does not invoke the
11677 3 The vfprintf function returns the number of characters transmitted, or a negative
11678 value if an output or encoding error occurred.
11679 4 EXAMPLE The following shows the use of the vfprintf function in a general error-reporting routine.
11680 #include <stdarg.h>
11682 void error(char *function_name, char *format, ...)
11685 va_start(args, format);
11686 // print out name of function causing error
11687 fprintf(stderr, "ERROR in %s: ", function_name);
11688 // print out remainder of message
11689 vfprintf(stderr, format, args);
11696 254) As the functions vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf, and
11697 vsscanf invoke the va_arg macro, the value of arg after the return is indeterminate.
11701 7.19.6.9 The vfscanf function
11703 1 #include <stdarg.h>
11705 int vfscanf(FILE * restrict stream,
11706 const char * restrict format,
11709 2 The vfscanf function is equivalent to fscanf, with the variable argument list
11710 replaced by arg, which shall have been initialized by the va_start macro (and
11711 possibly subsequent va_arg calls). The vfscanf function does not invoke the
11714 3 The vfscanf function returns the value of the macro EOF if an input failure occurs
11715 before any conversion. Otherwise, the vfscanf function returns the number of input
11716 items assigned, which can be fewer than provided for, or even zero, in the event of an
11717 early matching failure.
11718 7.19.6.10 The vprintf function
11720 1 #include <stdarg.h>
11722 int vprintf(const char * restrict format,
11725 2 The vprintf function is equivalent to printf, with the variable argument list
11726 replaced by arg, which shall have been initialized by the va_start macro (and
11727 possibly subsequent va_arg calls). The vprintf function does not invoke the
11730 3 The vprintf function returns the number of characters transmitted, or a negative value
11731 if an output or encoding error occurred.
11738 7.19.6.11 The vscanf function
11740 1 #include <stdarg.h>
11742 int vscanf(const char * restrict format,
11745 2 The vscanf function is equivalent to scanf, with the variable argument list replaced
11746 by arg, which shall have been initialized by the va_start macro (and possibly
11747 subsequent va_arg calls). The vscanf function does not invoke the va_end
11750 3 The vscanf function returns the value of the macro EOF if an input failure occurs
11751 before any conversion. Otherwise, the vscanf function returns the number of input
11752 items assigned, which can be fewer than provided for, or even zero, in the event of an
11753 early matching failure.
11754 7.19.6.12 The vsnprintf function
11756 1 #include <stdarg.h>
11758 int vsnprintf(char * restrict s, size_t n,
11759 const char * restrict format,
11762 2 The vsnprintf function is equivalent to snprintf, with the variable argument list
11763 replaced by arg, which shall have been initialized by the va_start macro (and
11764 possibly subsequent va_arg calls). The vsnprintf function does not invoke the
11765 va_end macro.254) If copying takes place between objects that overlap, the behavior is
11768 3 The vsnprintf function returns the number of characters that would have been written
11769 had n been sufficiently large, not counting the terminating null character, or a negative
11770 value if an encoding error occurred. Thus, the null-terminated output has been
11771 completely written if and only if the returned value is nonnegative and less than n.
11778 7.19.6.13 The vsprintf function
11780 1 #include <stdarg.h>
11782 int vsprintf(char * restrict s,
11783 const char * restrict format,
11786 2 The vsprintf function is equivalent to sprintf, with the variable argument list
11787 replaced by arg, which shall have been initialized by the va_start macro (and
11788 possibly subsequent va_arg calls). The vsprintf function does not invoke the
11789 va_end macro.254) If copying takes place between objects that overlap, the behavior is
11792 3 The vsprintf function returns the number of characters written in the array, not
11793 counting the terminating null character, or a negative value if an encoding error occurred.
11794 7.19.6.14 The vsscanf function
11796 1 #include <stdarg.h>
11798 int vsscanf(const char * restrict s,
11799 const char * restrict format,
11802 2 The vsscanf function is equivalent to sscanf, with the variable argument list
11803 replaced by arg, which shall have been initialized by the va_start macro (and
11804 possibly subsequent va_arg calls). The vsscanf function does not invoke the
11807 3 The vsscanf function returns the value of the macro EOF if an input failure occurs
11808 before any conversion. Otherwise, the vsscanf function returns the number of input
11809 items assigned, which can be fewer than provided for, or even zero, in the event of an
11810 early matching failure.
11817 7.19.7 Character input/output functions
11818 7.19.7.1 The fgetc function
11820 1 #include <stdio.h>
11821 int fgetc(FILE *stream);
11823 2 If the end-of-file indicator for the input stream pointed to by stream is not set and a
11824 next character is present, the fgetc function obtains that character as an unsigned
11825 char converted to an int and advances the associated file position indicator for the
11826 stream (if defined).
11828 3 If the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-
11829 of-file indicator for the stream is set and the fgetc function returns EOF. Otherwise, the
11830 fgetc function returns the next character from the input stream pointed to by stream.
11831 If a read error occurs, the error indicator for the stream is set and the fgetc function
11833 7.19.7.2 The fgets function
11835 1 #include <stdio.h>
11836 char *fgets(char * restrict s, int n,
11837 FILE * restrict stream);
11839 2 The fgets function reads at most one less than the number of characters specified by n
11840 from the stream pointed to by stream into the array pointed to by s. No additional
11841 characters are read after a new-line character (which is retained) or after end-of-file. A
11842 null character is written immediately after the last character read into the array.
11844 3 The fgets function returns s if successful. If end-of-file is encountered and no
11845 characters have been read into the array, the contents of the array remain unchanged and a
11846 null pointer is returned. If a read error occurs during the operation, the array contents are
11847 indeterminate and a null pointer is returned.
11852 255) An end-of-file and a read error can be distinguished by use of the feof and ferror functions.
11856 7.19.7.3 The fputc function
11858 1 #include <stdio.h>
11859 int fputc(int c, FILE *stream);
11861 2 The fputc function writes the character specified by c (converted to an unsigned
11862 char) to the output stream pointed to by stream, at the position indicated by the
11863 associated file position indicator for the stream (if defined), and advances the indicator
11864 appropriately. If the file cannot support positioning requests, or if the stream was opened
11865 with append mode, the character is appended to the output stream.
11867 3 The fputc function returns the character written. If a write error occurs, the error
11868 indicator for the stream is set and fputc returns EOF.
11869 7.19.7.4 The fputs function
11871 1 #include <stdio.h>
11872 int fputs(const char * restrict s,
11873 FILE * restrict stream);
11875 2 The fputs function writes the string pointed to by s to the stream pointed to by
11876 stream. The terminating null character is not written.
11878 3 The fputs function returns EOF if a write error occurs; otherwise it returns a
11880 7.19.7.5 The getc function
11882 1 #include <stdio.h>
11883 int getc(FILE *stream);
11885 2 The getc function is equivalent to fgetc, except that if it is implemented as a macro, it
11886 may evaluate stream more than once, so the argument should never be an expression
11895 3 The getc function returns the next character from the input stream pointed to by
11896 stream. If the stream is at end-of-file, the end-of-file indicator for the stream is set and
11897 getc returns EOF. If a read error occurs, the error indicator for the stream is set and
11899 7.19.7.6 The getchar function
11901 1 #include <stdio.h>
11904 2 The getchar function is equivalent to getc with the argument stdin.
11906 3 The getchar function returns the next character from the input stream pointed to by
11907 stdin. If the stream is at end-of-file, the end-of-file indicator for the stream is set and
11908 getchar returns EOF. If a read error occurs, the error indicator for the stream is set and
11909 getchar returns EOF.
11910 7.19.7.7 The gets function
11912 1 #include <stdio.h>
11913 char *gets(char *s);
11915 2 The gets function reads characters from the input stream pointed to by stdin, into the
11916 array pointed to by s, until end-of-file is encountered or a new-line character is read.
11917 Any new-line character is discarded, and a null character is written immediately after the
11918 last character read into the array.
11920 3 The gets function returns s if successful. If end-of-file is encountered and no
11921 characters have been read into the array, the contents of the array remain unchanged and a
11922 null pointer is returned. If a read error occurs during the operation, the array contents are
11923 indeterminate and a null pointer is returned.
11924 Forward references: future library directions (7.26.9).
11931 7.19.7.8 The putc function
11933 1 #include <stdio.h>
11934 int putc(int c, FILE *stream);
11936 2 The putc function is equivalent to fputc, except that if it is implemented as a macro, it
11937 may evaluate stream more than once, so that argument should never be an expression
11940 3 The putc function returns the character written. If a write error occurs, the error
11941 indicator for the stream is set and putc returns EOF.
11942 7.19.7.9 The putchar function
11944 1 #include <stdio.h>
11945 int putchar(int c);
11947 2 The putchar function is equivalent to putc with the second argument stdout.
11949 3 The putchar function returns the character written. If a write error occurs, the error
11950 indicator for the stream is set and putchar returns EOF.
11951 7.19.7.10 The puts function
11953 1 #include <stdio.h>
11954 int puts(const char *s);
11956 2 The puts function writes the string pointed to by s to the stream pointed to by stdout,
11957 and appends a new-line character to the output. The terminating null character is not
11960 3 The puts function returns EOF if a write error occurs; otherwise it returns a nonnegative
11968 7.19.7.11 The ungetc function
11970 1 #include <stdio.h>
11971 int ungetc(int c, FILE *stream);
11973 2 The ungetc function pushes the character specified by c (converted to an unsigned
11974 char) back onto the input stream pointed to by stream. Pushed-back characters will be
11975 returned by subsequent reads on that stream in the reverse order of their pushing. A
11976 successful intervening call (with the stream pointed to by stream) to a file positioning
11977 function (fseek, fsetpos, or rewind) discards any pushed-back characters for the
11978 stream. The external storage corresponding to the stream is unchanged.
11979 3 One character of pushback is guaranteed. If the ungetc function is called too many
11980 times on the same stream without an intervening read or file positioning operation on that
11981 stream, the operation may fail.
11982 4 If the value of c equals that of the macro EOF, the operation fails and the input stream is
11984 5 A successful call to the ungetc function clears the end-of-file indicator for the stream.
11985 The value of the file position indicator for the stream after reading or discarding all
11986 pushed-back characters shall be the same as it was before the characters were pushed
11987 back. For a text stream, the value of its file position indicator after a successful call to the
11988 ungetc function is unspecified until all pushed-back characters are read or discarded.
11989 For a binary stream, its file position indicator is decremented by each successful call to
11990 the ungetc function; if its value was zero before a call, it is indeterminate after the
11993 6 The ungetc function returns the character pushed back after conversion, or EOF if the
11995 Forward references: file positioning functions (7.19.9).
12000 256) See ''future library directions'' (7.26.9).
12004 7.19.8 Direct input/output functions
12005 7.19.8.1 The fread function
12007 1 #include <stdio.h>
12008 size_t fread(void * restrict ptr,
12009 size_t size, size_t nmemb,
12010 FILE * restrict stream);
12012 2 The fread function reads, into the array pointed to by ptr, up to nmemb elements
12013 whose size is specified by size, from the stream pointed to by stream. For each
12014 object, size calls are made to the fgetc function and the results stored, in the order
12015 read, in an array of unsigned char exactly overlaying the object. The file position
12016 indicator for the stream (if defined) is advanced by the number of characters successfully
12017 read. If an error occurs, the resulting value of the file position indicator for the stream is
12018 indeterminate. If a partial element is read, its value is indeterminate.
12020 3 The fread function returns the number of elements successfully read, which may be
12021 less than nmemb if a read error or end-of-file is encountered. If size or nmemb is zero,
12022 fread returns zero and the contents of the array and the state of the stream remain
12024 7.19.8.2 The fwrite function
12026 1 #include <stdio.h>
12027 size_t fwrite(const void * restrict ptr,
12028 size_t size, size_t nmemb,
12029 FILE * restrict stream);
12031 2 The fwrite function writes, from the array pointed to by ptr, up to nmemb elements
12032 whose size is specified by size, to the stream pointed to by stream. For each object,
12033 size calls are made to the fputc function, taking the values (in order) from an array of
12034 unsigned char exactly overlaying the object. The file position indicator for the
12035 stream (if defined) is advanced by the number of characters successfully written. If an
12036 error occurs, the resulting value of the file position indicator for the stream is
12045 3 The fwrite function returns the number of elements successfully written, which will be
12046 less than nmemb only if a write error is encountered. If size or nmemb is zero,
12047 fwrite returns zero and the state of the stream remains unchanged.
12048 7.19.9 File positioning functions
12049 7.19.9.1 The fgetpos function
12051 1 #include <stdio.h>
12052 int fgetpos(FILE * restrict stream,
12053 fpos_t * restrict pos);
12055 2 The fgetpos function stores the current values of the parse state (if any) and file
12056 position indicator for the stream pointed to by stream in the object pointed to by pos.
12057 The values stored contain unspecified information usable by the fsetpos function for
12058 repositioning the stream to its position at the time of the call to the fgetpos function.
12060 3 If successful, the fgetpos function returns zero; on failure, the fgetpos function
12061 returns nonzero and stores an implementation-defined positive value in errno.
12062 Forward references: the fsetpos function (7.19.9.3).
12063 7.19.9.2 The fseek function
12065 1 #include <stdio.h>
12066 int fseek(FILE *stream, long int offset, int whence);
12068 2 The fseek function sets the file position indicator for the stream pointed to by stream.
12069 If a read or write error occurs, the error indicator for the stream is set and fseek fails.
12070 3 For a binary stream, the new position, measured in characters from the beginning of the
12071 file, is obtained by adding offset to the position specified by whence. The specified
12072 position is the beginning of the file if whence is SEEK_SET, the current value of the file
12073 position indicator if SEEK_CUR, or end-of-file if SEEK_END. A binary stream need not
12074 meaningfully support fseek calls with a whence value of SEEK_END.
12075 4 For a text stream, either offset shall be zero, or offset shall be a value returned by
12076 an earlier successful call to the ftell function on a stream associated with the same file
12077 and whence shall be SEEK_SET.
12081 5 After determining the new position, a successful call to the fseek function undoes any
12082 effects of the ungetc function on the stream, clears the end-of-file indicator for the
12083 stream, and then establishes the new position. After a successful fseek call, the next
12084 operation on an update stream may be either input or output.
12086 6 The fseek function returns nonzero only for a request that cannot be satisfied.
12087 Forward references: the ftell function (7.19.9.4).
12088 7.19.9.3 The fsetpos function
12090 1 #include <stdio.h>
12091 int fsetpos(FILE *stream, const fpos_t *pos);
12093 2 The fsetpos function sets the mbstate_t object (if any) and file position indicator
12094 for the stream pointed to by stream according to the value of the object pointed to by
12095 pos, which shall be a value obtained from an earlier successful call to the fgetpos
12096 function on a stream associated with the same file. If a read or write error occurs, the
12097 error indicator for the stream is set and fsetpos fails.
12098 3 A successful call to the fsetpos function undoes any effects of the ungetc function
12099 on the stream, clears the end-of-file indicator for the stream, and then establishes the new
12100 parse state and position. After a successful fsetpos call, the next operation on an
12101 update stream may be either input or output.
12103 4 If successful, the fsetpos function returns zero; on failure, the fsetpos function
12104 returns nonzero and stores an implementation-defined positive value in errno.
12105 7.19.9.4 The ftell function
12107 1 #include <stdio.h>
12108 long int ftell(FILE *stream);
12110 2 The ftell function obtains the current value of the file position indicator for the stream
12111 pointed to by stream. For a binary stream, the value is the number of characters from
12112 the beginning of the file. For a text stream, its file position indicator contains unspecified
12113 information, usable by the fseek function for returning the file position indicator for the
12114 stream to its position at the time of the ftell call; the difference between two such
12115 return values is not necessarily a meaningful measure of the number of characters written
12121 3 If successful, the ftell function returns the current value of the file position indicator
12122 for the stream. On failure, the ftell function returns -1L and stores an
12123 implementation-defined positive value in errno.
12124 7.19.9.5 The rewind function
12126 1 #include <stdio.h>
12127 void rewind(FILE *stream);
12129 2 The rewind function sets the file position indicator for the stream pointed to by
12130 stream to the beginning of the file. It is equivalent to
12131 (void)fseek(stream, 0L, SEEK_SET)
12132 except that the error indicator for the stream is also cleared.
12134 3 The rewind function returns no value.
12135 7.19.10 Error-handling functions
12136 7.19.10.1 The clearerr function
12138 1 #include <stdio.h>
12139 void clearerr(FILE *stream);
12141 2 The clearerr function clears the end-of-file and error indicators for the stream pointed
12144 3 The clearerr function returns no value.
12151 7.19.10.2 The feof function
12153 1 #include <stdio.h>
12154 int feof(FILE *stream);
12156 2 The feof function tests the end-of-file indicator for the stream pointed to by stream.
12158 3 The feof function returns nonzero if and only if the end-of-file indicator is set for
12160 7.19.10.3 The ferror function
12162 1 #include <stdio.h>
12163 int ferror(FILE *stream);
12165 2 The ferror function tests the error indicator for the stream pointed to by stream.
12167 3 The ferror function returns nonzero if and only if the error indicator is set for
12169 7.19.10.4 The perror function
12171 1 #include <stdio.h>
12172 void perror(const char *s);
12174 2 The perror function maps the error number in the integer expression errno to an
12175 error message. It writes a sequence of characters to the standard error stream thus: first
12176 (if s is not a null pointer and the character pointed to by s is not the null character), the
12177 string pointed to by s followed by a colon (:) and a space; then an appropriate error
12178 message string followed by a new-line character. The contents of the error message
12179 strings are the same as those returned by the strerror function with argument errno.
12181 3 The perror function returns no value.
12182 Forward references: the strerror function (7.21.6.2).
12187 7.20 General utilities <stdlib.h>
12188 1 The header <stdlib.h> declares five types and several functions of general utility, and
12189 defines several macros.257)
12190 2 The types declared are size_t and wchar_t (both described in 7.17),
12192 which is a structure type that is the type of the value returned by the div function,
12194 which is a structure type that is the type of the value returned by the ldiv function, and
12196 which is a structure type that is the type of the value returned by the lldiv function.
12197 3 The macros defined are NULL (described in 7.17);
12201 which expand to integer constant expressions that can be used as the argument to the
12202 exit function to return unsuccessful or successful termination status, respectively, to the
12205 which expands to an integer constant expression that is the maximum value returned by
12206 the rand function; and
12208 which expands to a positive integer expression with type size_t that is the maximum
12209 number of bytes in a multibyte character for the extended character set specified by the
12210 current locale (category LC_CTYPE), which is never greater than MB_LEN_MAX.
12215 257) See ''future library directions'' (7.26.10).
12219 7.20.1 Numeric conversion functions
12220 1 The functions atof, atoi, atol, and atoll need not affect the value of the integer
12221 expression errno on an error. If the value of the result cannot be represented, the
12222 behavior is undefined.
12223 7.20.1.1 The atof function
12225 1 #include <stdlib.h>
12226 double atof(const char *nptr);
12228 2 The atof function converts the initial portion of the string pointed to by nptr to
12229 double representation. Except for the behavior on error, it is equivalent to
12230 strtod(nptr, (char **)NULL)
12232 3 The atof function returns the converted value.
12233 Forward references: the strtod, strtof, and strtold functions (7.20.1.3).
12234 7.20.1.2 The atoi, atol, and atoll functions
12236 1 #include <stdlib.h>
12237 int atoi(const char *nptr);
12238 long int atol(const char *nptr);
12239 long long int atoll(const char *nptr);
12241 2 The atoi, atol, and atoll functions convert the initial portion of the string pointed
12242 to by nptr to int, long int, and long long int representation, respectively.
12243 Except for the behavior on error, they are equivalent to
12244 atoi: (int)strtol(nptr, (char **)NULL, 10)
12245 atol: strtol(nptr, (char **)NULL, 10)
12246 atoll: strtoll(nptr, (char **)NULL, 10)
12248 3 The atoi, atol, and atoll functions return the converted value.
12249 Forward references: the strtol, strtoll, strtoul, and strtoull functions
12256 7.20.1.3 The strtod, strtof, and strtold functions
12258 1 #include <stdlib.h>
12259 double strtod(const char * restrict nptr,
12260 char ** restrict endptr);
12261 float strtof(const char * restrict nptr,
12262 char ** restrict endptr);
12263 long double strtold(const char * restrict nptr,
12264 char ** restrict endptr);
12266 2 The strtod, strtof, and strtold functions convert the initial portion of the string
12267 pointed to by nptr to double, float, and long double representation,
12268 respectively. First, they decompose the input string into three parts: an initial, possibly
12269 empty, sequence of white-space characters (as specified by the isspace function), a
12270 subject sequence resembling a floating-point constant or representing an infinity or NaN;
12271 and a final string of one or more unrecognized characters, including the terminating null
12272 character of the input string. Then, they attempt to convert the subject sequence to a
12273 floating-point number, and return the result.
12274 3 The expected form of the subject sequence is an optional plus or minus sign, then one of
12276 -- a nonempty sequence of decimal digits optionally containing a decimal-point
12277 character, then an optional exponent part as defined in 6.4.4.2;
12278 -- a 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing a
12279 decimal-point character, then an optional binary exponent part as defined in 6.4.4.2;
12280 -- INF or INFINITY, ignoring case
12281 -- NAN or NAN(n-char-sequenceopt), ignoring case in the NAN part, where:
12285 n-char-sequence digit
12286 n-char-sequence nondigit
12287 The subject sequence is defined as the longest initial subsequence of the input string,
12288 starting with the first non-white-space character, that is of the expected form. The subject
12289 sequence contains no characters if the input string is not of the expected form.
12290 4 If the subject sequence has the expected form for a floating-point number, the sequence of
12291 characters starting with the first digit or the decimal-point character (whichever occurs
12292 first) is interpreted as a floating constant according to the rules of 6.4.4.2, except that the
12295 decimal-point character is used in place of a period, and that if neither an exponent part
12296 nor a decimal-point character appears in a decimal floating point number, or if a binary
12297 exponent part does not appear in a hexadecimal floating point number, an exponent part
12298 of the appropriate type with value zero is assumed to follow the last digit in the string. If
12299 the subject sequence begins with a minus sign, the sequence is interpreted as negated.258)
12300 A character sequence INF or INFINITY is interpreted as an infinity, if representable in
12301 the return type, else like a floating constant that is too large for the range of the return
12302 type. A character sequence NAN or NAN(n-char-sequenceopt), is interpreted as a quiet
12303 NaN, if supported in the return type, else like a subject sequence part that does not have
12304 the expected form; the meaning of the n-char sequences is implementation-defined.259) A
12305 pointer to the final string is stored in the object pointed to by endptr, provided that
12306 endptr is not a null pointer.
12307 5 If the subject sequence has the hexadecimal form and FLT_RADIX is a power of 2, the
12308 value resulting from the conversion is correctly rounded.
12309 6 In other than the "C" locale, additional locale-specific subject sequence forms may be
12311 7 If the subject sequence is empty or does not have the expected form, no conversion is
12312 performed; the value of nptr is stored in the object pointed to by endptr, provided
12313 that endptr is not a null pointer.
12314 Recommended practice
12315 8 If the subject sequence has the hexadecimal form, FLT_RADIX is not a power of 2, and
12316 the result is not exactly representable, the result should be one of the two numbers in the
12317 appropriate internal format that are adjacent to the hexadecimal floating source value,
12318 with the extra stipulation that the error should have a correct sign for the current rounding
12320 9 If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in
12321 <float.h>) significant digits, the result should be correctly rounded. If the subject
12322 sequence D has the decimal form and more than DECIMAL_DIG significant digits,
12323 consider the two bounding, adjacent decimal strings L and U, both having
12324 DECIMAL_DIG significant digits, such that the values of L, D, and U satisfy L <= D <= U.
12325 The result should be one of the (equal or adjacent) values that would be obtained by
12326 correctly rounding L and U according to the current rounding direction, with the extra
12328 258) It is unspecified whether a minus-signed sequence is converted to a negative number directly or by
12329 negating the value resulting from converting the corresponding unsigned sequence (see F.5); the two
12330 methods may yield different results if rounding is toward positive or negative infinity. In either case,
12331 the functions honor the sign of zero if floating-point arithmetic supports signed zeros.
12332 259) An implementation may use the n-char sequence to determine extra information to be represented in
12333 the NaN's significand.
12337 stipulation that the error with respect to D should have a correct sign for the current
12338 rounding direction.260)
12340 10 The functions return the converted value, if any. If no conversion could be performed,
12341 zero is returned. If the correct value is outside the range of representable values, plus or
12342 minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the return
12343 type and sign of the value), and the value of the macro ERANGE is stored in errno. If
12344 the result underflows (7.12.1), the functions return a value whose magnitude is no greater
12345 than the smallest normalized positive number in the return type; whether errno acquires
12346 the value ERANGE is implementation-defined.
12347 7.20.1.4 The strtol, strtoll, strtoul, and strtoull functions
12349 1 #include <stdlib.h>
12351 const char * restrict nptr,
12352 char ** restrict endptr,
12354 long long int strtoll(
12355 const char * restrict nptr,
12356 char ** restrict endptr,
12358 unsigned long int strtoul(
12359 const char * restrict nptr,
12360 char ** restrict endptr,
12362 unsigned long long int strtoull(
12363 const char * restrict nptr,
12364 char ** restrict endptr,
12367 2 The strtol, strtoll, strtoul, and strtoull functions convert the initial
12368 portion of the string pointed to by nptr to long int, long long int, unsigned
12369 long int, and unsigned long long int representation, respectively. First,
12370 they decompose the input string into three parts: an initial, possibly empty, sequence of
12371 white-space characters (as specified by the isspace function), a subject sequence
12374 260) DECIMAL_DIG, defined in <float.h>, should be sufficiently large that L and U will usually round
12375 to the same internal floating value, but if not will round to adjacent values.
12379 resembling an integer represented in some radix determined by the value of base, and a
12380 final string of one or more unrecognized characters, including the terminating null
12381 character of the input string. Then, they attempt to convert the subject sequence to an
12382 integer, and return the result.
12383 3 If the value of base is zero, the expected form of the subject sequence is that of an
12384 integer constant as described in 6.4.4.1, optionally preceded by a plus or minus sign, but
12385 not including an integer suffix. If the value of base is between 2 and 36 (inclusive), the
12386 expected form of the subject sequence is a sequence of letters and digits representing an
12387 integer with the radix specified by base, optionally preceded by a plus or minus sign,
12388 but not including an integer suffix. The letters from a (or A) through z (or Z) are
12389 ascribed the values 10 through 35; only letters and digits whose ascribed values are less
12390 than that of base are permitted. If the value of base is 16, the characters 0x or 0X may
12391 optionally precede the sequence of letters and digits, following the sign if present.
12392 4 The subject sequence is defined as the longest initial subsequence of the input string,
12393 starting with the first non-white-space character, that is of the expected form. The subject
12394 sequence contains no characters if the input string is empty or consists entirely of white
12395 space, or if the first non-white-space character is other than a sign or a permissible letter
12397 5 If the subject sequence has the expected form and the value of base is zero, the sequence
12398 of characters starting with the first digit is interpreted as an integer constant according to
12399 the rules of 6.4.4.1. If the subject sequence has the expected form and the value of base
12400 is between 2 and 36, it is used as the base for conversion, ascribing to each letter its value
12401 as given above. If the subject sequence begins with a minus sign, the value resulting from
12402 the conversion is negated (in the return type). A pointer to the final string is stored in the
12403 object pointed to by endptr, provided that endptr is not a null pointer.
12404 6 In other than the "C" locale, additional locale-specific subject sequence forms may be
12406 7 If the subject sequence is empty or does not have the expected form, no conversion is
12407 performed; the value of nptr is stored in the object pointed to by endptr, provided
12408 that endptr is not a null pointer.
12410 8 The strtol, strtoll, strtoul, and strtoull functions return the converted
12411 value, if any. If no conversion could be performed, zero is returned. If the correct value
12412 is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
12413 LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type
12414 and sign of the value, if any), and the value of the macro ERANGE is stored in errno.
12421 7.20.2 Pseudo-random sequence generation functions
12422 7.20.2.1 The rand function
12424 1 #include <stdlib.h>
12427 2 The rand function computes a sequence of pseudo-random integers in the range 0 to
12429 3 The implementation shall behave as if no library function calls the rand function.
12431 4 The rand function returns a pseudo-random integer.
12432 Environmental limits
12433 5 The value of the RAND_MAX macro shall be at least 32767.
12434 7.20.2.2 The srand function
12436 1 #include <stdlib.h>
12437 void srand(unsigned int seed);
12439 2 The srand function uses the argument as a seed for a new sequence of pseudo-random
12440 numbers to be returned by subsequent calls to rand. If srand is then called with the
12441 same seed value, the sequence of pseudo-random numbers shall be repeated. If rand is
12442 called before any calls to srand have been made, the same sequence shall be generated
12443 as when srand is first called with a seed value of 1.
12444 3 The implementation shall behave as if no library function calls the srand function.
12446 4 The srand function returns no value.
12447 5 EXAMPLE The following functions define a portable implementation of rand and srand.
12448 static unsigned long int next = 1;
12449 int rand(void) // RAND_MAX assumed to be 32767
12451 next = next * 1103515245 + 12345;
12452 return (unsigned int)(next/65536) % 32768;
12459 void srand(unsigned int seed)
12464 7.20.3 Memory management functions
12465 1 The order and contiguity of storage allocated by successive calls to the calloc,
12466 malloc, and realloc functions is unspecified. The pointer returned if the allocation
12467 succeeds is suitably aligned so that it may be assigned to a pointer to any type of object
12468 and then used to access such an object or an array of such objects in the space allocated
12469 (until the space is explicitly deallocated). The lifetime of an allocated object extends
12470 from the allocation until the deallocation. Each such allocation shall yield a pointer to an
12471 object disjoint from any other object. The pointer returned points to the start (lowest byte
12472 address) of the allocated space. If the space cannot be allocated, a null pointer is
12473 returned. If the size of the space requested is zero, the behavior is implementation-
12474 defined: either a null pointer is returned, or the behavior is as if the size were some
12475 nonzero value, except that the returned pointer shall not be used to access an object.
12476 7.20.3.1 The calloc function
12478 1 #include <stdlib.h>
12479 void *calloc(size_t nmemb, size_t size);
12481 2 The calloc function allocates space for an array of nmemb objects, each of whose size
12482 is size. The space is initialized to all bits zero.261)
12484 3 The calloc function returns either a null pointer or a pointer to the allocated space.
12485 7.20.3.2 The free function
12487 1 #include <stdlib.h>
12488 void free(void *ptr);
12490 2 The free function causes the space pointed to by ptr to be deallocated, that is, made
12491 available for further allocation. If ptr is a null pointer, no action occurs. Otherwise, if
12492 the argument does not match a pointer earlier returned by the calloc, malloc, or
12495 261) Note that this need not be the same as the representation of floating-point zero or a null pointer
12500 realloc function, or if the space has been deallocated by a call to free or realloc,
12501 the behavior is undefined.
12503 3 The free function returns no value.
12504 7.20.3.3 The malloc function
12506 1 #include <stdlib.h>
12507 void *malloc(size_t size);
12509 2 The malloc function allocates space for an object whose size is specified by size and
12510 whose value is indeterminate.
12512 3 The malloc function returns either a null pointer or a pointer to the allocated space.
12513 7.20.3.4 The realloc function
12515 1 #include <stdlib.h>
12516 void *realloc(void *ptr, size_t size);
12518 2 The realloc function deallocates the old object pointed to by ptr and returns a
12519 pointer to a new object that has the size specified by size. The contents of the new
12520 object shall be the same as that of the old object prior to deallocation, up to the lesser of
12521 the new and old sizes. Any bytes in the new object beyond the size of the old object have
12522 indeterminate values.
12523 3 If ptr is a null pointer, the realloc function behaves like the malloc function for the
12524 specified size. Otherwise, if ptr does not match a pointer earlier returned by the
12525 calloc, malloc, or realloc function, or if the space has been deallocated by a call
12526 to the free or realloc function, the behavior is undefined. If memory for the new
12527 object cannot be allocated, the old object is not deallocated and its value is unchanged.
12529 4 The realloc function returns a pointer to the new object (which may have the same
12530 value as a pointer to the old object), or a null pointer if the new object could not be
12538 7.20.4 Communication with the environment
12539 7.20.4.1 The abort function
12541 1 #include <stdlib.h>
12544 2 The abort function causes abnormal program termination to occur, unless the signal
12545 SIGABRT is being caught and the signal handler does not return. Whether open streams
12546 with unwritten buffered data are flushed, open streams are closed, or temporary files are
12547 removed is implementation-defined. An implementation-defined form of the status
12548 unsuccessful termination is returned to the host environment by means of the function
12549 call raise(SIGABRT).
12551 3 The abort function does not return to its caller.
12552 7.20.4.2 The atexit function
12554 1 #include <stdlib.h>
12555 int atexit(void (*func)(void));
12557 2 The atexit function registers the function pointed to by func, to be called without
12558 arguments at normal program termination.
12559 Environmental limits
12560 3 The implementation shall support the registration of at least 32 functions.
12562 4 The atexit function returns zero if the registration succeeds, nonzero if it fails.
12563 Forward references: the exit function (7.20.4.3).
12564 7.20.4.3 The exit function
12566 1 #include <stdlib.h>
12567 void exit(int status);
12569 2 The exit function causes normal program termination to occur. If more than one call to
12570 the exit function is executed by a program, the behavior is undefined.
12573 3 First, all functions registered by the atexit function are called, in the reverse order of
12574 their registration,262) except that a function is called after any previously registered
12575 functions that had already been called at the time it was registered. If, during the call to
12576 any such function, a call to the longjmp function is made that would terminate the call
12577 to the registered function, the behavior is undefined.
12578 4 Next, all open streams with unwritten buffered data are flushed, all open streams are
12579 closed, and all files created by the tmpfile function are removed.
12580 5 Finally, control is returned to the host environment. If the value of status is zero or
12581 EXIT_SUCCESS, an implementation-defined form of the status successful termination is
12582 returned. If the value of status is EXIT_FAILURE, an implementation-defined form
12583 of the status unsuccessful termination is returned. Otherwise the status returned is
12584 implementation-defined.
12586 6 The exit function cannot return to its caller.
12587 7.20.4.4 The _Exit function
12589 1 #include <stdlib.h>
12590 void _Exit(int status);
12592 2 The _Exit function causes normal program termination to occur and control to be
12593 returned to the host environment. No functions registered by the atexit function or
12594 signal handlers registered by the signal function are called. The status returned to the
12595 host environment is determined in the same way as for the exit function (7.20.4.3).
12596 Whether open streams with unwritten buffered data are flushed, open streams are closed,
12597 or temporary files are removed is implementation-defined.
12599 3 The _Exit function cannot return to its caller.
12604 262) Each function is called as many times as it was registered, and in the correct order with respect to
12605 other registered functions.
12609 7.20.4.5 The getenv function
12611 1 #include <stdlib.h>
12612 char *getenv(const char *name);
12614 2 The getenv function searches an environment list, provided by the host environment,
12615 for a string that matches the string pointed to by name. The set of environment names
12616 and the method for altering the environment list are implementation-defined.
12617 3 The implementation shall behave as if no library function calls the getenv function.
12619 4 The getenv function returns a pointer to a string associated with the matched list
12620 member. The string pointed to shall not be modified by the program, but may be
12621 overwritten by a subsequent call to the getenv function. If the specified name cannot
12622 be found, a null pointer is returned.
12623 7.20.4.6 The system function
12625 1 #include <stdlib.h>
12626 int system(const char *string);
12628 2 If string is a null pointer, the system function determines whether the host
12629 environment has a command processor. If string is not a null pointer, the system
12630 function passes the string pointed to by string to that command processor to be
12631 executed in a manner which the implementation shall document; this might then cause the
12632 program calling system to behave in a non-conforming manner or to terminate.
12634 3 If the argument is a null pointer, the system function returns nonzero only if a
12635 command processor is available. If the argument is not a null pointer, and the system
12636 function does return, it returns an implementation-defined value.
12643 7.20.5 Searching and sorting utilities
12644 1 These utilities make use of a comparison function to search or sort arrays of unspecified
12645 type. Where an argument declared as size_t nmemb specifies the length of the array
12646 for a function, nmemb can have the value zero on a call to that function; the comparison
12647 function is not called, a search finds no matching element, and sorting performs no
12648 rearrangement. Pointer arguments on such a call shall still have valid values, as described
12650 2 The implementation shall ensure that the second argument of the comparison function
12651 (when called from bsearch), or both arguments (when called from qsort), are
12652 pointers to elements of the array.263) The first argument when called from bsearch
12654 3 The comparison function shall not alter the contents of the array. The implementation
12655 may reorder elements of the array between calls to the comparison function, but shall not
12656 alter the contents of any individual element.
12657 4 When the same objects (consisting of size bytes, irrespective of their current positions
12658 in the array) are passed more than once to the comparison function, the results shall be
12659 consistent with one another. That is, for qsort they shall define a total ordering on the
12660 array, and for bsearch the same object shall always compare the same way with the
12662 5 A sequence point occurs immediately before and immediately after each call to the
12663 comparison function, and also between any call to the comparison function and any
12664 movement of the objects passed as arguments to that call.
12665 7.20.5.1 The bsearch function
12667 1 #include <stdlib.h>
12668 void *bsearch(const void *key, const void *base,
12669 size_t nmemb, size_t size,
12670 int (*compar)(const void *, const void *));
12672 2 The bsearch function searches an array of nmemb objects, the initial element of which
12673 is pointed to by base, for an element that matches the object pointed to by key. The
12676 263) That is, if the value passed is p, then the following expressions are always nonzero:
12677 ((char *)p - (char *)base) % size == 0
12678 (char *)p >= (char *)base
12679 (char *)p < (char *)base + nmemb * size
12684 size of each element of the array is specified by size.
12685 3 The comparison function pointed to by compar is called with two arguments that point
12686 to the key object and to an array element, in that order. The function shall return an
12687 integer less than, equal to, or greater than zero if the key object is considered,
12688 respectively, to be less than, to match, or to be greater than the array element. The array
12689 shall consist of: all the elements that compare less than, all the elements that compare
12690 equal to, and all the elements that compare greater than the key object, in that order.264)
12692 4 The bsearch function returns a pointer to a matching element of the array, or a null
12693 pointer if no match is found. If two elements compare as equal, which element is
12694 matched is unspecified.
12695 7.20.5.2 The qsort function
12697 1 #include <stdlib.h>
12698 void qsort(void *base, size_t nmemb, size_t size,
12699 int (*compar)(const void *, const void *));
12701 2 The qsort function sorts an array of nmemb objects, the initial element of which is
12702 pointed to by base. The size of each object is specified by size.
12703 3 The contents of the array are sorted into ascending order according to a comparison
12704 function pointed to by compar, which is called with two arguments that point to the
12705 objects being compared. The function shall return an integer less than, equal to, or
12706 greater than zero if the first argument is considered to be respectively less than, equal to,
12707 or greater than the second.
12708 4 If two elements compare as equal, their order in the resulting sorted array is unspecified.
12710 5 The qsort function returns no value.
12715 264) In practice, the entire array is sorted according to the comparison function.
12719 7.20.6 Integer arithmetic functions
12720 7.20.6.1 The abs, labs and llabs functions
12722 1 #include <stdlib.h>
12724 long int labs(long int j);
12725 long long int llabs(long long int j);
12727 2 The abs, labs, and llabs functions compute the absolute value of an integer j. If the
12728 result cannot be represented, the behavior is undefined.265)
12730 3 The abs, labs, and llabs, functions return the absolute value.
12731 7.20.6.2 The div, ldiv, and lldiv functions
12733 1 #include <stdlib.h>
12734 div_t div(int numer, int denom);
12735 ldiv_t ldiv(long int numer, long int denom);
12736 lldiv_t lldiv(long long int numer, long long int denom);
12738 2 The div, ldiv, and lldiv, functions compute numer / denom and numer %
12739 denom in a single operation.
12741 3 The div, ldiv, and lldiv functions return a structure of type div_t, ldiv_t, and
12742 lldiv_t, respectively, comprising both the quotient and the remainder. The structures
12743 shall contain (in either order) the members quot (the quotient) and rem (the remainder),
12744 each of which has the same type as the arguments numer and denom. If either part of
12745 the result cannot be represented, the behavior is undefined.
12750 265) The absolute value of the most negative number cannot be represented in two's complement.
12754 7.20.7 Multibyte/wide character conversion functions
12755 1 The behavior of the multibyte character functions is affected by the LC_CTYPE category
12756 of the current locale. For a state-dependent encoding, each function is placed into its
12757 initial conversion state by a call for which its character pointer argument, s, is a null
12758 pointer. Subsequent calls with s as other than a null pointer cause the internal conversion
12759 state of the function to be altered as necessary. A call with s as a null pointer causes
12760 these functions to return a nonzero value if encodings have state dependency, and zero
12761 otherwise.266) Changing the LC_CTYPE category causes the conversion state of these
12762 functions to be indeterminate.
12763 7.20.7.1 The mblen function
12765 1 #include <stdlib.h>
12766 int mblen(const char *s, size_t n);
12768 2 If s is not a null pointer, the mblen function determines the number of bytes contained
12769 in the multibyte character pointed to by s. Except that the conversion state of the
12770 mbtowc function is not affected, it is equivalent to
12771 mbtowc((wchar_t *)0, s, n);
12772 3 The implementation shall behave as if no library function calls the mblen function.
12774 4 If s is a null pointer, the mblen function returns a nonzero or zero value, if multibyte
12775 character encodings, respectively, do or do not have state-dependent encodings. If s is
12776 not a null pointer, the mblen function either returns 0 (if s points to the null character),
12777 or returns the number of bytes that are contained in the multibyte character (if the next n
12778 or fewer bytes form a valid multibyte character), or returns -1 (if they do not form a valid
12779 multibyte character).
12780 Forward references: the mbtowc function (7.20.7.2).
12785 266) If the locale employs special bytes to change the shift state, these bytes do not produce separate wide
12786 character codes, but are grouped with an adjacent multibyte character.
12790 7.20.7.2 The mbtowc function
12792 1 #include <stdlib.h>
12793 int mbtowc(wchar_t * restrict pwc,
12794 const char * restrict s,
12797 2 If s is not a null pointer, the mbtowc function inspects at most n bytes beginning with
12798 the byte pointed to by s to determine the number of bytes needed to complete the next
12799 multibyte character (including any shift sequences). If the function determines that the
12800 next multibyte character is complete and valid, it determines the value of the
12801 corresponding wide character and then, if pwc is not a null pointer, stores that value in
12802 the object pointed to by pwc. If the corresponding wide character is the null wide
12803 character, the function is left in the initial conversion state.
12804 3 The implementation shall behave as if no library function calls the mbtowc function.
12806 4 If s is a null pointer, the mbtowc function returns a nonzero or zero value, if multibyte
12807 character encodings, respectively, do or do not have state-dependent encodings. If s is
12808 not a null pointer, the mbtowc function either returns 0 (if s points to the null character),
12809 or returns the number of bytes that are contained in the converted multibyte character (if
12810 the next n or fewer bytes form a valid multibyte character), or returns -1 (if they do not
12811 form a valid multibyte character).
12812 5 In no case will the value returned be greater than n or the value of the MB_CUR_MAX
12814 7.20.7.3 The wctomb function
12816 1 #include <stdlib.h>
12817 int wctomb(char *s, wchar_t wc);
12819 2 The wctomb function determines the number of bytes needed to represent the multibyte
12820 character corresponding to the wide character given by wc (including any shift
12821 sequences), and stores the multibyte character representation in the array whose first
12822 element is pointed to by s (if s is not a null pointer). At most MB_CUR_MAX characters
12823 are stored. If wc is a null wide character, a null byte is stored, preceded by any shift
12824 sequence needed to restore the initial shift state, and the function is left in the initial
12829 3 The implementation shall behave as if no library function calls the wctomb function.
12831 4 If s is a null pointer, the wctomb function returns a nonzero or zero value, if multibyte
12832 character encodings, respectively, do or do not have state-dependent encodings. If s is
12833 not a null pointer, the wctomb function returns -1 if the value of wc does not correspond
12834 to a valid multibyte character, or returns the number of bytes that are contained in the
12835 multibyte character corresponding to the value of wc.
12836 5 In no case will the value returned be greater than the value of the MB_CUR_MAX macro.
12837 7.20.8 Multibyte/wide string conversion functions
12838 1 The behavior of the multibyte string functions is affected by the LC_CTYPE category of
12839 the current locale.
12840 7.20.8.1 The mbstowcs function
12842 1 #include <stdlib.h>
12843 size_t mbstowcs(wchar_t * restrict pwcs,
12844 const char * restrict s,
12847 2 The mbstowcs function converts a sequence of multibyte characters that begins in the
12848 initial shift state from the array pointed to by s into a sequence of corresponding wide
12849 characters and stores not more than n wide characters into the array pointed to by pwcs.
12850 No multibyte characters that follow a null character (which is converted into a null wide
12851 character) will be examined or converted. Each multibyte character is converted as if by
12852 a call to the mbtowc function, except that the conversion state of the mbtowc function is
12854 3 No more than n elements will be modified in the array pointed to by pwcs. If copying
12855 takes place between objects that overlap, the behavior is undefined.
12857 4 If an invalid multibyte character is encountered, the mbstowcs function returns
12858 (size_t)(-1). Otherwise, the mbstowcs function returns the number of array
12859 elements modified, not including a terminating null wide character, if any.267)
12864 267) The array will not be null-terminated if the value returned is n.
12868 7.20.8.2 The wcstombs function
12870 1 #include <stdlib.h>
12871 size_t wcstombs(char * restrict s,
12872 const wchar_t * restrict pwcs,
12875 2 The wcstombs function converts a sequence of wide characters from the array pointed
12876 to by pwcs into a sequence of corresponding multibyte characters that begins in the
12877 initial shift state, and stores these multibyte characters into the array pointed to by s,
12878 stopping if a multibyte character would exceed the limit of n total bytes or if a null
12879 character is stored. Each wide character is converted as if by a call to the wctomb
12880 function, except that the conversion state of the wctomb function is not affected.
12881 3 No more than n bytes will be modified in the array pointed to by s. If copying takes place
12882 between objects that overlap, the behavior is undefined.
12884 4 If a wide character is encountered that does not correspond to a valid multibyte character,
12885 the wcstombs function returns (size_t)(-1). Otherwise, the wcstombs function
12886 returns the number of bytes modified, not including a terminating null character, if
12894 7.21 String handling <string.h>
12895 7.21.1 String function conventions
12896 1 The header <string.h> declares one type and several functions, and defines one
12897 macro useful for manipulating arrays of character type and other objects treated as arrays
12898 of character type.268) The type is size_t and the macro is NULL (both described in
12899 7.17). Various methods are used for determining the lengths of the arrays, but in all cases
12900 a char * or void * argument points to the initial (lowest addressed) character of the
12901 array. If an array is accessed beyond the end of an object, the behavior is undefined.
12902 2 Where an argument declared as size_t n specifies the length of the array for a
12903 function, n can have the value zero on a call to that function. Unless explicitly stated
12904 otherwise in the description of a particular function in this subclause, pointer arguments
12905 on such a call shall still have valid values, as described in 7.1.4. On such a call, a
12906 function that locates a character finds no occurrence, a function that compares two
12907 character sequences returns zero, and a function that copies characters copies zero
12909 3 For all functions in this subclause, each character shall be interpreted as if it had the type
12910 unsigned char (and therefore every possible object representation is valid and has a
12912 7.21.2 Copying functions
12913 7.21.2.1 The memcpy function
12915 1 #include <string.h>
12916 void *memcpy(void * restrict s1,
12917 const void * restrict s2,
12920 2 The memcpy function copies n characters from the object pointed to by s2 into the
12921 object pointed to by s1. If copying takes place between objects that overlap, the behavior
12924 3 The memcpy function returns the value of s1.
12929 268) See ''future library directions'' (7.26.11).
12933 7.21.2.2 The memmove function
12935 1 #include <string.h>
12936 void *memmove(void *s1, const void *s2, size_t n);
12938 2 The memmove function copies n characters from the object pointed to by s2 into the
12939 object pointed to by s1. Copying takes place as if the n characters from the object
12940 pointed to by s2 are first copied into a temporary array of n characters that does not
12941 overlap the objects pointed to by s1 and s2, and then the n characters from the
12942 temporary array are copied into the object pointed to by s1.
12944 3 The memmove function returns the value of s1.
12945 7.21.2.3 The strcpy function
12947 1 #include <string.h>
12948 char *strcpy(char * restrict s1,
12949 const char * restrict s2);
12951 2 The strcpy function copies the string pointed to by s2 (including the terminating null
12952 character) into the array pointed to by s1. If copying takes place between objects that
12953 overlap, the behavior is undefined.
12955 3 The strcpy function returns the value of s1.
12956 7.21.2.4 The strncpy function
12958 1 #include <string.h>
12959 char *strncpy(char * restrict s1,
12960 const char * restrict s2,
12963 2 The strncpy function copies not more than n characters (characters that follow a null
12964 character are not copied) from the array pointed to by s2 to the array pointed to by
12971 s1.269) If copying takes place between objects that overlap, the behavior is undefined.
12972 3 If the array pointed to by s2 is a string that is shorter than n characters, null characters
12973 are appended to the copy in the array pointed to by s1, until n characters in all have been
12976 4 The strncpy function returns the value of s1.
12977 7.21.3 Concatenation functions
12978 7.21.3.1 The strcat function
12980 1 #include <string.h>
12981 char *strcat(char * restrict s1,
12982 const char * restrict s2);
12984 2 The strcat function appends a copy of the string pointed to by s2 (including the
12985 terminating null character) to the end of the string pointed to by s1. The initial character
12986 of s2 overwrites the null character at the end of s1. If copying takes place between
12987 objects that overlap, the behavior is undefined.
12989 3 The strcat function returns the value of s1.
12990 7.21.3.2 The strncat function
12992 1 #include <string.h>
12993 char *strncat(char * restrict s1,
12994 const char * restrict s2,
12997 2 The strncat function appends not more than n characters (a null character and
12998 characters that follow it are not appended) from the array pointed to by s2 to the end of
12999 the string pointed to by s1. The initial character of s2 overwrites the null character at the
13000 end of s1. A terminating null character is always appended to the result.270) If copying
13002 269) Thus, if there is no null character in the first n characters of the array pointed to by s2, the result will
13003 not be null-terminated.
13004 270) Thus, the maximum number of characters that can end up in the array pointed to by s1 is
13009 takes place between objects that overlap, the behavior is undefined.
13011 3 The strncat function returns the value of s1.
13012 Forward references: the strlen function (7.21.6.3).
13013 7.21.4 Comparison functions
13014 1 The sign of a nonzero value returned by the comparison functions memcmp, strcmp,
13015 and strncmp is determined by the sign of the difference between the values of the first
13016 pair of characters (both interpreted as unsigned char) that differ in the objects being
13018 7.21.4.1 The memcmp function
13020 1 #include <string.h>
13021 int memcmp(const void *s1, const void *s2, size_t n);
13023 2 The memcmp function compares the first n characters of the object pointed to by s1 to
13024 the first n characters of the object pointed to by s2.271)
13026 3 The memcmp function returns an integer greater than, equal to, or less than zero,
13027 accordingly as the object pointed to by s1 is greater than, equal to, or less than the object
13029 7.21.4.2 The strcmp function
13031 1 #include <string.h>
13032 int strcmp(const char *s1, const char *s2);
13034 2 The strcmp function compares the string pointed to by s1 to the string pointed to by
13037 3 The strcmp function returns an integer greater than, equal to, or less than zero,
13038 accordingly as the string pointed to by s1 is greater than, equal to, or less than the string
13040 271) The contents of ''holes'' used as padding for purposes of alignment within structure objects are
13041 indeterminate. Strings shorter than their allocated space and unions may also cause problems in
13047 7.21.4.3 The strcoll function
13049 1 #include <string.h>
13050 int strcoll(const char *s1, const char *s2);
13052 2 The strcoll function compares the string pointed to by s1 to the string pointed to by
13053 s2, both interpreted as appropriate to the LC_COLLATE category of the current locale.
13055 3 The strcoll function returns an integer greater than, equal to, or less than zero,
13056 accordingly as the string pointed to by s1 is greater than, equal to, or less than the string
13057 pointed to by s2 when both are interpreted as appropriate to the current locale.
13058 7.21.4.4 The strncmp function
13060 1 #include <string.h>
13061 int strncmp(const char *s1, const char *s2, size_t n);
13063 2 The strncmp function compares not more than n characters (characters that follow a
13064 null character are not compared) from the array pointed to by s1 to the array pointed to
13067 3 The strncmp function returns an integer greater than, equal to, or less than zero,
13068 accordingly as the possibly null-terminated array pointed to by s1 is greater than, equal
13069 to, or less than the possibly null-terminated array pointed to by s2.
13070 7.21.4.5 The strxfrm function
13072 1 #include <string.h>
13073 size_t strxfrm(char * restrict s1,
13074 const char * restrict s2,
13077 2 The strxfrm function transforms the string pointed to by s2 and places the resulting
13078 string into the array pointed to by s1. The transformation is such that if the strcmp
13079 function is applied to two transformed strings, it returns a value greater than, equal to, or
13083 less than zero, corresponding to the result of the strcoll function applied to the same
13084 two original strings. No more than n characters are placed into the resulting array
13085 pointed to by s1, including the terminating null character. If n is zero, s1 is permitted to
13086 be a null pointer. If copying takes place between objects that overlap, the behavior is
13089 3 The strxfrm function returns the length of the transformed string (not including the
13090 terminating null character). If the value returned is n or more, the contents of the array
13091 pointed to by s1 are indeterminate.
13092 4 EXAMPLE The value of the following expression is the size of the array needed to hold the
13093 transformation of the string pointed to by s.
13094 1 + strxfrm(NULL, s, 0)
13096 7.21.5 Search functions
13097 7.21.5.1 The memchr function
13099 1 #include <string.h>
13100 void *memchr(const void *s, int c, size_t n);
13102 2 The memchr function locates the first occurrence of c (converted to an unsigned
13103 char) in the initial n characters (each interpreted as unsigned char) of the object
13106 3 The memchr function returns a pointer to the located character, or a null pointer if the
13107 character does not occur in the object.
13108 7.21.5.2 The strchr function
13110 1 #include <string.h>
13111 char *strchr(const char *s, int c);
13113 2 The strchr function locates the first occurrence of c (converted to a char) in the
13114 string pointed to by s. The terminating null character is considered to be part of the
13117 3 The strchr function returns a pointer to the located character, or a null pointer if the
13118 character does not occur in the string.
13121 7.21.5.3 The strcspn function
13123 1 #include <string.h>
13124 size_t strcspn(const char *s1, const char *s2);
13126 2 The strcspn function computes the length of the maximum initial segment of the string
13127 pointed to by s1 which consists entirely of characters not from the string pointed to by
13130 3 The strcspn function returns the length of the segment.
13131 7.21.5.4 The strpbrk function
13133 1 #include <string.h>
13134 char *strpbrk(const char *s1, const char *s2);
13136 2 The strpbrk function locates the first occurrence in the string pointed to by s1 of any
13137 character from the string pointed to by s2.
13139 3 The strpbrk function returns a pointer to the character, or a null pointer if no character
13140 from s2 occurs in s1.
13141 7.21.5.5 The strrchr function
13143 1 #include <string.h>
13144 char *strrchr(const char *s, int c);
13146 2 The strrchr function locates the last occurrence of c (converted to a char) in the
13147 string pointed to by s. The terminating null character is considered to be part of the
13150 3 The strrchr function returns a pointer to the character, or a null pointer if c does not
13151 occur in the string.
13158 7.21.5.6 The strspn function
13160 1 #include <string.h>
13161 size_t strspn(const char *s1, const char *s2);
13163 2 The strspn function computes the length of the maximum initial segment of the string
13164 pointed to by s1 which consists entirely of characters from the string pointed to by s2.
13166 3 The strspn function returns the length of the segment.
13167 7.21.5.7 The strstr function
13169 1 #include <string.h>
13170 char *strstr(const char *s1, const char *s2);
13172 2 The strstr function locates the first occurrence in the string pointed to by s1 of the
13173 sequence of characters (excluding the terminating null character) in the string pointed to
13176 3 The strstr function returns a pointer to the located string, or a null pointer if the string
13177 is not found. If s2 points to a string with zero length, the function returns s1.
13178 7.21.5.8 The strtok function
13180 1 #include <string.h>
13181 char *strtok(char * restrict s1,
13182 const char * restrict s2);
13184 2 A sequence of calls to the strtok function breaks the string pointed to by s1 into a
13185 sequence of tokens, each of which is delimited by a character from the string pointed to
13186 by s2. The first call in the sequence has a non-null first argument; subsequent calls in the
13187 sequence have a null first argument. The separator string pointed to by s2 may be
13188 different from call to call.
13189 3 The first call in the sequence searches the string pointed to by s1 for the first character
13190 that is not contained in the current separator string pointed to by s2. If no such character
13191 is found, then there are no tokens in the string pointed to by s1 and the strtok function
13195 returns a null pointer. If such a character is found, it is the start of the first token.
13196 4 The strtok function then searches from there for a character that is contained in the
13197 current separator string. If no such character is found, the current token extends to the
13198 end of the string pointed to by s1, and subsequent searches for a token will return a null
13199 pointer. If such a character is found, it is overwritten by a null character, which
13200 terminates the current token. The strtok function saves a pointer to the following
13201 character, from which the next search for a token will start.
13202 5 Each subsequent call, with a null pointer as the value of the first argument, starts
13203 searching from the saved pointer and behaves as described above.
13204 6 The implementation shall behave as if no library function calls the strtok function.
13206 7 The strtok function returns a pointer to the first character of a token, or a null pointer
13207 if there is no token.
13209 #include <string.h>
13210 static char str[] = "?a???b,,,#c";
13212 t = strtok(str, "?"); // t points to the token "a"
13213 t = strtok(NULL, ","); // t points to the token "??b"
13214 t = strtok(NULL, "#,"); // t points to the token "c"
13215 t = strtok(NULL, "?"); // t is a null pointer
13217 7.21.6 Miscellaneous functions
13218 7.21.6.1 The memset function
13220 1 #include <string.h>
13221 void *memset(void *s, int c, size_t n);
13223 2 The memset function copies the value of c (converted to an unsigned char) into
13224 each of the first n characters of the object pointed to by s.
13226 3 The memset function returns the value of s.
13233 7.21.6.2 The strerror function
13235 1 #include <string.h>
13236 char *strerror(int errnum);
13238 2 The strerror function maps the number in errnum to a message string. Typically,
13239 the values for errnum come from errno, but strerror shall map any value of type
13241 3 The implementation shall behave as if no library function calls the strerror function.
13243 4 The strerror function returns a pointer to the string, the contents of which are locale-
13244 specific. The array pointed to shall not be modified by the program, but may be
13245 overwritten by a subsequent call to the strerror function.
13246 7.21.6.3 The strlen function
13248 1 #include <string.h>
13249 size_t strlen(const char *s);
13251 2 The strlen function computes the length of the string pointed to by s.
13253 3 The strlen function returns the number of characters that precede the terminating null
13261 7.22 Type-generic math <tgmath.h>
13262 1 The header <tgmath.h> includes the headers <math.h> and <complex.h> and
13263 defines several type-generic macros.
13264 2 Of the <math.h> and <complex.h> functions without an f (float) or l (long
13265 double) suffix, several have one or more parameters whose corresponding real type is
13266 double. For each such function, except modf, there is a corresponding type-generic
13267 macro.272) The parameters whose corresponding real type is double in the function
13268 synopsis are generic parameters. Use of the macro invokes a function whose
13269 corresponding real type and type domain are determined by the arguments for the generic
13271 3 Use of the macro invokes a function whose generic parameters have the corresponding
13272 real type determined as follows:
13273 -- First, if any argument for generic parameters has type long double, the type
13274 determined is long double.
13275 -- Otherwise, if any argument for generic parameters has type double or is of integer
13276 type, the type determined is double.
13277 -- Otherwise, the type determined is float.
13278 4 For each unsuffixed function in <math.h> for which there is a function in
13279 <complex.h> with the same name except for a c prefix, the corresponding type-
13280 generic macro (for both functions) has the same name as the function in <math.h>. The
13281 corresponding type-generic macro for fabs and cabs is fabs.
13286 272) Like other function-like macros in Standard libraries, each type-generic macro can be suppressed to
13287 make available the corresponding ordinary function.
13288 273) If the type of the argument is not compatible with the type of the parameter for the selected function,
13289 the behavior is undefined.
13293 <math.h> <complex.h> type-generic
13294 function function macro
13312 If at least one argument for a generic parameter is complex, then use of the macro invokes
13313 a complex function; otherwise, use of the macro invokes a real function.
13314 5 For each unsuffixed function in <math.h> without a c-prefixed counterpart in
13315 <complex.h> (except modf), the corresponding type-generic macro has the same
13316 name as the function. These type-generic macros are:
13317 atan2 fma llround remainder
13318 cbrt fmax log10 remquo
13319 ceil fmin log1p rint
13320 copysign fmod log2 round
13321 erf frexp logb scalbn
13322 erfc hypot lrint scalbln
13323 exp2 ilogb lround tgamma
13324 expm1 ldexp nearbyint trunc
13325 fdim lgamma nextafter
13326 floor llrint nexttoward
13327 If all arguments for generic parameters are real, then use of the macro invokes a real
13328 function; otherwise, use of the macro results in undefined behavior.
13329 6 For each unsuffixed function in <complex.h> that is not a c-prefixed counterpart to a
13330 function in <math.h>, the corresponding type-generic macro has the same name as the
13331 function. These type-generic macros are:
13337 Use of the macro with any real or complex argument invokes a complex function.
13338 7 EXAMPLE With the declarations
13339 #include <tgmath.h>
13346 long double complex ldc;
13347 functions invoked by use of type-generic macros are shown in the following table:
13349 exp(n) exp(n), the function
13351 sin(d) sin(d), the function
13355 pow(ldc, f) cpowl(ldc, f)
13356 remainder(n, n) remainder(n, n), the function
13357 nextafter(d, f) nextafter(d, f), the function
13358 nexttoward(f, ld) nexttowardf(f, ld)
13359 copysign(n, ld) copysignl(n, ld)
13360 ceil(fc) undefined behavior
13361 rint(dc) undefined behavior
13362 fmax(ldc, ld) undefined behavior
13363 carg(n) carg(n), the function
13365 creal(d) creal(d), the function
13366 cimag(ld) cimagl(ld)
13368 carg(dc) carg(dc), the function
13369 cproj(ldc) cprojl(ldc)
13376 7.23 Date and time <time.h>
13377 7.23.1 Components of time
13378 1 The header <time.h> defines two macros, and declares several types and functions for
13379 manipulating time. Many functions deal with a calendar time that represents the current
13380 date (according to the Gregorian calendar) and time. Some functions deal with local
13381 time, which is the calendar time expressed for some specific time zone, and with Daylight
13382 Saving Time, which is a temporary change in the algorithm for determining local time.
13383 The local time zone and Daylight Saving Time are implementation-defined.
13384 2 The macros defined are NULL (described in 7.17); and
13386 which expands to an expression with type clock_t (described below) that is the
13387 number per second of the value returned by the clock function.
13388 3 The types declared are size_t (described in 7.17);
13392 which are arithmetic types capable of representing times; and
13394 which holds the components of a calendar time, called the broken-down time.
13395 4 The range and precision of times representable in clock_t and time_t are
13396 implementation-defined. The tm structure shall contain at least the following members,
13397 in any order. The semantics of the members and their normal ranges are expressed in the
13399 int tm_sec; // seconds after the minute -- [0, 60]
13400 int tm_min; // minutes after the hour -- [0, 59]
13401 int tm_hour; // hours since midnight -- [0, 23]
13402 int tm_mday; // day of the month -- [1, 31]
13403 int tm_mon; // months since January -- [0, 11]
13404 int tm_year; // years since 1900
13405 int tm_wday; // days since Sunday -- [0, 6]
13406 int tm_yday; // days since January 1 -- [0, 365]
13407 int tm_isdst; // Daylight Saving Time flag
13411 274) The range [0, 60] for tm_sec allows for a positive leap second.
13415 The value of tm_isdst is positive if Daylight Saving Time is in effect, zero if Daylight
13416 Saving Time is not in effect, and negative if the information is not available.
13417 7.23.2 Time manipulation functions
13418 7.23.2.1 The clock function
13420 1 #include <time.h>
13421 clock_t clock(void);
13423 2 The clock function determines the processor time used.
13425 3 The clock function returns the implementation's best approximation to the processor
13426 time used by the program since the beginning of an implementation-defined era related
13427 only to the program invocation. To determine the time in seconds, the value returned by
13428 the clock function should be divided by the value of the macro CLOCKS_PER_SEC. If
13429 the processor time used is not available or its value cannot be represented, the function
13430 returns the value (clock_t)(-1).275)
13431 7.23.2.2 The difftime function
13433 1 #include <time.h>
13434 double difftime(time_t time1, time_t time0);
13436 2 The difftime function computes the difference between two calendar times: time1 -
13439 3 The difftime function returns the difference expressed in seconds as a double.
13444 275) In order to measure the time spent in a program, the clock function should be called at the start of
13445 the program and its return value subtracted from the value returned by subsequent calls.
13449 7.23.2.3 The mktime function
13451 1 #include <time.h>
13452 time_t mktime(struct tm *timeptr);
13454 2 The mktime function converts the broken-down time, expressed as local time, in the
13455 structure pointed to by timeptr into a calendar time value with the same encoding as
13456 that of the values returned by the time function. The original values of the tm_wday
13457 and tm_yday components of the structure are ignored, and the original values of the
13458 other components are not restricted to the ranges indicated above.276) On successful
13459 completion, the values of the tm_wday and tm_yday components of the structure are
13460 set appropriately, and the other components are set to represent the specified calendar
13461 time, but with their values forced to the ranges indicated above; the final value of
13462 tm_mday is not set until tm_mon and tm_year are determined.
13464 3 The mktime function returns the specified calendar time encoded as a value of type
13465 time_t. If the calendar time cannot be represented, the function returns the value
13467 4 EXAMPLE What day of the week is July 4, 2001?
13470 static const char *const wday[] = {
13471 "Sunday", "Monday", "Tuesday", "Wednesday",
13472 "Thursday", "Friday", "Saturday", "-unknown-"
13474 struct tm time_str;
13480 276) Thus, a positive or zero value for tm_isdst causes the mktime function to presume initially that
13481 Daylight Saving Time, respectively, is or is not in effect for the specified time. A negative value
13482 causes it to attempt to determine whether Daylight Saving Time is in effect for the specified time.
13486 time_str.tm_year = 2001 - 1900;
13487 time_str.tm_mon = 7 - 1;
13488 time_str.tm_mday = 4;
13489 time_str.tm_hour = 0;
13490 time_str.tm_min = 0;
13491 time_str.tm_sec = 1;
13492 time_str.tm_isdst = -1;
13493 if (mktime(&time_str) == (time_t)(-1))
13494 time_str.tm_wday = 7;
13495 printf("%s\n", wday[time_str.tm_wday]);
13497 7.23.2.4 The time function
13499 1 #include <time.h>
13500 time_t time(time_t *timer);
13502 2 The time function determines the current calendar time. The encoding of the value is
13505 3 The time function returns the implementation's best approximation to the current
13506 calendar time. The value (time_t)(-1) is returned if the calendar time is not
13507 available. If timer is not a null pointer, the return value is also assigned to the object it
13509 7.23.3 Time conversion functions
13510 1 Except for the strftime function, these functions each return a pointer to one of two
13511 types of static objects: a broken-down time structure or an array of char. Execution of
13512 any of the functions that return a pointer to one of these object types may overwrite the
13513 information in any object of the same type pointed to by the value returned from any
13514 previous call to any of them. The implementation shall behave as if no other library
13515 functions call these functions.
13516 7.23.3.1 The asctime function
13518 1 #include <time.h>
13519 char *asctime(const struct tm *timeptr);
13521 2 The asctime function converts the broken-down time in the structure pointed to by
13522 timeptr into a string in the form
13523 Sun Sep 16 01:03:52 1973\n\0
13527 using the equivalent of the following algorithm.
13528 char *asctime(const struct tm *timeptr)
13530 static const char wday_name[7][3] = {
13531 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
13533 static const char mon_name[12][3] = {
13534 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
13535 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
13537 static char result[26];
13538 sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
13539 wday_name[timeptr->tm_wday],
13540 mon_name[timeptr->tm_mon],
13541 timeptr->tm_mday, timeptr->tm_hour,
13542 timeptr->tm_min, timeptr->tm_sec,
13543 1900 + timeptr->tm_year);
13547 3 The asctime function returns a pointer to the string.
13548 7.23.3.2 The ctime function
13550 1 #include <time.h>
13551 char *ctime(const time_t *timer);
13553 2 The ctime function converts the calendar time pointed to by timer to local time in the
13554 form of a string. It is equivalent to
13555 asctime(localtime(timer))
13557 3 The ctime function returns the pointer returned by the asctime function with that
13558 broken-down time as argument.
13559 Forward references: the localtime function (7.23.3.4).
13566 7.23.3.3 The gmtime function
13568 1 #include <time.h>
13569 struct tm *gmtime(const time_t *timer);
13571 2 The gmtime function converts the calendar time pointed to by timer into a broken-
13572 down time, expressed as UTC.
13574 3 The gmtime function returns a pointer to the broken-down time, or a null pointer if the
13575 specified time cannot be converted to UTC.
13576 7.23.3.4 The localtime function
13578 1 #include <time.h>
13579 struct tm *localtime(const time_t *timer);
13581 2 The localtime function converts the calendar time pointed to by timer into a
13582 broken-down time, expressed as local time.
13584 3 The localtime function returns a pointer to the broken-down time, or a null pointer if
13585 the specified time cannot be converted to local time.
13586 7.23.3.5 The strftime function
13588 1 #include <time.h>
13589 size_t strftime(char * restrict s,
13591 const char * restrict format,
13592 const struct tm * restrict timeptr);
13594 2 The strftime function places characters into the array pointed to by s as controlled by
13595 the string pointed to by format. The format shall be a multibyte character sequence,
13596 beginning and ending in its initial shift state. The format string consists of zero or
13597 more conversion specifiers and ordinary multibyte characters. A conversion specifier
13598 consists of a % character, possibly followed by an E or O modifier character (described
13599 below), followed by a character that determines the behavior of the conversion specifier.
13600 All ordinary multibyte characters (including the terminating null character) are copied
13603 unchanged into the array. If copying takes place between objects that overlap, the
13604 behavior is undefined. No more than maxsize characters are placed into the array.
13605 3 Each conversion specifier is replaced by appropriate characters as described in the
13606 following list. The appropriate characters are determined using the LC_TIME category
13607 of the current locale and by the values of zero or more members of the broken-down time
13608 structure pointed to by timeptr, as specified in brackets in the description. If any of
13609 the specified values is outside the normal range, the characters stored are unspecified.
13610 %a is replaced by the locale's abbreviated weekday name. [tm_wday]
13611 %A is replaced by the locale's full weekday name. [tm_wday]
13612 %b is replaced by the locale's abbreviated month name. [tm_mon]
13613 %B is replaced by the locale's full month name. [tm_mon]
13614 %c is replaced by the locale's appropriate date and time representation. [all specified
13616 %C is replaced by the year divided by 100 and truncated to an integer, as a decimal
13617 number (00-99). [tm_year]
13618 %d is replaced by the day of the month as a decimal number (01-31). [tm_mday]
13619 %D is equivalent to ''%m/%d/%y''. [tm_mon, tm_mday, tm_year]
13620 %e is replaced by the day of the month as a decimal number (1-31); a single digit is
13621 preceded by a space. [tm_mday]
13622 %F is equivalent to ''%Y-%m-%d'' (the ISO 8601 date format). [tm_year, tm_mon,
13624 %g is replaced by the last 2 digits of the week-based year (see below) as a decimal
13625 number (00-99). [tm_year, tm_wday, tm_yday]
13626 %G is replaced by the week-based year (see below) as a decimal number (e.g., 1997).
13627 [tm_year, tm_wday, tm_yday]
13628 %h is equivalent to ''%b''. [tm_mon]
13629 %H is replaced by the hour (24-hour clock) as a decimal number (00-23). [tm_hour]
13630 %I is replaced by the hour (12-hour clock) as a decimal number (01-12). [tm_hour]
13631 %j is replaced by the day of the year as a decimal number (001-366). [tm_yday]
13632 %m is replaced by the month as a decimal number (01-12). [tm_mon]
13633 %M is replaced by the minute as a decimal number (00-59). [tm_min]
13634 %n is replaced by a new-line character.
13635 %p is replaced by the locale's equivalent of the AM/PM designations associated with a
13636 12-hour clock. [tm_hour]
13637 %r is replaced by the locale's 12-hour clock time. [tm_hour, tm_min, tm_sec]
13638 %R is equivalent to ''%H:%M''. [tm_hour, tm_min]
13639 %S is replaced by the second as a decimal number (00-60). [tm_sec]
13640 %t is replaced by a horizontal-tab character.
13641 %T is equivalent to ''%H:%M:%S'' (the ISO 8601 time format). [tm_hour, tm_min,
13646 %u is replaced by the ISO 8601 weekday as a decimal number (1-7), where Monday
13648 %U is replaced by the week number of the year (the first Sunday as the first day of week
13649 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
13650 %V is replaced by the ISO 8601 week number (see below) as a decimal number
13651 (01-53). [tm_year, tm_wday, tm_yday]
13652 %w is replaced by the weekday as a decimal number (0-6), where Sunday is 0.
13654 %W is replaced by the week number of the year (the first Monday as the first day of
13655 week 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
13656 %x is replaced by the locale's appropriate date representation. [all specified in 7.23.1]
13657 %X is replaced by the locale's appropriate time representation. [all specified in 7.23.1]
13658 %y is replaced by the last 2 digits of the year as a decimal number (00-99).
13660 %Y is replaced by the year as a decimal number (e.g., 1997). [tm_year]
13661 %z is replaced by the offset from UTC in the ISO 8601 format ''-0430'' (meaning 4
13662 hours 30 minutes behind UTC, west of Greenwich), or by no characters if no time
13663 zone is determinable. [tm_isdst]
13664 %Z is replaced by the locale's time zone name or abbreviation, or by no characters if no
13665 time zone is determinable. [tm_isdst]
13666 %% is replaced by %.
13667 4 Some conversion specifiers can be modified by the inclusion of an E or O modifier
13668 character to indicate an alternative format or specification. If the alternative format or
13669 specification does not exist for the current locale, the modifier is ignored.
13670 %Ec is replaced by the locale's alternative date and time representation.
13671 %EC is replaced by the name of the base year (period) in the locale's alternative
13673 %Ex is replaced by the locale's alternative date representation.
13674 %EX is replaced by the locale's alternative time representation.
13675 %Ey is replaced by the offset from %EC (year only) in the locale's alternative
13677 %EY is replaced by the locale's full alternative year representation.
13678 %Od is replaced by the day of the month, using the locale's alternative numeric symbols
13679 (filled as needed with leading zeros, or with leading spaces if there is no alternative
13681 %Oe is replaced by the day of the month, using the locale's alternative numeric symbols
13682 (filled as needed with leading spaces).
13683 %OH is replaced by the hour (24-hour clock), using the locale's alternative numeric
13689 %OI is replaced by the hour (12-hour clock), using the locale's alternative numeric
13691 %Om is replaced by the month, using the locale's alternative numeric symbols.
13692 %OM is replaced by the minutes, using the locale's alternative numeric symbols.
13693 %OS is replaced by the seconds, using the locale's alternative numeric symbols.
13694 %Ou is replaced by the ISO 8601 weekday as a number in the locale's alternative
13695 representation, where Monday is 1.
13696 %OU is replaced by the week number, using the locale's alternative numeric symbols.
13697 %OV is replaced by the ISO 8601 week number, using the locale's alternative numeric
13699 %Ow is replaced by the weekday as a number, using the locale's alternative numeric
13701 %OW is replaced by the week number of the year, using the locale's alternative numeric
13703 %Oy is replaced by the last 2 digits of the year, using the locale's alternative numeric
13705 5 %g, %G, and %V give values according to the ISO 8601 week-based year. In this system,
13706 weeks begin on a Monday and week 1 of the year is the week that includes January 4th,
13707 which is also the week that includes the first Thursday of the year, and is also the first
13708 week that contains at least four days in the year. If the first Monday of January is the
13709 2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year; thus,
13710 for Saturday 2nd January 1999, %G is replaced by 1998 and %V is replaced by 53. If
13711 December 29th, 30th, or 31st is a Monday, it and any following days are part of week 1 of
13712 the following year. Thus, for Tuesday 30th December 1997, %G is replaced by 1998 and
13713 %V is replaced by 01.
13714 6 If a conversion specifier is not one of the above, the behavior is undefined.
13715 7 In the "C" locale, the E and O modifiers are ignored and the replacement strings for the
13716 following specifiers are:
13717 %a the first three characters of %A.
13718 %A one of ''Sunday'', ''Monday'', ... , ''Saturday''.
13719 %b the first three characters of %B.
13720 %B one of ''January'', ''February'', ... , ''December''.
13721 %c equivalent to ''%a %b %e %T %Y''.
13722 %p one of ''AM'' or ''PM''.
13723 %r equivalent to ''%I:%M:%S %p''.
13724 %x equivalent to ''%m/%d/%y''.
13725 %X equivalent to %T.
13726 %Z implementation-defined.
13732 8 If the total number of resulting characters including the terminating null character is not
13733 more than maxsize, the strftime function returns the number of characters placed
13734 into the array pointed to by s not including the terminating null character. Otherwise,
13735 zero is returned and the contents of the array are indeterminate.
13742 7.24 Extended multibyte and wide character utilities <wchar.h>
13743 7.24.1 Introduction
13744 1 The header <wchar.h> declares four data types, one tag, four macros, and many
13746 2 The types declared are wchar_t and size_t (both described in 7.17);
13748 which is an object type other than an array type that can hold the conversion state
13749 information necessary to convert between sequences of multibyte characters and wide
13752 which is an integer type unchanged by default argument promotions that can hold any
13753 value corresponding to members of the extended character set, as well as at least one
13754 value that does not correspond to any member of the extended character set (see WEOF
13757 which is declared as an incomplete structure type (the contents are described in 7.23.1).
13758 3 The macros defined are NULL (described in 7.17); WCHAR_MIN and WCHAR_MAX
13759 (described in 7.18.3); and
13761 which expands to a constant expression of type wint_t whose value does not
13762 correspond to any member of the extended character set.279) It is accepted (and returned)
13763 by several functions in this subclause to indicate end-of-file, that is, no more input from a
13764 stream. It is also used as a wide character value that does not correspond to any member
13765 of the extended character set.
13766 4 The functions declared are grouped as follows:
13767 -- Functions that perform input and output of wide characters, or multibyte characters,
13769 -- Functions that provide wide string numeric conversion;
13770 -- Functions that perform general wide string manipulation;
13773 277) See ''future library directions'' (7.26.12).
13774 278) wchar_t and wint_t can be the same integer type.
13775 279) The value of the macro WEOF may differ from that of EOF and need not be negative.
13779 -- Functions for wide string date and time conversion; and
13780 -- Functions that provide extended capabilities for conversion between multibyte and
13781 wide character sequences.
13782 5 Unless explicitly stated otherwise, if the execution of a function described in this
13783 subclause causes copying to take place between objects that overlap, the behavior is
13785 7.24.2 Formatted wide character input/output functions
13786 1 The formatted wide character input/output functions shall behave as if there is a sequence
13787 point after the actions associated with each specifier.280)
13788 7.24.2.1 The fwprintf function
13790 1 #include <stdio.h>
13792 int fwprintf(FILE * restrict stream,
13793 const wchar_t * restrict format, ...);
13795 2 The fwprintf function writes output to the stream pointed to by stream, under
13796 control of the wide string pointed to by format that specifies how subsequent arguments
13797 are converted for output. If there are insufficient arguments for the format, the behavior
13798 is undefined. If the format is exhausted while arguments remain, the excess arguments
13799 are evaluated (as always) but are otherwise ignored. The fwprintf function returns
13800 when the end of the format string is encountered.
13801 3 The format is composed of zero or more directives: ordinary wide characters (not %),
13802 which are copied unchanged to the output stream; and conversion specifications, each of
13803 which results in fetching zero or more subsequent arguments, converting them, if
13804 applicable, according to the corresponding conversion specifier, and then writing the
13805 result to the output stream.
13806 4 Each conversion specification is introduced by the wide character %. After the %, the
13807 following appear in sequence:
13808 -- Zero or more flags (in any order) that modify the meaning of the conversion
13810 -- An optional minimum field width. If the converted value has fewer wide characters
13811 than the field width, it is padded with spaces (by default) on the left (or right, if the
13814 280) The fwprintf functions perform writes to memory for the %n specifier.
13818 left adjustment flag, described later, has been given) to the field width. The field
13819 width takes the form of an asterisk * (described later) or a nonnegative decimal
13821 -- An optional precision that gives the minimum number of digits to appear for the d, i,
13822 o, u, x, and X conversions, the number of digits to appear after the decimal-point
13823 wide character for a, A, e, E, f, and F conversions, the maximum number of
13824 significant digits for the g and G conversions, or the maximum number of wide
13825 characters to be written for s conversions. The precision takes the form of a period
13826 (.) followed either by an asterisk * (described later) or by an optional decimal
13827 integer; if only the period is specified, the precision is taken as zero. If a precision
13828 appears with any other conversion specifier, the behavior is undefined.
13829 -- An optional length modifier that specifies the size of the argument.
13830 -- A conversion specifier wide character that specifies the type of conversion to be
13832 5 As noted above, a field width, or precision, or both, may be indicated by an asterisk. In
13833 this case, an int argument supplies the field width or precision. The arguments
13834 specifying field width, or precision, or both, shall appear (in that order) before the
13835 argument (if any) to be converted. A negative field width argument is taken as a - flag
13836 followed by a positive field width. A negative precision argument is taken as if the
13837 precision were omitted.
13838 6 The flag wide characters and their meanings are:
13839 - The result of the conversion is left-justified within the field. (It is right-justified if
13840 this flag is not specified.)
13841 + The result of a signed conversion always begins with a plus or minus sign. (It
13842 begins with a sign only when a negative value is converted if this flag is not
13844 space If the first wide character of a signed conversion is not a sign, or if a signed
13845 conversion results in no wide characters, a space is prefixed to the result. If the
13846 space and + flags both appear, the space flag is ignored.
13847 # The result is converted to an ''alternative form''. For o conversion, it increases
13848 the precision, if and only if necessary, to force the first digit of the result to be a
13849 zero (if the value and precision are both 0, a single 0 is printed). For x (or X)
13850 conversion, a nonzero result has 0x (or 0X) prefixed to it. For a, A, e, E, f, F, g,
13852 281) Note that 0 is taken as a flag, not as the beginning of a field width.
13853 282) The results of all floating conversions of a negative zero, and of negative values that round to zero,
13854 include a minus sign.
13858 and G conversions, the result of converting a floating-point number always
13859 contains a decimal-point wide character, even if no digits follow it. (Normally, a
13860 decimal-point wide character appears in the result of these conversions only if a
13861 digit follows it.) For g and G conversions, trailing zeros are not removed from the
13862 result. For other conversions, the behavior is undefined.
13863 0 For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros
13864 (following any indication of sign or base) are used to pad to the field width rather
13865 than performing space padding, except when converting an infinity or NaN. If the
13866 0 and - flags both appear, the 0 flag is ignored. For d, i, o, u, x, and X
13867 conversions, if a precision is specified, the 0 flag is ignored. For other
13868 conversions, the behavior is undefined.
13869 7 The length modifiers and their meanings are:
13870 hh Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13871 signed char or unsigned char argument (the argument will have
13872 been promoted according to the integer promotions, but its value shall be
13873 converted to signed char or unsigned char before printing); or that
13874 a following n conversion specifier applies to a pointer to a signed char
13876 h Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13877 short int or unsigned short int argument (the argument will
13878 have been promoted according to the integer promotions, but its value shall
13879 be converted to short int or unsigned short int before printing);
13880 or that a following n conversion specifier applies to a pointer to a short
13882 l (ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13883 long int or unsigned long int argument; that a following n
13884 conversion specifier applies to a pointer to a long int argument; that a
13885 following c conversion specifier applies to a wint_t argument; that a
13886 following s conversion specifier applies to a pointer to a wchar_t
13887 argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion
13889 ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13890 long long int or unsigned long long int argument; or that a
13891 following n conversion specifier applies to a pointer to a long long int
13893 j Specifies that a following d, i, o, u, x, or X conversion specifier applies to
13894 an intmax_t or uintmax_t argument; or that a following n conversion
13895 specifier applies to a pointer to an intmax_t argument.
13899 z Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13900 size_t or the corresponding signed integer type argument; or that a
13901 following n conversion specifier applies to a pointer to a signed integer type
13902 corresponding to size_t argument.
13903 t Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
13904 ptrdiff_t or the corresponding unsigned integer type argument; or that a
13905 following n conversion specifier applies to a pointer to a ptrdiff_t
13907 L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
13908 applies to a long double argument.
13909 If a length modifier appears with any conversion specifier other than as specified above,
13910 the behavior is undefined.
13911 8 The conversion specifiers and their meanings are:
13912 d,i The int argument is converted to signed decimal in the style [-]dddd. The
13913 precision specifies the minimum number of digits to appear; if the value
13914 being converted can be represented in fewer digits, it is expanded with
13915 leading zeros. The default precision is 1. The result of converting a zero
13916 value with a precision of zero is no wide characters.
13917 o,u,x,X The unsigned int argument is converted to unsigned octal (o), unsigned
13918 decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; the
13919 letters abcdef are used for x conversion and the letters ABCDEF for X
13920 conversion. The precision specifies the minimum number of digits to appear;
13921 if the value being converted can be represented in fewer digits, it is expanded
13922 with leading zeros. The default precision is 1. The result of converting a
13923 zero value with a precision of zero is no wide characters.
13924 f,F A double argument representing a floating-point number is converted to
13925 decimal notation in the style [-]ddd.ddd, where the number of digits after
13926 the decimal-point wide character is equal to the precision specification. If the
13927 precision is missing, it is taken as 6; if the precision is zero and the # flag is
13928 not specified, no decimal-point wide character appears. If a decimal-point
13929 wide character appears, at least one digit appears before it. The value is
13930 rounded to the appropriate number of digits.
13931 A double argument representing an infinity is converted in one of the styles
13932 [-]inf or [-]infinity -- which style is implementation-defined. A
13933 double argument representing a NaN is converted in one of the styles
13934 [-]nan or [-]nan(n-wchar-sequence) -- which style, and the meaning of
13935 any n-wchar-sequence, is implementation-defined. The F conversion
13936 specifier produces INF, INFINITY, or NAN instead of inf, infinity, or
13939 nan, respectively.283)
13940 e,E A double argument representing a floating-point number is converted in the
13941 style [-]d.ddd e(+-)dd, where there is one digit (which is nonzero if the
13942 argument is nonzero) before the decimal-point wide character and the number
13943 of digits after it is equal to the precision; if the precision is missing, it is taken
13944 as 6; if the precision is zero and the # flag is not specified, no decimal-point
13945 wide character appears. The value is rounded to the appropriate number of
13946 digits. The E conversion specifier produces a number with E instead of e
13947 introducing the exponent. The exponent always contains at least two digits,
13948 and only as many more digits as necessary to represent the exponent. If the
13949 value is zero, the exponent is zero.
13950 A double argument representing an infinity or NaN is converted in the style
13951 of an f or F conversion specifier.
13952 g,G A double argument representing a floating-point number is converted in
13953 style f or e (or in style F or E in the case of a G conversion specifier),
13954 depending on the value converted and the precision. Let P equal the
13955 precision if nonzero, 6 if the precision is omitted, or 1 if the precision is zero.
13956 Then, if a conversion with style E would have an exponent of X :
13957 -- if P > X >= -4, the conversion is with style f (or F) and precision
13959 -- otherwise, the conversion is with style e (or E) and precision P - 1.
13960 Finally, unless the # flag is used, any trailing zeros are removed from the
13961 fractional portion of the result and the decimal-point wide character is
13962 removed if there is no fractional portion remaining.
13963 A double argument representing an infinity or NaN is converted in the style
13964 of an f or F conversion specifier.
13965 a,A A double argument representing a floating-point number is converted in the
13966 style [-]0xh.hhhh p(+-)d, where there is one hexadecimal digit (which is
13967 nonzero if the argument is a normalized floating-point number and is
13968 otherwise unspecified) before the decimal-point wide character284) and the
13969 number of hexadecimal digits after it is equal to the precision; if the precision
13970 is missing and FLT_RADIX is a power of 2, then the precision is sufficient
13973 283) When applied to infinite and NaN values, the -, +, and space flag wide characters have their usual
13974 meaning; the # and 0 flag wide characters have no effect.
13975 284) Binary implementations can choose the hexadecimal digit to the left of the decimal-point wide
13976 character so that subsequent digits align to nibble (4-bit) boundaries.
13980 for an exact representation of the value; if the precision is missing and
13981 FLT_RADIX is not a power of 2, then the precision is sufficient to
13982 distinguish285) values of type double, except that trailing zeros may be
13983 omitted; if the precision is zero and the # flag is not specified, no decimal-
13984 point wide character appears. The letters abcdef are used for a conversion
13985 and the letters ABCDEF for A conversion. The A conversion specifier
13986 produces a number with X and P instead of x and p. The exponent always
13987 contains at least one digit, and only as many more digits as necessary to
13988 represent the decimal exponent of 2. If the value is zero, the exponent is
13990 A double argument representing an infinity or NaN is converted in the style
13991 of an f or F conversion specifier.
13992 c If no l length modifier is present, the int argument is converted to a wide
13993 character as if by calling btowc and the resulting wide character is written.
13994 If an l length modifier is present, the wint_t argument is converted to
13995 wchar_t and written.
13996 s If no l length modifier is present, the argument shall be a pointer to the initial
13997 element of a character array containing a multibyte character sequence
13998 beginning in the initial shift state. Characters from the array are converted as
13999 if by repeated calls to the mbrtowc function, with the conversion state
14000 described by an mbstate_t object initialized to zero before the first
14001 multibyte character is converted, and written up to (but not including) the
14002 terminating null wide character. If the precision is specified, no more than
14003 that many wide characters are written. If the precision is not specified or is
14004 greater than the size of the converted array, the converted array shall contain a
14005 null wide character.
14006 If an l length modifier is present, the argument shall be a pointer to the initial
14007 element of an array of wchar_t type. Wide characters from the array are
14008 written up to (but not including) a terminating null wide character. If the
14009 precision is specified, no more than that many wide characters are written. If
14010 the precision is not specified or is greater than the size of the array, the array
14011 shall contain a null wide character.
14012 p The argument shall be a pointer to void. The value of the pointer is
14013 converted to a sequence of printing wide characters, in an implementation-
14015 285) The precision p is sufficient to distinguish values of the source type if 16 p-1 > b n where b is
14016 FLT_RADIX and n is the number of base-b digits in the significand of the source type. A smaller p
14017 might suffice depending on the implementation's scheme for determining the digit to the left of the
14018 decimal-point wide character.
14023 n The argument shall be a pointer to signed integer into which is written the
14024 number of wide characters written to the output stream so far by this call to
14025 fwprintf. No argument is converted, but one is consumed. If the
14026 conversion specification includes any flags, a field width, or a precision, the
14027 behavior is undefined.
14028 % A % wide character is written. No argument is converted. The complete
14029 conversion specification shall be %%.
14030 9 If a conversion specification is invalid, the behavior is undefined.286) If any argument is
14031 not the correct type for the corresponding conversion specification, the behavior is
14033 10 In no case does a nonexistent or small field width cause truncation of a field; if the result
14034 of a conversion is wider than the field width, the field is expanded to contain the
14036 11 For a and A conversions, if FLT_RADIX is a power of 2, the value is correctly rounded
14037 to a hexadecimal floating number with the given precision.
14038 Recommended practice
14039 12 For a and A conversions, if FLT_RADIX is not a power of 2 and the result is not exactly
14040 representable in the given precision, the result should be one of the two adjacent numbers
14041 in hexadecimal floating style with the given precision, with the extra stipulation that the
14042 error should have a correct sign for the current rounding direction.
14043 13 For e, E, f, F, g, and G conversions, if the number of significant decimal digits is at most
14044 DECIMAL_DIG, then the result should be correctly rounded.287) If the number of
14045 significant decimal digits is more than DECIMAL_DIG but the source value is exactly
14046 representable with DECIMAL_DIG digits, then the result should be an exact
14047 representation with trailing zeros. Otherwise, the source value is bounded by two
14048 adjacent decimal strings L < U, both having DECIMAL_DIG significant digits; the value
14049 of the resultant decimal string D should satisfy L <= D <= U, with the extra stipulation that
14050 the error should have a correct sign for the current rounding direction.
14052 14 The fwprintf function returns the number of wide characters transmitted, or a negative
14053 value if an output or encoding error occurred.
14055 286) See ''future library directions'' (7.26.12).
14056 287) For binary-to-decimal conversion, the result format's values are the numbers representable with the
14057 given format specifier. The number of significant digits is determined by the format specifier, and in
14058 the case of fixed-point conversion by the source value as well.
14062 Environmental limits
14063 15 The number of wide characters that can be produced by any single conversion shall be at
14065 16 EXAMPLE To print a date and time in the form ''Sunday, July 3, 10:02'' followed by pi to five decimal
14071 wchar_t *weekday, *month; // pointers to wide strings
14072 int day, hour, min;
14073 fwprintf(stdout, L"%ls, %ls %d, %.2d:%.2d\n",
14074 weekday, month, day, hour, min);
14075 fwprintf(stdout, L"pi = %.5f\n", 4 * atan(1.0));
14077 Forward references: the btowc function (7.24.6.1.1), the mbrtowc function
14079 7.24.2.2 The fwscanf function
14081 1 #include <stdio.h>
14083 int fwscanf(FILE * restrict stream,
14084 const wchar_t * restrict format, ...);
14086 2 The fwscanf function reads input from the stream pointed to by stream, under
14087 control of the wide string pointed to by format that specifies the admissible input
14088 sequences and how they are to be converted for assignment, using subsequent arguments
14089 as pointers to the objects to receive the converted input. If there are insufficient
14090 arguments for the format, the behavior is undefined. If the format is exhausted while
14091 arguments remain, the excess arguments are evaluated (as always) but are otherwise
14093 3 The format is composed of zero or more directives: one or more white-space wide
14094 characters, an ordinary wide character (neither % nor a white-space wide character), or a
14095 conversion specification. Each conversion specification is introduced by the wide
14096 character %. After the %, the following appear in sequence:
14097 -- An optional assignment-suppressing wide character *.
14098 -- An optional decimal integer greater than zero that specifies the maximum field width
14099 (in wide characters).
14105 -- An optional length modifier that specifies the size of the receiving object.
14106 -- A conversion specifier wide character that specifies the type of conversion to be
14108 4 The fwscanf function executes each directive of the format in turn. If a directive fails,
14109 as detailed below, the function returns. Failures are described as input failures (due to the
14110 occurrence of an encoding error or the unavailability of input characters), or matching
14111 failures (due to inappropriate input).
14112 5 A directive composed of white-space wide character(s) is executed by reading input up to
14113 the first non-white-space wide character (which remains unread), or until no more wide
14114 characters can be read.
14115 6 A directive that is an ordinary wide character is executed by reading the next wide
14116 character of the stream. If that wide character differs from the directive, the directive
14117 fails and the differing and subsequent wide characters remain unread. Similarly, if end-
14118 of-file, an encoding error, or a read error prevents a wide character from being read, the
14120 7 A directive that is a conversion specification defines a set of matching input sequences, as
14121 described below for each specifier. A conversion specification is executed in the
14123 8 Input white-space wide characters (as specified by the iswspace function) are skipped,
14124 unless the specification includes a [, c, or n specifier.288)
14125 9 An input item is read from the stream, unless the specification includes an n specifier. An
14126 input item is defined as the longest sequence of input wide characters which does not
14127 exceed any specified field width and which is, or is a prefix of, a matching input
14128 sequence.289) The first wide character, if any, after the input item remains unread. If the
14129 length of the input item is zero, the execution of the directive fails; this condition is a
14130 matching failure unless end-of-file, an encoding error, or a read error prevented input
14131 from the stream, in which case it is an input failure.
14132 10 Except in the case of a % specifier, the input item (or, in the case of a %n directive, the
14133 count of input wide characters) is converted to a type appropriate to the conversion
14134 specifier. If the input item is not a matching sequence, the execution of the directive fails:
14135 this condition is a matching failure. Unless assignment suppression was indicated by a *,
14136 the result of the conversion is placed in the object pointed to by the first argument
14137 following the format argument that has not already received a conversion result. If this
14140 288) These white-space wide characters are not counted against a specified field width.
14141 289) fwscanf pushes back at most one input wide character onto the input stream. Therefore, some
14142 sequences that are acceptable to wcstod, wcstol, etc., are unacceptable to fwscanf.
14146 object does not have an appropriate type, or if the result of the conversion cannot be
14147 represented in the object, the behavior is undefined.
14148 11 The length modifiers and their meanings are:
14149 hh Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
14150 to an argument with type pointer to signed char or unsigned char.
14151 h Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
14152 to an argument with type pointer to short int or unsigned short
14154 l (ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
14155 to an argument with type pointer to long int or unsigned long
14156 int; that a following a, A, e, E, f, F, g, or G conversion specifier applies to
14157 an argument with type pointer to double; or that a following c, s, or [
14158 conversion specifier applies to an argument with type pointer to wchar_t.
14159 ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
14160 to an argument with type pointer to long long int or unsigned
14162 j Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
14163 to an argument with type pointer to intmax_t or uintmax_t.
14164 z Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
14165 to an argument with type pointer to size_t or the corresponding signed
14167 t Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
14168 to an argument with type pointer to ptrdiff_t or the corresponding
14169 unsigned integer type.
14170 L Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
14171 applies to an argument with type pointer to long double.
14172 If a length modifier appears with any conversion specifier other than as specified above,
14173 the behavior is undefined.
14174 12 The conversion specifiers and their meanings are:
14175 d Matches an optionally signed decimal integer, whose format is the same as
14176 expected for the subject sequence of the wcstol function with the value 10
14177 for the base argument. The corresponding argument shall be a pointer to
14179 i Matches an optionally signed integer, whose format is the same as expected
14180 for the subject sequence of the wcstol function with the value 0 for the
14181 base argument. The corresponding argument shall be a pointer to signed
14185 o Matches an optionally signed octal integer, whose format is the same as
14186 expected for the subject sequence of the wcstoul function with the value 8
14187 for the base argument. The corresponding argument shall be a pointer to
14189 u Matches an optionally signed decimal integer, whose format is the same as
14190 expected for the subject sequence of the wcstoul function with the value 10
14191 for the base argument. The corresponding argument shall be a pointer to
14193 x Matches an optionally signed hexadecimal integer, whose format is the same
14194 as expected for the subject sequence of the wcstoul function with the value
14195 16 for the base argument. The corresponding argument shall be a pointer to
14197 a,e,f,g Matches an optionally signed floating-point number, infinity, or NaN, whose
14198 format is the same as expected for the subject sequence of the wcstod
14199 function. The corresponding argument shall be a pointer to floating.
14200 c Matches a sequence of wide characters of exactly the number specified by the
14201 field width (1 if no field width is present in the directive).
14202 If no l length modifier is present, characters from the input field are
14203 converted as if by repeated calls to the wcrtomb function, with the
14204 conversion state described by an mbstate_t object initialized to zero
14205 before the first wide character is converted. The corresponding argument
14206 shall be a pointer to the initial element of a character array large enough to
14207 accept the sequence. No null character is added.
14208 If an l length modifier is present, the corresponding argument shall be a
14209 pointer to the initial element of an array of wchar_t large enough to accept
14210 the sequence. No null wide character is added.
14211 s Matches a sequence of non-white-space wide characters.
14212 If no l length modifier is present, characters from the input field are
14213 converted as if by repeated calls to the wcrtomb function, with the
14214 conversion state described by an mbstate_t object initialized to zero
14215 before the first wide character is converted. The corresponding argument
14216 shall be a pointer to the initial element of a character array large enough to
14217 accept the sequence and a terminating null character, which will be added
14219 If an l length modifier is present, the corresponding argument shall be a
14220 pointer to the initial element of an array of wchar_t large enough to accept
14224 the sequence and the terminating null wide character, which will be added
14226 [ Matches a nonempty sequence of wide characters from a set of expected
14227 characters (the scanset).
14228 If no l length modifier is present, characters from the input field are
14229 converted as if by repeated calls to the wcrtomb function, with the
14230 conversion state described by an mbstate_t object initialized to zero
14231 before the first wide character is converted. The corresponding argument
14232 shall be a pointer to the initial element of a character array large enough to
14233 accept the sequence and a terminating null character, which will be added
14235 If an l length modifier is present, the corresponding argument shall be a
14236 pointer to the initial element of an array of wchar_t large enough to accept
14237 the sequence and the terminating null wide character, which will be added
14239 The conversion specifier includes all subsequent wide characters in the
14240 format string, up to and including the matching right bracket (]). The wide
14241 characters between the brackets (the scanlist) compose the scanset, unless the
14242 wide character after the left bracket is a circumflex (^), in which case the
14243 scanset contains all wide characters that do not appear in the scanlist between
14244 the circumflex and the right bracket. If the conversion specifier begins with
14245 [] or [^], the right bracket wide character is in the scanlist and the next
14246 following right bracket wide character is the matching right bracket that ends
14247 the specification; otherwise the first following right bracket wide character is
14248 the one that ends the specification. If a - wide character is in the scanlist and
14249 is not the first, nor the second where the first wide character is a ^, nor the
14250 last character, the behavior is implementation-defined.
14251 p Matches an implementation-defined set of sequences, which should be the
14252 same as the set of sequences that may be produced by the %p conversion of
14253 the fwprintf function. The corresponding argument shall be a pointer to a
14254 pointer to void. The input item is converted to a pointer value in an
14255 implementation-defined manner. If the input item is a value converted earlier
14256 during the same program execution, the pointer that results shall compare
14257 equal to that value; otherwise the behavior of the %p conversion is undefined.
14258 n No input is consumed. The corresponding argument shall be a pointer to
14259 signed integer into which is to be written the number of wide characters read
14260 from the input stream so far by this call to the fwscanf function. Execution
14261 of a %n directive does not increment the assignment count returned at the
14262 completion of execution of the fwscanf function. No argument is
14265 converted, but one is consumed. If the conversion specification includes an
14266 assignment-suppressing wide character or a field width, the behavior is
14268 % Matches a single % wide character; no conversion or assignment occurs. The
14269 complete conversion specification shall be %%.
14270 13 If a conversion specification is invalid, the behavior is undefined.290)
14271 14 The conversion specifiers A, E, F, G, and X are also valid and behave the same as,
14272 respectively, a, e, f, g, and x.
14273 15 Trailing white space (including new-line wide characters) is left unread unless matched
14274 by a directive. The success of literal matches and suppressed assignments is not directly
14275 determinable other than via the %n directive.
14277 16 The fwscanf function returns the value of the macro EOF if an input failure occurs
14278 before any conversion. Otherwise, the function returns the number of input items
14279 assigned, which can be fewer than provided for, or even zero, in the event of an early
14281 17 EXAMPLE 1 The call:
14285 int n, i; float x; wchar_t name[50];
14286 n = fwscanf(stdin, L"%d%f%ls", &i, &x, name);
14287 with the input line:
14288 25 54.32E-1 thompson
14289 will assign to n the value 3, to i the value 25, to x the value 5.432, and to name the sequence
14292 18 EXAMPLE 2 The call:
14296 int i; float x; double y;
14297 fwscanf(stdin, L"%2d%f%*d %lf", &i, &x, &y);
14300 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
14301 56.0. The next wide character read from the input stream will be a.
14304 290) See ''future library directions'' (7.26.12).
14308 Forward references: the wcstod, wcstof, and wcstold functions (7.24.4.1.1), the
14309 wcstol, wcstoll, wcstoul, and wcstoull functions (7.24.4.1.2), the wcrtomb
14310 function (7.24.6.3.3).
14311 7.24.2.3 The swprintf function
14313 1 #include <wchar.h>
14314 int swprintf(wchar_t * restrict s,
14316 const wchar_t * restrict format, ...);
14318 2 The swprintf function is equivalent to fwprintf, except that the argument s
14319 specifies an array of wide characters into which the generated output is to be written,
14320 rather than written to a stream. No more than n wide characters are written, including a
14321 terminating null wide character, which is always added (unless n is zero).
14323 3 The swprintf function returns the number of wide characters written in the array, not
14324 counting the terminating null wide character, or a negative value if an encoding error
14325 occurred or if n or more wide characters were requested to be written.
14326 7.24.2.4 The swscanf function
14328 1 #include <wchar.h>
14329 int swscanf(const wchar_t * restrict s,
14330 const wchar_t * restrict format, ...);
14332 2 The swscanf function is equivalent to fwscanf, except that the argument s specifies a
14333 wide string from which the input is to be obtained, rather than from a stream. Reaching
14334 the end of the wide string is equivalent to encountering end-of-file for the fwscanf
14337 3 The swscanf function returns the value of the macro EOF if an input failure occurs
14338 before any conversion. Otherwise, the swscanf function returns the number of input
14339 items assigned, which can be fewer than provided for, or even zero, in the event of an
14340 early matching failure.
14347 7.24.2.5 The vfwprintf function
14349 1 #include <stdarg.h>
14352 int vfwprintf(FILE * restrict stream,
14353 const wchar_t * restrict format,
14356 2 The vfwprintf function is equivalent to fwprintf, with the variable argument list
14357 replaced by arg, which shall have been initialized by the va_start macro (and
14358 possibly subsequent va_arg calls). The vfwprintf function does not invoke the
14361 3 The vfwprintf function returns the number of wide characters transmitted, or a
14362 negative value if an output or encoding error occurred.
14363 4 EXAMPLE The following shows the use of the vfwprintf function in a general error-reporting
14365 #include <stdarg.h>
14368 void error(char *function_name, wchar_t *format, ...)
14371 va_start(args, format);
14372 // print out name of function causing error
14373 fwprintf(stderr, L"ERROR in %s: ", function_name);
14374 // print out remainder of message
14375 vfwprintf(stderr, format, args);
14382 291) As the functions vfwprintf, vswprintf, vfwscanf, vwprintf, vwscanf, and vswscanf
14383 invoke the va_arg macro, the value of arg after the return is indeterminate.
14387 7.24.2.6 The vfwscanf function
14389 1 #include <stdarg.h>
14392 int vfwscanf(FILE * restrict stream,
14393 const wchar_t * restrict format,
14396 2 The vfwscanf function is equivalent to fwscanf, with the variable argument list
14397 replaced by arg, which shall have been initialized by the va_start macro (and
14398 possibly subsequent va_arg calls). The vfwscanf function does not invoke the
14401 3 The vfwscanf function returns the value of the macro EOF if an input failure occurs
14402 before any conversion. Otherwise, the vfwscanf function returns the number of input
14403 items assigned, which can be fewer than provided for, or even zero, in the event of an
14404 early matching failure.
14405 7.24.2.7 The vswprintf function
14407 1 #include <stdarg.h>
14409 int vswprintf(wchar_t * restrict s,
14411 const wchar_t * restrict format,
14414 2 The vswprintf function is equivalent to swprintf, with the variable argument list
14415 replaced by arg, which shall have been initialized by the va_start macro (and
14416 possibly subsequent va_arg calls). The vswprintf function does not invoke the
14419 3 The vswprintf function returns the number of wide characters written in the array, not
14420 counting the terminating null wide character, or a negative value if an encoding error
14421 occurred or if n or more wide characters were requested to be generated.
14426 7.24.2.8 The vswscanf function
14428 1 #include <stdarg.h>
14430 int vswscanf(const wchar_t * restrict s,
14431 const wchar_t * restrict format,
14434 2 The vswscanf function is equivalent to swscanf, with the variable argument list
14435 replaced by arg, which shall have been initialized by the va_start macro (and
14436 possibly subsequent va_arg calls). The vswscanf function does not invoke the
14439 3 The vswscanf function returns the value of the macro EOF if an input failure occurs
14440 before any conversion. Otherwise, the vswscanf function returns the number of input
14441 items assigned, which can be fewer than provided for, or even zero, in the event of an
14442 early matching failure.
14443 7.24.2.9 The vwprintf function
14445 1 #include <stdarg.h>
14447 int vwprintf(const wchar_t * restrict format,
14450 2 The vwprintf function is equivalent to wprintf, with the variable argument list
14451 replaced by arg, which shall have been initialized by the va_start macro (and
14452 possibly subsequent va_arg calls). The vwprintf function does not invoke the
14455 3 The vwprintf function returns the number of wide characters transmitted, or a negative
14456 value if an output or encoding error occurred.
14463 7.24.2.10 The vwscanf function
14465 1 #include <stdarg.h>
14467 int vwscanf(const wchar_t * restrict format,
14470 2 The vwscanf function is equivalent to wscanf, with the variable argument list
14471 replaced by arg, which shall have been initialized by the va_start macro (and
14472 possibly subsequent va_arg calls). The vwscanf function does not invoke the
14475 3 The vwscanf function returns the value of the macro EOF if an input failure occurs
14476 before any conversion. Otherwise, the vwscanf function returns the number of input
14477 items assigned, which can be fewer than provided for, or even zero, in the event of an
14478 early matching failure.
14479 7.24.2.11 The wprintf function
14481 1 #include <wchar.h>
14482 int wprintf(const wchar_t * restrict format, ...);
14484 2 The wprintf function is equivalent to fwprintf with the argument stdout
14485 interposed before the arguments to wprintf.
14487 3 The wprintf function returns the number of wide characters transmitted, or a negative
14488 value if an output or encoding error occurred.
14489 7.24.2.12 The wscanf function
14491 1 #include <wchar.h>
14492 int wscanf(const wchar_t * restrict format, ...);
14494 2 The wscanf function is equivalent to fwscanf with the argument stdin interposed
14495 before the arguments to wscanf.
14501 3 The wscanf function returns the value of the macro EOF if an input failure occurs
14502 before any conversion. Otherwise, the wscanf function returns the number of input
14503 items assigned, which can be fewer than provided for, or even zero, in the event of an
14504 early matching failure.
14505 7.24.3 Wide character input/output functions
14506 7.24.3.1 The fgetwc function
14508 1 #include <stdio.h>
14510 wint_t fgetwc(FILE *stream);
14512 2 If the end-of-file indicator for the input stream pointed to by stream is not set and a
14513 next wide character is present, the fgetwc function obtains that wide character as a
14514 wchar_t converted to a wint_t and advances the associated file position indicator for
14515 the stream (if defined).
14517 3 If the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-
14518 of-file indicator for the stream is set and the fgetwc function returns WEOF. Otherwise,
14519 the fgetwc function returns the next wide character from the input stream pointed to by
14520 stream. If a read error occurs, the error indicator for the stream is set and the fgetwc
14521 function returns WEOF. If an encoding error occurs (including too few bytes), the value of
14522 the macro EILSEQ is stored in errno and the fgetwc function returns WEOF.292)
14523 7.24.3.2 The fgetws function
14525 1 #include <stdio.h>
14527 wchar_t *fgetws(wchar_t * restrict s,
14528 int n, FILE * restrict stream);
14530 2 The fgetws function reads at most one less than the number of wide characters
14531 specified by n from the stream pointed to by stream into the array pointed to by s. No
14534 292) An end-of-file and a read error can be distinguished by use of the feof and ferror functions.
14535 Also, errno will be set to EILSEQ by input/output functions only if an encoding error occurs.
14539 additional wide characters are read after a new-line wide character (which is retained) or
14540 after end-of-file. A null wide character is written immediately after the last wide
14541 character read into the array.
14543 3 The fgetws function returns s if successful. If end-of-file is encountered and no
14544 characters have been read into the array, the contents of the array remain unchanged and a
14545 null pointer is returned. If a read or encoding error occurs during the operation, the array
14546 contents are indeterminate and a null pointer is returned.
14547 7.24.3.3 The fputwc function
14549 1 #include <stdio.h>
14551 wint_t fputwc(wchar_t c, FILE *stream);
14553 2 The fputwc function writes the wide character specified by c to the output stream
14554 pointed to by stream, at the position indicated by the associated file position indicator
14555 for the stream (if defined), and advances the indicator appropriately. If the file cannot
14556 support positioning requests, or if the stream was opened with append mode, the
14557 character is appended to the output stream.
14559 3 The fputwc function returns the wide character written. If a write error occurs, the
14560 error indicator for the stream is set and fputwc returns WEOF. If an encoding error
14561 occurs, the value of the macro EILSEQ is stored in errno and fputwc returns WEOF.
14562 7.24.3.4 The fputws function
14564 1 #include <stdio.h>
14566 int fputws(const wchar_t * restrict s,
14567 FILE * restrict stream);
14569 2 The fputws function writes the wide string pointed to by s to the stream pointed to by
14570 stream. The terminating null wide character is not written.
14572 3 The fputws function returns EOF if a write or encoding error occurs; otherwise, it
14573 returns a nonnegative value.
14577 7.24.3.5 The fwide function
14579 1 #include <stdio.h>
14581 int fwide(FILE *stream, int mode);
14583 2 The fwide function determines the orientation of the stream pointed to by stream. If
14584 mode is greater than zero, the function first attempts to make the stream wide oriented. If
14585 mode is less than zero, the function first attempts to make the stream byte oriented.293)
14586 Otherwise, mode is zero and the function does not alter the orientation of the stream.
14588 3 The fwide function returns a value greater than zero if, after the call, the stream has
14589 wide orientation, a value less than zero if the stream has byte orientation, or zero if the
14590 stream has no orientation.
14591 7.24.3.6 The getwc function
14593 1 #include <stdio.h>
14595 wint_t getwc(FILE *stream);
14597 2 The getwc function is equivalent to fgetwc, except that if it is implemented as a
14598 macro, it may evaluate stream more than once, so the argument should never be an
14599 expression with side effects.
14601 3 The getwc function returns the next wide character from the input stream pointed to by
14603 7.24.3.7 The getwchar function
14605 1 #include <wchar.h>
14606 wint_t getwchar(void);
14611 293) If the orientation of the stream has already been determined, fwide does not change it.
14616 2 The getwchar function is equivalent to getwc with the argument stdin.
14618 3 The getwchar function returns the next wide character from the input stream pointed to
14620 7.24.3.8 The putwc function
14622 1 #include <stdio.h>
14624 wint_t putwc(wchar_t c, FILE *stream);
14626 2 The putwc function is equivalent to fputwc, except that if it is implemented as a
14627 macro, it may evaluate stream more than once, so that argument should never be an
14628 expression with side effects.
14630 3 The putwc function returns the wide character written, or WEOF.
14631 7.24.3.9 The putwchar function
14633 1 #include <wchar.h>
14634 wint_t putwchar(wchar_t c);
14636 2 The putwchar function is equivalent to putwc with the second argument stdout.
14638 3 The putwchar function returns the character written, or WEOF.
14639 7.24.3.10 The ungetwc function
14641 1 #include <stdio.h>
14643 wint_t ungetwc(wint_t c, FILE *stream);
14645 2 The ungetwc function pushes the wide character specified by c back onto the input
14646 stream pointed to by stream. Pushed-back wide characters will be returned by
14647 subsequent reads on that stream in the reverse order of their pushing. A successful
14651 intervening call (with the stream pointed to by stream) to a file positioning function
14652 (fseek, fsetpos, or rewind) discards any pushed-back wide characters for the
14653 stream. The external storage corresponding to the stream is unchanged.
14654 3 One wide character of pushback is guaranteed, even if the call to the ungetwc function
14655 follows just after a call to a formatted wide character input function fwscanf,
14656 vfwscanf, vwscanf, or wscanf. If the ungetwc function is called too many times
14657 on the same stream without an intervening read or file positioning operation on that
14658 stream, the operation may fail.
14659 4 If the value of c equals that of the macro WEOF, the operation fails and the input stream is
14661 5 A successful call to the ungetwc function clears the end-of-file indicator for the stream.
14662 The value of the file position indicator for the stream after reading or discarding all
14663 pushed-back wide characters is the same as it was before the wide characters were pushed
14664 back. For a text or binary stream, the value of its file position indicator after a successful
14665 call to the ungetwc function is unspecified until all pushed-back wide characters are
14668 6 The ungetwc function returns the wide character pushed back, or WEOF if the operation
14670 7.24.4 General wide string utilities
14671 1 The header <wchar.h> declares a number of functions useful for wide string
14672 manipulation. Various methods are used for determining the lengths of the arrays, but in
14673 all cases a wchar_t * argument points to the initial (lowest addressed) element of the
14674 array. If an array is accessed beyond the end of an object, the behavior is undefined.
14675 2 Where an argument declared as size_t n determines the length of the array for a
14676 function, n can have the value zero on a call to that function. Unless explicitly stated
14677 otherwise in the description of a particular function in this subclause, pointer arguments
14678 on such a call shall still have valid values, as described in 7.1.4. On such a call, a
14679 function that locates a wide character finds no occurrence, a function that compares two
14680 wide character sequences returns zero, and a function that copies wide characters copies
14681 zero wide characters.
14688 7.24.4.1 Wide string numeric conversion functions
14689 7.24.4.1.1 The wcstod, wcstof, and wcstold functions
14691 1 #include <wchar.h>
14692 double wcstod(const wchar_t * restrict nptr,
14693 wchar_t ** restrict endptr);
14694 float wcstof(const wchar_t * restrict nptr,
14695 wchar_t ** restrict endptr);
14696 long double wcstold(const wchar_t * restrict nptr,
14697 wchar_t ** restrict endptr);
14699 2 The wcstod, wcstof, and wcstold functions convert the initial portion of the wide
14700 string pointed to by nptr to double, float, and long double representation,
14701 respectively. First, they decompose the input string into three parts: an initial, possibly
14702 empty, sequence of white-space wide characters (as specified by the iswspace
14703 function), a subject sequence resembling a floating-point constant or representing an
14704 infinity or NaN; and a final wide string of one or more unrecognized wide characters,
14705 including the terminating null wide character of the input wide string. Then, they attempt
14706 to convert the subject sequence to a floating-point number, and return the result.
14707 3 The expected form of the subject sequence is an optional plus or minus sign, then one of
14709 -- a nonempty sequence of decimal digits optionally containing a decimal-point wide
14710 character, then an optional exponent part as defined for the corresponding single-byte
14711 characters in 6.4.4.2;
14712 -- a 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing a
14713 decimal-point wide character, then an optional binary exponent part as defined in
14715 -- INF or INFINITY, or any other wide string equivalent except for case
14716 -- NAN or NAN(n-wchar-sequenceopt), or any other wide string equivalent except for
14717 case in the NAN part, where:
14721 n-wchar-sequence digit
14722 n-wchar-sequence nondigit
14723 The subject sequence is defined as the longest initial subsequence of the input wide
14724 string, starting with the first non-white-space wide character, that is of the expected form.
14727 The subject sequence contains no wide characters if the input wide string is not of the
14729 4 If the subject sequence has the expected form for a floating-point number, the sequence of
14730 wide characters starting with the first digit or the decimal-point wide character
14731 (whichever occurs first) is interpreted as a floating constant according to the rules of
14732 6.4.4.2, except that the decimal-point wide character is used in place of a period, and that
14733 if neither an exponent part nor a decimal-point wide character appears in a decimal
14734 floating point number, or if a binary exponent part does not appear in a hexadecimal
14735 floating point number, an exponent part of the appropriate type with value zero is
14736 assumed to follow the last digit in the string. If the subject sequence begins with a minus
14737 sign, the sequence is interpreted as negated.294) A wide character sequence INF or
14738 INFINITY is interpreted as an infinity, if representable in the return type, else like a
14739 floating constant that is too large for the range of the return type. A wide character
14740 sequence NAN or NAN(n-wchar-sequenceopt) is interpreted as a quiet NaN, if supported
14741 in the return type, else like a subject sequence part that does not have the expected form;
14742 the meaning of the n-wchar sequences is implementation-defined.295) A pointer to the
14743 final wide string is stored in the object pointed to by endptr, provided that endptr is
14744 not a null pointer.
14745 5 If the subject sequence has the hexadecimal form and FLT_RADIX is a power of 2, the
14746 value resulting from the conversion is correctly rounded.
14747 6 In other than the "C" locale, additional locale-specific subject sequence forms may be
14749 7 If the subject sequence is empty or does not have the expected form, no conversion is
14750 performed; the value of nptr is stored in the object pointed to by endptr, provided
14751 that endptr is not a null pointer.
14752 Recommended practice
14753 8 If the subject sequence has the hexadecimal form, FLT_RADIX is not a power of 2, and
14754 the result is not exactly representable, the result should be one of the two numbers in the
14755 appropriate internal format that are adjacent to the hexadecimal floating source value,
14756 with the extra stipulation that the error should have a correct sign for the current rounding
14761 294) It is unspecified whether a minus-signed sequence is converted to a negative number directly or by
14762 negating the value resulting from converting the corresponding unsigned sequence (see F.5); the two
14763 methods may yield different results if rounding is toward positive or negative infinity. In either case,
14764 the functions honor the sign of zero if floating-point arithmetic supports signed zeros.
14765 295) An implementation may use the n-wchar sequence to determine extra information to be represented in
14766 the NaN's significand.
14770 9 If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in
14771 <float.h>) significant digits, the result should be correctly rounded. If the subject
14772 sequence D has the decimal form and more than DECIMAL_DIG significant digits,
14773 consider the two bounding, adjacent decimal strings L and U, both having
14774 DECIMAL_DIG significant digits, such that the values of L, D, and U satisfy L <= D <= U.
14775 The result should be one of the (equal or adjacent) values that would be obtained by
14776 correctly rounding L and U according to the current rounding direction, with the extra
14777 stipulation that the error with respect to D should have a correct sign for the current
14778 rounding direction.296)
14780 10 The functions return the converted value, if any. If no conversion could be performed,
14781 zero is returned. If the correct value is outside the range of representable values, plus or
14782 minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the return
14783 type and sign of the value), and the value of the macro ERANGE is stored in errno. If
14784 the result underflows (7.12.1), the functions return a value whose magnitude is no greater
14785 than the smallest normalized positive number in the return type; whether errno acquires
14786 the value ERANGE is implementation-defined.
14791 296) DECIMAL_DIG, defined in <float.h>, should be sufficiently large that L and U will usually round
14792 to the same internal floating value, but if not will round to adjacent values.
14796 7.24.4.1.2 The wcstol, wcstoll, wcstoul, and wcstoull functions
14798 1 #include <wchar.h>
14800 const wchar_t * restrict nptr,
14801 wchar_t ** restrict endptr,
14803 long long int wcstoll(
14804 const wchar_t * restrict nptr,
14805 wchar_t ** restrict endptr,
14807 unsigned long int wcstoul(
14808 const wchar_t * restrict nptr,
14809 wchar_t ** restrict endptr,
14811 unsigned long long int wcstoull(
14812 const wchar_t * restrict nptr,
14813 wchar_t ** restrict endptr,
14816 2 The wcstol, wcstoll, wcstoul, and wcstoull functions convert the initial
14817 portion of the wide string pointed to by nptr to long int, long long int,
14818 unsigned long int, and unsigned long long int representation,
14819 respectively. First, they decompose the input string into three parts: an initial, possibly
14820 empty, sequence of white-space wide characters (as specified by the iswspace
14821 function), a subject sequence resembling an integer represented in some radix determined
14822 by the value of base, and a final wide string of one or more unrecognized wide
14823 characters, including the terminating null wide character of the input wide string. Then,
14824 they attempt to convert the subject sequence to an integer, and return the result.
14825 3 If the value of base is zero, the expected form of the subject sequence is that of an
14826 integer constant as described for the corresponding single-byte characters in 6.4.4.1,
14827 optionally preceded by a plus or minus sign, but not including an integer suffix. If the
14828 value of base is between 2 and 36 (inclusive), the expected form of the subject sequence
14829 is a sequence of letters and digits representing an integer with the radix specified by
14830 base, optionally preceded by a plus or minus sign, but not including an integer suffix.
14831 The letters from a (or A) through z (or Z) are ascribed the values 10 through 35; only
14832 letters and digits whose ascribed values are less than that of base are permitted. If the
14833 value of base is 16, the wide characters 0x or 0X may optionally precede the sequence
14834 of letters and digits, following the sign if present.
14838 4 The subject sequence is defined as the longest initial subsequence of the input wide
14839 string, starting with the first non-white-space wide character, that is of the expected form.
14840 The subject sequence contains no wide characters if the input wide string is empty or
14841 consists entirely of white space, or if the first non-white-space wide character is other
14842 than a sign or a permissible letter or digit.
14843 5 If the subject sequence has the expected form and the value of base is zero, the sequence
14844 of wide characters starting with the first digit is interpreted as an integer constant
14845 according to the rules of 6.4.4.1. If the subject sequence has the expected form and the
14846 value of base is between 2 and 36, it is used as the base for conversion, ascribing to each
14847 letter its value as given above. If the subject sequence begins with a minus sign, the value
14848 resulting from the conversion is negated (in the return type). A pointer to the final wide
14849 string is stored in the object pointed to by endptr, provided that endptr is not a null
14851 6 In other than the "C" locale, additional locale-specific subject sequence forms may be
14853 7 If the subject sequence is empty or does not have the expected form, no conversion is
14854 performed; the value of nptr is stored in the object pointed to by endptr, provided
14855 that endptr is not a null pointer.
14857 8 The wcstol, wcstoll, wcstoul, and wcstoull functions return the converted
14858 value, if any. If no conversion could be performed, zero is returned. If the correct value
14859 is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
14860 LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type
14861 sign of the value, if any), and the value of the macro ERANGE is stored in errno.
14862 7.24.4.2 Wide string copying functions
14863 7.24.4.2.1 The wcscpy function
14865 1 #include <wchar.h>
14866 wchar_t *wcscpy(wchar_t * restrict s1,
14867 const wchar_t * restrict s2);
14869 2 The wcscpy function copies the wide string pointed to by s2 (including the terminating
14870 null wide character) into the array pointed to by s1.
14872 3 The wcscpy function returns the value of s1.
14877 7.24.4.2.2 The wcsncpy function
14879 1 #include <wchar.h>
14880 wchar_t *wcsncpy(wchar_t * restrict s1,
14881 const wchar_t * restrict s2,
14884 2 The wcsncpy function copies not more than n wide characters (those that follow a null
14885 wide character are not copied) from the array pointed to by s2 to the array pointed to by
14887 3 If the array pointed to by s2 is a wide string that is shorter than n wide characters, null
14888 wide characters are appended to the copy in the array pointed to by s1, until n wide
14889 characters in all have been written.
14891 4 The wcsncpy function returns the value of s1.
14892 7.24.4.2.3 The wmemcpy function
14894 1 #include <wchar.h>
14895 wchar_t *wmemcpy(wchar_t * restrict s1,
14896 const wchar_t * restrict s2,
14899 2 The wmemcpy function copies n wide characters from the object pointed to by s2 to the
14900 object pointed to by s1.
14902 3 The wmemcpy function returns the value of s1.
14907 297) Thus, if there is no null wide character in the first n wide characters of the array pointed to by s2, the
14908 result will not be null-terminated.
14912 7.24.4.2.4 The wmemmove function
14914 1 #include <wchar.h>
14915 wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2,
14918 2 The wmemmove function copies n wide characters from the object pointed to by s2 to
14919 the object pointed to by s1. Copying takes place as if the n wide characters from the
14920 object pointed to by s2 are first copied into a temporary array of n wide characters that
14921 does not overlap the objects pointed to by s1 or s2, and then the n wide characters from
14922 the temporary array are copied into the object pointed to by s1.
14924 3 The wmemmove function returns the value of s1.
14925 7.24.4.3 Wide string concatenation functions
14926 7.24.4.3.1 The wcscat function
14928 1 #include <wchar.h>
14929 wchar_t *wcscat(wchar_t * restrict s1,
14930 const wchar_t * restrict s2);
14932 2 The wcscat function appends a copy of the wide string pointed to by s2 (including the
14933 terminating null wide character) to the end of the wide string pointed to by s1. The initial
14934 wide character of s2 overwrites the null wide character at the end of s1.
14936 3 The wcscat function returns the value of s1.
14937 7.24.4.3.2 The wcsncat function
14939 1 #include <wchar.h>
14940 wchar_t *wcsncat(wchar_t * restrict s1,
14941 const wchar_t * restrict s2,
14944 2 The wcsncat function appends not more than n wide characters (a null wide character
14945 and those that follow it are not appended) from the array pointed to by s2 to the end of
14949 the wide string pointed to by s1. The initial wide character of s2 overwrites the null
14950 wide character at the end of s1. A terminating null wide character is always appended to
14953 3 The wcsncat function returns the value of s1.
14954 7.24.4.4 Wide string comparison functions
14955 1 Unless explicitly stated otherwise, the functions described in this subclause order two
14956 wide characters the same way as two integers of the underlying integer type designated
14958 7.24.4.4.1 The wcscmp function
14960 1 #include <wchar.h>
14961 int wcscmp(const wchar_t *s1, const wchar_t *s2);
14963 2 The wcscmp function compares the wide string pointed to by s1 to the wide string
14966 3 The wcscmp function returns an integer greater than, equal to, or less than zero,
14967 accordingly as the wide string pointed to by s1 is greater than, equal to, or less than the
14968 wide string pointed to by s2.
14969 7.24.4.4.2 The wcscoll function
14971 1 #include <wchar.h>
14972 int wcscoll(const wchar_t *s1, const wchar_t *s2);
14974 2 The wcscoll function compares the wide string pointed to by s1 to the wide string
14975 pointed to by s2, both interpreted as appropriate to the LC_COLLATE category of the
14978 3 The wcscoll function returns an integer greater than, equal to, or less than zero,
14979 accordingly as the wide string pointed to by s1 is greater than, equal to, or less than the
14982 298) Thus, the maximum number of wide characters that can end up in the array pointed to by s1 is
14987 wide string pointed to by s2 when both are interpreted as appropriate to the current
14989 7.24.4.4.3 The wcsncmp function
14991 1 #include <wchar.h>
14992 int wcsncmp(const wchar_t *s1, const wchar_t *s2,
14995 2 The wcsncmp function compares not more than n wide characters (those that follow a
14996 null wide character are not compared) from the array pointed to by s1 to the array
14999 3 The wcsncmp function returns an integer greater than, equal to, or less than zero,
15000 accordingly as the possibly null-terminated array pointed to by s1 is greater than, equal
15001 to, or less than the possibly null-terminated array pointed to by s2.
15002 7.24.4.4.4 The wcsxfrm function
15004 1 #include <wchar.h>
15005 size_t wcsxfrm(wchar_t * restrict s1,
15006 const wchar_t * restrict s2,
15009 2 The wcsxfrm function transforms the wide string pointed to by s2 and places the
15010 resulting wide string into the array pointed to by s1. The transformation is such that if
15011 the wcscmp function is applied to two transformed wide strings, it returns a value greater
15012 than, equal to, or less than zero, corresponding to the result of the wcscoll function
15013 applied to the same two original wide strings. No more than n wide characters are placed
15014 into the resulting array pointed to by s1, including the terminating null wide character. If
15015 n is zero, s1 is permitted to be a null pointer.
15017 3 The wcsxfrm function returns the length of the transformed wide string (not including
15018 the terminating null wide character). If the value returned is n or greater, the contents of
15019 the array pointed to by s1 are indeterminate.
15020 4 EXAMPLE The value of the following expression is the length of the array needed to hold the
15021 transformation of the wide string pointed to by s:
15026 1 + wcsxfrm(NULL, s, 0)
15028 7.24.4.4.5 The wmemcmp function
15030 1 #include <wchar.h>
15031 int wmemcmp(const wchar_t *s1, const wchar_t *s2,
15034 2 The wmemcmp function compares the first n wide characters of the object pointed to by
15035 s1 to the first n wide characters of the object pointed to by s2.
15037 3 The wmemcmp function returns an integer greater than, equal to, or less than zero,
15038 accordingly as the object pointed to by s1 is greater than, equal to, or less than the object
15040 7.24.4.5 Wide string search functions
15041 7.24.4.5.1 The wcschr function
15043 1 #include <wchar.h>
15044 wchar_t *wcschr(const wchar_t *s, wchar_t c);
15046 2 The wcschr function locates the first occurrence of c in the wide string pointed to by s.
15047 The terminating null wide character is considered to be part of the wide string.
15049 3 The wcschr function returns a pointer to the located wide character, or a null pointer if
15050 the wide character does not occur in the wide string.
15051 7.24.4.5.2 The wcscspn function
15053 1 #include <wchar.h>
15054 size_t wcscspn(const wchar_t *s1, const wchar_t *s2);
15056 2 The wcscspn function computes the length of the maximum initial segment of the wide
15057 string pointed to by s1 which consists entirely of wide characters not from the wide
15058 string pointed to by s2.
15065 3 The wcscspn function returns the length of the segment.
15066 7.24.4.5.3 The wcspbrk function
15068 1 #include <wchar.h>
15069 wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2);
15071 2 The wcspbrk function locates the first occurrence in the wide string pointed to by s1 of
15072 any wide character from the wide string pointed to by s2.
15074 3 The wcspbrk function returns a pointer to the wide character in s1, or a null pointer if
15075 no wide character from s2 occurs in s1.
15076 7.24.4.5.4 The wcsrchr function
15078 1 #include <wchar.h>
15079 wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
15081 2 The wcsrchr function locates the last occurrence of c in the wide string pointed to by
15082 s. The terminating null wide character is considered to be part of the wide string.
15084 3 The wcsrchr function returns a pointer to the wide character, or a null pointer if c does
15085 not occur in the wide string.
15086 7.24.4.5.5 The wcsspn function
15088 1 #include <wchar.h>
15089 size_t wcsspn(const wchar_t *s1, const wchar_t *s2);
15091 2 The wcsspn function computes the length of the maximum initial segment of the wide
15092 string pointed to by s1 which consists entirely of wide characters from the wide string
15095 3 The wcsspn function returns the length of the segment.
15100 7.24.4.5.6 The wcsstr function
15102 1 #include <wchar.h>
15103 wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);
15105 2 The wcsstr function locates the first occurrence in the wide string pointed to by s1 of
15106 the sequence of wide characters (excluding the terminating null wide character) in the
15107 wide string pointed to by s2.
15109 3 The wcsstr function returns a pointer to the located wide string, or a null pointer if the
15110 wide string is not found. If s2 points to a wide string with zero length, the function
15112 7.24.4.5.7 The wcstok function
15114 1 #include <wchar.h>
15115 wchar_t *wcstok(wchar_t * restrict s1,
15116 const wchar_t * restrict s2,
15117 wchar_t ** restrict ptr);
15119 2 A sequence of calls to the wcstok function breaks the wide string pointed to by s1 into
15120 a sequence of tokens, each of which is delimited by a wide character from the wide string
15121 pointed to by s2. The third argument points to a caller-provided wchar_t pointer into
15122 which the wcstok function stores information necessary for it to continue scanning the
15124 3 The first call in a sequence has a non-null first argument and stores an initial value in the
15125 object pointed to by ptr. Subsequent calls in the sequence have a null first argument and
15126 the object pointed to by ptr is required to have the value stored by the previous call in
15127 the sequence, which is then updated. The separator wide string pointed to by s2 may be
15128 different from call to call.
15129 4 The first call in the sequence searches the wide string pointed to by s1 for the first wide
15130 character that is not contained in the current separator wide string pointed to by s2. If no
15131 such wide character is found, then there are no tokens in the wide string pointed to by s1
15132 and the wcstok function returns a null pointer. If such a wide character is found, it is
15133 the start of the first token.
15134 5 The wcstok function then searches from there for a wide character that is contained in
15135 the current separator wide string. If no such wide character is found, the current token
15138 extends to the end of the wide string pointed to by s1, and subsequent searches in the
15139 same wide string for a token return a null pointer. If such a wide character is found, it is
15140 overwritten by a null wide character, which terminates the current token.
15141 6 In all cases, the wcstok function stores sufficient information in the pointer pointed to
15142 by ptr so that subsequent calls, with a null pointer for s1 and the unmodified pointer
15143 value for ptr, shall start searching just past the element overwritten by a null wide
15144 character (if any).
15146 7 The wcstok function returns a pointer to the first wide character of a token, or a null
15147 pointer if there is no token.
15150 static wchar_t str1[] = L"?a???b,,,#c";
15151 static wchar_t str2[] = L"\t \t";
15152 wchar_t *t, *ptr1, *ptr2;
15153 t = wcstok(str1, L"?", &ptr1); // t points to the token L"a"
15154 t = wcstok(NULL, L",", &ptr1); // t points to the token L"??b"
15155 t = wcstok(str2, L" \t", &ptr2); // t is a null pointer
15156 t = wcstok(NULL, L"#,", &ptr1); // t points to the token L"c"
15157 t = wcstok(NULL, L"?", &ptr1); // t is a null pointer
15159 7.24.4.5.8 The wmemchr function
15161 1 #include <wchar.h>
15162 wchar_t *wmemchr(const wchar_t *s, wchar_t c,
15165 2 The wmemchr function locates the first occurrence of c in the initial n wide characters of
15166 the object pointed to by s.
15168 3 The wmemchr function returns a pointer to the located wide character, or a null pointer if
15169 the wide character does not occur in the object.
15176 7.24.4.6 Miscellaneous functions
15177 7.24.4.6.1 The wcslen function
15179 1 #include <wchar.h>
15180 size_t wcslen(const wchar_t *s);
15182 2 The wcslen function computes the length of the wide string pointed to by s.
15184 3 The wcslen function returns the number of wide characters that precede the terminating
15185 null wide character.
15186 7.24.4.6.2 The wmemset function
15188 1 #include <wchar.h>
15189 wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);
15191 2 The wmemset function copies the value of c into each of the first n wide characters of
15192 the object pointed to by s.
15194 3 The wmemset function returns the value of s.
15195 7.24.5 Wide character time conversion functions
15196 7.24.5.1 The wcsftime function
15198 1 #include <time.h>
15200 size_t wcsftime(wchar_t * restrict s,
15202 const wchar_t * restrict format,
15203 const struct tm * restrict timeptr);
15205 2 The wcsftime function is equivalent to the strftime function, except that:
15206 -- The argument s points to the initial element of an array of wide characters into which
15207 the generated output is to be placed.
15212 -- The argument maxsize indicates the limiting number of wide characters.
15213 -- The argument format is a wide string and the conversion specifiers are replaced by
15214 corresponding sequences of wide characters.
15215 -- The return value indicates the number of wide characters.
15217 3 If the total number of resulting wide characters including the terminating null wide
15218 character is not more than maxsize, the wcsftime function returns the number of
15219 wide characters placed into the array pointed to by s not including the terminating null
15220 wide character. Otherwise, zero is returned and the contents of the array are
15222 7.24.6 Extended multibyte/wide character conversion utilities
15223 1 The header <wchar.h> declares an extended set of functions useful for conversion
15224 between multibyte characters and wide characters.
15225 2 Most of the following functions -- those that are listed as ''restartable'', 7.24.6.3 and
15226 7.24.6.4 -- take as a last argument a pointer to an object of type mbstate_t that is used
15227 to describe the current conversion state from a particular multibyte character sequence to
15228 a wide character sequence (or the reverse) under the rules of a particular setting for the
15229 LC_CTYPE category of the current locale.
15230 3 The initial conversion state corresponds, for a conversion in either direction, to the
15231 beginning of a new multibyte character in the initial shift state. A zero-valued
15232 mbstate_t object is (at least) one way to describe an initial conversion state. A zero-
15233 valued mbstate_t object can be used to initiate conversion involving any multibyte
15234 character sequence, in any LC_CTYPE category setting. If an mbstate_t object has
15235 been altered by any of the functions described in this subclause, and is then used with a
15236 different multibyte character sequence, or in the other conversion direction, or with a
15237 different LC_CTYPE category setting than on earlier function calls, the behavior is
15239 4 On entry, each function takes the described conversion state (either internal or pointed to
15240 by an argument) as current. The conversion state described by the pointed-to object is
15241 altered as needed to track the shift state, and the position within a multibyte character, for
15242 the associated multibyte character sequence.
15247 299) Thus, a particular mbstate_t object can be used, for example, with both the mbrtowc and
15248 mbsrtowcs functions as long as they are used to step sequentially through the same multibyte
15253 7.24.6.1 Single-byte/wide character conversion functions
15254 7.24.6.1.1 The btowc function
15256 1 #include <stdio.h>
15258 wint_t btowc(int c);
15260 2 The btowc function determines whether c constitutes a valid single-byte character in the
15261 initial shift state.
15263 3 The btowc function returns WEOF if c has the value EOF or if (unsigned char)c
15264 does not constitute a valid single-byte character in the initial shift state. Otherwise, it
15265 returns the wide character representation of that character.
15266 7.24.6.1.2 The wctob function
15268 1 #include <stdio.h>
15270 int wctob(wint_t c);
15272 2 The wctob function determines whether c corresponds to a member of the extended
15273 character set whose multibyte character representation is a single byte when in the initial
15276 3 The wctob function returns EOF if c does not correspond to a multibyte character with
15277 length one in the initial shift state. Otherwise, it returns the single-byte representation of
15278 that character as an unsigned char converted to an int.
15279 7.24.6.2 Conversion state functions
15280 7.24.6.2.1 The mbsinit function
15282 1 #include <wchar.h>
15283 int mbsinit(const mbstate_t *ps);
15285 2 If ps is not a null pointer, the mbsinit function determines whether the pointed-to
15286 mbstate_t object describes an initial conversion state.
15290 3 The mbsinit function returns nonzero if ps is a null pointer or if the pointed-to object
15291 describes an initial conversion state; otherwise, it returns zero.
15292 7.24.6.3 Restartable multibyte/wide character conversion functions
15293 1 These functions differ from the corresponding multibyte character functions of 7.20.7
15294 (mblen, mbtowc, and wctomb) in that they have an extra parameter, ps, of type
15295 pointer to mbstate_t that points to an object that can completely describe the current
15296 conversion state of the associated multibyte character sequence. If ps is a null pointer,
15297 each function uses its own internal mbstate_t object instead, which is initialized at
15298 program startup to the initial conversion state. The implementation behaves as if no
15299 library function calls these functions with a null pointer for ps.
15300 2 Also unlike their corresponding functions, the return value does not represent whether the
15301 encoding is state-dependent.
15302 7.24.6.3.1 The mbrlen function
15304 1 #include <wchar.h>
15305 size_t mbrlen(const char * restrict s,
15307 mbstate_t * restrict ps);
15309 2 The mbrlen function is equivalent to the call:
15310 mbrtowc(NULL, s, n, ps != NULL ? ps : &internal)
15311 where internal is the mbstate_t object for the mbrlen function, except that the
15312 expression designated by ps is evaluated only once.
15314 3 The mbrlen function returns a value between zero and n, inclusive, (size_t)(-2),
15316 Forward references: the mbrtowc function (7.24.6.3.2).
15323 7.24.6.3.2 The mbrtowc function
15325 1 #include <wchar.h>
15326 size_t mbrtowc(wchar_t * restrict pwc,
15327 const char * restrict s,
15329 mbstate_t * restrict ps);
15331 2 If s is a null pointer, the mbrtowc function is equivalent to the call:
15332 mbrtowc(NULL, "", 1, ps)
15333 In this case, the values of the parameters pwc and n are ignored.
15334 3 If s is not a null pointer, the mbrtowc function inspects at most n bytes beginning with
15335 the byte pointed to by s to determine the number of bytes needed to complete the next
15336 multibyte character (including any shift sequences). If the function determines that the
15337 next multibyte character is complete and valid, it determines the value of the
15338 corresponding wide character and then, if pwc is not a null pointer, stores that value in
15339 the object pointed to by pwc. If the corresponding wide character is the null wide
15340 character, the resulting state described is the initial conversion state.
15342 4 The mbrtowc function returns the first of the following that applies (given the current
15344 0 if the next n or fewer bytes complete the multibyte character that
15345 corresponds to the null wide character (which is the value stored).
15346 between 1 and n inclusive if the next n or fewer bytes complete a valid multibyte
15347 character (which is the value stored); the value returned is the number
15348 of bytes that complete the multibyte character.
15349 (size_t)(-2) if the next n bytes contribute to an incomplete (but potentially valid)
15350 multibyte character, and all n bytes have been processed (no value is
15352 (size_t)(-1) if an encoding error occurs, in which case the next n or fewer bytes
15353 do not contribute to a complete and valid multibyte character (no
15354 value is stored); the value of the macro EILSEQ is stored in errno,
15355 and the conversion state is unspecified.
15357 300) When n has at least the value of the MB_CUR_MAX macro, this case can only occur if s points at a
15358 sequence of redundant shift sequences (for implementations with state-dependent encodings).
15362 7.24.6.3.3 The wcrtomb function
15364 1 #include <wchar.h>
15365 size_t wcrtomb(char * restrict s,
15367 mbstate_t * restrict ps);
15369 2 If s is a null pointer, the wcrtomb function is equivalent to the call
15370 wcrtomb(buf, L'\0', ps)
15371 where buf is an internal buffer.
15372 3 If s is not a null pointer, the wcrtomb function determines the number of bytes needed
15373 to represent the multibyte character that corresponds to the wide character given by wc
15374 (including any shift sequences), and stores the multibyte character representation in the
15375 array whose first element is pointed to by s. At most MB_CUR_MAX bytes are stored. If
15376 wc is a null wide character, a null byte is stored, preceded by any shift sequence needed
15377 to restore the initial shift state; the resulting state described is the initial conversion state.
15379 4 The wcrtomb function returns the number of bytes stored in the array object (including
15380 any shift sequences). When wc is not a valid wide character, an encoding error occurs:
15381 the function stores the value of the macro EILSEQ in errno and returns
15382 (size_t)(-1); the conversion state is unspecified.
15383 7.24.6.4 Restartable multibyte/wide string conversion functions
15384 1 These functions differ from the corresponding multibyte string functions of 7.20.8
15385 (mbstowcs and wcstombs) in that they have an extra parameter, ps, of type pointer to
15386 mbstate_t that points to an object that can completely describe the current conversion
15387 state of the associated multibyte character sequence. If ps is a null pointer, each function
15388 uses its own internal mbstate_t object instead, which is initialized at program startup
15389 to the initial conversion state. The implementation behaves as if no library function calls
15390 these functions with a null pointer for ps.
15391 2 Also unlike their corresponding functions, the conversion source parameter, src, has a
15392 pointer-to-pointer type. When the function is storing the results of conversions (that is,
15393 when dst is not a null pointer), the pointer object pointed to by this parameter is updated
15394 to reflect the amount of the source processed by that invocation.
15401 7.24.6.4.1 The mbsrtowcs function
15403 1 #include <wchar.h>
15404 size_t mbsrtowcs(wchar_t * restrict dst,
15405 const char ** restrict src,
15407 mbstate_t * restrict ps);
15409 2 The mbsrtowcs function converts a sequence of multibyte characters that begins in the
15410 conversion state described by the object pointed to by ps, from the array indirectly
15411 pointed to by src into a sequence of corresponding wide characters. If dst is not a null
15412 pointer, the converted characters are stored into the array pointed to by dst. Conversion
15413 continues up to and including a terminating null character, which is also stored.
15414 Conversion stops earlier in two cases: when a sequence of bytes is encountered that does
15415 not form a valid multibyte character, or (if dst is not a null pointer) when len wide
15416 characters have been stored into the array pointed to by dst.301) Each conversion takes
15417 place as if by a call to the mbrtowc function.
15418 3 If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
15419 pointer (if conversion stopped due to reaching a terminating null character) or the address
15420 just past the last multibyte character converted (if any). If conversion stopped due to
15421 reaching a terminating null character and if dst is not a null pointer, the resulting state
15422 described is the initial conversion state.
15424 4 If the input conversion encounters a sequence of bytes that do not form a valid multibyte
15425 character, an encoding error occurs: the mbsrtowcs function stores the value of the
15426 macro EILSEQ in errno and returns (size_t)(-1); the conversion state is
15427 unspecified. Otherwise, it returns the number of multibyte characters successfully
15428 converted, not including the terminating null character (if any).
15433 301) Thus, the value of len is ignored if dst is a null pointer.
15437 7.24.6.4.2 The wcsrtombs function
15439 1 #include <wchar.h>
15440 size_t wcsrtombs(char * restrict dst,
15441 const wchar_t ** restrict src,
15443 mbstate_t * restrict ps);
15445 2 The wcsrtombs function converts a sequence of wide characters from the array
15446 indirectly pointed to by src into a sequence of corresponding multibyte characters that
15447 begins in the conversion state described by the object pointed to by ps. If dst is not a
15448 null pointer, the converted characters are then stored into the array pointed to by dst.
15449 Conversion continues up to and including a terminating null wide character, which is also
15450 stored. Conversion stops earlier in two cases: when a wide character is reached that does
15451 not correspond to a valid multibyte character, or (if dst is not a null pointer) when the
15452 next multibyte character would exceed the limit of len total bytes to be stored into the
15453 array pointed to by dst. Each conversion takes place as if by a call to the wcrtomb
15455 3 If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
15456 pointer (if conversion stopped due to reaching a terminating null wide character) or the
15457 address just past the last wide character converted (if any). If conversion stopped due to
15458 reaching a terminating null wide character, the resulting state described is the initial
15461 4 If conversion stops because a wide character is reached that does not correspond to a
15462 valid multibyte character, an encoding error occurs: the wcsrtombs function stores the
15463 value of the macro EILSEQ in errno and returns (size_t)(-1); the conversion
15464 state is unspecified. Otherwise, it returns the number of bytes in the resulting multibyte
15465 character sequence, not including the terminating null character (if any).
15470 302) If conversion stops because a terminating null wide character has been reached, the bytes stored
15471 include those necessary to reach the initial shift state immediately before the null byte.
15475 7.25 Wide character classification and mapping utilities <wctype.h>
15476 7.25.1 Introduction
15477 1 The header <wctype.h> declares three data types, one macro, and many functions.303)
15478 2 The types declared are
15480 described in 7.24.1;
15482 which is a scalar type that can hold values which represent locale-specific character
15485 which is a scalar type that can hold values which represent locale-specific character
15487 3 The macro defined is WEOF (described in 7.24.1).
15488 4 The functions declared are grouped as follows:
15489 -- Functions that provide wide character classification;
15490 -- Extensible functions that provide wide character classification;
15491 -- Functions that provide wide character case mapping;
15492 -- Extensible functions that provide wide character mapping.
15493 5 For all functions described in this subclause that accept an argument of type wint_t, the
15494 value shall be representable as a wchar_t or shall equal the value of the macro WEOF. If
15495 this argument has any other value, the behavior is undefined.
15496 6 The behavior of these functions is affected by the LC_CTYPE category of the current
15502 303) See ''future library directions'' (7.26.13).
15506 7.25.2 Wide character classification utilities
15507 1 The header <wctype.h> declares several functions useful for classifying wide
15509 2 The term printing wide character refers to a member of a locale-specific set of wide
15510 characters, each of which occupies at least one printing position on a display device. The
15511 term control wide character refers to a member of a locale-specific set of wide characters
15512 that are not printing wide characters.
15513 7.25.2.1 Wide character classification functions
15514 1 The functions in this subclause return nonzero (true) if and only if the value of the
15515 argument wc conforms to that in the description of the function.
15516 2 Each of the following functions returns true for each wide character that corresponds (as
15517 if by a call to the wctob function) to a single-byte character for which the corresponding
15518 character classification function from 7.4.1 returns true, except that the iswgraph and
15519 iswpunct functions may differ with respect to wide characters other than L' ' that are
15520 both printing and white-space wide characters.304)
15521 Forward references: the wctob function (7.24.6.1.2).
15522 7.25.2.1.1 The iswalnum function
15524 1 #include <wctype.h>
15525 int iswalnum(wint_t wc);
15527 2 The iswalnum function tests for any wide character for which iswalpha or
15529 7.25.2.1.2 The iswalpha function
15531 1 #include <wctype.h>
15532 int iswalpha(wint_t wc);
15534 2 The iswalpha function tests for any wide character for which iswupper or
15535 iswlower is true, or any wide character that is one of a locale-specific set of alphabetic
15537 304) For example, if the expression isalpha(wctob(wc)) evaluates to true, then the call
15538 iswalpha(wc) also returns true. But, if the expression isgraph(wctob(wc)) evaluates to true
15539 (which cannot occur for wc == L' ' of course), then either iswgraph(wc) or iswprint(wc)
15540 && iswspace(wc) is true, but not both.
15544 wide characters for which none of iswcntrl, iswdigit, iswpunct, or iswspace
15546 7.25.2.1.3 The iswblank function
15548 1 #include <wctype.h>
15549 int iswblank(wint_t wc);
15551 2 The iswblank function tests for any wide character that is a standard blank wide
15552 character or is one of a locale-specific set of wide characters for which iswspace is true
15553 and that is used to separate words within a line of text. The standard blank wide
15554 characters are the following: space (L' '), and horizontal tab (L'\t'). In the "C"
15555 locale, iswblank returns true only for the standard blank characters.
15556 7.25.2.1.4 The iswcntrl function
15558 1 #include <wctype.h>
15559 int iswcntrl(wint_t wc);
15561 2 The iswcntrl function tests for any control wide character.
15562 7.25.2.1.5 The iswdigit function
15564 1 #include <wctype.h>
15565 int iswdigit(wint_t wc);
15567 2 The iswdigit function tests for any wide character that corresponds to a decimal-digit
15568 character (as defined in 5.2.1).
15569 7.25.2.1.6 The iswgraph function
15571 1 #include <wctype.h>
15572 int iswgraph(wint_t wc);
15577 305) The functions iswlower and iswupper test true or false separately for each of these additional
15578 wide characters; all four combinations are possible.
15583 2 The iswgraph function tests for any wide character for which iswprint is true and
15584 iswspace is false.306)
15585 7.25.2.1.7 The iswlower function
15587 1 #include <wctype.h>
15588 int iswlower(wint_t wc);
15590 2 The iswlower function tests for any wide character that corresponds to a lowercase
15591 letter or is one of a locale-specific set of wide characters for which none of iswcntrl,
15592 iswdigit, iswpunct, or iswspace is true.
15593 7.25.2.1.8 The iswprint function
15595 1 #include <wctype.h>
15596 int iswprint(wint_t wc);
15598 2 The iswprint function tests for any printing wide character.
15599 7.25.2.1.9 The iswpunct function
15601 1 #include <wctype.h>
15602 int iswpunct(wint_t wc);
15604 2 The iswpunct function tests for any printing wide character that is one of a locale-
15605 specific set of punctuation wide characters for which neither iswspace nor iswalnum
15607 7.25.2.1.10 The iswspace function
15609 1 #include <wctype.h>
15610 int iswspace(wint_t wc);
15614 306) Note that the behavior of the iswgraph and iswpunct functions may differ from their
15615 corresponding functions in 7.4.1 with respect to printing, white-space, single-byte execution
15616 characters other than ' '.
15621 2 The iswspace function tests for any wide character that corresponds to a locale-specific
15622 set of white-space wide characters for which none of iswalnum, iswgraph, or
15624 7.25.2.1.11 The iswupper function
15626 1 #include <wctype.h>
15627 int iswupper(wint_t wc);
15629 2 The iswupper function tests for any wide character that corresponds to an uppercase
15630 letter or is one of a locale-specific set of wide characters for which none of iswcntrl,
15631 iswdigit, iswpunct, or iswspace is true.
15632 7.25.2.1.12 The iswxdigit function
15634 1 #include <wctype.h>
15635 int iswxdigit(wint_t wc);
15637 2 The iswxdigit function tests for any wide character that corresponds to a
15638 hexadecimal-digit character (as defined in 6.4.4.1).
15639 7.25.2.2 Extensible wide character classification functions
15640 1 The functions wctype and iswctype provide extensible wide character classification
15641 as well as testing equivalent to that performed by the functions described in the previous
15642 subclause (7.25.2.1).
15643 7.25.2.2.1 The iswctype function
15645 1 #include <wctype.h>
15646 int iswctype(wint_t wc, wctype_t desc);
15648 2 The iswctype function determines whether the wide character wc has the property
15649 described by desc. The current setting of the LC_CTYPE category shall be the same as
15650 during the call to wctype that returned the value desc.
15651 3 Each of the following expressions has a truth-value equivalent to the call to the wide
15652 character classification function (7.25.2.1) in the comment that follows the expression:
15657 iswctype(wc, wctype("alnum")) // iswalnum(wc)
15658 iswctype(wc, wctype("alpha")) // iswalpha(wc)
15659 iswctype(wc, wctype("blank")) // iswblank(wc)
15660 iswctype(wc, wctype("cntrl")) // iswcntrl(wc)
15661 iswctype(wc, wctype("digit")) // iswdigit(wc)
15662 iswctype(wc, wctype("graph")) // iswgraph(wc)
15663 iswctype(wc, wctype("lower")) // iswlower(wc)
15664 iswctype(wc, wctype("print")) // iswprint(wc)
15665 iswctype(wc, wctype("punct")) // iswpunct(wc)
15666 iswctype(wc, wctype("space")) // iswspace(wc)
15667 iswctype(wc, wctype("upper")) // iswupper(wc)
15668 iswctype(wc, wctype("xdigit")) // iswxdigit(wc)
15670 4 The iswctype function returns nonzero (true) if and only if the value of the wide
15671 character wc has the property described by desc.
15672 Forward references: the wctype function (7.25.2.2.2).
15673 7.25.2.2.2 The wctype function
15675 1 #include <wctype.h>
15676 wctype_t wctype(const char *property);
15678 2 The wctype function constructs a value with type wctype_t that describes a class of
15679 wide characters identified by the string argument property.
15680 3 The strings listed in the description of the iswctype function shall be valid in all
15681 locales as property arguments to the wctype function.
15683 4 If property identifies a valid class of wide characters according to the LC_CTYPE
15684 category of the current locale, the wctype function returns a nonzero value that is valid
15685 as the second argument to the iswctype function; otherwise, it returns zero. *
15692 7.25.3 Wide character case mapping utilities
15693 1 The header <wctype.h> declares several functions useful for mapping wide characters.
15694 7.25.3.1 Wide character case mapping functions
15695 7.25.3.1.1 The towlower function
15697 1 #include <wctype.h>
15698 wint_t towlower(wint_t wc);
15700 2 The towlower function converts an uppercase letter to a corresponding lowercase letter.
15702 3 If the argument is a wide character for which iswupper is true and there are one or
15703 more corresponding wide characters, as specified by the current locale, for which
15704 iswlower is true, the towlower function returns one of the corresponding wide
15705 characters (always the same one for any given locale); otherwise, the argument is
15706 returned unchanged.
15707 7.25.3.1.2 The towupper function
15709 1 #include <wctype.h>
15710 wint_t towupper(wint_t wc);
15712 2 The towupper function converts a lowercase letter to a corresponding uppercase letter.
15714 3 If the argument is a wide character for which iswlower is true and there are one or
15715 more corresponding wide characters, as specified by the current locale, for which
15716 iswupper is true, the towupper function returns one of the corresponding wide
15717 characters (always the same one for any given locale); otherwise, the argument is
15718 returned unchanged.
15719 7.25.3.2 Extensible wide character case mapping functions
15720 1 The functions wctrans and towctrans provide extensible wide character mapping as
15721 well as case mapping equivalent to that performed by the functions described in the
15722 previous subclause (7.25.3.1).
15729 7.25.3.2.1 The towctrans function
15731 1 #include <wctype.h>
15732 wint_t towctrans(wint_t wc, wctrans_t desc);
15734 2 The towctrans function maps the wide character wc using the mapping described by
15735 desc. The current setting of the LC_CTYPE category shall be the same as during the call
15736 to wctrans that returned the value desc.
15737 3 Each of the following expressions behaves the same as the call to the wide character case
15738 mapping function (7.25.3.1) in the comment that follows the expression:
15739 towctrans(wc, wctrans("tolower")) // towlower(wc)
15740 towctrans(wc, wctrans("toupper")) // towupper(wc)
15742 4 The towctrans function returns the mapped value of wc using the mapping described
15744 7.25.3.2.2 The wctrans function
15746 1 #include <wctype.h>
15747 wctrans_t wctrans(const char *property);
15749 2 The wctrans function constructs a value with type wctrans_t that describes a
15750 mapping between wide characters identified by the string argument property.
15751 3 The strings listed in the description of the towctrans function shall be valid in all
15752 locales as property arguments to the wctrans function.
15754 4 If property identifies a valid mapping of wide characters according to the LC_CTYPE
15755 category of the current locale, the wctrans function returns a nonzero value that is valid
15756 as the second argument to the towctrans function; otherwise, it returns zero.
15763 7.26 Future library directions
15764 1 The following names are grouped under individual headers for convenience. All external
15765 names described below are reserved no matter what headers are included by the program.
15766 7.26.1 Complex arithmetic <complex.h>
15767 1 The function names
15769 cerfc clog10 clgamma
15770 cexp2 clog1p ctgamma
15771 and the same names suffixed with f or l may be added to the declarations in the
15772 <complex.h> header.
15773 7.26.2 Character handling <ctype.h>
15774 1 Function names that begin with either is or to, and a lowercase letter may be added to
15775 the declarations in the <ctype.h> header.
15776 7.26.3 Errors <errno.h>
15777 1 Macros that begin with E and a digit or E and an uppercase letter may be added to the
15778 declarations in the <errno.h> header.
15779 7.26.4 Format conversion of integer types <inttypes.h>
15780 1 Macro names beginning with PRI or SCN followed by any lowercase letter or X may be
15781 added to the macros defined in the <inttypes.h> header.
15782 7.26.5 Localization <locale.h>
15783 1 Macros that begin with LC_ and an uppercase letter may be added to the definitions in
15784 the <locale.h> header.
15785 7.26.6 Signal handling <signal.h>
15786 1 Macros that begin with either SIG and an uppercase letter or SIG_ and an uppercase
15787 letter may be added to the definitions in the <signal.h> header.
15788 7.26.7 Boolean type and values <stdbool.h>
15789 1 The ability to undefine and perhaps then redefine the macros bool, true, and false is
15790 an obsolescent feature.
15791 7.26.8 Integer types <stdint.h>
15792 1 Typedef names beginning with int or uint and ending with _t may be added to the
15793 types defined in the <stdint.h> header. Macro names beginning with INT or UINT
15794 and ending with _MAX, _MIN, or _C may be added to the macros defined in the
15798 7.26.9 Input/output <stdio.h>
15799 1 Lowercase letters may be added to the conversion specifiers and length modifiers in
15800 fprintf and fscanf. Other characters may be used in extensions.
15801 2 The gets function is obsolescent, and is deprecated.
15802 3 The use of ungetc on a binary stream where the file position indicator is zero prior to
15803 the call is an obsolescent feature.
15804 7.26.10 General utilities <stdlib.h>
15805 1 Function names that begin with str and a lowercase letter may be added to the
15806 declarations in the <stdlib.h> header.
15807 7.26.11 String handling <string.h>
15808 1 Function names that begin with str, mem, or wcs and a lowercase letter may be added
15809 to the declarations in the <string.h> header.
15810 7.26.12 Extended multibyte and wide character utilities <wchar.h>
15811 1 Function names that begin with wcs and a lowercase letter may be added to the
15812 declarations in the <wchar.h> header.
15813 2 Lowercase letters may be added to the conversion specifiers and length modifiers in
15814 fwprintf and fwscanf. Other characters may be used in extensions.
15815 7.26.13 Wide character classification and mapping utilities
15817 1 Function names that begin with is or to and a lowercase letter may be added to the
15818 declarations in the <wctype.h> header.
15827 Language syntax summary
15828 1 NOTE The notation is described in 6.1.
15830 A.1 Lexical grammar
15831 A.1.1 Lexical elements
15838 (6.4) preprocessing-token:
15845 each non-white-space character that cannot be one of the above
15847 (6.4.1) keyword: one of
15848 auto enum restrict unsigned
15849 break extern return void
15850 case float short volatile
15851 char for signed while
15852 const goto sizeof _Bool
15853 continue if static _Complex
15854 default inline struct _Imaginary
15856 double long typedef
15857 else register union
15865 (6.4.2.1) identifier:
15866 identifier-nondigit
15867 identifier identifier-nondigit
15869 (6.4.2.1) identifier-nondigit:
15871 universal-character-name
15872 other implementation-defined characters
15873 (6.4.2.1) nondigit: one of
15874 _ a b c d e f g h i j k l m
15875 n o p q r s t u v w x y z
15876 A B C D E F G H I J K L M
15877 N O P Q R S T U V W X Y Z
15878 (6.4.2.1) digit: one of
15879 0 1 2 3 4 5 6 7 8 9
15880 A.1.4 Universal character names
15881 (6.4.3) universal-character-name:
15883 \U hex-quad hex-quad
15885 hexadecimal-digit hexadecimal-digit
15886 hexadecimal-digit hexadecimal-digit
15891 enumeration-constant
15893 (6.4.4.1) integer-constant:
15894 decimal-constant integer-suffixopt
15895 octal-constant integer-suffixopt
15896 hexadecimal-constant integer-suffixopt
15897 (6.4.4.1) decimal-constant:
15899 decimal-constant digit
15902 (6.4.4.1) octal-constant:
15904 octal-constant octal-digit
15905 (6.4.4.1) hexadecimal-constant:
15906 hexadecimal-prefix hexadecimal-digit
15907 hexadecimal-constant hexadecimal-digit
15908 (6.4.4.1) hexadecimal-prefix: one of
15910 (6.4.4.1) nonzero-digit: one of
15912 (6.4.4.1) octal-digit: one of
15914 (6.4.4.1) hexadecimal-digit: one of
15915 0 1 2 3 4 5 6 7 8 9
15918 (6.4.4.1) integer-suffix:
15919 unsigned-suffix long-suffixopt
15920 unsigned-suffix long-long-suffix
15921 long-suffix unsigned-suffixopt
15922 long-long-suffix unsigned-suffixopt
15923 (6.4.4.1) unsigned-suffix: one of
15925 (6.4.4.1) long-suffix: one of
15927 (6.4.4.1) long-long-suffix: one of
15929 (6.4.4.2) floating-constant:
15930 decimal-floating-constant
15931 hexadecimal-floating-constant
15932 (6.4.4.2) decimal-floating-constant:
15933 fractional-constant exponent-partopt floating-suffixopt
15934 digit-sequence exponent-part floating-suffixopt
15941 (6.4.4.2) hexadecimal-floating-constant:
15942 hexadecimal-prefix hexadecimal-fractional-constant
15943 binary-exponent-part floating-suffixopt
15944 hexadecimal-prefix hexadecimal-digit-sequence
15945 binary-exponent-part floating-suffixopt
15946 (6.4.4.2) fractional-constant:
15947 digit-sequenceopt . digit-sequence
15949 (6.4.4.2) exponent-part:
15950 e signopt digit-sequence
15951 E signopt digit-sequence
15952 (6.4.4.2) sign: one of
15954 (6.4.4.2) digit-sequence:
15956 digit-sequence digit
15957 (6.4.4.2) hexadecimal-fractional-constant:
15958 hexadecimal-digit-sequenceopt .
15959 hexadecimal-digit-sequence
15960 hexadecimal-digit-sequence .
15961 (6.4.4.2) binary-exponent-part:
15962 p signopt digit-sequence
15963 P signopt digit-sequence
15964 (6.4.4.2) hexadecimal-digit-sequence:
15966 hexadecimal-digit-sequence hexadecimal-digit
15967 (6.4.4.2) floating-suffix: one of
15969 (6.4.4.3) enumeration-constant:
15971 (6.4.4.4) character-constant:
15972 ' c-char-sequence '
15973 L' c-char-sequence '
15980 (6.4.4.4) c-char-sequence:
15982 c-char-sequence c-char
15984 any member of the source character set except
15985 the single-quote ', backslash \, or new-line character
15987 (6.4.4.4) escape-sequence:
15988 simple-escape-sequence
15989 octal-escape-sequence
15990 hexadecimal-escape-sequence
15991 universal-character-name
15992 (6.4.4.4) simple-escape-sequence: one of
15994 \a \b \f \n \r \t \v
15995 (6.4.4.4) octal-escape-sequence:
15997 \ octal-digit octal-digit
15998 \ octal-digit octal-digit octal-digit
15999 (6.4.4.4) hexadecimal-escape-sequence:
16000 \x hexadecimal-digit
16001 hexadecimal-escape-sequence hexadecimal-digit
16002 A.1.6 String literals
16003 (6.4.5) string-literal:
16004 " s-char-sequenceopt "
16005 L" s-char-sequenceopt "
16006 (6.4.5) s-char-sequence:
16008 s-char-sequence s-char
16010 any member of the source character set except
16011 the double-quote ", backslash \, or new-line character
16020 (6.4.6) punctuator: one of
16023 / % << >> < > <= >= == != ^ | && ||
16025 = *= /= %= += -= <<= >>= &= ^= |=
16027 <: :> <% %> %: %:%:
16029 (6.4.7) header-name:
16030 < h-char-sequence >
16031 " q-char-sequence "
16032 (6.4.7) h-char-sequence:
16034 h-char-sequence h-char
16036 any member of the source character set except
16037 the new-line character and >
16038 (6.4.7) q-char-sequence:
16040 q-char-sequence q-char
16042 any member of the source character set except
16043 the new-line character and "
16044 A.1.9 Preprocessing numbers
16049 pp-number identifier-nondigit
16059 A.2 Phrase structure grammar
16061 (6.5.1) primary-expression:
16066 (6.5.2) postfix-expression:
16068 postfix-expression [ expression ]
16069 postfix-expression ( argument-expression-listopt )
16070 postfix-expression . identifier
16071 postfix-expression -> identifier
16072 postfix-expression ++
16073 postfix-expression --
16074 ( type-name ) { initializer-list }
16075 ( type-name ) { initializer-list , }
16076 (6.5.2) argument-expression-list:
16077 assignment-expression
16078 argument-expression-list , assignment-expression
16079 (6.5.3) unary-expression:
16081 ++ unary-expression
16082 -- unary-expression
16083 unary-operator cast-expression
16084 sizeof unary-expression
16085 sizeof ( type-name )
16086 (6.5.3) unary-operator: one of
16088 (6.5.4) cast-expression:
16090 ( type-name ) cast-expression
16091 (6.5.5) multiplicative-expression:
16093 multiplicative-expression * cast-expression
16094 multiplicative-expression / cast-expression
16095 multiplicative-expression % cast-expression
16099 (6.5.6) additive-expression:
16100 multiplicative-expression
16101 additive-expression + multiplicative-expression
16102 additive-expression - multiplicative-expression
16103 (6.5.7) shift-expression:
16104 additive-expression
16105 shift-expression << additive-expression
16106 shift-expression >> additive-expression
16107 (6.5.8) relational-expression:
16109 relational-expression < shift-expression
16110 relational-expression > shift-expression
16111 relational-expression <= shift-expression
16112 relational-expression >= shift-expression
16113 (6.5.9) equality-expression:
16114 relational-expression
16115 equality-expression == relational-expression
16116 equality-expression != relational-expression
16117 (6.5.10) AND-expression:
16118 equality-expression
16119 AND-expression & equality-expression
16120 (6.5.11) exclusive-OR-expression:
16122 exclusive-OR-expression ^ AND-expression
16123 (6.5.12) inclusive-OR-expression:
16124 exclusive-OR-expression
16125 inclusive-OR-expression | exclusive-OR-expression
16126 (6.5.13) logical-AND-expression:
16127 inclusive-OR-expression
16128 logical-AND-expression && inclusive-OR-expression
16129 (6.5.14) logical-OR-expression:
16130 logical-AND-expression
16131 logical-OR-expression || logical-AND-expression
16132 (6.5.15) conditional-expression:
16133 logical-OR-expression
16134 logical-OR-expression ? expression : conditional-expression
16138 (6.5.16) assignment-expression:
16139 conditional-expression
16140 unary-expression assignment-operator assignment-expression
16141 (6.5.16) assignment-operator: one of
16142 = *= /= %= += -= <<= >>= &= ^= |=
16143 (6.5.17) expression:
16144 assignment-expression
16145 expression , assignment-expression
16146 (6.6) constant-expression:
16147 conditional-expression
16150 declaration-specifiers init-declarator-listopt ;
16151 (6.7) declaration-specifiers:
16152 storage-class-specifier declaration-specifiersopt
16153 type-specifier declaration-specifiersopt
16154 type-qualifier declaration-specifiersopt
16155 function-specifier declaration-specifiersopt
16156 (6.7) init-declarator-list:
16158 init-declarator-list , init-declarator
16159 (6.7) init-declarator:
16161 declarator = initializer
16162 (6.7.1) storage-class-specifier:
16174 (6.7.2) type-specifier:
16186 struct-or-union-specifier *
16189 (6.7.2.1) struct-or-union-specifier:
16190 struct-or-union identifieropt { struct-declaration-list }
16191 struct-or-union identifier
16192 (6.7.2.1) struct-or-union:
16195 (6.7.2.1) struct-declaration-list:
16197 struct-declaration-list struct-declaration
16198 (6.7.2.1) struct-declaration:
16199 specifier-qualifier-list struct-declarator-list ;
16200 (6.7.2.1) specifier-qualifier-list:
16201 type-specifier specifier-qualifier-listopt
16202 type-qualifier specifier-qualifier-listopt
16203 (6.7.2.1) struct-declarator-list:
16205 struct-declarator-list , struct-declarator
16206 (6.7.2.1) struct-declarator:
16208 declaratoropt : constant-expression
16215 (6.7.2.2) enum-specifier:
16216 enum identifieropt { enumerator-list }
16217 enum identifieropt { enumerator-list , }
16219 (6.7.2.2) enumerator-list:
16221 enumerator-list , enumerator
16222 (6.7.2.2) enumerator:
16223 enumeration-constant
16224 enumeration-constant = constant-expression
16225 (6.7.3) type-qualifier:
16229 (6.7.4) function-specifier:
16231 (6.7.5) declarator:
16232 pointeropt direct-declarator
16233 (6.7.5) direct-declarator:
16236 direct-declarator [ type-qualifier-listopt assignment-expressionopt ]
16237 direct-declarator [ static type-qualifier-listopt assignment-expression ]
16238 direct-declarator [ type-qualifier-list static assignment-expression ]
16239 direct-declarator [ type-qualifier-listopt * ]
16240 direct-declarator ( parameter-type-list )
16241 direct-declarator ( identifier-listopt )
16243 * type-qualifier-listopt
16244 * type-qualifier-listopt pointer
16245 (6.7.5) type-qualifier-list:
16247 type-qualifier-list type-qualifier
16248 (6.7.5) parameter-type-list:
16250 parameter-list , ...
16254 (6.7.5) parameter-list:
16255 parameter-declaration
16256 parameter-list , parameter-declaration
16257 (6.7.5) parameter-declaration:
16258 declaration-specifiers declarator
16259 declaration-specifiers abstract-declaratoropt
16260 (6.7.5) identifier-list:
16262 identifier-list , identifier
16264 specifier-qualifier-list abstract-declaratoropt
16265 (6.7.6) abstract-declarator:
16267 pointeropt direct-abstract-declarator
16268 (6.7.6) direct-abstract-declarator:
16269 ( abstract-declarator )
16270 direct-abstract-declaratoropt [ type-qualifier-listopt
16271 assignment-expressionopt ]
16272 direct-abstract-declaratoropt [ static type-qualifier-listopt
16273 assignment-expression ]
16274 direct-abstract-declaratoropt [ type-qualifier-list static
16275 assignment-expression ]
16276 direct-abstract-declaratoropt [ * ]
16277 direct-abstract-declaratoropt ( parameter-type-listopt )
16278 (6.7.7) typedef-name:
16280 (6.7.8) initializer:
16281 assignment-expression
16282 { initializer-list }
16283 { initializer-list , }
16284 (6.7.8) initializer-list:
16285 designationopt initializer
16286 initializer-list , designationopt initializer
16287 (6.7.8) designation:
16294 (6.7.8) designator-list:
16296 designator-list designator
16297 (6.7.8) designator:
16298 [ constant-expression ]
16304 expression-statement
16305 selection-statement
16306 iteration-statement
16308 (6.8.1) labeled-statement:
16309 identifier : statement
16310 case constant-expression : statement
16311 default : statement
16312 (6.8.2) compound-statement:
16313 { block-item-listopt }
16314 (6.8.2) block-item-list:
16316 block-item-list block-item
16317 (6.8.2) block-item:
16320 (6.8.3) expression-statement:
16322 (6.8.4) selection-statement:
16323 if ( expression ) statement
16324 if ( expression ) statement else statement
16325 switch ( expression ) statement
16332 (6.8.5) iteration-statement:
16333 while ( expression ) statement
16334 do statement while ( expression ) ;
16335 for ( expressionopt ; expressionopt ; expressionopt ) statement
16336 for ( declaration expressionopt ; expressionopt ) statement
16337 (6.8.6) jump-statement:
16341 return expressionopt ;
16342 A.2.4 External definitions
16343 (6.9) translation-unit:
16344 external-declaration
16345 translation-unit external-declaration
16346 (6.9) external-declaration:
16347 function-definition
16349 (6.9.1) function-definition:
16350 declaration-specifiers declarator declaration-listopt compound-statement
16351 (6.9.1) declaration-list:
16353 declaration-list declaration
16354 A.3 Preprocessing directives
16355 (6.10) preprocessing-file:
16366 if-group elif-groupsopt else-groupopt endif-line
16372 # if constant-expression new-line groupopt
16373 # ifdef identifier new-line groupopt
16374 # ifndef identifier new-line groupopt
16375 (6.10) elif-groups:
16377 elif-groups elif-group
16379 # elif constant-expression new-line groupopt
16381 # else new-line groupopt
16384 (6.10) control-line:
16385 # include pp-tokens new-line
16386 # define identifier replacement-list new-line
16387 # define identifier lparen identifier-listopt )
16388 replacement-list new-line
16389 # define identifier lparen ... ) replacement-list new-line
16390 # define identifier lparen identifier-list , ... )
16391 replacement-list new-line
16392 # undef identifier new-line
16393 # line pp-tokens new-line
16394 # error pp-tokensopt new-line
16395 # pragma pp-tokensopt new-line
16398 pp-tokensopt new-line
16399 (6.10) non-directive:
16402 a ( character not immediately preceded by white-space
16403 (6.10) replacement-list:
16412 preprocessing-token
16413 pp-tokens preprocessing-token
16415 the new-line character
16425 B.1 Diagnostics <assert.h>
16427 void assert(scalar expression);
16428 B.2 Complex <complex.h>
16429 complex imaginary I
16430 _Complex_I _Imaginary_I
16431 #pragma STDC CX_LIMITED_RANGE on-off-switch
16432 double complex cacos(double complex z);
16433 float complex cacosf(float complex z);
16434 long double complex cacosl(long double complex z);
16435 double complex casin(double complex z);
16436 float complex casinf(float complex z);
16437 long double complex casinl(long double complex z);
16438 double complex catan(double complex z);
16439 float complex catanf(float complex z);
16440 long double complex catanl(long double complex z);
16441 double complex ccos(double complex z);
16442 float complex ccosf(float complex z);
16443 long double complex ccosl(long double complex z);
16444 double complex csin(double complex z);
16445 float complex csinf(float complex z);
16446 long double complex csinl(long double complex z);
16447 double complex ctan(double complex z);
16448 float complex ctanf(float complex z);
16449 long double complex ctanl(long double complex z);
16450 double complex cacosh(double complex z);
16451 float complex cacoshf(float complex z);
16452 long double complex cacoshl(long double complex z);
16453 double complex casinh(double complex z);
16454 float complex casinhf(float complex z);
16455 long double complex casinhl(long double complex z);
16456 double complex catanh(double complex z);
16457 float complex catanhf(float complex z);
16458 long double complex catanhl(long double complex z);
16461 double complex ccosh(double complex z);
16462 float complex ccoshf(float complex z);
16463 long double complex ccoshl(long double complex z);
16464 double complex csinh(double complex z);
16465 float complex csinhf(float complex z);
16466 long double complex csinhl(long double complex z);
16467 double complex ctanh(double complex z);
16468 float complex ctanhf(float complex z);
16469 long double complex ctanhl(long double complex z);
16470 double complex cexp(double complex z);
16471 float complex cexpf(float complex z);
16472 long double complex cexpl(long double complex z);
16473 double complex clog(double complex z);
16474 float complex clogf(float complex z);
16475 long double complex clogl(long double complex z);
16476 double cabs(double complex z);
16477 float cabsf(float complex z);
16478 long double cabsl(long double complex z);
16479 double complex cpow(double complex x, double complex y);
16480 float complex cpowf(float complex x, float complex y);
16481 long double complex cpowl(long double complex x,
16482 long double complex y);
16483 double complex csqrt(double complex z);
16484 float complex csqrtf(float complex z);
16485 long double complex csqrtl(long double complex z);
16486 double carg(double complex z);
16487 float cargf(float complex z);
16488 long double cargl(long double complex z);
16489 double cimag(double complex z);
16490 float cimagf(float complex z);
16491 long double cimagl(long double complex z);
16492 double complex conj(double complex z);
16493 float complex conjf(float complex z);
16494 long double complex conjl(long double complex z);
16495 double complex cproj(double complex z);
16496 float complex cprojf(float complex z);
16497 long double complex cprojl(long double complex z);
16498 double creal(double complex z);
16499 float crealf(float complex z);
16500 long double creall(long double complex z);
16505 B.3 Character handling <ctype.h>
16506 int isalnum(int c);
16507 int isalpha(int c);
16508 int isblank(int c);
16509 int iscntrl(int c);
16510 int isdigit(int c);
16511 int isgraph(int c);
16512 int islower(int c);
16513 int isprint(int c);
16514 int ispunct(int c);
16515 int isspace(int c);
16516 int isupper(int c);
16517 int isxdigit(int c);
16518 int tolower(int c);
16519 int toupper(int c);
16520 B.4 Errors <errno.h>
16521 EDOM EILSEQ ERANGE errno
16522 B.5 Floating-point environment <fenv.h>
16523 fenv_t FE_OVERFLOW FE_TOWARDZERO
16524 fexcept_t FE_UNDERFLOW FE_UPWARD
16525 FE_DIVBYZERO FE_ALL_EXCEPT FE_DFL_ENV
16526 FE_INEXACT FE_DOWNWARD
16527 FE_INVALID FE_TONEAREST
16528 #pragma STDC FENV_ACCESS on-off-switch
16529 int feclearexcept(int excepts);
16530 int fegetexceptflag(fexcept_t *flagp, int excepts);
16531 int feraiseexcept(int excepts);
16532 int fesetexceptflag(const fexcept_t *flagp,
16534 int fetestexcept(int excepts);
16535 int fegetround(void);
16536 int fesetround(int round);
16537 int fegetenv(fenv_t *envp);
16538 int feholdexcept(fenv_t *envp);
16539 int fesetenv(const fenv_t *envp);
16540 int feupdateenv(const fenv_t *envp);
16546 B.6 Characteristics of floating types <float.h>
16547 FLT_ROUNDS DBL_MIN_EXP FLT_MAX
16548 FLT_EVAL_METHOD LDBL_MIN_EXP DBL_MAX
16549 FLT_RADIX FLT_MIN_10_EXP LDBL_MAX
16550 FLT_MANT_DIG DBL_MIN_10_EXP FLT_EPSILON
16551 DBL_MANT_DIG LDBL_MIN_10_EXP DBL_EPSILON
16552 LDBL_MANT_DIG FLT_MAX_EXP LDBL_EPSILON
16553 DECIMAL_DIG DBL_MAX_EXP FLT_MIN
16554 FLT_DIG LDBL_MAX_EXP DBL_MIN
16555 DBL_DIG FLT_MAX_10_EXP LDBL_MIN
16556 LDBL_DIG DBL_MAX_10_EXP
16557 FLT_MIN_EXP LDBL_MAX_10_EXP
16558 B.7 Format conversion of integer types <inttypes.h>
16560 PRIdN PRIdLEASTN PRIdFASTN PRIdMAX PRIdPTR
16561 PRIiN PRIiLEASTN PRIiFASTN PRIiMAX PRIiPTR
16562 PRIoN PRIoLEASTN PRIoFASTN PRIoMAX PRIoPTR
16563 PRIuN PRIuLEASTN PRIuFASTN PRIuMAX PRIuPTR
16564 PRIxN PRIxLEASTN PRIxFASTN PRIxMAX PRIxPTR
16565 PRIXN PRIXLEASTN PRIXFASTN PRIXMAX PRIXPTR
16566 SCNdN SCNdLEASTN SCNdFASTN SCNdMAX SCNdPTR
16567 SCNiN SCNiLEASTN SCNiFASTN SCNiMAX SCNiPTR
16568 SCNoN SCNoLEASTN SCNoFASTN SCNoMAX SCNoPTR
16569 SCNuN SCNuLEASTN SCNuFASTN SCNuMAX SCNuPTR
16570 SCNxN SCNxLEASTN SCNxFASTN SCNxMAX SCNxPTR
16571 intmax_t imaxabs(intmax_t j);
16572 imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
16573 intmax_t strtoimax(const char * restrict nptr,
16574 char ** restrict endptr, int base);
16575 uintmax_t strtoumax(const char * restrict nptr,
16576 char ** restrict endptr, int base);
16577 intmax_t wcstoimax(const wchar_t * restrict nptr,
16578 wchar_t ** restrict endptr, int base);
16579 uintmax_t wcstoumax(const wchar_t * restrict nptr,
16580 wchar_t ** restrict endptr, int base);
16587 B.8 Alternative spellings <iso646.h>
16588 and bitor not_eq xor
16589 and_eq compl or xor_eq
16591 B.9 Sizes of integer types <limits.h>
16592 CHAR_BIT CHAR_MAX INT_MIN ULONG_MAX
16593 SCHAR_MIN MB_LEN_MAX INT_MAX LLONG_MIN
16594 SCHAR_MAX SHRT_MIN UINT_MAX LLONG_MAX
16595 UCHAR_MAX SHRT_MAX LONG_MIN ULLONG_MAX
16596 CHAR_MIN USHRT_MAX LONG_MAX
16597 B.10 Localization <locale.h>
16598 struct lconv LC_ALL LC_CTYPE LC_NUMERIC
16599 NULL LC_COLLATE LC_MONETARY LC_TIME
16600 char *setlocale(int category, const char *locale);
16601 struct lconv *localeconv(void);
16602 B.11 Mathematics <math.h>
16603 float_t FP_INFINITE FP_FAST_FMAL
16604 double_t FP_NAN FP_ILOGB0
16605 HUGE_VAL FP_NORMAL FP_ILOGBNAN
16606 HUGE_VALF FP_SUBNORMAL MATH_ERRNO
16607 HUGE_VALL FP_ZERO MATH_ERREXCEPT
16608 INFINITY FP_FAST_FMA math_errhandling
16610 #pragma STDC FP_CONTRACT on-off-switch
16611 int fpclassify(real-floating x);
16612 int isfinite(real-floating x);
16613 int isinf(real-floating x);
16614 int isnan(real-floating x);
16615 int isnormal(real-floating x);
16616 int signbit(real-floating x);
16617 double acos(double x);
16618 float acosf(float x);
16619 long double acosl(long double x);
16620 double asin(double x);
16621 float asinf(float x);
16622 long double asinl(long double x);
16623 double atan(double x);
16626 float atanf(float x);
16627 long double atanl(long double x);
16628 double atan2(double y, double x);
16629 float atan2f(float y, float x);
16630 long double atan2l(long double y, long double x);
16631 double cos(double x);
16632 float cosf(float x);
16633 long double cosl(long double x);
16634 double sin(double x);
16635 float sinf(float x);
16636 long double sinl(long double x);
16637 double tan(double x);
16638 float tanf(float x);
16639 long double tanl(long double x);
16640 double acosh(double x);
16641 float acoshf(float x);
16642 long double acoshl(long double x);
16643 double asinh(double x);
16644 float asinhf(float x);
16645 long double asinhl(long double x);
16646 double atanh(double x);
16647 float atanhf(float x);
16648 long double atanhl(long double x);
16649 double cosh(double x);
16650 float coshf(float x);
16651 long double coshl(long double x);
16652 double sinh(double x);
16653 float sinhf(float x);
16654 long double sinhl(long double x);
16655 double tanh(double x);
16656 float tanhf(float x);
16657 long double tanhl(long double x);
16658 double exp(double x);
16659 float expf(float x);
16660 long double expl(long double x);
16661 double exp2(double x);
16662 float exp2f(float x);
16663 long double exp2l(long double x);
16664 double expm1(double x);
16665 float expm1f(float x);
16666 long double expm1l(long double x);
16670 double frexp(double value, int *exp);
16671 float frexpf(float value, int *exp);
16672 long double frexpl(long double value, int *exp);
16673 int ilogb(double x);
16674 int ilogbf(float x);
16675 int ilogbl(long double x);
16676 double ldexp(double x, int exp);
16677 float ldexpf(float x, int exp);
16678 long double ldexpl(long double x, int exp);
16679 double log(double x);
16680 float logf(float x);
16681 long double logl(long double x);
16682 double log10(double x);
16683 float log10f(float x);
16684 long double log10l(long double x);
16685 double log1p(double x);
16686 float log1pf(float x);
16687 long double log1pl(long double x);
16688 double log2(double x);
16689 float log2f(float x);
16690 long double log2l(long double x);
16691 double logb(double x);
16692 float logbf(float x);
16693 long double logbl(long double x);
16694 double modf(double value, double *iptr);
16695 float modff(float value, float *iptr);
16696 long double modfl(long double value, long double *iptr);
16697 double scalbn(double x, int n);
16698 float scalbnf(float x, int n);
16699 long double scalbnl(long double x, int n);
16700 double scalbln(double x, long int n);
16701 float scalblnf(float x, long int n);
16702 long double scalblnl(long double x, long int n);
16703 double cbrt(double x);
16704 float cbrtf(float x);
16705 long double cbrtl(long double x);
16706 double fabs(double x);
16707 float fabsf(float x);
16708 long double fabsl(long double x);
16709 double hypot(double x, double y);
16710 float hypotf(float x, float y);
16714 long double hypotl(long double x, long double y);
16715 double pow(double x, double y);
16716 float powf(float x, float y);
16717 long double powl(long double x, long double y);
16718 double sqrt(double x);
16719 float sqrtf(float x);
16720 long double sqrtl(long double x);
16721 double erf(double x);
16722 float erff(float x);
16723 long double erfl(long double x);
16724 double erfc(double x);
16725 float erfcf(float x);
16726 long double erfcl(long double x);
16727 double lgamma(double x);
16728 float lgammaf(float x);
16729 long double lgammal(long double x);
16730 double tgamma(double x);
16731 float tgammaf(float x);
16732 long double tgammal(long double x);
16733 double ceil(double x);
16734 float ceilf(float x);
16735 long double ceill(long double x);
16736 double floor(double x);
16737 float floorf(float x);
16738 long double floorl(long double x);
16739 double nearbyint(double x);
16740 float nearbyintf(float x);
16741 long double nearbyintl(long double x);
16742 double rint(double x);
16743 float rintf(float x);
16744 long double rintl(long double x);
16745 long int lrint(double x);
16746 long int lrintf(float x);
16747 long int lrintl(long double x);
16748 long long int llrint(double x);
16749 long long int llrintf(float x);
16750 long long int llrintl(long double x);
16751 double round(double x);
16752 float roundf(float x);
16753 long double roundl(long double x);
16754 long int lround(double x);
16758 long int lroundf(float x);
16759 long int lroundl(long double x);
16760 long long int llround(double x);
16761 long long int llroundf(float x);
16762 long long int llroundl(long double x);
16763 double trunc(double x);
16764 float truncf(float x);
16765 long double truncl(long double x);
16766 double fmod(double x, double y);
16767 float fmodf(float x, float y);
16768 long double fmodl(long double x, long double y);
16769 double remainder(double x, double y);
16770 float remainderf(float x, float y);
16771 long double remainderl(long double x, long double y);
16772 double remquo(double x, double y, int *quo);
16773 float remquof(float x, float y, int *quo);
16774 long double remquol(long double x, long double y,
16776 double copysign(double x, double y);
16777 float copysignf(float x, float y);
16778 long double copysignl(long double x, long double y);
16779 double nan(const char *tagp);
16780 float nanf(const char *tagp);
16781 long double nanl(const char *tagp);
16782 double nextafter(double x, double y);
16783 float nextafterf(float x, float y);
16784 long double nextafterl(long double x, long double y);
16785 double nexttoward(double x, long double y);
16786 float nexttowardf(float x, long double y);
16787 long double nexttowardl(long double x, long double y);
16788 double fdim(double x, double y);
16789 float fdimf(float x, float y);
16790 long double fdiml(long double x, long double y);
16791 double fmax(double x, double y);
16792 float fmaxf(float x, float y);
16793 long double fmaxl(long double x, long double y);
16794 double fmin(double x, double y);
16795 float fminf(float x, float y);
16796 long double fminl(long double x, long double y);
16797 double fma(double x, double y, double z);
16798 float fmaf(float x, float y, float z);
16802 long double fmal(long double x, long double y,
16804 int isgreater(real-floating x, real-floating y);
16805 int isgreaterequal(real-floating x, real-floating y);
16806 int isless(real-floating x, real-floating y);
16807 int islessequal(real-floating x, real-floating y);
16808 int islessgreater(real-floating x, real-floating y);
16809 int isunordered(real-floating x, real-floating y);
16810 B.12 Nonlocal jumps <setjmp.h>
16812 int setjmp(jmp_buf env);
16813 void longjmp(jmp_buf env, int val);
16814 B.13 Signal handling <signal.h>
16815 sig_atomic_t SIG_IGN SIGILL SIGTERM
16816 SIG_DFL SIGABRT SIGINT
16817 SIG_ERR SIGFPE SIGSEGV
16818 void (*signal(int sig, void (*func)(int)))(int);
16819 int raise(int sig);
16820 B.14 Variable arguments <stdarg.h>
16822 type va_arg(va_list ap, type);
16823 void va_copy(va_list dest, va_list src);
16824 void va_end(va_list ap);
16825 void va_start(va_list ap, parmN);
16826 B.15 Boolean type and values <stdbool.h>
16830 __bool_true_false_are_defined
16837 B.16 Common definitions <stddef.h>
16838 ptrdiff_t size_t wchar_t NULL
16839 offsetof(type, member-designator)
16840 B.17 Integer types <stdint.h>
16841 intN_t INT_LEASTN_MIN PTRDIFF_MAX
16842 uintN_t INT_LEASTN_MAX SIG_ATOMIC_MIN
16843 int_leastN_t UINT_LEASTN_MAX SIG_ATOMIC_MAX
16844 uint_leastN_t INT_FASTN_MIN SIZE_MAX
16845 int_fastN_t INT_FASTN_MAX WCHAR_MIN
16846 uint_fastN_t UINT_FASTN_MAX WCHAR_MAX
16847 intptr_t INTPTR_MIN WINT_MIN
16848 uintptr_t INTPTR_MAX WINT_MAX
16849 intmax_t UINTPTR_MAX INTN_C(value)
16850 uintmax_t INTMAX_MIN UINTN_C(value)
16851 INTN_MIN INTMAX_MAX INTMAX_C(value)
16852 INTN_MAX UINTMAX_MAX UINTMAX_C(value)
16853 UINTN_MAX PTRDIFF_MIN
16854 B.18 Input/output <stdio.h>
16855 size_t _IOLBF FILENAME_MAX TMP_MAX
16856 FILE _IONBF L_tmpnam stderr
16857 fpos_t BUFSIZ SEEK_CUR stdin
16858 NULL EOF SEEK_END stdout
16859 _IOFBF FOPEN_MAX SEEK_SET
16860 int remove(const char *filename);
16861 int rename(const char *old, const char *new);
16862 FILE *tmpfile(void);
16863 char *tmpnam(char *s);
16864 int fclose(FILE *stream);
16865 int fflush(FILE *stream);
16866 FILE *fopen(const char * restrict filename,
16867 const char * restrict mode);
16868 FILE *freopen(const char * restrict filename,
16869 const char * restrict mode,
16870 FILE * restrict stream);
16871 void setbuf(FILE * restrict stream,
16872 char * restrict buf);
16877 int setvbuf(FILE * restrict stream,
16878 char * restrict buf,
16879 int mode, size_t size);
16880 int fprintf(FILE * restrict stream,
16881 const char * restrict format, ...);
16882 int fscanf(FILE * restrict stream,
16883 const char * restrict format, ...);
16884 int printf(const char * restrict format, ...);
16885 int scanf(const char * restrict format, ...);
16886 int snprintf(char * restrict s, size_t n,
16887 const char * restrict format, ...);
16888 int sprintf(char * restrict s,
16889 const char * restrict format, ...);
16890 int sscanf(const char * restrict s,
16891 const char * restrict format, ...);
16892 int vfprintf(FILE * restrict stream,
16893 const char * restrict format, va_list arg);
16894 int vfscanf(FILE * restrict stream,
16895 const char * restrict format, va_list arg);
16896 int vprintf(const char * restrict format, va_list arg);
16897 int vscanf(const char * restrict format, va_list arg);
16898 int vsnprintf(char * restrict s, size_t n,
16899 const char * restrict format, va_list arg);
16900 int vsprintf(char * restrict s,
16901 const char * restrict format, va_list arg);
16902 int vsscanf(const char * restrict s,
16903 const char * restrict format, va_list arg);
16904 int fgetc(FILE *stream);
16905 char *fgets(char * restrict s, int n,
16906 FILE * restrict stream);
16907 int fputc(int c, FILE *stream);
16908 int fputs(const char * restrict s,
16909 FILE * restrict stream);
16910 int getc(FILE *stream);
16912 char *gets(char *s);
16913 int putc(int c, FILE *stream);
16914 int putchar(int c);
16915 int puts(const char *s);
16916 int ungetc(int c, FILE *stream);
16921 size_t fread(void * restrict ptr,
16922 size_t size, size_t nmemb,
16923 FILE * restrict stream);
16924 size_t fwrite(const void * restrict ptr,
16925 size_t size, size_t nmemb,
16926 FILE * restrict stream);
16927 int fgetpos(FILE * restrict stream,
16928 fpos_t * restrict pos);
16929 int fseek(FILE *stream, long int offset, int whence);
16930 int fsetpos(FILE *stream, const fpos_t *pos);
16931 long int ftell(FILE *stream);
16932 void rewind(FILE *stream);
16933 void clearerr(FILE *stream);
16934 int feof(FILE *stream);
16935 int ferror(FILE *stream);
16936 void perror(const char *s);
16937 B.19 General utilities <stdlib.h>
16938 size_t ldiv_t EXIT_FAILURE MB_CUR_MAX
16939 wchar_t lldiv_t EXIT_SUCCESS
16940 div_t NULL RAND_MAX
16941 double atof(const char *nptr);
16942 int atoi(const char *nptr);
16943 long int atol(const char *nptr);
16944 long long int atoll(const char *nptr);
16945 double strtod(const char * restrict nptr,
16946 char ** restrict endptr);
16947 float strtof(const char * restrict nptr,
16948 char ** restrict endptr);
16949 long double strtold(const char * restrict nptr,
16950 char ** restrict endptr);
16951 long int strtol(const char * restrict nptr,
16952 char ** restrict endptr, int base);
16953 long long int strtoll(const char * restrict nptr,
16954 char ** restrict endptr, int base);
16955 unsigned long int strtoul(
16956 const char * restrict nptr,
16957 char ** restrict endptr, int base);
16964 unsigned long long int strtoull(
16965 const char * restrict nptr,
16966 char ** restrict endptr, int base);
16968 void srand(unsigned int seed);
16969 void *calloc(size_t nmemb, size_t size);
16970 void free(void *ptr);
16971 void *malloc(size_t size);
16972 void *realloc(void *ptr, size_t size);
16974 int atexit(void (*func)(void));
16975 void exit(int status);
16976 void _Exit(int status);
16977 char *getenv(const char *name);
16978 int system(const char *string);
16979 void *bsearch(const void *key, const void *base,
16980 size_t nmemb, size_t size,
16981 int (*compar)(const void *, const void *));
16982 void qsort(void *base, size_t nmemb, size_t size,
16983 int (*compar)(const void *, const void *));
16985 long int labs(long int j);
16986 long long int llabs(long long int j);
16987 div_t div(int numer, int denom);
16988 ldiv_t ldiv(long int numer, long int denom);
16989 lldiv_t lldiv(long long int numer,
16990 long long int denom);
16991 int mblen(const char *s, size_t n);
16992 int mbtowc(wchar_t * restrict pwc,
16993 const char * restrict s, size_t n);
16994 int wctomb(char *s, wchar_t wchar);
16995 size_t mbstowcs(wchar_t * restrict pwcs,
16996 const char * restrict s, size_t n);
16997 size_t wcstombs(char * restrict s,
16998 const wchar_t * restrict pwcs, size_t n);
17005 B.20 String handling <string.h>
17008 void *memcpy(void * restrict s1,
17009 const void * restrict s2, size_t n);
17010 void *memmove(void *s1, const void *s2, size_t n);
17011 char *strcpy(char * restrict s1,
17012 const char * restrict s2);
17013 char *strncpy(char * restrict s1,
17014 const char * restrict s2, size_t n);
17015 char *strcat(char * restrict s1,
17016 const char * restrict s2);
17017 char *strncat(char * restrict s1,
17018 const char * restrict s2, size_t n);
17019 int memcmp(const void *s1, const void *s2, size_t n);
17020 int strcmp(const char *s1, const char *s2);
17021 int strcoll(const char *s1, const char *s2);
17022 int strncmp(const char *s1, const char *s2, size_t n);
17023 size_t strxfrm(char * restrict s1,
17024 const char * restrict s2, size_t n);
17025 void *memchr(const void *s, int c, size_t n);
17026 char *strchr(const char *s, int c);
17027 size_t strcspn(const char *s1, const char *s2);
17028 char *strpbrk(const char *s1, const char *s2);
17029 char *strrchr(const char *s, int c);
17030 size_t strspn(const char *s1, const char *s2);
17031 char *strstr(const char *s1, const char *s2);
17032 char *strtok(char * restrict s1,
17033 const char * restrict s2);
17034 void *memset(void *s, int c, size_t n);
17035 char *strerror(int errnum);
17036 size_t strlen(const char *s);
17043 B.21 Type-generic math <tgmath.h>
17044 acos sqrt fmod nextafter
17045 asin fabs frexp nexttoward
17046 atan atan2 hypot remainder
17047 acosh cbrt ilogb remquo
17048 asinh ceil ldexp rint
17049 atanh copysign lgamma round
17050 cos erf llrint scalbn
17051 sin erfc llround scalbln
17052 tan exp2 log10 tgamma
17053 cosh expm1 log1p trunc
17054 sinh fdim log2 carg
17055 tanh floor logb cimag
17057 log fmax lround cproj
17058 pow fmin nearbyint creal
17059 B.22 Date and time <time.h>
17061 CLOCKS_PER_SEC clock_t struct tm
17062 clock_t clock(void);
17063 double difftime(time_t time1, time_t time0);
17064 time_t mktime(struct tm *timeptr);
17065 time_t time(time_t *timer);
17066 char *asctime(const struct tm *timeptr);
17067 char *ctime(const time_t *timer);
17068 struct tm *gmtime(const time_t *timer);
17069 struct tm *localtime(const time_t *timer);
17070 size_t strftime(char * restrict s,
17072 const char * restrict format,
17073 const struct tm * restrict timeptr);
17080 B.23 Extended multibyte/wide character utilities <wchar.h>
17081 wchar_t wint_t WCHAR_MAX
17082 size_t struct tm WCHAR_MIN
17083 mbstate_t NULL WEOF
17084 int fwprintf(FILE * restrict stream,
17085 const wchar_t * restrict format, ...);
17086 int fwscanf(FILE * restrict stream,
17087 const wchar_t * restrict format, ...);
17088 int swprintf(wchar_t * restrict s, size_t n,
17089 const wchar_t * restrict format, ...);
17090 int swscanf(const wchar_t * restrict s,
17091 const wchar_t * restrict format, ...);
17092 int vfwprintf(FILE * restrict stream,
17093 const wchar_t * restrict format, va_list arg);
17094 int vfwscanf(FILE * restrict stream,
17095 const wchar_t * restrict format, va_list arg);
17096 int vswprintf(wchar_t * restrict s, size_t n,
17097 const wchar_t * restrict format, va_list arg);
17098 int vswscanf(const wchar_t * restrict s,
17099 const wchar_t * restrict format, va_list arg);
17100 int vwprintf(const wchar_t * restrict format,
17102 int vwscanf(const wchar_t * restrict format,
17104 int wprintf(const wchar_t * restrict format, ...);
17105 int wscanf(const wchar_t * restrict format, ...);
17106 wint_t fgetwc(FILE *stream);
17107 wchar_t *fgetws(wchar_t * restrict s, int n,
17108 FILE * restrict stream);
17109 wint_t fputwc(wchar_t c, FILE *stream);
17110 int fputws(const wchar_t * restrict s,
17111 FILE * restrict stream);
17112 int fwide(FILE *stream, int mode);
17113 wint_t getwc(FILE *stream);
17114 wint_t getwchar(void);
17115 wint_t putwc(wchar_t c, FILE *stream);
17116 wint_t putwchar(wchar_t c);
17117 wint_t ungetwc(wint_t c, FILE *stream);
17123 double wcstod(const wchar_t * restrict nptr,
17124 wchar_t ** restrict endptr);
17125 float wcstof(const wchar_t * restrict nptr,
17126 wchar_t ** restrict endptr);
17127 long double wcstold(const wchar_t * restrict nptr,
17128 wchar_t ** restrict endptr);
17129 long int wcstol(const wchar_t * restrict nptr,
17130 wchar_t ** restrict endptr, int base);
17131 long long int wcstoll(const wchar_t * restrict nptr,
17132 wchar_t ** restrict endptr, int base);
17133 unsigned long int wcstoul(const wchar_t * restrict nptr,
17134 wchar_t ** restrict endptr, int base);
17135 unsigned long long int wcstoull(
17136 const wchar_t * restrict nptr,
17137 wchar_t ** restrict endptr, int base);
17138 wchar_t *wcscpy(wchar_t * restrict s1,
17139 const wchar_t * restrict s2);
17140 wchar_t *wcsncpy(wchar_t * restrict s1,
17141 const wchar_t * restrict s2, size_t n);
17142 wchar_t *wmemcpy(wchar_t * restrict s1,
17143 const wchar_t * restrict s2, size_t n);
17144 wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2,
17146 wchar_t *wcscat(wchar_t * restrict s1,
17147 const wchar_t * restrict s2);
17148 wchar_t *wcsncat(wchar_t * restrict s1,
17149 const wchar_t * restrict s2, size_t n);
17150 int wcscmp(const wchar_t *s1, const wchar_t *s2);
17151 int wcscoll(const wchar_t *s1, const wchar_t *s2);
17152 int wcsncmp(const wchar_t *s1, const wchar_t *s2,
17154 size_t wcsxfrm(wchar_t * restrict s1,
17155 const wchar_t * restrict s2, size_t n);
17156 int wmemcmp(const wchar_t *s1, const wchar_t *s2,
17158 wchar_t *wcschr(const wchar_t *s, wchar_t c);
17159 size_t wcscspn(const wchar_t *s1, const wchar_t *s2);
17160 wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2); *
17161 wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
17162 size_t wcsspn(const wchar_t *s1, const wchar_t *s2);
17163 wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);
17167 wchar_t *wcstok(wchar_t * restrict s1,
17168 const wchar_t * restrict s2,
17169 wchar_t ** restrict ptr);
17170 wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n);
17171 size_t wcslen(const wchar_t *s);
17172 wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);
17173 size_t wcsftime(wchar_t * restrict s, size_t maxsize,
17174 const wchar_t * restrict format,
17175 const struct tm * restrict timeptr);
17176 wint_t btowc(int c);
17177 int wctob(wint_t c);
17178 int mbsinit(const mbstate_t *ps);
17179 size_t mbrlen(const char * restrict s, size_t n,
17180 mbstate_t * restrict ps);
17181 size_t mbrtowc(wchar_t * restrict pwc,
17182 const char * restrict s, size_t n,
17183 mbstate_t * restrict ps);
17184 size_t wcrtomb(char * restrict s, wchar_t wc,
17185 mbstate_t * restrict ps);
17186 size_t mbsrtowcs(wchar_t * restrict dst,
17187 const char ** restrict src, size_t len,
17188 mbstate_t * restrict ps);
17189 size_t wcsrtombs(char * restrict dst,
17190 const wchar_t ** restrict src, size_t len,
17191 mbstate_t * restrict ps);
17192 B.24 Wide character classification and mapping utilities <wctype.h>
17193 wint_t wctrans_t wctype_t WEOF
17194 int iswalnum(wint_t wc);
17195 int iswalpha(wint_t wc);
17196 int iswblank(wint_t wc);
17197 int iswcntrl(wint_t wc);
17198 int iswdigit(wint_t wc);
17199 int iswgraph(wint_t wc);
17200 int iswlower(wint_t wc);
17201 int iswprint(wint_t wc);
17202 int iswpunct(wint_t wc);
17203 int iswspace(wint_t wc);
17204 int iswupper(wint_t wc);
17205 int iswxdigit(wint_t wc);
17206 int iswctype(wint_t wc, wctype_t desc);
17209 wctype_t wctype(const char *property);
17210 wint_t towlower(wint_t wc);
17211 wint_t towupper(wint_t wc);
17212 wint_t towctrans(wint_t wc, wctrans_t desc);
17213 wctrans_t wctrans(const char *property);
17223 1 The following are the sequence points described in 5.1.2.3:
17224 -- The call to a function, after the arguments have been evaluated (6.5.2.2).
17225 -- The end of the first operand of the following operators: logical AND && (6.5.13);
17226 logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17).
17227 -- The end of a full declarator: declarators (6.7.5);
17228 -- The end of a full expression: an initializer (6.7.8); the expression in an expression
17229 statement (6.8.3); the controlling expression of a selection statement (if or switch)
17230 (6.8.4); the controlling expression of a while or do statement (6.8.5); each of the
17231 expressions of a for statement (6.8.5.3); the expression in a return statement
17233 -- Immediately before a library function returns (7.1.4).
17234 -- After the actions associated with each formatted input/output function conversion
17235 specifier (7.19.6, 7.24.2).
17236 -- Immediately before and immediately after each call to a comparison function, and
17237 also between any call to a comparison function and any movement of the objects
17238 passed as arguments to that call (7.20.5).
17247 Universal character names for identifiers
17248 1 This clause lists the hexadecimal code values that are valid in universal character names
17250 2 This table is reproduced unchanged from ISO/IEC TR 10176:1998, produced by ISO/IEC
17251 JTC 1/SC 22/WG 20, except for the omission of ranges that are part of the basic character
17253 Latin: 00AA, 00BA, 00C0-00D6, 00D8-00F6, 00F8-01F5, 01FA-0217,
17254 0250-02A8, 1E00-1E9B, 1EA0-1EF9, 207F
17255 Greek: 0386, 0388-038A, 038C, 038E-03A1, 03A3-03CE, 03D0-03D6,
17256 03DA, 03DC, 03DE, 03E0, 03E2-03F3, 1F00-1F15, 1F18-1F1D,
17257 1F20-1F45, 1F48-1F4D, 1F50-1F57, 1F59, 1F5B, 1F5D,
17258 1F5F-1F7D, 1F80-1FB4, 1FB6-1FBC, 1FC2-1FC4, 1FC6-1FCC,
17259 1FD0-1FD3, 1FD6-1FDB, 1FE0-1FEC, 1FF2-1FF4, 1FF6-1FFC
17260 Cyrillic: 0401-040C, 040E-044F, 0451-045C, 045E-0481, 0490-04C4,
17261 04C7-04C8, 04CB-04CC, 04D0-04EB, 04EE-04F5, 04F8-04F9
17262 Armenian: 0531-0556, 0561-0587
17263 Hebrew: 05B0-05B9, 05BB-05BD, 05BF, 05C1-05C2, 05D0-05EA,
17265 Arabic: 0621-063A, 0640-0652, 0670-06B7, 06BA-06BE, 06C0-06CE,
17266 06D0-06DC, 06E5-06E8, 06EA-06ED
17267 Devanagari: 0901-0903, 0905-0939, 093E-094D, 0950-0952, 0958-0963
17268 Bengali: 0981-0983, 0985-098C, 098F-0990, 0993-09A8, 09AA-09B0,
17269 09B2, 09B6-09B9, 09BE-09C4, 09C7-09C8, 09CB-09CD,
17270 09DC-09DD, 09DF-09E3, 09F0-09F1
17271 Gurmukhi: 0A02, 0A05-0A0A, 0A0F-0A10, 0A13-0A28, 0A2A-0A30,
17272 0A32-0A33, 0A35-0A36, 0A38-0A39, 0A3E-0A42, 0A47-0A48,
17273 0A4B-0A4D, 0A59-0A5C, 0A5E, 0A74
17274 Gujarati: 0A81-0A83, 0A85-0A8B, 0A8D, 0A8F-0A91, 0A93-0AA8,
17275 0AAA-0AB0, 0AB2-0AB3, 0AB5-0AB9, 0ABD-0AC5,
17276 0AC7-0AC9, 0ACB-0ACD, 0AD0, 0AE0
17277 Oriya: 0B01-0B03, 0B05-0B0C, 0B0F-0B10, 0B13-0B28, 0B2A-0B30,
17278 0B32-0B33, 0B36-0B39, 0B3E-0B43, 0B47-0B48, 0B4B-0B4D,
17281 0B5C-0B5D, 0B5F-0B61
17282 Tamil: 0B82-0B83, 0B85-0B8A, 0B8E-0B90, 0B92-0B95, 0B99-0B9A,
17283 0B9C, 0B9E-0B9F, 0BA3-0BA4, 0BA8-0BAA, 0BAE-0BB5,
17284 0BB7-0BB9, 0BBE-0BC2, 0BC6-0BC8, 0BCA-0BCD
17285 Telugu: 0C01-0C03, 0C05-0C0C, 0C0E-0C10, 0C12-0C28, 0C2A-0C33,
17286 0C35-0C39, 0C3E-0C44, 0C46-0C48, 0C4A-0C4D, 0C60-0C61
17287 Kannada: 0C82-0C83, 0C85-0C8C, 0C8E-0C90, 0C92-0CA8, 0CAA-0CB3,
17288 0CB5-0CB9, 0CBE-0CC4, 0CC6-0CC8, 0CCA-0CCD, 0CDE,
17290 Malayalam: 0D02-0D03, 0D05-0D0C, 0D0E-0D10, 0D12-0D28, 0D2A-0D39,
17291 0D3E-0D43, 0D46-0D48, 0D4A-0D4D, 0D60-0D61
17292 Thai: 0E01-0E3A, 0E40-0E5B
17293 Lao: 0E81-0E82, 0E84, 0E87-0E88, 0E8A, 0E8D, 0E94-0E97,
17294 0E99-0E9F, 0EA1-0EA3, 0EA5, 0EA7, 0EAA-0EAB,
17295 0EAD-0EAE, 0EB0-0EB9, 0EBB-0EBD, 0EC0-0EC4, 0EC6,
17296 0EC8-0ECD, 0EDC-0EDD
17297 Tibetan: 0F00, 0F18-0F19, 0F35, 0F37, 0F39, 0F3E-0F47, 0F49-0F69,
17298 0F71-0F84, 0F86-0F8B, 0F90-0F95, 0F97, 0F99-0FAD,
17300 Georgian: 10A0-10C5, 10D0-10F6
17301 Hiragana: 3041-3093, 309B-309C
17302 Katakana: 30A1-30F6, 30FB-30FC
17303 Bopomofo: 3105-312C
17304 CJK Unified Ideographs: 4E00-9FA5
17306 Digits: 0660-0669, 06F0-06F9, 0966-096F, 09E6-09EF, 0A66-0A6F,
17307 0AE6-0AEF, 0B66-0B6F, 0BE7-0BEF, 0C66-0C6F, 0CE6-0CEF,
17308 0D66-0D6F, 0E50-0E59, 0ED0-0ED9, 0F20-0F33
17309 Special characters: 00B5, 00B7, 02B0-02B8, 02BB, 02BD-02C1, 02D0-02D1,
17310 02E0-02E4, 037A, 0559, 093D, 0B3D, 1FBE, 203F-2040, 2102,
17311 2107, 210A-2113, 2115, 2118-211D, 2124, 2126, 2128, 212A-2131,
17312 2133-2138, 2160-2182, 3005-3007, 3021-3029
17321 Implementation limits
17322 1 The contents of the header <limits.h> are given below, in alphabetical order. The
17323 minimum magnitudes shown shall be replaced by implementation-defined magnitudes
17324 with the same sign. The values shall all be constant expressions suitable for use in #if
17325 preprocessing directives. The components are described further in 5.2.4.2.1.
17327 #define CHAR_MAX UCHAR_MAX or SCHAR_MAX
17328 #define CHAR_MIN 0 or SCHAR_MIN
17329 #define INT_MAX +32767
17330 #define INT_MIN -32767
17331 #define LONG_MAX +2147483647
17332 #define LONG_MIN -2147483647
17333 #define LLONG_MAX +9223372036854775807
17334 #define LLONG_MIN -9223372036854775807
17335 #define MB_LEN_MAX 1
17336 #define SCHAR_MAX +127
17337 #define SCHAR_MIN -127
17338 #define SHRT_MAX +32767
17339 #define SHRT_MIN -32767
17340 #define UCHAR_MAX 255
17341 #define USHRT_MAX 65535
17342 #define UINT_MAX 65535
17343 #define ULONG_MAX 4294967295
17344 #define ULLONG_MAX 18446744073709551615
17345 2 The contents of the header <float.h> are given below. All integer values, except
17346 FLT_ROUNDS, shall be constant expressions suitable for use in #if preprocessing
17347 directives; all floating values shall be constant expressions. The components are
17348 described further in 5.2.4.2.2.
17349 3 The values given in the following list shall be replaced by implementation-defined
17351 #define FLT_EVAL_METHOD
17353 4 The values given in the following list shall be replaced by implementation-defined
17354 constant expressions that are greater or equal in magnitude (absolute value) to those
17355 shown, with the same sign:
17359 #define DBL_MANT_DIG
17360 #define DBL_MAX_10_EXP +37
17361 #define DBL_MAX_EXP
17362 #define DBL_MIN_10_EXP -37
17363 #define DBL_MIN_EXP
17364 #define DECIMAL_DIG 10
17366 #define FLT_MANT_DIG
17367 #define FLT_MAX_10_EXP +37
17368 #define FLT_MAX_EXP
17369 #define FLT_MIN_10_EXP -37
17370 #define FLT_MIN_EXP
17371 #define FLT_RADIX 2
17372 #define LDBL_DIG 10
17373 #define LDBL_MANT_DIG
17374 #define LDBL_MAX_10_EXP +37
17375 #define LDBL_MAX_EXP
17376 #define LDBL_MIN_10_EXP -37
17377 #define LDBL_MIN_EXP
17378 5 The values given in the following list shall be replaced by implementation-defined
17379 constant expressions with values that are greater than or equal to those shown:
17380 #define DBL_MAX 1E+37
17381 #define FLT_MAX 1E+37
17382 #define LDBL_MAX 1E+37
17383 6 The values given in the following list shall be replaced by implementation-defined
17384 constant expressions with (positive) values that are less than or equal to those shown:
17385 #define DBL_EPSILON 1E-9
17386 #define DBL_MIN 1E-37
17387 #define FLT_EPSILON 1E-5
17388 #define FLT_MIN 1E-37
17389 #define LDBL_EPSILON 1E-9
17390 #define LDBL_MIN 1E-37
17399 IEC 60559 floating-point arithmetic
17401 1 This annex specifies C language support for the IEC 60559 floating-point standard. The
17402 IEC 60559 floating-point standard is specifically Binary floating-point arithmetic for
17403 microprocessor systems, second edition (IEC 60559:1989), previously designated
17404 IEC 559:1989 and as IEEE Standard for Binary Floating-Point Arithmetic
17405 (ANSI/IEEE 754-1985). IEEE Standard for Radix-Independent Floating-Point
17406 Arithmetic (ANSI/IEEE 854-1987) generalizes the binary standard to remove
17407 dependencies on radix and word length. IEC 60559 generally refers to the floating-point
17408 standard, as in IEC 60559 operation, IEC 60559 format, etc. An implementation that
17409 defines __STDC_IEC_559__ shall conform to the specifications in this annex. Where
17410 a binding between the C language and IEC 60559 is indicated, the IEC 60559-specified
17411 behavior is adopted by reference, unless stated otherwise.
17413 1 The C floating types match the IEC 60559 formats as follows:
17414 -- The float type matches the IEC 60559 single format.
17415 -- The double type matches the IEC 60559 double format.
17416 -- The long double type matches an IEC 60559 extended format,307) else a
17417 non-IEC 60559 extended format, else the IEC 60559 double format.
17418 Any non-IEC 60559 extended format used for the long double type shall have more
17419 precision than IEC 60559 double and at least the range of IEC 60559 double.308)
17420 Recommended practice
17421 2 The long double type should match an IEC 60559 extended format.
17426 307) ''Extended'' is IEC 60559's double-extended data format. Extended refers to both the common 80-bit
17427 and quadruple 128-bit IEC 60559 formats.
17428 308) A non-IEC 60559 long double type is required to provide infinity and NaNs, as its values include
17433 F.2.1 Infinities, signed zeros, and NaNs
17434 1 This specification does not define the behavior of signaling NaNs.309) It generally uses
17435 the term NaN to denote quiet NaNs. The NAN and INFINITY macros and the nan
17436 functions in <math.h> provide designations for IEC 60559 NaNs and infinities.
17437 F.3 Operators and functions
17438 1 C operators and functions provide IEC 60559 required and recommended facilities as
17440 -- The +, -, *, and / operators provide the IEC 60559 add, subtract, multiply, and
17442 -- The sqrt functions in <math.h> provide the IEC 60559 square root operation.
17443 -- The remainder functions in <math.h> provide the IEC 60559 remainder
17444 operation. The remquo functions in <math.h> provide the same operation but
17445 with additional information.
17446 -- The rint functions in <math.h> provide the IEC 60559 operation that rounds a
17447 floating-point number to an integer value (in the same precision). The nearbyint
17448 functions in <math.h> provide the nearbyinteger function recommended in the
17449 Appendix to ANSI/IEEE 854.
17450 -- The conversions for floating types provide the IEC 60559 conversions between
17451 floating-point precisions.
17452 -- The conversions from integer to floating types provide the IEC 60559 conversions
17453 from integer to floating point.
17454 -- The conversions from floating to integer types provide IEC 60559-like conversions
17455 but always round toward zero.
17456 -- The lrint and llrint functions in <math.h> provide the IEC 60559
17457 conversions, which honor the directed rounding mode, from floating point to the
17458 long int and long long int integer formats. The lrint and llrint
17459 functions can be used to implement IEC 60559 conversions from floating to other
17461 -- The translation time conversion of floating constants and the strtod, strtof,
17462 strtold, fprintf, fscanf, and related library functions in <stdlib.h>,
17463 <stdio.h>, and <wchar.h> provide IEC 60559 binary-decimal conversions. The
17464 strtold function in <stdlib.h> provides the conv function recommended in the
17465 Appendix to ANSI/IEEE 854.
17467 309) Since NaNs created by IEC 60559 operations are always quiet, quiet NaNs (along with infinities) are
17468 sufficient for closure of the arithmetic.
17472 -- The relational and equality operators provide IEC 60559 comparisons. IEC 60559
17473 identifies a need for additional comparison predicates to facilitate writing code that
17474 accounts for NaNs. The comparison macros (isgreater, isgreaterequal,
17475 isless, islessequal, islessgreater, and isunordered) in <math.h>
17476 supplement the language operators to address this need. The islessgreater and
17477 isunordered macros provide respectively a quiet version of the <> predicate and
17478 the unordered predicate recommended in the Appendix to IEC 60559.
17479 -- The feclearexcept, feraiseexcept, and fetestexcept functions in
17480 <fenv.h> provide the facility to test and alter the IEC 60559 floating-point
17481 exception status flags. The fegetexceptflag and fesetexceptflag
17482 functions in <fenv.h> provide the facility to save and restore all five status flags at
17483 one time. These functions are used in conjunction with the type fexcept_t and the
17484 floating-point exception macros (FE_INEXACT, FE_DIVBYZERO,
17485 FE_UNDERFLOW, FE_OVERFLOW, FE_INVALID) also in <fenv.h>.
17486 -- The fegetround and fesetround functions in <fenv.h> provide the facility
17487 to select among the IEC 60559 directed rounding modes represented by the rounding
17488 direction macros in <fenv.h> (FE_TONEAREST, FE_UPWARD, FE_DOWNWARD,
17489 FE_TOWARDZERO) and the values 0, 1, 2, and 3 of FLT_ROUNDS are the
17490 IEC 60559 directed rounding modes.
17491 -- The fegetenv, feholdexcept, fesetenv, and feupdateenv functions in
17492 <fenv.h> provide a facility to manage the floating-point environment, comprising
17493 the IEC 60559 status flags and control modes.
17494 -- The copysign functions in <math.h> provide the copysign function
17495 recommended in the Appendix to IEC 60559.
17496 -- The unary minus (-) operator provides the minus (-) operation recommended in the
17497 Appendix to IEC 60559.
17498 -- The scalbn and scalbln functions in <math.h> provide the scalb function
17499 recommended in the Appendix to IEC 60559.
17500 -- The logb functions in <math.h> provide the logb function recommended in the
17501 Appendix to IEC 60559, but following the newer specifications in ANSI/IEEE 854.
17502 -- The nextafter and nexttoward functions in <math.h> provide the nextafter
17503 function recommended in the Appendix to IEC 60559 (but with a minor change to
17504 better handle signed zeros).
17505 -- The isfinite macro in <math.h> provides the finite function recommended in
17506 the Appendix to IEC 60559.
17507 -- The isnan macro in <math.h> provides the isnan function recommended in the
17508 Appendix to IEC 60559.
17512 -- The signbit macro and the fpclassify macro in <math.h>, used in
17513 conjunction with the number classification macros (FP_NAN, FP_INFINITE,
17514 FP_NORMAL, FP_SUBNORMAL, FP_ZERO), provide the facility of the class
17515 function recommended in the Appendix to IEC 60559 (except that the classification
17516 macros defined in 7.12.3 do not distinguish signaling from quiet NaNs).
17517 F.4 Floating to integer conversion
17518 1 If the floating value is infinite or NaN or if the integral part of the floating value exceeds
17519 the range of the integer type, then the ''invalid'' floating-point exception is raised and the
17520 resulting value is unspecified. Whether conversion of non-integer floating values whose
17521 integral part is within the range of the integer type raises the ''inexact'' floating-point
17522 exception is unspecified.310)
17523 F.5 Binary-decimal conversion
17524 1 Conversion from the widest supported IEC 60559 format to decimal with
17525 DECIMAL_DIG digits and back is the identity function.311)
17526 2 Conversions involving IEC 60559 formats follow all pertinent recommended practice. In
17527 particular, conversion between any supported IEC 60559 format and decimal with
17528 DECIMAL_DIG or fewer significant digits is correctly rounded (honoring the current
17529 rounding mode), which assures that conversion from the widest supported IEC 60559
17530 format to decimal with DECIMAL_DIG digits and back is the identity function.
17531 3 Functions such as strtod that convert character sequences to floating types honor the
17532 rounding direction. Hence, if the rounding direction might be upward or downward, the
17533 implementation cannot convert a minus-signed sequence by negating the converted
17539 310) ANSI/IEEE 854, but not IEC 60559 (ANSI/IEEE 754), directly specifies that floating-to-integer
17540 conversions raise the ''inexact'' floating-point exception for non-integer in-range values. In those
17541 cases where it matters, library functions can be used to effect such conversions with or without raising
17542 the ''inexact'' floating-point exception. See rint, lrint, llrint, and nearbyint in
17544 311) If the minimum-width IEC 60559 extended format (64 bits of precision) is supported,
17545 DECIMAL_DIG shall be at least 21. If IEC 60559 double (53 bits of precision) is the widest
17546 IEC 60559 format supported, then DECIMAL_DIG shall be at least 17. (By contrast, LDBL_DIG and
17547 DBL_DIG are 18 and 15, respectively, for these formats.)
17551 F.6 Contracted expressions
17552 1 A contracted expression treats infinities, NaNs, signed zeros, subnormals, and the
17553 rounding directions in a manner consistent with the basic arithmetic operations covered
17555 Recommended practice
17556 2 A contracted expression should raise floating-point exceptions in a manner generally
17557 consistent with the basic arithmetic operations. A contracted expression should deliver
17558 the same value as its uncontracted counterpart, else should be correctly rounded (once).
17559 F.7 Floating-point environment
17560 1 The floating-point environment defined in <fenv.h> includes the IEC 60559 floating-
17561 point exception status flags and directed-rounding control modes. It includes also
17562 IEC 60559 dynamic rounding precision and trap enablement modes, if the
17563 implementation supports them.312)
17564 F.7.1 Environment management
17565 1 IEC 60559 requires that floating-point operations implicitly raise floating-point exception
17566 status flags, and that rounding control modes can be set explicitly to affect result values of
17567 floating-point operations. When the state for the FENV_ACCESS pragma (defined in
17568 <fenv.h>) is ''on'', these changes to the floating-point state are treated as side effects
17569 which respect sequence points.313)
17571 1 During translation the IEC 60559 default modes are in effect:
17572 -- The rounding direction mode is rounding to nearest.
17573 -- The rounding precision mode (if supported) is set so that results are not shortened.
17574 -- Trapping or stopping (if supported) is disabled on all floating-point exceptions.
17575 Recommended practice
17576 2 The implementation should produce a diagnostic message for each translation-time
17581 312) This specification does not require dynamic rounding precision nor trap enablement modes.
17582 313) If the state for the FENV_ACCESS pragma is ''off'', the implementation is free to assume the floating-
17583 point control modes will be the default ones and the floating-point status flags will not be tested,
17584 which allows certain optimizations (see F.8).
17588 floating-point exception, other than ''inexact'';314) the implementation should then
17589 proceed with the translation of the program.
17591 1 At program startup the floating-point environment is initialized as prescribed by
17593 -- All floating-point exception status flags are cleared.
17594 -- The rounding direction mode is rounding to nearest.
17595 -- The dynamic rounding precision mode (if supported) is set so that results are not
17597 -- Trapping or stopping (if supported) is disabled on all floating-point exceptions.
17598 F.7.4 Constant expressions
17599 1 An arithmetic constant expression of floating type, other than one in an initializer for an
17600 object that has static storage duration, is evaluated (as if) during execution; thus, it is
17601 affected by any operative floating-point control modes and raises floating-point
17602 exceptions as required by IEC 60559 (provided the state for the FENV_ACCESS pragma
17606 #pragma STDC FENV_ACCESS ON
17609 float w[] = { 0.0/0.0 }; // raises an exception
17610 static float x = 0.0/0.0; // does not raise an exception
17611 float y = 0.0/0.0; // raises an exception
17612 double z = 0.0/0.0; // raises an exception
17615 3 For the static initialization, the division is done at translation time, raising no (execution-time) floating-
17616 point exceptions. On the other hand, for the three automatic initializations the invalid division occurs at
17619 314) As floating constants are converted to appropriate internal representations at translation time, their
17620 conversion is subject to default rounding modes and raises no execution-time floating-point exceptions
17621 (even where the state of the FENV_ACCESS pragma is ''on''). Library functions, for example
17622 strtod, provide execution-time conversion of numeric strings.
17623 315) Where the state for the FENV_ACCESS pragma is ''on'', results of inexact expressions like 1.0/3.0
17624 are affected by rounding modes set at execution time, and expressions such as 0.0/0.0 and
17625 1.0/0.0 generate execution-time floating-point exceptions. The programmer can achieve the
17626 efficiency of translation-time evaluation through static initialization, such as
17627 const static double one_third = 1.0/3.0;
17634 F.7.5 Initialization
17635 1 All computation for automatic initialization is done (as if) at execution time; thus, it is
17636 affected by any operative modes and raises floating-point exceptions as required by
17637 IEC 60559 (provided the state for the FENV_ACCESS pragma is ''on''). All computation
17638 for initialization of objects that have static storage duration is done (as if) at translation
17642 #pragma STDC FENV_ACCESS ON
17645 float u[] = { 1.1e75 }; // raises exceptions
17646 static float v = 1.1e75; // does not raise exceptions
17647 float w = 1.1e75; // raises exceptions
17648 double x = 1.1e75; // may raise exceptions
17649 float y = 1.1e75f; // may raise exceptions
17650 long double z = 1.1e75; // does not raise exceptions
17653 3 The static initialization of v raises no (execution-time) floating-point exceptions because its computation is
17654 done at translation time. The automatic initialization of u and w require an execution-time conversion to
17655 float of the wider value 1.1e75, which raises floating-point exceptions. The automatic initializations
17656 of x and y entail execution-time conversion; however, in some expression evaluation methods, the
17657 conversions is not to a narrower format, in which case no floating-point exception is raised.316) The
17658 automatic initialization of z entails execution-time conversion, but not to a narrower format, so no floating-
17659 point exception is raised. Note that the conversions of the floating constants 1.1e75 and 1.1e75f to
17660 their internal representations occur at translation time in all cases.
17665 316) Use of float_t and double_t variables increases the likelihood of translation-time computation.
17666 For example, the automatic initialization
17667 double_t x = 1.1e75;
17668 could be done at translation time, regardless of the expression evaluation method.
17672 F.7.6 Changing the environment
17673 1 Operations defined in 6.5 and functions and macros defined for the standard libraries
17674 change floating-point status flags and control modes just as indicated by their
17675 specifications (including conformance to IEC 60559). They do not change flags or modes
17676 (so as to be detectable by the user) in any other cases.
17677 2 If the argument to the feraiseexcept function in <fenv.h> represents IEC 60559
17678 valid coincident floating-point exceptions for atomic operations (namely ''overflow'' and
17679 ''inexact'', or ''underflow'' and ''inexact''), then ''overflow'' or ''underflow'' is raised
17680 before ''inexact''.
17682 1 This section identifies code transformations that might subvert IEC 60559-specified
17683 behavior, and others that do not.
17684 F.8.1 Global transformations
17685 1 Floating-point arithmetic operations and external function calls may entail side effects
17686 which optimization shall honor, at least where the state of the FENV_ACCESS pragma is
17687 ''on''. The flags and modes in the floating-point environment may be regarded as global
17688 variables; floating-point operations (+, *, etc.) implicitly read the modes and write the
17690 2 Concern about side effects may inhibit code motion and removal of seemingly useless
17691 code. For example, in
17693 #pragma STDC FENV_ACCESS ON
17697 for (i = 0; i < n; i++) x + 1;
17700 x + 1 might raise floating-point exceptions, so cannot be removed. And since the loop
17701 body might not execute (maybe 0 >= n), x + 1 cannot be moved out of the loop. (Of
17702 course these optimizations are valid if the implementation can rule out the nettlesome
17704 3 This specification does not require support for trap handlers that maintain information
17705 about the order or count of floating-point exceptions. Therefore, between function calls,
17706 floating-point exceptions need not be precise: the actual order and number of occurrences
17707 of floating-point exceptions (> 1) may vary from what the source code expresses. Thus,
17708 the preceding loop could be treated as
17712 F.8.2 Expression transformations
17713 1 x / 2 (<->) x * 0.5 Although similar transformations involving inexact
17714 constants generally do not yield numerically equivalent
17715 expressions, if the constants are exact then such
17716 transformations can be made on IEC 60559 machines
17717 and others that round perfectly.
17718 1 * x and x / 1 (->) x The expressions 1 * x, x / 1, and x are equivalent
17719 (on IEC 60559 machines, among others).317)
17720 x / x (->) 1.0 The expressions x / x and 1.0 are not equivalent if x
17721 can be zero, infinite, or NaN.
17722 x - y (<->) x + (-y) The expressions x - y, x + (-y), and (-y) + x
17723 are equivalent (on IEC 60559 machines, among others).
17724 x - y (<->) -(y - x) The expressions x - y and -(y - x) are not
17725 equivalent because 1 - 1 is +0 but -(1 - 1) is -0 (in the
17726 default rounding direction).318)
17727 x - x (->) 0.0 The expressions x - x and 0.0 are not equivalent if
17728 x is a NaN or infinite.
17729 0 * x (->) 0.0 The expressions 0 * x and 0.0 are not equivalent if
17730 x is a NaN, infinite, or -0.
17731 x + 0(->)x The expressions x + 0 and x are not equivalent if x is
17732 -0, because (-0) + (+0) yields +0 (in the default
17733 rounding direction), not -0.
17734 x - 0(->)x (+0) - (+0) yields -0 when rounding is downward
17735 (toward -(inf)), but +0 otherwise, and (-0) - (+0) always
17736 yields -0; so, if the state of the FENV_ACCESS pragma
17737 is ''off'', promising default rounding, then the
17738 implementation can replace x - 0 by x, even if x
17741 317) Strict support for signaling NaNs -- not required by this specification -- would invalidate these and
17742 other transformations that remove arithmetic operators.
17743 318) IEC 60559 prescribes a signed zero to preserve mathematical identities across certain discontinuities.
17745 1/(1/ (+-) (inf)) is (+-) (inf)
17747 conj(csqrt(z)) is csqrt(conj(z)),
17753 -x (<->) 0 - x The expressions -x and 0 - x are not equivalent if x
17754 is +0, because -(+0) yields -0, but 0 - (+0) yields +0
17755 (unless rounding is downward).
17756 F.8.3 Relational operators
17757 1 x != x (->) false The statement x != x is true if x is a NaN.
17758 x == x (->) true The statement x == x is false if x is a NaN.
17759 x < y (->) isless(x,y) (and similarly for <=, >, >=) Though numerically
17760 equal, these expressions are not equivalent because of
17761 side effects when x or y is a NaN and the state of the
17762 FENV_ACCESS pragma is ''on''. This transformation,
17763 which would be desirable if extra code were required to
17764 cause the ''invalid'' floating-point exception for
17765 unordered cases, could be performed provided the state
17766 of the FENV_ACCESS pragma is ''off''.
17767 The sense of relational operators shall be maintained. This includes handling unordered
17768 cases as expressed by the source code.
17770 // calls g and raises ''invalid'' if a and b are unordered
17775 is not equivalent to
17776 // calls f and raises ''invalid'' if a and b are unordered
17782 // calls f without raising ''invalid'' if a and b are unordered
17783 if (isgreaterequal(a,b))
17787 nor, unless the state of the FENV_ACCESS pragma is ''off'', to
17794 // calls g without raising ''invalid'' if a and b are unordered
17799 but is equivalent to
17805 F.8.4 Constant arithmetic
17806 1 The implementation shall honor floating-point exceptions raised by execution-time
17807 constant arithmetic wherever the state of the FENV_ACCESS pragma is ''on''. (See F.7.4
17808 and F.7.5.) An operation on constants that raises no floating-point exception can be
17809 folded during translation, except, if the state of the FENV_ACCESS pragma is ''on'', a
17810 further check is required to assure that changing the rounding direction to downward does
17811 not alter the sign of the result,319) and implementations that support dynamic rounding
17812 precision modes shall assure further that the result of the operation raises no floating-
17813 point exception when converted to the semantic type of the operation.
17814 F.9 Mathematics <math.h>
17815 1 This subclause contains specifications of <math.h> facilities that are particularly suited
17816 for IEC 60559 implementations.
17817 2 The Standard C macro HUGE_VAL and its float and long double analogs,
17818 HUGE_VALF and HUGE_VALL, expand to expressions whose values are positive
17820 3 Special cases for functions in <math.h> are covered directly or indirectly by
17821 IEC 60559. The functions that IEC 60559 specifies directly are identified in F.3. The
17822 other functions in <math.h> treat infinities, NaNs, signed zeros, subnormals, and
17823 (provided the state of the FENV_ACCESS pragma is ''on'') the floating-point status flags
17824 in a manner consistent with the basic arithmetic operations covered by IEC 60559.
17825 4 The expression math_errhandling & MATH_ERREXCEPT shall evaluate to a
17827 5 The ''invalid'' and ''divide-by-zero'' floating-point exceptions are raised as specified in
17828 subsequent subclauses of this annex.
17829 6 The ''overflow'' floating-point exception is raised whenever an infinity -- or, because of
17830 rounding direction, a maximal-magnitude finite number -- is returned in lieu of a value
17833 319) 0 - 0 yields -0 instead of +0 just when the rounding direction is downward.
17837 whose magnitude is too large.
17838 7 The ''underflow'' floating-point exception is raised whenever a result is tiny (essentially
17839 subnormal or zero) and suffers loss of accuracy.320)
17840 8 Whether or when library functions raise the ''inexact'' floating-point exception is
17841 unspecified, unless explicitly specified otherwise.
17842 9 Whether or when library functions raise an undeserved ''underflow'' floating-point
17843 exception is unspecified.321) Otherwise, as implied by F.7.6, the <math.h> functions do
17844 not raise spurious floating-point exceptions (detectable by the user), other than the
17845 ''inexact'' floating-point exception.
17846 10 Whether the functions honor the rounding direction mode is implementation-defined,
17847 unless explicitly specified otherwise.
17848 11 Functions with a NaN argument return a NaN result and raise no floating-point exception,
17849 except where stated otherwise.
17850 12 The specifications in the following subclauses append to the definitions in <math.h>.
17851 For families of functions, the specifications apply to all of the functions even though only
17852 the principal function is shown. Unless otherwise specified, where the symbol ''(+-)''
17853 occurs in both an argument and the result, the result has the same sign as the argument.
17854 Recommended practice
17855 13 If a function with one or more NaN arguments returns a NaN result, the result should be
17856 the same as one of the NaN arguments (after possible type conversion), except perhaps
17858 F.9.1 Trigonometric functions
17859 F.9.1.1 The acos functions
17860 1 -- acos(1) returns +0.
17861 -- acos(x) returns a NaN and raises the ''invalid'' floating-point exception for
17867 320) IEC 60559 allows different definitions of underflow. They all result in the same values, but differ on
17868 when the floating-point exception is raised.
17869 321) It is intended that undeserved ''underflow'' and ''inexact'' floating-point exceptions are raised only if
17870 avoiding them would be too costly.
17874 F.9.1.2 The asin functions
17875 1 -- asin((+-)0) returns (+-)0.
17876 -- asin(x) returns a NaN and raises the ''invalid'' floating-point exception for
17878 F.9.1.3 The atan functions
17879 1 -- atan((+-)0) returns (+-)0.
17880 -- atan((+-)(inf)) returns (+-)pi /2.
17881 F.9.1.4 The atan2 functions
17882 1 -- atan2((+-)0, -0) returns (+-)pi .322)
17883 -- atan2((+-)0, +0) returns (+-)0.
17884 -- atan2((+-)0, x) returns (+-)pi for x < 0.
17885 -- atan2((+-)0, x) returns (+-)0 for x > 0.
17886 -- atan2(y, (+-)0) returns -pi /2 for y < 0.
17887 -- atan2(y, (+-)0) returns pi /2 for y > 0.
17888 -- atan2((+-)y, -(inf)) returns (+-)pi for finite y > 0.
17889 -- atan2((+-)y, +(inf)) returns (+-)0 for finite y > 0.
17890 -- atan2((+-)(inf), x) returns (+-)pi /2 for finite x.
17891 -- atan2((+-)(inf), -(inf)) returns (+-)3pi /4.
17892 -- atan2((+-)(inf), +(inf)) returns (+-)pi /4.
17893 F.9.1.5 The cos functions
17894 1 -- cos((+-)0) returns 1.
17895 -- cos((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
17896 F.9.1.6 The sin functions
17897 1 -- sin((+-)0) returns (+-)0.
17898 -- sin((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
17903 322) atan2(0, 0) does not raise the ''invalid'' floating-point exception, nor does atan2( y , 0) raise
17904 the ''divide-by-zero'' floating-point exception.
17908 F.9.1.7 The tan functions
17909 1 -- tan((+-)0) returns (+-)0.
17910 -- tan((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
17911 F.9.2 Hyperbolic functions
17912 F.9.2.1 The acosh functions
17913 1 -- acosh(1) returns +0.
17914 -- acosh(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 1.
17915 -- acosh(+(inf)) returns +(inf).
17916 F.9.2.2 The asinh functions
17917 1 -- asinh((+-)0) returns (+-)0.
17918 -- asinh((+-)(inf)) returns (+-)(inf).
17919 F.9.2.3 The atanh functions
17920 1 -- atanh((+-)0) returns (+-)0.
17921 -- atanh((+-)1) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception.
17922 -- atanh(x) returns a NaN and raises the ''invalid'' floating-point exception for
17924 F.9.2.4 The cosh functions
17925 1 -- cosh((+-)0) returns 1.
17926 -- cosh((+-)(inf)) returns +(inf).
17927 F.9.2.5 The sinh functions
17928 1 -- sinh((+-)0) returns (+-)0.
17929 -- sinh((+-)(inf)) returns (+-)(inf).
17930 F.9.2.6 The tanh functions
17931 1 -- tanh((+-)0) returns (+-)0.
17932 -- tanh((+-)(inf)) returns (+-)1.
17939 F.9.3 Exponential and logarithmic functions
17940 F.9.3.1 The exp functions
17941 1 -- exp((+-)0) returns 1.
17942 -- exp(-(inf)) returns +0.
17943 -- exp(+(inf)) returns +(inf).
17944 F.9.3.2 The exp2 functions
17945 1 -- exp2((+-)0) returns 1.
17946 -- exp2(-(inf)) returns +0.
17947 -- exp2(+(inf)) returns +(inf).
17948 F.9.3.3 The expm1 functions
17949 1 -- expm1((+-)0) returns (+-)0.
17950 -- expm1(-(inf)) returns -1.
17951 -- expm1(+(inf)) returns +(inf).
17952 F.9.3.4 The frexp functions
17953 1 -- frexp((+-)0, exp) returns (+-)0, and stores 0 in the object pointed to by exp.
17954 -- frexp((+-)(inf), exp) returns (+-)(inf), and stores an unspecified value in the object
17956 -- frexp(NaN, exp) stores an unspecified value in the object pointed to by exp
17957 (and returns a NaN).
17958 2 frexp raises no floating-point exceptions.
17959 3 On a binary system, the body of the frexp function might be
17961 *exp = (value == 0) ? 0 : (int)(1 + logb(value));
17962 return scalbn(value, -(*exp));
17964 F.9.3.5 The ilogb functions
17965 1 If the correct result is outside the range of the return type, the numeric result is
17966 unspecified and the ''invalid'' floating-point exception is raised.
17973 F.9.3.6 The ldexp functions
17974 1 On a binary system, ldexp(x, exp) is equivalent to scalbn(x, exp).
17975 F.9.3.7 The log functions
17976 1 -- log((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
17977 -- log(1) returns +0.
17978 -- log(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
17979 -- log(+(inf)) returns +(inf).
17980 F.9.3.8 The log10 functions
17981 1 -- log10((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
17982 -- log10(1) returns +0.
17983 -- log10(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
17984 -- log10(+(inf)) returns +(inf).
17985 F.9.3.9 The log1p functions
17986 1 -- log1p((+-)0) returns (+-)0.
17987 -- log1p(-1) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
17988 -- log1p(x) returns a NaN and raises the ''invalid'' floating-point exception for
17990 -- log1p(+(inf)) returns +(inf).
17991 F.9.3.10 The log2 functions
17992 1 -- log2((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
17993 -- log2(1) returns +0.
17994 -- log2(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
17995 -- log2(+(inf)) returns +(inf).
17996 F.9.3.11 The logb functions
17997 1 -- logb((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
17998 -- logb((+-)(inf)) returns +(inf).
18005 F.9.3.12 The modf functions
18006 1 -- modf((+-)x, iptr) returns a result with the same sign as x.
18007 -- modf((+-)(inf), iptr) returns (+-)0 and stores (+-)(inf) in the object pointed to by iptr.
18008 -- modf(NaN, iptr) stores a NaN in the object pointed to by iptr (and returns a
18010 2 modf behaves as though implemented by
18013 #pragma STDC FENV_ACCESS ON
18014 double modf(double value, double *iptr)
18016 int save_round = fegetround();
18017 fesetround(FE_TOWARDZERO);
18018 *iptr = nearbyint(value);
18019 fesetround(save_round);
18021 isinf(value) ? 0.0 :
18022 value - (*iptr), value);
18024 F.9.3.13 The scalbn and scalbln functions
18025 1 -- scalbn((+-)0, n) returns (+-)0.
18026 -- scalbn(x, 0) returns x.
18027 -- scalbn((+-)(inf), n) returns (+-)(inf).
18028 F.9.4 Power and absolute value functions
18029 F.9.4.1 The cbrt functions
18030 1 -- cbrt((+-)0) returns (+-)0.
18031 -- cbrt((+-)(inf)) returns (+-)(inf).
18032 F.9.4.2 The fabs functions
18033 1 -- fabs((+-)0) returns +0.
18034 -- fabs((+-)(inf)) returns +(inf).
18041 F.9.4.3 The hypot functions
18042 1 -- hypot(x, y), hypot(y, x), and hypot(x, -y) are equivalent.
18043 -- hypot(x, (+-)0) is equivalent to fabs(x).
18044 -- hypot((+-)(inf), y) returns +(inf), even if y is a NaN.
18045 F.9.4.4 The pow functions
18046 1 -- pow((+-)0, y) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception
18047 for y an odd integer < 0.
18048 -- pow((+-)0, y) returns +(inf) and raises the ''divide-by-zero'' floating-point exception
18049 for y < 0 and not an odd integer.
18050 -- pow((+-)0, y) returns (+-)0 for y an odd integer > 0.
18051 -- pow((+-)0, y) returns +0 for y > 0 and not an odd integer.
18052 -- pow(-1, (+-)(inf)) returns 1.
18053 -- pow(+1, y) returns 1 for any y, even a NaN.
18054 -- pow(x, (+-)0) returns 1 for any x, even a NaN.
18055 -- pow(x, y) returns a NaN and raises the ''invalid'' floating-point exception for
18056 finite x < 0 and finite non-integer y.
18057 -- pow(x, -(inf)) returns +(inf) for | x | < 1.
18058 -- pow(x, -(inf)) returns +0 for | x | > 1.
18059 -- pow(x, +(inf)) returns +0 for | x | < 1.
18060 -- pow(x, +(inf)) returns +(inf) for | x | > 1.
18061 -- pow(-(inf), y) returns -0 for y an odd integer < 0.
18062 -- pow(-(inf), y) returns +0 for y < 0 and not an odd integer.
18063 -- pow(-(inf), y) returns -(inf) for y an odd integer > 0.
18064 -- pow(-(inf), y) returns +(inf) for y > 0 and not an odd integer.
18065 -- pow(+(inf), y) returns +0 for y < 0.
18066 -- pow(+(inf), y) returns +(inf) for y > 0.
18073 F.9.4.5 The sqrt functions
18074 1 sqrt is fully specified as a basic arithmetic operation in IEC 60559.
18075 F.9.5 Error and gamma functions
18076 F.9.5.1 The erf functions
18077 1 -- erf((+-)0) returns (+-)0.
18078 -- erf((+-)(inf)) returns (+-)1.
18079 F.9.5.2 The erfc functions
18080 1 -- erfc(-(inf)) returns 2.
18081 -- erfc(+(inf)) returns +0.
18082 F.9.5.3 The lgamma functions
18083 1 -- lgamma(1) returns +0.
18084 -- lgamma(2) returns +0.
18085 -- lgamma(x) returns +(inf) and raises the ''divide-by-zero'' floating-point exception for
18086 x a negative integer or zero.
18087 -- lgamma(-(inf)) returns +(inf).
18088 -- lgamma(+(inf)) returns +(inf).
18089 F.9.5.4 The tgamma functions
18090 1 -- tgamma((+-)0) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception.
18091 -- tgamma(x) returns a NaN and raises the ''invalid'' floating-point exception for x a
18093 -- tgamma(-(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
18094 -- tgamma(+(inf)) returns +(inf).
18095 F.9.6 Nearest integer functions
18096 F.9.6.1 The ceil functions
18097 1 -- ceil((+-)0) returns (+-)0.
18098 -- ceil((+-)(inf)) returns (+-)(inf).
18099 2 The double version of ceil behaves as though implemented by
18108 #pragma STDC FENV_ACCESS ON
18109 double ceil(double x)
18112 int save_round = fegetround();
18113 fesetround(FE_UPWARD);
18114 result = rint(x); // or nearbyint instead of rint
18115 fesetround(save_round);
18118 F.9.6.2 The floor functions
18119 1 -- floor((+-)0) returns (+-)0.
18120 -- floor((+-)(inf)) returns (+-)(inf).
18121 2 See the sample implementation for ceil in F.9.6.1.
18122 F.9.6.3 The nearbyint functions
18123 1 The nearbyint functions use IEC 60559 rounding according to the current rounding
18124 direction. They do not raise the ''inexact'' floating-point exception if the result differs in
18125 value from the argument.
18126 -- nearbyint((+-)0) returns (+-)0 (for all rounding directions).
18127 -- nearbyint((+-)(inf)) returns (+-)(inf) (for all rounding directions).
18128 F.9.6.4 The rint functions
18129 1 The rint functions differ from the nearbyint functions only in that they do raise the
18130 ''inexact'' floating-point exception if the result differs in value from the argument.
18131 F.9.6.5 The lrint and llrint functions
18132 1 The lrint and llrint functions provide floating-to-integer conversion as prescribed
18133 by IEC 60559. They round according to the current rounding direction. If the rounded
18134 value is outside the range of the return type, the numeric result is unspecified and the
18135 ''invalid'' floating-point exception is raised. When they raise no other floating-point
18136 exception and the result differs from the argument, they raise the ''inexact'' floating-point
18144 F.9.6.6 The round functions
18145 1 -- round((+-)0) returns (+-)0.
18146 -- round((+-)(inf)) returns (+-)(inf).
18147 2 The double version of round behaves as though implemented by
18150 #pragma STDC FENV_ACCESS ON
18151 double round(double x)
18155 feholdexcept(&save_env);
18157 if (fetestexcept(FE_INEXACT)) {
18158 fesetround(FE_TOWARDZERO);
18159 result = rint(copysign(0.5 + fabs(x), x));
18161 feupdateenv(&save_env);
18164 The round functions may, but are not required to, raise the ''inexact'' floating-point
18165 exception for non-integer numeric arguments, as this implementation does.
18166 F.9.6.7 The lround and llround functions
18167 1 The lround and llround functions differ from the lrint and llrint functions
18168 with the default rounding direction just in that the lround and llround functions
18169 round halfway cases away from zero and need not raise the ''inexact'' floating-point
18170 exception for non-integer arguments that round to within the range of the return type.
18171 F.9.6.8 The trunc functions
18172 1 The trunc functions use IEC 60559 rounding toward zero (regardless of the current
18173 rounding direction).
18174 -- trunc((+-)0) returns (+-)0.
18175 -- trunc((+-)(inf)) returns (+-)(inf).
18182 F.9.7 Remainder functions
18183 F.9.7.1 The fmod functions
18184 1 -- fmod((+-)0, y) returns (+-)0 for y not zero.
18185 -- fmod(x, y) returns a NaN and raises the ''invalid'' floating-point exception for x
18186 infinite or y zero.
18187 -- fmod(x, (+-)(inf)) returns x for x not infinite.
18188 2 The double version of fmod behaves as though implemented by
18191 #pragma STDC FENV_ACCESS ON
18192 double fmod(double x, double y)
18195 result = remainder(fabs(x), (y = fabs(y)));
18196 if (signbit(result)) result += y;
18197 return copysign(result, x);
18199 F.9.7.2 The remainder functions
18200 1 The remainder functions are fully specified as a basic arithmetic operation in
18202 F.9.7.3 The remquo functions
18203 1 The remquo functions follow the specifications for the remainder functions. They
18204 have no further specifications special to IEC 60559 implementations.
18205 F.9.8 Manipulation functions
18206 F.9.8.1 The copysign functions
18207 1 copysign is specified in the Appendix to IEC 60559.
18208 F.9.8.2 The nan functions
18209 1 All IEC 60559 implementations support quiet NaNs, in all floating formats.
18216 F.9.8.3 The nextafter functions
18217 1 -- nextafter(x, y) raises the ''overflow'' and ''inexact'' floating-point exceptions
18218 for x finite and the function value infinite.
18219 -- nextafter(x, y) raises the ''underflow'' and ''inexact'' floating-point
18220 exceptions for the function value subnormal or zero and x != y.
18221 F.9.8.4 The nexttoward functions
18222 1 No additional requirements beyond those on nextafter.
18223 F.9.9 Maximum, minimum, and positive difference functions
18224 F.9.9.1 The fdim functions
18225 1 No additional requirements.
18226 F.9.9.2 The fmax functions
18227 1 If just one argument is a NaN, the fmax functions return the other argument (if both
18228 arguments are NaNs, the functions return a NaN).
18229 2 The body of the fmax function might be323)
18230 { return (isgreaterequal(x, y) ||
18231 isnan(y)) ? x : y; }
18232 F.9.9.3 The fmin functions
18233 1 The fmin functions are analogous to the fmax functions (see F.9.9.2).
18234 F.9.10 Floating multiply-add
18235 F.9.10.1 The fma functions
18236 1 -- fma(x, y, z) computes xy + z, correctly rounded once.
18237 -- fma(x, y, z) returns a NaN and optionally raises the ''invalid'' floating-point
18238 exception if one of x and y is infinite, the other is zero, and z is a NaN.
18239 -- fma(x, y, z) returns a NaN and raises the ''invalid'' floating-point exception if
18240 one of x and y is infinite, the other is zero, and z is not a NaN.
18241 -- fma(x, y, z) returns a NaN and raises the ''invalid'' floating-point exception if x
18242 times y is an exact infinity and z is also an infinity but with the opposite sign.
18247 323) Ideally, fmax would be sensitive to the sign of zero, for example fmax(-0.0, +0.0) would
18248 return +0; however, implementation in software might be impractical.
18254 IEC 60559-compatible complex arithmetic
18256 1 This annex supplements annex F to specify complex arithmetic for compatibility with
18257 IEC 60559 real floating-point arithmetic. Although these specifications have been
18258 carefully designed, there is little existing practice to validate the design decisions.
18259 Therefore, these specifications are not normative, but should be viewed more as
18260 recommended practice. An implementation that defines
18261 __STDC_IEC_559_COMPLEX__ should conform to the specifications in this annex.
18263 1 There is a new keyword _Imaginary, which is used to specify imaginary types. It is
18264 used as a type specifier within declaration specifiers in the same way as _Complex is
18265 (thus, _Imaginary float is a valid type name).
18266 2 There are three imaginary types, designated as float _Imaginary, double
18267 _Imaginary, and long double _Imaginary. The imaginary types (along with
18268 the real floating and complex types) are floating types.
18269 3 For imaginary types, the corresponding real type is given by deleting the keyword
18270 _Imaginary from the type name.
18271 4 Each imaginary type has the same representation and alignment requirements as the
18272 corresponding real type. The value of an object of imaginary type is the value of the real
18273 representation times the imaginary unit.
18274 5 The imaginary type domain comprises the imaginary types.
18276 1 A complex or imaginary value with at least one infinite part is regarded as an infinity
18277 (even if its other part is a NaN). A complex or imaginary value is a finite number if each
18278 of its parts is a finite number (neither infinite nor NaN). A complex or imaginary value is
18279 a zero if each of its parts is a zero.
18287 G.4.1 Imaginary types
18288 1 Conversions among imaginary types follow rules analogous to those for real floating
18290 G.4.2 Real and imaginary
18291 1 When a value of imaginary type is converted to a real type other than _Bool,324) the
18292 result is a positive zero.
18293 2 When a value of real type is converted to an imaginary type, the result is a positive
18295 G.4.3 Imaginary and complex
18296 1 When a value of imaginary type is converted to a complex type, the real part of the
18297 complex result value is a positive zero and the imaginary part of the complex result value
18298 is determined by the conversion rules for the corresponding real types.
18299 2 When a value of complex type is converted to an imaginary type, the real part of the
18300 complex value is discarded and the value of the imaginary part is converted according to
18301 the conversion rules for the corresponding real types.
18302 G.5 Binary operators
18303 1 The following subclauses supplement 6.5 in order to specify the type of the result for an
18304 operation with an imaginary operand.
18305 2 For most operand types, the value of the result of a binary operator with an imaginary or
18306 complex operand is completely determined, with reference to real arithmetic, by the usual
18307 mathematical formula. For some operand types, the usual mathematical formula is
18308 problematic because of its treatment of infinities and because of undue overflow or
18309 underflow; in these cases the result satisfies certain properties (specified in G.5.1), but is
18310 not completely determined.
18319 G.5.1 Multiplicative operators
18321 1 If one operand has real type and the other operand has imaginary type, then the result has
18322 imaginary type. If both operands have imaginary type, then the result has real type. (If
18323 either operand has complex type, then the result has complex type.)
18324 2 If the operands are not both complex, then the result and floating-point exception
18325 behavior of the * operator is defined by the usual mathematical formula:
18328 x xu i(xv) (xu) + i(xv)
18330 iy i(yu) -yv (-yv) + i(yu)
18332 x + iy (xu) + i(yu) (-yv) + i(xv)
18333 3 If the second operand is not complex, then the result and floating-point exception
18334 behavior of the / operator is defined by the usual mathematical formula:
18341 x + iy (x/u) + i(y/u) (y/v) + i(-x/v)
18342 4 The * and / operators satisfy the following infinity properties for all real, imaginary, and
18343 complex operands:325)
18344 -- if one operand is an infinity and the other operand is a nonzero finite number or an
18345 infinity, then the result of the * operator is an infinity;
18346 -- if the first operand is an infinity and the second operand is a finite number, then the
18347 result of the / operator is an infinity;
18348 -- if the first operand is a finite number and the second operand is an infinity, then the
18349 result of the / operator is a zero;
18354 325) These properties are already implied for those cases covered in the tables, but are required for all cases
18355 (at least where the state for CX_LIMITED_RANGE is ''off'').
18359 -- if the first operand is a nonzero finite number or an infinity and the second operand is
18360 a zero, then the result of the / operator is an infinity.
18361 5 If both operands of the * operator are complex or if the second operand of the / operator
18362 is complex, the operator raises floating-point exceptions if appropriate for the calculation
18363 of the parts of the result, and may raise spurious floating-point exceptions.
18364 6 EXAMPLE 1 Multiplication of double _Complex operands could be implemented as follows. Note
18365 that the imaginary unit I has imaginary type (see G.6).
18367 #include <complex.h>
18368 /* Multiply z * w ... */
18369 double complex _Cmultd(double complex z, double complex w)
18371 #pragma STDC FP_CONTRACT OFF
18372 double a, b, c, d, ac, bd, ad, bc, x, y;
18373 a = creal(z); b = cimag(z);
18374 c = creal(w); d = cimag(w);
18375 ac = a * c; bd = b * d;
18376 ad = a * d; bc = b * c;
18377 x = ac - bd; y = ad + bc;
18378 if (isnan(x) && isnan(y)) {
18379 /* Recover infinities that computed as NaN+iNaN ... */
18381 if ( isinf(a) || isinf(b) ) { // z is infinite
18382 /* "Box" the infinity and change NaNs in the other factor to 0 */
18383 a = copysign(isinf(a) ? 1.0 : 0.0, a);
18384 b = copysign(isinf(b) ? 1.0 : 0.0, b);
18385 if (isnan(c)) c = copysign(0.0, c);
18386 if (isnan(d)) d = copysign(0.0, d);
18389 if ( isinf(c) || isinf(d) ) { // w is infinite
18390 /* "Box" the infinity and change NaNs in the other factor to 0 */
18391 c = copysign(isinf(c) ? 1.0 : 0.0, c);
18392 d = copysign(isinf(d) ? 1.0 : 0.0, d);
18393 if (isnan(a)) a = copysign(0.0, a);
18394 if (isnan(b)) b = copysign(0.0, b);
18397 if (!recalc && (isinf(ac) || isinf(bd) ||
18398 isinf(ad) || isinf(bc))) {
18399 /* Recover infinities from overflow by changing NaNs to 0 ... */
18400 if (isnan(a)) a = copysign(0.0, a);
18401 if (isnan(b)) b = copysign(0.0, b);
18402 if (isnan(c)) c = copysign(0.0, c);
18403 if (isnan(d)) d = copysign(0.0, d);
18410 x = INFINITY * ( a * c - b * d );
18411 y = INFINITY * ( a * d + b * c );
18416 7 This implementation achieves the required treatment of infinities at the cost of only one isnan test in
18417 ordinary (finite) cases. It is less than ideal in that undue overflow and underflow may occur.
18419 8 EXAMPLE 2 Division of two double _Complex operands could be implemented as follows.
18421 #include <complex.h>
18422 /* Divide z / w ... */
18423 double complex _Cdivd(double complex z, double complex w)
18425 #pragma STDC FP_CONTRACT OFF
18426 double a, b, c, d, logbw, denom, x, y;
18428 a = creal(z); b = cimag(z);
18429 c = creal(w); d = cimag(w);
18430 logbw = logb(fmax(fabs(c), fabs(d)));
18431 if (isfinite(logbw)) {
18432 ilogbw = (int)logbw;
18433 c = scalbn(c, -ilogbw); d = scalbn(d, -ilogbw);
18435 denom = c * c + d * d;
18436 x = scalbn((a * c + b * d) / denom, -ilogbw);
18437 y = scalbn((b * c - a * d) / denom, -ilogbw);
18438 /* Recover infinities and zeros that computed as NaN+iNaN; */
18439 /* the only cases are nonzero/zero, infinite/finite, and finite/infinite, ... */
18440 if (isnan(x) && isnan(y)) {
18441 if ((denom == 0.0) &&
18442 (!isnan(a) || !isnan(b))) {
18443 x = copysign(INFINITY, c) * a;
18444 y = copysign(INFINITY, c) * b;
18446 else if ((isinf(a) || isinf(b)) &&
18447 isfinite(c) && isfinite(d)) {
18448 a = copysign(isinf(a) ? 1.0 : 0.0, a);
18449 b = copysign(isinf(b) ? 1.0 : 0.0, b);
18450 x = INFINITY * ( a * c + b * d );
18451 y = INFINITY * ( b * c - a * d );
18453 else if (isinf(logbw) &&
18454 isfinite(a) && isfinite(b)) {
18455 c = copysign(isinf(c) ? 1.0 : 0.0, c);
18456 d = copysign(isinf(d) ? 1.0 : 0.0, d);
18457 x = 0.0 * ( a * c + b * d );
18458 y = 0.0 * ( b * c - a * d );
18466 9 Scaling the denominator alleviates the main overflow and underflow problem, which is more serious than
18467 for multiplication. In the spirit of the multiplication example above, this code does not defend against
18468 overflow and underflow in the calculation of the numerator. Scaling with the scalbn function, instead of
18469 with division, provides better roundoff characteristics.
18471 G.5.2 Additive operators
18473 1 If both operands have imaginary type, then the result has imaginary type. (If one operand
18474 has real type and the other operand has imaginary type, or if either operand has complex
18475 type, then the result has complex type.)
18476 2 In all cases the result and floating-point exception behavior of a + or - operator is defined
18477 by the usual mathematical formula:
18480 x x(+-)u x (+-) iv (x (+-) u) (+-) iv
18482 iy (+-)u + iy i(y (+-) v) (+-)u + i(y (+-) v)
18484 x + iy (x (+-) u) + iy x + i(y (+-) v) (x (+-) u) + i(y (+-) v)
18485 G.6 Complex arithmetic <complex.h>
18490 are defined, respectively, as _Imaginary and a constant expression of type const
18491 float _Imaginary with the value of the imaginary unit. The macro
18493 is defined to be _Imaginary_I (not _Complex_I as stated in 7.3). Notwithstanding
18494 the provisions of 7.1.3, a program may undefine and then perhaps redefine the macro
18496 2 This subclause contains specifications for the <complex.h> functions that are
18497 particularly suited to IEC 60559 implementations. For families of functions, the
18498 specifications apply to all of the functions even though only the principal function is
18502 shown. Unless otherwise specified, where the symbol ''(+-)'' occurs in both an argument
18503 and the result, the result has the same sign as the argument.
18504 3 The functions are continuous onto both sides of their branch cuts, taking into account the
18505 sign of zero. For example, csqrt(-2 (+-) i0) = (+-)isqrt:2. ???
18506 4 Since complex and imaginary values are composed of real values, each function may be
18507 regarded as computing real values from real values. Except as noted, the functions treat
18508 real infinities, NaNs, signed zeros, subnormals, and the floating-point exception flags in a
18509 manner consistent with the specifications for real functions in F.9.326)
18510 5 The functions cimag, conj, cproj, and creal are fully specified for all
18511 implementations, including IEC 60559 ones, in 7.3.9. These functions raise no floating-
18513 6 Each of the functions cabs and carg is specified by a formula in terms of a real
18514 function (whose special cases are covered in annex F):
18515 cabs(x + iy) = hypot(x, y)
18516 carg(x + iy) = atan2(y, x)
18517 7 Each of the functions casin, catan, ccos, csin, and ctan is specified implicitly by
18518 a formula in terms of other complex functions (whose special cases are specified below):
18519 casin(z) = -i casinh(iz)
18520 catan(z) = -i catanh(iz)
18521 ccos(z) = ccosh(iz)
18522 csin(z) = -i csinh(iz)
18523 ctan(z) = -i ctanh(iz)
18524 8 For the other functions, the following subclauses specify behavior for special cases,
18525 including treatment of the ''invalid'' and ''divide-by-zero'' floating-point exceptions. For
18526 families of functions, the specifications apply to all of the functions even though only the
18527 principal function is shown. For a function f satisfying f (conj(z)) = conj( f (z)), the
18528 specifications for the upper half-plane imply the specifications for the lower half-plane; if
18529 the function f is also either even, f (-z) = f (z), or odd, f (-z) = - f (z), then the
18530 specifications for the first quadrant imply the specifications for the other three quadrants.
18531 9 In the following subclauses, cis(y) is defined as cos(y) + i sin(y).
18536 326) As noted in G.3, a complex value with at least one infinite part is regarded as an infinity even if its
18537 other part is a NaN.
18541 G.6.1 Trigonometric functions
18542 G.6.1.1 The cacos functions
18543 1 -- cacos(conj(z)) = conj(cacos(z)).
18544 -- cacos((+-)0 + i0) returns pi /2 - i0.
18545 -- cacos((+-)0 + iNaN) returns pi /2 + iNaN.
18546 -- cacos(x + i (inf)) returns pi /2 - i (inf), for finite x.
18547 -- cacos(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18548 point exception, for nonzero finite x.
18549 -- cacos(-(inf) + iy) returns pi - i (inf), for positive-signed finite y.
18550 -- cacos(+(inf) + iy) returns +0 - i (inf), for positive-signed finite y.
18551 -- cacos(-(inf) + i (inf)) returns 3pi /4 - i (inf).
18552 -- cacos(+(inf) + i (inf)) returns pi /4 - i (inf).
18553 -- cacos((+-)(inf) + iNaN) returns NaN (+-) i (inf) (where the sign of the imaginary part of the
18554 result is unspecified).
18555 -- cacos(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18556 point exception, for finite y.
18557 -- cacos(NaN + i (inf)) returns NaN - i (inf).
18558 -- cacos(NaN + iNaN) returns NaN + iNaN.
18559 G.6.2 Hyperbolic functions
18560 G.6.2.1 The cacosh functions
18561 1 -- cacosh(conj(z)) = conj(cacosh(z)).
18562 -- cacosh((+-)0 + i0) returns +0 + ipi /2.
18563 -- cacosh(x + i (inf)) returns +(inf) + ipi /2, for finite x.
18564 -- cacosh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
18565 floating-point exception, for finite x.
18566 -- cacosh(-(inf) + iy) returns +(inf) + ipi , for positive-signed finite y.
18567 -- cacosh(+(inf) + iy) returns +(inf) + i0, for positive-signed finite y.
18568 -- cacosh(-(inf) + i (inf)) returns +(inf) + i3pi /4.
18569 -- cacosh(+(inf) + i (inf)) returns +(inf) + ipi /4.
18570 -- cacosh((+-)(inf) + iNaN) returns +(inf) + iNaN.
18575 -- cacosh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
18576 floating-point exception, for finite y.
18577 -- cacosh(NaN + i (inf)) returns +(inf) + iNaN.
18578 -- cacosh(NaN + iNaN) returns NaN + iNaN.
18579 G.6.2.2 The casinh functions
18580 1 -- casinh(conj(z)) = conj(casinh(z)) and casinh is odd.
18581 -- casinh(+0 + i0) returns 0 + i0.
18582 -- casinh(x + i (inf)) returns +(inf) + ipi /2 for positive-signed finite x.
18583 -- casinh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
18584 floating-point exception, for finite x.
18585 -- casinh(+(inf) + iy) returns +(inf) + i0 for positive-signed finite y.
18586 -- casinh(+(inf) + i (inf)) returns +(inf) + ipi /4.
18587 -- casinh(+(inf) + iNaN) returns +(inf) + iNaN.
18588 -- casinh(NaN + i0) returns NaN + i0.
18589 -- casinh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
18590 floating-point exception, for finite nonzero y.
18591 -- casinh(NaN + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result
18593 -- casinh(NaN + iNaN) returns NaN + iNaN.
18594 G.6.2.3 The catanh functions
18595 1 -- catanh(conj(z)) = conj(catanh(z)) and catanh is odd.
18596 -- catanh(+0 + i0) returns +0 + i0.
18597 -- catanh(+0 + iNaN) returns +0 + iNaN.
18598 -- catanh(+1 + i0) returns +(inf) + i0 and raises the ''divide-by-zero'' floating-point
18600 -- catanh(x + i (inf)) returns +0 + ipi /2, for finite positive-signed x.
18601 -- catanh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
18602 floating-point exception, for nonzero finite x.
18603 -- catanh(+(inf) + iy) returns +0 + ipi /2, for finite positive-signed y.
18604 -- catanh(+(inf) + i (inf)) returns +0 + ipi /2.
18605 -- catanh(+(inf) + iNaN) returns +0 + iNaN.
18609 -- catanh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
18610 floating-point exception, for finite y.
18611 -- catanh(NaN + i (inf)) returns (+-)0 + ipi /2 (where the sign of the real part of the result is
18613 -- catanh(NaN + iNaN) returns NaN + iNaN.
18614 G.6.2.4 The ccosh functions
18615 1 -- ccosh(conj(z)) = conj(ccosh(z)) and ccosh is even.
18616 -- ccosh(+0 + i0) returns 1 + i0.
18617 -- ccosh(+0 + i (inf)) returns NaN (+-) i0 (where the sign of the imaginary part of the
18618 result is unspecified) and raises the ''invalid'' floating-point exception.
18619 -- ccosh(+0 + iNaN) returns NaN (+-) i0 (where the sign of the imaginary part of the
18620 result is unspecified).
18621 -- ccosh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
18622 exception, for finite nonzero x.
18623 -- ccosh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18624 point exception, for finite nonzero x.
18625 -- ccosh(+(inf) + i0) returns +(inf) + i0.
18626 -- ccosh(+(inf) + iy) returns +(inf) cis(y), for finite nonzero y.
18627 -- ccosh(+(inf) + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result is
18628 unspecified) and raises the ''invalid'' floating-point exception.
18629 -- ccosh(+(inf) + iNaN) returns +(inf) + iNaN.
18630 -- ccosh(NaN + i0) returns NaN (+-) i0 (where the sign of the imaginary part of the
18631 result is unspecified).
18632 -- ccosh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18633 point exception, for all nonzero numbers y.
18634 -- ccosh(NaN + iNaN) returns NaN + iNaN.
18635 G.6.2.5 The csinh functions
18636 1 -- csinh(conj(z)) = conj(csinh(z)) and csinh is odd.
18637 -- csinh(+0 + i0) returns +0 + i0.
18638 -- csinh(+0 + i (inf)) returns (+-)0 + iNaN (where the sign of the real part of the result is
18639 unspecified) and raises the ''invalid'' floating-point exception.
18640 -- csinh(+0 + iNaN) returns (+-)0 + iNaN (where the sign of the real part of the result is
18644 -- csinh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
18645 exception, for positive finite x.
18646 -- csinh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18647 point exception, for finite nonzero x.
18648 -- csinh(+(inf) + i0) returns +(inf) + i0.
18649 -- csinh(+(inf) + iy) returns +(inf) cis(y), for positive finite y.
18650 -- csinh(+(inf) + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result is
18651 unspecified) and raises the ''invalid'' floating-point exception.
18652 -- csinh(+(inf) + iNaN) returns (+-)(inf) + iNaN (where the sign of the real part of the result
18654 -- csinh(NaN + i0) returns NaN + i0.
18655 -- csinh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18656 point exception, for all nonzero numbers y.
18657 -- csinh(NaN + iNaN) returns NaN + iNaN.
18658 G.6.2.6 The ctanh functions
18659 1 -- ctanh(conj(z)) = conj(ctanh(z))and ctanh is odd.
18660 -- ctanh(+0 + i0) returns +0 + i0.
18661 -- ctanh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
18662 exception, for finite x.
18663 -- ctanh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18664 point exception, for finite x.
18665 -- ctanh(+(inf) + iy) returns 1 + i0 sin(2y), for positive-signed finite y.
18666 -- ctanh(+(inf) + i (inf)) returns 1 (+-) i0 (where the sign of the imaginary part of the result
18668 -- ctanh(+(inf) + iNaN) returns 1 (+-) i0 (where the sign of the imaginary part of the
18669 result is unspecified).
18670 -- ctanh(NaN + i0) returns NaN + i0.
18671 -- ctanh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18672 point exception, for all nonzero numbers y.
18673 -- ctanh(NaN + iNaN) returns NaN + iNaN.
18680 G.6.3 Exponential and logarithmic functions
18681 G.6.3.1 The cexp functions
18682 1 -- cexp(conj(z)) = conj(cexp(z)).
18683 -- cexp((+-)0 + i0) returns 1 + i0.
18684 -- cexp(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
18685 exception, for finite x.
18686 -- cexp(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18687 point exception, for finite x.
18688 -- cexp(+(inf) + i0) returns +(inf) + i0.
18689 -- cexp(-(inf) + iy) returns +0 cis(y), for finite y.
18690 -- cexp(+(inf) + iy) returns +(inf) cis(y), for finite nonzero y.
18691 -- cexp(-(inf) + i (inf)) returns (+-)0 (+-) i0 (where the signs of the real and imaginary parts of
18692 the result are unspecified).
18693 -- cexp(+(inf) + i (inf)) returns (+-)(inf) + iNaN and raises the ''invalid'' floating-point
18694 exception (where the sign of the real part of the result is unspecified).
18695 -- cexp(-(inf) + iNaN) returns (+-)0 (+-) i0 (where the signs of the real and imaginary parts
18696 of the result are unspecified).
18697 -- cexp(+(inf) + iNaN) returns (+-)(inf) + iNaN (where the sign of the real part of the result
18699 -- cexp(NaN + i0) returns NaN + i0.
18700 -- cexp(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18701 point exception, for all nonzero numbers y.
18702 -- cexp(NaN + iNaN) returns NaN + iNaN.
18703 G.6.3.2 The clog functions
18704 1 -- clog(conj(z)) = conj(clog(z)).
18705 -- clog(-0 + i0) returns -(inf) + ipi and raises the ''divide-by-zero'' floating-point
18707 -- clog(+0 + i0) returns -(inf) + i0 and raises the ''divide-by-zero'' floating-point
18709 -- clog(x + i (inf)) returns +(inf) + ipi /2, for finite x.
18710 -- clog(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18711 point exception, for finite x.
18715 -- clog(-(inf) + iy) returns +(inf) + ipi , for finite positive-signed y.
18716 -- clog(+(inf) + iy) returns +(inf) + i0, for finite positive-signed y.
18717 -- clog(-(inf) + i (inf)) returns +(inf) + i3pi /4.
18718 -- clog(+(inf) + i (inf)) returns +(inf) + ipi /4.
18719 -- clog((+-)(inf) + iNaN) returns +(inf) + iNaN.
18720 -- clog(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18721 point exception, for finite y.
18722 -- clog(NaN + i (inf)) returns +(inf) + iNaN.
18723 -- clog(NaN + iNaN) returns NaN + iNaN.
18724 G.6.4 Power and absolute-value functions
18725 G.6.4.1 The cpow functions
18726 1 The cpow functions raise floating-point exceptions if appropriate for the calculation of
18727 the parts of the result, and may raise spurious exceptions.327)
18728 G.6.4.2 The csqrt functions
18729 1 -- csqrt(conj(z)) = conj(csqrt(z)).
18730 -- csqrt((+-)0 + i0) returns +0 + i0.
18731 -- csqrt(x + i (inf)) returns +(inf) + i (inf), for all x (including NaN).
18732 -- csqrt(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18733 point exception, for finite x.
18734 -- csqrt(-(inf) + iy) returns +0 + i (inf), for finite positive-signed y.
18735 -- csqrt(+(inf) + iy) returns +(inf) + i0, for finite positive-signed y.
18736 -- csqrt(-(inf) + iNaN) returns NaN (+-) i (inf) (where the sign of the imaginary part of the
18737 result is unspecified).
18738 -- csqrt(+(inf) + iNaN) returns +(inf) + iNaN.
18739 -- csqrt(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
18740 point exception, for finite y.
18741 -- csqrt(NaN + iNaN) returns NaN + iNaN.
18746 327) This allows cpow( z , c ) to be implemented as cexp(c clog( z )) without precluding
18747 implementations that treat special cases more carefully.
18751 G.7 Type-generic math <tgmath.h>
18752 1 Type-generic macros that accept complex arguments also accept imaginary arguments. If
18753 an argument is imaginary, the macro expands to an expression whose type is real,
18754 imaginary, or complex, as appropriate for the particular function: if the argument is
18755 imaginary, then the types of cos, cosh, fabs, carg, cimag, and creal are real; the
18756 types of sin, tan, sinh, tanh, asin, atan, asinh, and atanh are imaginary; and
18757 the types of the others are complex.
18758 2 Given an imaginary argument, each of the type-generic macros cos, sin, tan, cosh,
18759 sinh, tanh, asin, atan, asinh, atanh is specified by a formula in terms of real
18762 sin(iy) = i sinh(y)
18763 tan(iy) = i tanh(y)
18765 sinh(iy) = i sin(y)
18766 tanh(iy) = i tan(y)
18767 asin(iy) = i asinh(y)
18768 atan(iy) = i atanh(y)
18769 asinh(iy) = i asin(y)
18770 atanh(iy) = i atan(y)
18779 Language independent arithmetic
18781 1 This annex documents the extent to which the C language supports the ISO/IEC 10967-1
18782 standard for language-independent arithmetic (LIA-1). LIA-1 is more general than
18783 IEC 60559 (annex F) in that it covers integer and diverse floating-point arithmetics.
18785 1 The relevant C arithmetic types meet the requirements of LIA-1 types if an
18786 implementation adds notification of exceptional arithmetic operations and meets the 1
18787 unit in the last place (ULP) accuracy requirement (LIA-1 subclause 5.2.8).
18789 1 The LIA-1 data type Boolean is implemented by the C data type bool with values of
18790 true and false, all from <stdbool.h>.
18791 H.2.2 Integer types
18792 1 The signed C integer types int, long int, long long int, and the corresponding
18793 unsigned types are compatible with LIA-1. If an implementation adds support for the
18794 LIA-1 exceptional values ''integer_overflow'' and ''undefined'', then those types are
18795 LIA-1 conformant types. C's unsigned integer types are ''modulo'' in the LIA-1 sense
18796 in that overflows or out-of-bounds results silently wrap. An implementation that defines
18797 signed integer types as also being modulo need not detect integer overflow, in which case,
18798 only integer divide-by-zero need be detected.
18799 2 The parameters for the integer data types can be accessed by the following:
18800 maxint INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX,
18802 minint INT_MIN, LONG_MIN, LLONG_MIN
18803 3 The parameter ''bounded'' is always true, and is not provided. The parameter ''minint''
18804 is always 0 for the unsigned types, and is not provided for those types.
18811 H.2.2.1 Integer operations
18812 1 The integer operations on integer types are the following:
18819 absI abs(x), labs(x), llabs(x)
18826 where x and y are expressions of the same integer type.
18827 H.2.3 Floating-point types
18828 1 The C floating-point types float, double, and long double are compatible with
18829 LIA-1. If an implementation adds support for the LIA-1 exceptional values
18830 ''underflow'', ''floating_overflow'', and ''"undefined'', then those types are conformant
18831 with LIA-1. An implementation that uses IEC 60559 floating-point formats and
18832 operations (see annex F) along with IEC 60559 status flags and traps has LIA-1
18834 H.2.3.1 Floating-point parameters
18835 1 The parameters for a floating point data type can be accessed by the following:
18837 p FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG
18838 emax FLT_MAX_EXP, DBL_MAX_EXP, LDBL_MAX_EXP
18839 emin FLT_MIN_EXP, DBL_MIN_EXP, LDBL_MIN_EXP
18840 2 The derived constants for the floating point types are accessed by the following:
18845 fmax FLT_MAX, DBL_MAX, LDBL_MAX
18846 fminN FLT_MIN, DBL_MIN, LDBL_MIN
18847 epsilon FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON
18848 rnd_style FLT_ROUNDS
18849 H.2.3.2 Floating-point operations
18850 1 The floating-point operations on floating-point types are the following:
18856 absF fabsf(x), fabs(x), fabsl(x)
18857 exponentF 1.f+logbf(x), 1.0+logb(x), 1.L+logbl(x)
18858 scaleF scalbnf(x, n), scalbn(x, n), scalbnl(x, n),
18859 scalblnf(x, li), scalbln(x, li), scalblnl(x, li)
18860 intpartF modff(x, &y), modf(x, &y), modfl(x, &y)
18861 fractpartF modff(x, &y), modf(x, &y), modfl(x, &y)
18868 where x and y are expressions of the same floating point type, n is of type int, and li
18869 is of type long int.
18870 H.2.3.3 Rounding styles
18871 1 The C Standard requires all floating types to use the same radix and rounding style, so
18872 that only one identifier for each is provided to map to LIA-1.
18873 2 The FLT_ROUNDS parameter can be used to indicate the LIA-1 rounding styles:
18874 truncate FLT_ROUNDS == 0
18878 nearest FLT_ROUNDS == 1
18879 other FLT_ROUNDS != 0 && FLT_ROUNDS != 1
18880 provided that an implementation extends FLT_ROUNDS to cover the rounding style used
18881 in all relevant LIA-1 operations, not just addition as in C.
18882 H.2.4 Type conversions
18883 1 The LIA-1 type conversions are the following type casts:
18884 cvtI' (->) I (int)i, (long int)i, (long long int)i,
18885 (unsigned int)i, (unsigned long int)i,
18886 (unsigned long long int)i
18887 cvtF (->) I (int)x, (long int)x, (long long int)x,
18888 (unsigned int)x, (unsigned long int)x,
18889 (unsigned long long int)x
18890 cvtI (->) F (float)i, (double)i, (long double)i
18891 cvtF' (->) F (float)x, (double)x, (long double)x
18892 2 In the above conversions from floating to integer, the use of (cast)x can be replaced with
18893 (cast)round(x), (cast)rint(x), (cast)nearbyint(x), (cast)trunc(x),
18894 (cast)ceil(x), or (cast)floor(x). In addition, C's floating-point to integer
18895 conversion functions, lrint(), llrint(), lround(), and llround(), can be
18896 used. They all meet LIA-1's requirements on floating to integer rounding for in-range
18897 values. For out-of-range values, the conversions shall silently wrap for the modulo types.
18898 3 The fmod() function is useful for doing silent wrapping to unsigned integer types, e.g.,
18899 fmod( fabs(rint(x)), 65536.0 ) or (0.0 <= (y = fmod( rint(x),
18900 65536.0 )) ? y : 65536.0 + y) will compute an integer value in the range 0.0
18901 to 65535.0 which can then be cast to unsigned short int. But, the
18902 remainder() function is not useful for doing silent wrapping to signed integer types,
18903 e.g., remainder( rint(x), 65536.0 ) will compute an integer value in the
18904 range -32767.0 to +32768.0 which is not, in general, in the range of signed short
18906 4 C's conversions (casts) from floating-point to floating-point can meet LIA-1
18907 requirements if an implementation uses round-to-nearest (IEC 60559 default).
18908 5 C's conversions (casts) from integer to floating-point can meet LIA-1 requirements if an
18909 implementation uses round-to-nearest.
18917 1 Notification is the process by which a user or program is informed that an exceptional
18918 arithmetic operation has occurred. C's operations are compatible with LIA-1 in that C
18919 allows an implementation to cause a notification to occur when any arithmetic operation
18920 returns an exceptional value as defined in LIA-1 clause 5.
18921 H.3.1 Notification alternatives
18922 1 LIA-1 requires at least the following two alternatives for handling of notifications:
18923 setting indicators or trap-and-terminate. LIA-1 allows a third alternative: trap-and-
18925 2 An implementation need only support a given notification alternative for the entire
18926 program. An implementation may support the ability to switch between notification
18927 alternatives during execution, but is not required to do so. An implementation can
18928 provide separate selection for each kind of notification, but this is not required.
18929 3 C allows an implementation to provide notification. C's SIGFPE (for traps) and
18930 FE_INVALID, FE_DIVBYZERO, FE_OVERFLOW, FE_UNDERFLOW (for indicators)
18931 can provide LIA-1 notification.
18932 4 C's signal handlers are compatible with LIA-1. Default handling of SIGFPE can
18933 provide trap-and-terminate behavior, except for those LIA-1 operations implemented by
18934 math library function calls. User-provided signal handlers for SIGFPE allow for trap-
18935 and-resume behavior with the same constraint.
18937 1 C's <fenv.h> status flags are compatible with the LIA-1 indicators.
18938 2 The following mapping is for floating-point types:
18939 undefined FE_INVALID, FE_DIVBYZERO
18940 floating_overflow FE_OVERFLOW
18941 underflow FE_UNDERFLOW
18942 3 The floating-point indicator interrogation and manipulation operations are:
18943 set_indicators feraiseexcept(i)
18944 clear_indicators feclearexcept(i)
18945 test_indicators fetestexcept(i)
18946 current_indicators fetestexcept(FE_ALL_EXCEPT)
18947 where i is an expression of type int representing a subset of the LIA-1 indicators.
18948 4 C allows an implementation to provide the following LIA-1 required behavior: at
18949 program termination if any indicator is set the implementation shall send an unambiguous
18952 and ''hard to ignore'' message (see LIA-1 subclause 6.1.2)
18953 5 LIA-1 does not make the distinction between floating-point and integer for ''undefined''.
18954 This documentation makes that distinction because <fenv.h> covers only the floating-
18957 1 C is compatible with LIA-1's trap requirements for arithmetic operations, but not for
18958 math library functions (which are not permitted to generate any externally visible
18959 exceptional conditions). An implementation can provide an alternative of notification
18960 through termination with a ''hard-to-ignore'' message (see LIA-1 subclause 6.1.3).
18961 2 LIA-1 does not require that traps be precise.
18962 3 C does require that SIGFPE be the signal corresponding to arithmetic exceptions, if there
18963 is any signal raised for them.
18964 4 C supports signal handlers for SIGFPE and allows trapping of arithmetic exceptions.
18965 When arithmetic exceptions do trap, C's signal-handler mechanism allows trap-and-
18966 terminate (either default implementation behavior or user replacement for it) or trap-and-
18967 resume, at the programmer's option.
18977 1 An implementation may generate warnings in many situations, none of which are
18978 specified as part of this International Standard. The following are a few of the more
18980 2 -- A new struct or union type appears in a function prototype (6.2.1, 6.7.2.3).
18981 -- A block with initialization of an object that has automatic storage duration is jumped
18983 -- An implicit narrowing conversion is encountered, such as the assignment of a long
18984 int or a double to an int, or a pointer to void to a pointer to any type other than
18985 a character type (6.3).
18986 -- A hexadecimal floating constant cannot be represented exactly in its evaluation format
18988 -- An integer character constant includes more than one character or a wide character
18989 constant includes more than one multibyte character (6.4.4.4).
18990 -- The characters /* are found in a comment (6.4.7).
18991 -- An ''unordered'' binary operator (not comma, &&, or ||) contains a side effect to an
18992 lvalue in one operand, and a side effect to, or an access to the value of, the identical
18993 lvalue in the other operand (6.5).
18994 -- A function is called but no prototype has been supplied (6.5.2.2).
18995 -- The arguments in a function call do not agree in number and type with those of the
18996 parameters in a function definition that is not a prototype (6.5.2.2).
18997 -- An object is defined but not used (6.7).
18998 -- A value is given to an object of an enumerated type other than by assignment of an
18999 enumeration constant that is a member of that type, or an enumeration object that has
19000 the same type, or the value of a function that returns the same enumerated type
19002 -- An aggregate has a partly bracketed initialization (6.7.7).
19003 -- A statement cannot be reached (6.8).
19004 -- A statement with no apparent effect is encountered (6.8).
19005 -- A constant expression is used as the controlling expression of a selection statement
19009 -- An incorrectly formed preprocessing group is encountered while skipping a
19010 preprocessing group (6.10.1).
19011 -- An unrecognized #pragma directive is encountered (6.10.6).
19021 1 This annex collects some information about portability that appears in this International
19023 J.1 Unspecified behavior
19024 1 The following are unspecified:
19025 -- The manner and timing of static initialization (5.1.2).
19026 -- The termination status returned to the hosted environment if the return type of main
19027 is not compatible with int (5.1.2.2.3).
19028 -- The behavior of the display device if a printing character is written when the active
19029 position is at the final position of a line (5.2.2).
19030 -- The behavior of the display device if a backspace character is written when the active
19031 position is at the initial position of a line (5.2.2).
19032 -- The behavior of the display device if a horizontal tab character is written when the
19033 active position is at or past the last defined horizontal tabulation position (5.2.2).
19034 -- The behavior of the display device if a vertical tab character is written when the active
19035 position is at or past the last defined vertical tabulation position (5.2.2).
19036 -- How an extended source character that does not correspond to a universal character
19037 name counts toward the significant initial characters in an external identifier (5.2.4.1).
19038 -- Many aspects of the representations of types (6.2.6).
19039 -- The value of padding bytes when storing values in structures or unions (6.2.6.1).
19040 -- The value of a union member other than the last one stored into (6.2.6.1).
19041 -- The representation used when storing a value in an object that has more than one
19042 object representation for that value (6.2.6.1).
19043 -- The values of any padding bits in integer representations (6.2.6.2).
19044 -- Whether certain operators can generate negative zeros and whether a negative zero
19045 becomes a normal zero when stored in an object (6.2.6.2).
19046 -- Whether two string literals result in distinct arrays (6.4.5).
19047 -- The order in which subexpressions are evaluated and the order in which side effects
19048 take place, except as specified for the function-call (), &&, ||, ?:, and comma
19052 -- The order in which the function designator, arguments, and subexpressions within the
19053 arguments are evaluated in a function call (6.5.2.2).
19054 -- The order of side effects among compound literal initialization list expressions
19056 -- The order in which the operands of an assignment operator are evaluated (6.5.16).
19057 -- The alignment of the addressable storage unit allocated to hold a bit-field (6.7.2.1).
19058 -- Whether a call to an inline function uses the inline definition or the external definition
19059 of the function (6.7.4).
19060 -- Whether or not a size expression is evaluated when it is part of the operand of a
19061 sizeof operator and changing the value of the size expression would not affect the
19062 result of the operator (6.7.5.2).
19063 -- The order in which any side effects occur among the initialization list expressions in
19064 an initializer (6.7.8).
19065 -- The layout of storage for function parameters (6.9.1).
19066 -- When a fully expanded macro replacement list contains a function-like macro name
19067 as its last preprocessing token and the next preprocessing token from the source file is
19068 a (, and the fully expanded replacement of that macro ends with the name of the first
19069 macro and the next preprocessing token from the source file is again a (, whether that
19070 is considered a nested replacement (6.10.3).
19071 -- The order in which # and ## operations are evaluated during macro substitution
19072 (6.10.3.2, 6.10.3.3).
19073 -- Whether errno is a macro or an identifier with external linkage (7.5).
19074 -- The state of the floating-point status flags when execution passes from a part of the
19075 program translated with FENV_ACCESS ''off'' to a part translated with
19076 FENV_ACCESS ''on'' (7.6.1).
19077 -- The order in which feraiseexcept raises floating-point exceptions, except as
19078 stated in F.7.6 (7.6.2.3).
19079 -- Whether math_errhandling is a macro or an identifier with external linkage
19081 -- The results of the frexp functions when the specified value is not a floating-point
19083 -- The numeric result of the ilogb functions when the correct value is outside the
19084 range of the return type (7.12.6.5, F.9.3.5).
19085 -- The result of rounding when the value is out of range (7.12.9.5, 7.12.9.7, F.9.6.5).
19089 -- The value stored by the remquo functions in the object pointed to by quo when y is
19091 -- Whether setjmp is a macro or an identifier with external linkage (7.13).
19092 -- Whether va_copy and va_end are macros or identifiers with external linkage
19094 -- The hexadecimal digit before the decimal point when a non-normalized floating-point
19095 number is printed with an a or A conversion specifier (7.19.6.1, 7.24.2.1).
19096 -- The value of the file position indicator after a successful call to the ungetc function
19097 for a text stream, or the ungetwc function for any stream, until all pushed-back
19098 characters are read or discarded (7.19.7.11, 7.24.3.10).
19099 -- The details of the value stored by the fgetpos function (7.19.9.1).
19100 -- The details of the value returned by the ftell function for a text stream (7.19.9.4).
19101 -- Whether the strtod, strtof, strtold, wcstod, wcstof, and wcstold
19102 functions convert a minus-signed sequence to a negative number directly or by
19103 negating the value resulting from converting the corresponding unsigned sequence
19104 (7.20.1.3, 7.24.4.1.1).
19105 -- The order and contiguity of storage allocated by successive calls to the calloc,
19106 malloc, and realloc functions (7.20.3).
19107 -- The amount of storage allocated by a successful call to the calloc, malloc, or
19108 realloc function when 0 bytes was requested (7.20.3).
19109 -- Which of two elements that compare as equal is matched by the bsearch function
19111 -- The order of two elements that compare as equal in an array sorted by the qsort
19112 function (7.20.5.2).
19113 -- The encoding of the calendar time returned by the time function (7.23.2.4).
19114 -- The characters stored by the strftime or wcsftime function if any of the time
19115 values being converted is outside the normal range (7.23.3.5, 7.24.5.1).
19116 -- The conversion state after an encoding error occurs (7.24.6.3.2, 7.24.6.3.3, 7.24.6.4.1,
19118 -- The resulting value when the ''invalid'' floating-point exception is raised during
19119 IEC 60559 floating to integer conversion (F.4).
19120 -- Whether conversion of non-integer IEC 60559 floating values to integer raises the
19121 ''inexact'' floating-point exception (F.4).
19127 -- Whether or when library functions in <math.h> raise the ''inexact'' floating-point
19128 exception in an IEC 60559 conformant implementation (F.9).
19129 -- Whether or when library functions in <math.h> raise an undeserved ''underflow''
19130 floating-point exception in an IEC 60559 conformant implementation (F.9).
19131 -- The exponent value stored by frexp for a NaN or infinity (F.9.3.4).
19132 -- The numeric result returned by the lrint, llrint, lround, and llround
19133 functions if the rounded value is outside the range of the return type (F.9.6.5, F.9.6.7).
19134 -- The sign of one part of the complex result of several math functions for certain
19135 exceptional values in IEC 60559 compatible implementations (G.6.1.1, G.6.2.2,
19136 G.6.2.3, G.6.2.4, G.6.2.5, G.6.2.6, G.6.3.1, G.6.4.2).
19137 J.2 Undefined behavior
19138 1 The behavior is undefined in the following circumstances:
19139 -- A ''shall'' or ''shall not'' requirement that appears outside of a constraint is violated
19141 -- A nonempty source file does not end in a new-line character which is not immediately
19142 preceded by a backslash character or ends in a partial preprocessing token or
19144 -- Token concatenation produces a character sequence matching the syntax of a
19145 universal character name (5.1.1.2).
19146 -- A program in a hosted environment does not define a function named main using one
19147 of the specified forms (5.1.2.2.1).
19148 -- A character not in the basic source character set is encountered in a source file, except
19149 in an identifier, a character constant, a string literal, a header name, a comment, or a
19150 preprocessing token that is never converted to a token (5.2.1).
19151 -- An identifier, comment, string literal, character constant, or header name contains an
19152 invalid multibyte character or does not begin and end in the initial shift state (5.2.1.2).
19153 -- The same identifier has both internal and external linkage in the same translation unit
19155 -- An object is referred to outside of its lifetime (6.2.4).
19156 -- The value of a pointer to an object whose lifetime has ended is used (6.2.4).
19157 -- The value of an object with automatic storage duration is used while it is
19158 indeterminate (6.2.4, 6.7.8, 6.8).
19159 -- A trap representation is read by an lvalue expression that does not have character type
19164 -- A trap representation is produced by a side effect that modifies any part of the object
19165 using an lvalue expression that does not have character type (6.2.6.1).
19166 -- The arguments to certain operators are such that could produce a negative zero result,
19167 but the implementation does not support negative zeros (6.2.6.2).
19168 -- Two declarations of the same object or function specify types that are not compatible
19170 -- Conversion to or from an integer type produces a value outside the range that can be
19171 represented (6.3.1.4).
19172 -- Demotion of one real floating type to another produces a value outside the range that
19173 can be represented (6.3.1.5).
19174 -- An lvalue does not designate an object when evaluated (6.3.2.1).
19175 -- A non-array lvalue with an incomplete type is used in a context that requires the value
19176 of the designated object (6.3.2.1).
19177 -- An lvalue having array type is converted to a pointer to the initial element of the
19178 array, and the array object has register storage class (6.3.2.1).
19179 -- An attempt is made to use the value of a void expression, or an implicit or explicit
19180 conversion (except to void) is applied to a void expression (6.3.2.2).
19181 -- Conversion of a pointer to an integer type produces a value outside the range that can
19182 be represented (6.3.2.3).
19183 -- Conversion between two pointer types produces a result that is incorrectly aligned
19185 -- A pointer is used to call a function whose type is not compatible with the pointed-to
19187 -- An unmatched ' or " character is encountered on a logical source line during
19188 tokenization (6.4).
19189 -- A reserved keyword token is used in translation phase 7 or 8 for some purpose other
19190 than as a keyword (6.4.1).
19191 -- A universal character name in an identifier does not designate a character whose
19192 encoding falls into one of the specified ranges (6.4.2.1).
19193 -- The initial character of an identifier is a universal character name designating a digit
19195 -- Two identifiers differ only in nonsignificant characters (6.4.2.1).
19196 -- The identifier __func__ is explicitly declared (6.4.2.2).
19201 -- The program attempts to modify a string literal (6.4.5).
19202 -- The characters ', \, ", //, or /* occur in the sequence between the < and >
19203 delimiters, or the characters ', \, //, or /* occur in the sequence between the "
19204 delimiters, in a header name preprocessing token (6.4.7).
19205 -- Between two sequence points, an object is modified more than once, or is modified
19206 and the prior value is read other than to determine the value to be stored (6.5).
19207 -- An exceptional condition occurs during the evaluation of an expression (6.5).
19208 -- An object has its stored value accessed other than by an lvalue of an allowable type
19210 -- An attempt is made to modify the result of a function call, a conditional operator, an
19211 assignment operator, or a comma operator, or to access it after the next sequence
19212 point (6.5.2.2, 6.5.15, 6.5.16, 6.5.17).
19213 -- For a call to a function without a function prototype in scope, the number of
19214 arguments does not equal the number of parameters (6.5.2.2).
19215 -- For call to a function without a function prototype in scope where the function is
19216 defined with a function prototype, either the prototype ends with an ellipsis or the
19217 types of the arguments after promotion are not compatible with the types of the
19218 parameters (6.5.2.2).
19219 -- For a call to a function without a function prototype in scope where the function is not
19220 defined with a function prototype, the types of the arguments after promotion are not
19221 compatible with those of the parameters after promotion (with certain exceptions)
19223 -- A function is defined with a type that is not compatible with the type (of the
19224 expression) pointed to by the expression that denotes the called function (6.5.2.2).
19225 -- The operand of the unary * operator has an invalid value (6.5.3.2).
19226 -- A pointer is converted to other than an integer or pointer type (6.5.4).
19227 -- The value of the second operand of the / or % operator is zero (6.5.5).
19228 -- Addition or subtraction of a pointer into, or just beyond, an array object and an
19229 integer type produces a result that does not point into, or just beyond, the same array
19231 -- Addition or subtraction of a pointer into, or just beyond, an array object and an
19232 integer type produces a result that points just beyond the array object and is used as
19233 the operand of a unary * operator that is evaluated (6.5.6).
19234 -- Pointers that do not point into, or just beyond, the same array object are subtracted
19239 -- An array subscript is out of range, even if an object is apparently accessible with the
19240 given subscript (as in the lvalue expression a[1][7] given the declaration int
19242 -- The result of subtracting two pointers is not representable in an object of type
19244 -- An expression is shifted by a negative number or by an amount greater than or equal
19245 to the width of the promoted expression (6.5.7).
19246 -- An expression having signed promoted type is left-shifted and either the value of the
19247 expression is negative or the result of shifting would be not be representable in the
19248 promoted type (6.5.7).
19249 -- Pointers that do not point to the same aggregate or union (nor just beyond the same
19250 array object) are compared using relational operators (6.5.8).
19251 -- An object is assigned to an inexactly overlapping object or to an exactly overlapping
19252 object with incompatible type (6.5.16.1).
19253 -- An expression that is required to be an integer constant expression does not have an
19254 integer type; has operands that are not integer constants, enumeration constants,
19255 character constants, sizeof expressions whose results are integer constants, or
19256 immediately-cast floating constants; or contains casts (outside operands to sizeof
19257 operators) other than conversions of arithmetic types to integer types (6.6).
19258 -- A constant expression in an initializer is not, or does not evaluate to, one of the
19259 following: an arithmetic constant expression, a null pointer constant, an address
19260 constant, or an address constant for an object type plus or minus an integer constant
19262 -- An arithmetic constant expression does not have arithmetic type; has operands that
19263 are not integer constants, floating constants, enumeration constants, character
19264 constants, or sizeof expressions; or contains casts (outside operands to sizeof
19265 operators) other than conversions of arithmetic types to arithmetic types (6.6).
19266 -- The value of an object is accessed by an array-subscript [], member-access . or ->,
19267 address &, or indirection * operator or a pointer cast in creating an address constant
19269 -- An identifier for an object is declared with no linkage and the type of the object is
19270 incomplete after its declarator, or after its init-declarator if it has an initializer (6.7).
19271 -- A function is declared at block scope with an explicit storage-class specifier other
19272 than extern (6.7.1).
19273 -- A structure or union is defined as containing no named members (6.7.2.1).
19278 -- An attempt is made to access, or generate a pointer to just past, a flexible array
19279 member of a structure when the referenced object provides no elements for that array
19281 -- When the complete type is needed, an incomplete structure or union type is not
19282 completed in the same scope by another declaration of the tag that defines the content
19284 -- An attempt is made to modify an object defined with a const-qualified type through
19285 use of an lvalue with non-const-qualified type (6.7.3).
19286 -- An attempt is made to refer to an object defined with a volatile-qualified type through
19287 use of an lvalue with non-volatile-qualified type (6.7.3).
19288 -- The specification of a function type includes any type qualifiers (6.7.3).
19289 -- Two qualified types that are required to be compatible do not have the identically
19290 qualified version of a compatible type (6.7.3).
19291 -- An object which has been modified is accessed through a restrict-qualified pointer to
19292 a const-qualified type, or through a restrict-qualified pointer and another pointer that
19293 are not both based on the same object (6.7.3.1).
19294 -- A restrict-qualified pointer is assigned a value based on another restricted pointer
19295 whose associated block neither began execution before the block associated with this
19296 pointer, nor ended before the assignment (6.7.3.1).
19297 -- A function with external linkage is declared with an inline function specifier, but is
19298 not also defined in the same translation unit (6.7.4).
19299 -- Two pointer types that are required to be compatible are not identically qualified, or
19300 are not pointers to compatible types (6.7.5.1).
19301 -- The size expression in an array declaration is not a constant expression and evaluates
19302 at program execution time to a nonpositive value (6.7.5.2).
19303 -- In a context requiring two array types to be compatible, they do not have compatible
19304 element types, or their size specifiers evaluate to unequal values (6.7.5.2).
19305 -- A declaration of an array parameter includes the keyword static within the [ and
19306 ] and the corresponding argument does not provide access to the first element of an
19307 array with at least the specified number of elements (6.7.5.3).
19308 -- A storage-class specifier or type qualifier modifies the keyword void as a function
19309 parameter type list (6.7.5.3).
19310 -- In a context requiring two function types to be compatible, they do not have
19311 compatible return types, or their parameters disagree in use of the ellipsis terminator
19312 or the number and type of parameters (after default argument promotion, when there
19313 is no parameter type list or when one type is specified by a function definition with an
19316 identifier list) (6.7.5.3).
19317 -- The value of an unnamed member of a structure or union is used (6.7.8).
19318 -- The initializer for a scalar is neither a single expression nor a single expression
19319 enclosed in braces (6.7.8).
19320 -- The initializer for a structure or union object that has automatic storage duration is
19321 neither an initializer list nor a single expression that has compatible structure or union
19323 -- The initializer for an aggregate or union, other than an array initialized by a string
19324 literal, is not a brace-enclosed list of initializers for its elements or members (6.7.8).
19325 -- An identifier with external linkage is used, but in the program there does not exist
19326 exactly one external definition for the identifier, or the identifier is not used and there
19327 exist multiple external definitions for the identifier (6.9).
19328 -- A function definition includes an identifier list, but the types of the parameters are not
19329 declared in a following declaration list (6.9.1).
19330 -- An adjusted parameter type in a function definition is not an object type (6.9.1).
19331 -- A function that accepts a variable number of arguments is defined without a
19332 parameter type list that ends with the ellipsis notation (6.9.1).
19333 -- The } that terminates a function is reached, and the value of the function call is used
19334 by the caller (6.9.1).
19335 -- An identifier for an object with internal linkage and an incomplete type is declared
19336 with a tentative definition (6.9.2).
19337 -- The token defined is generated during the expansion of a #if or #elif
19338 preprocessing directive, or the use of the defined unary operator does not match
19339 one of the two specified forms prior to macro replacement (6.10.1).
19340 -- The #include preprocessing directive that results after expansion does not match
19341 one of the two header name forms (6.10.2).
19342 -- The character sequence in an #include preprocessing directive does not start with a
19344 -- There are sequences of preprocessing tokens within the list of macro arguments that
19345 would otherwise act as preprocessing directives (6.10.3).
19346 -- The result of the preprocessing operator # is not a valid character string literal
19348 -- The result of the preprocessing operator ## is not a valid preprocessing token
19353 -- The #line preprocessing directive that results after expansion does not match one of
19354 the two well-defined forms, or its digit sequence specifies zero or a number greater
19355 than 2147483647 (6.10.4).
19356 -- A non-STDC #pragma preprocessing directive that is documented as causing
19357 translation failure or some other form of undefined behavior is encountered (6.10.6).
19358 -- A #pragma STDC preprocessing directive does not match one of the well-defined
19360 -- The name of a predefined macro, or the identifier defined, is the subject of a
19361 #define or #undef preprocessing directive (6.10.8).
19362 -- An attempt is made to copy an object to an overlapping object by use of a library
19363 function, other than as explicitly allowed (e.g., memmove) (clause 7).
19364 -- A file with the same name as one of the standard headers, not provided as part of the
19365 implementation, is placed in any of the standard places that are searched for included
19366 source files (7.1.2).
19367 -- A header is included within an external declaration or definition (7.1.2).
19368 -- A function, object, type, or macro that is specified as being declared or defined by
19369 some standard header is used before any header that declares or defines it is included
19371 -- A standard header is included while a macro is defined with the same name as a
19373 -- The program attempts to declare a library function itself, rather than via a standard
19374 header, but the declaration does not have external linkage (7.1.2).
19375 -- The program declares or defines a reserved identifier, other than as allowed by 7.1.4
19377 -- The program removes the definition of a macro whose name begins with an
19378 underscore and either an uppercase letter or another underscore (7.1.3).
19379 -- An argument to a library function has an invalid value or a type not expected by a
19380 function with variable number of arguments (7.1.4).
19381 -- The pointer passed to a library function array parameter does not have a value such
19382 that all address computations and object accesses are valid (7.1.4).
19383 -- The macro definition of assert is suppressed in order to access an actual function
19385 -- The argument to the assert macro does not have a scalar type (7.2).
19386 -- The CX_LIMITED_RANGE, FENV_ACCESS, or FP_CONTRACT pragma is used in
19387 any context other than outside all external declarations or preceding all explicit
19390 declarations and statements inside a compound statement (7.3.4, 7.6.1, 7.12.2).
19391 -- The value of an argument to a character handling function is neither equal to the value
19392 of EOF nor representable as an unsigned char (7.4).
19393 -- A macro definition of errno is suppressed in order to access an actual object, or the
19394 program defines an identifier with the name errno (7.5).
19395 -- Part of the program tests floating-point status flags, sets floating-point control modes,
19396 or runs under non-default mode settings, but was translated with the state for the
19397 FENV_ACCESS pragma ''off'' (7.6.1).
19398 -- The exception-mask argument for one of the functions that provide access to the
19399 floating-point status flags has a nonzero value not obtained by bitwise OR of the
19400 floating-point exception macros (7.6.2).
19401 -- The fesetexceptflag function is used to set floating-point status flags that were
19402 not specified in the call to the fegetexceptflag function that provided the value
19403 of the corresponding fexcept_t object (7.6.2.4).
19404 -- The argument to fesetenv or feupdateenv is neither an object set by a call to
19405 fegetenv or feholdexcept, nor is it an environment macro (7.6.4.3, 7.6.4.4).
19406 -- The value of the result of an integer arithmetic or conversion function cannot be
19407 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).
19408 -- The program modifies the string pointed to by the value returned by the setlocale
19409 function (7.11.1.1).
19410 -- The program modifies the structure pointed to by the value returned by the
19411 localeconv function (7.11.2.1).
19412 -- A macro definition of math_errhandling is suppressed or the program defines
19413 an identifier with the name math_errhandling (7.12).
19414 -- An argument to a floating-point classification or comparison macro is not of real
19415 floating type (7.12.3, 7.12.14).
19416 -- A macro definition of setjmp is suppressed in order to access an actual function, or
19417 the program defines an external identifier with the name setjmp (7.13).
19418 -- An invocation of the setjmp macro occurs other than in an allowed context
19420 -- The longjmp function is invoked to restore a nonexistent environment (7.13.2.1).
19421 -- After a longjmp, there is an attempt to access the value of an object of automatic
19422 storage class with non-volatile-qualified type, local to the function containing the
19423 invocation of the corresponding setjmp macro, that was changed between the
19424 setjmp invocation and longjmp call (7.13.2.1).
19428 -- The program specifies an invalid pointer to a signal handler function (7.14.1.1).
19429 -- A signal handler returns when the signal corresponded to a computational exception
19431 -- A signal occurs as the result of calling the abort or raise function, and the signal
19432 handler calls the raise function (7.14.1.1).
19433 -- A signal occurs other than as the result of calling the abort or raise function, and
19434 the signal handler refers to an object with static storage duration other than by
19435 assigning a value to an object declared as volatile sig_atomic_t, or calls any
19436 function in the standard library other than the abort function, the _Exit function,
19437 or the signal function (for the same signal number) (7.14.1.1).
19438 -- The value of errno is referred to after a signal occurred other than as the result of
19439 calling the abort or raise function and the corresponding signal handler obtained
19440 a SIG_ERR return from a call to the signal function (7.14.1.1).
19441 -- A signal is generated by an asynchronous signal handler (7.14.1.1).
19442 -- A function with a variable number of arguments attempts to access its varying
19443 arguments other than through a properly declared and initialized va_list object, or
19444 before the va_start macro is invoked (7.15, 7.15.1.1, 7.15.1.4).
19445 -- The macro va_arg is invoked using the parameter ap that was passed to a function
19446 that invoked the macro va_arg with the same parameter (7.15).
19447 -- A macro definition of va_start, va_arg, va_copy, or va_end is suppressed in
19448 order to access an actual function, or the program defines an external identifier with
19449 the name va_copy or va_end (7.15.1).
19450 -- The va_start or va_copy macro is invoked without a corresponding invocation
19451 of the va_end macro in the same function, or vice versa (7.15.1, 7.15.1.2, 7.15.1.3,
19453 -- The type parameter to the va_arg macro is not such that a pointer to an object of
19454 that type can be obtained simply by postfixing a * (7.15.1.1).
19455 -- The va_arg macro is invoked when there is no actual next argument, or with a
19456 specified type that is not compatible with the promoted type of the actual next
19457 argument, with certain exceptions (7.15.1.1).
19458 -- The va_copy or va_start macro is called to initialize a va_list that was
19459 previously initialized by either macro without an intervening invocation of the
19460 va_end macro for the same va_list (7.15.1.2, 7.15.1.4).
19461 -- The parameter parmN of a va_start macro is declared with the register
19462 storage class, with a function or array type, or with a type that is not compatible with
19463 the type that results after application of the default argument promotions (7.15.1.4).
19466 -- The member designator parameter of an offsetof macro is an invalid right
19467 operand of the . operator for the type parameter, or designates a bit-field (7.17).
19468 -- The argument in an instance of one of the integer-constant macros is not a decimal,
19469 octal, or hexadecimal constant, or it has a value that exceeds the limits for the
19470 corresponding type (7.18.4).
19471 -- A byte input/output function is applied to a wide-oriented stream, or a wide character
19472 input/output function is applied to a byte-oriented stream (7.19.2).
19473 -- Use is made of any portion of a file beyond the most recent wide character written to
19474 a wide-oriented stream (7.19.2).
19475 -- The value of a pointer to a FILE object is used after the associated file is closed
19477 -- The stream for the fflush function points to an input stream or to an update stream
19478 in which the most recent operation was input (7.19.5.2).
19479 -- The string pointed to by the mode argument in a call to the fopen function does not
19480 exactly match one of the specified character sequences (7.19.5.3).
19481 -- An output operation on an update stream is followed by an input operation without an
19482 intervening call to the fflush function or a file positioning function, or an input
19483 operation on an update stream is followed by an output operation with an intervening
19484 call to a file positioning function (7.19.5.3).
19485 -- An attempt is made to use the contents of the array that was supplied in a call to the
19486 setvbuf function (7.19.5.6).
19487 -- There are insufficient arguments for the format in a call to one of the formatted
19488 input/output functions, or an argument does not have an appropriate type (7.19.6.1,
19489 7.19.6.2, 7.24.2.1, 7.24.2.2).
19490 -- The format in a call to one of the formatted input/output functions or to the
19491 strftime or wcsftime function is not a valid multibyte character sequence that
19492 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,
19494 -- In a call to one of the formatted output functions, a precision appears with a
19495 conversion specifier other than those described (7.19.6.1, 7.24.2.1).
19496 -- A conversion specification for a formatted output function uses an asterisk to denote
19497 an argument-supplied field width or precision, but the corresponding argument is not
19498 provided (7.19.6.1, 7.24.2.1).
19499 -- A conversion specification for a formatted output function uses a # or 0 flag with a
19500 conversion specifier other than those described (7.19.6.1, 7.24.2.1).
19505 -- A conversion specification for one of the formatted input/output functions uses a
19506 length modifier with a conversion specifier other than those described (7.19.6.1,
19507 7.19.6.2, 7.24.2.1, 7.24.2.2).
19508 -- An s conversion specifier is encountered by one of the formatted output functions,
19509 and the argument is missing the null terminator (unless a precision is specified that
19510 does not require null termination) (7.19.6.1, 7.24.2.1).
19511 -- An n conversion specification for one of the formatted input/output functions includes
19512 any flags, an assignment-suppressing character, a field width, or a precision (7.19.6.1,
19513 7.19.6.2, 7.24.2.1, 7.24.2.2).
19514 -- A % conversion specifier is encountered by one of the formatted input/output
19515 functions, but the complete conversion specification is not exactly %% (7.19.6.1,
19516 7.19.6.2, 7.24.2.1, 7.24.2.2).
19517 -- An invalid conversion specification is found in the format for one of the formatted
19518 input/output functions, or the strftime or wcsftime function (7.19.6.1, 7.19.6.2,
19519 7.23.3.5, 7.24.2.1, 7.24.2.2, 7.24.5.1).
19520 -- The number of characters transmitted by a formatted output function is greater than
19521 INT_MAX (7.19.6.1, 7.19.6.3, 7.19.6.8, 7.19.6.10).
19522 -- The result of a conversion by one of the formatted input functions cannot be
19523 represented in the corresponding object, or the receiving object does not have an
19524 appropriate type (7.19.6.2, 7.24.2.2).
19525 -- A c, s, or [ conversion specifier is encountered by one of the formatted input
19526 functions, and the array pointed to by the corresponding argument is not large enough
19527 to accept the input sequence (and a null terminator if the conversion specifier is s or
19528 [) (7.19.6.2, 7.24.2.2).
19529 -- A c, s, or [ conversion specifier with an l qualifier is encountered by one of the
19530 formatted input functions, but the input is not a valid multibyte character sequence
19531 that begins in the initial shift state (7.19.6.2, 7.24.2.2).
19532 -- The input item for a %p conversion by one of the formatted input functions is not a
19533 value converted earlier during the same program execution (7.19.6.2, 7.24.2.2).
19534 -- The vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf,
19535 vsscanf, vfwprintf, vfwscanf, vswprintf, vswscanf, vwprintf, or
19536 vwscanf function is called with an improperly initialized va_list argument, or
19537 the argument is used (other than in an invocation of va_end) after the function
19538 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,
19539 7.24.2.5, 7.24.2.6, 7.24.2.7, 7.24.2.8, 7.24.2.9, 7.24.2.10).
19540 -- The contents of the array supplied in a call to the fgets, gets, or fgetws function
19541 are used after a read error occurred (7.19.7.2, 7.19.7.7, 7.24.3.2).
19544 -- The file position indicator for a binary stream is used after a call to the ungetc
19545 function where its value was zero before the call (7.19.7.11).
19546 -- The file position indicator for a stream is used after an error occurred during a call to
19547 the fread or fwrite function (7.19.8.1, 7.19.8.2).
19548 -- A partial element read by a call to the fread function is used (7.19.8.1).
19549 -- The fseek function is called for a text stream with a nonzero offset and either the
19550 offset was not returned by a previous successful call to the ftell function on a
19551 stream associated with the same file or whence is not SEEK_SET (7.19.9.2).
19552 -- The fsetpos function is called to set a position that was not returned by a previous
19553 successful call to the fgetpos function on a stream associated with the same file
19555 -- A non-null pointer returned by a call to the calloc, malloc, or realloc function
19556 with a zero requested size is used to access an object (7.20.3).
19557 -- The value of a pointer that refers to space deallocated by a call to the free or
19558 realloc function is used (7.20.3).
19559 -- The pointer argument to the free or realloc function does not match a pointer
19560 earlier returned by calloc, malloc, or realloc, or the space has been
19561 deallocated by a call to free or realloc (7.20.3.2, 7.20.3.4).
19562 -- The value of the object allocated by the malloc function is used (7.20.3.3).
19563 -- The value of any bytes in a new object allocated by the realloc function beyond
19564 the size of the old object are used (7.20.3.4).
19565 -- The program executes more than one call to the exit function (7.20.4.3).
19566 -- During the call to a function registered with the atexit function, a call is made to
19567 the longjmp function that would terminate the call to the registered function
19569 -- The string set up by the getenv or strerror function is modified by the program
19570 (7.20.4.5, 7.21.6.2).
19571 -- A command is executed through the system function in a way that is documented as
19572 causing termination or some other form of undefined behavior (7.20.4.6).
19573 -- A searching or sorting utility function is called with an invalid pointer argument, even
19574 if the number of elements is zero (7.20.5).
19575 -- The comparison function called by a searching or sorting utility function alters the
19576 contents of the array being searched or sorted, or returns ordering values
19577 inconsistently (7.20.5).
19582 -- The array being searched by the bsearch function does not have its elements in
19583 proper order (7.20.5.1).
19584 -- The current conversion state is used by a multibyte/wide character conversion
19585 function after changing the LC_CTYPE category (7.20.7).
19586 -- A string or wide string utility function is instructed to access an array beyond the end
19587 of an object (7.21.1, 7.24.4).
19588 -- A string or wide string utility function is called with an invalid pointer argument, even
19589 if the length is zero (7.21.1, 7.24.4).
19590 -- The contents of the destination array are used after a call to the strxfrm,
19591 strftime, wcsxfrm, or wcsftime function in which the specified length was
19592 too small to hold the entire null-terminated result (7.21.4.5, 7.23.3.5, 7.24.4.4.4,
19594 -- The first argument in the very first call to the strtok or wcstok is a null pointer
19595 (7.21.5.8, 7.24.4.5.7).
19596 -- The type of an argument to a type-generic macro is not compatible with the type of
19597 the corresponding parameter of the selected function (7.22).
19598 -- A complex argument is supplied for a generic parameter of a type-generic macro that
19599 has no corresponding complex function (7.22).
19600 -- The argument corresponding to an s specifier without an l qualifier in a call to the
19601 fwprintf function does not point to a valid multibyte character sequence that
19602 begins in the initial shift state (7.24.2.11).
19603 -- In a call to the wcstok function, the object pointed to by ptr does not have the
19604 value stored by the previous call for the same wide string (7.24.4.5.7).
19605 -- An mbstate_t object is used inappropriately (7.24.6).
19606 -- The value of an argument of type wint_t to a wide character classification or case
19607 mapping function is neither equal to the value of WEOF nor representable as a
19609 -- The iswctype function is called using a different LC_CTYPE category from the
19610 one in effect for the call to the wctype function that returned the description
19612 -- The towctrans function is called using a different LC_CTYPE category from the
19613 one in effect for the call to the wctrans function that returned the description
19621 J.3 Implementation-defined behavior
19622 1 A conforming implementation is required to document its choice of behavior in each of
19623 the areas listed in this subclause. The following are implementation-defined:
19625 1 -- How a diagnostic is identified (3.10, 5.1.1.3).
19626 -- Whether each nonempty sequence of white-space characters other than new-line is
19627 retained or replaced by one space character in translation phase 3 (5.1.1.2).
19629 1 -- The mapping between physical source file multibyte characters and the source
19630 character set in translation phase 1 (5.1.1.2).
19631 -- The name and type of the function called at program startup in a freestanding
19632 environment (5.1.2.1).
19633 -- The effect of program termination in a freestanding environment (5.1.2.1).
19634 -- An alternative manner in which the main function may be defined (5.1.2.2.1).
19635 -- The values given to the strings pointed to by the argv argument to main (5.1.2.2.1).
19636 -- What constitutes an interactive device (5.1.2.3).
19637 -- The set of signals, their semantics, and their default handling (7.14).
19638 -- Signal values other than SIGFPE, SIGILL, and SIGSEGV that correspond to a
19639 computational exception (7.14.1.1).
19640 -- Signals for which the equivalent of signal(sig, SIG_IGN); is executed at
19641 program startup (7.14.1.1).
19642 -- The set of environment names and the method for altering the environment list used
19643 by the getenv function (7.20.4.5).
19644 -- The manner of execution of the string by the system function (7.20.4.6).
19646 1 -- Which additional multibyte characters may appear in identifiers and their
19647 correspondence to universal character names (6.4.2).
19648 -- The number of significant initial characters in an identifier (5.2.4.1, 6.4.2).
19656 1 -- The number of bits in a byte (3.6).
19657 -- The values of the members of the execution character set (5.2.1).
19658 -- The unique value of the member of the execution character set produced for each of
19659 the standard alphabetic escape sequences (5.2.2).
19660 -- The value of a char object into which has been stored any character other than a
19661 member of the basic execution character set (6.2.5).
19662 -- Which of signed char or unsigned char has the same range, representation,
19663 and behavior as ''plain'' char (6.2.5, 6.3.1.1).
19664 -- The mapping of members of the source character set (in character constants and string
19665 literals) to members of the execution character set (6.4.4.4, 5.1.1.2).
19666 -- The value of an integer character constant containing more than one character or
19667 containing a character or escape sequence that does not map to a single-byte
19668 execution character (6.4.4.4).
19669 -- The value of a wide character constant containing more than one multibyte character,
19670 or containing a multibyte character or escape sequence not represented in the
19671 extended execution character set (6.4.4.4).
19672 -- The current locale used to convert a wide character constant consisting of a single
19673 multibyte character that maps to a member of the extended execution character set
19674 into a corresponding wide character code (6.4.4.4).
19675 -- The current locale used to convert a wide string literal into corresponding wide
19676 character codes (6.4.5).
19677 -- The value of a string literal containing a multibyte character or escape sequence not
19678 represented in the execution character set (6.4.5).
19680 1 -- Any extended integer types that exist in the implementation (6.2.5).
19681 -- Whether signed integer types are represented using sign and magnitude, two's
19682 complement, or ones' complement, and whether the extraordinary value is a trap
19683 representation or an ordinary value (6.2.6.2).
19684 -- The rank of any extended integer type relative to another extended integer type with
19685 the same precision (6.3.1.1).
19686 -- The result of, or the signal raised by, converting an integer to a signed integer type
19687 when the value cannot be represented in an object of that type (6.3.1.3).
19693 -- The results of some bitwise operations on signed integers (6.5).
19694 J.3.6 Floating point
19695 1 -- The accuracy of the floating-point operations and of the library functions in
19696 <math.h> and <complex.h> that return floating-point results (5.2.4.2.2).
19697 -- The accuracy of the conversions between floating-point internal representations and
19698 string representations performed by the library functions in <stdio.h>,
19699 <stdlib.h>, and <wchar.h> (5.2.4.2.2).
19700 -- The rounding behaviors characterized by non-standard values of FLT_ROUNDS
19702 -- The evaluation methods characterized by non-standard negative values of
19703 FLT_EVAL_METHOD (5.2.4.2.2).
19704 -- The direction of rounding when an integer is converted to a floating-point number that
19705 cannot exactly represent the original value (6.3.1.4).
19706 -- The direction of rounding when a floating-point number is converted to a narrower
19707 floating-point number (6.3.1.5).
19708 -- How the nearest representable value or the larger or smaller representable value
19709 immediately adjacent to the nearest representable value is chosen for certain floating
19710 constants (6.4.4.2).
19711 -- Whether and how floating expressions are contracted when not disallowed by the
19712 FP_CONTRACT pragma (6.5).
19713 -- The default state for the FENV_ACCESS pragma (7.6.1).
19714 -- Additional floating-point exceptions, rounding modes, environments, and
19715 classifications, and their macro names (7.6, 7.12).
19716 -- The default state for the FP_CONTRACT pragma (7.12.2). *
19717 J.3.7 Arrays and pointers
19718 1 -- The result of converting a pointer to an integer or vice versa (6.3.2.3).
19719 -- The size of the result of subtracting two pointers to elements of the same array
19728 1 -- The extent to which suggestions made by using the register storage-class
19729 specifier are effective (6.7.1).
19730 -- The extent to which suggestions made by using the inline function specifier are
19732 J.3.9 Structures, unions, enumerations, and bit-fields
19733 1 -- Whether a ''plain'' int bit-field is treated as a signed int bit-field or as an
19734 unsigned int bit-field (6.7.2, 6.7.2.1).
19735 -- Allowable bit-field types other than _Bool, signed int, and unsigned int
19737 -- Whether a bit-field can straddle a storage-unit boundary (6.7.2.1).
19738 -- The order of allocation of bit-fields within a unit (6.7.2.1).
19739 -- The alignment of non-bit-field members of structures (6.7.2.1). This should present
19740 no problem unless binary data written by one implementation is read by another.
19741 -- The integer type compatible with each enumerated type (6.7.2.2).
19743 1 -- What constitutes an access to an object that has volatile-qualified type (6.7.3).
19744 J.3.11 Preprocessing directives
19745 1 -- The locations within #pragma directives where header name preprocessing tokens
19746 are recognized (6.4, 6.4.7).
19747 -- How sequences in both forms of header names are mapped to headers or external
19748 source file names (6.4.7).
19749 -- Whether the value of a character constant in a constant expression that controls
19750 conditional inclusion matches the value of the same character constant in the
19751 execution character set (6.10.1).
19752 -- Whether the value of a single-character character constant in a constant expression
19753 that controls conditional inclusion may have a negative value (6.10.1).
19754 -- The places that are searched for an included < > delimited header, and how the places
19755 are specified or the header is identified (6.10.2).
19756 -- How the named source file is searched for in an included " " delimited header
19758 -- The method by which preprocessing tokens (possibly resulting from macro
19759 expansion) in a #include directive are combined into a header name (6.10.2).
19763 -- The nesting limit for #include processing (6.10.2).
19764 -- Whether the # operator inserts a \ character before the \ character that begins a
19765 universal character name in a character constant or string literal (6.10.3.2).
19766 -- The behavior on each recognized non-STDC #pragma directive (6.10.6).
19767 -- The definitions for __DATE__ and __TIME__ when respectively, the date and
19768 time of translation are not available (6.10.8).
19769 J.3.12 Library functions
19770 1 -- Any library facilities available to a freestanding program, other than the minimal set
19771 required by clause 4 (5.1.2.1).
19772 -- The format of the diagnostic printed by the assert macro (7.2.1.1).
19773 -- The representation of the floating-point status flags stored by the
19774 fegetexceptflag function (7.6.2.2).
19775 -- Whether the feraiseexcept function raises the ''inexact'' floating-point
19776 exception in addition to the ''overflow'' or ''underflow'' floating-point exception
19778 -- Strings other than "C" and "" that may be passed as the second argument to the
19779 setlocale function (7.11.1.1).
19780 -- The types defined for float_t and double_t when the value of the
19781 FLT_EVAL_METHOD macro is less than 0 (7.12).
19782 -- Domain errors for the mathematics functions, other than those required by this
19783 International Standard (7.12.1).
19784 -- The values returned by the mathematics functions on domain errors (7.12.1).
19785 -- The values returned by the mathematics functions on underflow range errors, whether
19786 errno is set to the value of the macro ERANGE when the integer expression
19787 math_errhandling & MATH_ERRNO is nonzero, and whether the ''underflow''
19788 floating-point exception is raised when the integer expression math_errhandling
19789 & MATH_ERREXCEPT is nonzero. (7.12.1).
19790 -- Whether a domain error occurs or zero is returned when an fmod function has a
19791 second argument of zero (7.12.10.1).
19792 -- Whether a domain error occurs or zero is returned when a remainder function has
19793 a second argument of zero (7.12.10.2).
19794 -- The base-2 logarithm of the modulus used by the remquo functions in reducing the
19795 quotient (7.12.10.3).
19801 -- Whether a domain error occurs or zero is returned when a remquo function has a
19802 second argument of zero (7.12.10.3).
19803 -- Whether the equivalent of signal(sig, SIG_DFL); is executed prior to the call
19804 of a signal handler, and, if not, the blocking of signals that is performed (7.14.1.1).
19805 -- The null pointer constant to which the macro NULL expands (7.17).
19806 -- Whether the last line of a text stream requires a terminating new-line character
19808 -- Whether space characters that are written out to a text stream immediately before a
19809 new-line character appear when read in (7.19.2).
19810 -- The number of null characters that may be appended to data written to a binary
19812 -- Whether the file position indicator of an append-mode stream is initially positioned at
19813 the beginning or end of the file (7.19.3).
19814 -- Whether a write on a text stream causes the associated file to be truncated beyond that
19816 -- The characteristics of file buffering (7.19.3).
19817 -- Whether a zero-length file actually exists (7.19.3).
19818 -- The rules for composing valid file names (7.19.3).
19819 -- Whether the same file can be simultaneously open multiple times (7.19.3).
19820 -- The nature and choice of encodings used for multibyte characters in files (7.19.3).
19821 -- The effect of the remove function on an open file (7.19.4.1).
19822 -- The effect if a file with the new name exists prior to a call to the rename function
19824 -- Whether an open temporary file is removed upon abnormal program termination
19826 -- Which changes of mode are permitted (if any), and under what circumstances
19828 -- The style used to print an infinity or NaN, and the meaning of any n-char or n-wchar
19829 sequence printed for a NaN (7.19.6.1, 7.24.2.1).
19830 -- The output for %p conversion in the fprintf or fwprintf function (7.19.6.1,
19832 -- The interpretation of a - character that is neither the first nor the last character, nor
19833 the second where a ^ character is the first, in the scanlist for %[ conversion in the
19834 fscanf or fwscanf function (7.19.6.2, 7.24.2.1).
19837 -- The set of sequences matched by a %p conversion and the interpretation of the
19838 corresponding input item in the fscanf or fwscanf function (7.19.6.2, 7.24.2.2).
19839 -- The value to which the macro errno is set by the fgetpos, fsetpos, or ftell
19840 functions on failure (7.19.9.1, 7.19.9.3, 7.19.9.4).
19841 -- The meaning of any n-char or n-wchar sequence in a string representing a NaN that is
19842 converted by the strtod, strtof, strtold, wcstod, wcstof, or wcstold
19843 function (7.20.1.3, 7.24.4.1.1).
19844 -- Whether or not the strtod, strtof, strtold, wcstod, wcstof, or wcstold
19845 function sets errno to ERANGE when underflow occurs (7.20.1.3, 7.24.4.1.1).
19846 -- Whether the calloc, malloc, and realloc functions return a null pointer or a
19847 pointer to an allocated object when the size requested is zero (7.20.3).
19848 -- Whether open streams with unwritten buffered data are flushed, open streams are
19849 closed, or temporary files are removed when the abort or _Exit function is called
19850 (7.20.4.1, 7.20.4.4).
19851 -- The termination status returned to the host environment by the abort, exit, or
19852 _Exit function (7.20.4.1, 7.20.4.3, 7.20.4.4).
19853 -- The value returned by the system function when its argument is not a null pointer
19855 -- The local time zone and Daylight Saving Time (7.23.1).
19856 -- The range and precision of times representable in clock_t and time_t (7.23).
19857 -- The era for the clock function (7.23.2.1).
19858 -- The replacement string for the %Z specifier to the strftime, and wcsftime
19859 functions in the "C" locale (7.23.3.5, 7.24.5.1).
19860 -- Whether the functions in <math.h> honor the rounding direction mode in an
19861 IEC 60559 conformant implementation, unless explicitly specified otherwise (F.9).
19862 J.3.13 Architecture
19863 1 -- The values or expressions assigned to the macros specified in the headers
19864 <float.h>, <limits.h>, and <stdint.h> (5.2.4.2, 7.18.2, 7.18.3).
19865 -- The number, order, and encoding of bytes in any object (when not explicitly specified
19866 in this International Standard) (6.2.6.1).
19867 -- The value of the result of the sizeof operator (6.5.3.4).
19874 J.4 Locale-specific behavior
19875 1 The following characteristics of a hosted environment are locale-specific and are required
19876 to be documented by the implementation:
19877 -- Additional members of the source and execution character sets beyond the basic
19878 character set (5.2.1).
19879 -- The presence, meaning, and representation of additional multibyte characters in the
19880 execution character set beyond the basic character set (5.2.1.2).
19881 -- The shift states used for the encoding of multibyte characters (5.2.1.2).
19882 -- The direction of writing of successive printing characters (5.2.2).
19883 -- The decimal-point character (7.1.1).
19884 -- The set of printing characters (7.4, 7.25.2).
19885 -- The set of control characters (7.4, 7.25.2).
19886 -- The sets of characters tested for by the isalpha, isblank, islower, ispunct,
19887 isspace, isupper, iswalpha, iswblank, iswlower, iswpunct,
19888 iswspace, or iswupper functions (7.4.1.2, 7.4.1.3, 7.4.1.7, 7.4.1.9, 7.4.1.10,
19889 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).
19890 -- The native environment (7.11.1.1).
19891 -- Additional subject sequences accepted by the numeric conversion functions (7.20.1,
19893 -- The collation sequence of the execution character set (7.21.4.3, 7.24.4.4.2).
19894 -- The contents of the error message strings set up by the strerror function
19896 -- The formats for time and date (7.23.3.5, 7.24.5.1).
19897 -- Character mappings that are supported by the towctrans function (7.25.1).
19898 -- Character classifications that are supported by the iswctype function (7.25.1).
19905 J.5 Common extensions
19906 1 The following extensions are widely used in many systems, but are not portable to all
19907 implementations. The inclusion of any extension that may cause a strictly conforming
19908 program to become invalid renders an implementation nonconforming. Examples of such
19909 extensions are new keywords, extra library functions declared in standard headers, or
19910 predefined macros with names that do not begin with an underscore.
19911 J.5.1 Environment arguments
19912 1 In a hosted environment, the main function receives a third argument, char *envp[],
19913 that points to a null-terminated array of pointers to char, each of which points to a string
19914 that provides information about the environment for this execution of the program
19916 J.5.2 Specialized identifiers
19917 1 Characters other than the underscore _, letters, and digits, that are not part of the basic
19918 source character set (such as the dollar sign $, or characters in national character sets)
19919 may appear in an identifier (6.4.2).
19920 J.5.3 Lengths and cases of identifiers
19921 1 All characters in identifiers (with or without external linkage) are significant (6.4.2).
19922 J.5.4 Scopes of identifiers
19923 1 A function identifier, or the identifier of an object the declaration of which contains the
19924 keyword extern, has file scope (6.2.1).
19925 J.5.5 Writable string literals
19926 1 String literals are modifiable (in which case, identical string literals should denote distinct
19928 J.5.6 Other arithmetic types
19929 1 Additional arithmetic types, such as __int128 or double double, and their
19930 appropriate conversions are defined (6.2.5, 6.3.1). Additional floating types may have
19931 more range or precision than long double, may be used for evaluating expressions of
19932 other floating types, and may be used to define float_t or double_t.
19939 J.5.7 Function pointer casts
19940 1 A pointer to an object or to void may be cast to a pointer to a function, allowing data to
19941 be invoked as a function (6.5.4).
19942 2 A pointer to a function may be cast to a pointer to an object or to void, allowing a
19943 function to be inspected or modified (for example, by a debugger) (6.5.4).
19944 J.5.8 Extended bit-field types
19945 1 A bit-field may be declared with a type other than _Bool, unsigned int, or
19946 signed int, with an appropriate maximum width (6.7.2.1).
19947 J.5.9 The fortran keyword
19948 1 The fortran function specifier may be used in a function declaration to indicate that
19949 calls suitable for FORTRAN should be generated, or that a different representation for the
19950 external name is to be generated (6.7.4).
19951 J.5.10 The asm keyword
19952 1 The asm keyword may be used to insert assembly language directly into the translator
19953 output (6.8). The most common implementation is via a statement of the form:
19954 asm ( character-string-literal );
19955 J.5.11 Multiple external definitions
19956 1 There may be more than one external definition for the identifier of an object, with or
19957 without the explicit use of the keyword extern; if the definitions disagree, or more than
19958 one is initialized, the behavior is undefined (6.9.2).
19959 J.5.12 Predefined macro names
19960 1 Macro names that do not begin with an underscore, describing the translation and
19961 execution environments, are defined by the implementation before translation begins
19963 J.5.13 Floating-point status flags
19964 1 If any floating-point status flags are set on normal termination after all calls to functions
19965 registered by the atexit function have been made (see 7.20.4.3), the implementation
19966 writes some diagnostics indicating the fact to the stderr stream, if it is still open,
19973 J.5.14 Extra arguments for signal handlers
19974 1 Handlers for specific signals are called with extra arguments in addition to the signal
19976 J.5.15 Additional stream types and file-opening modes
19977 1 Additional mappings from files to streams are supported (7.19.2).
19978 2 Additional file-opening modes may be specified by characters appended to the mode
19979 argument of the fopen function (7.19.5.3).
19980 J.5.16 Defined file position indicator
19981 1 The file position indicator is decremented by each successful call to the ungetc or
19982 ungetwc function for a text stream, except if its value was zero before a call (7.19.7.11,
19984 J.5.17 Math error reporting
19985 1 Functions declared in <complex.h> and <math.h> raise SIGFPE to report errors
19986 instead of, or in addition to, setting errno or raising floating-point exceptions (7.3,
19996 1. ''The C Reference Manual'' by Dennis M. Ritchie, a version of which was
19997 published in The C Programming Language by Brian W. Kernighan and Dennis
19998 M. Ritchie, Prentice-Hall, Inc., (1978). Copyright owned by AT&T.
19999 2. 1984 /usr/group Standard by the /usr/group Standards Committee, Santa Clara,
20000 California, USA, November 1984.
20001 3. ANSI X3/TR-1-82 (1982), American National Dictionary for Information
20002 Processing Systems, Information Processing Systems Technical Report.
20003 4. ANSI/IEEE 754-1985, American National Standard for Binary Floating-Point
20005 5. ANSI/IEEE 854-1988, American National Standard for Radix-Independent
20006 Floating-Point Arithmetic.
20007 6. IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems,
20008 second edition (previously designated IEC 559:1989).
20009 7. ISO 31-11:1992, Quantities and units -- Part 11: Mathematical signs and
20010 symbols for use in the physical sciences and technology.
20011 8. ISO/IEC 646:1991, Information technology -- ISO 7-bit coded character set for
20012 information interchange.
20013 9. ISO/IEC 2382-1:1993, Information technology -- Vocabulary -- Part 1:
20015 10. ISO 4217:1995, Codes for the representation of currencies and funds.
20016 11. ISO 8601:1988, Data elements and interchange formats -- Information
20017 interchange -- Representation of dates and times.
20018 12. ISO/IEC 9899:1990, Programming languages -- C.
20019 13. ISO/IEC 9899/COR1:1994, Technical Corrigendum 1.
20020 14. ISO/IEC 9899/COR2:1996, Technical Corrigendum 2.
20021 15. ISO/IEC 9899/AMD1:1995, Amendment 1 to ISO/IEC 9899:1990 C Integrity.
20022 16. ISO/IEC 9945-2:1993, Information technology -- Portable Operating System
20023 Interface (POSIX) -- Part 2: Shell and Utilities.
20024 17. ISO/IEC TR 10176:1998, Information technology -- Guidelines for the
20025 preparation of programming language standards.
20026 18. ISO/IEC 10646-1:1993, Information technology -- Universal Multiple-Octet
20027 Coded Character Set (UCS) -- Part 1: Architecture and Basic Multilingual Plane.
20031 19. ISO/IEC 10646-1/COR1:1996, Technical Corrigendum 1 to
20032 ISO/IEC 10646-1:1993.
20033 20. ISO/IEC 10646-1/COR2:1998, Technical Corrigendum 2 to
20034 ISO/IEC 10646-1:1993.
20035 21. ISO/IEC 10646-1/AMD1:1996, Amendment 1 to ISO/IEC 10646-1:1993
20036 Transformation Format for 16 planes of group 00 (UTF-16).
20037 22. ISO/IEC 10646-1/AMD2:1996, Amendment 2 to ISO/IEC 10646-1:1993 UCS
20038 Transformation Format 8 (UTF-8).
20039 23. ISO/IEC 10646-1/AMD3:1996, Amendment 3 to ISO/IEC 10646-1:1993.
20040 24. ISO/IEC 10646-1/AMD4:1996, Amendment 4 to ISO/IEC 10646-1:1993.
20041 25. ISO/IEC 10646-1/AMD5:1998, Amendment 5 to ISO/IEC 10646-1:1993 Hangul
20043 26. ISO/IEC 10646-1/AMD6:1997, Amendment 6 to ISO/IEC 10646-1:1993 Tibetan.
20044 27. ISO/IEC 10646-1/AMD7:1997, Amendment 7 to ISO/IEC 10646-1:1993 33
20045 additional characters.
20046 28. ISO/IEC 10646-1/AMD8:1997, Amendment 8 to ISO/IEC 10646-1:1993.
20047 29. ISO/IEC 10646-1/AMD9:1997, Amendment 9 to ISO/IEC 10646-1:1993
20048 Identifiers for characters.
20049 30. ISO/IEC 10646-1/AMD10:1998, Amendment 10 to ISO/IEC 10646-1:1993
20051 31. ISO/IEC 10646-1/AMD11:1998, Amendment 11 to ISO/IEC 10646-1:1993
20052 Unified Canadian Aboriginal Syllabics.
20053 32. ISO/IEC 10646-1/AMD12:1998, Amendment 12 to ISO/IEC 10646-1:1993
20055 33. ISO/IEC 10967-1:1994, Information technology -- Language independent
20056 arithmetic -- Part 1: Integer and floating point arithmetic.
20069 ??? x ???, 3.18 , (comma punctuator), 6.5.2, 6.7, 6.7.2.1, 6.7.2.2,
20071 ??? x ???, 3.19 - (subtraction operator), 6.5.6, F.3, G.5.2
20072 ! (logical negation operator), 6.5.3.3 - (unary minus operator), 6.5.3.3, F.3
20073 != (inequality operator), 6.5.9 -- (postfix decrement operator), 6.3.2.1, 6.5.2.4
20074 # operator, 6.10.3.2 -- (prefix decrement operator), 6.3.2.1, 6.5.3.1
20075 # preprocessing directive, 6.10.7 -= (subtraction assignment operator), 6.5.16.2
20076 # punctuator, 6.10 -> (structure/union pointer operator), 6.5.2.3
20077 ## operator, 6.10.3.3 . (structure/union member operator), 6.3.2.1,
20078 #define preprocessing directive, 6.10.3 6.5.2.3
20079 #elif preprocessing directive, 6.10.1 . punctuator, 6.7.8
20080 #else preprocessing directive, 6.10.1 ... (ellipsis punctuator), 6.5.2.2, 6.7.5.3, 6.10.3
20081 #endif preprocessing directive, 6.10.1 / (division operator), 6.5.5, F.3, G.5.1
20082 #error preprocessing directive, 4, 6.10.5 /* */ (comment delimiters), 6.4.9
20083 #if preprocessing directive, 5.2.4.2.1, 5.2.4.2.2, // (comment delimiter), 6.4.9
20084 6.10.1, 7.1.4 /= (division assignment operator), 6.5.16.2
20085 #ifdef preprocessing directive, 6.10.1 : (colon punctuator), 6.7.2.1
20086 #ifndef preprocessing directive, 6.10.1 :> (alternative spelling of ]), 6.4.6
20087 #include preprocessing directive, 5.1.1.2, ; (semicolon punctuator), 6.7, 6.7.2.1, 6.8.3,
20088 6.10.2 6.8.5, 6.8.6
20089 #line preprocessing directive, 6.10.4 < (less-than operator), 6.5.8
20090 #pragma preprocessing directive, 6.10.6 <% (alternative spelling of {), 6.4.6
20091 #undef preprocessing directive, 6.10.3.5, 7.1.3, <: (alternative spelling of [), 6.4.6
20092 7.1.4 << (left-shift operator), 6.5.7
20093 % (remainder operator), 6.5.5 <<= (left-shift assignment operator), 6.5.16.2
20094 %: (alternative spelling of #), 6.4.6 <= (less-than-or-equal-to operator), 6.5.8
20095 %:%: (alternative spelling of ##), 6.4.6 <assert.h> header, 7.2, B.1
20096 %= (remainder assignment operator), 6.5.16.2 <complex.h> header, 5.2.4.2.2, 7.3, 7.22,
20097 %> (alternative spelling of }), 6.4.6 7.26.1, G.6, J.5.17
20098 & (address operator), 6.3.2.1, 6.5.3.2 <ctype.h> header, 7.4, 7.26.2
20099 & (bitwise AND operator), 6.5.10 <errno.h> header, 7.5, 7.26.3
20100 && (logical AND operator), 6.5.13 <fenv.h> header, 5.1.2.3, 5.2.4.2.2, 7.6, 7.12, F,
20101 &= (bitwise AND assignment operator), 6.5.16.2 H
20102 ' ' (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,
20103 7.4.1.10, 7.25.2.1.3 7.24.4.1.1
20104 ( ) (cast operator), 6.5.4 <inttypes.h> header, 7.8, 7.26.4
20105 ( ) (function-call operator), 6.5.2.2 <iso646.h> header, 4, 7.9
20106 ( ) (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
20107 ( ){ } (compound-literal operator), 6.5.2.5 <locale.h> header, 7.11, 7.26.5
20108 * (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,
20109 * (indirection operator), 6.5.2.1, 6.5.3.2 F.9, J.5.17
20110 * (multiplication operator), 6.5.5, F.3, G.5.1 <setjmp.h> header, 7.13
20111 *= (multiplication assignment operator), 6.5.16.2 <signal.h> header, 7.14, 7.26.6
20112 + (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
20113 G.5.2 <stdbool.h> header, 4, 7.16, 7.26.7, H
20114 + (unary plus operator), 6.5.3.3 <stddef.h> header, 4, 6.3.2.1, 6.3.2.3, 6.4.4.4,
20115 ++ (postfix increment operator), 6.3.2.1, 6.5.2.4 6.4.5, 6.5.3.4, 6.5.6, 7.17
20116 ++ (prefix increment operator), 6.3.2.1, 6.5.3.1 <stdint.h> header, 4, 5.2.4.2, 6.10.1, 7.8,
20117 += (addition assignment operator), 6.5.16.2 7.18, 7.26.8
20118 , (comma operator), 6.5.17
20121 <stdio.h> header, 5.2.4.2.2, 7.19, 7.26.9, F __cplusplus macro, 6.10.8
20122 <stdlib.h> header, 5.2.4.2.2, 7.20, 7.26.10, F __DATE__ macro, 6.10.8
20123 <string.h> header, 7.21, 7.26.11 __FILE__ macro, 6.10.8, 7.2.1.1
20124 <tgmath.h> header, 7.22, G.7 __func__ identifier, 6.4.2.2, 7.2.1.1
20125 <time.h> header, 7.23 __LINE__ macro, 6.10.8, 7.2.1.1
20126 <wchar.h> header, 5.2.4.2.2, 7.19.1, 7.24, __STDC_, 6.11.9
20127 7.26.12, F __STDC__ macro, 6.10.8
20128 <wctype.h> header, 7.25, 7.26.13 __STDC_CONSTANT_MACROS macro, 7.18.4
20129 = (equal-sign punctuator), 6.7, 6.7.2.2, 6.7.8 __STDC_FORMAT_MACROS macro, 7.8.1
20130 = (simple assignment operator), 6.5.16.1 __STDC_HOSTED__ macro, 6.10.8
20131 == (equality operator), 6.5.9 __STDC_IEC_559__ macro, 6.10.8, F.1
20132 > (greater-than operator), 6.5.8 __STDC_IEC_559_COMPLEX__ macro,
20133 >= (greater-than-or-equal-to operator), 6.5.8 6.10.8, G.1
20134 >> (right-shift operator), 6.5.7 __STDC_ISO_10646__ macro, 6.10.8
20135 >>= (right-shift assignment operator), 6.5.16.2 __STDC_LIMIT_MACROS macro, 7.18.2,
20136 ? : (conditional operator), 6.5.15 7.18.3
20137 ?? (trigraph sequences), 5.2.1.1 __STDC_MB_MIGHT_NEQ_WC__ macro,
20138 [ ] (array subscript operator), 6.5.2.1, 6.5.3.2 6.10.8, 7.17
20139 [ ] (brackets punctuator), 6.7.5.2, 6.7.8 __STDC_VERSION__ macro, 6.10.8
20140 \ (backslash character), 5.1.1.2, 5.2.1, 6.4.4.4 __TIME__ macro, 6.10.8
20141 \ (escape character), 6.4.4.4 __VA_ARGS__ identifier, 6.10.3, 6.10.3.1
20142 \" (double-quote escape sequence), 6.4.4.4, _Bool type, 6.2.5, 6.3.1.1, 6.3.1.2, 6.7.2
20143 6.4.5, 6.10.9 _Bool type conversions, 6.3.1.2
20144 \\ (backslash escape sequence), 6.4.4.4, 6.10.9 _Complex types, 6.2.5, 6.7.2, 7.3.1, G
20145 \' (single-quote escape sequence), 6.4.4.4, 6.4.5 _Complex_I macro, 7.3.1
20146 \0 (null character), 5.2.1, 6.4.4.4, 6.4.5 _Exit function, 7.20.4.4
20147 padding of binary stream, 7.19.2 _Imaginary keyword, G.2
20148 \? (question-mark escape sequence), 6.4.4.4 _Imaginary types, 7.3.1, G
20149 \a (alert escape sequence), 5.2.2, 6.4.4.4 _Imaginary_I macro, 7.3.1, G.6
20150 \b (backspace escape sequence), 5.2.2, 6.4.4.4 _IOFBF macro, 7.19.1, 7.19.5.5, 7.19.5.6
20151 \f (form-feed escape sequence), 5.2.2, 6.4.4.4, _IOLBF macro, 7.19.1, 7.19.5.6
20152 7.4.1.10 _IONBF macro, 7.19.1, 7.19.5.5, 7.19.5.6
20153 \n (new-line escape sequence), 5.2.2, 6.4.4.4, _Pragma operator, 5.1.1.2, 6.10.9
20154 7.4.1.10 { } (braces punctuator), 6.7.2.2, 6.7.2.3, 6.7.8,
20155 \octal digits (octal-character escape sequence), 6.8.2
20156 6.4.4.4 { } (compound-literal operator), 6.5.2.5
20157 \r (carriage-return escape sequence), 5.2.2, | (bitwise inclusive OR operator), 6.5.12
20158 6.4.4.4, 7.4.1.10 |= (bitwise inclusive OR assignment operator),
20159 \t (horizontal-tab escape sequence), 5.2.2, 6.5.16.2
20160 6.4.4.4, 7.4.1.3, 7.4.1.10, 7.25.2.1.3 || (logical OR operator), 6.5.14
20161 \U (universal character names), 6.4.3 ~ (bitwise complement operator), 6.5.3.3
20162 \u (universal character names), 6.4.3
20163 \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,
20165 \x hexadecimal digits (hexadecimal-character abs function, 7.20.6.1
20166 escape sequence), 6.4.4.4 absolute-value functions
20167 ^ (bitwise exclusive OR operator), 6.5.11 complex, 7.3.8, G.6.4
20168 ^= (bitwise exclusive OR assignment operator), integer, 7.8.2.1, 7.20.6.1
20169 6.5.16.2 real, 7.12.7, F.9.4
20170 __bool_true_false_are_defined abstract declarator, 6.7.6
20171 macro, 7.16 abstract machine, 5.1.2.3
20175 access, 3.1, 6.7.3 array
20176 accuracy, see floating-point accuracy argument, 6.9.1
20177 acos functions, 7.12.4.1, F.9.1.1 declarator, 6.7.5.2
20178 acos type-generic macro, 7.22 initialization, 6.7.8
20179 acosh functions, 7.12.5.1, F.9.2.1 multidimensional, 6.5.2.1
20180 acosh type-generic macro, 7.22 parameter, 6.9.1
20181 active position, 5.2.2 storage order, 6.5.2.1
20182 actual argument, 3.3 subscript operator ([ ]), 6.5.2.1, 6.5.3.2
20183 actual parameter (deprecated), 3.3 subscripting, 6.5.2.1
20184 addition assignment operator (+=), 6.5.16.2 type, 6.2.5
20185 addition operator (+), 6.5.2.1, 6.5.3.2, 6.5.6, F.3, type conversion, 6.3.2.1
20186 G.5.2 variable length, 6.7.5, 6.7.5.2
20187 additive expressions, 6.5.6, G.5.2 arrow operator (->), 6.5.2.3
20188 address constant, 6.6 as-if rule, 5.1.2.3
20189 address operator (&), 6.3.2.1, 6.5.3.2 ASCII code set, 5.2.1.1
20190 aggregate initialization, 6.7.8 asctime function, 7.23.3.1
20191 aggregate types, 6.2.5 asin functions, 7.12.4.2, F.9.1.2
20192 alert escape sequence (\a), 5.2.2, 6.4.4.4 asin type-generic macro, 7.22, G.7
20193 aliasing, 6.5 asinh functions, 7.12.5.2, F.9.2.2
20194 alignment, 3.2 asinh type-generic macro, 7.22, G.7
20195 pointer, 6.2.5, 6.3.2.3 asm keyword, J.5.10
20196 structure/union member, 6.7.2.1 assert macro, 7.2.1.1
20197 allocated storage, order and contiguity, 7.20.3 assert.h header, 7.2, B.1
20198 and macro, 7.9 assignment
20199 AND operators compound, 6.5.16.2
20200 bitwise (&), 6.5.10 conversion, 6.5.16.1
20201 bitwise assignment (&=), 6.5.16.2 expression, 6.5.16
20202 logical (&&), 6.5.13 operators, 6.3.2.1, 6.5.16
20203 and_eq macro, 7.9 simple, 6.5.16.1
20204 ANSI/IEEE 754, F.1 associativity of operators, 6.5
20205 ANSI/IEEE 854, F.1 asterisk punctuator (*), 6.7.5.1, 6.7.5.2
20206 argc (main function parameter), 5.1.2.2.1 atan functions, 7.12.4.3, F.9.1.3
20207 argument, 3.3 atan type-generic macro, 7.22, G.7
20208 array, 6.9.1 atan2 functions, 7.12.4.4, F.9.1.4
20209 default promotions, 6.5.2.2 atan2 type-generic macro, 7.22
20210 function, 6.5.2.2, 6.9.1 atanh functions, 7.12.5.3, F.9.2.3
20211 macro, substitution, 6.10.3.1 atanh type-generic macro, 7.22, G.7
20212 argument, complex, 7.3.9.1 atexit function, 7.20.4.2, 7.20.4.3, 7.20.4.4,
20213 argv (main function parameter), 5.1.2.2.1 J.5.13
20214 arithmetic constant expression, 6.6 atof function, 7.20.1, 7.20.1.1
20215 arithmetic conversions, usual, see usual arithmetic atoi function, 7.20.1, 7.20.1.2
20216 conversions atol function, 7.20.1, 7.20.1.2
20217 arithmetic operators atoll function, 7.20.1, 7.20.1.2
20218 additive, 6.5.6, G.5.2 auto storage-class specifier, 6.7.1, 6.9
20219 bitwise, 6.5.10, 6.5.11, 6.5.12 automatic storage duration, 5.2.3, 6.2.4
20220 increment and decrement, 6.5.2.4, 6.5.3.1
20221 multiplicative, 6.5.5, G.5.1 backslash character (\), 5.1.1.2, 5.2.1, 6.4.4.4
20222 shift, 6.5.7 backslash escape sequence (\\), 6.4.4.4, 6.10.9
20223 unary, 6.5.3.3 backspace escape sequence (\b), 5.2.2, 6.4.4.4
20224 arithmetic types, 6.2.5 basic character set, 3.6, 3.7.2, 5.2.1
20225 arithmetic, pointer, 6.5.6 basic types, 6.2.5
20229 behavior, 3.4 call by value, 6.5.2.2
20230 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,
20232 bit, 3.5 carg functions, 7.3.9.1, G.6
20233 high order, 3.6 carg type-generic macro, 7.22, G.7
20234 low order, 3.6 carriage-return escape sequence (\r), 5.2.2,
20235 bit-field, 6.7.2.1 6.4.4.4, 7.4.1.10
20236 bitand macro, 7.9 case label, 6.8.1, 6.8.4.2
20237 bitor macro, 7.9 case mapping functions
20238 bitwise operators, 6.5 character, 7.4.2
20239 AND, 6.5.10 wide character, 7.25.3.1
20240 AND assignment (&=), 6.5.16.2 extensible, 7.25.3.2
20241 complement (~), 6.5.3.3 casin functions, 7.3.5.2, G.6
20242 exclusive OR, 6.5.11 type-generic macro for, 7.22
20243 exclusive OR assignment (^=), 6.5.16.2 casinh functions, 7.3.6.2, G.6.2.2
20244 inclusive OR, 6.5.12 type-generic macro for, 7.22
20245 inclusive OR assignment (|=), 6.5.16.2 cast expression, 6.5.4
20246 shift, 6.5.7 cast operator (( )), 6.5.4
20247 blank character, 7.4.1.3 catan functions, 7.3.5.3, G.6
20248 block, 6.8, 6.8.2, 6.8.4, 6.8.5 type-generic macro for, 7.22
20249 block scope, 6.2.1 catanh functions, 7.3.6.3, G.6.2.3
20250 block structure, 6.2.1 type-generic macro for, 7.22
20251 bold type convention, 6.1 cbrt functions, 7.12.7.1, F.9.4.1
20252 bool macro, 7.16 cbrt type-generic macro, 7.22
20253 boolean type, 6.3.1.2 ccos functions, 7.3.5.4, G.6
20254 boolean type conversion, 6.3.1.1, 6.3.1.2 type-generic macro for, 7.22
20255 braces punctuator ({ }), 6.7.2.2, 6.7.2.3, 6.7.8, ccosh functions, 7.3.6.4, G.6.2.4
20256 6.8.2 type-generic macro for, 7.22
20257 brackets operator ([ ]), 6.5.2.1, 6.5.3.2 ceil functions, 7.12.9.1, F.9.6.1
20258 brackets punctuator ([ ]), 6.7.5.2, 6.7.8 ceil type-generic macro, 7.22
20259 branch cuts, 7.3.3 cerf function, 7.26.1
20260 break statement, 6.8.6.3 cerfc function, 7.26.1
20261 broken-down time, 7.23.1, 7.23.2.3, 7.23.3, cexp functions, 7.3.7.1, G.6.3.1
20262 7.23.3.1, 7.23.3.3, 7.23.3.4, 7.23.3.5 type-generic macro for, 7.22
20263 bsearch function, 7.20.5, 7.20.5.1 cexp2 function, 7.26.1
20264 btowc function, 7.24.6.1.1 cexpm1 function, 7.26.1
20265 BUFSIZ macro, 7.19.1, 7.19.2, 7.19.5.5 char type, 6.2.5, 6.3.1.1, 6.7.2
20266 byte, 3.6, 6.5.3.4 char type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,
20267 byte input/output functions, 7.19.1 6.3.1.8
20268 byte-oriented stream, 7.19.2 CHAR_BIT macro, 5.2.4.2.1
20269 CHAR_MAX macro, 5.2.4.2.1, 7.11.2.1
20270 C program, 5.1.1.1 CHAR_MIN macro, 5.2.4.2.1
20271 C++, 7.8.1, 7.18.2, 7.18.3, 7.18.4 character, 3.7, 3.7.1
20272 cabs functions, 7.3.8.1, G.6 character array initialization, 6.7.8
20273 type-generic macro for, 7.22 character case mapping functions, 7.4.2
20274 cacos functions, 7.3.5.1, G.6.1.1 wide character, 7.25.3.1
20275 type-generic macro for, 7.22 extensible, 7.25.3.2
20276 cacosh functions, 7.3.6.1, G.6.2.1 character classification functions, 7.4.1
20277 type-generic macro for, 7.22 wide character, 7.25.2.1
20278 calendar time, 7.23.1, 7.23.2.2, 7.23.2.3, 7.23.2.4, extensible, 7.25.2.2
20279 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
20283 character display semantics, 5.2.2 complex.h header, 5.2.4.2.2, 7.3, 7.22, 7.26.1,
20284 character handling header, 7.4, 7.11.1.1 G.6, J.5.17
20285 character input/output functions, 7.19.7 compliance, see conformance
20286 wide character, 7.24.3 components of time, 7.23.1
20287 character sets, 5.2.1 composite type, 6.2.7
20288 character string literal, see string literal compound assignment, 6.5.16.2
20289 character type conversion, 6.3.1.1 compound literals, 6.5.2.5
20290 character types, 6.2.5, 6.7.8 compound statement, 6.8.2
20291 cimag functions, 7.3.9.2, 7.3.9.4, G.6 compound-literal operator (( ){ }), 6.5.2.5
20292 cimag type-generic macro, 7.22, G.7 concatenation functions
20293 cis function, G.6 string, 7.21.3
20294 classification functions wide string, 7.24.4.3
20295 character, 7.4.1 concatenation, preprocessing, see preprocessing
20296 floating-point, 7.12.3 concatenation
20297 wide character, 7.25.2.1 conceptual models, 5.1
20298 extensible, 7.25.2.2 conditional inclusion, 6.10.1
20299 clearerr function, 7.19.10.1 conditional operator (? :), 6.5.15
20300 clgamma function, 7.26.1 conformance, 4
20301 clock function, 7.23.2.1 conj functions, 7.3.9.3, G.6
20302 clock_t type, 7.23.1, 7.23.2.1 conj type-generic macro, 7.22
20303 CLOCKS_PER_SEC macro, 7.23.1, 7.23.2.1 const type qualifier, 6.7.3
20304 clog functions, 7.3.7.2, G.6.3.2 const-qualified type, 6.2.5, 6.3.2.1, 6.7.3
20305 type-generic macro for, 7.22 constant expression, 6.6, F.7.4
20306 clog10 function, 7.26.1 constants, 6.4.4
20307 clog1p function, 7.26.1 as primary expression, 6.5.1
20308 clog2 function, 7.26.1 character, 6.4.4.4
20309 collating sequences, 5.2.1 enumeration, 6.2.1, 6.4.4.3
20310 colon punctuator (:), 6.7.2.1 floating, 6.4.4.2
20311 comma operator (,), 6.5.17 hexadecimal, 6.4.4.1
20312 comma punctuator (,), 6.5.2, 6.7, 6.7.2.1, 6.7.2.2, integer, 6.4.4.1
20313 6.7.2.3, 6.7.8 octal, 6.4.4.1
20314 command processor, 7.20.4.6 constraint, 3.8, 4
20315 comment delimiters (/* */ and //), 6.4.9 content of structure/union/enumeration, 6.7.2.3
20316 comments, 5.1.1.2, 6.4, 6.4.9 contiguity of allocated storage, 7.20.3
20317 common extensions, J.5 continue statement, 6.8.6.2
20318 common initial sequence, 6.5.2.3 contracted expression, 6.5, 7.12.2, F.6
20319 common real type, 6.3.1.8 control character, 5.2.1, 7.4
20320 common warnings, I control wide character, 7.25.2
20321 comparison functions, 7.20.5, 7.20.5.1, 7.20.5.2 conversion, 6.3
20322 string, 7.21.4 arithmetic operands, 6.3.1
20323 wide string, 7.24.4.4 array argument, 6.9.1 *
20324 comparison macros, 7.12.14 array parameter, 6.9.1
20325 comparison, pointer, 6.5.8 arrays, 6.3.2.1
20326 compatible type, 6.2.7, 6.7.2, 6.7.3, 6.7.5 boolean, 6.3.1.2
20327 compl macro, 7.9 boolean, characters, and integers, 6.3.1.1
20328 complement operator (~), 6.5.3.3 by assignment, 6.5.16.1
20329 complex macro, 7.3.1 by return statement, 6.8.6.4
20330 complex numbers, 6.2.5, G complex types, 6.3.1.6
20331 complex type conversion, 6.3.1.6, 6.3.1.7 explicit, 6.3
20332 complex type domain, 6.2.5 function, 6.3.2.1
20333 complex types, 6.2.5, 6.7.2, G function argument, 6.5.2.2, 6.9.1
20337 function designators, 6.3.2.1 type-generic macro for, 7.22
20338 function parameter, 6.9.1 csinh functions, 7.3.6.5, G.6.2.5
20339 imaginary, G.4.1 type-generic macro for, 7.22
20340 imaginary and complex, G.4.3 csqrt functions, 7.3.8.3, G.6.4.2
20341 implicit, 6.3 type-generic macro for, 7.22
20342 lvalues, 6.3.2.1 ctan functions, 7.3.5.6, G.6
20343 pointer, 6.3.2.1, 6.3.2.3 type-generic macro for, 7.22
20344 real and complex, 6.3.1.7 ctanh functions, 7.3.6.6, G.6.2.6
20345 real and imaginary, G.4.2 type-generic macro for, 7.22
20346 real floating and integer, 6.3.1.4, F.3, F.4 ctgamma function, 7.26.1
20347 real floating types, 6.3.1.5, F.3 ctime function, 7.23.3.2
20348 signed and unsigned integers, 6.3.1.3 ctype.h header, 7.4, 7.26.2
20349 usual arithmetic, see usual arithmetic current object, 6.7.8
20350 conversions CX_LIMITED_RANGE pragma, 6.10.6, 7.3.4
20352 conversion functions data stream, see streams
20353 multibyte/wide character, 7.20.7 date and time header, 7.23
20354 extended, 7.24.6 Daylight Saving Time, 7.23.1
20355 restartable, 7.24.6.3 DBL_DIG macro, 5.2.4.2.2
20356 multibyte/wide string, 7.20.8 DBL_EPSILON macro, 5.2.4.2.2
20357 restartable, 7.24.6.4 DBL_MANT_DIG macro, 5.2.4.2.2
20358 numeric, 7.8.2.3, 7.20.1 DBL_MAX macro, 5.2.4.2.2
20359 wide string, 7.8.2.4, 7.24.4.1 DBL_MAX_10_EXP macro, 5.2.4.2.2
20360 single byte/wide character, 7.24.6.1 DBL_MAX_EXP macro, 5.2.4.2.2
20361 time, 7.23.3 DBL_MIN macro, 5.2.4.2.2
20362 wide character, 7.24.5 DBL_MIN_10_EXP macro, 5.2.4.2.2
20363 conversion specifier, 7.19.6.1, 7.19.6.2, 7.24.2.1, DBL_MIN_EXP macro, 5.2.4.2.2
20364 7.24.2.2 decimal constant, 6.4.4.1
20365 conversion state, 7.20.7, 7.24.6, 7.24.6.2.1, decimal digit, 5.2.1
20366 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
20367 7.24.6.4.1, 7.24.6.4.2 DECIMAL_DIG macro, 5.2.4.2.2, 7.19.6.1,
20368 conversion state functions, 7.24.6.2 7.20.1.3, 7.24.2.1, 7.24.4.1.1, F.5
20369 copying functions declaration specifiers, 6.7
20370 string, 7.21.2 declarations, 6.7
20371 wide string, 7.24.4.2 function, 6.7.5.3
20372 copysign functions, 7.3.9.4, 7.12.11.1, F.3, pointer, 6.7.5.1
20373 F.9.8.1 structure/union, 6.7.2.1
20374 copysign type-generic macro, 7.22 typedef, 6.7.7
20375 correctly rounded result, 3.9 declarator, 6.7.5
20376 corresponding real type, 6.2.5 abstract, 6.7.6
20377 cos functions, 7.12.4.5, F.9.1.5 declarator type derivation, 6.2.5, 6.7.5
20378 cos type-generic macro, 7.22, G.7 decrement operators, see arithmetic operators,
20379 cosh functions, 7.12.5.4, F.9.2.4 increment and decrement
20380 cosh type-generic macro, 7.22, G.7 default argument promotions, 6.5.2.2
20381 cpow functions, 7.3.8.2, G.6.4.1 default initialization, 6.7.8
20382 type-generic macro for, 7.22 default label, 6.8.1, 6.8.4.2
20383 cproj functions, 7.3.9.4, G.6 define preprocessing directive, 6.10.3
20384 cproj type-generic macro, 7.22 defined operator, 6.10.1, 6.10.8
20385 creal functions, 7.3.9.5, G.6 definition, 6.7
20386 creal type-generic macro, 7.22, G.7 function, 6.9.1
20387 csin functions, 7.3.5.5, G.6 derived declarator types, 6.2.5
20391 derived types, 6.2.5 end-of-file indicator, 7.19.1, 7.19.5.3, 7.19.7.1,
20392 designated initializer, 6.7.8 7.19.7.5, 7.19.7.6, 7.19.7.11, 7.19.9.2,
20393 destringizing, 6.10.9 7.19.9.3, 7.19.10.1, 7.19.10.2, 7.24.3.1,
20394 device input/output, 5.1.2.3 7.24.3.10
20395 diagnostic message, 3.10, 5.1.1.3 end-of-file macro, see EOF macro
20396 diagnostics, 5.1.1.3 end-of-line indicator, 5.2.1
20397 diagnostics header, 7.2 endif preprocessing directive, 6.10.1
20398 difftime function, 7.23.2.2 enum type, 6.2.5, 6.7.2, 6.7.2.2
20399 digit, 5.2.1, 7.4 enumerated type, 6.2.5
20400 digraphs, 6.4.6 enumeration, 6.2.5, 6.7.2.2
20401 direct input/output functions, 7.19.8 enumeration constant, 6.2.1, 6.4.4.3
20402 display device, 5.2.2 enumeration content, 6.7.2.3
20403 div function, 7.20.6.2 enumeration members, 6.7.2.2
20404 div_t type, 7.20 enumeration specifiers, 6.7.2.2
20405 division assignment operator (/=), 6.5.16.2 enumeration tag, 6.2.3, 6.7.2.3
20406 division operator (/), 6.5.5, F.3, G.5.1 enumerator, 6.7.2.2
20407 do statement, 6.8.5.2 environment, 5
20408 documentation of implementation, 4 environment functions, 7.20.4
20409 domain error, 7.12.1, 7.12.4.1, 7.12.4.2, 7.12.4.4, environment list, 7.20.4.5
20410 7.12.5.1, 7.12.5.3, 7.12.6.5, 7.12.6.7, environmental considerations, 5.2
20411 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,
20412 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,
20413 7.12.9.7, 7.12.10.1, 7.12.10.2, 7.12.10.3 7.24.2.1
20414 dot operator (.), 6.5.2.3 EOF macro, 7.4, 7.19.1, 7.19.5.1, 7.19.5.2,
20415 double _Complex type, 6.2.5 7.19.6.2, 7.19.6.7, 7.19.6.9, 7.19.6.11,
20416 double _Complex type conversion, 6.3.1.6, 7.19.6.14, 7.19.7.1, 7.19.7.3, 7.19.7.4,
20417 6.3.1.7, 6.3.1.8 7.19.7.5, 7.19.7.6, 7.19.7.9, 7.19.7.10,
20418 double _Imaginary type, G.2 7.19.7.11, 7.24.1, 7.24.2.2, 7.24.2.4,
20419 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,
20420 7.24.2.2, F.2 7.24.3.4, 7.24.6.1.1, 7.24.6.1.2
20421 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
20422 6.3.1.8 equal-to operator, see equality operator
20423 double-precision arithmetic, 5.1.2.3 equality expressions, 6.5.9
20424 double-quote escape sequence (\"), 6.4.4.4, equality operator (==), 6.5.9
20425 6.4.5, 6.10.9 ERANGE macro, 7.5, 7.8.2.3, 7.8.2.4, 7.12.1,
20426 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
20428 EDOM macro, 7.5, 7.12.1, see also domain error erf functions, 7.12.8.1, F.9.5.1
20429 effective type, 6.5 erf type-generic macro, 7.22
20430 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
20431 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
20432 see also encoding error errno macro, 7.1.3, 7.3.2, 7.5, 7.8.2.3, 7.8.2.4,
20433 element type, 6.2.5 7.12.1, 7.14.1.1, 7.19.3, 7.19.9.3, 7.19.10.4,
20434 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,
20435 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,
20436 else preprocessing directive, 6.10.1 7.24.6.3.3, 7.24.6.4.1, 7.24.6.4.2, J.5.17
20437 else statement, 6.8.4.1 errno.h header, 7.5, 7.26.3
20438 empty statement, 6.8.3 error
20439 encoding error, 7.19.3, 7.24.3.1, 7.24.3.3, domain, see domain error
20440 7.24.6.3.2, 7.24.6.3.3, 7.24.6.4.1, 7.24.6.4.2 encoding, see encoding error
20441 end-of-file, 7.24.1 range, see range error
20445 error conditions, 7.12.1 extended characters, 5.2.1
20446 error functions, 7.12.8, F.9.5 extended integer types, 6.2.5, 6.3.1.1, 6.4.4.1,
20447 error indicator, 7.19.1, 7.19.5.3, 7.19.7.1, 7.18
20448 7.19.7.3, 7.19.7.5, 7.19.7.6, 7.19.7.8, extended multibyte/wide character conversion
20449 7.19.7.9, 7.19.9.2, 7.19.10.1, 7.19.10.3, utilities, 7.24.6
20450 7.24.3.1, 7.24.3.3 extensible wide character case mapping functions,
20451 error preprocessing directive, 4, 6.10.5 7.25.3.2
20452 error-handling functions, 7.19.10, 7.21.6.2 extensible wide character classification functions,
20453 escape character (\), 6.4.4.4 7.25.2.2
20454 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
20455 evaluation format, 5.2.4.2.2, 6.4.4.2, 7.12 external definition, 6.9
20456 evaluation method, 5.2.4.2.2, 6.5, F.7.5 external identifiers, underscore, 7.1.3
20457 evaluation order, 6.5 external linkage, 6.2.2
20458 exceptional condition, 6.5, 7.12.1 external name, 6.4.2.1
20459 excess precision, 5.2.4.2.2, 6.3.1.5, 6.3.1.8, external object definitions, 6.9.2
20461 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
20462 exclusive OR operators fabs type-generic macro, 7.22, G.7
20463 bitwise (^), 6.5.11 false macro, 7.16
20464 bitwise assignment (^=), 6.5.16.2 fclose function, 7.19.5.1
20465 executable program, 5.1.1.1 fdim functions, 7.12.12.1, F.9.9.1
20466 execution character set, 5.2.1 fdim type-generic macro, 7.22
20467 execution environment, 5, 5.1.2, see also FE_ALL_EXCEPT macro, 7.6
20468 environmental limits FE_DFL_ENV macro, 7.6
20469 execution sequence, 5.1.2.3, 6.8 FE_DIVBYZERO macro, 7.6, 7.12, F.3
20470 exit function, 5.1.2.2.3, 7.19.3, 7.20, 7.20.4.3, FE_DOWNWARD macro, 7.6, F.3
20471 7.20.4.4 FE_INEXACT macro, 7.6, F.3
20472 EXIT_FAILURE macro, 7.20, 7.20.4.3 FE_INVALID macro, 7.6, 7.12, F.3
20473 EXIT_SUCCESS macro, 7.20, 7.20.4.3 FE_OVERFLOW macro, 7.6, 7.12, F.3
20474 exp functions, 7.12.6.1, F.9.3.1 FE_TONEAREST macro, 7.6, F.3
20475 exp type-generic macro, 7.22 FE_TOWARDZERO macro, 7.6, F.3
20476 exp2 functions, 7.12.6.2, F.9.3.2 FE_UNDERFLOW macro, 7.6, F.3
20477 exp2 type-generic macro, 7.22 FE_UPWARD macro, 7.6, F.3
20478 explicit conversion, 6.3 feclearexcept function, 7.6.2, 7.6.2.1, F.3
20479 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
20480 expm1 type-generic macro, 7.22 fegetexceptflag function, 7.6.2, 7.6.2.2, F.3
20481 exponent part, 6.4.4.2 fegetround function, 7.6, 7.6.3.1, F.3
20482 exponential functions feholdexcept function, 7.6.4.2, 7.6.4.3,
20483 complex, 7.3.7, G.6.3 7.6.4.4, F.3
20484 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
20485 expression, 6.5 FENV_ACCESS pragma, 6.10.6, 7.6.1, F.7, F.8,
20486 assignment, 6.5.16 F.9
20487 cast, 6.5.4 fenv_t type, 7.6
20488 constant, 6.6 feof function, 7.19.10.2
20489 full, 6.8 feraiseexcept function, 7.6.2, 7.6.2.3, F.3
20490 order of evaluation, 6.5 ferror function, 7.19.10.3
20491 parenthesized, 6.5.1 fesetenv function, 7.6.4.3, F.3
20492 primary, 6.5.1 fesetexceptflag function, 7.6.2, 7.6.2.4, F.3
20493 unary, 6.5.3 fesetround function, 7.6, 7.6.3.2, F.3
20494 expression statement, 6.8.3 fetestexcept function, 7.6.2, 7.6.2.5, F.3
20495 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
20499 fexcept_t type, 7.6, F.3 floating-point status flag, 7.6, F.7.6
20500 fflush function, 7.19.5.2, 7.19.5.3 floor functions, 7.12.9.2, F.9.6.2
20501 fgetc function, 7.19.1, 7.19.3, 7.19.7.1, floor type-generic macro, 7.22
20502 7.19.7.5, 7.19.8.1 FLT_DIG macro, 5.2.4.2.2
20503 fgetpos function, 7.19.2, 7.19.9.1, 7.19.9.3 FLT_EPSILON macro, 5.2.4.2.2
20504 fgets function, 7.19.1, 7.19.7.2 FLT_EVAL_METHOD macro, 5.2.4.2.2, 6.8.6.4,
20505 fgetwc function, 7.19.1, 7.19.3, 7.24.3.1, 7.12
20506 7.24.3.6 FLT_MANT_DIG macro, 5.2.4.2.2
20507 fgetws function, 7.19.1, 7.24.3.2 FLT_MAX macro, 5.2.4.2.2
20508 field width, 7.19.6.1, 7.24.2.1 FLT_MAX_10_EXP macro, 5.2.4.2.2
20509 file, 7.19.3 FLT_MAX_EXP macro, 5.2.4.2.2
20510 access functions, 7.19.5 FLT_MIN macro, 5.2.4.2.2
20511 name, 7.19.3 FLT_MIN_10_EXP macro, 5.2.4.2.2
20512 operations, 7.19.4 FLT_MIN_EXP macro, 5.2.4.2.2
20513 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,
20514 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
20515 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
20516 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
20517 7.24.3.3, 7.24.3.10 fma type-generic macro, 7.22
20518 positioning functions, 7.19.9 fmax functions, 7.12.12.2, F.9.9.2
20519 file scope, 6.2.1, 6.9 fmax type-generic macro, 7.22
20520 FILE type, 7.19.1, 7.19.3 fmin functions, 7.12.12.3, F.9.9.3
20521 FILENAME_MAX macro, 7.19.1 fmin type-generic macro, 7.22
20522 flags, 7.19.6.1, 7.24.2.1 fmod functions, 7.12.10.1, F.9.7.1
20523 floating-point status, see floating-point status fmod type-generic macro, 7.22
20524 flag fopen function, 7.19.5.3, 7.19.5.4
20525 flexible array member, 6.7.2.1 FOPEN_MAX macro, 7.19.1, 7.19.3, 7.19.4.3
20526 float _Complex type, 6.2.5 for statement, 6.8.5, 6.8.5.3
20527 float _Complex type conversion, 6.3.1.6, form-feed character, 5.2.1, 6.4
20528 6.3.1.7, 6.3.1.8 form-feed escape sequence (\f), 5.2.2, 6.4.4.4,
20529 float _Imaginary type, G.2 7.4.1.10
20530 float type, 6.2.5, 6.4.4.2, 6.7.2, F.2 formal argument (deprecated), 3.15
20531 float type conversion, 6.3.1.4, 6.3.1.5, 6.3.1.7, formal parameter, 3.15
20532 6.3.1.8 formatted input/output functions, 7.11.1.1, 7.19.6
20533 float.h header, 4, 5.2.4.2.2, 7.7, 7.20.1.3, wide character, 7.24.2
20534 7.24.4.1.1 fortran keyword, J.5.9
20535 float_t type, 7.12, J.5.6 forward reference, 3.11
20536 floating constant, 6.4.4.2 FP_CONTRACT pragma, 6.5, 6.10.6, 7.12.2, see
20537 floating suffix, f or F, 6.4.4.2 also contracted expression
20538 floating type conversion, 6.3.1.4, 6.3.1.5, 6.3.1.7, FP_FAST_FMA macro, 7.12
20539 F.3, F.4 FP_FAST_FMAF macro, 7.12
20540 floating types, 6.2.5, 6.11.1 FP_FAST_FMAL macro, 7.12
20541 floating-point accuracy, 5.2.4.2.2, 6.4.4.2, 6.5, FP_ILOGB0 macro, 7.12, 7.12.6.5
20542 7.20.1.3, F.5, see also contracted expression FP_ILOGBNAN macro, 7.12, 7.12.6.5
20543 floating-point arithmetic functions, 7.12, F.9 FP_INFINITE macro, 7.12, F.3
20544 floating-point classification functions, 7.12.3 FP_NAN macro, 7.12, F.3
20545 floating-point control mode, 7.6, F.7.6 FP_NORMAL macro, 7.12, F.3
20546 floating-point environment, 7.6, F.7, F.7.6 FP_SUBNORMAL macro, 7.12, F.3
20547 floating-point exception, 7.6, 7.6.2, F.9 FP_ZERO macro, 7.12, F.3
20548 floating-point number, 5.2.4.2.2, 6.2.5 fpclassify macro, 7.12.3.1, F.3
20549 floating-point rounding mode, 5.2.4.2.2 fpos_t type, 7.19.1, 7.19.2
20553 fprintf function, 7.8.1, 7.19.1, 7.19.6.1, language, 6.11
20554 7.19.6.2, 7.19.6.3, 7.19.6.5, 7.19.6.6, library, 7.26
20555 7.19.6.8, 7.24.2.2, F.3 fwide function, 7.19.2, 7.24.3.5
20556 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,
20557 7.19.7.8, 7.19.8.2 7.24.2.1, 7.24.2.2, 7.24.2.3, 7.24.2.5,
20558 fputs function, 7.19.1, 7.19.7.4 7.24.2.11
20559 fputwc function, 7.19.1, 7.19.3, 7.24.3.3, fwrite function, 7.19.1, 7.19.8.2
20560 7.24.3.8 fwscanf function, 7.8.1, 7.19.1, 7.24.2.2,
20561 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
20562 fread function, 7.19.1, 7.19.8.1
20563 free function, 7.20.3.2, 7.20.3.4 gamma functions, 7.12.8, F.9.5
20564 freestanding execution environment, 4, 5.1.2, general utilities, 7.20
20565 5.1.2.1 wide string, 7.24.4
20566 freopen function, 7.19.2, 7.19.5.4 general wide string utilities, 7.24.4
20567 frexp functions, 7.12.6.4, F.9.3.4 generic parameters, 7.22
20568 frexp type-generic macro, 7.22 getc function, 7.19.1, 7.19.7.5, 7.19.7.6
20569 fscanf function, 7.8.1, 7.19.1, 7.19.6.2, getchar function, 7.19.1, 7.19.7.6
20570 7.19.6.4, 7.19.6.7, 7.19.6.9, F.3 getenv function, 7.20.4.5
20571 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
20572 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
20573 fsetpos function, 7.19.2, 7.19.5.3, 7.19.7.11, getwchar function, 7.19.1, 7.24.3.7
20574 7.19.9.1, 7.19.9.3, 7.24.3.10 gmtime function, 7.23.3.3
20575 ftell function, 7.19.9.2, 7.19.9.4 goto statement, 6.2.1, 6.8.1, 6.8.6.1
20576 full declarator, 6.7.5 graphic characters, 5.2.1
20577 full expression, 6.8 greater-than operator (>), 6.5.8
20578 fully buffered stream, 7.19.3 greater-than-or-equal-to operator (>=), 6.5.8
20580 argument, 6.5.2.2, 6.9.1 header, 5.1.1.1, 7.1.2, see also standard headers
20581 body, 6.9.1 header names, 6.4, 6.4.7, 6.10.2
20582 call, 6.5.2.2 hexadecimal constant, 6.4.4.1
20583 library, 7.1.4 hexadecimal digit, 6.4.4.1, 6.4.4.2, 6.4.4.4
20584 declarator, 6.7.5.3, 6.11.6 hexadecimal prefix, 6.4.4.1
20585 definition, 6.7.5.3, 6.9.1, 6.11.7 hexadecimal-character escape sequence
20586 designator, 6.3.2.1 (\x hexadecimal digits), 6.4.4.4
20587 image, 5.2.3 high-order bit, 3.6
20588 library, 5.1.1.1, 7.1.4 horizontal-tab character, 5.2.1, 6.4
20589 name length, 5.2.4.1, 6.4.2.1, 6.11.3 horizontal-tab escape sequence (\r), 7.25.2.1.3
20590 parameter, 5.1.2.2.1, 6.5.2.2, 6.7, 6.9.1 horizontal-tab escape sequence (\t), 5.2.2,
20591 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
20592 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
20593 prototype scope, 6.2.1, 6.7.5.2 HUGE_VAL macro, 7.12, 7.12.1, 7.20.1.3,
20594 recursive call, 6.5.2.2 7.24.4.1.1, F.9
20595 return, 6.8.6.4 HUGE_VALF macro, 7.12, 7.12.1, 7.20.1.3,
20596 scope, 6.2.1 7.24.4.1.1, F.9
20597 type, 6.2.5 HUGE_VALL macro, 7.12, 7.12.1, 7.20.1.3,
20598 type conversion, 6.3.2.1 7.24.4.1.1, F.9
20599 function specifiers, 6.7.4 hyperbolic functions
20600 function type, 6.2.5 complex, 7.3.6, G.6.2
20601 function-call operator (( )), 6.5.2.2 real, 7.12.5, F.9.2
20602 function-like macro, 6.10.3 hypot functions, 7.12.7.3, F.9.4.3
20603 future directions hypot type-generic macro, 7.22
20607 I macro, 7.3.1, 7.3.9.4, G.6 initial position, 5.2.2
20608 identifier, 6.4.2.1, 6.5.1 initial shift state, 5.2.1.2
20609 linkage, see linkage initialization, 5.1.2, 6.2.4, 6.3.2.1, 6.5.2.5, 6.7.8,
20610 maximum length, 6.4.2.1 F.7.5
20611 name spaces, 6.2.3 in blocks, 6.8
20612 reserved, 6.4.1, 7.1.3 initializer, 6.7.8
20613 scope, 6.2.1 permitted form, 6.6
20614 type, 6.2.5 string literal, 6.3.2.1
20615 identifier list, 6.7.5 inline, 6.7.4
20616 identifier nondigit, 6.4.2.1 inner scope, 6.2.1
20617 IEC 559, F.1 input failure, 7.24.2.6, 7.24.2.8, 7.24.2.10
20618 IEC 60559, 2, 5.1.2.3, 5.2.4.2.2, 6.10.8, 7.3.3, 7.6, input/output functions
20619 7.6.4.2, 7.12.1, 7.12.10.2, 7.12.14, F, G, H.1 character, 7.19.7
20620 IEEE 754, F.1 direct, 7.19.8
20621 IEEE 854, F.1 formatted, 7.19.6
20622 IEEE floating-point arithmetic standard, see wide character, 7.24.2
20623 IEC 60559, ANSI/IEEE 754, wide character, 7.24.3
20624 ANSI/IEEE 854 formatted, 7.24.2
20625 if preprocessing directive, 5.2.4.2.1, 5.2.4.2.2, input/output header, 7.19
20626 6.10.1, 7.1.4 input/output, device, 5.1.2.3
20627 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
20628 ifdef preprocessing directive, 6.10.1 int type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,
20629 ifndef preprocessing directive, 6.10.1 6.3.1.8
20630 ilogb functions, 7.12, 7.12.6.5, F.9.3.5 INT_FASTN_MAX macros, 7.18.2.3
20631 ilogb type-generic macro, 7.22 INT_FASTN_MIN macros, 7.18.2.3
20632 imaginary macro, 7.3.1, G.6 int_fastN_t types, 7.18.1.3
20633 imaginary numbers, G INT_LEASTN_MAX macros, 7.18.2.2
20634 imaginary type domain, G.2 INT_LEASTN_MIN macros, 7.18.2.2
20635 imaginary types, G int_leastN_t types, 7.18.1.2
20636 imaxabs function, 7.8.2.1 INT_MAX macro, 5.2.4.2.1, 7.12, 7.12.6.5
20637 imaxdiv function, 7.8, 7.8.2.2 INT_MIN macro, 5.2.4.2.1, 7.12
20638 imaxdiv_t type, 7.8 integer arithmetic functions, 7.8.2.1, 7.8.2.2,
20639 implementation, 3.12 7.20.6
20640 implementation limit, 3.13, 4, 5.2.4.2, 6.4.2.1, integer character constant, 6.4.4.4
20641 6.7.5, 6.8.4.2, E, see also environmental integer constant, 6.4.4.1
20642 limits integer constant expression, 6.6
20643 implementation-defined behavior, 3.4.1, 4, J.3 integer conversion rank, 6.3.1.1
20644 implementation-defined value, 3.17.1 integer promotions, 5.1.2.3, 5.2.4.2.1, 6.3.1.1,
20645 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,
20646 implicit initialization, 6.7.8 7.19.6.1, 7.24.2.1
20647 include preprocessing directive, 5.1.1.2, 6.10.2 integer suffix, 6.4.4.1
20648 inclusive OR operators integer type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,
20649 bitwise (|), 6.5.12 F.3, F.4
20650 bitwise assignment (|=), 6.5.16.2 integer types, 6.2.5, 7.18
20651 incomplete type, 6.2.5 extended, 6.2.5, 6.3.1.1, 6.4.4.1, 7.18
20652 increment operators, see arithmetic operators, interactive device, 5.1.2.3, 7.19.3, 7.19.5.3
20653 increment and decrement internal linkage, 6.2.2
20654 indeterminate value, 3.17.2 internal name, 6.4.2.1
20655 indirection operator (*), 6.5.2.1, 6.5.3.2 interrupt, 5.2.3
20656 inequality operator (!=), 6.5.9 INTMAX_C macro, 7.18.4.2
20657 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
20661 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,
20662 intmax_t type, 7.18.1.5, 7.19.6.1, 7.19.6.2, 7.25.2.2.1
20663 7.24.2.1, 7.24.2.2 iswblank function, 7.25.2.1.3, 7.25.2.2.1
20664 INTN_C macros, 7.18.4.1 iswcntrl function, 7.25.2.1.2, 7.25.2.1.4,
20665 INTN_MAX macros, 7.18.2.1 7.25.2.1.7, 7.25.2.1.11, 7.25.2.2.1
20666 INTN_MIN macros, 7.18.2.1 iswctype function, 7.25.2.2.1, 7.25.2.2.2
20667 intN_t types, 7.18.1.1 iswdigit function, 7.25.2.1.1, 7.25.2.1.2,
20668 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
20669 INTPTR_MIN macro, 7.18.2.4 iswgraph function, 7.25.2.1, 7.25.2.1.6,
20670 intptr_t type, 7.18.1.4 7.25.2.1.10, 7.25.2.2.1
20671 inttypes.h header, 7.8, 7.26.4 iswlower function, 7.25.2.1.2, 7.25.2.1.7,
20672 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
20673 isalpha function, 7.4.1.1, 7.4.1.2 iswprint function, 7.25.2.1.6, 7.25.2.1.8,
20674 isblank function, 7.4.1.3 7.25.2.2.1
20675 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,
20676 7.4.1.11 7.25.2.1.7, 7.25.2.1.9, 7.25.2.1.10,
20677 isdigit function, 7.4.1.1, 7.4.1.2, 7.4.1.5, 7.25.2.1.11, 7.25.2.2.1
20678 7.4.1.7, 7.4.1.11, 7.11.1.1 iswspace function, 7.19.6.2, 7.24.2.2,
20679 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,
20680 isgraph function, 7.4.1.6 7.25.2.1.7, 7.25.2.1.9, 7.25.2.1.10,
20681 isgreater macro, 7.12.14.1, F.3 7.25.2.1.11, 7.25.2.2.1
20682 isgreaterequal macro, 7.12.14.2, F.3 iswupper function, 7.25.2.1.2, 7.25.2.1.11,
20683 isinf macro, 7.12.3.3 7.25.2.2.1, 7.25.3.1.1, 7.25.3.1.2
20684 isless macro, 7.12.14.3, F.3 iswxdigit function, 7.25.2.1.12, 7.25.2.2.1
20685 islessequal macro, 7.12.14.4, F.3 isxdigit function, 7.4.1.12, 7.11.1.1
20686 islessgreater macro, 7.12.14.5, F.3 italic type convention, 3, 6.1
20687 islower function, 7.4.1.2, 7.4.1.7, 7.4.2.1, iteration statements, 6.8.5
20689 isnan macro, 7.12.3.4, F.3 jmp_buf type, 7.13
20690 isnormal macro, 7.12.3.5 jump statements, 6.8.6
20692 ISO 4217, 2, 7.11.2.1 keywords, 6.4.1, G.2, J.5.9, J.5.10
20693 ISO 8601, 2, 7.23.3.5 known constant size, 6.2.5
20694 ISO/IEC 10646, 2, 6.4.2.1, 6.4.3, 6.10.8
20695 ISO/IEC 10976-1, H.1 L_tmpnam macro, 7.19.1, 7.19.4.4
20696 ISO/IEC 2382-1, 2, 3 label name, 6.2.1, 6.2.3
20697 ISO/IEC 646, 2, 5.2.1.1 labeled statement, 6.8.1
20698 ISO/IEC 9945-2, 7.11 labs function, 7.20.6.1
20699 ISO/IEC TR 10176, D language, 6
20700 iso646.h header, 4, 7.9 future directions, 6.11
20701 isprint function, 5.2.2, 7.4.1.8 syntax summary, A
20702 ispunct function, 7.4.1.2, 7.4.1.7, 7.4.1.9, Latin alphabet, 5.2.1, 6.4.2.1
20703 7.4.1.11 LC_ALL macro, 7.11, 7.11.1.1, 7.11.2.1
20704 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,
20705 7.4.1.10, 7.4.1.11, 7.19.6.2, 7.20.1.3, 7.24.4.4.2
20706 7.20.1.4, 7.24.2.2 LC_CTYPE macro, 7.11, 7.11.1.1, 7.20, 7.20.7,
20707 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,
20708 isupper function, 7.4.1.2, 7.4.1.11, 7.4.2.1, 7.25.3.2.1, 7.25.3.2.2
20709 7.4.2.2 LC_MONETARY macro, 7.11, 7.11.1.1, 7.11.2.1
20710 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
20711 7.25.2.1.10, 7.25.2.2.1 LC_TIME macro, 7.11, 7.11.1.1, 7.23.3.5
20715 lconv structure type, 7.11 llabs function, 7.20.6.1
20716 LDBL_DIG macro, 5.2.4.2.2 lldiv function, 7.20.6.2
20717 LDBL_EPSILON macro, 5.2.4.2.2 lldiv_t type, 7.20
20718 LDBL_MANT_DIG macro, 5.2.4.2.2 LLONG_MAX macro, 5.2.4.2.1, 7.20.1.4,
20719 LDBL_MAX macro, 5.2.4.2.2 7.24.4.1.2
20720 LDBL_MAX_10_EXP macro, 5.2.4.2.2 LLONG_MIN macro, 5.2.4.2.1, 7.20.1.4,
20721 LDBL_MAX_EXP macro, 5.2.4.2.2 7.24.4.1.2
20722 LDBL_MIN macro, 5.2.4.2.2 llrint functions, 7.12.9.5, F.3, F.9.6.5
20723 LDBL_MIN_10_EXP macro, 5.2.4.2.2 llrint type-generic macro, 7.22
20724 LDBL_MIN_EXP macro, 5.2.4.2.2 llround functions, 7.12.9.7, F.9.6.7
20725 ldexp functions, 7.12.6.6, F.9.3.6 llround type-generic macro, 7.22
20726 ldexp type-generic macro, 7.22 local time, 7.23.1
20727 ldiv function, 7.20.6.2 locale, 3.4.2
20728 ldiv_t type, 7.20 locale-specific behavior, 3.4.2, J.4
20729 leading underscore in identifiers, 7.1.3 locale.h header, 7.11, 7.26.5
20730 left-shift assignment operator (<<=), 6.5.16.2 localeconv function, 7.11.1.1, 7.11.2.1
20731 left-shift operator (<<), 6.5.7 localization, 7.11
20732 length localtime function, 7.23.3.4
20733 external name, 5.2.4.1, 6.4.2.1, 6.11.3 log functions, 7.12.6.7, F.9.3.7
20734 function name, 5.2.4.1, 6.4.2.1, 6.11.3 log type-generic macro, 7.22
20735 identifier, 6.4.2.1 log10 functions, 7.12.6.8, F.9.3.8
20736 internal name, 5.2.4.1, 6.4.2.1 log10 type-generic macro, 7.22
20737 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
20738 7.24.6.3.1 log1p type-generic macro, 7.22
20739 length modifier, 7.19.6.1, 7.19.6.2, 7.24.2.1, log2 functions, 7.12.6.10, F.9.3.10
20740 7.24.2.2 log2 type-generic macro, 7.22
20741 less-than operator (<), 6.5.8 logarithmic functions
20742 less-than-or-equal-to operator (<=), 6.5.8 complex, 7.3.7, G.6.3
20743 letter, 5.2.1, 7.4 real, 7.12.6, F.9.3
20744 lexical elements, 5.1.1.2, 6.4 logb functions, 7.12.6.11, F.3, F.9.3.11
20745 lgamma functions, 7.12.8.3, F.9.5.3 logb type-generic macro, 7.22
20746 lgamma type-generic macro, 7.22 logical operators
20747 library, 5.1.1.1, 7 AND (&&), 6.5.13
20748 future directions, 7.26 negation (!), 6.5.3.3
20749 summary, B OR (||), 6.5.14
20750 terms, 7.1.1 logical source lines, 5.1.1.2
20751 use of functions, 7.1.4 long double _Complex type, 6.2.5
20752 lifetime, 6.2.4 long double _Complex type conversion,
20753 limits 6.3.1.6, 6.3.1.7, 6.3.1.8
20754 environmental, see environmental limits long double _Imaginary type, G.2
20755 implementation, see implementation limits long double suffix, l or L, 6.4.4.2
20756 numerical, see numerical limits long double type, 6.2.5, 6.4.4.2, 6.7.2,
20757 translation, see translation limits 7.19.6.1, 7.19.6.2, 7.24.2.1, 7.24.2.2, F.2
20758 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,
20759 line buffered stream, 7.19.3 6.3.1.7, 6.3.1.8
20760 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,
20761 line preprocessing directive, 6.10.4 7.19.6.2, 7.24.2.1, 7.24.2.2
20762 lines, 5.1.1.2, 7.19.2 long int type conversion, 6.3.1.1, 6.3.1.3,
20763 preprocessing directive, 6.10 6.3.1.4, 6.3.1.8
20764 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
20765 6.11.2 long long int type, 6.2.5, 6.3.1.1, 6.7.2,
20769 7.19.6.1, 7.19.6.2, 7.24.2.1, 7.24.2.2 mbsinit function, 7.24.6.2.1
20770 long long int type conversion, 6.3.1.1, mbsrtowcs function, 7.24.6.4.1
20771 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,
20772 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,
20773 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
20774 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
20775 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,
20776 loop body, 6.8.5 7.24.6.3
20777 low-order bit, 3.6 member access operators (. and ->), 6.5.2.3
20778 lowercase letter, 5.2.1 member alignment, 6.7.2.1
20779 lrint functions, 7.12.9.5, F.3, F.9.6.5 memchr function, 7.21.5.1
20780 lrint type-generic macro, 7.22 memcmp function, 7.21.4, 7.21.4.1
20781 lround functions, 7.12.9.7, F.9.6.7 memcpy function, 7.21.2.1
20782 lround type-generic macro, 7.22 memmove function, 7.21.2.2
20783 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
20784 memset function, 7.21.6.1
20785 macro argument substitution, 6.10.3.1 minimum functions, 7.12.12, F.9.9
20786 macro definition minus operator, unary, 6.5.3.3
20787 library function, 7.1.4 miscellaneous functions
20788 macro invocation, 6.10.3 string, 7.21.6
20789 macro name, 6.10.3 wide string, 7.24.4.6
20790 length, 5.2.4.1 mktime function, 7.23.2.3
20791 predefined, 6.10.8, 6.11.9 modf functions, 7.12.6.12, F.9.3.12
20792 redefinition, 6.10.3 modifiable lvalue, 6.3.2.1
20793 scope, 6.10.3.5 modulus functions, 7.12.6.12
20794 macro parameter, 6.10.3 modulus, complex, 7.3.8.1
20795 macro preprocessor, 6.10 multibyte character, 3.7.2, 5.2.1.2, 6.4.4.4
20796 macro replacement, 6.10.3 multibyte conversion functions
20797 magnitude, complex, 7.3.8.1 wide character, 7.20.7
20798 main function, 5.1.2.2.1, 5.1.2.2.3, 6.7.3.1, 6.7.4, extended, 7.24.6
20799 7.19.3 restartable, 7.24.6.3
20800 malloc function, 7.20.3, 7.20.3.2, 7.20.3.3, wide string, 7.20.8
20801 7.20.3.4 restartable, 7.24.6.4
20802 manipulation functions multibyte string, 7.1.1
20803 complex, 7.3.9 multibyte/wide character conversion functions,
20804 real, 7.12.11, F.9.8 7.20.7
20805 matching failure, 7.24.2.6, 7.24.2.8, 7.24.2.10 extended, 7.24.6
20806 math.h header, 5.2.4.2.2, 6.5, 7.12, 7.22, F, F.9, restartable, 7.24.6.3
20807 J.5.17 multibyte/wide string conversion functions, 7.20.8
20808 MATH_ERREXCEPT macro, 7.12, F.9 restartable, 7.24.6.4
20809 math_errhandling macro, 7.1.3, 7.12, F.9 multidimensional array, 6.5.2.1
20810 MATH_ERRNO macro, 7.12 multiplication assignment operator (*=), 6.5.16.2
20811 maximum functions, 7.12.12, F.9.9 multiplication operator (*), 6.5.5, F.3, G.5.1
20812 MB_CUR_MAX macro, 7.1.1, 7.20, 7.20.7.2, multiplicative expressions, 6.5.5, G.5.1
20813 7.20.7.3, 7.24.6.3.3
20814 MB_LEN_MAX macro, 5.2.4.2.1, 7.1.1, 7.20 n-char sequence, 7.20.1.3
20815 mblen function, 7.20.7.1, 7.24.6.3 n-wchar sequence, 7.24.4.1.1
20816 mbrlen function, 7.24.6.3.1 name
20817 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
20818 7.24.2.1, 7.24.2.2, 7.24.6.3.1, 7.24.6.3.2, file, 7.19.3
20819 7.24.6.4.1 internal, 5.2.4.1, 6.4.2.1
20823 label, 6.2.3 octal-character escape sequence (\octal digits),
20824 structure/union member, 6.2.3 6.4.4.4
20825 name spaces, 6.2.3 offsetof macro, 7.17
20826 named label, 6.8.1 on-off switch, 6.10.6
20827 NaN, 5.2.4.2.2 ones' complement, 6.2.6.2
20828 nan functions, 7.12.11.2, F.2.1, F.9.8.2 operand, 6.4.6, 6.5
20829 NAN macro, 7.12, F.2.1 operating system, 5.1.2.1, 7.20.4.6
20830 NDEBUG macro, 7.2 operations on files, 7.19.4
20831 nearbyint functions, 7.12.9.3, 7.12.9.4, F.3, operator, 6.4.6
20832 F.9.6.3 operators, 6.5
20833 nearbyint type-generic macro, 7.22 assignment, 6.5.16
20834 nearest integer functions, 7.12.9, F.9.6 associativity, 6.5
20835 negation operator (!), 6.5.3.3 equality, 6.5.9
20836 negative zero, 6.2.6.2, 7.12.11.1 multiplicative, 6.5.5, G.5.1
20837 new-line character, 5.1.1.2, 5.2.1, 6.4, 6.10, 6.10.4 postfix, 6.5.2
20838 new-line escape sequence (\n), 5.2.2, 6.4.4.4, precedence, 6.5
20839 7.4.1.10 preprocessing, 6.10.1, 6.10.3.2, 6.10.3.3, 6.10.9
20840 nextafter functions, 7.12.11.3, 7.12.11.4, F.3, relational, 6.5.8
20841 F.9.8.3 shift, 6.5.7
20842 nextafter type-generic macro, 7.22 unary, 6.5.3
20843 nexttoward functions, 7.12.11.4, F.3, F.9.8.4 unary arithmetic, 6.5.3.3
20844 nexttoward type-generic macro, 7.22 or macro, 7.9
20845 no linkage, 6.2.2 OR operators
20846 non-stop floating-point control mode, 7.6.4.2 bitwise exclusive (^), 6.5.11
20847 nongraphic characters, 5.2.2, 6.4.4.4 bitwise exclusive assignment (^=), 6.5.16.2
20848 nonlocal jumps header, 7.13 bitwise inclusive (|), 6.5.12
20849 norm, complex, 7.3.8.1 bitwise inclusive assignment (|=), 6.5.16.2
20850 not macro, 7.9 logical (||), 6.5.14
20851 not-equal-to operator, see inequality operator or_eq macro, 7.9
20852 not_eq macro, 7.9 order of allocated storage, 7.20.3
20853 null character (\0), 5.2.1, 6.4.4.4, 6.4.5 order of evaluation, 6.5
20854 padding of binary stream, 7.19.2 ordinary identifier name space, 6.2.3
20855 NULL macro, 7.11, 7.17, 7.19.1, 7.20, 7.21.1, orientation of stream, 7.19.2, 7.24.3.5
20856 7.23.1, 7.24.1 outer scope, 6.2.1
20857 null pointer, 6.3.2.3
20858 null pointer constant, 6.3.2.3 padding
20859 null preprocessing directive, 6.10.7 binary stream, 7.19.2
20860 null statement, 6.8.3 bits, 6.2.6.2, 7.18.1.1
20861 null wide character, 7.1.1 structure/union, 6.2.6.1, 6.7.2.1
20862 number classification macros, 7.12, 7.12.3.1 parameter, 3.15
20863 numeric conversion functions, 7.8.2.3, 7.20.1 array, 6.9.1
20864 wide string, 7.8.2.4, 7.24.4.1 ellipsis, 6.7.5.3, 6.10.3
20865 numerical limits, 5.2.4.2 function, 6.5.2.2, 6.7, 6.9.1
20867 object, 3.14 main function, 5.1.2.2.1
20868 object representation, 6.2.6.1 program, 5.1.2.2.1
20869 object type, 6.2.5 parameter type list, 6.7.5.3
20870 object-like macro, 6.10.3 parentheses punctuator (( )), 6.7.5.3, 6.8.4, 6.8.5
20871 obsolescence, 6.11, 7.26 parenthesized expression, 6.5.1
20872 octal constant, 6.4.4.1 parse state, 7.19.2
20873 octal digit, 6.4.4.1, 6.4.4.4 permitted form of initializer, 6.6
20877 perror function, 7.19.10.4 PRIcPTR macros, 7.8.1
20878 phase angle, complex, 7.3.9.1 primary expression, 6.5.1
20879 physical source lines, 5.1.1.2 printf function, 7.19.1, 7.19.6.3, 7.19.6.10
20880 placemarker, 6.10.3.3 printing character, 5.2.2, 7.4, 7.4.1.8
20881 plus operator, unary, 6.5.3.3 printing wide character, 7.25.2
20882 pointer arithmetic, 6.5.6 program diagnostics, 7.2.1
20883 pointer comparison, 6.5.8 program execution, 5.1.2.2.2, 5.1.2.3
20884 pointer declarator, 6.7.5.1 program file, 5.1.1.1
20885 pointer operator (->), 6.5.2.3 program image, 5.1.1.2
20886 pointer to function, 6.5.2.2 program name (argv[0]), 5.1.2.2.1
20887 pointer type, 6.2.5 program parameters, 5.1.2.2.1
20888 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
20889 pointer, null, 6.3.2.3 program structure, 5.1.1.1
20890 portability, 4, J program termination, 5.1.2, 5.1.2.1, 5.1.2.2.3,
20891 position indicator, file, see file position indicator 5.1.2.3
20892 positive difference, 7.12.12.1 program, conforming, 4
20893 positive difference functions, 7.12.12, F.9.9 program, strictly conforming, 4
20894 postfix decrement operator (--), 6.3.2.1, 6.5.2.4 promotions
20895 postfix expressions, 6.5.2 default argument, 6.5.2.2
20896 postfix increment operator (++), 6.3.2.1, 6.5.2.4 integer, 5.1.2.3, 6.3.1.1
20897 pow functions, 7.12.7.4, F.9.4.4 prototype, see function prototype
20898 pow type-generic macro, 7.22 pseudo-random sequence functions, 7.20.2
20899 power functions PTRDIFF_MAX macro, 7.18.3
20900 complex, 7.3.8, G.6.4 PTRDIFF_MIN macro, 7.18.3
20901 real, 7.12.7, F.9.4 ptrdiff_t type, 7.17, 7.18.3, 7.19.6.1,
20902 pp-number, 6.4.8 7.19.6.2, 7.24.2.1, 7.24.2.2
20903 pragma operator, 6.10.9 punctuators, 6.4.6
20904 pragma preprocessing directive, 6.10.6, 6.11.8 putc function, 7.19.1, 7.19.7.8, 7.19.7.9
20905 precedence of operators, 6.5 putchar function, 7.19.1, 7.19.7.9
20906 precedence of syntax rules, 5.1.1.2 puts function, 7.19.1, 7.19.7.10
20907 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
20908 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
20909 predefined macro names, 6.10.8, 6.11.9
20910 prefix decrement operator (--), 6.3.2.1, 6.5.3.1 qsort function, 7.20.5, 7.20.5.2
20911 prefix increment operator (++), 6.3.2.1, 6.5.3.1 qualified types, 6.2.5
20912 preprocessing concatenation, 6.10.3.3 qualified version of type, 6.2.5
20913 preprocessing directives, 5.1.1.2, 6.10 question-mark escape sequence (\?), 6.4.4.4
20914 preprocessing file, 5.1.1.1, 6.10 quiet NaN, 5.2.4.2.2
20915 preprocessing numbers, 6.4, 6.4.8
20916 preprocessing operators raise function, 7.14, 7.14.1.1, 7.14.2.1, 7.20.4.1
20917 #, 6.10.3.2 rand function, 7.20, 7.20.2.1, 7.20.2.2
20918 ##, 6.10.3.3 RAND_MAX macro, 7.20, 7.20.2.1
20919 _Pragma, 5.1.1.2, 6.10.9 range
20920 defined, 6.10.1 excess, 5.2.4.2.2, 6.3.1.5, 6.3.1.8, 6.8.6.4
20921 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,
20922 preprocessing translation unit, 5.1.1.1 7.12.6.1, 7.12.6.2, 7.12.6.3, 7.12.6.5,
20923 preprocessor, 6.10 7.12.6.6, 7.12.6.7, 7.12.6.8, 7.12.6.9,
20924 PRIcFASTN macros, 7.8.1 7.12.6.10, 7.12.6.11, 7.12.6.13, 7.12.7.3,
20925 PRIcLEASTN macros, 7.8.1 7.12.7.4, 7.12.8.2, 7.12.8.3, 7.12.8.4,
20926 PRIcMAX macros, 7.8.1 7.12.9.5, 7.12.9.7, 7.12.11.3, 7.12.12.1,
20927 PRIcN macros, 7.8.1 7.12.13.1
20931 rank, see integer conversion rank same scope, 6.2.1
20932 real floating type conversion, 6.3.1.4, 6.3.1.5, save calling environment function, 7.13.1
20933 6.3.1.7, F.3, F.4 scalar types, 6.2.5
20934 real floating types, 6.2.5 scalbln function, 7.12.6.13, F.3, F.9.3.13
20935 real type domain, 6.2.5 scalbln type-generic macro, 7.22
20936 real types, 6.2.5 scalbn function, 7.12.6.13, F.3, F.9.3.13
20937 real-floating, 7.12.3 scalbn type-generic macro, 7.22
20938 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
20939 recommended practice, 3.16 scanlist, 7.19.6.2, 7.24.2.2
20940 recursion, 6.5.2.2 scanset, 7.19.6.2, 7.24.2.2
20941 recursive function call, 6.5.2.2 SCHAR_MAX macro, 5.2.4.2.1
20942 redefinition of macro, 6.10.3 SCHAR_MIN macro, 5.2.4.2.1
20943 reentrancy, 5.1.2.3, 5.2.3 SCNcFASTN macros, 7.8.1
20944 library functions, 7.1.4 SCNcLEASTN macros, 7.8.1
20945 referenced type, 6.2.5 SCNcMAX macros, 7.8.1
20946 register storage-class specifier, 6.7.1, 6.9 SCNcN macros, 7.8.1
20947 relational expressions, 6.5.8 SCNcPTR macros, 7.8.1
20948 reliability of data, interrupted, 5.1.2.3 scope of identifier, 6.2.1, 6.9.2
20949 remainder assignment operator (%=), 6.5.16.2 search functions
20950 remainder functions, 7.12.10, F.9.7 string, 7.21.5
20951 remainder functions, 7.12.10.2, 7.12.10.3, F.3, utility, 7.20.5
20952 F.9.7.2 wide string, 7.24.4.5
20953 remainder operator (%), 6.5.5 SEEK_CUR macro, 7.19.1, 7.19.9.2
20954 remainder type-generic macro, 7.22 SEEK_END macro, 7.19.1, 7.19.9.2
20955 remove function, 7.19.4.1, 7.19.4.4 SEEK_SET macro, 7.19.1, 7.19.9.2
20956 remquo functions, 7.12.10.3, F.3, F.9.7.3 selection statements, 6.8.4
20957 remquo type-generic macro, 7.22 self-referential structure, 6.7.2.3
20958 rename function, 7.19.4.2 semicolon punctuator (;), 6.7, 6.7.2.1, 6.8.3,
20959 representations of types, 6.2.6 6.8.5, 6.8.6
20960 pointer, 6.2.5 separate compilation, 5.1.1.1
20961 rescanning and replacement, 6.10.3.4 separate translation, 5.1.1.1
20962 reserved identifiers, 6.4.1, 7.1.3 sequence points, 5.1.2.3, 6.5, 6.8, 7.1.4, 7.19.6,
20963 restartable multibyte/wide character conversion 7.20.5, 7.24.2, C
20964 functions, 7.24.6.3 sequencing of statements, 6.8
20965 restartable multibyte/wide string conversion setbuf function, 7.19.3, 7.19.5.1, 7.19.5.5
20966 functions, 7.24.6.4 setjmp macro, 7.1.3, 7.13.1.1, 7.13.2.1
20967 restore calling environment function, 7.13.2 setjmp.h header, 7.13
20968 restrict type qualifier, 6.7.3, 6.7.3.1 setlocale function, 7.11.1.1, 7.11.2.1
20969 restrict-qualified type, 6.2.5, 6.7.3 setvbuf function, 7.19.1, 7.19.3, 7.19.5.1,
20970 return statement, 6.8.6.4 7.19.5.5, 7.19.5.6
20971 rewind function, 7.19.5.3, 7.19.7.11, 7.19.9.5, shall, 4
20972 7.24.3.10 shift expressions, 6.5.7
20973 right-shift assignment operator (>>=), 6.5.16.2 shift sequence, 7.1.1
20974 right-shift operator (>>), 6.5.7 shift states, 5.2.1.2
20975 rint functions, 7.12.9.4, F.3, F.9.6.4 short identifier, character, 5.2.4.1, 6.4.3
20976 rint type-generic macro, 7.22 short int type, 6.2.5, 6.3.1.1, 6.7.2, 7.19.6.1,
20977 round functions, 7.12.9.6, F.9.6.6 7.19.6.2, 7.24.2.1, 7.24.2.2
20978 round type-generic macro, 7.22 short int type conversion, 6.3.1.1, 6.3.1.3,
20979 rounding mode, floating point, 5.2.4.2.2 6.3.1.4, 6.3.1.8
20980 rvalue, 6.3.2.1 SHRT_MAX macro, 5.2.4.2.1
20981 SHRT_MIN macro, 5.2.4.2.1
20985 side effects, 5.1.2.3, 6.5 source lines, 5.1.1.2
20986 SIG_ATOMIC_MAX macro, 7.18.3 source text, 5.1.1.2
20987 SIG_ATOMIC_MIN macro, 7.18.3 space character (' '), 5.1.1.2, 5.2.1, 6.4, 7.4.1.3,
20988 sig_atomic_t type, 7.14, 7.14.1.1, 7.18.3 7.4.1.10, 7.25.2.1.3
20989 SIG_DFL macro, 7.14, 7.14.1.1 sprintf function, 7.19.6.6, 7.19.6.13
20990 SIG_ERR macro, 7.14, 7.14.1.1 sqrt functions, 7.12.7.5, F.3, F.9.4.5
20991 SIG_IGN macro, 7.14, 7.14.1.1 sqrt type-generic macro, 7.22
20992 SIGABRT macro, 7.14, 7.20.4.1 srand function, 7.20.2.2
20993 SIGFPE macro, 7.14, 7.14.1.1, J.5.17 sscanf function, 7.19.6.7, 7.19.6.14
20994 SIGILL macro, 7.14, 7.14.1.1 standard error stream, 7.19.1, 7.19.3, 7.19.10.4
20995 SIGINT macro, 7.14 standard headers, 4, 7.1.2
20996 sign and magnitude, 6.2.6.2 <assert.h>, 7.2, B.1
20997 sign bit, 6.2.6.2 <complex.h>, 5.2.4.2.2, 7.3, 7.22, 7.26.1,
20998 signal function, 7.14.1.1, 7.20.4.4 G.6, J.5.17
20999 signal handler, 5.1.2.3, 5.2.3, 7.14.1.1, 7.14.2.1 <ctype.h>, 7.4, 7.26.2
21000 signal handling functions, 7.14.1 <errno.h>, 7.5, 7.26.3
21001 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
21002 signaling NaN, 5.2.4.2.2, F.2.1 <float.h>, 4, 5.2.4.2.2, 7.7, 7.20.1.3,
21003 signals, 5.1.2.3, 5.2.3, 7.14.1 7.24.4.1.1
21004 signbit macro, 7.12.3.6, F.3 <inttypes.h>, 7.8, 7.26.4
21005 signed char type, 6.2.5, 7.19.6.1, 7.19.6.2, <iso646.h>, 4, 7.9
21006 7.24.2.1, 7.24.2.2 <limits.h>, 4, 5.2.4.2.1, 6.2.5, 7.10
21007 signed character, 6.3.1.1 <locale.h>, 7.11, 7.26.5
21008 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,
21009 signed type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4, J.5.17
21010 6.3.1.8 <setjmp.h>, 7.13
21011 signed types, 6.2.5, 6.7.2 <signal.h>, 7.14, 7.26.6
21012 significand part, 6.4.4.2 <stdarg.h>, 4, 6.7.5.3, 7.15
21013 SIGSEGV macro, 7.14, 7.14.1.1 <stdbool.h>, 4, 7.16, 7.26.7, H
21014 SIGTERM macro, 7.14 <stddef.h>, 4, 6.3.2.1, 6.3.2.3, 6.4.4.4,
21015 simple assignment operator (=), 6.5.16.1 6.4.5, 6.5.3.4, 6.5.6, 7.17
21016 sin functions, 7.12.4.6, F.9.1.6 <stdint.h>, 4, 5.2.4.2, 6.10.1, 7.8, 7.18,
21017 sin type-generic macro, 7.22, G.7 7.26.8
21018 single-byte character, 3.7.1, 5.2.1.2 <stdio.h>, 5.2.4.2.2, 7.19, 7.26.9, F
21019 single-byte/wide character conversion functions, <stdlib.h>, 5.2.4.2.2, 7.20, 7.26.10, F
21020 7.24.6.1 <string.h>, 7.21, 7.26.11
21021 single-precision arithmetic, 5.1.2.3 <tgmath.h>, 7.22, G.7
21022 single-quote escape sequence (\'), 6.4.4.4, 6.4.5 <time.h>, 7.23
21023 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,
21024 sinh type-generic macro, 7.22, G.7 F
21025 SIZE_MAX macro, 7.18.3 <wctype.h>, 7.25, 7.26.13
21026 size_t type, 6.5.3.4, 7.17, 7.18.3, 7.19.1, standard input stream, 7.19.1, 7.19.3
21027 7.19.6.1, 7.19.6.2, 7.20, 7.21.1, 7.23.1, standard integer types, 6.2.5
21028 7.24.1, 7.24.2.1, 7.24.2.2 standard output stream, 7.19.1, 7.19.3
21029 sizeof operator, 6.3.2.1, 6.5.3, 6.5.3.4 standard signed integer types, 6.2.5
21030 snprintf function, 7.19.6.5, 7.19.6.12 state-dependent encoding, 5.2.1.2, 7.20.7
21031 sorting utility functions, 7.20.5 statements, 6.8
21032 source character set, 5.1.1.2, 5.2.1 break, 6.8.6.3
21033 source file, 5.1.1.1 compound, 6.8.2
21034 name, 6.10.4, 6.10.8 continue, 6.8.6.2
21035 source file inclusion, 6.10.2 do, 6.8.5.2
21039 else, 6.8.4.1 strictly conforming program, 4
21040 expression, 6.8.3 string, 7.1.1
21041 for, 6.8.5.3 comparison functions, 7.21.4
21042 goto, 6.8.6.1 concatenation functions, 7.21.3
21043 if, 6.8.4.1 conversion functions, 7.11.1.1
21044 iteration, 6.8.5 copying functions, 7.21.2
21045 jump, 6.8.6 library function conventions, 7.21.1
21046 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
21047 null, 6.8.3 miscellaneous functions, 7.21.6
21048 return, 6.8.6.4 numeric conversion functions, 7.8.2.3, 7.20.1
21049 selection, 6.8.4 search functions, 7.21.5
21050 sequencing, 6.8 string handling header, 7.21
21051 switch, 6.8.4.2 string.h header, 7.21, 7.26.11
21052 while, 6.8.5.1 stringizing, 6.10.3.2, 6.10.9
21053 static storage duration, 6.2.4 strlen function, 7.21.6.3
21054 static storage-class specifier, 6.2.2, 6.2.4, 6.7.1 strncat function, 7.21.3.2
21055 static, in array declarators, 6.7.5.2, 6.7.5.3 strncmp function, 7.21.4, 7.21.4.4
21056 stdarg.h header, 4, 6.7.5.3, 7.15 strncpy function, 7.21.2.4
21057 stdbool.h header, 4, 7.16, 7.26.7, H strpbrk function, 7.21.5.4
21058 STDC, 6.10.6, 6.11.8 strrchr function, 7.21.5.5
21059 stddef.h header, 4, 6.3.2.1, 6.3.2.3, 6.4.4.4, strspn function, 7.21.5.6
21060 6.4.5, 6.5.3.4, 6.5.6, 7.17 strstr function, 7.21.5.7
21061 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,
21062 stdin macro, 7.19.1, 7.19.2, 7.19.3, 7.19.6.4, 7.24.2.2, F.3
21063 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
21064 stdint.h header, 4, 5.2.4.2, 6.10.1, 7.8, 7.18, strtoimax function, 7.8.2.3
21065 7.26.8 strtok function, 7.21.5.8
21066 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,
21067 stdlib.h header, 5.2.4.2.2, 7.20, 7.26.10, F 7.20.1.4, 7.24.2.2
21068 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
21069 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
21070 storage duration, 6.2.4 strtoul function, 7.8.2.3, 7.19.6.2, 7.20.1.2,
21071 storage order of array, 6.5.2.1 7.20.1.4, 7.24.2.2
21072 storage-class specifiers, 6.7.1, 6.11.5 strtoull function, 7.8.2.3, 7.20.1.2, 7.20.1.4
21073 strcat function, 7.21.3.1 strtoumax function, 7.8.2.3
21074 strchr function, 7.21.5.2 struct hack, see flexible array member
21075 strcmp function, 7.21.4, 7.21.4.2 structure
21076 strcoll function, 7.11.1.1, 7.21.4.3, 7.21.4.5 arrow operator (->), 6.5.2.3
21077 strcpy function, 7.21.2.3 content, 6.7.2.3
21078 strcspn function, 7.21.5.3 dot operator (.), 6.5.2.3
21079 streams, 7.19.2, 7.20.4.3 initialization, 6.7.8
21080 fully buffered, 7.19.3 member alignment, 6.7.2.1
21081 line buffered, 7.19.3 member name space, 6.2.3
21082 orientation, 7.19.2 member operator (.), 6.3.2.1, 6.5.2.3
21083 standard error, 7.19.1, 7.19.3 pointer operator (->), 6.5.2.3
21084 standard input, 7.19.1, 7.19.3 specifier, 6.7.2.1
21085 standard output, 7.19.1, 7.19.3 tag, 6.2.3, 6.7.2.3
21086 unbuffered, 7.19.3 type, 6.2.5, 6.7.2.1
21087 strerror function, 7.19.10.4, 7.21.6.2 strxfrm function, 7.11.1.1, 7.21.4.5
21088 strftime function, 7.11.1.1, 7.23.3, 7.23.3.5, subscripting, 6.5.2.1
21089 7.24.5.1 subtraction assignment operator (-=), 6.5.16.2
21093 subtraction operator (-), 6.5.6, F.3, G.5.2 tolower function, 7.4.2.1
21094 suffix toupper function, 7.4.2.2
21095 floating constant, 6.4.4.2 towctrans function, 7.25.3.2.1, 7.25.3.2.2
21096 integer constant, 6.4.4.1 towlower function, 7.25.3.1.1, 7.25.3.2.1
21097 switch body, 6.8.4.2 towupper function, 7.25.3.1.2, 7.25.3.2.1
21098 switch case label, 6.8.1, 6.8.4.2 translation environment, 5, 5.1.1
21099 switch default label, 6.8.1, 6.8.4.2 translation limits, 5.2.4.1
21100 switch statement, 6.8.1, 6.8.4.2 translation phases, 5.1.1.2
21101 swprintf function, 7.24.2.3, 7.24.2.7 translation unit, 5.1.1.1, 6.9
21102 swscanf function, 7.24.2.4, 7.24.2.8 trap representation, 6.2.6.1, 6.2.6.2, 6.3.2.3,
21104 syntactic categories, 6.1 trigonometric functions
21105 syntax notation, 6.1 complex, 7.3.5, G.6.1
21106 syntax rule precedence, 5.1.1.2 real, 7.12.4, F.9.1
21107 syntax summary, language, A trigraph sequences, 5.1.1.2, 5.2.1.1
21108 system function, 7.20.4.6 true macro, 7.16
21109 trunc functions, 7.12.9.8, F.9.6.8
21110 tab characters, 5.2.1, 6.4 trunc type-generic macro, 7.22
21111 tag compatibility, 6.2.7 truncation, 6.3.1.4, 7.12.9.8, 7.19.3, 7.19.5.3
21112 tag name space, 6.2.3 truncation toward zero, 6.5.5
21113 tags, 6.7.2.3 two's complement, 6.2.6.2, 7.18.1.1
21114 tan functions, 7.12.4.7, F.9.1.7 type category, 6.2.5
21115 tan type-generic macro, 7.22, G.7 type conversion, 6.3
21116 tanh functions, 7.12.5.6, F.9.2.6 type definitions, 6.7.7
21117 tanh type-generic macro, 7.22, G.7 type domain, 6.2.5, G.2
21118 tentative definition, 6.9.2 type names, 6.7.6
21119 terms, 3 type punning, 6.5.2.3
21120 text streams, 7.19.2, 7.19.7.11, 7.19.9.2, 7.19.9.4 type qualifiers, 6.7.3
21121 tgamma functions, 7.12.8.4, F.9.5.4 type specifiers, 6.7.2
21122 tgamma type-generic macro, 7.22 type-generic macro, 7.22, G.7
21123 tgmath.h header, 7.22, G.7 typedef declaration, 6.7.7
21124 time typedef storage-class specifier, 6.7.1, 6.7.7
21125 broken down, 7.23.1, 7.23.2.3, 7.23.3, 7.23.3.1, types, 6.2.5
21126 7.23.3.3, 7.23.3.4, 7.23.3.5 character, 6.7.8
21127 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
21128 7.23.3.2, 7.23.3.3, 7.23.3.4 complex, 6.2.5, G
21129 components, 7.23.1 composite, 6.2.7
21130 conversion functions, 7.23.3 const qualified, 6.7.3
21131 wide character, 7.24.5 conversions, 6.3
21132 local, 7.23.1 imaginary, G
21133 manipulation functions, 7.23.2 restrict qualified, 6.7.3
21134 time function, 7.23.2.4 volatile qualified, 6.7.3
21135 time.h header, 7.23
21136 time_t type, 7.23.1 UCHAR_MAX macro, 5.2.4.2.1
21137 tm structure type, 7.23.1, 7.24.1 UINT_FASTN_MAX macros, 7.18.2.3
21138 TMP_MAX macro, 7.19.1, 7.19.4.3, 7.19.4.4 uint_fastN_t types, 7.18.1.3
21139 tmpfile function, 7.19.4.3, 7.20.4.3 UINT_LEASTN_MAX macros, 7.18.2.2
21140 tmpnam function, 7.19.1, 7.19.4.3, 7.19.4.4 uint_leastN_t types, 7.18.1.2
21141 token, 5.1.1.2, 6.4, see also preprocessing tokens UINT_MAX macro, 5.2.4.2.1
21142 token concatenation, 6.10.3.3 UINTMAX_C macro, 7.18.4.2
21143 token pasting, 6.10.3.3 UINTMAX_MAX macro, 7.8.2.3, 7.8.2.4, 7.18.2.5
21147 uintmax_t type, 7.18.1.5, 7.19.6.1, 7.19.6.2, USHRT_MAX macro, 5.2.4.2.1
21148 7.24.2.1, 7.24.2.2 usual arithmetic conversions, 6.3.1.8, 6.5.5, 6.5.6,
21149 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
21150 UINTN_MAX macros, 7.18.2.1 utilities, general, 7.20
21151 uintN_t types, 7.18.1.1 wide string, 7.24.4
21152 UINTPTR_MAX macro, 7.18.2.4
21153 uintptr_t type, 7.18.1.4 va_arg macro, 7.15, 7.15.1, 7.15.1.1, 7.15.1.2,
21154 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,
21155 7.24.4.1.2 7.19.6.11, 7.19.6.12, 7.19.6.13, 7.19.6.14,
21156 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,
21157 7.24.4.1.2 7.24.2.9, 7.24.2.10
21158 unary arithmetic operators, 6.5.3.3 va_copy macro, 7.15, 7.15.1, 7.15.1.1, 7.15.1.2,
21159 unary expression, 6.5.3 7.15.1.3
21160 unary minus operator (-), 6.5.3.3, F.3 va_end macro, 7.1.3, 7.15, 7.15.1, 7.15.1.3,
21161 unary operators, 6.5.3 7.15.1.4, 7.19.6.8, 7.19.6.9, 7.19.6.10,
21162 unary plus operator (+), 6.5.3.3 7.19.6.11, 7.19.6.12, 7.19.6.13, 7.19.6.14,
21163 unbuffered stream, 7.19.3 7.24.2.5, 7.24.2.6, 7.24.2.7, 7.24.2.8,
21164 undef preprocessing directive, 6.10.3.5, 7.1.3, 7.24.2.9, 7.24.2.10
21165 7.1.4 va_list type, 7.15, 7.15.1.3
21166 undefined behavior, 3.4.3, 4, J.2 va_start macro, 7.15, 7.15.1, 7.15.1.1,
21167 underscore character, 6.4.2.1 7.15.1.2, 7.15.1.3, 7.15.1.4, 7.19.6.8,
21168 underscore, leading, in identifier, 7.1.3 7.19.6.9, 7.19.6.10, 7.19.6.11, 7.19.6.12,
21169 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,
21170 7.19.9.3 7.24.2.7, 7.24.2.8, 7.24.2.9, 7.24.2.10
21171 ungetwc function, 7.19.1, 7.24.3.10 value, 3.17
21172 Unicode required set, 6.10.8 value bits, 6.2.6.2
21173 union variable arguments, 6.10.3, 7.15
21174 arrow operator (->), 6.5.2.3 variable arguments header, 7.15
21175 content, 6.7.2.3 variable length array, 6.7.5, 6.7.5.2
21176 dot operator (.), 6.5.2.3 variably modified type, 6.7.5, 6.7.5.2
21177 initialization, 6.7.8 vertical-tab character, 5.2.1, 6.4
21178 member alignment, 6.7.2.1 vertical-tab escape sequence (\v), 5.2.2, 6.4.4.4,
21179 member name space, 6.2.3 7.4.1.10
21180 member operator (.), 6.3.2.1, 6.5.2.3 vfprintf function, 7.19.1, 7.19.6.8
21181 pointer operator (->), 6.5.2.3 vfscanf function, 7.19.1, 7.19.6.8, 7.19.6.9
21182 specifier, 6.7.2.1 vfwprintf function, 7.19.1, 7.24.2.5
21183 tag, 6.2.3, 6.7.2.3 vfwscanf function, 7.19.1, 7.24.2.6, 7.24.3.10
21184 type, 6.2.5, 6.7.2.1 visibility of identifier, 6.2.1
21185 universal character name, 6.4.3 VLA, see variable length array
21186 unqualified type, 6.2.5 void expression, 6.3.2.2
21187 unqualified version of type, 6.2.5 void function parameter, 6.7.5.3
21188 unsigned integer suffix, u or U, 6.4.4.1 void type, 6.2.5, 6.3.2.2, 6.7.2
21189 unsigned integer types, 6.2.5, 6.3.1.3, 6.4.4.1 void type conversion, 6.3.2.2
21190 unsigned type conversion, 6.3.1.1, 6.3.1.3, volatile storage, 5.1.2.3
21191 6.3.1.4, 6.3.1.8 volatile type qualifier, 6.7.3
21192 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
21193 7.24.2.1, 7.24.2.2 vprintf function, 7.19.1, 7.19.6.8, 7.19.6.10
21194 unspecified behavior, 3.4.4, 4, J.1 vscanf function, 7.19.1, 7.19.6.8, 7.19.6.11
21195 unspecified value, 3.17.3 vsnprintf function, 7.19.6.8, 7.19.6.12
21196 uppercase letter, 5.2.1 vsprintf function, 7.19.6.8, 7.19.6.13
21197 use of library functions, 7.1.4 vsscanf function, 7.19.6.8, 7.19.6.14
21201 vswprintf function, 7.24.2.7 wctype.h header, 7.25, 7.26.13
21202 vswscanf function, 7.24.2.8 wctype_t type, 7.25.1, 7.25.2.2.2
21203 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,
21204 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,
21206 warnings, I while statement, 6.8.5.1
21207 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,
21209 WCHAR_MAX macro, 7.18.3, 7.24.1 white-space characters, 6.4
21210 WCHAR_MIN macro, 7.18.3, 7.24.1 wide character, 3.7.3
21211 wchar_t type, 3.7.3, 6.4.4.4, 6.4.5, 6.7.8, case mapping functions, 7.25.3.1
21212 6.10.8, 7.17, 7.18.3, 7.19.6.1, 7.19.6.2, 7.20, extensible, 7.25.3.2
21213 7.24.1, 7.24.2.1, 7.24.2.2 classification functions, 7.25.2.1
21214 wcrtomb function, 7.19.3, 7.19.6.2, 7.24.2.2, extensible, 7.25.2.2
21215 7.24.6.3.3, 7.24.6.4.2 constant, 6.4.4.4
21216 wcscat function, 7.24.4.3.1 formatted input/output functions, 7.24.2
21217 wcschr function, 7.24.4.5.1 input functions, 7.19.1
21218 wcscmp function, 7.24.4.4.1, 7.24.4.4.4 input/output functions, 7.19.1, 7.24.3
21219 wcscoll function, 7.24.4.4.2, 7.24.4.4.4 output functions, 7.19.1
21220 wcscpy function, 7.24.4.2.1 single-byte conversion functions, 7.24.6.1
21221 wcscspn function, 7.24.4.5.2 wide string, 7.1.1
21222 wcsftime function, 7.11.1.1, 7.24.5.1 wide string comparison functions, 7.24.4.4
21223 wcslen function, 7.24.4.6.1 wide string concatenation functions, 7.24.4.3
21224 wcsncat function, 7.24.4.3.2 wide string copying functions, 7.24.4.2
21225 wcsncmp function, 7.24.4.4.3 wide string literal, see string literal
21226 wcsncpy function, 7.24.4.2.2 wide string miscellaneous functions, 7.24.4.6
21227 wcspbrk function, 7.24.4.5.3 wide string numeric conversion functions, 7.8.2.4,
21228 wcsrchr function, 7.24.4.5.4 7.24.4.1
21229 wcsrtombs function, 7.24.6.4.2 wide string search functions, 7.24.4.5
21230 wcsspn function, 7.24.4.5.5 wide-oriented stream, 7.19.2
21231 wcsstr function, 7.24.4.5.6 width, 6.2.6.2
21232 wcstod function, 7.19.6.2, 7.24.2.2 WINT_MAX macro, 7.18.3
21233 wcstod function, 7.24.4.1.1 WINT_MIN macro, 7.18.3
21234 wcstof function, 7.24.4.1.1 wint_t type, 7.18.3, 7.19.6.1, 7.24.1, 7.24.2.1,
21235 wcstoimax function, 7.8.2.4 7.25.1
21236 wcstok function, 7.24.4.5.7 wmemchr function, 7.24.4.5.8
21237 wcstol function, 7.8.2.4, 7.19.6.2, 7.24.2.2, wmemcmp function, 7.24.4.4.5
21238 7.24.4.1.2 wmemcpy function, 7.24.4.2.3
21239 wcstold function, 7.24.4.1.1 wmemmove function, 7.24.4.2.4
21240 wcstoll function, 7.8.2.4, 7.24.4.1.2 wmemset function, 7.24.4.6.2
21241 wcstombs function, 7.20.8.2, 7.24.6.4 wprintf function, 7.19.1, 7.24.2.9, 7.24.2.11
21242 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,
21243 7.24.4.1.2 7.24.3.10
21244 wcstoull function, 7.8.2.4, 7.24.4.1.2
21245 wcstoumax function, 7.8.2.4 xor macro, 7.9
21246 wcsxfrm function, 7.24.4.4.4 xor_eq macro, 7.9
21247 wctob function, 7.24.6.1.2, 7.25.2.1
21248 wctomb function, 7.20.7.3, 7.20.8.2, 7.24.6.3
21249 wctrans function, 7.25.3.2.1, 7.25.3.2.2
21250 wctrans_t type, 7.25.1, 7.25.3.2.2
21251 wctype function, 7.25.2.2.1, 7.25.2.2.2