newer c1x draft
[c-standard] / n1548.txt
1 N1548                    Committee Draft -- December 2, 2010          ISO/IEC 9899:201x
2
3
4
5
6 INTERNATIONAL STANDARD                         (C)ISO/IEC              ISO/IEC 9899:201x
7
8
9
10
11 Programming languages -- C
12
13
14                                        ABSTRACT
15
16
17
18                      (Cover sheet to be provided by ISO Secretariat.)
19
20 This International Standard specifies the form and establishes the interpretation of
21 programs expressed in the programming language C. Its purpose is to promote
22 portability, reliability, maintainability, and efficient execution of C language programs on
23 a variety of computing systems.
24
25 Clauses are included that detail the C language itself and the contents of the C language
26 execution library. Annexes summarize aspects of both of them, and enumerate factors
27 that influence the portability of C programs.
28
29 Although this International Standard is intended to guide knowledgeable C language
30 programmers as well as implementors of C language translation systems, the document
31 itself is not designed to serve as a tutorial.
32
33 Recipients of this draft are invited to submit, with their comments, notification of any
34 relevant patent rights of which they are aware and to provide supporting documentation.
35
36 Changes from the previous draft (N1256) are indicated by ''diff marks'' in the right
37 margin: deleted text is marked with ''*'', new or changed text with '' ''.
38
39
40
41
42 [page i]
43
44
45
46 [page ii]
47
48 Contents
49 Foreword       . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                 xiii
50 Introduction    . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
51 1. Scope       . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                   1
52 2. Normative references     . . . . . . . . . . . . . . . . . . . . . . .                                  2
53 3. Terms, definitions, and symbols    . . . . . . . . . . . . . . . . . . .                                 3
54 4. Conformance       . . . . . . . . . . . . . . . . . . . . . . . . . .                                   8
55 5. Environment    . . . . . . . . . . .       . .   .   .   .   .   .   .   .    .   .   .   .   .   .    10
56    5.1 Conceptual models       . . . . . .    . .   .   .   .   .   .   .   .    .   .   .   .   .   .    10
57         5.1.1  Translation environment .      . .   .   .   .   .   .   .   .    .   .   .   .   .   .    10
58         5.1.2  Execution environments     .   . .   .   .   .   .   .   .   .    .   .   .   .   .   .    12
59    5.2 Environmental considerations    . .    . .   .   .   .   .   .   .   .    .   .   .   .   .   .    22
60         5.2.1  Character sets    . . . . .    . .   .   .   .   .   .   .   .    .   .   .   .   .   .    22
61         5.2.2  Character display semantics      .   .   .   .   .   .   .   .    .   .   .   .   .   .    24
62         5.2.3  Signals and interrupts . .     . .   .   .   .   .   .   .   .    .   .   .   .   .   .    25
63         5.2.4  Environmental limits    . .    . .   .   .   .   .   .   .   .    .   .   .   .   .   .    25
64 6. Language . . . . . . . . . . . . . . . .             .   .   .   .   .   .    .   .   .   .   .   .    35
65    6.1 Notation . . . . . . . . . . . . . .             .   .   .   .   .   .    .   .   .   .   .   .    35
66    6.2 Concepts       . . . . . . . . . . . . .         .   .   .   .   .   .    .   .   .   .   .   .    35
67         6.2.1   Scopes of identifiers     . . . . .      .   .   .   .   .   .    .   .   .   .   .   .    35
68         6.2.2   Linkages of identifiers . . . . .        .   .   .   .   .   .    .   .   .   .   .   .    36
69         6.2.3   Name spaces of identifiers      . . .    .   .   .   .   .   .    .   .   .   .   .   .    37
70         6.2.4   Storage durations of objects     . .    .   .   .   .   .   .    .   .   .   .   .   .    38
71         6.2.5   Types       . . . . . . . . . . .       .   .   .   .   .   .    .   .   .   .   .   .    39
72         6.2.6   Representations of types . . . .        .   .   .   .   .   .    .   .   .   .   .   .    44
73         6.2.7   Compatible type and composite type          .   .   .   .   .    .   .   .   .   .   .    47
74         6.2.8   Alignment of objects     . . . . .      .   .   .   .   .   .    .   .   .   .   .   .    48
75    6.3 Conversions       . . . . . . . . . . . .        .   .   .   .   .   .    .   .   .   .   .   .    50
76         6.3.1   Arithmetic operands      . . . . .      .   .   .   .   .   .    .   .   .   .   .   .    50
77         6.3.2   Other operands       . . . . . . .      .   .   .   .   .   .    .   .   .   .   .   .    54
78    6.4 Lexical elements       . . . . . . . . . .       .   .   .   .   .   .    .   .   .   .   .   .    57
79         6.4.1   Keywords . . . . . . . . . .            .   .   .   .   .   .    .   .   .   .   .   .    58
80         6.4.2   Identifiers . . . . . . . . . .          .   .   .   .   .   .    .   .   .   .   .   .    59
81         6.4.3   Universal character names      . . .    .   .   .   .   .   .    .   .   .   .   .   .    61
82         6.4.4   Constants . . . . . . . . . .           .   .   .   .   .   .    .   .   .   .   .   .    62
83         6.4.5   String literals   . . . . . . . .       .   .   .   .   .   .    .   .   .   .   .   .    70
84         6.4.6   Punctuators . . . . . . . . .           .   .   .   .   .   .    .   .   .   .   .   .    72
85         6.4.7   Header names      . . . . . . . .       .   .   .   .   .   .    .   .   .   .   .   .    73
86         6.4.8   Preprocessing numbers        . . . .    .   .   .   .   .   .    .   .   .   .   .   .    74
87         6.4.9   Comments        . . . . . . . . .       .   .   .   .   .   .    .   .   .   .   .   .    75
88
89
90 [page iii]
91
92      6.5  Expressions      . . . . . . . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .    76
93           6.5.1   Primary expressions      . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    78
94           6.5.2   Postfix operators . . . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .    79
95           6.5.3   Unary operators      . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    88
96           6.5.4   Cast operators . . . . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .    91
97           6.5.5   Multiplicative operators   . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    92
98           6.5.6   Additive operators     . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    92
99           6.5.7   Bitwise shift operators . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .    94
100           6.5.8   Relational operators . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .    95
101           6.5.9   Equality operators     . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    96
102           6.5.10 Bitwise AND operator . . .        .   .   .   .   .   .   .   .   .   .   .   .   .   .    97
103           6.5.11 Bitwise exclusive OR operator         .   .   .   .   .   .   .   .   .   .   .   .   .    98
104           6.5.12 Bitwise inclusive OR operator     .   .   .   .   .   .   .   .   .   .   .   .   .   .    98
105           6.5.13 Logical AND operator . . .        .   .   .   .   .   .   .   .   .   .   .   .   .   .    99
106           6.5.14 Logical OR operator       . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    99
107           6.5.15 Conditional operator      . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   100
108           6.5.16 Assignment operators . . .        .   .   .   .   .   .   .   .   .   .   .   .   .   .   101
109           6.5.17 Comma operator . . . . .          .   .   .   .   .   .   .   .   .   .   .   .   .   .   104
110      6.6 Constant expressions . . . . . . .        .   .   .   .   .   .   .   .   .   .   .   .   .   .   105
111      6.7 Declarations      . . . . . . . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   107
112           6.7.1   Storage-class specifiers    . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   108
113           6.7.2   Type specifiers . . . . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   109
114           6.7.3   Type qualifiers . . . . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   120
115           6.7.4   Function specifiers     . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   124
116           6.7.5   Alignment specifier . . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   126
117           6.7.6   Declarators     . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   127
118           6.7.7   Type names . . . . . . .         .   .   .   .   .   .   .   .   .   .   .   .   .   .   135
119           6.7.8   Type definitions      . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   136
120           6.7.9   Initialization    . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   138
121           6.7.10 Static assertions     . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   144
122      6.8 Statements and blocks      . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   145
123           6.8.1   Labeled statements     . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   145
124           6.8.2   Compound statement       . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   146
125           6.8.3   Expression and null statements       .   .   .   .   .   .   .   .   .   .   .   .   .   146
126           6.8.4   Selection statements     . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   147
127           6.8.5   Iteration statements . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   149
128           6.8.6   Jump statements      . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   150
129      6.9 External definitions      . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   154
130           6.9.1   Function definitions . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   155
131           6.9.2   External object definitions   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   157
132      6.10 Preprocessing directives     . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   159
133           6.10.1 Conditional inclusion     . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   161
134           6.10.2 Source file inclusion      . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   163
135           6.10.3 Macro replacement . . . .         .   .   .   .   .   .   .   .   .   .   .   .   .   .   165
136
137
138 [page iv]
139
140        6.10.4 Line control . . . . . .        .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   172
141        6.10.5 Error directive . . . . .       .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   173
142        6.10.6 Pragma directive . . . .        .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   173
143        6.10.7 Null directive      . . . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   174
144        6.10.8 Predefined macro names .         .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   174
145        6.10.9 Pragma operator       . . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   176
146   6.11 Future language directions     . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   178
147        6.11.1 Floating types      . . . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   178
148        6.11.2 Linkages of identifiers . .      .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   178
149        6.11.3 External names        . . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   178
150        6.11.4 Character escape sequences          .   .   .   .   .   .   .   .    .   .   .   .   .   .   178
151        6.11.5 Storage-class specifiers     .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   178
152        6.11.6 Function declarators      . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   178
153        6.11.7 Function definitions . . .       .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   178
154        6.11.8 Pragma directives       . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   178
155        6.11.9 Predefined macro names .         .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   178
156 7. Library . . . . . . . . . . . . . . . . . .                .   .   .   .   .    .   .   .   .   .   .   179
157    7.1 Introduction     . . . . . . . . . . . . .             .   .   .   .   .    .   .   .   .   .   .   179
158          7.1.1 Definitions of terms . . . . . . .              .   .   .   .   .    .   .   .   .   .   .   179
159          7.1.2 Standard headers . . . . . . . .               .   .   .   .   .    .   .   .   .   .   .   180
160          7.1.3 Reserved identifiers . . . . . . .              .   .   .   .   .    .   .   .   .   .   .   181
161          7.1.4 Use of library functions    . . . . .          .   .   .   .   .    .   .   .   .   .   .   182
162    7.2 Diagnostics <assert.h>          . . . . . . .          .   .   .   .   .    .   .   .   .   .   .   185
163          7.2.1 Program diagnostics       . . . . . .          .   .   .   .   .    .   .   .   .   .   .   185
164    7.3 Complex arithmetic <complex.h>           . . .         .   .   .   .   .    .   .   .   .   .   .   187
165          7.3.1 Introduction . . . . . . . . . .               .   .   .   .   .    .   .   .   .   .   .   187
166          7.3.2 Conventions . . . . . . . . . .                .   .   .   .   .    .   .   .   .   .   .   188
167          7.3.3 Branch cuts . . . . . . . . . .                .   .   .   .   .    .   .   .   .   .   .   188
168          7.3.4 The CX_LIMITED_RANGE pragma                    .   .   .   .   .    .   .   .   .   .   .   188
169          7.3.5 Trigonometric functions . . . . .              .   .   .   .   .    .   .   .   .   .   .   189
170          7.3.6 Hyperbolic functions      . . . . . .          .   .   .   .   .    .   .   .   .   .   .   191
171          7.3.7 Exponential and logarithmic functions              .   .   .   .    .   .   .   .   .   .   193
172          7.3.8 Power and absolute-value functions             .   .   .   .   .    .   .   .   .   .   .   194
173          7.3.9 Manipulation functions      . . . . .          .   .   .   .   .    .   .   .   .   .   .   195
174    7.4 Character handling <ctype.h> . . . . .                 .   .   .   .   .    .   .   .   .   .   .   199
175          7.4.1 Character classification functions    .         .   .   .   .   .    .   .   .   .   .   .   199
176          7.4.2 Character case mapping functions     .         .   .   .   .   .    .   .   .   .   .   .   202
177    7.5 Errors <errno.h>         . . . . . . . . . .           .   .   .   .   .    .   .   .   .   .   .   204
178    7.6 Floating-point environment <fenv.h>        . .         .   .   .   .   .    .   .   .   .   .   .   205
179          7.6.1 The FENV_ACCESS pragma           . . .         .   .   .   .   .    .   .   .   .   .   .   207
180          7.6.2 Floating-point exceptions      . . . .         .   .   .   .   .    .   .   .   .   .   .   208
181          7.6.3 Rounding . . . . . . . . . . .                 .   .   .   .   .    .   .   .   .   .   .   211
182          7.6.4 Environment        . . . . . . . . .           .   .   .   .   .    .   .   .   .   .   .   212
183    7.7 Characteristics of floating types <float.h>             .   .   .   .   .    .   .   .   .   .   .   215
184
185 [page v]
186
187      7.8    Format conversion of integer types <inttypes.h> . . . .           .   .   .   .   216
188             7.8.1    Macros for format specifiers      . . . . . . . . . .     .   .   .   .   216
189             7.8.2    Functions for greatest-width integer types   . . . . .   .   .   .   .   217
190      7.9    Alternative spellings <iso646.h> . . . . . . . . . . .            .   .   .   .   220
191      7.10   Sizes of integer types <limits.h>         . . . . . . . . . .     .   .   .   .   221
192      7.11   Localization <locale.h> . . . . . . . . . . . . . .               .   .   .   .   222
193             7.11.1 Locale control . . . . . . . . . . . . . . . .             .   .   .   .   223
194             7.11.2 Numeric formatting convention inquiry . . . . . .          .   .   .   .   224
195      7.12   Mathematics <math.h> . . . . . . . . . . . . . . .                .   .   .   .   230
196             7.12.1 Treatment of error conditions . . . . . . . . . .          .   .   .   .   232
197             7.12.2 The FP_CONTRACT pragma             . . . . . . . . . .     .   .   .   .   234
198             7.12.3 Classification macros       . . . . . . . . . . . . .       .   .   .   .   234
199             7.12.4 Trigonometric functions . . . . . . . . . . . .            .   .   .   .   237
200             7.12.5 Hyperbolic functions       . . . . . . . . . . . . .       .   .   .   .   239
201             7.12.6 Exponential and logarithmic functions        . . . . . .   .   .   .   .   241
202             7.12.7 Power and absolute-value functions         . . . . . . .   .   .   .   .   246
203             7.12.8 Error and gamma functions . . . . . . . . . . .            .   .   .   .   248
204             7.12.9 Nearest integer functions . . . . . . . . . . . .          .   .   .   .   250
205             7.12.10 Remainder functions       . . . . . . . . . . . . .       .   .   .   .   253
206             7.12.11 Manipulation functions       . . . . . . . . . . . .      .   .   .   .   254
207             7.12.12 Maximum, minimum, and positive difference functions           .   .   .   256
208             7.12.13 Floating multiply-add . . . . . . . . . . . . .           .   .   .   .   257
209             7.12.14 Comparison macros . . . . . . . . . . . . . .             .   .   .   .   258
210      7.13   Nonlocal jumps <setjmp.h>            . . . . . . . . . . . .      .   .   .   .   261
211             7.13.1 Save calling environment         . . . . . . . . . . .     .   .   .   .   261
212             7.13.2 Restore calling environment        . . . . . . . . . .     .   .   .   .   262
213      7.14   Signal handling <signal.h> . . . . . . . . . . . . .              .   .   .   .   264
214             7.14.1 Specify signal handling       . . . . . . . . . . . .      .   .   .   .   265
215             7.14.2 Send signal      . . . . . . . . . . . . . . . . .         .   .   .   .   266
216      7.15   Alignment <stdalign.h>            . . . . . . . . . . . . .       .   .   .   .   267
217      7.16   Variable arguments <stdarg.h>           . . . . . . . . . . .     .   .   .   .   268
218             7.16.1 Variable argument list access macros . . . . . . .         .   .   .   .   268
219      7.17   Atomics <stdatomic.h> . . . . . . . . . . . . . .                 .   .   .   .   272
220             7.17.1 Introduction . . . . . . . . . . . . . . . . .             .   .   .   .   272
221             7.17.2 Initialization      . . . . . . . . . . . . . . . .        .   .   .   .   273
222             7.17.3 Order and consistency . . . . . . . . . . . . .            .   .   .   .   274
223             7.17.4 Fences . . . . . . . . . . . . . . . . . . .               .   .   .   .   277
224             7.17.5 Lock-free property       . . . . . . . . . . . . . .       .   .   .   .   278
225             7.17.6 Atomic integer and address types         . . . . . . . .   .   .   .   .   279
226             7.17.7 Operations on atomic types . . . . . . . . . . .           .   .   .   .   281
227             7.17.8 Atomic flag type and operations . . . . . . . . .           .   .   .   .   284
228      7.18   Boolean type and values <stdbool.h>             . . . . . . . .   .   .   .   .   286
229      7.19   Common definitions <stddef.h> . . . . . . . . . . .                .   .   .   .   287
230      7.20   Integer types <stdint.h> . . . . . . . . . . . . . .              .   .   .   .   289
231
232
233 [page vi]
234
235          7.20.1 Integer types      . . . . . . . . . . . .      .   .    .   .   .   .   .   .   289
236          7.20.2 Limits of specified-width integer types    . .   .   .    .   .   .   .   .   .   291
237          7.20.3 Limits of other integer types    . . . . . .    .   .    .   .   .   .   .   .   293
238          7.20.4 Macros for integer constants     . . . . . .    .   .    .   .   .   .   .   .   294
239   7.21   Input/output <stdio.h>         . . . . . . . . . .     .   .    .   .   .   .   .   .   296
240          7.21.1 Introduction . . . . . . . . . . . . .          .   .    .   .   .   .   .   .   296
241          7.21.2 Streams       . . . . . . . . . . . . . .       .   .    .   .   .   .   .   .   298
242          7.21.3 Files . . . . . . . . . . . . . . . .           .   .    .   .   .   .   .   .   300
243          7.21.4 Operations on files      . . . . . . . . . .     .   .    .   .   .   .   .   .   302
244          7.21.5 File access functions     . . . . . . . . .     .   .    .   .   .   .   .   .   304
245          7.21.6 Formatted input/output functions     . . . .    .   .    .   .   .   .   .   .   309
246          7.21.7 Character input/output functions . . . . .      .   .    .   .   .   .   .   .   330
247          7.21.8 Direct input/output functions    . . . . . .    .   .    .   .   .   .   .   .   334
248          7.21.9 File positioning functions     . . . . . . .    .   .    .   .   .   .   .   .   335
249          7.21.10 Error-handling functions . . . . . . . .       .   .    .   .   .   .   .   .   338
250   7.22   General utilities <stdlib.h>        . . . . . . . .    .   .    .   .   .   .   .   .   340
251          7.22.1 Numeric conversion functions . . . . . .        .   .    .   .   .   .   .   .   341
252          7.22.2 Pseudo-random sequence generation functions         .    .   .   .   .   .   .   346
253          7.22.3 Memory management functions . . . . .           .   .    .   .   .   .   .   .   347
254          7.22.4 Communication with the environment        . .   .   .    .   .   .   .   .   .   349
255          7.22.5 Searching and sorting utilities . . . . . .     .   .    .   .   .   .   .   .   353
256          7.22.6 Integer arithmetic functions     . . . . . .    .   .    .   .   .   .   .   .   355
257          7.22.7 Multibyte/wide character conversion functions       .    .   .   .   .   .   .   356
258          7.22.8 Multibyte/wide string conversion functions      .   .    .   .   .   .   .   .   358
259   7.23   String handling <string.h> . . . . . . . . .           .   .    .   .   .   .   .   .   360
260          7.23.1 String function conventions . . . . . . .       .   .    .   .   .   .   .   .   360
261          7.23.2 Copying functions       . . . . . . . . . .     .   .    .   .   .   .   .   .   360
262          7.23.3 Concatenation functions . . . . . . . .         .   .    .   .   .   .   .   .   362
263          7.23.4 Comparison functions . . . . . . . . .          .   .    .   .   .   .   .   .   363
264          7.23.5 Search functions      . . . . . . . . . . .     .   .    .   .   .   .   .   .   365
265          7.23.6 Miscellaneous functions . . . . . . . .         .   .    .   .   .   .   .   .   368
266   7.24   Type-generic math <tgmath.h>          . . . . . . .    .   .    .   .   .   .   .   .   370
267   7.25   Threads <threads.h>          . . . . . . . . . . .     .   .    .   .   .   .   .   .   373
268          7.25.1 Introduction . . . . . . . . . . . . .          .   .    .   .   .   .   .   .   373
269          7.25.2 Initialization functions . . . . . . . . .      .   .    .   .   .   .   .   .   375
270          7.25.3 Condition variable functions     . . . . . .    .   .    .   .   .   .   .   .   375
271          7.25.4 Mutex functions       . . . . . . . . . . .     .   .    .   .   .   .   .   .   377
272          7.25.5 Thread functions . . . . . . . . . . .          .   .    .   .   .   .   .   .   380
273          7.25.6 Thread-specific storage functions     . . . .    .   .    .   .   .   .   .   .   382
274          7.25.7 Time functions . . . . . . . . . . . .          .   .    .   .   .   .   .   .   384
275   7.26   Date and time <time.h>         . . . . . . . . . .     .   .    .   .   .   .   .   .   385
276          7.26.1 Components of time        . . . . . . . . .     .   .    .   .   .   .   .   .   385
277          7.26.2 Time manipulation functions      . . . . . .    .   .    .   .   .   .   .   .   386
278          7.26.3 Time conversion functions      . . . . . . .    .   .    .   .   .   .   .   .   388
279
280
281 [page vii]
282
283    7.27 Unicode utilities <uchar.h> . . . . . . . . . . . . . .               . .     .   395
284         7.27.1 Restartable multibyte/wide character conversion functions        .     .   395
285    7.28 Extended multibyte and wide character utilities <wchar.h> . .         . .     .   399
286         7.28.1 Introduction . . . . . . . . . . . . . . . . . .               . .     .   399
287         7.28.2 Formatted wide character input/output functions       . . .    . .     .   400
288         7.28.3 Wide character input/output functions        . . . . . . .     . .     .   418
289         7.28.4 General wide string utilities     . . . . . . . . . . .        . .     .   422
290                  7.28.4.1 Wide string numeric conversion functions     . .    . .     .   423
291                  7.28.4.2 Wide string copying functions . . . . . . .         . .     .   427
292                  7.28.4.3 Wide string concatenation functions      . . . .    . .     .   429
293                  7.28.4.4 Wide string comparison functions      . . . . .     . .     .   430
294                  7.28.4.5 Wide string search functions      . . . . . . .     . .     .   432
295                  7.28.4.6 Miscellaneous functions      . . . . . . . . .      . .     .   436
296         7.28.5 Wide character time conversion functions       . . . . . .     . .     .   436
297         7.28.6 Extended multibyte/wide character conversion utilities .       . .     .   437
298                  7.28.6.1 Single-byte/wide character conversion functions     . .     .   438
299                  7.28.6.2 Conversion state functions     . . . . . . . .      . .     .   438
300                  7.28.6.3 Restartable multibyte/wide character conversion
301                            functions   . . . . . . . . . . . . . . .          . . . 439
302                  7.28.6.4 Restartable multibyte/wide string conversion
303                            functions   . . . . . . . . . . . . . . .          .   .   .   441
304    7.29 Wide character classification and mapping utilities <wctype.h>         .   .   .   444
305         7.29.1 Introduction . . . . . . . . . . . . . . . . . .               .   .   .   444
306         7.29.2 Wide character classification utilities . . . . . . . .         .   .   .   445
307                  7.29.2.1 Wide character classification functions     . . .    .   .   .   445
308                  7.29.2.2 Extensible wide character classification
309                            functions   . . . . . . . . . . . . . . .          . . . 448
310         7.29.3 Wide character case mapping utilities . . . . . . . .          . . . 450
311                  7.29.3.1 Wide character case mapping functions      . . .    . . . 450
312                  7.29.3.2 Extensible wide character case mapping
313                            functions   . . . . . . . . . . . . . . .          .   .   .   450
314    7.30 Future library directions    . . . . . . . . . . . . . . . .          .   .   .   452
315         7.30.1 Complex arithmetic <complex.h> . . . . . . . .                 .   .   .   452
316         7.30.2 Character handling <ctype.h>            . . . . . . . . .      .   .   .   452
317         7.30.3 Errors <errno.h>           . . . . . . . . . . . . . .         .   .   .   452
318         7.30.4 Format conversion of integer types <inttypes.h>            .   .   .   .   452
319         7.30.5 Localization <locale.h>           . . . . . . . . . . .        .   .   .   452
320         7.30.6 Signal handling <signal.h>           . . . . . . . . . .       .   .   .   452
321         7.30.7 Boolean type and values <stdbool.h>            . . . . . .     .   .   .   452
322         7.30.8 Integer types <stdint.h>          . . . . . . . . . . .        .   .   .   452
323         7.30.9 Input/output <stdio.h>          . . . . . . . . . . . .        .   .   .   453
324         7.30.10 General utilities <stdlib.h>        . . . . . . . . . .       .   .   .   453
325         7.30.11 String handling <string.h>          . . . . . . . . . .       .   .   .   453
326
327
328
329 [page viii]
330
331         7.30.12 Extended multibyte and wide character utilities
332                 <wchar.h>        . . . . . . . . . . . . . . . . . . . . 453
333         7.30.13 Wide character classification and mapping utilities
334                 <wctype.h> . . . . . . . . . . . . . . . . . . . . 453
335 Annex A (informative) Language syntax summary   . .       .   .   .   .    .   .   .   .   .   .   454
336   A.1 Lexical grammar       . . . . . . . . . . . .       .   .   .   .    .   .   .   .   .   .   454
337   A.2 Phrase structure grammar . . . . . . . . .          .   .   .   .    .   .   .   .   .   .   461
338   A.3 Preprocessing directives    . . . . . . . . .       .   .   .   .    .   .   .   .   .   .   469
339 Annex B (informative) Library summary     . . . . . . . . . . . . .                    .   .   .   471
340   B.1 Diagnostics <assert.h>          . . . . . . . . . . . . . . .                    .   .   .   471
341   B.2 Complex <complex.h> . . . . . . . . . . . . . . . .                              .   .   .   471
342   B.3 Character handling <ctype.h> . . . . . . . . . . . . .                           .   .   .   473
343   B.4 Errors <errno.h>         . . . . . . . . . . . . . . . . . .                     .   .   .   473
344   B.5 Floating-point environment <fenv.h>          . . . . . . . . . .                 .   .   .   473
345   B.6 Characteristics of floating types <float.h> . . . . . . . .                       .   .   .   474
346   B.7 Format conversion of integer types <inttypes.h> . . . . .                        .   .   .   474
347   B.8 Alternative spellings <iso646.h> . . . . . . . . . . . .                         .   .   .   475
348   B.9 Sizes of integer types <limits.h>          . . . . . . . . . . .                 .   .   .   475
349   B.10 Localization <locale.h> . . . . . . . . . . . . . . .                           .   .   .   475
350   B.11 Mathematics <math.h> . . . . . . . . . . . . . . . .                            .   .   .   475
351   B.12 Nonlocal jumps <setjmp.h>          . . . . . . . . . . . . .                    .   .   .   480
352   B.13 Signal handling <signal.h> . . . . . . . . . . . . . .                          .   .   .   480
353   B.14 Alignment <stdalign.h>           . . . . . . . . . . . . . .                    .   .   .   481
354   B.15 Variable arguments <stdarg.h>         . . . . . . . . . . . .                   .   .   .   481
355   B.16 Atomics <stdatomic.h> . . . . . . . . . . . . . . .                             .   .   .   481
356   B.17 Boolean type and values <stdbool.h>           . . . . . . . . .                 .   .   .   483
357   B.18 Common definitions <stddef.h> . . . . . . . . . . . .                            .   .   .   483
358   B.19 Integer types <stdint.h> . . . . . . . . . . . . . . .                          .   .   .   483
359   B.20 Input/output <stdio.h>         . . . . . . . . . . . . . . .                    .   .   .   484
360   B.21 General utilities <stdlib.h>       . . . . . . . . . . . . .                    .   .   .   487
361   B.22 String handling <string.h> . . . . . . . . . . . . . .                          .   .   .   489
362   B.23 Type-generic math <tgmath.h>          . . . . . . . . . . . .                   .   .   .   491
363   B.24 Threads <threads.h>          . . . . . . . . . . . . . . . .                    .   .   .   491
364   B.25 Date and time <time.h>         . . . . . . . . . . . . . . .                    .   .   .   492
365   B.26 Unicode utilities <uchar.h> . . . . . . . . . . . . . .                         .   .   .   493
366   B.27 Extended multibyte/wide character utilities <wchar.h>     . . .                 .   .   .   493
367   B.28 Wide character classification and mapping utilities <wctype.h>                   .   .   .   498
368 Annex C (informative) Sequence points     . . . . . . . . . . . . . . . . . 499
369 Annex D (normative) Universal character names for identifiers . . . . . . . 500
370   D.1 Ranges of characters allowed       . . . . . . . . . . . . . . . . . 500
371   D.2 Ranges of characters disallowed initially . . . . . . . . . . . . . 500
372 Annex E (informative) Implementation limits        . . . . . . . . . . . . . . 501
373
374 [page ix]
375
376 Annex F (normative) IEC 60559 floating-point arithmetic . . . . . .          . .     .   .   503
377   F.1 Introduction      . . . . . . . . . . . . . . . . . . . .             . .     .   .   503
378   F.2 Types . . . . . . . . . . . . . . . . . . . . . . .                   . .     .   .   503
379   F.3 Operators and functions       . . . . . . . . . . . . . . .           . .     .   .   504
380   F.4 Floating to integer conversion    . . . . . . . . . . . . .           . .     .   .   506
381   F.5 Binary-decimal conversion       . . . . . . . . . . . . . .           . .     .   .   506
382   F.6 The return statement . . . . . . . . . . . . . . . .                  . .     .   .   507
383   F.7 Contracted expressions . . . . . . . . . . . . . . . .                . .     .   .   507
384   F.8 Floating-point environment      . . . . . . . . . . . . . .           . .     .   .   507
385   F.9 Optimization . . . . . . . . . . . . . . . . . . . .                  . .     .   .   510
386   F.10 Mathematics <math.h> . . . . . . . . . . . . . . .                   . .     .   .   513
387         F.10.1 Trigonometric functions . . . . . . . . . . . .              . .     .   .   514
388         F.10.2 Hyperbolic functions     . . . . . . . . . . . . .           . .     .   .   516
389         F.10.3 Exponential and logarithmic functions    . . . . . .         . .     .   .   516
390         F.10.4 Power and absolute value functions     . . . . . . .         . .     .   .   520
391         F.10.5 Error and gamma functions . . . . . . . . . . .              . .     .   .   521
392         F.10.6 Nearest integer functions . . . . . . . . . . . .            . .     .   .   522
393         F.10.7 Remainder functions      . . . . . . . . . . . . .           . .     .   .   524
394         F.10.8 Manipulation functions     . . . . . . . . . . . .           . .     .   .   525
395         F.10.9 Maximum, minimum, and positive difference functions            .     .   .   526
396         F.10.10 Floating multiply-add . . . . . . . . . . . . .             . .     .   .   526
397         F.10.11 Comparison macros . . . . . . . . . . . . . .               . .     .   .   527
398 Annex G (normative) IEC 60559-compatible complex arithmetic     .   .   .   .   .   .   .   528
399   G.1 Introduction     . . . . . . . . . . . . . . . . .        .   .   .   .   .   .   .   528
400   G.2 Types . . . . . . . . . . . . . . . . . . . .             .   .   .   .   .   .   .   528
401   G.3 Conventions      . . . . . . . . . . . . . . . . .        .   .   .   .   .   .   .   528
402   G.4 Conversions      . . . . . . . . . . . . . . . . .        .   .   .   .   .   .   .   529
403        G.4.1 Imaginary types     . . . . . . . . . . . .        .   .   .   .   .   .   .   529
404        G.4.2 Real and imaginary . . . . . . . . . . .           .   .   .   .   .   .   .   529
405        G.4.3 Imaginary and complex       . . . . . . . . .      .   .   .   .   .   .   .   529
406   G.5 Binary operators     . . . . . . . . . . . . . . .        .   .   .   .   .   .   .   529
407        G.5.1 Multiplicative operators    . . . . . . . . .      .   .   .   .   .   .   .   530
408        G.5.2 Additive operators     . . . . . . . . . . .       .   .   .   .   .   .   .   533
409   G.6 Complex arithmetic <complex.h>         . . . . . . .      .   .   .   .   .   .   .   533
410        G.6.1 Trigonometric functions . . . . . . . . .          .   .   .   .   .   .   .   535
411        G.6.2 Hyperbolic functions     . . . . . . . . . .       .   .   .   .   .   .   .   535
412        G.6.3 Exponential and logarithmic functions     . . .    .   .   .   .   .   .   .   539
413        G.6.4 Power and absolute-value functions      . . . .    .   .   .   .   .   .   .   540
414   G.7 Type-generic math <tgmath.h>         . . . . . . . .      .   .   .   .   .   .   .   541
415 Annex H (informative) Language independent arithmetic . .   .   .   .   .   .   .   .   .   542
416   H.1 Introduction     . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .   .   542
417   H.2 Types . . . . . . . . . . . . . . . . . . .           .   .   .   .   .   .   .   .   542
418   H.3 Notification      . . . . . . . . . . . . . . . .      .   .   .   .   .   .   .   .   546
419
420
421 [page x]
422
423 Annex I (informative) Common warnings         . . . . . . . . . . . . . . . . 548
424 Annex J (informative) Portability issues    . . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   550
425   J.1 Unspecified behavior . . . .           . . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   550
426   J.2 Undefined behavior          . . . .    . . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   553
427   J.3 Implementation-defined behavior          . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   566
428   J.4 Locale-specific behavior         . .   . . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   574
429   J.5 Common extensions          . . . .    . . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   575
430 Annex K (normative) Bounds-checking interfaces . . . . . . . . . .                             .   .   .   578
431   K.1 Background       . . . . . . . . . . . . . . . . . . . . .                               .   .   .   578
432   K.2 Scope . . . . . . . . . . . . . . . . . . . . . . . .                                    .   .   .   579
433   K.3 Library     . . . . . . . . . . . . . . . . . . . . . . .                                .   .   .   579
434        K.3.1 Introduction . . . . . . . . . . . . . . . . . .                                  .   .   .   579
435                 K.3.1.1 Standard headers     . . . . . . . . . . . .                           .   .   .   579
436                 K.3.1.2 Reserved identifiers     . . . . . . . . . . .                          .   .   .   580
437                 K.3.1.3 Use of errno . . . . . . . . . . . . . .                               .   .   .   580
438                 K.3.1.4 Runtime-constraint violations     . . . . . . .                        .   .   .   580
439        K.3.2 Errors <errno.h>           . . . . . . . . . . . . . .                            .   .   .   581
440        K.3.3 Common definitions <stddef.h>               . . . . . . . .                        .   .   .   581
441        K.3.4 Integer types <stdint.h>           . . . . . . . . . . .                          .   .   .   581
442        K.3.5 Input/output <stdio.h>          . . . . . . . . . . . .                           .   .   .   582
443                 K.3.5.1 Operations on files      . . . . . . . . . . .                          .   .   .   582
444                 K.3.5.2 File access functions . . . . . . . . . . .                            .   .   .   584
445                 K.3.5.3 Formatted input/output functions . . . . . .                           .   .   .   587
446                 K.3.5.4 Character input/output functions . . . . . .                           .   .   .   598
447        K.3.6 General utilities <stdlib.h>          . . . . . . . . . .                         .   .   .   600
448                 K.3.6.1 Runtime-constraint handling       . . . . . . .                        .   .   .   600
449                 K.3.6.2 Communication with the environment . . . .                             .   .   .   602
450                 K.3.6.3 Searching and sorting utilities . . . . . . .                          .   .   .   603
451                 K.3.6.4 Multibyte/wide character conversion functions                          .   .   .   606
452                 K.3.6.5 Multibyte/wide string conversion functions . .                         .   .   .   607
453        K.3.7 String handling <string.h>            . . . . . . . . . .                         .   .   .   610
454                 K.3.7.1 Copying functions       . . . . . . . . . . .                          .   .   .   610
455                 K.3.7.2 Concatenation functions       . . . . . . . . .                        .   .   .   613
456                 K.3.7.3 Search functions     . . . . . . . . . . . .                           .   .   .   616
457                 K.3.7.4 Miscellaneous functions       . . . . . . . . .                        .   .   .   617
458        K.3.8 Date and time <time.h>          . . . . . . . . . . . .                           .   .   .   620
459                 K.3.8.1 Components of time . . . . . . . . . . .                               .   .   .   620
460                 K.3.8.2 Time conversion functions       . . . . . . . .                        .   .   .   620
461        K.3.9 Extended multibyte and wide character utilities
462                 <wchar.h>        . . . . . . . . . . . . . . . . .                             . . . 623
463                 K.3.9.1 Formatted wide character input/output functions                        . . . 624
464                 K.3.9.2 General wide string utilities . . . . . . . .                          . . . 635
465
466
467
468 [page xi]
469
470                K.3.9.3 Extended multibyte/wide character conversion
471                        utilities . . . . . . . . . . . . . . . . . . . 643
472 Annex L (normative) Analyzability . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   648
473   L.1 Scope . . . . . . . . . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   648
474   L.2 Definitions . . . . . . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   648
475   L.3 Requirements . . . . . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   649
476 Bibliography   . . . . . . . . . . . . . . . . . . . . . . . . . . . 650
477 Index    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
478
479
480
481
482 [page xii]
483
484     Foreword
485 1   ISO (the International Organization for Standardization) and IEC (the International
486     Electrotechnical Commission) form the specialized system for worldwide
487     standardization. National bodies that are member of ISO or IEC participate in the
488     development of International Standards through technical committees established by the
489     respective organization to deal with particular fields of technical activity. ISO and IEC
490     technical committees collaborate in fields of mutual interest. Other international
491     organizations, governmental and non-governmental, in liaison with ISO and IEC, also
492     take part in the work.
493 2   International Standards are drafted in accordance with the rules given in the ISO/IEC
494     Directives, Part 2. This International Standard was drafted in accordance with the fifth
495     edition (2004).
496 3   In the field of information technology, ISO and IEC have established a joint technical
497     committee, ISO/IEC JTC 1. Draft International Standards adopted by the joint technical
498     committee are circulated to national bodies for voting. Publication as an International
499     Standard requires approval by at least 75% of the national bodies casting a vote.
500 4   Attention is drawn to the possibility that some of the elements of this document may be
501     the subject of patent rights. ISO and IEC shall not be held responsible for identifying any
502     or all such patent rights.
503 5   This International Standard was prepared by Joint Technical Committee ISO/IEC JTC 1,
504     Information technology, Subcommittee SC 22, Programming languages, their
505     environments and system software interfaces. The Working Group responsible for this
506     standard (WG 14) maintains a site on the World Wide Web at http://www.open-
507     std.org/JTC1/SC22/WG14/ containing additional information relevant to this
508     standard such as a Rationale for many of the decisions made during its preparation and a
509     log of Defect Reports and Responses.
510 6   This third edition cancels and replaces the second edition, ISO/IEC 9899:1999, as
511     corrected by ISO/IEC 9899:1999/Cor 1:2001, ISO/IEC 9899:1999/Cor 2:2004, and
512     ISO/IEC 9899:1999/Cor 3:2007. Major changes from the previous edition include:
513     -- conditional (optional) features (including some that were previously mandatory)
514     -- support for multiple threads of execution including an improved memory sequencing
515       model, atomic objects, and thread-local storage (<stdatomic.h> and
516       <threads.h>)
517     -- additional floating-point characteristic macros (<float.h>)
518     -- querying and specifying alignment of objects (<stdalign.h>, <stdlib.h>)
519     -- Unicode characters and           strings   (<uchar.h>)       (originally   specified    in
520       ISO/IEC TR 19769:2004)
521     -- type-generic expressions
522
523
524 [page xiii]
525
526     -- static assertions
527     -- anonymous structures and unions
528     -- no-return functions
529     -- macros to create complex numbers (<complex.h>)
530     -- support for opening files for exclusive access
531     -- removed the gets function (<stdio.h>)
532     -- added the aligned_alloc, at_quick_exit, and quick_exit functions
533       (<stdlib.h>)
534     -- (conditional) support for bounds-checking interfaces (originally specified in
535       ISO/IEC TR 24731-1:2007)
536     -- (conditional) support for analyzability
537 7   Major changes in the second edition included:
538     -- restricted character set support via digraphs and <iso646.h> (originally specified
539       in AMD1)
540     -- wide character library support in <wchar.h> and <wctype.h> (originally
541       specified in AMD1)
542     -- more precise aliasing rules via effective type
543     -- restricted pointers
544     -- variable length arrays
545     -- flexible array members
546     -- static and type qualifiers in parameter array declarators
547     -- complex (and imaginary) support in <complex.h>
548     -- type-generic math macros in <tgmath.h>
549     -- the long long int type and library functions
550     -- increased minimum translation limits
551     -- additional floating-point characteristics in <float.h>
552     -- remove implicit int
553     -- reliable integer division
554     -- universal character names (\u and \U)
555     -- extended identifiers
556     -- hexadecimal floating-point constants and %a and %A printf/scanf conversion
557       specifiers
558
559
560
561 [page xiv]
562
563 -- compound literals
564 -- designated initializers
565 -- // comments
566 -- extended integer types and library functions in <inttypes.h> and <stdint.h>
567 -- remove implicit function declaration
568 -- preprocessor arithmetic done in intmax_t/uintmax_t
569 -- mixed declarations and code
570 -- new block scopes for selection and iteration statements
571 -- integer constant type rules
572 -- integer promotion rules
573 -- macros with a variable number of arguments
574 -- the vscanf family of functions in <stdio.h> and <wchar.h>
575 -- additional math library functions in <math.h>
576 -- treatment of error conditions by math library functions (math_errhandling)
577 -- floating-point environment access in <fenv.h>
578 -- IEC 60559 (also known as IEC 559 or IEEE arithmetic) support
579 -- trailing comma allowed in enum declaration
580 -- %lf conversion specifier allowed in printf
581 -- inline functions
582 -- the snprintf family of functions in <stdio.h>
583 -- boolean type in <stdbool.h>
584 -- idempotent type qualifiers
585 -- empty macro arguments
586 -- new structure type compatibility rules (tag compatibility)
587 -- additional predefined macro names
588 -- _Pragma preprocessing operator
589 -- standard pragmas
590 -- __func__ predefined identifier
591 -- va_copy macro
592 -- additional strftime conversion specifiers
593 -- LIA compatibility annex
594
595
596 [page xv]
597
598     -- deprecate ungetc at the beginning of a binary file
599     -- remove deprecation of aliased array parameters
600     -- conversion of array to pointer not limited to lvalues
601     -- relaxed constraints on aggregate and union initialization
602     -- relaxed restrictions on portable header names
603     -- return without expression not permitted in function that returns a value (and vice
604       versa)
605 8   Annexes D, F, G, K, and L form a normative part of this standard; annexes A, B, C, E, H, *
606     I, J, the bibliography, and the index are for information only. In accordance with Part 2 of
607     the ISO/IEC Directives, this foreword, the introduction, notes, footnotes, and examples
608     are also for information only.
609
610
611
612
613 [page xvi]
614
615     Introduction
616 1   With the introduction of new devices and extended character sets, new features may be
617     added to this International Standard. Subclauses in the language and library clauses warn
618     implementors and programmers of usages which, though valid in themselves, may
619     conflict with future additions.
620 2   Certain features are obsolescent, which means that they may be considered for
621     withdrawal in future revisions of this International Standard. They are retained because
622     of their widespread use, but their use in new implementations (for implementation
623     features) or new programs (for language [6.11] or library features [7.30]) is discouraged.
624 3   This International Standard is divided into four major subdivisions:
625     -- preliminary elements (clauses 1-4);
626     -- the characteristics of environments that translate and execute C programs (clause 5);
627     -- the language syntax, constraints, and semantics (clause 6);
628     -- the library facilities (clause 7).
629 4   Examples are provided to illustrate possible forms of the constructions described.
630     Footnotes are provided to emphasize consequences of the rules described in that
631     subclause or elsewhere in this International Standard. References are used to refer to
632     other related subclauses. Recommendations are provided to give advice or guidance to
633     implementors. Annexes provide additional information and summarize the information
634     contained in this International Standard. A bibliography lists documents that were
635     referred to during the preparation of the standard.
636 5   The language clause (clause 6) is derived from ''The C Reference Manual''.
637 6   The library clause (clause 7) is based on the 1984 /usr/group Standard.
638
639
640
641
642 [page xvii]
643
644
645
646 [page xviii]
647
648
649
650     Programming languages -- C
651
652
653
654     1. Scope
655 1   This International Standard specifies the form and establishes the interpretation of
656     programs written in the C programming language.1) It specifies
657     -- the representation of C programs;
658     -- the syntax and constraints of the C language;
659     -- the semantic rules for interpreting C programs;
660     -- the representation of input data to be processed by C programs;
661     -- the representation of output data produced by C programs;
662     -- the restrictions and limits imposed by a conforming implementation of C.
663 2   This International Standard does not specify
664     -- the mechanism by which C programs are transformed for use by a data-processing
665       system;
666     -- the mechanism by which C programs are invoked for use by a data-processing
667       system;
668     -- the mechanism by which input data are transformed for use by a C program;
669     -- the mechanism by which output data are transformed after being produced by a C
670       program;
671     -- the size or complexity of a program and its data that will exceed the capacity of any
672       specific data-processing system or the capacity of a particular processor;
673     -- all minimal requirements of a data-processing system that is capable of supporting a
674       conforming implementation.
675
676
677     1)   This International Standard is designed to promote the portability of C programs among a variety of
678          data-processing systems. It is intended for use by implementors and programmers.
679
680 [page 1]
681
682
683     2. Normative references
684 1   The following referenced documents are indispensable for the application of this
685     document. For dated references, only the edition cited applies. For undated references,
686     the latest edition of the referenced document (including any amendments) applies.
687 2   ISO 31-11:1992, Quantities and units -- Part 11: Mathematical signs and symbols for
688     use in the physical sciences and technology.
689 3   ISO/IEC 646, Information technology -- ISO 7-bit coded character set for information
690     interchange.
691 4   ISO/IEC 2382-1:1993, Information technology -- Vocabulary -- Part 1: Fundamental
692     terms.
693 5   ISO 4217, Codes for the representation of currencies and funds.
694 6   ISO 8601, Data elements and interchange formats -- Information interchange --
695     Representation of dates and times.
696 7   ISO/IEC 10646 (all parts), Information technology -- Universal Multiple-Octet Coded
697     Character Set (UCS).
698 8   IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems (previously
699     designated IEC 559:1989).
700
701
702
703
704 [page 2]
705
706
707     3. Terms, definitions, and symbols
708 1   For the purposes of this International Standard, the following definitions apply. Other
709     terms are defined where they appear in italic type or on the left side of a syntax rule.
710     Terms explicitly defined in this International Standard are not to be presumed to refer
711     implicitly to similar terms defined elsewhere. Terms not defined in this International
712     Standard are to be interpreted according to ISO/IEC 2382-1. Mathematical symbols not
713     defined in this International Standard are to be interpreted according to ISO 31-11.
714     3.1
715 1   access
716     <execution-time action> to read or modify the value of an object
717 2   NOTE 1   Where only one of these two actions is meant, ''read'' or ''modify'' is used.
718
719 3   NOTE 2   ''Modify'' includes the case where the new value being stored is the same as the previous value.
720
721 4   NOTE 3   Expressions that are not evaluated do not access objects.
722
723     3.2
724 1   alignment
725     requirement that objects of a particular type be located on storage boundaries with
726     addresses that are particular multiples of a byte address
727     3.3
728 1   argument
729     actual argument
730     actual parameter (deprecated)
731     expression in the comma-separated list bounded by the parentheses in a function call
732     expression, or a sequence of preprocessing tokens in the comma-separated list bounded
733     by the parentheses in a function-like macro invocation
734     3.4
735 1   behavior
736     external appearance or action
737     3.4.1
738 1   implementation-defined behavior
739     unspecified behavior where each implementation documents how the choice is made
740 2   EXAMPLE An example of implementation-defined behavior is the propagation of the high-order bit
741     when a signed integer is shifted right.
742
743     3.4.2
744 1   locale-specific behavior
745     behavior that depends on local conventions of nationality, culture, and language that each
746     implementation documents
747
748
749 [page 3]
750
751 2   EXAMPLE An example of locale-specific behavior is whether the islower function returns true for
752     characters other than the 26 lowercase Latin letters.
753
754     3.4.3
755 1   undefined behavior
756     behavior, upon use of a nonportable or erroneous program construct or of erroneous data,
757     for which this International Standard imposes no requirements
758 2   NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable
759     results, to behaving during translation or program execution in a documented manner characteristic of the
760     environment (with or without the issuance of a diagnostic message), to terminating a translation or
761     execution (with the issuance of a diagnostic message).
762
763 3   EXAMPLE        An example of undefined behavior is the behavior on integer overflow.
764
765     3.4.4
766 1   unspecified behavior
767     use of an unspecified value, or other behavior where this International Standard provides
768     two or more possibilities and imposes no further requirements on which is chosen in any
769     instance
770 2   EXAMPLE        An example of unspecified behavior is the order in which the arguments to a function are
771     evaluated.
772
773     3.5
774 1   bit
775     unit of data storage in the execution environment large enough to hold an object that may
776     have one of two values
777 2   NOTE     It need not be possible to express the address of each individual bit of an object.
778
779     3.6
780 1   byte
781     addressable unit of data storage large enough to hold any member of the basic character
782     set of the execution environment
783 2   NOTE 1     It is possible to express the address of each individual byte of an object uniquely.
784
785 3   NOTE 2 A byte is composed of a contiguous sequence of bits, the number of which is implementation-
786     defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order
787     bit.
788
789     3.7
790 1   character
791     <abstract> member of a set of elements used for the organization, control, or
792     representation of data
793     3.7.1
794 1   character
795     single-byte character
796     <C> bit representation that fits in a byte
797 [page 4]
798
799     3.7.2
800 1   multibyte character
801     sequence of one or more bytes representing a member of the extended character set of
802     either the source or the execution environment
803 2   NOTE    The extended character set is a superset of the basic character set.
804
805     3.7.3
806 1   wide character
807     bit representation that fits in an object of type wchar_t, capable of representing any
808     character in the current locale
809     3.8
810 1   constraint
811     restriction, either syntactic or semantic, by which the exposition of language elements is
812     to be interpreted
813     3.9
814 1   correctly rounded result
815     representation in the result format that is nearest in value, subject to the current rounding
816     mode, to what the result would be given unlimited range and precision
817     3.10
818 1   diagnostic message
819     message belonging to an implementation-defined subset of the implementation's message
820     output
821     3.11
822 1   forward reference
823     reference to a later subclause of this International Standard that contains additional
824     information relevant to this subclause
825     3.12
826 1   implementation
827     particular set of software, running in a particular translation environment under particular
828     control options, that performs translation of programs for, and supports execution of
829     functions in, a particular execution environment
830     3.13
831 1   implementation limit
832     restriction imposed upon programs by the implementation
833     3.14
834 1   memory location
835     either an object of scalar type, or a maximal sequence of adjacent bit-fields all having
836     nonzero width
837
838 [page 5]
839
840 2   NOTE 1 Two threads of execution can update and access separate memory locations without interfering
841     with each other.
842
843 3   NOTE 2 A bit-field and an adjacent non-bit-field member are in separate memory locations. The same
844     applies to two bit-fields, if one is declared inside a nested structure declaration and the other is not, or if the
845     two are separated by a zero-length bit-field declaration, or if they are separated by a non-bit-field member
846     declaration. It is not safe to concurrently update two non-atomic bit-fields in the same structure if all
847     members declared between them are also (non-zero-length) bit-fields, no matter what the sizes of those
848     intervening bit-fields happen to be.
849
850 4   EXAMPLE        A structure declared as
851              struct {
852                    char a;
853                    int b:5, c:11, :0, d:8;
854                    struct { int ee:8; } e;
855              }
856     contains four separate memory locations: The member a, and bit-fields d and e.ee are each separate
857     memory locations, and can be modified concurrently without interfering with each other. The bit-fields b
858     and c together constitute the fourth memory location. The bit-fields b and c cannot be concurrently
859     modified, but b and a, for example, can be.
860
861     3.15
862 1   object
863     region of data storage in the execution environment, the contents of which can represent
864     values
865 2   NOTE      When referenced, an object may be interpreted as having a particular type; see 6.3.2.1.
866
867     3.16
868 1   parameter
869     formal parameter
870     formal argument (deprecated)
871     object declared as part of a function declaration or definition that acquires a value on
872     entry to the function, or an identifier from the comma-separated list bounded by the
873     parentheses immediately following the macro name in a function-like macro definition
874     3.17
875 1   recommended practice
876     specification that is strongly recommended as being in keeping with the intent of the
877     standard, but that may be impractical for some implementations
878     3.18
879 1   runtime-constraint
880     requirement on a program when calling a library function
881 2   NOTE 1 Despite the similar terms, a runtime-constraint is not a kind of constraint as defined by 3.8, and
882     need not be diagnosed at translation time.
883
884 3   NOTE 2 Implementations that support the extensions in annex K are required to verify that the runtime-
885     constraints for a library function are not violated by the program; see K.3.1.4.
886
887 [page 6]
888
889     3.19
890 1   value
891     precise meaning of the contents of an object when interpreted as having a specific type
892     3.19.1
893 1   implementation-defined value
894     unspecified value where each implementation documents how the choice is made
895     3.19.2
896 1   indeterminate value
897     either an unspecified value or a trap representation
898     3.19.3
899 1   unspecified value
900     valid value of the relevant type where this International Standard imposes no
901     requirements on which value is chosen in any instance
902 2   NOTE     An unspecified value cannot be a trap representation.
903
904     3.19.4
905 1   trap representation
906     an object representation that need not represent a value of the object type
907     3.19.5
908 1   perform a trap
909     interrupt execution of the program such that no further operations are performed
910 2   NOTE In this International Standard, when the word ''trap'' is not immediately followed by
911     ''representation'', this is the intended usage.2)
912
913     3.20
914 1   [^ x^]
915     ceiling of x: the least integer greater than or equal to x
916 2   EXAMPLE       [^2.4^] is 3, [^-2.4^] is -2.
917
918     3.21
919 1   [_ x_]
920     floor of x: the greatest integer less than or equal to x
921 2   EXAMPLE       [_2.4_] is 2, [_-2.4_] is -3.
922
923
924
925
926     2)   For example, ''Trapping or stopping (if supported) is disabled...'' (F.8.2). Note that fetching a trap
927          representation might perform a trap but is not required to (see 6.2.6.1).
928
929 [page 7]
930
931
932     4. Conformance
933 1   In this International Standard, ''shall'' is to be interpreted as a requirement on an
934     implementation or on a program; conversely, ''shall not'' is to be interpreted as a
935     prohibition.
936 2   If a ''shall'' or ''shall not'' requirement that appears outside of a constraint or runtime-
937     constraint is violated, the behavior is undefined. Undefined behavior is otherwise
938     indicated in this International Standard by the words ''undefined behavior'' or by the
939     omission of any explicit definition of behavior. There is no difference in emphasis among
940     these three; they all describe ''behavior that is undefined''.
941 3   A program that is correct in all other aspects, operating on correct data, containing
942     unspecified behavior shall be a correct program and act in accordance with 5.1.2.3.
943 4   The implementation shall not successfully translate a preprocessing translation unit
944     containing a #error preprocessing directive unless it is part of a group skipped by
945     conditional inclusion.
946 5   A strictly conforming program shall use only those features of the language and library
947     specified in this International Standard.3) It shall not produce output dependent on any
948     unspecified, undefined, or implementation-defined behavior, and shall not exceed any
949     minimum implementation limit.
950 6   The two forms of conforming implementation are hosted and freestanding. A conforming
951     hosted implementation shall accept any strictly conforming program. A conforming
952     freestanding implementation shall accept any strictly conforming program that does not
953     use complex types and in which the use of the features specified in the library clause
954     (clause 7) is confined to the contents of the standard headers <float.h>,
955     <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>,
956     <stddef.h>, and <stdint.h>. A conforming implementation may have extensions
957     (including additional library functions), provided they do not alter the behavior of any
958     strictly conforming program.4)
959
960
961
962     3)   A strictly conforming program can use conditional features (see 6.10.8.3) provided the use is guarded
963          by an appropriate conditional inclusion preprocessing directive using the related macro. For example:
964                  #ifdef __STDC_IEC_559__ /* FE_UPWARD defined */
965                     /* ... */
966                     fesetround(FE_UPWARD);
967                     /* ... */
968                  #endif
969
970     4)   This implies that a conforming implementation reserves no identifiers other than those explicitly
971          reserved in this International Standard.
972
973 [page 8]
974
975 7   A conforming program is one that is acceptable to a conforming implementation.5)
976 8   An implementation shall be accompanied by a document that defines all implementation-
977     defined and locale-specific characteristics and all extensions.
978     Forward references: conditional inclusion (6.10.1), error directive (6.10.5),
979     characteristics of floating types <float.h> (7.7), alternative spellings <iso646.h>
980     (7.9), sizes of integer types <limits.h> (7.10), alignment <stdalign.h> (7.15),
981     variable arguments <stdarg.h> (7.16), boolean type and values <stdbool.h>
982     (7.18), common definitions <stddef.h> (7.19), integer types <stdint.h> (7.20).
983
984
985
986
987     5)   Strictly conforming programs are intended to be maximally portable among conforming
988          implementations. Conforming programs may depend upon nonportable features of a conforming
989          implementation.
990
991 [page 9]
992
993
994     5. Environment
995 1   An implementation translates C source files and executes C programs in two data-
996     processing-system environments, which will be called the translation environment and
997     the execution environment in this International Standard. Their characteristics define and
998     constrain the results of executing conforming C programs constructed according to the
999     syntactic and semantic rules for conforming implementations.
1000     Forward references: In this clause, only a few of many possible forward references
1001     have been noted.
1002     5.1 Conceptual models
1003     5.1.1 Translation environment
1004     5.1.1.1 Program structure
1005 1   A C program need not all be translated at the same time. The text of the program is kept
1006     in units called source files, (or preprocessing files) in this International Standard. A
1007     source file together with all the headers and source files included via the preprocessing
1008     directive #include is known as a preprocessing translation unit. After preprocessing, a
1009     preprocessing translation unit is called a translation unit. Previously translated translation
1010     units may be preserved individually or in libraries. The separate translation units of a
1011     program communicate by (for example) calls to functions whose identifiers have external
1012     linkage, manipulation of objects whose identifiers have external linkage, or manipulation
1013     of data files. Translation units may be separately translated and then later linked to
1014     produce an executable program.
1015     Forward references: linkages of identifiers (6.2.2), external definitions (6.9),
1016     preprocessing directives (6.10).
1017     5.1.1.2 Translation phases
1018 1   The precedence among the syntax rules of translation is specified by the following
1019     phases.6)
1020          1.   Physical source file multibyte characters are mapped, in an implementation-
1021               defined manner, to the source character set (introducing new-line characters for
1022               end-of-line indicators) if necessary. Trigraph sequences are replaced by
1023               corresponding single-character internal representations.
1024
1025
1026
1027     6)    Implementations shall behave as if these separate phases occur, even though many are typically folded
1028           together in practice. Source files, translation units, and translated translation units need not
1029           necessarily be stored as files, nor need there be any one-to-one correspondence between these entities
1030           and any external representation. The description is conceptual only, and does not specify any
1031           particular implementation.
1032
1033 [page 10]
1034
1035      2.   Each instance of a backslash character (\) immediately followed by a new-line
1036           character is deleted, splicing physical source lines to form logical source lines.
1037           Only the last backslash on any physical source line shall be eligible for being part
1038           of such a splice. A source file that is not empty shall end in a new-line character,
1039           which shall not be immediately preceded by a backslash character before any such
1040           splicing takes place.
1041      3.   The source file is decomposed into preprocessing tokens7) and sequences of
1042           white-space characters (including comments). A source file shall not end in a
1043           partial preprocessing token or in a partial comment. Each comment is replaced by
1044           one space character. New-line characters are retained. Whether each nonempty
1045           sequence of white-space characters other than new-line is retained or replaced by
1046           one space character is implementation-defined.
1047      4. Preprocessing directives are executed, macro invocations are expanded, and
1048         _Pragma unary operator expressions are executed. If a character sequence that
1049         matches the syntax of a universal character name is produced by token
1050         concatenation (6.10.3.3), the behavior is undefined. A #include preprocessing
1051         directive causes the named header or source file to be processed from phase 1
1052         through phase 4, recursively. All preprocessing directives are then deleted.
1053      5. Each source character set member and escape sequence in character constants and
1054         string literals is converted to the corresponding member of the execution character
1055         set; if there is no corresponding member, it is converted to an implementation-
1056         defined member other than the null (wide) character.8)
1057      6.   Adjacent string literal tokens are concatenated.
1058      7. White-space characters separating tokens are no longer significant. Each
1059         preprocessing token is converted into a token. The resulting tokens are
1060         syntactically and semantically analyzed and translated as a translation unit.
1061      8.   All external object and function references are resolved. Library components are
1062           linked to satisfy external references to functions and objects not defined in the
1063           current translation. All such translator output is collected into a program image
1064           which contains information needed for execution in its execution environment.
1065 Forward references: universal character names (6.4.3), lexical elements (6.4),
1066 preprocessing directives (6.10), trigraph sequences (5.2.1.1), external definitions (6.9).
1067
1068
1069
1070 7)    As described in 6.4, the process of dividing a source file's characters into preprocessing tokens is
1071       context-dependent. For example, see the handling of < within a #include preprocessing directive.
1072 8)    An implementation need not convert all non-corresponding source characters to the same execution
1073       character.
1074
1075 [page 11]
1076
1077     5.1.1.3 Diagnostics
1078 1   A conforming implementation shall produce at least one diagnostic message (identified in
1079     an implementation-defined manner) if a preprocessing translation unit or translation unit
1080     contains a violation of any syntax rule or constraint, even if the behavior is also explicitly
1081     specified as undefined or implementation-defined. Diagnostic messages need not be
1082     produced in other circumstances.9)
1083 2   EXAMPLE        An implementation shall issue a diagnostic for the translation unit:
1084              char i;
1085              int i;
1086     because in those cases where wording in this International Standard describes the behavior for a construct
1087     as being both a constraint error and resulting in undefined behavior, the constraint error shall be diagnosed.
1088
1089     5.1.2 Execution environments
1090 1   Two execution environments are defined: freestanding and hosted. In both cases,
1091     program startup occurs when a designated C function is called by the execution
1092     environment. All objects with static storage duration shall be initialized (set to their
1093     initial values) before program startup. The manner and timing of such initialization are
1094     otherwise unspecified. Program termination returns control to the execution
1095     environment.
1096     Forward references: storage durations of objects (6.2.4), initialization (6.7.9).
1097     5.1.2.1 Freestanding environment
1098 1   In a freestanding environment (in which C program execution may take place without any
1099     benefit of an operating system), the name and type of the function called at program
1100     startup are implementation-defined. Any library facilities available to a freestanding
1101     program, other than the minimal set required by clause 4, are implementation-defined.
1102 2   The effect of program termination in a freestanding environment is implementation-
1103     defined.
1104     5.1.2.2 Hosted environment
1105 1   A hosted environment need not be provided, but shall conform to the following
1106     specifications if present.
1107
1108
1109
1110
1111     9)   The intent is that an implementation should identify the nature of, and where possible localize, each
1112          violation. Of course, an implementation is free to produce any number of diagnostics as long as a
1113          valid program is still correctly translated. It may also successfully translate an invalid program.
1114
1115 [page 12]
1116
1117     5.1.2.2.1 Program startup
1118 1   The function called at program startup is named main. The implementation declares no
1119     prototype for this function. It shall be defined with a return type of int and with no
1120     parameters:
1121             int main(void) { /* ... */ }
1122     or with two parameters (referred to here as argc and argv, though any names may be
1123     used, as they are local to the function in which they are declared):
1124             int main(int argc, char *argv[]) { /* ... */ }
1125     or equivalent;10) or in some other implementation-defined manner.
1126 2   If they are declared, the parameters to the main function shall obey the following
1127     constraints:
1128     -- The value of argc shall be nonnegative.
1129     -- argv[argc] shall be a null pointer.
1130     -- If the value of argc is greater than zero, the array members argv[0] through
1131       argv[argc-1] inclusive shall contain pointers to strings, which are given
1132       implementation-defined values by the host environment prior to program startup. The
1133       intent is to supply to the program information determined prior to program startup
1134       from elsewhere in the hosted environment. If the host environment is not capable of
1135       supplying strings with letters in both uppercase and lowercase, the implementation
1136       shall ensure that the strings are received in lowercase.
1137     -- If the value of argc is greater than zero, the string pointed to by argv[0]
1138       represents the program name; argv[0][0] shall be the null character if the
1139       program name is not available from the host environment. If the value of argc is
1140       greater than one, the strings pointed to by argv[1] through argv[argc-1]
1141       represent the program parameters.
1142     -- The parameters argc and argv and the strings pointed to by the argv array shall
1143       be modifiable by the program, and retain their last-stored values between program
1144       startup and program termination.
1145     5.1.2.2.2 Program execution
1146 1   In a hosted environment, a program may use all the functions, macros, type definitions,
1147     and objects described in the library clause (clause 7).
1148
1149
1150
1151
1152     10) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as
1153         char ** argv, and so on.
1154
1155 [page 13]
1156
1157     5.1.2.2.3 Program termination
1158 1   If the return type of the main function is a type compatible with int, a return from the
1159     initial call to the main function is equivalent to calling the exit function with the value
1160     returned by the main function as its argument;11) reaching the } that terminates the
1161     main function returns a value of 0. If the return type is not compatible with int, the
1162     termination status returned to the host environment is unspecified.
1163     Forward references: definition of terms (7.1.1), the exit function (7.22.4.4).
1164     5.1.2.3 Program execution
1165 1   The semantic descriptions in this International Standard describe the behavior of an
1166     abstract machine in which issues of optimization are irrelevant.
1167 2   Accessing a volatile object, modifying an object, modifying a file, or calling a function
1168     that does any of those operations are all side effects,12) which are changes in the state of
1169     the execution environment. Evaluation of an expression in general includes both value
1170     computations and initiation of side effects. Value computation for an lvalue expression
1171     includes determining the identity of the designated object.
1172 3   Sequenced before is an asymmetric, transitive, pair-wise relation between evaluations
1173     executed by a single thread, which induces a partial order among those evaluations.
1174     Given any two evaluations A and B, if A is sequenced before B, then the execution of A
1175     shall precede the execution of B. (Conversely, if A is sequenced before B, then B is
1176     sequenced after A.) If A is not sequenced before or after B, then A and B are
1177     unsequenced. Evaluations A and B are indeterminately sequenced when A is sequenced
1178     either before or after B, but it is unspecified which.13) The presence of a sequence point
1179     between the evaluation of expressions A and B implies that every value computation and
1180     side effect associated with A is sequenced before every value computation and side effect
1181     associated with B. (A summary of the sequence points is given in annex C.)
1182 4   In the abstract machine, all expressions are evaluated as specified by the semantics. An
1183     actual implementation need not evaluate part of an expression if it can deduce that its
1184     value is not used and that no needed side effects are produced (including any caused by
1185
1186     11) In accordance with 6.2.4, the lifetimes of objects with automatic storage duration declared in main
1187         will have ended in the former case, even where they would not have in the latter.
1188     12) The IEC 60559 standard for binary floating-point arithmetic requires certain user-accessible status
1189         flags and control modes. Floating-point operations implicitly set the status flags; modes affect result
1190         values of floating-point operations. Implementations that support such floating-point state are
1191         required to regard changes to it as side effects -- see annex F for details. The floating-point
1192         environment library <fenv.h> provides a programming facility for indicating when these side
1193         effects matter, freeing the implementations in other cases.
1194     13) The executions of unsequenced evaluations can interleave. Indeterminately sequenced evaluations
1195         cannot interleave, but can be executed in any order.
1196
1197 [page 14]
1198
1199      calling a function or accessing a volatile object).
1200 5    When the processing of the abstract machine is interrupted by receipt of a signal, the
1201      values of objects that are neither lock-free atomic objects nor of type volatile
1202      sig_atomic_t are unspecified, and the value of any object that is modified by the
1203      handler that is neither a lock-free atomic object nor of type volatile
1204      sig_atomic_t becomes undefined.
1205 6    The least requirements on a conforming implementation are:
1206      -- Accesses to volatile objects are evaluated strictly according to the rules of the abstract
1207        machine.
1208      -- At program termination, all data written into files shall be identical to the result that
1209        execution of the program according to the abstract semantics would have produced.
1210      -- The input and output dynamics of interactive devices shall take place as specified in
1211        7.21.3. The intent of these requirements is that unbuffered or line-buffered output
1212        appear as soon as possible, to ensure that prompting messages actually appear prior to
1213        a program waiting for input.
1214      This is the observable behavior of the program.
1215 7    What constitutes an interactive device is implementation-defined.
1216 8    More stringent correspondences between abstract and actual semantics may be defined by
1217      each implementation.
1218 9    EXAMPLE 1 An implementation might define a one-to-one correspondence between abstract and actual
1219      semantics: at every sequence point, the values of the actual objects would agree with those specified by the
1220      abstract semantics. The keyword volatile would then be redundant.
1221 10   Alternatively, an implementation might perform various optimizations within each translation unit, such
1222      that the actual semantics would agree with the abstract semantics only when making function calls across
1223      translation unit boundaries. In such an implementation, at the time of each function entry and function
1224      return where the calling function and the called function are in different translation units, the values of all
1225      externally linked objects and of all objects accessible via pointers therein would agree with the abstract
1226      semantics. Furthermore, at the time of each such function entry the values of the parameters of the called
1227      function and of all objects accessible via pointers therein would agree with the abstract semantics. In this
1228      type of implementation, objects referred to by interrupt service routines activated by the signal function
1229      would require explicit specification of volatile storage, as well as other implementation-defined
1230      restrictions.
1231
1232 11   EXAMPLE 2       In executing the fragment
1233               char c1, c2;
1234               /* ... */
1235               c1 = c1 + c2;
1236      the ''integer promotions'' require that the abstract machine promote the value of each variable to int size
1237      and then add the two ints and truncate the sum. Provided the addition of two chars can be done without
1238      overflow, or with overflow wrapping silently to produce the correct result, the actual execution need only
1239      produce the same result, possibly omitting the promotions.
1240
1241 [page 15]
1242
1243 12   EXAMPLE 3       Similarly, in the fragment
1244               float f1, f2;
1245               double d;
1246               /* ... */
1247               f1 = f2 * d;
1248      the multiplication may be executed using single-precision arithmetic if the implementation can ascertain
1249      that the result would be the same as if it were executed using double-precision arithmetic (for example, if d
1250      were replaced by the constant 2.0, which has type double).
1251
1252 13   EXAMPLE 4 Implementations employing wide registers have to take care to honor appropriate
1253      semantics. Values are independent of whether they are represented in a register or in memory. For
1254      example, an implicit spilling of a register is not permitted to alter the value. Also, an explicit store and load
1255      is required to round to the precision of the storage type. In particular, casts and assignments are required to
1256      perform their specified conversion. For the fragment
1257               double d1, d2;
1258               float f;
1259               d1 = f = expression;
1260               d2 = (float) expression;
1261      the values assigned to d1 and d2 are required to have been converted to float.
1262
1263 14   EXAMPLE 5 Rearrangement for floating-point expressions is often restricted because of limitations in
1264      precision as well as range. The implementation cannot generally apply the mathematical associative rules
1265      for addition or multiplication, nor the distributive rule, because of roundoff error, even in the absence of
1266      overflow and underflow. Likewise, implementations cannot generally replace decimal constants in order to
1267      rearrange expressions. In the following fragment, rearrangements suggested by mathematical rules for real
1268      numbers are often not valid (see F.9).
1269               double x, y, z;
1270               /* ... */
1271               x = (x * y) * z;            //   not equivalent to x   *= y * z;
1272               z = (x - y) + y ;           //   not equivalent to z   = x;
1273               z = x + x * y;              //   not equivalent to z   = x * (1.0 + y);
1274               y = x / 5.0;                //   not equivalent to y   = x * 0.2;
1275
1276 15   EXAMPLE 6       To illustrate the grouping behavior of expressions, in the following fragment
1277               int a, b;
1278               /* ... */
1279               a = a + 32760 + b + 5;
1280      the expression statement behaves exactly the same as
1281               a = (((a + 32760) + b) + 5);
1282      due to the associativity and precedence of these operators. Thus, the result of the sum (a + 32760) is
1283      next added to b, and that result is then added to 5 which results in the value assigned to a. On a machine in
1284      which overflows produce an explicit trap and in which the range of values representable by an int is
1285      [-32768, +32767], the implementation cannot rewrite this expression as
1286               a = ((a + b) + 32765);
1287      since if the values for a and b were, respectively, -32754 and -15, the sum a + b would produce a trap
1288      while the original expression would not; nor can the expression be rewritten either as
1289
1290
1291 [page 16]
1292
1293               a = ((a + 32765) + b);
1294      or
1295               a = (a + (b + 32765));
1296      since the values for a and b might have been, respectively, 4 and -8 or -17 and 12. However, on a machine
1297      in which overflow silently generates some value and where positive and negative overflows cancel, the
1298      above expression statement can be rewritten by the implementation in any of the above ways because the
1299      same result will occur.
1300
1301 16   EXAMPLE 7 The grouping of an expression does not completely determine its evaluation. In the
1302      following fragment
1303               #include <stdio.h>
1304               int sum;
1305               char *p;
1306               /* ... */
1307               sum = sum * 10 - '0' + (*p++ = getchar());
1308      the expression statement is grouped as if it were written as
1309               sum = (((sum * 10) - '0') + ((*(p++)) = (getchar())));
1310      but the actual increment of p can occur at any time between the previous sequence point and the next
1311      sequence point (the ;), and the call to getchar can occur at any point prior to the need of its returned
1312      value.
1313
1314      Forward references: expressions (6.5), type qualifiers (6.7.3), statements (6.8), the
1315      signal function (7.14), files (7.21.3).
1316      5.1.2.4 Multi-threaded executions and data races
1317 1    Under a hosted implementation, a program can have more than one thread of execution
1318      (or thread) running concurrently. The execution of each thread proceeds as defined by
1319      the remainder of this standard. The execution of the entire program consists of an
1320      execution of all of its threads.14) Under a freestanding implementation, it is
1321      implementation-defined whether a program can have more than one thread of execution.
1322 2    The value of an object visible to a thread T at a particular point is the initial value of the
1323      object, a value stored in the object by T , or a value stored in the object by another thread,
1324      according to the rules below.
1325 3    NOTE 1 In some cases, there may instead be undefined behavior. Much of this section is motivated by
1326      the desire to support atomic operations with explicit and detailed visibility constraints. However, it also
1327      implicitly supports a simpler view for more restricted programs.
1328
1329 4    Two expression evaluations conflict if one of them modifies a memory location and the
1330      other one reads or modifies the same memory location.
1331
1332
1333
1334
1335      14) The execution can usually be viewed as an interleaving of all of the threads. However, some kinds of
1336          atomic operations, for example, allow executions inconsistent with a simple interleaving as described
1337          below.
1338
1339 [page 17]
1340
1341 5    The library defines a number of atomic operations (7.17) and operations on mutexes
1342      (7.25.4) that are specially identified as synchronization operations. These operations play
1343      a special role in making assignments in one thread visible to another. A synchronization
1344      operation on one or more memory locations is either an acquire operation, a release
1345      operation, both an acquire and release operation, or a consume operation. A
1346      synchronization operation without an associated memory location is a fence and can be
1347      either an acquire fence, a release fence, or both an acquire and release fence. In addition,
1348      there are relaxed atomic operations, which are not synchronization operations, and
1349      atomic read-modify-write operations, which have special characteristics.
1350 6    NOTE 2 For example, a call that acquires a mutex will perform an acquire operation on the locations
1351      composing the mutex. Correspondingly, a call that releases the same mutex will perform a release
1352      operation on those same locations. Informally, performing a release operation on A forces prior side effects
1353      on other memory locations to become visible to other threads that later perform an acquire or consume
1354      operation on A. We do not include relaxed atomic operations as synchronization operations although, like
1355      synchronization operations, they cannot contribute to data races.
1356
1357 7    All modifications to a particular atomic object M occur in some particular total order,
1358      called the modification order of M. If A and B are modifications of an atomic object M,
1359      and A happens before B, then A shall precede B in the modification order of M, which is
1360      defined below.
1361 8    NOTE 3     This states that the modification orders must respect the ''happens before'' relation.
1362
1363 9    NOTE 4 There is a separate order for each atomic object. There is no requirement that these can be
1364      combined into a single total order for all objects. In general this will be impossible since different threads
1365      may observe modifications to different variables in inconsistent orders.
1366
1367 10   A release sequence on an atomic object M is a maximal contiguous sub-sequence of side
1368      effects in the modification order of M, where the first operation is a release and every
1369      subsequent operation either is performed by the same thread that performed the release or
1370      is an atomic read-modify-write operation.
1371 11   Certain library calls synchronize with other library calls performed by another thread. In
1372      particular, an atomic operation A that performs a release operation on an object M
1373      synchronizes with an atomic operation B that performs an acquire operation on M and
1374      reads a value written by any side effect in the release sequence headed by A.
1375 12   NOTE 5 Except in the specified cases, reading a later value does not necessarily ensure visibility as
1376      described below. Such a requirement would sometimes interfere with efficient implementation.
1377
1378 13   NOTE 6 The specifications of the synchronization operations define when one reads the value written by
1379      another. For atomic variables, the definition is clear. All operations on a given mutex occur in a single total
1380      order. Each mutex acquisition ''reads the value written'' by the last mutex release.
1381
1382 14   An evaluation A carries a dependency 15) to an evaluation B if:
1383
1384
1385      15) The ''carries a dependency'' relation is a subset of the ''sequenced before'' relation, and is similarly
1386          strictly intra-thread.
1387
1388 [page 18]
1389
1390      -- the value of A is used as an operand of B, unless:
1391            o B is an invocation of the kill_dependency macro,
1392
1393            o A is the left operand of a && or || operator,
1394
1395            o A is the left operand of a ? : operator, or
1396
1397            o A is the left operand of a , operator;
1398          or
1399      -- A writes a scalar object or bit-field M, B reads from M the value written by A, and A
1400        is sequenced before B, or
1401      -- for some evaluation X, A carries a dependency to X and X carries a dependency to B.
1402 15   An evaluation A is dependency-ordered before16) an evaluation B if:
1403      -- A performs a release operation on an atomic object M, and B performs a consume
1404        operation on M and reads a value written by any side effect in the release sequence
1405        headed by A, or
1406      -- for some evaluation X, A is dependency-ordered before X and X carries a
1407        dependency to B.
1408 16   An evaluation A inter-thread happens before an evaluation B if A synchronizes with B, A
1409      is dependency-ordered before B, or, for some evaluation X:
1410      -- A synchronizes with X and X is sequenced before B,
1411      -- A is sequenced before X and X inter-thread happens before B, or
1412      -- A inter-thread happens before X and X inter-thread happens before B.
1413 17   NOTE 7 The ''inter-thread happens before'' relation describes arbitrary concatenations of ''sequenced
1414      before'', ''synchronizes with'', and ''dependency-ordered before'' relationships, with two exceptions. The
1415      first exception is that a concatenation is not permitted to end with ''dependency-ordered before'' followed
1416      by ''sequenced before''. The reason for this limitation is that a consume operation participating in a
1417      ''dependency-ordered before'' relationship provides ordering only with respect to operations to which this
1418      consume operation actually carries a dependency. The reason that this limitation applies only to the end of
1419      such a concatenation is that any subsequent release operation will provide the required ordering for a prior
1420      consume operation. The second exception is that a concatenation is not permitted to consist entirely of
1421      ''sequenced before''. The reasons for this limitation are (1) to permit ''inter-thread happens before'' to be
1422      transitively closed and (2) the ''happens before'' relation, defined below, provides for relationships
1423      consisting entirely of ''sequenced before''.
1424
1425 18   An evaluation A happens before an evaluation B if A is sequenced before B or A inter-
1426      thread happens before B.
1427
1428
1429
1430      16) The ''dependency-ordered before'' relation is analogous to the ''synchronizes with'' relation, but uses
1431          release/consume in place of release/acquire.
1432
1433 [page 19]
1434
1435 19   A visible side effect A on an object M with respect to a value computation B of M
1436      satisfies the conditions:
1437      -- A happens before B, and
1438      -- there is no other side effect X to M such that A happens before X and X happens
1439          before B.
1440      The value of a non-atomic scalar object M, as determined by evaluation B, shall be the
1441      value stored by the visible side effect A.
1442 20   NOTE 8 If there is ambiguity about which side effect to a non-atomic object is visible, then there is a data
1443      race and the behavior is undefined.
1444
1445 21   NOTE 9 This states that operations on ordinary variables are not visibly reordered. This is not actually
1446      detectable without data races, but it is necessary to ensure that data races, as defined here, and with suitable
1447      restrictions on the use of atomics, correspond to data races in a simple interleaved (sequentially consistent)
1448      execution.
1449
1450 22   The visible sequence of side effects on an atomic object M, with respect to a value
1451      computation B of M, is a maximal contiguous sub-sequence of side effects in the
1452      modification order of M, where the first side effect is visible with respect to B, and for
1453      every subsequent side effect, it is not the case that B happens before it. The value of an
1454      atomic object M, as determined by evaluation B, shall be the value stored by some
1455      operation in the visible sequence of M with respect to B. Furthermore, if a value
1456      computation A of an atomic object M happens before a value computation B of M, and
1457      the value computed by A corresponds to the value stored by side effect X, then the value
1458      computed by B shall either equal the value computed by A, or be the value stored by side
1459      effect Y , where Y follows X in the modification order of M.
1460 23   NOTE 10 This effectively disallows compiler reordering of atomic operations to a single object, even if
1461      both operations are ''relaxed'' loads. By doing so, we effectively make the ''cache coherence'' guarantee
1462      provided by most hardware available to C atomic operations.
1463
1464 24   NOTE 11 The visible sequence depends on the ''happens before'' relation, which in turn depends on the
1465      values observed by loads of atomics, which we are restricting here. The intended reading is that there must
1466      exist an association of atomic loads with modifications they observe that, together with suitably chosen
1467      modification orders and the ''happens before'' relation derived as described above, satisfy the resulting
1468      constraints as imposed here.
1469
1470 25   The execution of a program contains a data race if it contains two conflicting actions in
1471      different threads, at least one of which is not atomic, and neither happens before the
1472      other. Any such data race results in undefined behavior.
1473 26   NOTE 12 It can be shown that programs that correctly use simple mutexes and
1474      memory_order_seq_cst operations to prevent all data races, and use no other synchronization
1475      operations, behave as though the operations executed by their constituent threads were simply interleaved,
1476      with each value computation of an object being the last value stored in that interleaving. This is normally
1477      referred to as ''sequential consistency''. However, this applies only to data-race-free programs, and data-
1478      race-free programs cannot observe most program transformations that do not change single-threaded
1479      program semantics. In fact, most single-threaded program transformations continue to be allowed, since
1480      any program that behaves differently as a result must contain undefined behavior.
1481
1482 [page 20]
1483
1484 27   NOTE 13 Compiler transformations that introduce assignments to a potentially shared memory location
1485      that would not be modified by the abstract machine are generally precluded by this standard, since such an
1486      assignment might overwrite another assignment by a different thread in cases in which an abstract machine
1487      execution would not have encountered a data race. This includes implementations of data member
1488      assignment that overwrite adjacent members in separate memory locations. We also generally preclude
1489      reordering of atomic loads in cases in which the atomics in question may alias, since this may violate the
1490      "visible sequence" rules.
1491
1492 28   NOTE 14 Transformations that introduce a speculative read of a potentially shared memory location may
1493      not preserve the semantics of the program as defined in this standard, since they potentially introduce a data
1494      race. However, they are typically valid in the context of an optimizing compiler that targets a specific
1495      machine with well-defined semantics for data races. They would be invalid for a hypothetical machine that
1496      is not tolerant of races or provides hardware race detection.
1497
1498
1499
1500
1501 [page 21]
1502
1503     5.2 Environmental considerations
1504     5.2.1 Character sets
1505 1   Two sets of characters and their associated collating sequences shall be defined: the set in
1506     which source files are written (the source character set), and the set interpreted in the
1507     execution environment (the execution character set). Each set is further divided into a
1508     basic character set, whose contents are given by this subclause, and a set of zero or more
1509     locale-specific members (which are not members of the basic character set) called
1510     extended characters. The combined set is also called the extended character set. The
1511     values of the members of the execution character set are implementation-defined.
1512 2   In a character constant or string literal, members of the execution character set shall be
1513     represented by corresponding members of the source character set or by escape
1514     sequences consisting of the backslash \ followed by one or more characters. A byte with
1515     all bits set to 0, called the null character, shall exist in the basic execution character set; it
1516     is used to terminate a character string.
1517 3   Both the basic source and basic execution character sets shall have the following
1518     members: the 26 uppercase letters of the Latin alphabet
1519             A    B   C      D   E   F    G    H    I    J    K    L   M
1520             N    O   P      Q   R   S    T    U    V    W    X    Y   Z
1521     the 26 lowercase letters of the Latin alphabet
1522             a    b   c      d   e   f    g    h    i    j    k    l   m
1523             n    o   p      q   r   s    t    u    v    w    x    y   z
1524     the 10 decimal digits
1525             0    1   2      3   4   5    6    7    8    9
1526     the following 29 graphic characters
1527             !    "   #      %   &   '    (    )    *    +    ,    -   .    /    :
1528             ;    <   =      >   ?   [    \    ]    ^    _    {    |   }    ~
1529     the space character, and control characters representing horizontal tab, vertical tab, and
1530     form feed. The representation of each member of the source and execution basic
1531     character sets shall fit in a byte. In both the source and execution basic character sets, the
1532     value of each character after 0 in the above list of decimal digits shall be one greater than
1533     the value of the previous. In source files, there shall be some way of indicating the end of
1534     each line of text; this International Standard treats such an end-of-line indicator as if it
1535     were a single new-line character. In the basic execution character set, there shall be
1536     control characters representing alert, backspace, carriage return, and new line. If any
1537     other characters are encountered in a source file (except in an identifier, a character
1538     constant, a string literal, a header name, a comment, or a preprocessing token that is never
1539
1540 [page 22]
1541
1542     converted to a token), the behavior is undefined.
1543 4   A letter is an uppercase letter or a lowercase letter as defined above; in this International
1544     Standard the term does not include other characters that are letters in other alphabets.
1545 5   The universal character name construct provides a way to name other characters.
1546     Forward references: universal character names (6.4.3), character constants (6.4.4.4),
1547     preprocessing directives (6.10), string literals (6.4.5), comments (6.4.9), string (7.1.1).
1548     5.2.1.1 Trigraph sequences
1549 1   Before any other processing takes place, each occurrence of one of the following
1550     sequences of three characters (called trigraph sequences17)) is replaced with the
1551     corresponding single character.
1552            ??=      #                       ??)      ]                       ??!     |
1553            ??(      [                       ??'      ^                       ??>     }
1554            ??/      \                       ??<      {                       ??-     ~
1555     No other trigraph sequences exist. Each ? that does not begin one of the trigraphs listed
1556     above is not changed.
1557 2   EXAMPLE 1
1558               ??=define arraycheck(a, b) a??(b??) ??!??! b??(a??)
1559     becomes
1560               #define arraycheck(a, b) a[b] || b[a]
1561
1562 3   EXAMPLE 2      The following source line
1563               printf("Eh???/n");
1564     becomes (after replacement of the trigraph sequence ??/)
1565               printf("Eh?\n");
1566
1567     5.2.1.2 Multibyte characters
1568 1   The source character set may contain multibyte characters, used to represent members of
1569     the extended character set. The execution character set may also contain multibyte
1570     characters, which need not have the same encoding as for the source character set. For
1571     both character sets, the following shall hold:
1572     -- The basic character set shall be present and each character shall be encoded as a
1573       single byte.
1574     -- The presence, meaning, and representation of any additional members is locale-
1575       specific.
1576
1577     17) The trigraph sequences enable the input of characters that are not defined in the Invariant Code Set as
1578         described in ISO/IEC 646, which is a subset of the seven-bit US ASCII code set.
1579
1580 [page 23]
1581
1582     -- A multibyte character set may have a state-dependent encoding, wherein each
1583       sequence of multibyte characters begins in an initial shift state and enters other
1584       locale-specific shift states when specific multibyte characters are encountered in the
1585       sequence. While in the initial shift state, all single-byte characters retain their usual
1586       interpretation and do not alter the shift state. The interpretation for subsequent bytes
1587       in the sequence is a function of the current shift state.
1588     -- A byte with all bits zero shall be interpreted as a null character independent of shift
1589       state. Such a byte shall not occur as part of any other multibyte character.
1590 2   For source files, the following shall hold:
1591     -- An identifier, comment, string literal, character constant, or header name shall begin
1592       and end in the initial shift state.
1593     -- An identifier, comment, string literal, character constant, or header name shall consist
1594       of a sequence of valid multibyte characters.
1595     5.2.2 Character display semantics
1596 1   The active position is that location on a display device where the next character output by
1597     the fputc function would appear. The intent of writing a printing character (as defined
1598     by the isprint function) to a display device is to display a graphic representation of
1599     that character at the active position and then advance the active position to the next
1600     position on the current line. The direction of writing is locale-specific. If the active
1601     position is at the final position of a line (if there is one), the behavior of the display device
1602     is unspecified.
1603 2   Alphabetic escape sequences representing nongraphic characters in the execution
1604     character set are intended to produce actions on display devices as follows:
1605     \a (alert) Produces an audible or visible alert without changing the active position.
1606     \b (backspace) Moves the active position to the previous position on the current line. If
1607        the active position is at the initial position of a line, the behavior of the display
1608        device is unspecified.
1609     \f ( form feed) Moves the active position to the initial position at the start of the next
1610        logical page.
1611     \n (new line) Moves the active position to the initial position of the next line.
1612     \r (carriage return) Moves the active position to the initial position of the current line.
1613     \t (horizontal tab) Moves the active position to the next horizontal tabulation position
1614        on the current line. If the active position is at or past the last defined horizontal
1615        tabulation position, the behavior of the display device is unspecified.
1616     \v (vertical tab) Moves the active position to the initial position of the next vertical
1617        tabulation position. If the active position is at or past the last defined vertical
1618 [page 24]
1619
1620          tabulation position, the behavior of the display device is unspecified.
1621 3   Each of these escape sequences shall produce a unique implementation-defined value
1622     which can be stored in a single char object. The external representations in a text file
1623     need not be identical to the internal representations, and are outside the scope of this
1624     International Standard.
1625     Forward references: the isprint function (7.4.1.8), the fputc function (7.21.7.3).
1626     5.2.3 Signals and interrupts
1627 1   Functions shall be implemented such that they may be interrupted at any time by a signal,
1628     or may be called by a signal handler, or both, with no alteration to earlier, but still active,
1629     invocations' control flow (after the interruption), function return values, or objects with
1630     automatic storage duration. All such objects shall be maintained outside the function
1631     image (the instructions that compose the executable representation of a function) on a
1632     per-invocation basis.
1633     5.2.4 Environmental limits
1634 1   Both the translation and execution environments constrain the implementation of
1635     language translators and libraries. The following summarizes the language-related
1636     environmental limits on a conforming implementation; the library-related limits are
1637     discussed in clause 7.
1638     5.2.4.1 Translation limits
1639 1   The implementation shall be able to translate and execute at least one program that
1640     contains at least one instance of every one of the following limits:18)
1641     -- 127 nesting levels of blocks
1642     -- 63 nesting levels of conditional inclusion
1643     -- 12 pointer, array, and function declarators (in any combinations) modifying an
1644       arithmetic, structure, union, or void type in a declaration
1645     -- 63 nesting levels of parenthesized declarators within a full declarator
1646     -- 63 nesting levels of parenthesized expressions within a full expression
1647     -- 63 significant initial characters in an internal identifier or a macro name (each
1648       universal character name or extended source character is considered a single
1649       character)
1650     -- 31 significant initial characters in an external identifier (each universal character name
1651       specifying a short identifier of 0000FFFF or less is considered 6 characters, each
1652
1653
1654     18) Implementations should avoid imposing fixed translation limits whenever possible.
1655
1656 [page 25]
1657
1658          universal character name specifying a short identifier of 00010000 or more is
1659          considered 10 characters, and each extended source character is considered the same
1660          number of characters as the corresponding universal character name, if any)19)
1661     -- 4095 external identifiers in one translation unit
1662     -- 511 identifiers with block scope declared in one block
1663     -- 4095 macro identifiers simultaneously defined in one preprocessing translation unit
1664     -- 127 parameters in one function definition
1665     -- 127 arguments in one function call
1666     -- 127 parameters in one macro definition
1667     -- 127 arguments in one macro invocation
1668     -- 4095 characters in a logical source line
1669     -- 4095 characters in a string literal (after concatenation)
1670     -- 65535 bytes in an object (in a hosted environment only)
1671     -- 15 nesting levels for #included files
1672     -- 1023 case labels for a switch statement (excluding those for any nested switch
1673       statements)
1674     -- 1023 members in a single structure or union
1675     -- 1023 enumeration constants in a single enumeration
1676     -- 63 levels of nested structure or union definitions in a single struct-declaration-list
1677     5.2.4.2 Numerical limits
1678 1   An implementation is required to document all the limits specified in this subclause,
1679     which are specified in the headers <limits.h> and <float.h>. Additional limits are
1680     specified in <stdint.h>.
1681     Forward references: integer types <stdint.h> (7.20).
1682     5.2.4.2.1 Sizes of integer types <limits.h>
1683 1   The values given below shall be replaced by constant expressions suitable for use in #if
1684     preprocessing directives. Moreover, except for CHAR_BIT and MB_LEN_MAX, the
1685     following shall be replaced by expressions that have the same type as would an
1686     expression that is an object of the corresponding type converted according to the integer
1687     promotions. Their implementation-defined values shall be equal or greater in magnitude
1688
1689
1690     19) See ''future language directions'' (6.11.3).
1691
1692 [page 26]
1693
1694 (absolute value) to those shown, with the same sign.
1695 -- number of bits for smallest object that is not a bit-field (byte)
1696   CHAR_BIT                                            8
1697 -- minimum value for an object of type signed char
1698   SCHAR_MIN                                -127 // -(27 - 1)
1699 -- maximum value for an object of type signed char
1700   SCHAR_MAX                                +127 // 27 - 1
1701 -- maximum value for an object of type unsigned char
1702   UCHAR_MAX                                 255 // 28 - 1
1703 -- minimum value for an object of type char
1704   CHAR_MIN                               see below
1705 -- maximum value for an object of type char
1706   CHAR_MAX                              see below
1707 -- maximum number of bytes in a multibyte character, for any supported locale
1708   MB_LEN_MAX                                    1
1709 -- minimum value for an object of type short int
1710   SHRT_MIN                               -32767 // -(215 - 1)
1711 -- maximum value for an object of type short int
1712   SHRT_MAX                               +32767 // 215 - 1
1713 -- maximum value for an object of type unsigned short int
1714   USHRT_MAX                               65535 // 216 - 1
1715 -- minimum value for an object of type int
1716   INT_MIN                                 -32767 // -(215 - 1)
1717 -- maximum value for an object of type int
1718   INT_MAX                                +32767 // 215 - 1
1719 -- maximum value for an object of type unsigned int
1720   UINT_MAX                                65535 // 216 - 1
1721 -- minimum value for an object of type long int
1722   LONG_MIN                         -2147483647 // -(231 - 1)
1723 -- maximum value for an object of type long int
1724   LONG_MAX                         +2147483647 // 231 - 1
1725 -- maximum value for an object of type unsigned long int
1726   ULONG_MAX                         4294967295 // 232 - 1
1727
1728
1729 [page 27]
1730
1731     -- minimum value for an object of type long long int
1732       LLONG_MIN          -9223372036854775807 // -(263 - 1)
1733     -- maximum value for an object of type long long int
1734       LLONG_MAX          +9223372036854775807 // 263 - 1
1735     -- maximum value for an object of type unsigned long long int
1736       ULLONG_MAX         18446744073709551615 // 264 - 1
1737 2   If the value of an object of type char is treated as a signed integer when used in an
1738     expression, the value of CHAR_MIN shall be the same as that of SCHAR_MIN and the
1739     value of CHAR_MAX shall be the same as that of SCHAR_MAX. Otherwise, the value of
1740     CHAR_MIN shall be 0 and the value of CHAR_MAX shall be the same as that of
1741     UCHAR_MAX.20) The value UCHAR_MAX shall equal 2CHAR_BIT - 1.
1742     Forward references: representations of types (6.2.6), conditional inclusion (6.10.1).
1743     5.2.4.2.2 Characteristics of floating types <float.h>
1744 1   The characteristics of floating types are defined in terms of a model that describes a
1745     representation of floating-point numbers and values that provide information about an
1746     implementation's floating-point arithmetic.21) The following parameters are used to
1747     define the model for each floating-point type:
1748            s          sign ((+-)1)
1749            b          base or radix of exponent representation (an integer > 1)
1750            e          exponent (an integer between a minimum emin and a maximum emax )
1751            p          precision (the number of base-b digits in the significand)
1752             fk        nonnegative integers less than b (the significand digits)
1753 2   A floating-point number (x) is defined by the following model:
1754                        p
1755            x = sb e   (Sum) f k b-k ,
1756                       k=1
1757                                     emin <= e <= emax
1758
1759 3   In addition to normalized floating-point numbers ( f 1 > 0 if x != 0), floating types may be
1760     able to contain other kinds of floating-point numbers, such as subnormal floating-point
1761     numbers (x != 0, e = emin , f 1 = 0) and unnormalized floating-point numbers (x != 0,
1762     e > emin , f 1 = 0), and values that are not floating-point numbers, such as infinities and
1763     NaNs. A NaN is an encoding signifying Not-a-Number. A quiet NaN propagates
1764     through almost every arithmetic operation without raising a floating-point exception; a
1765     signaling NaN generally raises a floating-point exception when occurring as an
1766
1767
1768     20) See 6.2.5.
1769     21) The floating-point model is intended to clarify the description of each floating-point characteristic and
1770         does not require the floating-point arithmetic of the implementation to be identical.
1771
1772 [page 28]
1773
1774     arithmetic operand.22)
1775 4   An implementation may give zero and values that are not floating-point numbers (such as
1776     infinities and NaNs) a sign or may leave them unsigned. Wherever such values are
1777     unsigned, any requirement in this International Standard to retrieve the sign shall produce
1778     an unspecified sign, and any requirement to set the sign shall be ignored.
1779 5   The minimum range of representable values for a floating type is the most negative finite
1780     floating-point number representable in that type through the most positive finite floating-
1781     point number representable in that type. In addition, if negative infinity is representable
1782     in a type, the range of that type is extended to all negative real numbers; likewise, if
1783     positive infinity is representable in a type, the range of that type is extended to all positive
1784     real numbers.
1785 6   The accuracy of the floating-point operations (+, -, *, /) and of the library functions in
1786     <math.h> and <complex.h> that return floating-point results is implementation-
1787     defined, as is the accuracy of the conversion between floating-point internal
1788     representations and string representations performed by the library functions in
1789     <stdio.h>, <stdlib.h>, and <wchar.h>. The implementation may state that the
1790     accuracy is unknown.
1791 7   All integer values in the <float.h> header, except FLT_ROUNDS, shall be constant
1792     expressions suitable for use in #if preprocessing directives; all floating values shall be
1793     constant expressions. All except DECIMAL_DIG, FLT_EVAL_METHOD, FLT_RADIX,
1794     and FLT_ROUNDS have separate names for all three floating-point types. The floating-
1795     point model representation is provided for all values except FLT_EVAL_METHOD and
1796     FLT_ROUNDS.
1797 8   The rounding mode for floating-point addition is characterized by the implementation-
1798     defined value of FLT_ROUNDS:23)
1799           -1      indeterminable
1800            0      toward zero
1801            1      to nearest
1802            2      toward positive infinity
1803            3      toward negative infinity
1804     All other values for FLT_ROUNDS characterize implementation-defined rounding
1805     behavior.
1806
1807
1808     22) IEC 60559:1989 specifies quiet and signaling NaNs. For implementations that do not support
1809         IEC 60559:1989, the terms quiet NaN and signaling NaN are intended to apply to encodings with
1810         similar behavior.
1811     23) Evaluation of FLT_ROUNDS correctly reflects any execution-time change of rounding mode through
1812         the function fesetround in <fenv.h>.
1813
1814 [page 29]
1815
1816 9    Except for assignment and cast (which remove all extra range and precision), the values
1817      yielded by operators with floating operands and values subject to the usual arithmetic
1818      conversions and of floating constants are evaluated to a format whose range and precision
1819      may be greater than required by the type. The use of evaluation formats is characterized
1820      by the implementation-defined value of FLT_EVAL_METHOD:24)
1821             -1         indeterminable;
1822               0        evaluate all operations and constants just to the range and precision of the
1823                        type;
1824               1        evaluate operations and constants of type float and double to the
1825                        range and precision of the double type, evaluate long double
1826                        operations and constants to the range and precision of the long double
1827                        type;
1828               2        evaluate all operations and constants to the range and precision of the
1829                        long double type.
1830      All other negative values for FLT_EVAL_METHOD characterize implementation-defined
1831      behavior.
1832 10   The presence or absence of subnormal numbers is characterized by the implementation-
1833      defined     values     of    FLT_HAS_SUBNORM,          DBL_HAS_SUBNORM,           and
1834      LDBL_HAS_SUBNORM:
1835             -1       indeterminable25)
1836              0       absent26) (type does not support subnormal numbers)
1837              1       present (type does support subnormal numbers)
1838 11   The values given in the following list shall be replaced by constant expressions with
1839      implementation-defined values that are greater or equal in magnitude (absolute value) to
1840      those shown, with the same sign:
1841      -- radix of exponent representation, b
1842        FLT_RADIX                                                    2
1843
1844
1845
1846
1847      24) The evaluation method determines evaluation formats of expressions involving all floating types, not
1848          just real types. For example, if FLT_EVAL_METHOD is 1, then the product of two float
1849          _Complex operands is represented in the double _Complex format, and its parts are evaluated to
1850          double.
1851      25) Characterization as indeterminable is intended if floating-point operations do not consistently interpret
1852          subnormal representations as zero, nor as nonzero.
1853      26) Characterization as absent is intended if no floating-point operations produce subnormal results from
1854          non-subnormal inputs, even if the type format includes representations of subnormal numbers.
1855
1856 [page 30]
1857
1858 -- number of base-FLT_RADIX digits in the floating-point significand, p
1859    FLT_MANT_DIG
1860    DBL_MANT_DIG
1861    LDBL_MANT_DIG
1862 -- number of decimal digits, n, such that any floating-point number with p radix b digits
1863   can be rounded to a floating-point number with n decimal digits and back again
1864   without change to the value,
1865        { p log10 b        if b is a power of 10
1866        {
1867        { [^1 + p log10 b^] otherwise
1868    FLT_DECIMAL_DIG                                   6
1869    DBL_DECIMAL_DIG                                  10
1870    LDBL_DECIMAL_DIG                                 10
1871 -- number of decimal digits, n, such that any floating-point number in the widest
1872   supported floating type with pmax radix b digits can be rounded to a floating-point
1873   number with n decimal digits and back again without change to the value,
1874        { pmax log10 b       if b is a power of 10
1875        {
1876        { [^1 + pmax log10 b^] otherwise
1877    DECIMAL_DIG                                     10
1878 -- number of decimal digits, q, such that any floating-point number with q decimal digits
1879   can be rounded into a floating-point number with p radix b digits and back again
1880   without change to the q decimal digits,
1881        { p log10 b          if b is a power of 10
1882        {
1883        { [_( p - 1) log10 b_] otherwise
1884    FLT_DIG                                          6
1885    DBL_DIG                                         10
1886    LDBL_DIG                                        10
1887 -- minimum negative integer such that FLT_RADIX raised to one less than that power is
1888   a normalized floating-point number, emin
1889    FLT_MIN_EXP
1890    DBL_MIN_EXP
1891    LDBL_MIN_EXP
1892
1893
1894
1895
1896 [page 31]
1897
1898      -- minimum negative integer such that 10 raised to that power is in the range of
1899        normalized floating-point numbers, [^log10 b emin -1 ^]
1900                                          [                  ]
1901        FLT_MIN_10_EXP                                 -37
1902        DBL_MIN_10_EXP                                 -37
1903        LDBL_MIN_10_EXP                                -37
1904      -- maximum integer such that FLT_RADIX raised to one less than that power is a
1905        representable finite floating-point number, emax
1906           FLT_MAX_EXP
1907           DBL_MAX_EXP
1908           LDBL_MAX_EXP
1909      -- maximum integer such that 10 raised to that power is in the range of representable
1910        finite floating-point numbers, [_log10 ((1 - b- p )b emax )_]
1911           FLT_MAX_10_EXP                               +37
1912           DBL_MAX_10_EXP                               +37
1913           LDBL_MAX_10_EXP                              +37
1914 12   The values given in the following list shall be replaced by constant expressions with
1915      implementation-defined values that are greater than or equal to those shown:
1916      -- maximum representable finite floating-point number, (1 - b- p )b emax
1917           FLT_MAX                                   1E+37
1918           DBL_MAX                                   1E+37
1919           LDBL_MAX                                  1E+37
1920 13   The values given in the following list shall be replaced by constant expressions with
1921      implementation-defined (positive) values that are less than or equal to those shown:
1922      -- the difference between 1 and the least value greater than 1 that is representable in the
1923        given floating point type, b1- p
1924           FLT_EPSILON                                1E-5
1925           DBL_EPSILON                                1E-9
1926           LDBL_EPSILON                               1E-9
1927      -- minimum normalized positive floating-point number, b emin -1
1928           FLT_MIN                                   1E-37
1929           DBL_MIN                                   1E-37
1930           LDBL_MIN                                  1E-37
1931
1932
1933
1934
1935 [page 32]
1936
1937      -- minimum positive floating-point number27)
1938          FLT_TRUE_MIN                                       1E-37
1939          DBL_TRUE_MIN                                       1E-37
1940          LDBL_TRUE_MIN                                      1E-37
1941      Recommended practice
1942 14   Conversion from (at least) double to decimal with DECIMAL_DIG digits and back
1943      should be the identity function.
1944 15   EXAMPLE 1 The following describes an artificial floating-point representation that meets the minimum
1945      requirements of this International Standard, and the appropriate values in a <float.h> header for type
1946      float:
1947                         6
1948            x = s16e    (Sum) f k 16-k ,
1949                        k=1
1950                                        -31 <= e <= +32
1951
1952              FLT_RADIX                                    16
1953              FLT_MANT_DIG                                  6
1954              FLT_EPSILON                     9.53674316E-07F
1955              FLT_DECIMAL_DIG                               9
1956              FLT_DIG                                       6
1957              FLT_MIN_EXP                                 -31
1958              FLT_MIN                         2.93873588E-39F
1959              FLT_MIN_10_EXP                              -38
1960              FLT_MAX_EXP                                 +32
1961              FLT_MAX                         3.40282347E+38F
1962              FLT_MAX_10_EXP                              +38
1963
1964 16   EXAMPLE 2 The following describes floating-point representations that also meet the requirements for
1965      single-precision and double-precision numbers in IEC 60559,28) and the appropriate values in a
1966      <float.h> header for types float and double:
1967                        24
1968            x f = s2e   (Sum) f k 2-k ,
1969                        k=1
1970                                       -125 <= e <= +128
1971
1972                        53
1973            x d = s2e   (Sum) f k 2-k ,
1974                        k=1
1975                                       -1021 <= e <= +1024
1976
1977              FLT_RADIX                                     2
1978              DECIMAL_DIG                                  17
1979              FLT_MANT_DIG                                 24
1980              FLT_EPSILON                     1.19209290E-07F // decimal constant
1981              FLT_EPSILON                            0X1P-23F // hex constant
1982              FLT_DECIMAL_DIG                               9
1983
1984
1985      27) If the presence or absence of subnormal numbers is indeterminable, then the value is intended to be a
1986          positive number no greater than the minimum normalized positive number for the type.
1987      28) The floating-point model in that standard sums powers of b from zero, so the values of the exponent
1988          limits are one less than shown here.
1989
1990 [page 33]
1991
1992         FLT_DIG                             6
1993         FLT_MIN_EXP                      -125
1994         FLT_MIN               1.17549435E-38F               //   decimal constant
1995         FLT_MIN                     0X1P-126F               //   hex constant
1996         FLT_TRUE_MIN          1.40129846E-45F               //   decimal constant
1997         FLT_TRUE_MIN                0X1P-149F               //   hex constant
1998         FLT_HAS_SUBNORM                     1
1999         FLT_MIN_10_EXP                    -37
2000         FLT_MAX_EXP                      +128
2001         FLT_MAX               3.40282347E+38F               // decimal constant
2002         FLT_MAX               0X1.fffffeP127F               // hex constant
2003         FLT_MAX_10_EXP                    +38
2004         DBL_MANT_DIG                       53
2005         DBL_EPSILON    2.2204460492503131E-16               // decimal constant
2006         DBL_EPSILON                   0X1P-52               // hex constant
2007         DBL_DECIMAL_DIG                    17
2008         DBL_DIG                            15
2009         DBL_MIN_EXP                     -1021
2010         DBL_MIN      2.2250738585072014E-308                //   decimal constant
2011         DBL_MIN                     0X1P-1022               //   hex constant
2012         DBL_TRUE_MIN 4.9406564584124654E-324                //   decimal constant
2013         DBL_TRUE_MIN                0X1P-1074               //   hex constant
2014         DBL_HAS_SUBNORM                     1
2015         DBL_MIN_10_EXP                   -307
2016         DBL_MAX_EXP                     +1024
2017         DBL_MAX      1.7976931348623157E+308                // decimal constant
2018         DBL_MAX        0X1.fffffffffffffP1023               // hex constant
2019         DBL_MAX_10_EXP                   +308
2020 If a type wider than double were supported, then DECIMAL_DIG would be greater than 17. For
2021 example, if the widest type were to use the minimal-width IEC 60559 double-extended format (64 bits of
2022 precision), then DECIMAL_DIG would be 21.
2023
2024 Forward references:        conditional inclusion (6.10.1), complex arithmetic
2025 <complex.h> (7.3), extended multibyte and wide character utilities <wchar.h>
2026 (7.28), floating-point environment <fenv.h> (7.6), general utilities <stdlib.h>
2027 (7.22), input/output <stdio.h> (7.21), mathematics <math.h> (7.12).
2028
2029
2030
2031
2032 [page 34]
2033
2034
2035     6. Language
2036     6.1 Notation
2037 1   In the syntax notation used in this clause, syntactic categories (nonterminals) are
2038     indicated by italic type, and literal words and character set members (terminals) by bold
2039     type. A colon (:) following a nonterminal introduces its definition. Alternative
2040     definitions are listed on separate lines, except when prefaced by the words ''one of''. An
2041     optional symbol is indicated by the subscript ''opt'', so that
2042              { expressionopt }
2043     indicates an optional expression enclosed in braces.
2044 2   When syntactic categories are referred to in the main text, they are not italicized and
2045     words are separated by spaces instead of hyphens.
2046 3   A summary of the language syntax is given in annex A.
2047     6.2 Concepts
2048     6.2.1 Scopes of identifiers
2049 1   An identifier can denote an object; a function; a tag or a member of a structure, union, or
2050     enumeration; a typedef name; a label name; a macro name; or a macro parameter. The
2051     same identifier can denote different entities at different points in the program. A member
2052     of an enumeration is called an enumeration constant. Macro names and macro
2053     parameters are not considered further here, because prior to the semantic phase of
2054     program translation any occurrences of macro names in the source file are replaced by the
2055     preprocessing token sequences that constitute their macro definitions.
2056 2   For each different entity that an identifier designates, the identifier is visible (i.e., can be
2057     used) only within a region of program text called its scope. Different entities designated
2058     by the same identifier either have different scopes, or are in different name spaces. There
2059     are four kinds of scopes: function, file, block, and function prototype. (A function
2060     prototype is a declaration of a function that declares the types of its parameters.)
2061 3   A label name is the only kind of identifier that has function scope. It can be used (in a
2062     goto statement) anywhere in the function in which it appears, and is declared implicitly
2063     by its syntactic appearance (followed by a : and a statement).
2064 4   Every other identifier has scope determined by the placement of its declaration (in a
2065     declarator or type specifier). If the declarator or type specifier that declares the identifier
2066     appears outside of any block or list of parameters, the identifier has file scope, which
2067     terminates at the end of the translation unit. If the declarator or type specifier that
2068     declares the identifier appears inside a block or within the list of parameter declarations in
2069     a function definition, the identifier has block scope, which terminates at the end of the
2070     associated block. If the declarator or type specifier that declares the identifier appears
2071
2072 [page 35]
2073
2074     within the list of parameter declarations in a function prototype (not part of a function
2075     definition), the identifier has function prototype scope, which terminates at the end of the
2076     function declarator. If an identifier designates two different entities in the same name
2077     space, the scopes might overlap. If so, the scope of one entity (the inner scope) will end
2078     strictly before the scope of the other entity (the outer scope). Within the inner scope, the
2079     identifier designates the entity declared in the inner scope; the entity declared in the outer
2080     scope is hidden (and not visible) within the inner scope.
2081 5   Unless explicitly stated otherwise, where this International Standard uses the term
2082     ''identifier'' to refer to some entity (as opposed to the syntactic construct), it refers to the
2083     entity in the relevant name space whose declaration is visible at the point the identifier
2084     occurs.
2085 6   Two identifiers have the same scope if and only if their scopes terminate at the same
2086     point.
2087 7   Structure, union, and enumeration tags have scope that begins just after the appearance of
2088     the tag in a type specifier that declares the tag. Each enumeration constant has scope that
2089     begins just after the appearance of its defining enumerator in an enumerator list. Any
2090     other identifier has scope that begins just after the completion of its declarator.
2091 8   As a special case, a type name (which is not a declaration of an identifier) is considered to
2092     have a scope that begins just after the place within the type name where the omitted
2093     identifier would appear were it not omitted.
2094     Forward references: declarations (6.7), function calls (6.5.2.2), function definitions
2095     (6.9.1), identifiers (6.4.2), macro replacement (6.10.3), name spaces of identifiers (6.2.3),
2096     source file inclusion (6.10.2), statements (6.8).
2097     6.2.2 Linkages of identifiers
2098 1   An identifier declared in different scopes or in the same scope more than once can be
2099     made to refer to the same object or function by a process called linkage.29) There are
2100     three kinds of linkage: external, internal, and none.
2101 2   In the set of translation units and libraries that constitutes an entire program, each
2102     declaration of a particular identifier with external linkage denotes the same object or
2103     function. Within one translation unit, each declaration of an identifier with internal
2104     linkage denotes the same object or function. Each declaration of an identifier with no
2105     linkage denotes a unique entity.
2106 3   If the declaration of a file scope identifier for an object or a function contains the storage-
2107     class specifier static, the identifier has internal linkage.30)
2108
2109
2110
2111     29) There is no linkage between different identifiers.
2112
2113 [page 36]
2114
2115 4   For an identifier declared with the storage-class specifier extern in a scope in which a
2116     prior declaration of that identifier is visible,31) if the prior declaration specifies internal or
2117     external linkage, the linkage of the identifier at the later declaration is the same as the
2118     linkage specified at the prior declaration. If no prior declaration is visible, or if the prior
2119     declaration specifies no linkage, then the identifier has external linkage.
2120 5   If the declaration of an identifier for a function has no storage-class specifier, its linkage
2121     is determined exactly as if it were declared with the storage-class specifier extern. If
2122     the declaration of an identifier for an object has file scope and no storage-class specifier,
2123     its linkage is external.
2124 6   The following identifiers have no linkage: an identifier declared to be anything other than
2125     an object or a function; an identifier declared to be a function parameter; a block scope
2126     identifier for an object declared without the storage-class specifier extern.
2127 7   If, within a translation unit, the same identifier appears with both internal and external
2128     linkage, the behavior is undefined.
2129     Forward references: declarations (6.7), expressions (6.5), external definitions (6.9),
2130     statements (6.8).
2131     6.2.3 Name spaces of identifiers
2132 1   If more than one declaration of a particular identifier is visible at any point in a
2133     translation unit, the syntactic context disambiguates uses that refer to different entities.
2134     Thus, there are separate name spaces for various categories of identifiers, as follows:
2135     -- label names (disambiguated by the syntax of the label declaration and use);
2136     -- the tags of structures, unions, and enumerations (disambiguated by following any32)
2137       of the keywords struct, union, or enum);
2138     -- the members of structures or unions; each structure or union has a separate name
2139       space for its members (disambiguated by the type of the expression used to access the
2140       member via the . or -> operator);
2141     -- all other identifiers, called ordinary identifiers (declared in ordinary declarators or as
2142       enumeration constants).
2143     Forward references: enumeration specifiers (6.7.2.2), labeled statements (6.8.1),
2144     structure and union specifiers (6.7.2.1), structure and union members (6.5.2.3), tags
2145     (6.7.2.3), the goto statement (6.8.6.1).
2146
2147     30) A function declaration can contain the storage-class specifier static only if it is at file scope; see
2148         6.7.1.
2149     31) As specified in 6.2.1, the later declaration might hide the prior declaration.
2150     32) There is only one name space for tags even though three are possible.
2151
2152 [page 37]
2153
2154     6.2.4 Storage durations of objects
2155 1   An object has a storage duration that determines its lifetime. There are four storage
2156     durations: static, thread, automatic, and allocated. Allocated storage is described in
2157     7.22.3.
2158 2   The lifetime of an object is the portion of program execution during which storage is
2159     guaranteed to be reserved for it. An object exists, has a constant address,33) and retains
2160     its last-stored value throughout its lifetime.34) If an object is referred to outside of its
2161     lifetime, the behavior is undefined. The value of a pointer becomes indeterminate when
2162     the object it points to (or just past) reaches the end of its lifetime.
2163 3   An object whose identifier is declared without the storage-class specifier
2164     _Thread_local, and either with external or internal linkage or with the storage-class
2165     specifier static, has static storage duration. Its lifetime is the entire execution of the
2166     program and its stored value is initialized only once, prior to program startup.
2167 4   An object whose identifier is declared with the storage-class specifier _Thread_local
2168     has thread storage duration. Its lifetime is the entire execution of the thread for which it
2169     is created, and its stored value is initialized when the thread is started. There is a distinct
2170     object per thread, and use of the declared name in an expression refers to the object
2171     associated with the thread evaluating the expression. The result of attempting to
2172     indirectly access an object with thread storage duration from a thread other than the one
2173     with which the object is associated is implementation-defined.
2174 5   An object whose identifier is declared with no linkage and without the storage-class
2175     specifier static has automatic storage duration, as do some compound literals. The
2176     result of attempting to indirectly access an object with automatic storage duration from a
2177     thread other than the one with which the object is associated is implementation-defined.
2178 6   For such an object that does not have a variable length array type, its lifetime extends
2179     from entry into the block with which it is associated until execution of that block ends in
2180     any way. (Entering an enclosed block or calling a function suspends, but does not end,
2181     execution of the current block.) If the block is entered recursively, a new instance of the
2182     object is created each time. The initial value of the object is indeterminate. If an
2183     initialization is specified for the object, it is performed each time the declaration or
2184     compound literal is reached in the execution of the block; otherwise, the value becomes
2185     indeterminate each time the declaration is reached.
2186
2187
2188
2189     33) The term ''constant address'' means that two pointers to the object constructed at possibly different
2190         times will compare equal. The address may be different during two different executions of the same
2191         program.
2192     34) In the case of a volatile object, the last store need not be explicit in the program.
2193
2194 [page 38]
2195
2196 7   For such an object that does have a variable length array type, its lifetime extends from
2197     the declaration of the object until execution of the program leaves the scope of the
2198     declaration.35) If the scope is entered recursively, a new instance of the object is created
2199     each time. The initial value of the object is indeterminate.
2200 8   A non-lvalue expression with structure or union type, where the structure or union
2201     contains a member with array type (including, recursively, members of all contained
2202     structures and unions) refers to an object with automatic storage duration and temporary
2203     lifetime.36) Its lifetime begins when the expression is evaluated and its initial value is the
2204     value of the expression. Its lifetime ends when the evaluation of the containing full
2205     expression or full declarator ends. Any attempt to modify an object with temporary
2206     lifetime results in undefined behavior.
2207     Forward references: array declarators (6.7.6.2), compound literals (6.5.2.5), declarators
2208     (6.7.6), function calls (6.5.2.2), initialization (6.7.9), statements (6.8).
2209     6.2.5 Types
2210 1   The meaning of a value stored in an object or returned by a function is determined by the
2211     type of the expression used to access it. (An identifier declared to be an object is the
2212     simplest such expression; the type is specified in the declaration of the identifier.) Types
2213     are partitioned into object types (types that describe objects) and function types (types
2214     that describe functions). At various points within a translation unit an object type may be
2215     incomplete (lacking sufficient information to determine the size of objects of that type) or
2216     complete (having sufficient information).37)
2217 2   An object declared as type _Bool is large enough to store the values 0 and 1.
2218 3   An object declared as type char is large enough to store any member of the basic
2219     execution character set. If a member of the basic execution character set is stored in a
2220     char object, its value is guaranteed to be nonnegative. If any other character is stored in
2221     a char object, the resulting value is implementation-defined but shall be within the range
2222     of values that can be represented in that type.
2223 4   There are five standard signed integer types, designated as signed char, short
2224     int, int, long int, and long long int. (These and other types may be
2225     designated in several additional ways, as described in 6.7.2.) There may also be
2226     implementation-defined extended signed integer types.38) The standard and extended
2227     signed integer types are collectively called signed integer types.39)
2228
2229     35) Leaving the innermost block containing the declaration, or jumping to a point in that block or an
2230         embedded block prior to the declaration, leaves the scope of the declaration.
2231     36) The address of such an object is taken implicitly when an array member is accessed.
2232     37) A type may be incomplete or complete throughout an entire translation unit, or it may change states at
2233         different points within a translation unit.
2234
2235 [page 39]
2236
2237 5    An object declared as type signed char occupies the same amount of storage as a
2238      ''plain'' char object. A ''plain'' int object has the natural size suggested by the
2239      architecture of the execution environment (large enough to contain any value in the range
2240      INT_MIN to INT_MAX as defined in the header <limits.h>).
2241 6    For each of the signed integer types, there is a corresponding (but different) unsigned
2242      integer type (designated with the keyword unsigned) that uses the same amount of
2243      storage (including sign information) and has the same alignment requirements. The type
2244      _Bool and the unsigned integer types that correspond to the standard signed integer
2245      types are the standard unsigned integer types. The unsigned integer types that
2246      correspond to the extended signed integer types are the extended unsigned integer types.
2247      The standard and extended unsigned integer types are collectively called unsigned integer
2248      types.40)
2249 7    The standard signed integer types and standard unsigned integer types are collectively
2250      called the standard integer types, the extended signed integer types and extended
2251      unsigned integer types are collectively called the extended integer types.
2252 8    For any two integer types with the same signedness and different integer conversion rank
2253      (see 6.3.1.1), the range of values of the type with smaller integer conversion rank is a
2254      subrange of the values of the other type.
2255 9    The range of nonnegative values of a signed integer type is a subrange of the
2256      corresponding unsigned integer type, and the representation of the same value in each
2257      type is the same.41) A computation involving unsigned operands can never overflow,
2258      because a result that cannot be represented by the resulting unsigned integer type is
2259      reduced modulo the number that is one greater than the largest value that can be
2260      represented by the resulting type.
2261 10   There are three real floating types, designated as float, double, and long
2262      double.42) The set of values of the type float is a subset of the set of values of the
2263      type double; the set of values of the type double is a subset of the set of values of the
2264      type long double.
2265
2266
2267      38) Implementation-defined keywords shall have the form of an identifier reserved for any use as
2268          described in 7.1.3.
2269      39) Therefore, any statement in this Standard about signed integer types also applies to the extended
2270          signed integer types.
2271      40) Therefore, any statement in this Standard about unsigned integer types also applies to the extended
2272          unsigned integer types.
2273      41) The same representation and alignment requirements are meant to imply interchangeability as
2274          arguments to functions, return values from functions, and members of unions.
2275      42) See ''future language directions'' (6.11.1).
2276
2277 [page 40]
2278
2279 11   There are three complex types, designated as float _Complex, double
2280      _Complex, and long double _Complex.43) (Complex types are a conditional
2281      feature that implementations need not support; see 6.10.8.3.) The real floating and
2282      complex types are collectively called the floating types.
2283 12   For each floating type there is a corresponding real type, which is always a real floating
2284      type. For real floating types, it is the same type. For complex types, it is the type given
2285      by deleting the keyword _Complex from the type name.
2286 13   Each complex type has the same representation and alignment requirements as an array
2287      type containing exactly two elements of the corresponding real type; the first element is
2288      equal to the real part, and the second element to the imaginary part, of the complex
2289      number.
2290 14   The type char, the signed and unsigned integer types, and the floating types are
2291      collectively called the basic types. The basic types are complete object types. Even if the
2292      implementation defines two or more basic types to have the same representation, they are
2293      nevertheless different types.44)
2294 15   The three types char, signed char, and unsigned char are collectively called
2295      the character types. The implementation shall define char to have the same range,
2296      representation, and behavior as either signed char or unsigned char.45)
2297 16   An enumeration comprises a set of named integer constant values. Each distinct
2298      enumeration constitutes a different enumerated type.
2299 17   The type char, the signed and unsigned integer types, and the enumerated types are
2300      collectively called integer types. The integer and real floating types are collectively called
2301      real types.
2302 18   Integer and floating types are collectively called arithmetic types. Each arithmetic type
2303      belongs to one type domain: the real type domain comprises the real types, the complex
2304      type domain comprises the complex types.
2305 19   The void type comprises an empty set of values; it is an incomplete object type that
2306      cannot be completed.
2307
2308
2309
2310      43) A specification for imaginary types is in annex G.
2311      44) An implementation may define new keywords that provide alternative ways to designate a basic (or
2312          any other) type; this does not violate the requirement that all basic types be different.
2313          Implementation-defined keywords shall have the form of an identifier reserved for any use as
2314          described in 7.1.3.
2315      45) CHAR_MIN, defined in <limits.h>, will have one of the values 0 or SCHAR_MIN, and this can be
2316          used to distinguish the two options. Irrespective of the choice made, char is a separate type from the
2317          other two and is not compatible with either.
2318
2319 [page 41]
2320
2321 20   Any number of derived types can be constructed from the object and function types, as
2322      follows:
2323      -- An array type describes a contiguously allocated nonempty set of objects with a
2324        particular member object type, called the element type. The element type shall be
2325        complete whenever the array type is specified. Array types are characterized by their
2326        element type and by the number of elements in the array. An array type is said to be
2327        derived from its element type, and if its element type is T , the array type is sometimes
2328        called ''array of T ''. The construction of an array type from an element type is called
2329        ''array type derivation''.
2330      -- A structure type describes a sequentially allocated nonempty set of member objects
2331        (and, in certain circumstances, an incomplete array), each of which has an optionally
2332        specified name and possibly distinct type.
2333      -- A union type describes an overlapping nonempty set of member objects, each of
2334        which has an optionally specified name and possibly distinct type.
2335      -- A function type describes a function with specified return type. A function type is
2336        characterized by its return type and the number and types of its parameters. A
2337        function type is said to be derived from its return type, and if its return type is T , the
2338        function type is sometimes called ''function returning T ''. The construction of a
2339        function type from a return type is called ''function type derivation''.
2340      -- A pointer type may be derived from a function type or an object type, called the
2341        referenced type. A pointer type describes an object whose value provides a reference
2342        to an entity of the referenced type. A pointer type derived from the referenced type T
2343        is sometimes called ''pointer to T ''. The construction of a pointer type from a
2344        referenced type is called ''pointer type derivation''. A pointer type is a complete
2345        object type.
2346      -- An atomic type describes the type designated by the construct _Atomic ( type-
2347        name ). (Atomic types are a conditional feature that implementations need not
2348        support; see 6.10.8.3.)
2349      These methods of constructing derived types can be applied recursively.
2350 21   Arithmetic types and pointer types are collectively called scalar types. Array and
2351      structure types are collectively called aggregate types.46)
2352 22   An array type of unknown size is an incomplete type. It is completed, for an identifier of
2353      that type, by specifying the size in a later declaration (with internal or external linkage).
2354      A structure or union type of unknown content (as described in 6.7.2.3) is an incomplete
2355
2356
2357      46) Note that aggregate type does not include union type because an object with union type can only
2358          contain one member at a time.
2359
2360 [page 42]
2361
2362      type. It is completed, for all declarations of that type, by declaring the same structure or
2363      union tag with its defining content later in the same scope.
2364 23   A type has known constant size if the type is not incomplete and is not a variable length
2365      array type.
2366 24   Array, function, and pointer types are collectively called derived declarator types. A
2367      declarator type derivation from a type T is the construction of a derived declarator type
2368      from T by the application of an array-type, a function-type, or a pointer-type derivation to
2369      T.
2370 25   A type is characterized by its type category, which is either the outermost derivation of a
2371      derived type (as noted above in the construction of derived types), or the type itself if the
2372      type consists of no derived types.
2373 26   Any type so far mentioned is an unqualified type. Each unqualified type has several
2374      qualified versions of its type,47) corresponding to the combinations of one, two, or all
2375      three of the const, volatile, and restrict qualifiers. The qualified or unqualified
2376      versions of a type are distinct types that belong to the same type category and have the
2377      same representation and alignment requirements.48) A derived type is not qualified by the
2378      qualifiers (if any) of the type from which it is derived.
2379 27   Further, there is the _Atomic qualifier. The presence of the _Atomic qualifier
2380      designates an atomic type. The size, representation, and alignment of an atomic type
2381      need not be the same as those of the corresponding unqualified type. Therefore, this
2382      Standard explicitly uses the phrase ''atomic, qualified or unqualified type'' whenever the
2383      atomic version of a type is permitted along with the other qualified versions of a type.
2384      The phrase ''qualified or unqualified type'', without specific mention of atomic, does not
2385      include the atomic types.
2386 28   A pointer to void shall have the same representation and alignment requirements as a
2387      pointer to a character type.48) Similarly, pointers to qualified or unqualified versions of
2388      compatible types shall have the same representation and alignment requirements. All
2389      pointers to structure types shall have the same representation and alignment requirements
2390      as each other. All pointers to union types shall have the same representation and
2391      alignment requirements as each other. Pointers to other types need not have the same
2392      representation or alignment requirements.
2393 29   EXAMPLE 1 The type designated as ''float *'' has type ''pointer to float''. Its type category is
2394      pointer, not a floating type. The const-qualified version of this type is designated as ''float * const''
2395      whereas the type designated as ''const float *'' is not a qualified type -- its type is ''pointer to const-
2396
2397
2398      47) See 6.7.3 regarding qualified array and function types.
2399      48) The same representation and alignment requirements are meant to imply interchangeability as
2400          arguments to functions, return values from functions, and members of unions.
2401
2402 [page 43]
2403
2404      qualified float'' and is a pointer to a qualified type.
2405
2406 30   EXAMPLE 2 The type designated as ''struct tag (*[5])(float)'' has type ''array of pointer to
2407      function returning struct tag''. The array has length five and the function has a single parameter of type
2408      float. Its type category is array.
2409
2410      Forward references: compatible type and composite type (6.2.7), declarations (6.7).
2411      6.2.6 Representations of types
2412      6.2.6.1 General
2413 1    The representations of all types are unspecified except as stated in this subclause.
2414 2    Except for bit-fields, objects are composed of contiguous sequences of one or more bytes,
2415      the number, order, and encoding of which are either explicitly specified or
2416      implementation-defined.
2417 3    Values stored in unsigned bit-fields and objects of type unsigned char shall be
2418      represented using a pure binary notation.49)
2419 4    Values stored in non-bit-field objects of any other object type consist of n x CHAR_BIT
2420      bits, where n is the size of an object of that type, in bytes. The value may be copied into
2421      an object of type unsigned char [n] (e.g., by memcpy); the resulting set of bytes is
2422      called the object representation of the value. Values stored in bit-fields consist of m bits,
2423      where m is the size specified for the bit-field. The object representation is the set of m
2424      bits the bit-field comprises in the addressable storage unit holding it. Two values (other
2425      than NaNs) with the same object representation compare equal, but values that compare
2426      equal may have different object representations.
2427 5    Certain object representations need not represent a value of the object type. If the stored
2428      value of an object has such a representation and is read by an lvalue expression that does
2429      not have character type, the behavior is undefined. If such a representation is produced
2430      by a side effect that modifies all or any part of the object by an lvalue expression that
2431      does not have character type, the behavior is undefined.50) Such a representation is called
2432      a trap representation.
2433 6    When a value is stored in an object of structure or union type, including in a member
2434      object, the bytes of the object representation that correspond to any padding bytes take
2435      unspecified values.51) The value of a structure or union object is never a trap
2436
2437
2438      49) A positional representation for integers that uses the binary digits 0 and 1, in which the values
2439          represented by successive bits are additive, begin with 1, and are multiplied by successive integral
2440          powers of 2, except perhaps the bit with the highest position. (Adapted from the American National
2441          Dictionary for Information Processing Systems.) A byte contains CHAR_BIT bits, and the values of
2442          type unsigned char range from 0 to 2
2443                                                    CHAR_BIT
2444                                                              - 1.
2445      50) Thus, an automatic variable can be initialized to a trap representation without causing undefined
2446          behavior, but the value of the variable cannot be used until a proper value is stored in it.
2447
2448 [page 44]
2449
2450     representation, even though the value of a member of the structure or union object may be
2451     a trap representation.
2452 7   When a value is stored in a member of an object of union type, the bytes of the object
2453     representation that do not correspond to that member but do correspond to other members
2454     take unspecified values.
2455 8   Where an operator is applied to a value that has more than one object representation,
2456     which object representation is used shall not affect the value of the result.52) Where a
2457     value is stored in an object using a type that has more than one object representation for
2458     that value, it is unspecified which representation is used, but a trap representation shall
2459     not be generated.
2460 9   Loads and stores of objects with                            atomic       types     are     done      with
2461     memory_order_seq_cst semantics.
2462     Forward references: declarations (6.7), expressions (6.5), lvalues, arrays, and function
2463     designators (6.3.2.1), order and consistency (7.17.3).
2464     6.2.6.2 Integer types
2465 1   For unsigned integer types other than unsigned char, the bits of the object
2466     representation shall be divided into two groups: value bits and padding bits (there need
2467     not be any of the latter). If there are N value bits, each bit shall represent a different
2468     power of 2 between 1 and 2 N -1 , so that objects of that type shall be capable of
2469     representing values from 0 to 2 N - 1 using a pure binary representation; this shall be
2470     known as the value representation. The values of any padding bits are unspecified.53)
2471 2   For signed integer types, the bits of the object representation shall be divided into three
2472     groups: value bits, padding bits, and the sign bit. There need not be any padding bits;
2473     signed char shall not have any padding bits. There shall be exactly one sign bit.
2474     Each bit that is a value bit shall have the same value as the same bit in the object
2475     representation of the corresponding unsigned type (if there are M value bits in the signed
2476     type and N in the unsigned type, then M <= N ). If the sign bit is zero, it shall not affect
2477
2478     51) Thus, for example, structure assignment need not copy any padding bits.
2479     52) It is possible for objects x and y with the same effective type T to have the same value when they are
2480         accessed as objects of type T, but to have different values in other contexts. In particular, if == is
2481         defined for type T, then x == y does not imply that memcmp(&x, &y, sizeof (T)) == 0.
2482         Furthermore, x == y does not necessarily imply that x and y have the same value; other operations
2483         on values of type T may distinguish between them.
2484     53) Some combinations of padding bits might generate trap representations, for example, if one padding
2485         bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap
2486         representation other than as part of an exceptional condition such as an overflow, and this cannot occur
2487         with unsigned types. All other combinations of padding bits are alternative object representations of
2488         the value specified by the value bits.
2489
2490 [page 45]
2491
2492     the resulting value. If the sign bit is one, the value shall be modified in one of the
2493     following ways:
2494     -- the corresponding value with sign bit 0 is negated (sign and magnitude);
2495     -- the sign bit has the value -(2 M ) (two's complement);
2496     -- the sign bit has the value -(2 M - 1) (ones' complement).
2497     Which of these applies is implementation-defined, as is whether the value with sign bit 1
2498     and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones'
2499     complement), is a trap representation or a normal value. In the case of sign and
2500     magnitude and ones' complement, if this representation is a normal value it is called a
2501     negative zero.
2502 3   If the implementation supports negative zeros, they shall be generated only by:
2503     -- the &, |, ^, ~, <<, and >> operators with operands that produce such a value;
2504     -- the +, -, *, /, and % operators where one operand is a negative zero and the result is
2505       zero;
2506     -- compound assignment operators based on the above cases.
2507     It is unspecified whether these cases actually generate a negative zero or a normal zero,
2508     and whether a negative zero becomes a normal zero when stored in an object.
2509 4   If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<,
2510     and >> operators with operands that would produce such a value is undefined.
2511 5   The values of any padding bits are unspecified.54) A valid (non-trap) object representation
2512     of a signed integer type where the sign bit is zero is a valid object representation of the
2513     corresponding unsigned type, and shall represent the same value. For any integer type,
2514     the object representation where all the bits are zero shall be a representation of the value
2515     zero in that type.
2516 6   The precision of an integer type is the number of bits it uses to represent values,
2517     excluding any sign and padding bits. The width of an integer type is the same but
2518     including any sign bit; thus for unsigned integer types the two values are the same, while
2519     for signed integer types the width is one greater than the precision.
2520
2521
2522
2523
2524     54) Some combinations of padding bits might generate trap representations, for example, if one padding
2525         bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap
2526         representation other than as part of an exceptional condition such as an overflow. All other
2527         combinations of padding bits are alternative object representations of the value specified by the value
2528         bits.
2529
2530 [page 46]
2531
2532     6.2.7 Compatible type and composite type
2533 1   Two types have compatible type if their types are the same. Additional rules for
2534     determining whether two types are compatible are described in 6.7.2 for type specifiers,
2535     in 6.7.3 for type qualifiers, and in 6.7.6 for declarators.55) Moreover, two structure,
2536     union, or enumerated types declared in separate translation units are compatible if their
2537     tags and members satisfy the following requirements: If one is declared with a tag, the
2538     other shall be declared with the same tag. If both are completed anywhere within their
2539     respective translation units, then the following additional requirements apply: there shall
2540     be a one-to-one correspondence between their members such that each pair of
2541     corresponding members are declared with compatible types; if one member of the pair is
2542     declared with an alignment specifier, the other is declared with an equivalent alignment
2543     specifier; and if one member of the pair is declared with a name, the other is declared
2544     with the same name. For two structures, corresponding members shall be declared in the
2545     same order. For two structures or unions, corresponding bit-fields shall have the same
2546     widths. For two enumerations, corresponding members shall have the same values.
2547 2   All declarations that refer to the same object or function shall have compatible type;
2548     otherwise, the behavior is undefined.
2549 3   A composite type can be constructed from two types that are compatible; it is a type that
2550     is compatible with both of the two types and satisfies the following conditions:
2551     -- If both types are array types, the following rules are applied:
2552           o If one type is an array of known constant size, the composite type is an array of
2553              that size.
2554           o Otherwise, if one type is a variable length array whose size is specified by an
2555              expression that is not evaluated, the behavior is undefined.
2556           o Otherwise, if one type is a variable length array whose size is specified, the
2557              composite type is a variable length array of that size.
2558           o Otherwise, if one type is a variable length array of unspecified size, the composite
2559              type is a variable length array of unspecified size.
2560           o Otherwise, both types are arrays of unknown size and the composite type is an
2561              array of unknown size.
2562         The element type of the composite type is the composite type of the two element
2563         types.
2564     -- If only one type is a function type with a parameter type list (a function prototype),
2565       the composite type is a function prototype with the parameter type list.
2566
2567
2568     55) Two types need not be identical to be compatible.
2569
2570 [page 47]
2571
2572     -- If both types are function types with parameter type lists, the type of each parameter
2573       in the composite parameter type list is the composite type of the corresponding
2574       parameters.
2575     These rules apply recursively to the types from which the two types are derived.
2576 4   For an identifier with internal or external linkage declared in a scope in which a prior
2577     declaration of that identifier is visible,56) if the prior declaration specifies internal or
2578     external linkage, the type of the identifier at the later declaration becomes the composite
2579     type.
2580     Forward references: array declarators (6.7.6.2).
2581 5   EXAMPLE        Given the following two file scope declarations:
2582              int f(int (*)(), double (*)[3]);
2583              int f(int (*)(char *), double (*)[]);
2584     The resulting composite type for the function is:
2585              int f(int (*)(char *), double (*)[3]);
2586
2587     6.2.8 Alignment of objects
2588 1   Complete object types have alignment requirements which place restrictions on the
2589     addresses at which objects of that type may be allocated. An alignment is an
2590     implementation-defined integer value representing the number of bytes between
2591     successive addresses at which a given object can be allocated. An object type imposes an
2592     alignment requirement on every object of that type: stricter alignment can be requested
2593     using the _Alignas keyword.
2594 2   A fundamental alignment is represented by an alignment less than or equal to the greatest
2595     alignment supported by the implementation in all contexts, which is equal to
2596     alignof(max_align_t).
2597 3   An extended alignment is represented by an alignment greater than
2598     alignof(max_align_t). It is implementation-defined whether any extended
2599     alignments are supported and the contexts in which they are supported. A type having an
2600     extended alignment requirement is an over-aligned type.57)
2601 4   Alignments are represented as values of the type size_t. Valid alignments include only
2602     those values returned by an alignof expression for fundamental types, plus an
2603     additional implementation-defined set of values, which may be empty. Every valid
2604     alignment value shall be a nonnegative integral power of two.
2605
2606
2607     56) As specified in 6.2.1, the later declaration might hide the prior declaration.
2608     57) Every over-aligned type is, or contains, a structure or union type with a member to which an extended
2609         alignment has been applied.
2610
2611 [page 48]
2612
2613 5   Alignments have an order from weaker to stronger or stricter alignments. Stricter
2614     alignments have larger alignment values. An address that satisfies an alignment
2615     requirement also satisfies any weaker valid alignment requirement.
2616 6   The alignment requirement of a complete type can be queried using an alignof
2617     expression. The types char, signed char, and unsigned char shall have the
2618     weakest alignment requirement.
2619 7   Comparing alignments is meaningful and provides the obvious results:
2620     -- Two alignments are equal when their numeric values are equal.
2621     -- Two alignments are different when their numeric values are not equal.
2622     -- When an alignment is larger than another it represents a stricter alignment.
2623
2624
2625
2626
2627 [page 49]
2628
2629     6.3 Conversions
2630 1   Several operators convert operand values from one type to another automatically. This
2631     subclause specifies the result required from such an implicit conversion, as well as those
2632     that result from a cast operation (an explicit conversion). The list in 6.3.1.8 summarizes
2633     the conversions performed by most ordinary operators; it is supplemented as required by
2634     the discussion of each operator in 6.5.
2635 2   Conversion of an operand value to a compatible type causes no change to the value or the
2636     representation.
2637     Forward references: cast operators (6.5.4).
2638     6.3.1 Arithmetic operands
2639     6.3.1.1 Boolean, characters, and integers
2640 1   Every integer type has an integer conversion rank defined as follows:
2641     -- No two signed integer types shall have the same rank, even if they have the same
2642       representation.
2643     -- The rank of a signed integer type shall be greater than the rank of any signed integer
2644       type with less precision.
2645     -- The rank of long long int shall be greater than the rank of long int, which
2646       shall be greater than the rank of int, which shall be greater than the rank of short
2647       int, which shall be greater than the rank of signed char.
2648     -- The rank of any unsigned integer type shall equal the rank of the corresponding
2649       signed integer type, if any.
2650     -- The rank of any standard integer type shall be greater than the rank of any extended
2651       integer type with the same width.
2652     -- The rank of char shall equal the rank of signed char and unsigned char.
2653     -- The rank of _Bool shall be less than the rank of all other standard integer types.
2654     -- The rank of any enumerated type shall equal the rank of the compatible integer type
2655       (see 6.7.2.2).
2656     -- The rank of any extended signed integer type relative to another extended signed
2657       integer type with the same precision is implementation-defined, but still subject to the
2658       other rules for determining the integer conversion rank.
2659     -- For all integer types T1, T2, and T3, if T1 has greater rank than T2 and T2 has
2660       greater rank than T3, then T1 has greater rank than T3.
2661 2   The following may be used in an expression wherever an int or unsigned int may
2662     be used:
2663
2664 [page 50]
2665
2666     -- An object or expression with an integer type (other than int or unsigned int)
2667       whose integer conversion rank is less than or equal to the rank of int and
2668       unsigned int.
2669     -- A bit-field of type _Bool, int, signed int, or unsigned int.
2670     If an int can represent all values of the original type (as restricted by the width, for a
2671     bit-field), the value is converted to an int; otherwise, it is converted to an unsigned
2672     int. These are called the integer promotions.58) All other types are unchanged by the
2673     integer promotions.
2674 3   The integer promotions preserve value including sign. As discussed earlier, whether a
2675     ''plain'' char is treated as signed is implementation-defined.
2676     Forward references: enumeration specifiers (6.7.2.2), structure and union specifiers
2677     (6.7.2.1).
2678     6.3.1.2 Boolean type
2679 1   When any scalar value is converted to _Bool, the result is 0 if the value compares equal
2680     to 0; otherwise, the result is 1.59)
2681     6.3.1.3 Signed and unsigned integers
2682 1   When a value with integer type is converted to another integer type other than _Bool, if
2683     the value can be represented by the new type, it is unchanged.
2684 2   Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or
2685     subtracting one more than the maximum value that can be represented in the new type
2686     until the value is in the range of the new type.60)
2687 3   Otherwise, the new type is signed and the value cannot be represented in it; either the
2688     result is implementation-defined or an implementation-defined signal is raised.
2689     6.3.1.4 Real floating and integer
2690 1   When a finite value of real floating type is converted to an integer type other than _Bool,
2691     the fractional part is discarded (i.e., the value is truncated toward zero). If the value of
2692     the integral part cannot be represented by the integer type, the behavior is undefined.61)
2693
2694
2695     58) The integer promotions are applied only: as part of the usual arithmetic conversions, to certain
2696         argument expressions, to the operands of the unary +, -, and ~ operators, and to both operands of the
2697         shift operators, as specified by their respective subclauses.
2698     59) NaNs do not compare equal to 0 and thus convert to 1.
2699     60) The rules describe arithmetic on the mathematical value, not the value of a given type of expression.
2700     61) The remaindering operation performed when a value of integer type is converted to unsigned type
2701         need not be performed when a value of real floating type is converted to unsigned type. Thus, the
2702         range of portable real floating values is (-1, Utype_MAX+1).
2703
2704 [page 51]
2705
2706 2   When a value of integer type is converted to a real floating type, if the value being
2707     converted can be represented exactly in the new type, it is unchanged. If the value being
2708     converted is in the range of values that can be represented but cannot be represented
2709     exactly, the result is either the nearest higher or nearest lower representable value, chosen
2710     in an implementation-defined manner. If the value being converted is outside the range of
2711     values that can be represented, the behavior is undefined. Results of some implicit
2712     conversions (6.3.1.8, 6.8.6.4) may be represented in greater precision and range than that
2713     required by the new type.
2714     6.3.1.5 Real floating types
2715 1   When a value of real floating type is converted to a real floating type, if the value being
2716     converted can be represented exactly in the new type, it is unchanged. If the value being
2717     converted is in the range of values that can be represented but cannot be represented
2718     exactly, the result is either the nearest higher or nearest lower representable value, chosen
2719     in an implementation-defined manner. If the value being converted is outside the range of
2720     values that can be represented, the behavior is undefined. Results of some implicit
2721     conversions (6.3.1.8, 6.8.6.4) may be represented in greater precision and range than that
2722     required by the new type.
2723     6.3.1.6 Complex types
2724 1   When a value of complex type is converted to another complex type, both the real and
2725     imaginary parts follow the conversion rules for the corresponding real types.
2726     6.3.1.7 Real and complex
2727 1   When a value of real type is converted to a complex type, the real part of the complex
2728     result value is determined by the rules of conversion to the corresponding real type and
2729     the imaginary part of the complex result value is a positive zero or an unsigned zero.
2730 2   When a value of complex type is converted to a real type, the imaginary part of the
2731     complex value is discarded and the value of the real part is converted according to the
2732     conversion rules for the corresponding real type.
2733     6.3.1.8 Usual arithmetic conversions
2734 1   Many operators that expect operands of arithmetic type cause conversions and yield result
2735     types in a similar way. The purpose is to determine a common real type for the operands
2736     and result. For the specified operands, each operand is converted, without change of type
2737     domain, to a type whose corresponding real type is the common real type. Unless
2738     explicitly stated otherwise, the common real type is also the corresponding real type of
2739     the result, whose type domain is the type domain of the operands if they are the same,
2740     and complex otherwise. This pattern is called the usual arithmetic conversions:
2741           First, if the corresponding real type of either operand is long double, the other
2742           operand is converted, without change of type domain, to a type whose
2743
2744 [page 52]
2745
2746            corresponding real type is long double.
2747            Otherwise, if the corresponding real type of either operand is double, the other
2748            operand is converted, without change of type domain, to a type whose
2749            corresponding real type is double.
2750            Otherwise, if the corresponding real type of either operand is float, the other
2751            operand is converted, without change of type domain, to a type whose
2752            corresponding real type is float.62)
2753            Otherwise, the integer promotions are performed on both operands. Then the
2754            following rules are applied to the promoted operands:
2755                   If both operands have the same type, then no further conversion is needed.
2756                   Otherwise, if both operands have signed integer types or both have unsigned
2757                   integer types, the operand with the type of lesser integer conversion rank is
2758                   converted to the type of the operand with greater rank.
2759                   Otherwise, if the operand that has unsigned integer type has rank greater or
2760                   equal to the rank of the type of the other operand, then the operand with
2761                   signed integer type is converted to the type of the operand with unsigned
2762                   integer type.
2763                   Otherwise, if the type of the operand with signed integer type can represent
2764                   all of the values of the type of the operand with unsigned integer type, then
2765                   the operand with unsigned integer type is converted to the type of the
2766                   operand with signed integer type.
2767                   Otherwise, both operands are converted to the unsigned integer type
2768                   corresponding to the type of the operand with signed integer type.
2769 2   The values of floating operands and of the results of floating expressions may be
2770     represented in greater precision and range than that required by the type; the types are not
2771     changed thereby.63)
2772
2773
2774
2775
2776     62) For example, addition of a double _Complex and a float entails just the conversion of the
2777         float operand to double (and yields a double _Complex result).
2778     63) The cast and assignment operators are still required to remove extra range and precision.
2779
2780 [page 53]
2781
2782     6.3.2 Other operands
2783     6.3.2.1 Lvalues, arrays, and function designators
2784 1   An lvalue is an expression (with an object type other than void) that potentially
2785     designates an object;64) if an lvalue does not designate an object when it is evaluated, the
2786     behavior is undefined. When an object is said to have a particular type, the type is
2787     specified by the lvalue used to designate the object. A modifiable lvalue is an lvalue that
2788     does not have array type, does not have an incomplete type, does not have a const-
2789     qualified type, and if it is a structure or union, does not have any member (including,
2790     recursively, any member or element of all contained aggregates or unions) with a const-
2791     qualified type.
2792 2   Except when it is the operand of the sizeof operator, the unary & operator, the ++
2793     operator, the -- operator, or the left operand of the . operator or an assignment operator,
2794     an lvalue that does not have array type is converted to the value stored in the designated
2795     object (and is no longer an lvalue); this is called lvalue conversion. If the lvalue has
2796     qualified type, the value has the unqualified version of the type of the lvalue; additionally,
2797     if the lvalue has atomic type, the value has the non-atomic version of the type of the
2798     lvalue; otherwise, the value has the type of the lvalue. If the lvalue has an incomplete
2799     type and does not have array type, the behavior is undefined. If the lvalue designates an
2800     object of automatic storage duration that could have been declared with the register
2801     storage class (never had its address taken), and that object is uninitialized (not declared
2802     with an initializer and no assignment to it has been performed prior to use), the behavior
2803     is undefined.
2804 3   Except when it is the operand of the sizeof operator or the unary & operator, or is a
2805     string literal used to initialize an array, an expression that has type ''array of type'' is
2806     converted to an expression with type ''pointer to type'' that points to the initial element of
2807     the array object and is not an lvalue. If the array object has register storage class, the
2808     behavior is undefined.
2809 4   A function designator is an expression that has function type. Except when it is the
2810     operand of the sizeof operator65) or the unary & operator, a function designator with
2811     type ''function returning type'' is converted to an expression that has type ''pointer to
2812
2813
2814     64) The name ''lvalue'' comes originally from the assignment expression E1 = E2, in which the left
2815         operand E1 is required to be a (modifiable) lvalue. It is perhaps better considered as representing an
2816         object ''locator value''. What is sometimes called ''rvalue'' is in this International Standard described
2817         as the ''value of an expression''.
2818          An obvious example of an lvalue is an identifier of an object. As a further example, if E is a unary
2819          expression that is a pointer to an object, *E is an lvalue that designates the object to which E points.
2820     65) Because this conversion does not occur, the operand of the sizeof operator remains a function
2821         designator and violates the constraint in 6.5.3.4.
2822
2823 [page 54]
2824
2825     function returning type''.
2826     Forward references: address and indirection operators (6.5.3.2), assignment operators
2827     (6.5.16), common definitions <stddef.h> (7.19), initialization (6.7.9), postfix
2828     increment and decrement operators (6.5.2.4), prefix increment and decrement operators
2829     (6.5.3.1), the sizeof operator (6.5.3.4), structure and union members (6.5.2.3).
2830     6.3.2.2 void
2831 1   The (nonexistent) value of a void expression (an expression that has type void) shall not
2832     be used in any way, and implicit or explicit conversions (except to void) shall not be
2833     applied to such an expression. If an expression of any other type is evaluated as a void
2834     expression, its value or designator is discarded. (A void expression is evaluated for its
2835     side effects.)
2836     6.3.2.3 Pointers
2837 1   A pointer to void may be converted to or from a pointer to any object type. A pointer to
2838     any object type may be converted to a pointer to void and back again; the result shall
2839     compare equal to the original pointer.
2840 2   For any qualifier q, a pointer to a non-q-qualified type may be converted to a pointer to
2841     the q-qualified version of the type; the values stored in the original and converted pointers
2842     shall compare equal.
2843 3   An integer constant expression with the value 0, or such an expression cast to type
2844     void *, is called a null pointer constant.66) If a null pointer constant is converted to a
2845     pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal
2846     to a pointer to any object or function.
2847 4   Conversion of a null pointer to another pointer type yields a null pointer of that type.
2848     Any two null pointers shall compare equal.
2849 5   An integer may be converted to any pointer type. Except as previously specified, the
2850     result is implementation-defined, might not be correctly aligned, might not point to an
2851     entity of the referenced type, and might be a trap representation.67)
2852 6   Any pointer type may be converted to an integer type. Except as previously specified, the
2853     result is implementation-defined. If the result cannot be represented in the integer type,
2854     the behavior is undefined. The result need not be in the range of values of any integer
2855     type.
2856
2857
2858
2859
2860     66) The macro NULL is defined in <stddef.h> (and other headers) as a null pointer constant; see 7.19.
2861     67) The mapping functions for converting a pointer to an integer or an integer to a pointer are intended to
2862         be consistent with the addressing structure of the execution environment.
2863
2864 [page 55]
2865
2866 7   A pointer to an object type may be converted to a pointer to a different object type. If the
2867     resulting pointer is not correctly aligned68) for the referenced type, the behavior is
2868     undefined. Otherwise, when converted back again, the result shall compare equal to the
2869     original pointer. When a pointer to an object is converted to a pointer to a character type,
2870     the result points to the lowest addressed byte of the object. Successive increments of the
2871     result, up to the size of the object, yield pointers to the remaining bytes of the object.
2872 8   A pointer to a function of one type may be converted to a pointer to a function of another
2873     type and back again; the result shall compare equal to the original pointer. If a converted
2874     pointer is used to call a function whose type is not compatible with the referenced type,
2875     the behavior is undefined.
2876     Forward references: cast operators (6.5.4), equality operators (6.5.9), integer types
2877     capable of holding object pointers (7.20.1.4), simple assignment (6.5.16.1).
2878
2879
2880
2881
2882     68) In general, the concept ''correctly aligned'' is transitive: if a pointer to type A is correctly aligned for a
2883         pointer to type B, which in turn is correctly aligned for a pointer to type C, then a pointer to type A is
2884         correctly aligned for a pointer to type C.
2885
2886 [page 56]
2887
2888     6.4 Lexical elements
2889     Syntax
2890 1            token:
2891                       keyword
2892                       identifier
2893                       constant
2894                       string-literal
2895                       punctuator
2896              preprocessing-token:
2897                     header-name
2898                     identifier
2899                     pp-number
2900                     character-constant
2901                     string-literal
2902                     punctuator
2903                     each non-white-space character that cannot be one of the above
2904     Constraints
2905 2   Each preprocessing token that is converted to a token shall have the lexical form of a
2906     keyword, an identifier, a constant, a string literal, or a punctuator.
2907     Semantics
2908 3   A token is the minimal lexical element of the language in translation phases 7 and 8. The
2909     categories of tokens are: keywords, identifiers, constants, string literals, and punctuators.
2910     A preprocessing token is the minimal lexical element of the language in translation
2911     phases 3 through 6. The categories of preprocessing tokens are: header names,
2912     identifiers, preprocessing numbers, character constants, string literals, punctuators, and
2913     single non-white-space characters that do not lexically match the other preprocessing
2914     token categories.69) If a ' or a " character matches the last category, the behavior is
2915     undefined. Preprocessing tokens can be separated by white space; this consists of
2916     comments (described later), or white-space characters (space, horizontal tab, new-line,
2917     vertical tab, and form-feed), or both. As described in 6.10, in certain circumstances
2918     during translation phase 4, white space (or the absence thereof) serves as more than
2919     preprocessing token separation. White space may appear within a preprocessing token
2920     only as part of a header name or between the quotation characters in a character constant
2921     or string literal.
2922
2923
2924
2925     69) An additional category, placemarkers, is used internally in translation phase 4 (see 6.10.3.3); it cannot
2926         occur in source files.
2927
2928 [page 57]
2929
2930 4   If the input stream has been parsed into preprocessing tokens up to a given character, the
2931     next preprocessing token is the longest sequence of characters that could constitute a
2932     preprocessing token. There is one exception to this rule: header name preprocessing
2933     tokens are recognized only within #include preprocessing directives and in
2934     implementation-defined locations within #pragma directives. In such contexts, a
2935     sequence of characters that could be either a header name or a string literal is recognized
2936     as the former.
2937 5   EXAMPLE 1 The program fragment 1Ex is parsed as a preprocessing number token (one that is not a
2938     valid floating or integer constant token), even though a parse as the pair of preprocessing tokens 1 and Ex
2939     might produce a valid expression (for example, if Ex were a macro defined as +1). Similarly, the program
2940     fragment 1E1 is parsed as a preprocessing number (one that is a valid floating constant token), whether or
2941     not E is a macro name.
2942
2943 6   EXAMPLE 2 The program fragment x+++++y is parsed as x ++ ++ + y, which violates a constraint on
2944     increment operators, even though the parse x ++ + ++ y might yield a correct expression.
2945
2946     Forward references: character constants (6.4.4.4), comments (6.4.9), expressions (6.5),
2947     floating constants (6.4.4.2), header names (6.4.7), macro replacement (6.10.3), postfix
2948     increment and decrement operators (6.5.2.4), prefix increment and decrement operators
2949     (6.5.3.1), preprocessing directives (6.10), preprocessing numbers (6.4.8), string literals
2950     (6.4.5).
2951     6.4.1 Keywords
2952     Syntax
2953 1            keyword: one of
2954                    alignof                         goto                         union
2955                    auto                            if                           unsigned
2956                    break                           inline                       void
2957                    case                            int                          volatile
2958                    char                            long                         while
2959                    const                           register                     _Alignas
2960                    continue                        restrict                     _Atomic
2961                    default                         return                       _Bool
2962                    do                              short                        _Complex
2963                    double                          signed                       _Generic
2964                    else                            sizeof                       _Imaginary
2965                    enum                            static                       _Noreturn
2966                    extern                          struct                       _Static_assert
2967                    float                           switch                       _Thread_local
2968                    for                             typedef
2969     Semantics
2970 2   The above tokens (case sensitive) are reserved (in translation phases 7 and 8) for use as
2971     keywords, and shall not be used otherwise. The keyword _Imaginary is reserved for
2972 [page 58]
2973
2974     specifying imaginary types.70)
2975     6.4.2 Identifiers
2976     6.4.2.1 General
2977     Syntax
2978 1            identifier:
2979                     identifier-nondigit
2980                     identifier identifier-nondigit
2981                     identifier digit
2982              identifier-nondigit:
2983                     nondigit
2984                     universal-character-name
2985                     other implementation-defined characters
2986              nondigit: one of
2987                     _ a b            c    d    e    f     g    h    i    j     k    l    m
2988                         n o          p    q    r    s     t    u    v    w     x    y    z
2989                         A B          C    D    E    F     G    H    I    J     K    L    M
2990                         N O          P    Q    R    S     T    U    V    W     X    Y    Z
2991              digit: one of
2992                     0 1        2     3    4    5    6     7    8    9
2993     Semantics
2994 2   An identifier is a sequence of nondigit characters (including the underscore _, the
2995     lowercase and uppercase Latin letters, and other characters) and digits, which designates
2996     one or more entities as described in 6.2.1. Lowercase and uppercase letters are distinct.
2997     There is no specific limit on the maximum length of an identifier.
2998 3   Each universal character name in an identifier shall designate a character whose encoding
2999     in ISO/IEC 10646 falls into one of the ranges specified in D.1.71) The initial character
3000     shall not be a universal character name designating a character whose encoding falls into
3001     one of the ranges specified in D.2. An implementation may allow multibyte characters
3002     that are not part of the basic source character set to appear in identifiers; which characters
3003     and their correspondence to universal character names is implementation-defined.
3004
3005
3006
3007     70) One possible specification for imaginary types appears in annex G.
3008     71) On systems in which linkers cannot accept extended characters, an encoding of the universal character
3009         name may be used in forming valid external identifiers. For example, some otherwise unused
3010         character or sequence of characters may be used to encode the \u in a universal character name.
3011         Extended characters may produce a long external identifier.
3012
3013 [page 59]
3014
3015 4   When preprocessing tokens are converted to tokens during translation phase 7, if a
3016     preprocessing token could be converted to either a keyword or an identifier, it is converted
3017     to a keyword.
3018     Implementation limits
3019 5   As discussed in 5.2.4.1, an implementation may limit the number of significant initial
3020     characters in an identifier; the limit for an external name (an identifier that has external
3021     linkage) may be more restrictive than that for an internal name (a macro name or an
3022     identifier that does not have external linkage). The number of significant characters in an
3023     identifier is implementation-defined.
3024 6   Any identifiers that differ in a significant character are different identifiers. If two
3025     identifiers differ only in nonsignificant characters, the behavior is undefined.
3026     Forward references: universal character names (6.4.3), macro replacement (6.10.3).
3027     6.4.2.2 Predefined identifiers
3028     Semantics
3029 1   The identifier __func__ shall be implicitly declared by the translator as if,
3030     immediately following the opening brace of each function definition, the declaration
3031              static const char __func__[] = "function-name";
3032     appeared, where function-name is the name of the lexically-enclosing function.72)
3033 2   This name is encoded as if the implicit declaration had been written in the source
3034     character set and then translated into the execution character set as indicated in translation
3035     phase 5.
3036 3   EXAMPLE        Consider the code fragment:
3037              #include <stdio.h>
3038              void myfunc(void)
3039              {
3040                    printf("%s\n", __func__);
3041                    /* ... */
3042              }
3043     Each time the function is called, it will print to the standard output stream:
3044              myfunc
3045
3046     Forward references: function definitions (6.9.1).
3047
3048
3049
3050
3051     72) Since the name __func__ is reserved for any use by the implementation (7.1.3), if any other
3052         identifier is explicitly declared using the name __func__, the behavior is undefined.
3053
3054 [page 60]
3055
3056     6.4.3 Universal character names
3057     Syntax
3058 1            universal-character-name:
3059                     \u hex-quad
3060                     \U hex-quad hex-quad
3061              hex-quad:
3062                     hexadecimal-digit hexadecimal-digit
3063                                  hexadecimal-digit hexadecimal-digit
3064     Constraints
3065 2   A universal character name shall not specify a character whose short identifier is less than
3066     00A0 other than 0024 ($), 0040 (@), or 0060 ('), nor one in the range D800 through
3067     DFFF inclusive.73)
3068     Description
3069 3   Universal character names may be used in identifiers, character constants, and string
3070     literals to designate characters that are not in the basic character set.
3071     Semantics
3072 4   The universal character name \Unnnnnnnn designates the character whose eight-digit
3073     short identifier (as specified by ISO/IEC 10646) is nnnnnnnn.74) Similarly, the universal
3074     character name \unnnn designates the character whose four-digit short identifier is nnnn
3075     (and whose eight-digit short identifier is 0000nnnn).
3076
3077
3078
3079
3080     73) The disallowed characters are the characters in the basic character set and the code positions reserved
3081         by ISO/IEC 10646 for control characters, the character DELETE, and the S-zone (reserved for use by
3082         UTF-16).
3083
3084     74) Short identifiers for characters were first specified in ISO/IEC 10646-1/AMD9:1997.
3085
3086 [page 61]
3087
3088     6.4.4 Constants
3089     Syntax
3090 1            constant:
3091                     integer-constant
3092                     floating-constant
3093                     enumeration-constant
3094                     character-constant
3095     Constraints
3096 2   Each constant shall have a type and the value of a constant shall be in the range of
3097     representable values for its type.
3098     Semantics
3099 3   Each constant has a type, determined by its form and value, as detailed later.
3100     6.4.4.1 Integer constants
3101     Syntax
3102 1            integer-constant:
3103                      decimal-constant integer-suffixopt
3104                      octal-constant integer-suffixopt
3105                      hexadecimal-constant integer-suffixopt
3106              decimal-constant:
3107                    nonzero-digit
3108                    decimal-constant digit
3109              octal-constant:
3110                     0
3111                     octal-constant octal-digit
3112              hexadecimal-constant:
3113                    hexadecimal-prefix hexadecimal-digit
3114                    hexadecimal-constant hexadecimal-digit
3115              hexadecimal-prefix: one of
3116                    0x 0X
3117              nonzero-digit: one of
3118                     1 2 3 4          5     6     7   8    9
3119              octal-digit: one of
3120                      0 1 2 3         4     5     6   7
3121
3122
3123
3124
3125 [page 62]
3126
3127             hexadecimal-digit:   one of
3128                   0 1 2           3 4     5    6   7     8   9
3129                   a b c           d e     f
3130                   A B C           D E     F
3131             integer-suffix:
3132                     unsigned-suffix long-suffixopt
3133                     unsigned-suffix long-long-suffix
3134                     long-suffix unsigned-suffixopt
3135                     long-long-suffix unsigned-suffixopt
3136             unsigned-suffix: one of
3137                    u U
3138             long-suffix: one of
3139                    l L
3140             long-long-suffix: one of
3141                    ll LL
3142     Description
3143 2   An integer constant begins with a digit, but has no period or exponent part. It may have a
3144     prefix that specifies its base and a suffix that specifies its type.
3145 3   A decimal constant begins with a nonzero digit and consists of a sequence of decimal
3146     digits. An octal constant consists of the prefix 0 optionally followed by a sequence of the
3147     digits 0 through 7 only. A hexadecimal constant consists of the prefix 0x or 0X followed
3148     by a sequence of the decimal digits and the letters a (or A) through f (or F) with values
3149     10 through 15 respectively.
3150     Semantics
3151 4   The value of a decimal constant is computed base 10; that of an octal constant, base 8;
3152     that of a hexadecimal constant, base 16. The lexically first digit is the most significant.
3153 5   The type of an integer constant is the first of the corresponding list in which its value can
3154     be represented.
3155
3156
3157
3158
3159 [page 63]
3160
3161                                                                      Octal or Hexadecimal
3162     Suffix                       Decimal Constant                           Constant
3163
3164     none                int                                    int
3165                         long int                               unsigned int
3166                         long long int                          long int
3167                                                                unsigned long int
3168                                                                long long int
3169                                                                unsigned long long int
3170
3171     u or U              unsigned int                           unsigned int
3172                         unsigned long int                      unsigned long int
3173                         unsigned long long int                 unsigned long long int
3174
3175     l or L              long int                               long int
3176                         long long int                          unsigned long int
3177                                                                long long int
3178                                                                unsigned long long int
3179
3180     Both u or U         unsigned long int                      unsigned long int
3181     and l or L          unsigned long long int                 unsigned long long int
3182
3183     ll or LL            long long int                          long long int
3184                                                                unsigned long long int
3185
3186     Both u or U         unsigned long long int                 unsigned long long int
3187     and ll or LL
3188 6   If an integer constant cannot be represented by any type in its list, it may have an
3189     extended integer type, if the extended integer type can represent its value. If all of the
3190     types in the list for the constant are signed, the extended integer type shall be signed. If
3191     all of the types in the list for the constant are unsigned, the extended integer type shall be
3192     unsigned. If the list contains both signed and unsigned types, the extended integer type
3193     may be signed or unsigned. If an integer constant cannot be represented by any type in
3194     its list and has no extended integer type, then the integer constant has no type.
3195
3196
3197
3198
3199 [page 64]
3200
3201     6.4.4.2 Floating constants
3202     Syntax
3203 1            floating-constant:
3204                     decimal-floating-constant
3205                     hexadecimal-floating-constant
3206              decimal-floating-constant:
3207                    fractional-constant exponent-partopt floating-suffixopt
3208                    digit-sequence exponent-part floating-suffixopt
3209              hexadecimal-floating-constant:
3210                    hexadecimal-prefix hexadecimal-fractional-constant
3211                                   binary-exponent-part floating-suffixopt
3212                    hexadecimal-prefix hexadecimal-digit-sequence
3213                                   binary-exponent-part floating-suffixopt
3214              fractional-constant:
3215                      digit-sequenceopt . digit-sequence
3216                      digit-sequence .
3217              exponent-part:
3218                    e signopt digit-sequence
3219                    E signopt digit-sequence
3220              sign: one of
3221                     + -
3222              digit-sequence:
3223                      digit
3224                      digit-sequence digit
3225              hexadecimal-fractional-constant:
3226                    hexadecimal-digit-sequenceopt .
3227                                   hexadecimal-digit-sequence
3228                    hexadecimal-digit-sequence .
3229              binary-exponent-part:
3230                     p signopt digit-sequence
3231                     P signopt digit-sequence
3232              hexadecimal-digit-sequence:
3233                    hexadecimal-digit
3234                    hexadecimal-digit-sequence hexadecimal-digit
3235              floating-suffix: one of
3236                     f l F L
3237
3238 [page 65]
3239
3240     Description
3241 2   A floating constant has a significand part that may be followed by an exponent part and a
3242     suffix that specifies its type. The components of the significand part may include a digit
3243     sequence representing the whole-number part, followed by a period (.), followed by a
3244     digit sequence representing the fraction part. The components of the exponent part are an
3245     e, E, p, or P followed by an exponent consisting of an optionally signed digit sequence.
3246     Either the whole-number part or the fraction part has to be present; for decimal floating
3247     constants, either the period or the exponent part has to be present.
3248     Semantics
3249 3   The significand part is interpreted as a (decimal or hexadecimal) rational number; the
3250     digit sequence in the exponent part is interpreted as a decimal integer. For decimal
3251     floating constants, the exponent indicates the power of 10 by which the significand part is
3252     to be scaled. For hexadecimal floating constants, the exponent indicates the power of 2
3253     by which the significand part is to be scaled. For decimal floating constants, and also for
3254     hexadecimal floating constants when FLT_RADIX is not a power of 2, the result is either
3255     the nearest representable value, or the larger or smaller representable value immediately
3256     adjacent to the nearest representable value, chosen in an implementation-defined manner.
3257     For hexadecimal floating constants when FLT_RADIX is a power of 2, the result is
3258     correctly rounded.
3259 4   An unsuffixed floating constant has type double. If suffixed by the letter f or F, it has
3260     type float. If suffixed by the letter l or L, it has type long double.
3261 5   Floating constants are converted to internal format as if at translation-time. The
3262     conversion of a floating constant shall not raise an exceptional condition or a floating-
3263     point exception at execution time. All floating constants of the same source form75) shall
3264     convert to the same internal format with the same value.
3265     Recommended practice
3266 6   The implementation should produce a diagnostic message if a hexadecimal constant
3267     cannot be represented exactly in its evaluation format; the implementation should then
3268     proceed with the translation of the program.
3269 7   The translation-time conversion of floating constants should match the execution-time
3270     conversion of character strings by library functions, such as strtod, given matching
3271     inputs suitable for both conversions, the same result format, and default execution-time
3272     rounding.76)
3273
3274     75) 1.23, 1.230, 123e-2, 123e-02, and 1.23L are all different source forms and thus need not
3275         convert to the same internal format and value.
3276     76) The specification for the library functions recommends more accurate conversion than required for
3277         floating constants (see 7.22.1.3).
3278
3279 [page 66]
3280
3281     6.4.4.3 Enumeration constants
3282     Syntax
3283 1            enumeration-constant:
3284                    identifier
3285     Semantics
3286 2   An identifier declared as an enumeration constant has type int.
3287     Forward references: enumeration specifiers (6.7.2.2).
3288     6.4.4.4 Character constants
3289     Syntax
3290 1            character-constant:
3291                     ' c-char-sequence '
3292                     L' c-char-sequence '
3293                     u' c-char-sequence '
3294                     U' c-char-sequence '
3295              c-char-sequence:
3296                     c-char
3297                     c-char-sequence c-char
3298              c-char:
3299                        any member of the source character set except
3300                                     the single-quote ', backslash \, or new-line character
3301                        escape-sequence
3302              escape-sequence:
3303                     simple-escape-sequence
3304                     octal-escape-sequence
3305                     hexadecimal-escape-sequence
3306                     universal-character-name
3307              simple-escape-sequence: one of
3308                     \' \" \? \\
3309                     \a \b \f \n \r                  \t    \v
3310              octal-escape-sequence:
3311                      \ octal-digit
3312                      \ octal-digit octal-digit
3313                      \ octal-digit octal-digit octal-digit
3314
3315
3316
3317
3318 [page 67]
3319
3320            hexadecimal-escape-sequence:
3321                  \x hexadecimal-digit
3322                  hexadecimal-escape-sequence hexadecimal-digit
3323     Description
3324 2   An integer character constant is a sequence of one or more multibyte characters enclosed
3325     in single-quotes, as in 'x'. A wide character constant is the same, except prefixed by the
3326     letter L, u, or U. With a few exceptions detailed later, the elements of the sequence are
3327     any members of the source character set; they are mapped in an implementation-defined
3328     manner to members of the execution character set.
3329 3   The single-quote ', the double-quote ", the question-mark ?, the backslash \, and
3330     arbitrary integer values are representable according to the following table of escape
3331     sequences:
3332           single quote '            \'
3333           double quote "            \"
3334           question mark ?           \?
3335           backslash \               \\
3336           octal character           \octal digits
3337           hexadecimal character     \x hexadecimal digits
3338 4   The double-quote " and question-mark ? are representable either by themselves or by the
3339     escape sequences \" and \?, respectively, but the single-quote ' and the backslash \
3340     shall be represented, respectively, by the escape sequences \' and \\.
3341 5   The octal digits that follow the backslash in an octal escape sequence are taken to be part
3342     of the construction of a single character for an integer character constant or of a single
3343     wide character for a wide character constant. The numerical value of the octal integer so
3344     formed specifies the value of the desired character or wide character.
3345 6   The hexadecimal digits that follow the backslash and the letter x in a hexadecimal escape
3346     sequence are taken to be part of the construction of a single character for an integer
3347     character constant or of a single wide character for a wide character constant. The
3348     numerical value of the hexadecimal integer so formed specifies the value of the desired
3349     character or wide character.
3350 7   Each octal or hexadecimal escape sequence is the longest sequence of characters that can
3351     constitute the escape sequence.
3352 8   In addition, characters not in the basic character set are representable by universal
3353     character names and certain nongraphic characters are representable by escape sequences
3354     consisting of the backslash \ followed by a lowercase letter: \a, \b, \f, \n, \r, \t,
3355     and \v.77)
3356
3357
3358
3359 [page 68]
3360
3361      Constraints
3362 9    The value of an octal or hexadecimal escape sequence shall be in the range of
3363      representable values for the corresponding type:
3364             Prefix      Corresponding Type
3365             none       unsigned char
3366             L          the unsigned type corresponding to wchar_t
3367             u          char16_t
3368             U          char32_t
3369      Semantics
3370 10   An integer character constant has type int. The value of an integer character constant
3371      containing a single character that maps to a single-byte execution character is the
3372      numerical value of the representation of the mapped character interpreted as an integer.
3373      The value of an integer character constant containing more than one character (e.g.,
3374      'ab'), or containing a character or escape sequence that does not map to a single-byte
3375      execution character, is implementation-defined. If an integer character constant contains
3376      a single character or escape sequence, its value is the one that results when an object with
3377      type char whose value is that of the single character or escape sequence is converted to
3378      type int.
3379 11   A wide character constant prefixed by the letter L has type wchar_t, an integer type
3380      defined in the <stddef.h> header; a wide character constant prefixed by the letter u or
3381      U has type char16_t or char32_t, respectively, unsigned integer types defined in the
3382      <uchar.h> header. The value of a wide character constant containing a single
3383      multibyte character that maps to a single member of the extended execution character set
3384      is the wide character corresponding to that multibyte character, as defined by the
3385      mbtowc, mbrtoc16, or mbrtoc32 function as appropriate for its type, with an
3386      implementation-defined current locale. The value of a wide character constant containing
3387      more than one multibyte character or a single multibyte character that maps to multiple
3388      members of the extended execution character set, or containing a multibyte character or
3389      escape sequence not represented in the extended execution character set, is
3390      implementation-defined.
3391 12   EXAMPLE 1      The construction '\0' is commonly used to represent the null character.
3392
3393 13   EXAMPLE 2 Consider implementations that use two's complement representation for integers and eight
3394      bits for objects that have type char. In an implementation in which type char has the same range of
3395      values as signed char, the integer character constant '\xFF' has the value -1; if type char has the
3396      same range of values as unsigned char, the character constant '\xFF' has the value +255.
3397
3398
3399
3400
3401      77) The semantics of these characters were discussed in 5.2.2. If any other character follows a backslash,
3402          the result is not a token and a diagnostic is required. See ''future language directions'' (6.11.4).
3403
3404 [page 69]
3405
3406 14   EXAMPLE 3 Even if eight bits are used for objects that have type char, the construction '\x123'
3407      specifies an integer character constant containing only one character, since a hexadecimal escape sequence
3408      is terminated only by a non-hexadecimal character. To specify an integer character constant containing the
3409      two characters whose values are '\x12' and '3', the construction '\0223' may be used, since an octal
3410      escape sequence is terminated after three octal digits. (The value of this two-character integer character
3411      constant is implementation-defined.)
3412
3413 15   EXAMPLE 4 Even if 12 or more bits are used for objects that have type wchar_t, the construction
3414      L'\1234' specifies the implementation-defined value that results from the combination of the values
3415      0123 and '4'.
3416
3417      Forward references: common definitions <stddef.h> (7.19), the mbtowc function
3418      (7.22.7.2), Unicode utilities <uchar.h> (7.27).
3419      6.4.5 String literals
3420      Syntax
3421 1             string-literal:
3422                       encoding-prefixopt " s-char-sequenceopt "
3423               encoding-prefix:
3424                      u8
3425                      u
3426                      U
3427                      L
3428               s-char-sequence:
3429                      s-char
3430                      s-char-sequence s-char
3431               s-char:
3432                         any member of the source character set except
3433                                      the double-quote ", backslash \, or new-line character
3434                         escape-sequence
3435      Constraints
3436 2    A sequence of adjacent string literal tokens shall not include both a wide string literal and
3437      a UTF-8 string literal.
3438      Description
3439 3    A character string literal is a sequence of zero or more multibyte characters enclosed in
3440      double-quotes, as in "xyz". A UTF-8 string literal is the same, except prefixed by u8.
3441      A wide string literal is the same, except prefixed by the letter L, u, or U.
3442 4    The same considerations apply to each element of the sequence in a string literal as if it
3443      were in an integer character constant (for a character or UTF-8 string literal) or a wide
3444      character constant (for a wide string literal), except that the single-quote ' is
3445      representable either by itself or by the escape sequence \', but the double-quote " shall
3446 [page 70]
3447
3448     be represented by the escape sequence \".
3449     Semantics
3450 5   In translation phase 6, the multibyte character sequences specified by any sequence of
3451     adjacent character and identically-prefixed string literal tokens are concatenated into a
3452     single multibyte character sequence. If any of the tokens has an encoding prefix, the
3453     resulting multibyte character sequence is treated as having the same prefix; otherwise, it
3454     is treated as a character string literal. Whether differently-prefixed wide string literal
3455     tokens can be concatenated and, if so, the treatment of the resulting multibyte character
3456     sequence are implementation-defined.
3457 6   In translation phase 7, a byte or code of value zero is appended to each multibyte
3458     character sequence that results from a string literal or literals.78) The multibyte character
3459     sequence is then used to initialize an array of static storage duration and length just
3460     sufficient to contain the sequence. For character string literals, the array elements have
3461     type char, and are initialized with the individual bytes of the multibyte character
3462     sequence. For UTF-8 string literals, the array elements have type char, and are
3463     initialized with the characters of the multibyte character sequence, as encoded in UTF-8.
3464     For wide string literals prefixed by the letter L, the array elements have type wchar_t
3465     and are initialized with the sequence of wide characters corresponding to the multibyte
3466     character sequence, as defined by the mbstowcs function with an implementation-
3467     defined current locale. For wide string literals prefixed by the letter u or U, the array
3468     elements have type char16_t or char32_t, respectively, and are initialized with the
3469     sequence of wide characters corresponding to the multibyte character sequence, as
3470     defined by successive calls to the mbrtoc16, or mbrtoc32 function as appropriate for
3471     its type, with an implementation-defined current locale. The value of a string literal
3472     containing a multibyte character or escape sequence not represented in the execution
3473     character set is implementation-defined.
3474 7   It is unspecified whether these arrays are distinct provided their elements have the
3475     appropriate values. If the program attempts to modify such an array, the behavior is
3476     undefined.
3477 8   EXAMPLE 1      This pair of adjacent character string literals
3478              "\x12" "3"
3479     produces a single character string literal containing the two characters whose values are '\x12' and '3',
3480     because escape sequences are converted into single members of the execution character set just prior to
3481     adjacent string literal concatenation.
3482
3483 9   EXAMPLE 2      Each of the sequences of adjacent string literal tokens
3484
3485
3486
3487     78) A string literal need not be a string (see 7.1.1), because a null character may be embedded in it by a
3488         \0 escape sequence.
3489
3490 [page 71]
3491
3492              "a" "b" L"c"
3493              "a" L"b" "c"
3494              L"a" "b" L"c"
3495              L"a" L"b" L"c"
3496     is equivalent to the string literal
3497              L"abc"
3498     Likewise, each of the sequences
3499              "a" "b" u"c"
3500              "a" u"b" "c"
3501              u"a" "b" u"c"
3502              u"a" u"b" u"c"
3503     is equivalent to
3504              u"abc"
3505
3506     Forward references: common definitions <stddef.h> (7.19), the mbstowcs
3507     function (7.22.8.1), Unicode utilities <uchar.h> (7.27).
3508     6.4.6 Punctuators
3509     Syntax
3510 1            punctuator: one of
3511                     [ ] ( ) { } . ->
3512                     ++ -- & * + - ~ !
3513                     / % << >> < > <= >=                         ==    !=    ^    |   &&   ||
3514                     ? : ; ...
3515                     = *= /= %= += -= <<=                        >>=    &=       ^=   |=
3516                     , # ##
3517                     <: :> <% %> %: %:%:
3518     Semantics
3519 2   A punctuator is a symbol that has independent syntactic and semantic significance.
3520     Depending on context, it may specify an operation to be performed (which in turn may
3521     yield a value or a function designator, produce a side effect, or some combination thereof)
3522     in which case it is known as an operator (other forms of operator also exist in some
3523     contexts). An operand is an entity on which an operator acts.
3524
3525
3526
3527
3528 [page 72]
3529
3530 3   In all aspects of the language, the six tokens79)
3531              <:    :>      <%    %>     %:     %:%:
3532     behave, respectively, the same as the six tokens
3533              [     ]       {     }      #      ##
3534     except for their spelling.80)
3535     Forward references: expressions (6.5), declarations (6.7), preprocessing directives
3536     (6.10), statements (6.8).
3537     6.4.7 Header names
3538     Syntax
3539 1            header-name:
3540                     < h-char-sequence >
3541                     " q-char-sequence "
3542              h-char-sequence:
3543                     h-char
3544                     h-char-sequence h-char
3545              h-char:
3546                        any member of the source character set except
3547                                     the new-line character and >
3548              q-char-sequence:
3549                     q-char
3550                     q-char-sequence q-char
3551              q-char:
3552                        any member of the source character set except
3553                                     the new-line character and "
3554     Semantics
3555 2   The sequences in both forms of header names are mapped in an implementation-defined
3556     manner to headers or external source file names as specified in 6.10.2.
3557 3   If the characters ', \, ", //, or /* occur in the sequence between the < and > delimiters,
3558     the behavior is undefined. Similarly, if the characters ', \, //, or /* occur in the
3559
3560
3561
3562
3563     79) These tokens are sometimes called ''digraphs''.
3564     80) Thus [ and <: behave differently when ''stringized'' (see 6.10.3.2), but can otherwise be freely
3565         interchanged.
3566
3567 [page 73]
3568
3569     sequence between the " delimiters, the behavior is undefined.81) Header name
3570     preprocessing tokens are recognized only within #include preprocessing directives and
3571     in implementation-defined locations within #pragma directives.82)
3572 4   EXAMPLE       The following sequence of characters:
3573              0x3<1/a.h>1e2
3574              #include <1/a.h>
3575              #define const.member@$
3576     forms the following sequence of preprocessing tokens (with each individual preprocessing token delimited
3577     by a { on the left and a } on the right).
3578              {0x3}{<}{1}{/}{a}{.}{h}{>}{1e2}
3579              {#}{include} {<1/a.h>}
3580              {#}{define} {const}{.}{member}{@}{$}
3581
3582     Forward references: source file inclusion (6.10.2).
3583     6.4.8 Preprocessing numbers
3584     Syntax
3585 1            pp-number:
3586                    digit
3587                    . digit
3588                    pp-number       digit
3589                    pp-number       identifier-nondigit
3590                    pp-number       e sign
3591                    pp-number       E sign
3592                    pp-number       p sign
3593                    pp-number       P sign
3594                    pp-number       .
3595     Description
3596 2   A preprocessing number begins with a digit optionally preceded by a period (.) and may
3597     be followed by valid identifier characters and the character sequences e+, e-, E+, E-,
3598     p+, p-, P+, or P-.
3599 3   Preprocessing number tokens lexically include all floating and integer constant tokens.
3600     Semantics
3601 4   A preprocessing number does not have type or a value; it acquires both after a successful
3602     conversion (as part of translation phase 7) to a floating constant token or an integer
3603     constant token.
3604
3605
3606     81) Thus, sequences of characters that resemble escape sequences cause undefined behavior.
3607     82) For an example of a header name preprocessing token used in a #pragma directive, see 6.10.9.
3608
3609 [page 74]
3610
3611     6.4.9 Comments
3612 1   Except within a character constant, a string literal, or a comment, the characters /*
3613     introduce a comment. The contents of such a comment are examined only to identify
3614     multibyte characters and to find the characters */ that terminate it.83)
3615 2   Except within a character constant, a string literal, or a comment, the characters //
3616     introduce a comment that includes all multibyte characters up to, but not including, the
3617     next new-line character. The contents of such a comment are examined only to identify
3618     multibyte characters and to find the terminating new-line character.
3619 3   EXAMPLE
3620              "a//b"                             //   four-character string literal
3621              #include "//e"                     //   undefined behavior
3622              // */                              //   comment, not syntax error
3623              f = g/**//h;                       //   equivalent to f = g / h;
3624              //\
3625              i();                               // part of a two-line comment
3626              /\
3627              / j();                             // part of a two-line comment
3628              #define glue(x,y) x##y
3629              glue(/,/) k();                     // syntax error, not comment
3630              /*//*/ l();                        // equivalent to l();
3631              m = n//**/o
3632                 + p;                            // equivalent to m = n + p;
3633
3634
3635
3636
3637     83) Thus, /* ... */ comments do not nest.
3638
3639 [page 75]
3640
3641     6.5 Expressions
3642 1   An expression is a sequence of operators and operands that specifies computation of a
3643     value, or that designates an object or a function, or that generates side effects, or that
3644     performs a combination thereof. The value computations of the operands of an operator
3645     are sequenced before the value computation of the result of the operator.
3646 2   If a side effect on a scalar object is unsequenced relative to either a different side effect
3647     on the same scalar object or a value computation using the value of the same scalar
3648     object, the behavior is undefined. If there are multiple allowable orderings of the
3649     subexpressions of an expression, the behavior is undefined if such an unsequenced side
3650     effect occurs in any of the orderings.84)
3651 3   The grouping of operators and operands is indicated by the syntax.85) Except as specified
3652     later, side effects and value computations of subexpressions are unsequenced.86)         *
3653 4   Some operators (the unary operator ~, and the binary operators <<, >>, &, ^, and |,
3654     collectively described as bitwise operators) are required to have operands that have
3655     integer type. These operators yield values that depend on the internal representations of
3656     integers, and have implementation-defined and undefined aspects for signed types.
3657 5   If an exceptional condition occurs during the evaluation of an expression (that is, if the
3658     result is not mathematically defined or not in the range of representable values for its
3659     type), the behavior is undefined.
3660
3661
3662
3663     84) This paragraph renders undefined statement expressions such as
3664                   i = ++i + 1;
3665                   a[i++] = i;
3666          while allowing
3667                   i = i + 1;
3668                   a[i] = i;
3669
3670     85) The syntax specifies the precedence of operators in the evaluation of an expression, which is the same
3671         as the order of the major subclauses of this subclause, highest precedence first. Thus, for example, the
3672         expressions allowed as the operands of the binary + operator (6.5.6) are those expressions defined in
3673         6.5.1 through 6.5.6. The exceptions are cast expressions (6.5.4) as operands of unary operators
3674         (6.5.3), and an operand contained between any of the following pairs of operators: grouping
3675         parentheses () (6.5.1), subscripting brackets [] (6.5.2.1), function-call parentheses () (6.5.2.2), and
3676         the conditional operator ? : (6.5.15).
3677          Within each major subclause, the operators have the same precedence. Left- or right-associativity is
3678          indicated in each subclause by the syntax for the expressions discussed therein.
3679     86) In an expression that is evaluated more than once during the execution of a program, unsequenced and
3680         indeterminately sequenced evaluations of its subexpressions need not be performed consistently in
3681         different evaluations.
3682
3683 [page 76]
3684
3685 6   The effective type of an object for an access to its stored value is the declared type of the
3686     object, if any.87) If a value is stored into an object having no declared type through an
3687     lvalue having a type that is not a character type, then the type of the lvalue becomes the
3688     effective type of the object for that access and for subsequent accesses that do not modify
3689     the stored value. If a value is copied into an object having no declared type using
3690     memcpy or memmove, or is copied as an array of character type, then the effective type
3691     of the modified object for that access and for subsequent accesses that do not modify the
3692     value is the effective type of the object from which the value is copied, if it has one. For
3693     all other accesses to an object having no declared type, the effective type of the object is
3694     simply the type of the lvalue used for the access.
3695 7   An object shall have its stored value accessed only by an lvalue expression that has one of
3696     the following types:88)
3697     -- a type compatible with the effective type of the object,
3698     -- a qualified version of a type compatible with the effective type of the object,
3699     -- a type that is the signed or unsigned type corresponding to the effective type of the
3700       object,
3701     -- a type that is the signed or unsigned type corresponding to a qualified version of the
3702       effective type of the object,
3703     -- an aggregate or union type that includes one of the aforementioned types among its
3704       members (including, recursively, a member of a subaggregate or contained union), or
3705     -- a character type.
3706 8   A floating expression may be contracted, that is, evaluated as though it were a single
3707     operation, thereby omitting rounding errors implied by the source code and the
3708     expression evaluation method.89) The FP_CONTRACT pragma in <math.h> provides a
3709     way to disallow contracted expressions. Otherwise, whether and how expressions are
3710     contracted is implementation-defined.90)
3711     Forward references: the FP_CONTRACT pragma (7.12.2), copying functions (7.23.2).
3712
3713
3714     87) Allocated objects have no declared type.
3715     88) The intent of this list is to specify those circumstances in which an object may or may not be aliased.
3716     89) The intermediate operations in the contracted expression are evaluated as if to infinite precision and
3717         range, while the final operation is rounded to the format determined by the expression evaluation
3718         method. A contracted expression might also omit the raising of floating-point exceptions.
3719     90) This license is specifically intended to allow implementations to exploit fast machine instructions that
3720         combine multiple C operators. As contractions potentially undermine predictability, and can even
3721         decrease accuracy for containing expressions, their use needs to be well-defined and clearly
3722         documented.
3723
3724 [page 77]
3725
3726     6.5.1 Primary expressions
3727     Syntax
3728 1            primary-expression:
3729                     identifier
3730                     constant
3731                     string-literal
3732                     ( expression )
3733                     generic-selection
3734     Semantics
3735 2   An identifier is a primary expression, provided it has been declared as designating an
3736     object (in which case it is an lvalue) or a function (in which case it is a function
3737     designator).91)
3738 3   A constant is a primary expression. Its type depends on its form and value, as detailed in
3739     6.4.4.
3740 4   A string literal is a primary expression. It is an lvalue with type as detailed in 6.4.5.
3741 5   A parenthesized expression is a primary expression. Its type and value are identical to
3742     those of the unparenthesized expression. It is an lvalue, a function designator, or a void
3743     expression if the unparenthesized expression is, respectively, an lvalue, a function
3744     designator, or a void expression.
3745     Forward references: declarations (6.7).
3746     6.5.1.1 Generic selection
3747     Syntax
3748 1            generic-selection:
3749                     _Generic ( assignment-expression , generic-assoc-list )
3750              generic-assoc-list:
3751                     generic-association
3752                     generic-assoc-list , generic-association
3753              generic-association:
3754                     type-name : assignment-expression
3755                     default : assignment-expression
3756     Constraints
3757 2   A generic selection shall have no more than one default generic association. The type
3758     name in a generic association shall specify a complete object type other than a variably
3759
3760     91) Thus, an undeclared identifier is a violation of the syntax.
3761
3762 [page 78]
3763
3764     modified type. No two generic associations in the same generic selection shall specify
3765     compatible types. The controlling expression of a generic selection shall have type
3766     compatible with at most one of the types named in its generic association list. If a
3767     generic selection has no default generic association, its controlling expression shall
3768     have type compatible with exactly one of the types named in its generic association list.
3769     Semantics
3770 3   The controlling expression of a generic selection is not evaluated. If a generic selection
3771     has a generic association with a type name that is compatible with the type of the
3772     controlling expression, then the result expression of the generic selection is the
3773     expression in that generic association. Otherwise, the result expression of the generic
3774     selection is the expression in the default generic association. None of the expressions
3775     from any other generic association of the generic selection is evaluated.
3776 4   The type and value of a generic selection are identical to those of its result expression. It
3777     is an lvalue, a function designator, or a void expression if its result expression is,
3778     respectively, an lvalue, a function designator, or a void expression.
3779 5   EXAMPLE      The cbrt type-generic macro could be implemented as follows:
3780              #define cbrt(X) _Generic((X),                                      \
3781                                      long double: cbrtl,                        \
3782                                      default: cbrt,                             \
3783                                      float: cbrtf                               \
3784                                      )(X)
3785
3786     6.5.2 Postfix operators
3787     Syntax
3788 1            postfix-expression:
3789                     primary-expression
3790                     postfix-expression [ expression ]
3791                     postfix-expression ( argument-expression-listopt )
3792                     postfix-expression . identifier
3793                     postfix-expression -> identifier
3794                     postfix-expression ++
3795                     postfix-expression --
3796                     ( type-name ) { initializer-list }
3797                     ( type-name ) { initializer-list , }
3798              argument-expression-list:
3799                    assignment-expression
3800                    argument-expression-list , assignment-expression
3801
3802
3803
3804
3805 [page 79]
3806
3807     6.5.2.1 Array subscripting
3808     Constraints
3809 1   One of the expressions shall have type ''pointer to complete object type'', the other
3810     expression shall have integer type, and the result has type ''type''.
3811     Semantics
3812 2   A postfix expression followed by an expression in square brackets [] is a subscripted
3813     designation of an element of an array object. The definition of the subscript operator []
3814     is that E1[E2] is identical to (*((E1)+(E2))). Because of the conversion rules that
3815     apply to the binary + operator, if E1 is an array object (equivalently, a pointer to the
3816     initial element of an array object) and E2 is an integer, E1[E2] designates the E2-th
3817     element of E1 (counting from zero).
3818 3   Successive subscript operators designate an element of a multidimensional array object.
3819     If E is an n-dimensional array (n >= 2) with dimensions i x j x . . . x k, then E (used as
3820     other than an lvalue) is converted to a pointer to an (n - 1)-dimensional array with
3821     dimensions j x . . . x k. If the unary * operator is applied to this pointer explicitly, or
3822     implicitly as a result of subscripting, the result is the referenced (n - 1)-dimensional
3823     array, which itself is converted into a pointer if used as other than an lvalue. It follows
3824     from this that arrays are stored in row-major order (last subscript varies fastest).
3825 4   EXAMPLE        Consider the array object defined by the declaration
3826              int x[3][5];
3827     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
3828     array of five ints. In the expression x[i], which is equivalent to (*((x)+(i))), x is first converted to
3829     a pointer to the initial array of five ints. Then i is adjusted according to the type of x, which conceptually
3830     entails multiplying i by the size of the object to which the pointer points, namely an array of five int
3831     objects. The results are added and indirection is applied to yield an array of five ints. When used in the
3832     expression x[i][j], that array is in turn converted to a pointer to the first of the ints, so x[i][j]
3833     yields an int.
3834
3835     Forward references: additive operators (6.5.6), address and indirection operators
3836     (6.5.3.2), array declarators (6.7.6.2).
3837     6.5.2.2 Function calls
3838     Constraints
3839 1   The expression that denotes the called function92) shall have type pointer to function
3840     returning void or returning a complete object type other than an array type.
3841 2   If the expression that denotes the called function has a type that includes a prototype, the
3842     number of arguments shall agree with the number of parameters. Each argument shall
3843
3844
3845     92) Most often, this is the result of converting an identifier that is a function designator.
3846
3847 [page 80]
3848
3849     have a type such that its value may be assigned to an object with the unqualified version
3850     of the type of its corresponding parameter.
3851     Semantics
3852 3   A postfix expression followed by parentheses () containing a possibly empty, comma-
3853     separated list of expressions is a function call. The postfix expression denotes the called
3854     function. The list of expressions specifies the arguments to the function.
3855 4   An argument may be an expression of any complete object type. In preparing for the call
3856     to a function, the arguments are evaluated, and each parameter is assigned the value of the
3857     corresponding argument.93)
3858 5   If the expression that denotes the called function has type pointer to function returning an
3859     object type, the function call expression has the same type as that object type, and has the
3860     value determined as specified in 6.8.6.4. Otherwise, the function call has type void.         *
3861 6   If the expression that denotes the called function has a type that does not include a
3862     prototype, the integer promotions are performed on each argument, and arguments that
3863     have type float are promoted to double. These are called the default argument
3864     promotions. If the number of arguments does not equal the number of parameters, the
3865     behavior is undefined. If the function is defined with a type that includes a prototype, and
3866     either the prototype ends with an ellipsis (, ...) or the types of the arguments after
3867     promotion are not compatible with the types of the parameters, the behavior is undefined.
3868     If the function is defined with a type that does not include a prototype, and the types of
3869     the arguments after promotion are not compatible with those of the parameters after
3870     promotion, the behavior is undefined, except for the following cases:
3871     -- one promoted type is a signed integer type, the other promoted type is the
3872       corresponding unsigned integer type, and the value is representable in both types;
3873     -- both types are pointers to qualified or unqualified versions of a character type or
3874       void.
3875 7   If the expression that denotes the called function has a type that does include a prototype,
3876     the arguments are implicitly converted, as if by assignment, to the types of the
3877     corresponding parameters, taking the type of each parameter to be the unqualified version
3878     of its declared type. The ellipsis notation in a function prototype declarator causes
3879     argument type conversion to stop after the last declared parameter. The default argument
3880     promotions are performed on trailing arguments.
3881
3882
3883
3884     93) A function may change the values of its parameters, but these changes cannot affect the values of the
3885         arguments. On the other hand, it is possible to pass a pointer to an object, and the function may
3886         change the value of the object pointed to. A parameter declared to have array or function type is
3887         adjusted to have a pointer type as described in 6.9.1.
3888
3889 [page 81]
3890
3891 8    No other conversions are performed implicitly; in particular, the number and types of
3892      arguments are not compared with those of the parameters in a function definition that
3893      does not include a function prototype declarator.
3894 9    If the function is defined with a type that is not compatible with the type (of the
3895      expression) pointed to by the expression that denotes the called function, the behavior is
3896      undefined.
3897 10   There is a sequence point after the evaluations of the function designator and the actual
3898      arguments but before the actual call. Every evaluation in the calling function (including
3899      other function calls) that is not otherwise specifically sequenced before or after the
3900      execution of the body of the called function is indeterminately sequenced with respect to
3901      the execution of the called function.94)
3902 11   Recursive function calls shall be permitted, both directly and indirectly through any chain
3903      of other functions.
3904 12   EXAMPLE        In the function call
3905               (*pf[f1()]) (f2(), f3() + f4())
3906      the functions f1, f2, f3, and f4 may be called in any order. All side effects have to be completed before
3907      the function pointed to by pf[f1()] is called.
3908
3909      Forward references: function declarators (including prototypes) (6.7.6.3), function
3910      definitions (6.9.1), the return statement (6.8.6.4), simple assignment (6.5.16.1).
3911      6.5.2.3 Structure and union members
3912      Constraints
3913 1    The first operand of the . operator shall have an atomic, qualified, or unqualified
3914      structure or union type, and the second operand shall name a member of that type.
3915 2    The first operand of the -> operator shall have type ''pointer to atomic, qualified, or
3916      unqualified structure'' or ''pointer to atomic, qualified, or unqualified union'', and the
3917      second operand shall name a member of the type pointed to.
3918      Semantics
3919 3    A postfix expression followed by the . operator and an identifier designates a member of
3920      a structure or union object. The value is that of the named member,95) and is an lvalue if
3921      the first expression is an lvalue. If the first expression has qualified type, the result has
3922      the so-qualified version of the type of the designated member.
3923
3924      94) In other words, function executions do not ''interleave'' with each other.
3925      95) If the member used to read the contents of a union object is not the same as the member last used to
3926          store a value in the object, the appropriate part of the object representation of the value is reinterpreted
3927          as an object representation in the new type as described in 6.2.6 (a process sometimes called ''type
3928          punning''). This might be a trap representation.
3929
3930 [page 82]
3931
3932 4   A postfix expression followed by the -> operator and an identifier designates a member
3933     of a structure or union object. The value is that of the named member of the object to
3934     which the first expression points, and is an lvalue.96) If the first expression is a pointer to
3935     a qualified type, the result has the so-qualified version of the type of the designated
3936     member.
3937 5   Accessing a member of an atomic structure or union object results in undefined
3938     behavior.97)
3939 6   One special guarantee is made in order to simplify the use of unions: if a union contains
3940     several structures that share a common initial sequence (see below), and if the union
3941     object currently contains one of these structures, it is permitted to inspect the common
3942     initial part of any of them anywhere that a declaration of the completed type of the union
3943     is visible. Two structures share a common initial sequence if corresponding members
3944     have compatible types (and, for bit-fields, the same widths) for a sequence of one or more
3945     initial members.
3946 7   EXAMPLE 1 If f is a function returning a structure or union, and x is a member of that structure or
3947     union, f().x is a valid postfix expression but is not an lvalue.
3948
3949 8   EXAMPLE 2       In:
3950              struct s { int i; const int ci; };
3951              struct s s;
3952              const struct s cs;
3953              volatile struct s vs;
3954     the various members have the types:
3955              s.i          int
3956              s.ci         const int
3957              cs.i         const int
3958              cs.ci        const int
3959              vs.i         volatile int
3960              vs.ci        volatile const int
3961
3962
3963
3964
3965     96) If &E is a valid pointer expression (where & is the ''address-of '' operator, which generates a pointer to
3966         its operand), the expression (&E)->MOS is the same as E.MOS.
3967     97) For example, a data race would occur if access to the entire structure or union in one thread conflicts
3968         with access to a member from another thread, where at least one access is a modification. Members
3969         can be safely accessed using a non-atomic object which is assigned to or from the atomic object.
3970
3971 [page 83]
3972
3973 9   EXAMPLE 3       The following is a valid fragment:
3974              union {
3975                      struct {
3976                            int      alltypes;
3977                      } n;
3978                      struct {
3979                            int      type;
3980                            int      intnode;
3981                      } ni;
3982                      struct {
3983                            int      type;
3984                            double doublenode;
3985                      } nf;
3986              } u;
3987              u.nf.type = 1;
3988              u.nf.doublenode = 3.14;
3989              /* ... */
3990              if (u.n.alltypes == 1)
3991                      if (sin(u.nf.doublenode) == 0.0)
3992                            /* ... */
3993     The following is not a valid fragment (because the union type is not visible within function f):
3994              struct t1 { int m; };
3995              struct t2 { int m; };
3996              int f(struct t1 *p1, struct t2 *p2)
3997              {
3998                    if (p1->m < 0)
3999                            p2->m = -p2->m;
4000                    return p1->m;
4001              }
4002              int g()
4003              {
4004                    union {
4005                            struct t1 s1;
4006                            struct t2 s2;
4007                    } u;
4008                    /* ... */
4009                    return f(&u.s1, &u.s2);
4010              }
4011
4012     Forward references: address and indirection operators (6.5.3.2), structure and union
4013     specifiers (6.7.2.1).
4014
4015
4016
4017
4018 [page 84]
4019
4020     6.5.2.4 Postfix increment and decrement operators
4021     Constraints
4022 1   The operand of the postfix increment or decrement operator shall have atomic, qualified,
4023     or unqualified real or pointer type, and shall be a modifiable lvalue.
4024     Semantics
4025 2   The result of the postfix ++ operator is the value of the operand. As a side effect, the
4026     value of the operand object is incremented (that is, the value 1 of the appropriate type is
4027     added to it). See the discussions of additive operators and compound assignment for
4028     information on constraints, types, and conversions and the effects of operations on
4029     pointers. The value computation of the result is sequenced before the side effect of
4030     updating the stored value of the operand. With respect to an indeterminately-sequenced
4031     function call, the operation of postfix ++ is a single evaluation. Postfix ++ on an object
4032     with atomic type is a read-modify-write operation with memory_order_seq_cst
4033     memory order semantics.98)
4034 3   The postfix -- operator is analogous to the postfix ++ operator, except that the value of
4035     the operand is decremented (that is, the value 1 of the appropriate type is subtracted from
4036     it).
4037     Forward references: additive operators (6.5.6), compound assignment (6.5.16.2).
4038     6.5.2.5 Compound literals
4039     Constraints
4040 1   The type name shall specify a complete object type or an array of unknown size, but not a
4041     variable length array type.
4042 2   All the constraints for initializer lists in 6.7.9 also apply to compound literals.
4043     Semantics
4044 3   A postfix expression that consists of a parenthesized type name followed by a brace-
4045     enclosed list of initializers is a compound literal. It provides an unnamed object whose
4046     value is given by the initializer list.99)
4047
4048
4049     98) Where a pointer to an atomic object can be formed, this is equivalent to the following code sequence
4050         where T is the type of E:
4051                  T tmp;
4052                  T result = E;
4053                  do {
4054                         tmp = result + 1;
4055                  } while (!atomic_compare_exchange_strong(&E, &result, tmp));
4056          with result being the result of the operation.
4057
4058 [page 85]
4059
4060 4    If the type name specifies an array of unknown size, the size is determined by the
4061      initializer list as specified in 6.7.9, and the type of the compound literal is that of the
4062      completed array type. Otherwise (when the type name specifies an object type), the type
4063      of the compound literal is that specified by the type name. In either case, the result is an
4064      lvalue.
4065 5    The value of the compound literal is that of an unnamed object initialized by the
4066      initializer list. If the compound literal occurs outside the body of a function, the object
4067      has static storage duration; otherwise, it has automatic storage duration associated with
4068      the enclosing block.
4069 6    All the semantic rules for initializer lists in 6.7.9 also apply to compound literals.100)
4070 7    String literals, and compound literals with const-qualified types, need not designate
4071      distinct objects.101)
4072 8    EXAMPLE 1       The file scope definition
4073               int *p = (int []){2, 4};
4074      initializes p to point to the first element of an array of two ints, the first having the value two and the
4075      second, four. The expressions in this compound literal are required to be constant. The unnamed object
4076      has static storage duration.
4077
4078 9    EXAMPLE 2       In contrast, in
4079               void f(void)
4080               {
4081                     int *p;
4082                     /*...*/
4083                     p = (int [2]){*p};
4084                     /*...*/
4085               }
4086      p is assigned the address of the first element of an array of two ints, the first having the value previously
4087      pointed to by p and the second, zero. The expressions in this compound literal need not be constant. The
4088      unnamed object has automatic storage duration.
4089
4090 10   EXAMPLE 3 Initializers with designations can be combined with compound literals. Structure objects
4091      created using compound literals can be passed to functions without depending on member order:
4092               drawline((struct point){.x=1, .y=1},
4093                     (struct point){.x=3, .y=4});
4094      Or, if drawline instead expected pointers to struct point:
4095
4096
4097
4098      99) Note that this differs from a cast expression. For example, a cast specifies a conversion to scalar types
4099          or void only, and the result of a cast expression is not an lvalue.
4100      100) For example, subobjects without explicit initializers are initialized to zero.
4101      101) This allows implementations to share storage for string literals and constant compound literals with
4102           the same or overlapping representations.
4103
4104 [page 86]
4105
4106               drawline(&(struct point){.x=1, .y=1},
4107                     &(struct point){.x=3, .y=4});
4108
4109 11   EXAMPLE 4        A read-only compound literal can be specified through constructions like:
4110               (const float []){1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6}
4111
4112 12   EXAMPLE 5        The following three expressions have different meanings:
4113               "/tmp/fileXXXXXX"
4114               (char []){"/tmp/fileXXXXXX"}
4115               (const char []){"/tmp/fileXXXXXX"}
4116      The first always has static storage duration and has type array of char, but need not be modifiable; the last
4117      two have automatic storage duration when they occur within the body of a function, and the first of these
4118      two is modifiable.
4119
4120 13   EXAMPLE 6 Like string literals, const-qualified compound literals can be placed into read-only memory
4121      and can even be shared. For example,
4122               (const char []){"abc"} == "abc"
4123      might yield 1 if the literals' storage is shared.
4124
4125 14   EXAMPLE 7 Since compound literals are unnamed, a single compound literal cannot specify a circularly
4126      linked object. For example, there is no way to write a self-referential compound literal that could be used
4127      as the function argument in place of the named object endless_zeros below:
4128               struct int_list { int car; struct int_list *cdr; };
4129               struct int_list endless_zeros = {0, &endless_zeros};
4130               eval(endless_zeros);
4131
4132 15   EXAMPLE 8        Each compound literal creates only a single object in a given scope:
4133               struct s { int i; };
4134               int f (void)
4135               {
4136                     struct s *p = 0, *q;
4137                     int j = 0;
4138               again:
4139                         q = p, p = &((struct s){ j++ });
4140                         if (j < 2) goto again;
4141                         return p == q && q->i == 1;
4142               }
4143      The function f() always returns the value 1.
4144 16   Note that if an iteration statement were used instead of an explicit goto and a labeled statement, the
4145      lifetime of the unnamed object would be the body of the loop only, and on entry next time around p would
4146      have an indeterminate value, which would result in undefined behavior.
4147
4148      Forward references: type names (6.7.7), initialization (6.7.9).
4149
4150
4151
4152
4153 [page 87]
4154
4155     6.5.3 Unary operators
4156     Syntax
4157 1            unary-expression:
4158                     postfix-expression
4159                     ++ unary-expression
4160                     -- unary-expression
4161                     unary-operator cast-expression
4162                     sizeof unary-expression
4163                     sizeof ( type-name )
4164                     alignof ( type-name )
4165              unary-operator: one of
4166                     & * + - ~             !
4167     6.5.3.1 Prefix increment and decrement operators
4168     Constraints
4169 1   The operand of the prefix increment or decrement operator shall have atomic, qualified,
4170     or unqualified real or pointer type, and shall be a modifiable lvalue.
4171     Semantics
4172 2   The value of the operand of the prefix ++ operator is incremented. The result is the new
4173     value of the operand after incrementation. The expression ++E is equivalent to (E+=1).
4174     See the discussions of additive operators and compound assignment for information on
4175     constraints, types, side effects, and conversions and the effects of operations on pointers.
4176 3   The prefix -- operator is analogous to the prefix ++ operator, except that the value of the
4177     operand is decremented.
4178     Forward references: additive operators (6.5.6), compound assignment (6.5.16.2).
4179     6.5.3.2 Address and indirection operators
4180     Constraints
4181 1   The operand of the unary & operator shall be either a function designator, the result of a
4182     [] or unary * operator, or an lvalue that designates an object that is not a bit-field and is
4183     not declared with the register storage-class specifier.
4184 2   The operand of the unary * operator shall have pointer type.
4185     Semantics
4186 3   The unary & operator yields the address of its operand. If the operand has type ''type'',
4187     the result has type ''pointer to type''. If the operand is the result of a unary * operator,
4188     neither that operator nor the & operator is evaluated and the result is as if both were
4189     omitted, except that the constraints on the operators still apply and the result is not an
4190
4191 [page 88]
4192
4193     lvalue. Similarly, if the operand is the result of a [] operator, neither the & operator nor
4194     the unary * that is implied by the [] is evaluated and the result is as if the & operator
4195     were removed and the [] operator were changed to a + operator. Otherwise, the result is
4196     a pointer to the object or function designated by its operand.
4197 4   The unary * operator denotes indirection. If the operand points to a function, the result is
4198     a function designator; if it points to an object, the result is an lvalue designating the
4199     object. If the operand has type ''pointer to type'', the result has type ''type''. If an
4200     invalid value has been assigned to the pointer, the behavior of the unary * operator is
4201     undefined.102)
4202     Forward references: storage-class specifiers (6.7.1), structure and union specifiers
4203     (6.7.2.1).
4204     6.5.3.3 Unary arithmetic operators
4205     Constraints
4206 1   The operand of the unary + or - operator shall have arithmetic type; of the ~ operator,
4207     integer type; of the ! operator, scalar type.
4208     Semantics
4209 2   The result of the unary + operator is the value of its (promoted) operand. The integer
4210     promotions are performed on the operand, and the result has the promoted type.
4211 3   The result of the unary - operator is the negative of its (promoted) operand. The integer
4212     promotions are performed on the operand, and the result has the promoted type.
4213 4   The result of the ~ operator is the bitwise complement of its (promoted) operand (that is,
4214     each bit in the result is set if and only if the corresponding bit in the converted operand is
4215     not set). The integer promotions are performed on the operand, and the result has the
4216     promoted type. If the promoted type is an unsigned type, the expression ~E is equivalent
4217     to the maximum value representable in that type minus E.
4218 5   The result of the logical negation operator ! is 0 if the value of its operand compares
4219     unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int.
4220     The expression !E is equivalent to (0==E).
4221
4222
4223
4224     102) Thus, &*E is equivalent to E (even if E is a null pointer), and &(E1[E2]) to ((E1)+(E2)). It is
4225          always true that if E is a function designator or an lvalue that is a valid operand of the unary &
4226          operator, *&E is a function designator or an lvalue equal to E. If *P is an lvalue and T is the name of
4227          an object pointer type, *(T)P is an lvalue that has a type compatible with that to which T points.
4228          Among the invalid values for dereferencing a pointer by the unary * operator are a null pointer, an
4229          address inappropriately aligned for the type of object pointed to, and the address of an object after the
4230          end of its lifetime.
4231
4232 [page 89]
4233
4234     6.5.3.4 The sizeof and alignof operators
4235     Constraints
4236 1   The sizeof operator shall not be applied to an expression that has function type or an
4237     incomplete type, to the parenthesized name of such a type, or to an expression that
4238     designates a bit-field member. The alignof operator shall not be applied to a function
4239     type or an incomplete type.
4240     Semantics
4241 2   The sizeof operator yields the size (in bytes) of its operand, which may be an
4242     expression or the parenthesized name of a type. The size is determined from the type of
4243     the operand. The result is an integer. If the type of the operand is a variable length array
4244     type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an
4245     integer constant.
4246 3   The alignof operator yields the alignment requirement of its operand type. The result
4247     is an integer constant. When applied to an array type, the result is the alignment
4248     requirement of the element type.
4249 4   When sizeof is applied to an operand that has type char, unsigned char, or
4250     signed char, (or a qualified version thereof) the result is 1. When applied to an
4251     operand that has array type, the result is the total number of bytes in the array.103) When
4252     applied to an operand that has structure or union type, the result is the total number of
4253     bytes in such an object, including internal and trailing padding.
4254 5   The value of the result of both operators is implementation-defined, and its type (an
4255     unsigned integer type) is size_t, defined in <stddef.h> (and other headers).
4256 6   EXAMPLE 1 A principal use of the sizeof operator is in communication with routines such as storage
4257     allocators and I/O systems. A storage-allocation function might accept a size (in bytes) of an object to
4258     allocate and return a pointer to void. For example:
4259             extern void *alloc(size_t);
4260             double *dp = alloc(sizeof *dp);
4261     The implementation of the alloc function should ensure that its return value is aligned suitably for
4262     conversion to a pointer to double.
4263
4264 7   EXAMPLE 2      Another use of the sizeof operator is to compute the number of elements in an array:
4265             sizeof array / sizeof array[0]
4266
4267 8   EXAMPLE 3      In this example, the size of a variable length array is computed and returned from a
4268     function:
4269             #include <stddef.h>
4270
4271
4272
4273     103) When applied to a parameter declared to have array or function type, the sizeof operator yields the
4274          size of the adjusted (pointer) type (see 6.9.1).
4275
4276 [page 90]
4277
4278              size_t fsize3(int n)
4279              {
4280                    char b[n+3];                  // variable length array
4281                    return sizeof b;              // execution time sizeof
4282              }
4283              int main()
4284              {
4285                    size_t size;
4286                    size = fsize3(10); // fsize3 returns 13
4287                    return 0;
4288              }
4289
4290     Forward references: common definitions <stddef.h> (7.19), declarations (6.7),
4291     structure and union specifiers (6.7.2.1), type names (6.7.7), array declarators (6.7.6.2).
4292     6.5.4 Cast operators
4293     Syntax
4294 1            cast-expression:
4295                     unary-expression
4296                     ( type-name ) cast-expression
4297     Constraints
4298 2   Unless the type name specifies a void type, the type name shall specify atomic, qualified,
4299     or unqualified scalar type, and the operand shall have scalar type.
4300 3   Conversions that involve pointers, other than where permitted by the constraints of
4301     6.5.16.1, shall be specified by means of an explicit cast.
4302 4   A pointer type shall not be converted to any floating type. A floating type shall not be
4303     converted to any pointer type.
4304     Semantics
4305 5   Preceding an expression by a parenthesized type name converts the value of the
4306     expression to the named type. This construction is called a cast.104) A cast that specifies
4307     no conversion has no effect on the type or value of an expression.
4308 6   If the value of the expression is represented with greater precision or range than required
4309     by the type named by the cast (6.3.1.8), then the cast specifies a conversion even if the
4310     type of the expression is the same as the named type and removes any extra range and
4311     precision.
4312     Forward references: equality operators (6.5.9), function declarators (including
4313     prototypes) (6.7.6.3), simple assignment (6.5.16.1), type names (6.7.7).
4314
4315     104) A cast does not yield an lvalue. Thus, a cast to a qualified type has the same effect as a cast to the
4316          unqualified version of the type.
4317
4318 [page 91]
4319
4320     6.5.5 Multiplicative operators
4321     Syntax
4322 1            multiplicative-expression:
4323                      cast-expression
4324                      multiplicative-expression * cast-expression
4325                      multiplicative-expression / cast-expression
4326                      multiplicative-expression % cast-expression
4327     Constraints
4328 2   Each of the operands shall have arithmetic type. The operands of the % operator shall
4329     have integer type.
4330     Semantics
4331 3   The usual arithmetic conversions are performed on the operands.
4332 4   The result of the binary * operator is the product of the operands.
4333 5   The result of the / operator is the quotient from the division of the first operand by the
4334     second; the result of the % operator is the remainder. In both operations, if the value of
4335     the second operand is zero, the behavior is undefined.
4336 6   When integers are divided, the result of the / operator is the algebraic quotient with any
4337     fractional part discarded.105) If the quotient a/b is representable, the expression
4338     (a/b)*b + a%b shall equal a; otherwise, the behavior of both a/b and a%b is
4339     undefined.
4340     6.5.6 Additive operators
4341     Syntax
4342 1            additive-expression:
4343                     multiplicative-expression
4344                     additive-expression + multiplicative-expression
4345                     additive-expression - multiplicative-expression
4346     Constraints
4347 2   For addition, either both operands shall have arithmetic type, or one operand shall be a
4348     pointer to a complete object type and the other shall have integer type. (Incrementing is
4349     equivalent to adding 1.)
4350 3   For subtraction, one of the following shall hold:
4351
4352
4353
4354
4355     105) This is often called ''truncation toward zero''.
4356
4357 [page 92]
4358
4359     -- both operands have arithmetic type;
4360     -- both operands are pointers to qualified or unqualified versions of compatible complete
4361       object types; or
4362     -- the left operand is a pointer to a complete object type and the right operand has
4363       integer type.
4364     (Decrementing is equivalent to subtracting 1.)
4365     Semantics
4366 4   If both operands have arithmetic type, the usual arithmetic conversions are performed on
4367     them.
4368 5   The result of the binary + operator is the sum of the operands.
4369 6   The result of the binary - operator is the difference resulting from the subtraction of the
4370     second operand from the first.
4371 7   For the purposes of these operators, a pointer to an object that is not an element of an
4372     array behaves the same as a pointer to the first element of an array of length one with the
4373     type of the object as its element type.
4374 8   When an expression that has integer type is added to or subtracted from a pointer, the
4375     result has the type of the pointer operand. If the pointer operand points to an element of
4376     an array object, and the array is large enough, the result points to an element offset from
4377     the original element such that the difference of the subscripts of the resulting and original
4378     array elements equals the integer expression. In other words, if the expression P points to
4379     the i-th element of an array object, the expressions (P)+N (equivalently, N+(P)) and
4380     (P)-N (where N has the value n) point to, respectively, the i+n-th and i-n-th elements of
4381     the array object, provided they exist. Moreover, if the expression P points to the last
4382     element of an array object, the expression (P)+1 points one past the last element of the
4383     array object, and if the expression Q points one past the last element of an array object,
4384     the expression (Q)-1 points to the last element of the array object. If both the pointer
4385     operand and the result point to elements of the same array object, or one past the last
4386     element of the array object, the evaluation shall not produce an overflow; otherwise, the
4387     behavior is undefined. If the result points one past the last element of the array object, it
4388     shall not be used as the operand of a unary * operator that is evaluated.
4389 9   When two pointers are subtracted, both shall point to elements of the same array object,
4390     or one past the last element of the array object; the result is the difference of the
4391     subscripts of the two array elements. The size of the result is implementation-defined,
4392     and its type (a signed integer type) is ptrdiff_t defined in the <stddef.h> header.
4393     If the result is not representable in an object of that type, the behavior is undefined. In
4394     other words, if the expressions P and Q point to, respectively, the i-th and j-th elements of
4395     an array object, the expression (P)-(Q) has the value i-j provided the value fits in an
4396
4397 [page 93]
4398
4399      object of type ptrdiff_t. Moreover, if the expression P points either to an element of
4400      an array object or one past the last element of an array object, and the expression Q points
4401      to the last element of the same array object, the expression ((Q)+1)-(P) has the same
4402      value as ((Q)-(P))+1 and as -((P)-((Q)+1)), and has the value zero if the
4403      expression P points one past the last element of the array object, even though the
4404      expression (Q)+1 does not point to an element of the array object.106)
4405 10   EXAMPLE        Pointer arithmetic is well defined with pointers to variable length array types.
4406               {
4407                        int n = 4, m = 3;
4408                        int a[n][m];
4409                        int (*p)[m] = a;            //   p == &a[0]
4410                        p += 1;                     //   p == &a[1]
4411                        (*p)[2] = 99;               //   a[1][2] == 99
4412                        n = p - a;                  //   n == 1
4413               }
4414 11   If array a in the above example were declared to be an array of known constant size, and pointer p were
4415      declared to be a pointer to an array of the same known constant size (pointing to a), the results would be
4416      the same.
4417
4418      Forward references: array declarators (6.7.6.2), common definitions <stddef.h>
4419      (7.19).
4420      6.5.7 Bitwise shift operators
4421      Syntax
4422 1             shift-expression:
4423                       additive-expression
4424                       shift-expression << additive-expression
4425                       shift-expression >> additive-expression
4426      Constraints
4427 2    Each of the operands shall have integer type.
4428      Semantics
4429 3    The integer promotions are performed on each of the operands. The type of the result is
4430      that of the promoted left operand. If the value of the right operand is negative or is
4431
4432      106) Another way to approach pointer arithmetic is first to convert the pointer(s) to character pointer(s): In
4433           this scheme the integer expression added to or subtracted from the converted pointer is first multiplied
4434           by the size of the object originally pointed to, and the resulting pointer is converted back to the
4435           original type. For pointer subtraction, the result of the difference between the character pointers is
4436           similarly divided by the size of the object originally pointed to.
4437           When viewed in this way, an implementation need only provide one extra byte (which may overlap
4438           another object in the program) just after the end of the object in order to satisfy the ''one past the last
4439           element'' requirements.
4440
4441 [page 94]
4442
4443     greater than or equal to the width of the promoted left operand, the behavior is undefined.
4444 4   The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with
4445     zeros. If E1 has an unsigned type, the value of the result is E1 x 2E2 , reduced modulo
4446     one more than the maximum value representable in the result type. If E1 has a signed
4447     type and nonnegative value, and E1 x 2E2 is representable in the result type, then that is
4448     the resulting value; otherwise, the behavior is undefined.
4449 5   The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type
4450     or if E1 has a signed type and a nonnegative value, the value of the result is the integral
4451     part of the quotient of E1 / 2E2 . If E1 has a signed type and a negative value, the
4452     resulting value is implementation-defined.
4453     6.5.8 Relational operators
4454     Syntax
4455 1            relational-expression:
4456                      shift-expression
4457                      relational-expression   <    shift-expression
4458                      relational-expression   >    shift-expression
4459                      relational-expression   <=   shift-expression
4460                      relational-expression   >=   shift-expression
4461     Constraints
4462 2   One of the following shall hold:
4463     -- both operands have real type; or                                                            *
4464     -- both operands are pointers to qualified or unqualified versions of compatible object
4465       types.
4466     Semantics
4467 3   If both of the operands have arithmetic type, the usual arithmetic conversions are
4468     performed.
4469 4   For the purposes of these operators, a pointer to an object that is not an element of an
4470     array behaves the same as a pointer to the first element of an array of length one with the
4471     type of the object as its element type.
4472 5   When two pointers are compared, the result depends on the relative locations in the
4473     address space of the objects pointed to. If two pointers to object types both point to the
4474     same object, or both point one past the last element of the same array object, they
4475     compare equal. If the objects pointed to are members of the same aggregate object,
4476     pointers to structure members declared later compare greater than pointers to members
4477     declared earlier in the structure, and pointers to array elements with larger subscript
4478     values compare greater than pointers to elements of the same array with lower subscript
4479
4480 [page 95]
4481
4482     values. All pointers to members of the same union object compare equal. If the
4483     expression P points to an element of an array object and the expression Q points to the
4484     last element of the same array object, the pointer expression Q+1 compares greater than
4485     P. In all other cases, the behavior is undefined.
4486 6   Each of the operators < (less than), > (greater than), <= (less than or equal to), and >=
4487     (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is
4488     false.107) The result has type int.
4489     6.5.9 Equality operators
4490     Syntax
4491 1            equality-expression:
4492                     relational-expression
4493                     equality-expression == relational-expression
4494                     equality-expression != relational-expression
4495     Constraints
4496 2   One of the following shall hold:
4497     -- both operands have arithmetic type;
4498     -- both operands are pointers to qualified or unqualified versions of compatible types;
4499     -- one operand is a pointer to an object type and the other is a pointer to a qualified or
4500       unqualified version of void; or
4501     -- one operand is a pointer and the other is a null pointer constant.
4502     Semantics
4503 3   The == (equal to) and != (not equal to) operators are analogous to the relational
4504     operators except for their lower precedence.108) Each of the operators yields 1 if the
4505     specified relation is true and 0 if it is false. The result has type int. For any pair of
4506     operands, exactly one of the relations is true.
4507 4   If both of the operands have arithmetic type, the usual arithmetic conversions are
4508     performed. Values of complex types are equal if and only if both their real parts are equal
4509     and also their imaginary parts are equal. Any two values of arithmetic types from
4510     different type domains are equal if and only if the results of their conversions to the
4511     (complex) result type determined by the usual arithmetic conversions are equal.
4512
4513
4514
4515     107) The expression a<b<c is not interpreted as in ordinary mathematics. As the syntax indicates, it
4516          means (a<b)<c; in other words, ''if a is less than b, compare 1 to c; otherwise, compare 0 to c''.
4517     108) Because of the precedences, a<b == c<d is 1 whenever a<b and c<d have the same truth-value.
4518
4519 [page 96]
4520
4521 5   Otherwise, at least one operand is a pointer. If one operand is a pointer and the other is a
4522     null pointer constant, the null pointer constant is converted to the type of the pointer. If
4523     one operand is a pointer to an object type and the other is a pointer to a qualified or
4524     unqualified version of void, the former is converted to the type of the latter.
4525 6   Two pointers compare equal if and only if both are null pointers, both are pointers to the
4526     same object (including a pointer to an object and a subobject at its beginning) or function,
4527     both are pointers to one past the last element of the same array object, or one is a pointer
4528     to one past the end of one array object and the other is a pointer to the start of a different
4529     array object that happens to immediately follow the first array object in the address
4530     space.109)
4531 7   For the purposes of these operators, a pointer to an object that is not an element of an
4532     array behaves the same as a pointer to the first element of an array of length one with the
4533     type of the object as its element type.
4534     6.5.10 Bitwise AND operator
4535     Syntax
4536 1            AND-expression:
4537                    equality-expression
4538                    AND-expression & equality-expression
4539     Constraints
4540 2   Each of the operands shall have integer type.
4541     Semantics
4542 3   The usual arithmetic conversions are performed on the operands.
4543 4   The result of the binary & operator is the bitwise AND of the operands (that is, each bit in
4544     the result is set if and only if each of the corresponding bits in the converted operands is
4545     set).
4546
4547
4548
4549
4550     109) Two objects may be adjacent in memory because they are adjacent elements of a larger array or
4551          adjacent members of a structure with no padding between them, or because the implementation chose
4552          to place them so, even though they are unrelated. If prior invalid pointer operations (such as accesses
4553          outside array bounds) produced undefined behavior, subsequent comparisons also produce undefined
4554          behavior.
4555
4556 [page 97]
4557
4558     6.5.11 Bitwise exclusive OR operator
4559     Syntax
4560 1            exclusive-OR-expression:
4561                      AND-expression
4562                      exclusive-OR-expression ^ AND-expression
4563     Constraints
4564 2   Each of the operands shall have integer type.
4565     Semantics
4566 3   The usual arithmetic conversions are performed on the operands.
4567 4   The result of the ^ operator is the bitwise exclusive OR of the operands (that is, each bit
4568     in the result is set if and only if exactly one of the corresponding bits in the converted
4569     operands is set).
4570     6.5.12 Bitwise inclusive OR operator
4571     Syntax
4572 1            inclusive-OR-expression:
4573                      exclusive-OR-expression
4574                      inclusive-OR-expression | exclusive-OR-expression
4575     Constraints
4576 2   Each of the operands shall have integer type.
4577     Semantics
4578 3   The usual arithmetic conversions are performed on the operands.
4579 4   The result of the | operator is the bitwise inclusive OR of the operands (that is, each bit in
4580     the result is set if and only if at least one of the corresponding bits in the converted
4581     operands is set).
4582
4583
4584
4585
4586 [page 98]
4587
4588     6.5.13 Logical AND operator
4589     Syntax
4590 1            logical-AND-expression:
4591                      inclusive-OR-expression
4592                      logical-AND-expression && inclusive-OR-expression
4593     Constraints
4594 2   Each of the operands shall have scalar type.
4595     Semantics
4596 3   The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it
4597     yields 0. The result has type int.
4598 4   Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation;
4599     if the second operand is evaluated, there is a sequence point between the evaluations of
4600     the first and second operands. If the first operand compares equal to 0, the second
4601     operand is not evaluated.
4602     6.5.14 Logical OR operator
4603     Syntax
4604 1            logical-OR-expression:
4605                      logical-AND-expression
4606                      logical-OR-expression || logical-AND-expression
4607     Constraints
4608 2   Each of the operands shall have scalar type.
4609     Semantics
4610 3   The || operator shall yield 1 if either of its operands compare unequal to 0; otherwise, it
4611     yields 0. The result has type int.
4612 4   Unlike the bitwise | operator, the || operator guarantees left-to-right evaluation; if the
4613     second operand is evaluated, there is a sequence point between the evaluations of the first
4614     and second operands. If the first operand compares unequal to 0, the second operand is
4615     not evaluated.
4616
4617
4618
4619
4620 [page 99]
4621
4622     6.5.15 Conditional operator
4623     Syntax
4624 1            conditional-expression:
4625                     logical-OR-expression
4626                     logical-OR-expression ? expression : conditional-expression
4627     Constraints
4628 2   The first operand shall have scalar type.
4629 3   One of the following shall hold for the second and third operands:
4630     -- both operands have arithmetic type;
4631     -- both operands have the same structure or union type;
4632     -- both operands have void type;
4633     -- both operands are pointers to qualified or unqualified versions of compatible types;
4634     -- one operand is a pointer and the other is a null pointer constant; or
4635     -- one operand is a pointer to an object type and the other is a pointer to a qualified or
4636       unqualified version of void.
4637     Semantics
4638 4   The first operand is evaluated; there is a sequence point between its evaluation and the
4639     evaluation of the second or third operand (whichever is evaluated). The second operand
4640     is evaluated only if the first compares unequal to 0; the third operand is evaluated only if
4641     the first compares equal to 0; the result is the value of the second or third operand
4642     (whichever is evaluated), converted to the type described below.110)                        *
4643 5   If both the second and third operands have arithmetic type, the result type that would be
4644     determined by the usual arithmetic conversions, were they applied to those two operands,
4645     is the type of the result. If both the operands have structure or union type, the result has
4646     that type. If both operands have void type, the result has void type.
4647 6   If both the second and third operands are pointers or one is a null pointer constant and the
4648     other is a pointer, the result type is a pointer to a type qualified with all the type qualifiers
4649     of the types referenced by both operands. Furthermore, if both operands are pointers to
4650     compatible types or to differently qualified versions of compatible types, the result type is
4651     a pointer to an appropriately qualified version of the composite type; if one operand is a
4652     null pointer constant, the result has the type of the other operand; otherwise, one operand
4653     is a pointer to void or a qualified version of void, in which case the result type is a
4654     pointer to an appropriately qualified version of void.
4655
4656     110) A conditional expression does not yield an lvalue.
4657
4658 [page 100]
4659
4660 7   EXAMPLE The common type that results when the second and third operands are pointers is determined
4661     in two independent stages. The appropriate qualifiers, for example, do not depend on whether the two
4662     pointers have compatible types.
4663 8   Given the declarations
4664               const void *c_vp;
4665               void *vp;
4666               const int *c_ip;
4667               volatile int *v_ip;
4668               int *ip;
4669               const char *c_cp;
4670     the third column in the following table is the common type that is the result of a conditional expression in
4671     which the first two columns are the second and third operands (in either order):
4672               c_vp    c_ip      const void *
4673               v_ip    0         volatile int *
4674               c_ip    v_ip      const volatile int *
4675               vp      c_cp      const void *
4676               ip      c_ip      const int *
4677               vp      ip        void *
4678
4679     6.5.16 Assignment operators
4680     Syntax
4681 1            assignment-expression:
4682                     conditional-expression
4683                     unary-expression assignment-operator assignment-expression
4684              assignment-operator: one of
4685                     = *= /= %= +=                       -=     <<=      >>=      &=     ^=     |=
4686     Constraints
4687 2   An assignment operator shall have a modifiable lvalue as its left operand.
4688     Semantics
4689 3   An assignment operator stores a value in the object designated by the left operand. An
4690     assignment expression has the value of the left operand after the assignment,111) but is not
4691     an lvalue. The type of an assignment expression is the type the left operand would have
4692     after lvalue conversion. The side effect of updating the stored value of the left operand is
4693     sequenced after the value computations of the left and right operands. The evaluations of
4694     the operands are unsequenced.
4695
4696
4697
4698
4699     111) The implementation is permitted to read the object to determine the value but is not required to, even
4700          when the object has volatile-qualified type.
4701
4702 [page 101]
4703
4704     6.5.16.1 Simple assignment
4705     Constraints
4706 1   One of the following shall hold:112)
4707     -- the left operand has atomic, qualified, or unqualified arithmetic type, and the right has
4708       arithmetic type;
4709     -- the left operand has an atomic, qualified, or unqualified version of a structure or union
4710       type compatible with the type of the right;
4711     -- the left operand has atomic, qualified, or unqualified pointer type, and (considering
4712       the type the left operand would have after lvalue conversion) both operands are
4713       pointers to qualified or unqualified versions of compatible types, and the type pointed
4714       to by the left has all the qualifiers of the type pointed to by the right;
4715     -- the left operand has atomic, qualified, or unqualified pointer type, and (considering
4716       the type the left operand would have after lvalue conversion) one operand is a pointer
4717       to an object type, and the other is a pointer to a qualified or unqualified version of
4718       void, and the type pointed to by the left has all the qualifiers of the type pointed to
4719       by the right;
4720     -- the left operand is an atomic, qualified, or unqualified pointer, and the right is a null
4721       pointer constant; or
4722     -- the left operand has type atomic, qualified, or unqualified _Bool, and the right is a
4723       pointer.
4724     Semantics
4725 2   In simple assignment (=), the value of the right operand is converted to the type of the
4726     assignment expression and replaces the value stored in the object designated by the left
4727     operand.
4728 3   If the value being stored in an object is read from another object that overlaps in any way
4729     the storage of the first object, then the overlap shall be exact and the two objects shall
4730     have qualified or unqualified versions of a compatible type; otherwise, the behavior is
4731     undefined.
4732 4   EXAMPLE 1       In the program fragment
4733
4734
4735
4736
4737     112) The asymmetric appearance of these constraints with respect to type qualifiers is due to the conversion
4738          (specified in 6.3.2.1) that changes lvalues to ''the value of the expression'' and thus removes any type
4739          qualifiers that were applied to the type category of the expression (for example, it removes const but
4740          not volatile from the type int volatile * const).
4741
4742 [page 102]
4743
4744             int f(void);
4745             char c;
4746             /* ... */
4747             if ((c = f()) == -1)
4748                     /* ... */
4749     the int value returned by the function may be truncated when stored in the char, and then converted back
4750     to int width prior to the comparison. In an implementation in which ''plain'' char has the same range of
4751     values as unsigned char (and char is narrower than int), the result of the conversion cannot be
4752     negative, so the operands of the comparison can never compare equal. Therefore, for full portability, the
4753     variable c should be declared as int.
4754
4755 5   EXAMPLE 2       In the fragment:
4756             char c;
4757             int i;
4758             long l;
4759             l = (c = i);
4760     the value of i is converted to the type of the assignment expression c = i, that is, char type. The value
4761     of the expression enclosed in parentheses is then converted to the type of the outer assignment expression,
4762     that is, long int type.
4763
4764 6   EXAMPLE 3       Consider the fragment:
4765             const char **cpp;
4766             char *p;
4767             const char c = 'A';
4768             cpp = &p;                  // constraint violation
4769             *cpp = &c;                 // valid
4770             *p = 0;                    // valid
4771     The first assignment is unsafe because it would allow the following valid code to attempt to change the
4772     value of the const object c.
4773
4774     6.5.16.2 Compound assignment
4775     Constraints
4776 1   For the operators += and -= only, either the left operand shall be an atomic, qualified, or
4777     unqualified pointer to a complete object type, and the right shall have integer type; or the
4778     left operand shall have atomic, qualified, or unqualified arithmetic type, and the right
4779     shall have arithmetic type.
4780 2   For the other operators, the left operand shall have atomic, qualified, or unqualified
4781     arithmetic type, and (considering the type the left operand would have after lvalue
4782     conversion) each operand shall have arithmetic type consistent with those allowed by the
4783     corresponding binary operator.
4784     Semantics
4785 3   A compound assignment of the form E1 op = E2 is equivalent to the simple assignment
4786     expression E1 = E1 op (E2), except that the lvalue E1 is evaluated only once, and with
4787     respect to an indeterminately-sequenced function call, the operation of a compound
4788 [page 103]
4789
4790     assignment is a single evaluation. If E1 has an atomic type, compound assignment is a
4791     read-modify-write operation with memory_order_seq_cst memory order
4792     semantics.113)
4793     6.5.17 Comma operator
4794     Syntax
4795 1            expression:
4796                     assignment-expression
4797                     expression , assignment-expression
4798     Semantics
4799 2   The left operand of a comma operator is evaluated as a void expression; there is a
4800     sequence point between its evaluation and that of the right operand. Then the right
4801     operand is evaluated; the result has its type and value.114)                        *
4802 3   EXAMPLE As indicated by the syntax, the comma operator (as described in this subclause) cannot
4803     appear in contexts where a comma is used to separate items in a list (such as arguments to functions or lists
4804     of initializers). On the other hand, it can be used within a parenthesized expression or within the second
4805     expression of a conditional operator in such contexts. In the function call
4806              f(a, (t=3, t+2), c)
4807     the function has three arguments, the second of which has the value 5.
4808
4809     Forward references: initialization (6.7.9).
4810
4811
4812
4813
4814     113) Where a pointer to an atomic object can be formed, this is equivalent to the following code sequence
4815          where T is the type of E1:
4816                   T tmp = E1;
4817                   T result;
4818                   do {
4819                         result = tmp op (E2);
4820                   } while (!atomic_compare_exchange_strong(&E1, &tmp, result));
4821           with result being the result of the operation.
4822     114) A comma operator does not yield an lvalue.
4823
4824 [page 104]
4825
4826     6.6 Constant expressions
4827     Syntax
4828 1            constant-expression:
4829                     conditional-expression
4830     Description
4831 2   A constant expression can be evaluated during translation rather than runtime, and
4832     accordingly may be used in any place that a constant may be.
4833     Constraints
4834 3   Constant expressions shall not contain assignment, increment, decrement, function-call,
4835     or comma operators, except when they are contained within a subexpression that is not
4836     evaluated.115)
4837 4   Each constant expression shall evaluate to a constant that is in the range of representable
4838     values for its type.
4839     Semantics
4840 5   An expression that evaluates to a constant is required in several contexts. If a floating
4841     expression is evaluated in the translation environment, the arithmetic precision and range
4842     shall be at least as great as if the expression were being evaluated in the execution
4843     environment.116)
4844 6   An integer constant expression117) shall have integer type and shall only have operands
4845     that are integer constants, enumeration constants, character constants, sizeof
4846     expressions whose results are integer constants, and floating constants that are the
4847     immediate operands of casts. Cast operators in an integer constant expression shall only
4848     convert arithmetic types to integer types, except as part of an operand to the sizeof
4849     operator.
4850 7   More latitude is permitted for constant expressions in initializers. Such a constant
4851     expression shall be, or evaluate to, one of the following:
4852     -- an arithmetic constant expression,
4853
4854
4855
4856     115) The operand of a sizeof operator is usually not evaluated (6.5.3.4).
4857     116) The use of evaluation formats as characterized by FLT_EVAL_METHOD also applies to evaluation in
4858          the translation environment.
4859     117) An integer constant expression is required in a number of contexts such as the size of a bit-field
4860          member of a structure, the value of an enumeration constant, and the size of a non-variable length
4861          array. Further constraints that apply to the integer constant expressions used in conditional-inclusion
4862          preprocessing directives are discussed in 6.10.1.
4863
4864 [page 105]
4865
4866      -- a null pointer constant,
4867      -- an address constant, or
4868      -- an address constant for a complete object type plus or minus an integer constant
4869        expression.
4870 8    An arithmetic constant expression shall have arithmetic type and shall only have
4871      operands that are integer constants, floating constants, enumeration constants, character
4872      constants, and sizeof expressions. Cast operators in an arithmetic constant expression
4873      shall only convert arithmetic types to arithmetic types, except as part of an operand to a
4874      sizeof operator whose result is an integer constant.
4875 9    An address constant is a null pointer, a pointer to an lvalue designating an object of static
4876      storage duration, or a pointer to a function designator; it shall be created explicitly using
4877      the unary & operator or an integer constant cast to pointer type, or implicitly by the use of
4878      an expression of array or function type. The array-subscript [] and member-access .
4879      and -> operators, the address & and indirection * unary operators, and pointer casts may
4880      be used in the creation of an address constant, but the value of an object shall not be
4881      accessed by use of these operators.
4882 10   An implementation may accept other forms of constant expressions.
4883 11   The semantic rules for the evaluation of a constant expression are the same as for
4884      nonconstant expressions.118)
4885      Forward references: array declarators (6.7.6.2), initialization (6.7.9).
4886
4887
4888
4889
4890      118) Thus, in the following initialization,
4891                     static int i = 2 || 1 / 0;
4892            the expression is a valid integer constant expression with value one.
4893
4894 [page 106]
4895
4896     6.7 Declarations
4897     Syntax
4898 1            declaration:
4899                     declaration-specifiers init-declarator-listopt ;
4900                     static_assert-declaration
4901              declaration-specifiers:
4902                     storage-class-specifier declaration-specifiersopt
4903                     type-specifier declaration-specifiersopt
4904                     type-qualifier declaration-specifiersopt
4905                     function-specifier declaration-specifiersopt
4906                     alignment-specifier declaration-specifiersopt
4907              init-declarator-list:
4908                      init-declarator
4909                      init-declarator-list , init-declarator
4910              init-declarator:
4911                      declarator
4912                      declarator = initializer
4913     Constraints
4914 2   A declaration other than a static_assert declaration shall declare at least a declarator
4915     (other than the parameters of a function or the members of a structure or union), a tag, or
4916     the members of an enumeration.
4917 3   If an identifier has no linkage, there shall be no more than one declaration of the identifier
4918     (in a declarator or type specifier) with the same scope and in the same name space, except
4919     that a typedef name can be redefined to denote the same type as it currently does and tags
4920     may be redeclared as specified in 6.7.2.3.
4921 4   All declarations in the same scope that refer to the same object or function shall specify
4922     compatible types.
4923     Semantics
4924 5   A declaration specifies the interpretation and attributes of a set of identifiers. A definition
4925     of an identifier is a declaration for that identifier that:
4926     -- for an object, causes storage to be reserved for that object;
4927     -- for a function, includes the function body;119)
4928
4929
4930
4931     119) Function definitions have a different syntax, described in 6.9.1.
4932
4933 [page 107]
4934
4935     -- for an enumeration constant or typedef name, is the (only) declaration of the
4936       identifier.
4937 6   The declaration specifiers consist of a sequence of specifiers that indicate the linkage,
4938     storage duration, and part of the type of the entities that the declarators denote. The init-
4939     declarator-list is a comma-separated sequence of declarators, each of which may have
4940     additional type information, or an initializer, or both. The declarators contain the
4941     identifiers (if any) being declared.
4942 7   If an identifier for an object is declared with no linkage, the type for the object shall be
4943     complete by the end of its declarator, or by the end of its init-declarator if it has an
4944     initializer; in the case of function parameters (including in prototypes), it is the adjusted
4945     type (see 6.7.6.3) that is required to be complete.
4946     Forward references: declarators (6.7.6), enumeration specifiers (6.7.2.2), initialization
4947     (6.7.9), type names (6.7.7), type qualifiers (6.7.3).
4948     6.7.1 Storage-class specifiers
4949     Syntax
4950 1            storage-class-specifier:
4951                     typedef
4952                     extern
4953                     static
4954                     _Thread_local
4955                     auto
4956                     register
4957     Constraints
4958 2   At most, one storage-class specifier may be given in the declaration specifiers in a
4959     declaration, except that _Thread_local may appear with static or extern.120)
4960 3   In the declaration of an object with block scope, if the declaration specifiers include
4961     _Thread_local, they shall also include either static or extern. If
4962     _Thread_local appears in any declaration of an object, it shall be present in every
4963     declaration of that object.
4964     Semantics
4965 4   The typedef specifier is called a ''storage-class specifier'' for syntactic convenience
4966     only; it is discussed in 6.7.8. The meanings of the various linkages and storage durations
4967     were discussed in 6.2.2 and 6.2.4.
4968
4969
4970
4971     120) See ''future language directions'' (6.11.5).
4972
4973 [page 108]
4974
4975 5   A declaration of an identifier for an object with storage-class specifier register
4976     suggests that access to the object be as fast as possible. The extent to which such
4977     suggestions are effective is implementation-defined.121)
4978 6   The declaration of an identifier for a function that has block scope shall have no explicit
4979     storage-class specifier other than extern.
4980 7   If an aggregate or union object is declared with a storage-class specifier other than
4981     typedef, the properties resulting from the storage-class specifier, except with respect to
4982     linkage, also apply to the members of the object, and so on recursively for any aggregate
4983     or union member objects.
4984     Forward references: type definitions (6.7.8).
4985     6.7.2 Type specifiers
4986     Syntax
4987 1            type-specifier:
4988                     void
4989                     char
4990                     short
4991                     int
4992                     long
4993                     float
4994                     double
4995                     signed
4996                     unsigned
4997                     _Bool
4998                     _Complex
4999                     atomic-type-specifier
5000                     struct-or-union-specifier
5001                     enum-specifier
5002                     typedef-name
5003     Constraints
5004 2   At least one type specifier shall be given in the declaration specifiers in each declaration,
5005     and in the specifier-qualifier list in each struct declaration and type name. Each list of
5006
5007
5008     121) The implementation may treat any register declaration simply as an auto declaration. However,
5009          whether or not addressable storage is actually used, the address of any part of an object declared with
5010          storage-class specifier register cannot be computed, either explicitly (by use of the unary &
5011          operator as discussed in 6.5.3.2) or implicitly (by converting an array name to a pointer as discussed in
5012          6.3.2.1). Thus, the only operator that can be applied to an array declared with storage-class specifier
5013          register is sizeof.
5014
5015 [page 109]
5016
5017     type specifiers shall be one of the following multisets (delimited by commas, when there
5018     is more than one multiset per item); the type specifiers may occur in any order, possibly
5019     intermixed with the other declaration specifiers.
5020     -- void
5021     -- char
5022     -- signed char
5023     -- unsigned char
5024     -- short, signed short, short int, or signed short int
5025     -- unsigned short, or unsigned short int
5026     -- int, signed, or signed int
5027     -- unsigned, or unsigned int
5028     -- long, signed long, long int, or signed long int
5029     -- unsigned long, or unsigned long int
5030     -- long long, signed long long, long long int, or
5031       signed long long int
5032     -- unsigned long long, or unsigned long long int
5033     -- float
5034     -- double
5035     -- long double
5036     -- _Bool
5037     -- float _Complex
5038     -- double _Complex
5039     -- long double _Complex
5040     -- atomic type specifier
5041     -- struct or union specifier
5042     -- enum specifier
5043     -- typedef name
5044 3   The type specifier _Complex shall not be used if the implementation does not support
5045     complex types (see 6.10.8.3).
5046
5047
5048
5049
5050 [page 110]
5051
5052     Semantics
5053 4   Specifiers for structures, unions, enumerations, and atomic types are discussed in 6.7.2.1
5054     through 6.7.2.4. Declarations of typedef names are discussed in 6.7.8. The
5055     characteristics of the other types are discussed in 6.2.5.
5056 5   Each of the comma-separated multisets designates the same type, except that for bit-
5057     fields, it is implementation-defined whether the specifier int designates the same type as
5058     signed int or the same type as unsigned int.
5059     Forward references: atomic type specifiers (6.7.2.4), enumeration specifiers (6.7.2.2),
5060     structure and union specifiers (6.7.2.1), tags (6.7.2.3), type definitions (6.7.8).
5061     6.7.2.1 Structure and union specifiers
5062     Syntax
5063 1            struct-or-union-specifier:
5064                      struct-or-union identifieropt { struct-declaration-list }
5065                      struct-or-union identifier
5066              struct-or-union:
5067                      struct
5068                      union
5069              struct-declaration-list:
5070                      struct-declaration
5071                      struct-declaration-list struct-declaration
5072              struct-declaration:
5073                      specifier-qualifier-list struct-declarator-listopt ;
5074                      static_assert-declaration
5075              specifier-qualifier-list:
5076                     type-specifier specifier-qualifier-listopt
5077                     type-qualifier specifier-qualifier-listopt
5078              struct-declarator-list:
5079                      struct-declarator
5080                      struct-declarator-list , struct-declarator
5081              struct-declarator:
5082                      declarator
5083                      declaratoropt : constant-expression
5084     Constraints
5085 2   A struct-declaration that does not declare an anonymous structure or anonymous union
5086     shall contain a struct-declarator-list.
5087
5088
5089 [page 111]
5090
5091 3    A structure or union shall not contain a member with incomplete or function type (hence,
5092      a structure shall not contain an instance of itself, but may contain a pointer to an instance
5093      of itself), except that the last member of a structure with more than one named member
5094      may have incomplete array type; such a structure (and any union containing, possibly
5095      recursively, a member that is such a structure) shall not be a member of a structure or an
5096      element of an array.
5097 4    The expression that specifies the width of a bit-field shall be an integer constant
5098      expression with a nonnegative value that does not exceed the width of an object of the
5099      type that would be specified were the colon and expression omitted.122) If the value is
5100      zero, the declaration shall have no declarator.
5101 5    A bit-field shall have a type that is a qualified or unqualified version of _Bool, signed
5102      int, unsigned int, or some other implementation-defined type. It is
5103      implementation-defined whether atomic types are permitted.
5104      Semantics
5105 6    As discussed in 6.2.5, a structure is a type consisting of a sequence of members, whose
5106      storage is allocated in an ordered sequence, and a union is a type consisting of a sequence
5107      of members whose storage overlap.
5108 7    Structure and union specifiers have the same form. The keywords struct and union
5109      indicate that the type being specified is, respectively, a structure type or a union type.
5110 8    The presence of a struct-declaration-list in a struct-or-union-specifier declares a new type,
5111      within a translation unit. The struct-declaration-list is a sequence of declarations for the
5112      members of the structure or union. If the struct-declaration-list contains no named
5113      members, no anonymous structures, and no anonymous unions, the behavior is undefined.
5114      The type is incomplete until immediately after the } that terminates the list, and complete
5115      thereafter.
5116 9    A member of a structure or union may have any complete object type other than a
5117      variably modified type.123) In addition, a member may be declared to consist of a
5118      specified number of bits (including a sign bit, if any). Such a member is called a
5119      bit-field;124) its width is preceded by a colon.
5120 10   A bit-field is interpreted as having a signed or unsigned integer type consisting of the
5121      specified number of bits.125) If the value 0 or 1 is stored into a nonzero-width bit-field of
5122
5123      122) While the number of bits in a _Bool object is at least CHAR_BIT, the width (number of sign and
5124           value bits) of a _Bool may be just 1 bit.
5125      123) A structure or union cannot contain a member with a variably modified type because member names
5126           are not ordinary identifiers as defined in 6.2.3.
5127      124) The unary & (address-of) operator cannot be applied to a bit-field object; thus, there are no pointers to
5128           or arrays of bit-field objects.
5129
5130 [page 112]
5131
5132      type _Bool, the value of the bit-field shall compare equal to the value stored; a _Bool
5133      bit-field has the semantics of a _Bool.
5134 11   An implementation may allocate any addressable storage unit large enough to hold a bit-
5135      field. If enough space remains, a bit-field that immediately follows another bit-field in a
5136      structure shall be packed into adjacent bits of the same unit. If insufficient space remains,
5137      whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is
5138      implementation-defined. The order of allocation of bit-fields within a unit (high-order to
5139      low-order or low-order to high-order) is implementation-defined. The alignment of the
5140      addressable storage unit is unspecified.
5141 12   A bit-field declaration with no declarator, but only a colon and a width, indicates an
5142      unnamed bit-field.126) As a special case, a bit-field structure member with a width of 0
5143      indicates that no further bit-field is to be packed into the unit in which the previous bit-
5144      field, if any, was placed.
5145 13   An unnamed member of structure type with no tag is called an anonymous structure; an
5146      unnamed member of union type with no tag is called an anonymous union. The members
5147      of an anonymous structure or union are considered to be members of the containing
5148      structure or union. This applies recursively if the containing structure or union is also
5149      anonymous.
5150 14   Each non-bit-field member of a structure or union object is aligned in an implementation-
5151      defined manner appropriate to its type.
5152 15   Within a structure object, the non-bit-field members and the units in which bit-fields
5153      reside have addresses that increase in the order in which they are declared. A pointer to a
5154      structure object, suitably converted, points to its initial member (or if that member is a
5155      bit-field, then to the unit in which it resides), and vice versa. There may be unnamed
5156      padding within a structure object, but not at its beginning.
5157 16   The size of a union is sufficient to contain the largest of its members. The value of at
5158      most one of the members can be stored in a union object at any time. A pointer to a
5159      union object, suitably converted, points to each of its members (or if a member is a bit-
5160      field, then to the unit in which it resides), and vice versa.
5161 17   There may be unnamed padding at the end of a structure or union.
5162 18   As a special case, the last element of a structure with more than one named member may
5163      have an incomplete array type; this is called a flexible array member. In most situations,
5164
5165
5166      125) As specified in 6.7.2 above, if the actual type specifier used is int or a typedef-name defined as int,
5167           then it is implementation-defined whether the bit-field is signed or unsigned.
5168      126) An unnamed bit-field structure member is useful for padding to conform to externally imposed
5169           layouts.
5170
5171 [page 113]
5172
5173      the flexible array member is ignored. In particular, the size of the structure is as if the
5174      flexible array member were omitted except that it may have more trailing padding than
5175      the omission would imply. However, when a . (or ->) operator has a left operand that is
5176      (a pointer to) a structure with a flexible array member and the right operand names that
5177      member, it behaves as if that member were replaced with the longest array (with the same
5178      element type) that would not make the structure larger than the object being accessed; the
5179      offset of the array shall remain that of the flexible array member, even if this would differ
5180      from that of the replacement array. If this array would have no elements, it behaves as if
5181      it had one element but the behavior is undefined if any attempt is made to access that
5182      element or to generate a pointer one past it.
5183 19   EXAMPLE 1       The following illustrates anonymous structures and unions:
5184               struct v {
5185                     union {      // anonymous union
5186                            struct { int i, j; };    // anonymous structure
5187                            struct { long k, l; } w;
5188                     };
5189                     int m;
5190               } v1;
5191               v1.i = 2;   // valid
5192               v1.k = 3;   // invalid: inner structure is not anonymous
5193               v1.w.k = 5; // valid
5194
5195 20   EXAMPLE 2       After the declaration:
5196               struct s { int n; double d[]; };
5197      the structure struct s has a flexible array member d. A typical way to use this is:
5198               int m = /* some value */;
5199               struct s *p = malloc(sizeof (struct s) + sizeof (double [m]));
5200      and assuming that the call to malloc succeeds, the object pointed to by p behaves, for most purposes, as if
5201      p had been declared as:
5202               struct { int n; double d[m]; } *p;
5203      (there are circumstances in which this equivalence is broken; in particular, the offsets of member d might
5204      not be the same).
5205 21   Following the above declaration:
5206               struct s t1 = { 0 };                         //   valid
5207               struct s t2 = { 1, { 4.2 }};                 //   invalid
5208               t1.n = 4;                                    //   valid
5209               t1.d[0] = 4.2;                               //   might be undefined behavior
5210      The initialization of t2 is invalid (and violates a constraint) because struct s is treated as if it did not
5211      contain member d. The assignment to t1.d[0] is probably undefined behavior, but it is possible that
5212               sizeof (struct s) >= offsetof(struct s, d) + sizeof (double)
5213      in which case the assignment would be legitimate. Nevertheless, it cannot appear in strictly conforming
5214      code.
5215
5216 [page 114]
5217
5218 22   After the further declaration:
5219               struct ss { int n; };
5220      the expressions:
5221               sizeof (struct s) >= sizeof (struct ss)
5222               sizeof (struct s) >= offsetof(struct s, d)
5223      are always equal to 1.
5224 23   If sizeof (double) is 8, then after the following code is executed:
5225               struct s *s1;
5226               struct s *s2;
5227               s1 = malloc(sizeof (struct s) + 64);
5228               s2 = malloc(sizeof (struct s) + 46);
5229      and assuming that the calls to malloc succeed, the objects pointed to by s1 and s2 behave, for most
5230      purposes, as if the identifiers had been declared as:
5231               struct { int n; double d[8]; } *s1;
5232               struct { int n; double d[5]; } *s2;
5233 24   Following the further successful assignments:
5234               s1 = malloc(sizeof (struct s) + 10);
5235               s2 = malloc(sizeof (struct s) + 6);
5236      they then behave as if the declarations were:
5237               struct { int n; double d[1]; } *s1, *s2;
5238      and:
5239               double *dp;
5240               dp = &(s1->d[0]);          //   valid
5241               *dp = 42;                  //   valid
5242               dp = &(s2->d[0]);          //   valid
5243               *dp = 42;                  //   undefined behavior
5244 25   The assignment:
5245               *s1 = *s2;
5246      only copies the member n; if any of the array elements are within the first sizeof (struct s) bytes
5247      of the structure, they might be copied or simply overwritten with indeterminate values.
5248
5249      Forward references: declarators (6.7.6), tags (6.7.2.3).
5250
5251
5252
5253
5254 [page 115]
5255
5256     6.7.2.2 Enumeration specifiers
5257     Syntax
5258 1            enum-specifier:
5259                    enum identifieropt { enumerator-list }
5260                    enum identifieropt { enumerator-list , }
5261                    enum identifier
5262              enumerator-list:
5263                    enumerator
5264                    enumerator-list , enumerator
5265              enumerator:
5266                    enumeration-constant
5267                    enumeration-constant = constant-expression
5268     Constraints
5269 2   The expression that defines the value of an enumeration constant shall be an integer
5270     constant expression that has a value representable as an int.
5271     Semantics
5272 3   The identifiers in an enumerator list are declared as constants that have type int and
5273     may appear wherever such are permitted.127) An enumerator with = defines its
5274     enumeration constant as the value of the constant expression. If the first enumerator has
5275     no =, the value of its enumeration constant is 0. Each subsequent enumerator with no =
5276     defines its enumeration constant as the value of the constant expression obtained by
5277     adding 1 to the value of the previous enumeration constant. (The use of enumerators with
5278     = may produce enumeration constants with values that duplicate other values in the same
5279     enumeration.) The enumerators of an enumeration are also known as its members.
5280 4   Each enumerated type shall be compatible with char, a signed integer type, or an
5281     unsigned integer type. The choice of type is implementation-defined,128) but shall be
5282     capable of representing the values of all the members of the enumeration. The
5283     enumerated type is incomplete until immediately after the } that terminates the list of
5284     enumerator declarations, and complete thereafter.
5285
5286
5287
5288
5289     127) Thus, the identifiers of enumeration constants declared in the same scope shall all be distinct from
5290          each other and from other identifiers declared in ordinary declarators.
5291     128) An implementation may delay the choice of which integer type until all enumeration constants have
5292          been seen.
5293
5294 [page 116]
5295
5296 5   EXAMPLE       The following fragment:
5297              enum hue { chartreuse, burgundy, claret=20, winedark };
5298              enum hue col, *cp;
5299              col = claret;
5300              cp = &col;
5301              if (*cp != burgundy)
5302                    /* ... */
5303     makes hue the tag of an enumeration, and then declares col as an object that has that type and cp as a
5304     pointer to an object that has that type. The enumerated values are in the set { 0, 1, 20, 21 }.
5305
5306     Forward references: tags (6.7.2.3).
5307     6.7.2.3 Tags
5308     Constraints
5309 1   A specific type shall have its content defined at most once.
5310 2   Where two declarations that use the same tag declare the same type, they shall both use
5311     the same choice of struct, union, or enum.
5312 3   A type specifier of the form
5313             enum identifier
5314     without an enumerator list shall only appear after the type it specifies is complete.
5315     Semantics
5316 4   All declarations of structure, union, or enumerated types that have the same scope and
5317     use the same tag declare the same type. Irrespective of whether there is a tag or what
5318     other declarations of the type are in the same translation unit, the type is incomplete129)
5319     until immediately after the closing brace of the list defining the content, and complete
5320     thereafter.
5321 5   Two declarations of structure, union, or enumerated types which are in different scopes or
5322     use different tags declare distinct types. Each declaration of a structure, union, or
5323     enumerated type which does not include a tag declares a distinct type.
5324 6   A type specifier of the form
5325
5326
5327
5328
5329     129) An incomplete type may only by used when the size of an object of that type is not needed. It is not
5330          needed, for example, when a typedef name is declared to be a specifier for a structure or union, or
5331          when a pointer to or a function returning a structure or union is being declared. (See incomplete types
5332          in 6.2.5.) The specification has to be complete before such a function is called or defined.
5333
5334 [page 117]
5335
5336               struct-or-union identifieropt { struct-declaration-list }
5337      or
5338               enum identifieropt { enumerator-list }
5339      or
5340               enum identifieropt { enumerator-list , }
5341      declares a structure, union, or enumerated type. The list defines the structure content,
5342      union content, or enumeration content. If an identifier is provided,130) the type specifier
5343      also declares the identifier to be the tag of that type.
5344 7    A declaration of the form
5345               struct-or-union identifier ;
5346      specifies a structure or union type and declares the identifier as a tag of that type.131)
5347 8    If a type specifier of the form
5348               struct-or-union identifier
5349      occurs other than as part of one of the above forms, and no other declaration of the
5350      identifier as a tag is visible, then it declares an incomplete structure or union type, and
5351      declares the identifier as the tag of that type.131)
5352 9    If a type specifier of the form
5353               struct-or-union identifier
5354      or
5355               enum identifier
5356      occurs other than as part of one of the above forms, and a declaration of the identifier as a
5357      tag is visible, then it specifies the same type as that other declaration, and does not
5358      redeclare the tag.
5359 10   EXAMPLE 1       This mechanism allows declaration of a self-referential structure.
5360               struct tnode {
5361                     int count;
5362                     struct tnode *left, *right;
5363               };
5364      specifies a structure that contains an integer and two pointers to objects of the same type. Once this
5365      declaration has been given, the declaration
5366
5367
5368
5369
5370      130) If there is no identifier, the type can, within the translation unit, only be referred to by the declaration
5371           of which it is a part. Of course, when the declaration is of a typedef name, subsequent declarations
5372           can make use of that typedef name to declare objects having the specified structure, union, or
5373           enumerated type.
5374      131) A similar construction with enum does not exist.
5375
5376 [page 118]
5377
5378               struct tnode s, *sp;
5379      declares s to be an object of the given type and sp to be a pointer to an object of the given type. With
5380      these declarations, the expression sp->left refers to the left struct tnode pointer of the object to
5381      which sp points; the expression s.right->count designates the count member of the right struct
5382      tnode pointed to from s.
5383 11   The following alternative formulation uses the typedef mechanism:
5384               typedef struct tnode TNODE;
5385               struct tnode {
5386                     int count;
5387                     TNODE *left, *right;
5388               };
5389               TNODE s, *sp;
5390
5391 12   EXAMPLE 2 To illustrate the use of prior declaration of a tag to specify a pair of mutually referential
5392      structures, the declarations
5393               struct s1 { struct s2 *s2p; /* ... */ }; // D1
5394               struct s2 { struct s1 *s1p; /* ... */ }; // D2
5395      specify a pair of structures that contain pointers to each other. Note, however, that if s2 were already
5396      declared as a tag in an enclosing scope, the declaration D1 would refer to it, not to the tag s2 declared in
5397      D2. To eliminate this context sensitivity, the declaration
5398               struct s2;
5399      may be inserted ahead of D1. This declares a new tag s2 in the inner scope; the declaration D2 then
5400      completes the specification of the new type.
5401
5402      Forward references: declarators (6.7.6), type definitions (6.7.8).
5403      6.7.2.4 Atomic type specifiers
5404      Syntax
5405 1             atomic-type-specifier:
5406                      _Atomic ( type-name )
5407      Constraints
5408 2    Atomic type specifiers shall not be used if the implementation does not support atomic
5409      types (see 6.10.8.3).
5410 3    The type name in an atomic type specifier shall not refer to an array type, a function type,
5411      an atomic type, or a qualified type.
5412      Semantics
5413 4    The properties associated with atomic types are meaningful only for expressions that are
5414      lvalues. If the _Atomic keyword is immediately followed by a left parenthesis, it is
5415      interpreted as a type specifier (with a type name), not as a type qualifier.
5416
5417
5418
5419
5420 [page 119]
5421
5422     6.7.3 Type qualifiers
5423     Syntax
5424 1            type-qualifier:
5425                     const
5426                     restrict
5427                     volatile
5428                     _Atomic
5429     Constraints
5430 2   Types other than pointer types whose referenced type is an object type shall not be
5431     restrict-qualified.
5432 3   The type modified by the _Atomic qualifier shall not be an array type or a function
5433     type.
5434     Semantics
5435 4   The properties associated with qualified types are meaningful only for expressions that
5436     are lvalues.132)
5437 5   If the same qualifier appears more than once in the same specifier-qualifier-list, either
5438     directly or via one or more typedefs, the behavior is the same as if it appeared only
5439     once. If other qualifiers appear along with the _Atomic qualifier in a specifier-qualifier-
5440     list, the resulting type is the so-qualified atomic type.
5441 6   If an attempt is made to modify an object defined with a const-qualified type through use
5442     of an lvalue with non-const-qualified type, the behavior is undefined. If an attempt is
5443     made to refer to an object defined with a volatile-qualified type through use of an lvalue
5444     with non-volatile-qualified type, the behavior is undefined.133)
5445 7   An object that has volatile-qualified type may be modified in ways unknown to the
5446     implementation or have other unknown side effects. Therefore any expression referring
5447     to such an object shall be evaluated strictly according to the rules of the abstract machine,
5448     as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the
5449     object shall agree with that prescribed by the abstract machine, except as modified by the
5450
5451
5452
5453
5454     132) The implementation may place a const object that is not volatile in a read-only region of
5455          storage. Moreover, the implementation need not allocate storage for such an object if its address is
5456          never used.
5457     133) This applies to those objects that behave as if they were defined with qualified types, even if they are
5458          never actually defined as objects in the program (such as an object at a memory-mapped input/output
5459          address).
5460
5461 [page 120]
5462
5463      unknown factors mentioned previously.134) What constitutes an access to an object that
5464      has volatile-qualified type is implementation-defined.
5465 8    An object that is accessed through a restrict-qualified pointer has a special association
5466      with that pointer. This association, defined in 6.7.3.1 below, requires that all accesses to
5467      that object use, directly or indirectly, the value of that particular pointer.135) The intended
5468      use of the restrict qualifier (like the register storage class) is to promote
5469      optimization, and deleting all instances of the qualifier from all preprocessing translation
5470      units composing a conforming program does not change its meaning (i.e., observable
5471      behavior).
5472 9    If the specification of an array type includes any type qualifiers, the element type is so-
5473      qualified, not the array type. If the specification of a function type includes any type
5474      qualifiers, the behavior is undefined.136)
5475 10   For two qualified types to be compatible, both shall have the identically qualified version
5476      of a compatible type; the order of type qualifiers within a list of specifiers or qualifiers
5477      does not affect the specified type.
5478 11   EXAMPLE 1      An object declared
5479               extern const volatile int real_time_clock;
5480      may be modifiable by hardware, but cannot be assigned to, incremented, or decremented.
5481
5482 12   EXAMPLE 2 The following declarations and expressions illustrate the behavior when type qualifiers
5483      modify an aggregate type:
5484               const struct s { int mem; } cs = { 1 };
5485               struct s ncs; // the object ncs is modifiable
5486               typedef int A[2][3];
5487               const A a = {{4, 5, 6}, {7, 8, 9}}; // array of array of const int
5488               int *pi;
5489               const int *pci;
5490               ncs = cs;            //    valid
5491               cs = ncs;            //    violates modifiable lvalue constraint for =
5492               pi = &ncs.mem;       //    valid
5493               pi = &cs.mem;        //    violates type constraints for =
5494               pci = &cs.mem;       //    valid
5495               pi = a[0];           //    invalid: a[0] has type ''const int *''
5496
5497
5498
5499      134) A volatile declaration may be used to describe an object corresponding to a memory-mapped
5500           input/output port or an object accessed by an asynchronously interrupting function. Actions on
5501           objects so declared shall not be ''optimized out'' by an implementation or reordered except as
5502           permitted by the rules for evaluating expressions.
5503      135) For example, a statement that assigns a value returned by malloc to a single pointer establishes this
5504           association between the allocated object and the pointer.
5505      136) Both of these can occur through the use of typedefs.
5506
5507 [page 121]
5508
5509 13   EXAMPLE 3       The declaration
5510               _Atomic volatile int *p;
5511      specifies that p has the type ''pointer to volatile atomic int'', a pointer to a volatile-qualified atomic type.
5512
5513      6.7.3.1 Formal definition of restrict
5514 1    Let D be a declaration of an ordinary identifier that provides a means of designating an
5515      object P as a restrict-qualified pointer to type T.
5516 2    If D appears inside a block and does not have storage class extern, let B denote the
5517      block. If D appears in the list of parameter declarations of a function definition, let B
5518      denote the associated block. Otherwise, let B denote the block of main (or the block of
5519      whatever function is called at program startup in a freestanding environment).
5520 3    In what follows, a pointer expression E is said to be based on object P if (at some
5521      sequence point in the execution of B prior to the evaluation of E) modifying P to point to
5522      a copy of the array object into which it formerly pointed would change the value of E.137)
5523      Note that ''based'' is defined only for expressions with pointer types.
5524 4    During each execution of B, let L be any lvalue that has &L based on P. If L is used to
5525      access the value of the object X that it designates, and X is also modified (by any means),
5526      then the following requirements apply: T shall not be const-qualified. Every other lvalue
5527      used to access the value of X shall also have its address based on P. Every access that
5528      modifies X shall be considered also to modify P, for the purposes of this subclause. If P
5529      is assigned the value of a pointer expression E that is based on another restricted pointer
5530      object P2, associated with block B2, then either the execution of B2 shall begin before
5531      the execution of B, or the execution of B2 shall end prior to the assignment. If these
5532      requirements are not met, then the behavior is undefined.
5533 5    Here an execution of B means that portion of the execution of the program that would
5534      correspond to the lifetime of an object with scalar type and automatic storage duration
5535      associated with B.
5536 6    A translator is free to ignore any or all aliasing implications of uses of restrict.
5537 7    EXAMPLE 1       The file scope declarations
5538               int * restrict a;
5539               int * restrict b;
5540               extern int c[];
5541      assert that if an object is accessed using one of a, b, or c, and that object is modified anywhere in the
5542      program, then it is never accessed using either of the other two.
5543
5544
5545      137) In other words, E depends on the value of P itself rather than on the value of an object referenced
5546           indirectly through P. For example, if identifier p has type (int **restrict), then the pointer
5547           expressions p and p+1 are based on the restricted pointer object designated by p, but the pointer
5548           expressions *p and p[1] are not.
5549
5550 [page 122]
5551
5552 8    EXAMPLE 2       The function parameter declarations in the following example
5553              void f(int n, int * restrict p, int * restrict q)
5554              {
5555                    while (n-- > 0)
5556                          *p++ = *q++;
5557              }
5558      assert that, during each execution of the function, if an object is accessed through one of the pointer
5559      parameters, then it is not also accessed through the other.
5560 9    The benefit of the restrict qualifiers is that they enable a translator to make an effective dependence
5561      analysis of function f without examining any of the calls of f in the program. The cost is that the
5562      programmer has to examine all of those calls to ensure that none give undefined behavior. For example, the
5563      second call of f in g has undefined behavior because each of d[1] through d[49] is accessed through
5564      both p and q.
5565               void g(void)
5566               {
5567                     extern int d[100];
5568                     f(50, d + 50, d); // valid
5569                     f(50, d + 1, d); // undefined behavior
5570               }
5571
5572 10   EXAMPLE 3       The function parameter declarations
5573              void h(int n, int * restrict p, int * restrict q, int * restrict r)
5574              {
5575                    int i;
5576                    for (i = 0; i < n; i++)
5577                           p[i] = q[i] + r[i];
5578              }
5579      illustrate how an unmodified object can be aliased through two restricted pointers. In particular, if a and b
5580      are disjoint arrays, a call of the form h(100, a, b, b) has defined behavior, because array b is not
5581      modified within function h.
5582
5583 11   EXAMPLE 4 The rule limiting assignments between restricted pointers does not distinguish between a
5584      function call and an equivalent nested block. With one exception, only ''outer-to-inner'' assignments
5585      between restricted pointers declared in nested blocks have defined behavior.
5586              {
5587                       int * restrict p1;
5588                       int * restrict q1;
5589                       p1 = q1; // undefined behavior
5590                       {
5591                             int * restrict p2 = p1; // valid
5592                             int * restrict q2 = q1; // valid
5593                             p1 = q2;                // undefined behavior
5594                             p2 = q2;                // undefined behavior
5595                       }
5596              }
5597
5598
5599
5600
5601 [page 123]
5602
5603 12   The one exception allows the value of a restricted pointer to be carried out of the block in which it (or, more
5604      precisely, the ordinary identifier used to designate it) is declared when that block finishes execution. For
5605      example, this permits new_vector to return a vector.
5606               typedef struct { int n; float * restrict v; } vector;
5607               vector new_vector(int n)
5608               {
5609                     vector t;
5610                     t.n = n;
5611                     t.v = malloc(n * sizeof (float));
5612                     return t;
5613               }
5614
5615      6.7.4 Function specifiers
5616      Syntax
5617 1             function-specifier:
5618                      inline
5619                      _Noreturn
5620      Constraints
5621 2    Function specifiers shall be used only in the declaration of an identifier for a function.
5622 3    An inline definition of a function with external linkage shall not contain a definition of a
5623      modifiable object with static or thread storage duration, and shall not contain a reference
5624      to an identifier with internal linkage.
5625 4    In a hosted environment, no function specifier(s) shall appear in a declaration of main.
5626      Semantics
5627 5    A function specifier may appear more than once; the behavior is the same as if it
5628      appeared only once.
5629 6    A function declared with an inline function specifier is an inline function. Making a *
5630      function an inline function suggests that calls to the function be as fast as possible.138)
5631      The extent to which such suggestions are effective is implementation-defined.139)
5632
5633
5634
5635
5636      138) By using, for example, an alternative to the usual function call mechanism, such as ''inline
5637           substitution''. Inline substitution is not textual substitution, nor does it create a new function.
5638           Therefore, for example, the expansion of a macro used within the body of the function uses the
5639           definition it had at the point the function body appears, and not where the function is called; and
5640           identifiers refer to the declarations in scope where the body occurs. Likewise, the function has a
5641           single address, regardless of the number of inline definitions that occur in addition to the external
5642           definition.
5643      139) For example, an implementation might never perform inline substitution, or might only perform inline
5644           substitutions to calls in the scope of an inline declaration.
5645
5646 [page 124]
5647
5648 7    Any function with internal linkage can be an inline function. For a function with external
5649      linkage, the following restrictions apply: If a function is declared with an inline
5650      function specifier, then it shall also be defined in the same translation unit. If all of the
5651      file scope declarations for a function in a translation unit include the inline function
5652      specifier without extern, then the definition in that translation unit is an inline
5653      definition. An inline definition does not provide an external definition for the function,
5654      and does not forbid an external definition in another translation unit. An inline definition
5655      provides an alternative to an external definition, which a translator may use to implement
5656      any call to the function in the same translation unit. It is unspecified whether a call to the
5657      function uses the inline definition or the external definition.140)
5658 8    A function declared with a _Noreturn function specifier shall not return to its caller.
5659      Recommended practice
5660 9    The implementation should produce a diagnostic message for a function declared with a
5661      _Noreturn function specifier that appears to be capable of returning to its caller.
5662 10   EXAMPLE 1 The declaration of an inline function with external linkage can result in either an external
5663      definition, or a definition available for use only within the translation unit. A file scope declaration with
5664      extern creates an external definition. The following example shows an entire translation unit.
5665               inline double fahr(double t)
5666               {
5667                     return (9.0 * t) / 5.0 + 32.0;
5668               }
5669               inline double cels(double t)
5670               {
5671                     return (5.0 * (t - 32.0)) / 9.0;
5672               }
5673               extern double fahr(double);                  // creates an external definition
5674               double convert(int is_fahr, double temp)
5675               {
5676                     /* A translator may perform inline substitutions */
5677                     return is_fahr ? cels(temp) : fahr(temp);
5678               }
5679 11   Note that the definition of fahr is an external definition because fahr is also declared with extern, but
5680      the definition of cels is an inline definition. Because cels has external linkage and is referenced, an
5681      external definition has to appear in another translation unit (see 6.9); the inline definition and the external
5682      definition are distinct and either may be used for the call.
5683
5684 12   EXAMPLE 2
5685
5686
5687
5688
5689      140) Since an inline definition is distinct from the corresponding external definition and from any other
5690           corresponding inline definitions in other translation units, all corresponding objects with static storage
5691           duration are also distinct in each of the definitions.
5692
5693 [page 125]
5694
5695              _Noreturn void f () {
5696                    abort(); // ok
5697              }
5698              _Noreturn void g (int i) { // causes undefined behavior if i <= 0
5699                    if (i > 0) abort();
5700              }
5701
5702     Forward references: function definitions (6.9.1).
5703     6.7.5 Alignment specifier
5704     Syntax
5705 1            alignment-specifier:
5706                    _Alignas ( type-name )
5707                    _Alignas ( constant-expression )
5708     Constraints
5709 2   An alignment attribute shall not be specified in a declaration of a typedef, or a bit-field, or
5710     a function, or a parameter, or an object declared with the register storage-class
5711     specifier.
5712 3   The constant expression shall be an integer constant expression. It shall evaluate to a
5713     valid fundamental alignment, or to a valid extended alignment supported by the
5714     implementation in the context in which it appears, or to zero.
5715 4   The combined effect of all alignment attributes in a declaration shall not specify an
5716     alignment that is less strict than the alignment that would otherwise be required for the
5717     type of the object or member being declared.
5718     Semantics
5719 5   The first form is equivalent to _Alignas(alignof(type-name)).
5720 6   The alignment requirement of the declared object or member is taken to be the specified
5721     alignment. An alignment specification of zero has no effect.141) When multiple
5722     alignment specifiers occur in a declaration, the effective alignment requirement is the
5723     strictest specified alignment.
5724 7   If the definition of an object has an alignment specifier, any other declaration of that
5725     object shall either specify equivalent alignment or have no alignment specifier. If the
5726     definition of an object does not have an alignment specifier, any other declaration of that
5727     object shall also have no alignment specifier. If declarations of an object in different
5728     translation units have different alignment specifiers, the behavior is undefined.
5729
5730
5731
5732     141) An alignment specification of zero also does not affect other alignment specifications in the same
5733          declaration.
5734
5735 [page 126]
5736
5737     6.7.6 Declarators
5738     Syntax
5739 1            declarator:
5740                     pointeropt direct-declarator
5741              direct-declarator:
5742                      identifier
5743                      ( declarator )
5744                      direct-declarator [ type-qualifier-listopt assignment-expressionopt ]
5745                      direct-declarator [ static type-qualifier-listopt assignment-expression ]
5746                      direct-declarator [ type-qualifier-list static assignment-expression ]
5747                      direct-declarator [ type-qualifier-listopt * ]
5748                      direct-declarator ( parameter-type-list )
5749                      direct-declarator ( identifier-listopt )
5750              pointer:
5751                     * type-qualifier-listopt
5752                     * type-qualifier-listopt pointer
5753              type-qualifier-list:
5754                     type-qualifier
5755                     type-qualifier-list type-qualifier
5756              parameter-type-list:
5757                    parameter-list
5758                    parameter-list , ...
5759              parameter-list:
5760                    parameter-declaration
5761                    parameter-list , parameter-declaration
5762              parameter-declaration:
5763                    declaration-specifiers declarator
5764                    declaration-specifiers abstract-declaratoropt
5765              identifier-list:
5766                     identifier
5767                     identifier-list , identifier
5768     Semantics
5769 2   Each declarator declares one identifier, and asserts that when an operand of the same
5770     form as the declarator appears in an expression, it designates a function or object with the
5771     scope, storage duration, and type indicated by the declaration specifiers.
5772 3   A full declarator is a declarator that is not part of another declarator. The end of a full
5773     declarator is a sequence point. If, in the nested sequence of declarators in a full
5774 [page 127]
5775
5776     declarator, there is a declarator specifying a variable length array type, the type specified
5777     by the full declarator is said to be variably modified. Furthermore, any type derived by
5778     declarator type derivation from a variably modified type is itself variably modified.
5779 4   In the following subclauses, consider a declaration
5780             T D1
5781     where T contains the declaration specifiers that specify a type T (such as int) and D1 is
5782     a declarator that contains an identifier ident. The type specified for the identifier ident in
5783     the various forms of declarator is described inductively using this notation.
5784 5   If, in the declaration ''T D1'', D1 has the form
5785             identifier
5786     then the type specified for ident is T .
5787 6   If, in the declaration ''T D1'', D1 has the form
5788             ( D )
5789     then ident has the type specified by the declaration ''T D''. Thus, a declarator in
5790     parentheses is identical to the unparenthesized declarator, but the binding of complicated
5791     declarators may be altered by parentheses.
5792     Implementation limits
5793 7   As discussed in 5.2.4.1, an implementation may limit the number of pointer, array, and
5794     function declarators that modify an arithmetic, structure, union, or void type, either
5795     directly or via one or more typedefs.
5796     Forward references: array declarators (6.7.6.2), type definitions (6.7.8).
5797     6.7.6.1 Pointer declarators
5798     Semantics
5799 1   If, in the declaration ''T D1'', D1 has the form
5800             * type-qualifier-listopt D
5801     and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
5802     T '', then the type specified for ident is ''derived-declarator-type-list type-qualifier-list
5803     pointer to T ''. For each type qualifier in the list, ident is a so-qualified pointer.
5804 2   For two pointer types to be compatible, both shall be identically qualified and both shall
5805     be pointers to compatible types.
5806 3   EXAMPLE The following pair of declarations demonstrates the difference between a ''variable pointer
5807     to a constant value'' and a ''constant pointer to a variable value''.
5808
5809
5810
5811
5812 [page 128]
5813
5814              const int *ptr_to_constant;
5815              int *const constant_ptr;
5816     The contents of any object pointed to by ptr_to_constant shall not be modified through that pointer,
5817     but ptr_to_constant itself may be changed to point to another object. Similarly, the contents of the
5818     int pointed to by constant_ptr may be modified, but constant_ptr itself shall always point to the
5819     same location.
5820 4   The declaration of the constant pointer constant_ptr may be clarified by including a definition for the
5821     type ''pointer to int''.
5822              typedef int *int_ptr;
5823              const int_ptr constant_ptr;
5824     declares constant_ptr as an object that has type ''const-qualified pointer to int''.
5825
5826     6.7.6.2 Array declarators
5827     Constraints
5828 1   In addition to optional type qualifiers and the keyword static, the [ and ] may delimit
5829     an expression or *. If they delimit an expression (which specifies the size of an array), the
5830     expression shall have an integer type. If the expression is a constant expression, it shall
5831     have a value greater than zero. The element type shall not be an incomplete or function
5832     type. The optional type qualifiers and the keyword static shall appear only in a
5833     declaration of a function parameter with an array type, and then only in the outermost
5834     array type derivation.
5835 2   If an identifier is declared as having a variably modified type, it shall be an ordinary
5836     identifier (as defined in 6.2.3), have no linkage, and have either block scope or function
5837     prototype scope. If an identifier is declared to be an object with static or thread storage
5838     duration, it shall not have a variable length array type.
5839     Semantics
5840 3   If, in the declaration ''T D1'', D1 has one of the forms:
5841              D[ type-qualifier-listopt assignment-expressionopt ]
5842              D[ static type-qualifier-listopt assignment-expression ]
5843              D[ type-qualifier-list static assignment-expression ]
5844              D[ type-qualifier-listopt * ]
5845     and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
5846     T '', then the type specified for ident is ''derived-declarator-type-list array of T ''.142)
5847     (See 6.7.6.3 for the meaning of the optional type qualifiers and the keyword static.)
5848 4   If the size is not present, the array type is an incomplete type. If the size is * instead of
5849     being an expression, the array type is a variable length array type of unspecified size,
5850     which can only be used in declarations or type names with function prototype scope;143)
5851
5852     142) When several ''array of'' specifications are adjacent, a multidimensional array is declared.
5853
5854 [page 129]
5855
5856     such arrays are nonetheless complete types. If the size is an integer constant expression
5857     and the element type has a known constant size, the array type is not a variable length
5858     array type; otherwise, the array type is a variable length array type. (Variable length
5859     arrays are a conditional feature that implementations need not support; see 6.10.8.3.)
5860 5   If the size is an expression that is not an integer constant expression: if it occurs in a
5861     declaration at function prototype scope, it is treated as if it were replaced by *; otherwise,
5862     each time it is evaluated it shall have a value greater than zero. The size of each instance
5863     of a variable length array type does not change during its lifetime. Where a size
5864     expression is part of the operand of a sizeof operator and changing the value of the
5865     size expression would not affect the result of the operator, it is unspecified whether or not
5866     the size expression is evaluated.
5867 6   For two array types to be compatible, both shall have compatible element types, and if
5868     both size specifiers are present, and are integer constant expressions, then both size
5869     specifiers shall have the same constant value. If the two array types are used in a context
5870     which requires them to be compatible, it is undefined behavior if the two size specifiers
5871     evaluate to unequal values.
5872 7   EXAMPLE 1
5873              float fa[11], *afp[17];
5874     declares an array of float numbers and an array of pointers to float numbers.
5875
5876 8   EXAMPLE 2       Note the distinction between the declarations
5877              extern int *x;
5878              extern int y[];
5879     The first declares x to be a pointer to int; the second declares y to be an array of int of unspecified size
5880     (an incomplete type), the storage for which is defined elsewhere.
5881
5882 9   EXAMPLE 3       The following declarations demonstrate the compatibility rules for variably modified types.
5883              extern int n;
5884              extern int m;
5885              void fcompat(void)
5886              {
5887                    int a[n][6][m];
5888                    int (*p)[4][n+1];
5889                    int c[n][n][6][m];
5890                    int (*r)[n][n][n+1];
5891                    p = a;       // invalid: not compatible because 4 != 6
5892                    r = c;       // compatible, but defined behavior only if
5893                                 // n == 6 and m == n+1
5894              }
5895
5896
5897
5898
5899     143) Thus, * can be used only in function declarations that are not definitions (see 6.7.6.3).
5900
5901 [page 130]
5902
5903 10   EXAMPLE 4 All declarations of variably modified (VM) types have to be at either block scope or
5904      function prototype scope. Array objects declared with the _Thread_local, static, or extern
5905      storage-class specifier cannot have a variable length array (VLA) type. However, an object declared with
5906      the static storage-class specifier can have a VM type (that is, a pointer to a VLA type). Finally, all
5907      identifiers declared with a VM type have to be ordinary identifiers and cannot, therefore, be members of
5908      structures or unions.
5909              extern int n;
5910              int A[n];                                           // invalid: file scope VLA
5911              extern int (*p2)[n];                                // invalid: file scope VM
5912              int B[100];                                         // valid: file scope but not VM
5913              void fvla(int m, int C[m][m]);                      // valid: VLA with prototype scope
5914              void fvla(int m, int C[m][m])                       // valid: adjusted to auto pointer to VLA
5915              {
5916                    typedef int VLA[m][m];                        // valid: block scope typedef VLA
5917                       struct tag {
5918                             int (*y)[n];                         // invalid: y not ordinary identifier
5919                             int z[n];                            // invalid: z not ordinary identifier
5920                       };
5921                       int D[m];                                  //   valid: auto VLA
5922                       static int E[m];                           //   invalid: static block scope VLA
5923                       extern int F[m];                           //   invalid: F has linkage and is VLA
5924                       int (*s)[m];                               //   valid: auto pointer to VLA
5925                       extern int (*r)[m];                        //   invalid: r has linkage and points to VLA
5926                       static int (*q)[m] = &B;                   //   valid: q is a static block pointer to VLA
5927              }
5928
5929      Forward references:          function declarators (6.7.6.3), function definitions (6.9.1),
5930      initialization (6.7.9).
5931      6.7.6.3 Function declarators (including prototypes)
5932      Constraints
5933 1    A function declarator shall not specify a return type that is a function type or an array
5934      type.
5935 2    The only storage-class specifier that shall occur in a parameter declaration is register.
5936 3    An identifier list in a function declarator that is not part of a definition of that function
5937      shall be empty.
5938 4    After adjustment, the parameters in a parameter type list in a function declarator that is
5939      part of a definition of that function shall not have incomplete type.
5940      Semantics
5941 5    If, in the declaration ''T D1'', D1 has the form
5942
5943
5944
5945
5946 [page 131]
5947
5948             D( parameter-type-list )
5949      or
5950             D( identifier-listopt )
5951      and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
5952      T '', then the type specified for ident is ''derived-declarator-type-list function returning
5953      T ''.
5954 6    A parameter type list specifies the types of, and may declare identifiers for, the
5955      parameters of the function.
5956 7    A declaration of a parameter as ''array of type'' shall be adjusted to ''qualified pointer to
5957      type'', where the type qualifiers (if any) are those specified within the [ and ] of the
5958      array type derivation. If the keyword static also appears within the [ and ] of the
5959      array type derivation, then for each call to the function, the value of the corresponding
5960      actual argument shall provide access to the first element of an array with at least as many
5961      elements as specified by the size expression.
5962 8    A declaration of a parameter as ''function returning type'' shall be adjusted to ''pointer to
5963      function returning type'', as in 6.3.2.1.
5964 9    If the list terminates with an ellipsis (, ...), no information about the number or types
5965      of the parameters after the comma is supplied.144)
5966 10   The special case of an unnamed parameter of type void as the only item in the list
5967      specifies that the function has no parameters.
5968 11   If, in a parameter declaration, an identifier can be treated either as a typedef name or as a
5969      parameter name, it shall be taken as a typedef name.
5970 12   If the function declarator is not part of a definition of that function, parameters may have
5971      incomplete type and may use the [*] notation in their sequences of declarator specifiers
5972      to specify variable length array types.
5973 13   The storage-class specifier in the declaration specifiers for a parameter declaration, if
5974      present, is ignored unless the declared parameter is one of the members of the parameter
5975      type list for a function definition.
5976 14   An identifier list declares only the identifiers of the parameters of the function. An empty
5977      list in a function declarator that is part of a definition of that function specifies that the
5978      function has no parameters. The empty list in a function declarator that is not part of a
5979      definition of that function specifies that no information about the number or types of the
5980      parameters is supplied.145)
5981
5982
5983
5984      144) The macros defined in the <stdarg.h> header (7.16) may be used to access arguments that
5985           correspond to the ellipsis.
5986
5987 [page 132]
5988
5989 15   For two function types to be compatible, both shall specify compatible return types.146)
5990      Moreover, the parameter type lists, if both are present, shall agree in the number of
5991      parameters and in use of the ellipsis terminator; corresponding parameters shall have
5992      compatible types. If one type has a parameter type list and the other type is specified by a
5993      function declarator that is not part of a function definition and that contains an empty
5994      identifier list, the parameter list shall not have an ellipsis terminator and the type of each
5995      parameter shall be compatible with the type that results from the application of the
5996      default argument promotions. If one type has a parameter type list and the other type is
5997      specified by a function definition that contains a (possibly empty) identifier list, both shall
5998      agree in the number of parameters, and the type of each prototype parameter shall be
5999      compatible with the type that results from the application of the default argument
6000      promotions to the type of the corresponding identifier. (In the determination of type
6001      compatibility and of a composite type, each parameter declared with function or array
6002      type is taken as having the adjusted type and each parameter declared with qualified type
6003      is taken as having the unqualified version of its declared type.)
6004 16   EXAMPLE 1       The declaration
6005               int f(void), *fip(), (*pfi)();
6006      declares a function f with no parameters returning an int, a function fip with no parameter specification
6007      returning a pointer to an int, and a pointer pfi to a function with no parameter specification returning an
6008      int. It is especially useful to compare the last two. The binding of *fip() is *(fip()), so that the
6009      declaration suggests, and the same construction in an expression requires, the calling of a function fip,
6010      and then using indirection through the pointer result to yield an int. In the declarator (*pfi)(), the
6011      extra parentheses are necessary to indicate that indirection through a pointer to a function yields a function
6012      designator, which is then used to call the function; it returns an int.
6013 17   If the declaration occurs outside of any function, the identifiers have file scope and external linkage. If the
6014      declaration occurs inside a function, the identifiers of the functions f and fip have block scope and either
6015      internal or external linkage (depending on what file scope declarations for these identifiers are visible), and
6016      the identifier of the pointer pfi has block scope and no linkage.
6017
6018 18   EXAMPLE 2       The declaration
6019               int (*apfi[3])(int *x, int *y);
6020      declares an array apfi of three pointers to functions returning int. Each of these functions has two
6021      parameters that are pointers to int. The identifiers x and y are declared for descriptive purposes only and
6022      go out of scope at the end of the declaration of apfi.
6023
6024 19   EXAMPLE 3       The declaration
6025               int (*fpfi(int (*)(long), int))(int, ...);
6026      declares a function fpfi that returns a pointer to a function returning an int. The function fpfi has two
6027      parameters: a pointer to a function returning an int (with one parameter of type long int), and an int.
6028      The pointer returned by fpfi points to a function that has one int parameter and accepts zero or more
6029
6030
6031      145) See ''future language directions'' (6.11.6).
6032      146) If both function types are ''old style'', parameter types are not compared.
6033
6034 [page 133]
6035
6036      additional arguments of any type.
6037
6038 20   EXAMPLE 4        The following prototype has a variably modified parameter.
6039                void addscalar(int n, int m,
6040                      double a[n][n*m+300], double x);
6041                int main()
6042                {
6043                      double b[4][308];
6044                      addscalar(4, 2, b, 2.17);
6045                      return 0;
6046                }
6047                void addscalar(int n, int m,
6048                      double a[n][n*m+300], double x)
6049                {
6050                      for (int i = 0; i < n; i++)
6051                            for (int j = 0, k = n*m+300; j < k; j++)
6052                                  // a is a pointer to a VLA with n*m+300 elements
6053                                  a[i][j] += x;
6054                }
6055
6056 21   EXAMPLE 5        The following are all compatible function prototype declarators.
6057                double    maximum(int       n,   int   m,   double   a[n][m]);
6058                double    maximum(int       n,   int   m,   double   a[*][*]);
6059                double    maximum(int       n,   int   m,   double   a[ ][*]);
6060                double    maximum(int       n,   int   m,   double   a[ ][m]);
6061      as are:
6062                void   f(double     (* restrict a)[5]);
6063                void   f(double     a[restrict][5]);
6064                void   f(double     a[restrict 3][5]);
6065                void   f(double     a[restrict static 3][5]);
6066      (Note that the last declaration also specifies that the argument corresponding to a in any call to f must be a
6067      non-null pointer to the first of at least three arrays of 5 doubles, which the others do not.)
6068
6069      Forward references: function definitions (6.9.1), type names (6.7.7).
6070
6071
6072
6073
6074 [page 134]
6075
6076     6.7.7 Type names
6077     Syntax
6078 1            type-name:
6079                     specifier-qualifier-list abstract-declaratoropt
6080              abstract-declarator:
6081                     pointer
6082                     pointeropt direct-abstract-declarator
6083              direct-abstract-declarator:
6084                      ( abstract-declarator )
6085                      direct-abstract-declaratoropt [ type-qualifier-listopt
6086                                     assignment-expressionopt ]
6087                      direct-abstract-declaratoropt [ static type-qualifier-listopt
6088                                     assignment-expression ]
6089                      direct-abstract-declaratoropt [ type-qualifier-list static
6090                                     assignment-expression ]
6091                      direct-abstract-declaratoropt [ * ]
6092                      direct-abstract-declaratoropt ( parameter-type-listopt )
6093     Semantics
6094 2   In several contexts, it is necessary to specify a type. This is accomplished using a type
6095     name, which is syntactically a declaration for a function or an object of that type that
6096     omits the identifier.147)
6097 3   EXAMPLE        The constructions
6098              (a)      int
6099              (b)      int   *
6100              (c)      int   *[3]
6101              (d)      int   (*)[3]
6102              (e)      int   (*)[*]
6103              (f)      int   *()
6104              (g)      int   (*)(void)
6105              (h)      int   (*const [])(unsigned int, ...)
6106     name respectively the types (a) int, (b) pointer to int, (c) array of three pointers to int, (d) pointer to an
6107     array of three ints, (e) pointer to a variable length array of an unspecified number of ints, (f) function
6108     with no parameter specification returning a pointer to int, (g) pointer to function with no parameters
6109     returning an int, and (h) array of an unspecified number of constant pointers to functions, each with one
6110     parameter that has type unsigned int and an unspecified number of other parameters, returning an
6111     int.
6112
6113
6114
6115
6116     147) As indicated by the syntax, empty parentheses in a type name are interpreted as ''function with no
6117          parameter specification'', rather than redundant parentheses around the omitted identifier.
6118
6119 [page 135]
6120
6121     6.7.8 Type definitions
6122     Syntax
6123 1            typedef-name:
6124                     identifier
6125     Constraints
6126 2   If a typedef name specifies a variably modified type then it shall have block scope.
6127     Semantics
6128 3   In a declaration whose storage-class specifier is typedef, each declarator defines an
6129     identifier to be a typedef name that denotes the type specified for the identifier in the way
6130     described in 6.7.6. Any array size expressions associated with variable length array
6131     declarators are evaluated each time the declaration of the typedef name is reached in the
6132     order of execution. A typedef declaration does not introduce a new type, only a
6133     synonym for the type so specified. That is, in the following declarations:
6134              typedef T type_ident;
6135              type_ident D;
6136     type_ident is defined as a typedef name with the type specified by the declaration
6137     specifiers in T (known as T ), and the identifier in D has the type ''derived-declarator-
6138     type-list T '' where the derived-declarator-type-list is specified by the declarators of D. A
6139     typedef name shares the same name space as other identifiers declared in ordinary
6140     declarators.
6141 4   EXAMPLE 1       After
6142              typedef int MILES, KLICKSP();
6143              typedef struct { double hi, lo; } range;
6144     the constructions
6145              MILES distance;
6146              extern KLICKSP *metricp;
6147              range x;
6148              range z, *zp;
6149     are all valid declarations. The type of distance is int, that of metricp is ''pointer to function with no
6150     parameter specification returning int'', and that of x and z is the specified structure; zp is a pointer to
6151     such a structure. The object distance has a type compatible with any other int object.
6152
6153 5   EXAMPLE 2       After the declarations
6154              typedef struct s1 { int x; } t1, *tp1;
6155              typedef struct s2 { int x; } t2, *tp2;
6156     type t1 and the type pointed to by tp1 are compatible. Type t1 is also compatible with type struct
6157     s1, but not compatible with the types struct s2, t2, the type pointed to by tp2, or int.
6158
6159
6160
6161
6162 [page 136]
6163
6164 6   EXAMPLE 3       The following obscure constructions
6165              typedef signed int t;
6166              typedef int plain;
6167              struct tag {
6168                    unsigned t:4;
6169                    const t:5;
6170                    plain r:5;
6171              };
6172     declare a typedef name t with type signed int, a typedef name plain with type int, and a structure
6173     with three bit-field members, one named t that contains values in the range [0, 15], an unnamed const-
6174     qualified bit-field which (if it could be accessed) would contain values in either the range [-15, +15] or
6175     [-16, +15], and one named r that contains values in one of the ranges [0, 31], [-15, +15], or [-16, +15].
6176     (The choice of range is implementation-defined.) The first two bit-field declarations differ in that
6177     unsigned is a type specifier (which forces t to be the name of a structure member), while const is a
6178     type qualifier (which modifies t which is still visible as a typedef name). If these declarations are followed
6179     in an inner scope by
6180              t f(t (t));
6181              long t;
6182     then a function f is declared with type ''function returning signed int with one unnamed parameter
6183     with type pointer to function returning signed int with one unnamed parameter with type signed
6184     int'', and an identifier t with type long int.
6185
6186 7   EXAMPLE 4 On the other hand, typedef names can be used to improve code readability. All three of the
6187     following declarations of the signal function specify exactly the same type, the first without making use
6188     of any typedef names.
6189              typedef void fv(int), (*pfv)(int);
6190              void (*signal(int, void (*)(int)))(int);
6191              fv *signal(int, fv *);
6192              pfv signal(int, pfv);
6193
6194 8   EXAMPLE 5 If a typedef name denotes a variable length array type, the length of the array is fixed at the
6195     time the typedef name is defined, not each time it is used:
6196              void copyt(int n)
6197              {
6198                    typedef int B[n];   //               B is n ints, n evaluated now
6199                    n += 1;
6200                    B a;                //               a is n ints, n without += 1
6201                    int b[n];           //               a and b are different sizes
6202                    for (int i = 1; i < n;               i++)
6203                          a[i-1] = b[i];
6204              }
6205
6206
6207
6208
6209 [page 137]
6210
6211     6.7.9 Initialization
6212     Syntax
6213 1            initializer:
6214                       assignment-expression
6215                       { initializer-list }
6216                       { initializer-list , }
6217              initializer-list:
6218                       designationopt initializer
6219                       initializer-list , designationopt initializer
6220              designation:
6221                     designator-list =
6222              designator-list:
6223                     designator
6224                     designator-list designator
6225              designator:
6226                     [ constant-expression ]
6227                     . identifier
6228     Constraints
6229 2   No initializer shall attempt to provide a value for an object not contained within the entity
6230     being initialized.
6231 3   The type of the entity to be initialized shall be an array of unknown size or a complete
6232     object type that is not a variable length array type.
6233 4   All the expressions in an initializer for an object that has static or thread storage duration
6234     shall be constant expressions or string literals.
6235 5   If the declaration of an identifier has block scope, and the identifier has external or
6236     internal linkage, the declaration shall have no initializer for the identifier.
6237 6   If a designator has the form
6238              [ constant-expression ]
6239     then the current object (defined below) shall have array type and the expression shall be
6240     an integer constant expression. If the array is of unknown size, any nonnegative value is
6241     valid.
6242 7   If a designator has the form
6243              . identifier
6244     then the current object (defined below) shall have structure or union type and the
6245     identifier shall be the name of a member of that type.
6246 [page 138]
6247
6248      Semantics
6249 8    An initializer specifies the initial value stored in an object.
6250 9    Except where explicitly stated otherwise, for the purposes of this subclause unnamed
6251      members of objects of structure and union type do not participate in initialization.
6252      Unnamed members of structure objects have indeterminate value even after initialization.
6253 10   If an object that has automatic storage duration is not initialized explicitly, its value is
6254      indeterminate. If an object that has static or thread storage duration is not initialized
6255      explicitly, then:
6256      -- if it has pointer type, it is initialized to a null pointer;
6257      -- if it has arithmetic type, it is initialized to (positive or unsigned) zero;
6258      -- if it is an aggregate, every member is initialized (recursively) according to these rules,
6259        and any padding is initialized to zero bits;
6260      -- if it is a union, the first named member is initialized (recursively) according to these
6261        rules, and any padding is initialized to zero bits;
6262 11   The initializer for a scalar shall be a single expression, optionally enclosed in braces. The
6263      initial value of the object is that of the expression (after conversion); the same type
6264      constraints and conversions as for simple assignment apply, taking the type of the scalar
6265      to be the unqualified version of its declared type.
6266 12   The rest of this subclause deals with initializers for objects that have aggregate or union
6267      type.
6268 13   The initializer for a structure or union object that has automatic storage duration shall be
6269      either an initializer list as described below, or a single expression that has compatible
6270      structure or union type. In the latter case, the initial value of the object, including
6271      unnamed members, is that of the expression.
6272 14   An array of character type may be initialized by a character string literal or UTF-8 string
6273      literal, optionally enclosed in braces. Successive bytes of the string literal (including the
6274      terminating null character if there is room or if the array is of unknown size) initialize the
6275      elements of the array.
6276 15   An array with element type compatible with a qualified or unqualified version of
6277      wchar_t may be initialized by a wide string literal, optionally enclosed in braces.
6278      Successive wide characters of the wide string literal (including the terminating null wide
6279      character if there is room or if the array is of unknown size) initialize the elements of the
6280      array.
6281 16   Otherwise, the initializer for an object that has aggregate or union type shall be a brace-
6282      enclosed list of initializers for the elements or named members.
6283
6284
6285 [page 139]
6286
6287 17   Each brace-enclosed initializer list has an associated current object. When no
6288      designations are present, subobjects of the current object are initialized in order according
6289      to the type of the current object: array elements in increasing subscript order, structure
6290      members in declaration order, and the first named member of a union.148) In contrast, a
6291      designation causes the following initializer to begin initialization of the subobject
6292      described by the designator. Initialization then continues forward in order, beginning
6293      with the next subobject after that described by the designator.149)
6294 18   Each designator list begins its description with the current object associated with the
6295      closest surrounding brace pair. Each item in the designator list (in order) specifies a
6296      particular member of its current object and changes the current object for the next
6297      designator (if any) to be that member.150) The current object that results at the end of the
6298      designator list is the subobject to be initialized by the following initializer.
6299 19   The initialization shall occur in initializer list order, each initializer provided for a
6300      particular subobject overriding any previously listed initializer for the same subobject;151)
6301      all subobjects that are not initialized explicitly shall be initialized implicitly the same as
6302      objects that have static storage duration.
6303 20   If the aggregate or union contains elements or members that are aggregates or unions,
6304      these rules apply recursively to the subaggregates or contained unions. If the initializer of
6305      a subaggregate or contained union begins with a left brace, the initializers enclosed by
6306      that brace and its matching right brace initialize the elements or members of the
6307      subaggregate or the contained union. Otherwise, only enough initializers from the list are
6308      taken to account for the elements or members of the subaggregate or the first member of
6309      the contained union; any remaining initializers are left to initialize the next element or
6310      member of the aggregate of which the current subaggregate or contained union is a part.
6311 21   If there are fewer initializers in a brace-enclosed list than there are elements or members
6312      of an aggregate, or fewer characters in a string literal used to initialize an array of known
6313      size than there are elements in the array, the remainder of the aggregate shall be
6314      initialized implicitly the same as objects that have static storage duration.
6315
6316
6317
6318      148) If the initializer list for a subaggregate or contained union does not begin with a left brace, its
6319           subobjects are initialized as usual, but the subaggregate or contained union does not become the
6320           current object: current objects are associated only with brace-enclosed initializer lists.
6321      149) After a union member is initialized, the next object is not the next member of the union; instead, it is
6322           the next subobject of an object containing the union.
6323      150) Thus, a designator can only specify a strict subobject of the aggregate or union that is associated with
6324           the surrounding brace pair. Note, too, that each separate designator list is independent.
6325      151) Any initializer for the subobject which is overridden and so not used to initialize that subobject might
6326           not be evaluated at all.
6327
6328 [page 140]
6329
6330 22   If an array of unknown size is initialized, its size is determined by the largest indexed
6331      element with an explicit initializer. The array type is completed at the end of its
6332      initializer list.
6333 23   The evaluations of the initialization list expressions are indeterminately sequenced with
6334      respect to one another and thus the order in which any side effects occur is
6335      unspecified.152)
6336 24   EXAMPLE 1       Provided that <complex.h> has been #included, the declarations
6337               int i = 3.5;
6338               double complex c = 5 + 3 * I;
6339      define and initialize i with the value 3 and c with the value 5.0 + i3.0.
6340
6341 25   EXAMPLE 2       The declaration
6342               int x[] = { 1, 3, 5 };
6343      defines and initializes x as a one-dimensional array object that has three elements, as no size was specified
6344      and there are three initializers.
6345
6346 26   EXAMPLE 3       The declaration
6347               int y[4][3] =         {
6348                     { 1, 3,         5 },
6349                     { 2, 4,         6 },
6350                     { 3, 5,         7 },
6351               };
6352      is a definition with a fully bracketed initialization: 1, 3, and 5 initialize the first row of y (the array object
6353      y[0]), namely y[0][0], y[0][1], and y[0][2]. Likewise the next two lines initialize y[1] and
6354      y[2]. The initializer ends early, so y[3] is initialized with zeros. Precisely the same effect could have
6355      been achieved by
6356               int y[4][3] = {
6357                     1, 3, 5, 2, 4, 6, 3, 5, 7
6358               };
6359      The initializer for y[0] does not begin with a left brace, so three items from the list are used. Likewise the
6360      next three are taken successively for y[1] and y[2].
6361
6362 27   EXAMPLE 4       The declaration
6363               int z[4][3] = {
6364                     { 1 }, { 2 }, { 3 }, { 4 }
6365               };
6366      initializes the first column of z as specified and initializes the rest with zeros.
6367
6368 28   EXAMPLE 5       The declaration
6369               struct { int a[3], b; } w[] = { { 1 }, 2 };
6370      is a definition with an inconsistently bracketed initialization. It defines an array with two element
6371
6372
6373
6374      152) In particular, the evaluation order need not be the same as the order of subobject initialization.
6375
6376 [page 141]
6377
6378      structures: w[0].a[0] is 1 and w[1].a[0] is 2; all the other elements are zero.
6379
6380 29   EXAMPLE 6         The declaration
6381                short q[4][3][2] = {
6382                      { 1 },
6383                      { 2, 3 },
6384                      { 4, 5, 6 }
6385                };
6386      contains an incompletely but consistently bracketed initialization. It defines a three-dimensional array
6387      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
6388      q[2][0][0], q[2][0][1], and q[2][1][0], respectively; all the rest are zero. The initializer for
6389      q[0][0] does not begin with a left brace, so up to six items from the current list may be used. There is
6390      only one, so the values for the remaining five elements are initialized with zero. Likewise, the initializers
6391      for q[1][0] and q[2][0] do not begin with a left brace, so each uses up to six items, initializing their
6392      respective two-dimensional subaggregates. If there had been more than six items in any of the lists, a
6393      diagnostic message would have been issued. The same initialization result could have been achieved by:
6394                short q[4][3][2] = {
6395                      1, 0, 0, 0, 0, 0,
6396                      2, 3, 0, 0, 0, 0,
6397                      4, 5, 6
6398                };
6399      or by:
6400                short q[4][3][2] = {
6401                      {
6402                            { 1 },
6403                      },
6404                      {
6405                            { 2, 3 },
6406                      },
6407                      {
6408                            { 4, 5 },
6409                            { 6 },
6410                      }
6411                };
6412      in a fully bracketed form.
6413 30   Note that the fully bracketed and minimally bracketed forms of initialization are, in general, less likely to
6414      cause confusion.
6415
6416 31   EXAMPLE 7         One form of initialization that completes array types involves typedef names. Given the
6417      declaration
6418                typedef int A[];          // OK - declared with block scope
6419      the declaration
6420                A a = { 1, 2 }, b = { 3, 4, 5 };
6421      is identical to
6422                int a[] = { 1, 2 }, b[] = { 3, 4, 5 };
6423      due to the rules for incomplete types.
6424
6425 [page 142]
6426
6427 32   EXAMPLE 8       The declaration
6428               char s[] = "abc", t[3] = "abc";
6429      defines ''plain'' char array objects s and t whose elements are initialized with character string literals.
6430      This declaration is identical to
6431               char s[] = { 'a', 'b', 'c', '\0' },
6432                    t[] = { 'a', 'b', 'c' };
6433      The contents of the arrays are modifiable. On the other hand, the declaration
6434               char *p = "abc";
6435      defines p with type ''pointer to char'' and initializes it to point to an object with type ''array of char''
6436      with length 4 whose elements are initialized with a character string literal. If an attempt is made to use p to
6437      modify the contents of the array, the behavior is undefined.
6438
6439 33   EXAMPLE 9       Arrays can be initialized to correspond to the elements of an enumeration by using
6440      designators:
6441               enum { member_one,           member_two };
6442               const char *nm[] =           {
6443                     [member_two]           = "member two",
6444                     [member_one]           = "member one",
6445               };
6446
6447 34   EXAMPLE 10       Structure members can be initialized to nonzero values without depending on their order:
6448               div_t answer = { .quot = 2, .rem = -1 };
6449
6450 35   EXAMPLE 11 Designators can be used to provide explicit initialization when unadorned initializer lists
6451      might be misunderstood:
6452               struct { int a[3], b; } w[] =
6453                     { [0].a = {1}, [1].a[0] = 2 };
6454
6455 36   EXAMPLE 12       Space can be ''allocated'' from both ends of an array by using a single designator:
6456               int a[MAX] = {
6457                     1, 3, 5, 7, 9, [MAX-5] = 8, 6, 4, 2, 0
6458               };
6459 37   In the above, if MAX is greater than ten, there will be some zero-valued elements in the middle; if it is less
6460      than ten, some of the values provided by the first five initializers will be overridden by the second five.
6461
6462 38   EXAMPLE 13       Any member of a union can be initialized:
6463               union { /* ... */ } u = { .any_member = 42 };
6464
6465      Forward references: common definitions <stddef.h> (7.19).
6466
6467
6468
6469
6470 [page 143]
6471
6472     6.7.10 Static assertions
6473     Syntax
6474 1            static_assert-declaration:
6475                      _Static_assert ( constant-expression , string-literal ) ;
6476     Constraints
6477 2   The constant expression shall compare unequal to 0.
6478     Semantics
6479 3   The constant expression shall be an integer constant expression. If the value of the
6480     constant expression compares unequal to 0, the declaration has no effect. Otherwise, the
6481     constraint is violated and the implementation shall produce a diagnostic message that
6482     includes the text of the string literal, except that characters not in the basic source
6483     character set are not required to appear in the message.
6484     Forward references: diagnostics (7.2).
6485
6486
6487
6488
6489 [page 144]
6490
6491     6.8 Statements and blocks
6492     Syntax
6493 1            statement:
6494                     labeled-statement
6495                     compound-statement
6496                     expression-statement
6497                     selection-statement
6498                     iteration-statement
6499                     jump-statement
6500     Semantics
6501 2   A statement specifies an action to be performed. Except as indicated, statements are
6502     executed in sequence.
6503 3   A block allows a set of declarations and statements to be grouped into one syntactic unit.
6504     The initializers of objects that have automatic storage duration, and the variable length
6505     array declarators of ordinary identifiers with block scope, are evaluated and the values are
6506     stored in the objects (including storing an indeterminate value in objects without an
6507     initializer) each time the declaration is reached in the order of execution, as if it were a
6508     statement, and within each declaration in the order that declarators appear.
6509 4   A full expression is an expression that is not part of another expression or of a declarator.
6510     Each of the following is a full expression: an initializer that is not part of a compound
6511     literal; the expression in an expression statement; the controlling expression of a selection
6512     statement (if or switch); the controlling expression of a while or do statement; each
6513     of the (optional) expressions of a for statement; the (optional) expression in a return
6514     statement. There is a sequence point between the evaluation of a full expression and the
6515     evaluation of the next full expression to be evaluated.
6516     Forward references: expression and null statements (6.8.3), selection statements
6517     (6.8.4), iteration statements (6.8.5), the return statement (6.8.6.4).
6518     6.8.1 Labeled statements
6519     Syntax
6520 1            labeled-statement:
6521                     identifier : statement
6522                     case constant-expression : statement
6523                     default : statement
6524     Constraints
6525 2   A case or default label shall appear only in a switch statement. Further
6526     constraints on such labels are discussed under the switch statement.
6527
6528 [page 145]
6529
6530 3   Label names shall be unique within a function.
6531     Semantics
6532 4   Any statement may be preceded by a prefix that declares an identifier as a label name.
6533     Labels in themselves do not alter the flow of control, which continues unimpeded across
6534     them.
6535     Forward references: the goto statement (6.8.6.1), the switch statement (6.8.4.2).
6536     6.8.2 Compound statement
6537     Syntax
6538 1            compound-statement:
6539                    { block-item-listopt }
6540              block-item-list:
6541                      block-item
6542                      block-item-list block-item
6543              block-item:
6544                      declaration
6545                      statement
6546     Semantics
6547 2   A compound statement is a block.
6548     6.8.3 Expression and null statements
6549     Syntax
6550 1            expression-statement:
6551                     expressionopt ;
6552     Semantics
6553 2   The expression in an expression statement is evaluated as a void expression for its side
6554     effects.153)
6555 3   A null statement (consisting of just a semicolon) performs no operations.
6556 4   EXAMPLE 1 If a function call is evaluated as an expression statement for its side effects only, the
6557     discarding of its value may be made explicit by converting the expression to a void expression by means of
6558     a cast:
6559              int p(int);
6560              /* ... */
6561              (void)p(0);
6562
6563
6564
6565     153) Such as assignments, and function calls which have side effects.
6566
6567 [page 146]
6568
6569 5   EXAMPLE 2       In the program fragment
6570              char *s;
6571              /* ... */
6572              while (*s++ != '\0')
6573                      ;
6574     a null statement is used to supply an empty loop body to the iteration statement.
6575
6576 6   EXAMPLE 3       A null statement may also be used to carry a label just before the closing } of a compound
6577     statement.
6578              while (loop1) {
6579                    /* ... */
6580                    while (loop2) {
6581                            /* ... */
6582                            if (want_out)
6583                                    goto end_loop1;
6584                            /* ... */
6585                    }
6586                    /* ... */
6587              end_loop1: ;
6588              }
6589
6590     Forward references: iteration statements (6.8.5).
6591     6.8.4 Selection statements
6592     Syntax
6593 1            selection-statement:
6594                      if ( expression ) statement
6595                      if ( expression ) statement else statement
6596                      switch ( expression ) statement
6597     Semantics
6598 2   A selection statement selects among a set of statements depending on the value of a
6599     controlling expression.
6600 3   A selection statement is a block whose scope is a strict subset of the scope of its
6601     enclosing block. Each associated substatement is also a block whose scope is a strict
6602     subset of the scope of the selection statement.
6603     6.8.4.1 The if statement
6604     Constraints
6605 1   The controlling expression of an if statement shall have scalar type.
6606     Semantics
6607 2   In both forms, the first substatement is executed if the expression compares unequal to 0.
6608     In the else form, the second substatement is executed if the expression compares equal
6609
6610
6611 [page 147]
6612
6613     to 0. If the first substatement is reached via a label, the second substatement is not
6614     executed.
6615 3   An else is associated with the lexically nearest preceding if that is allowed by the
6616     syntax.
6617     6.8.4.2 The switch statement
6618     Constraints
6619 1   The controlling expression of a switch statement shall have integer type.
6620 2   If a switch statement has an associated case or default label within the scope of an
6621     identifier with a variably modified type, the entire switch statement shall be within the
6622     scope of that identifier.154)
6623 3   The expression of each case label shall be an integer constant expression and no two of
6624     the case constant expressions in the same switch statement shall have the same value
6625     after conversion. There may be at most one default label in a switch statement.
6626     (Any enclosed switch statement may have a default label or case constant
6627     expressions with values that duplicate case constant expressions in the enclosing
6628     switch statement.)
6629     Semantics
6630 4   A switch statement causes control to jump to, into, or past the statement that is the
6631     switch body, depending on the value of a controlling expression, and on the presence of a
6632     default label and the values of any case labels on or in the switch body. A case or
6633     default label is accessible only within the closest enclosing switch statement.
6634 5   The integer promotions are performed on the controlling expression. The constant
6635     expression in each case label is converted to the promoted type of the controlling
6636     expression. If a converted value matches that of the promoted controlling expression,
6637     control jumps to the statement following the matched case label. Otherwise, if there is
6638     a default label, control jumps to the labeled statement. If no converted case constant
6639     expression matches and there is no default label, no part of the switch body is
6640     executed.
6641     Implementation limits
6642 6   As discussed in 5.2.4.1, the implementation may limit the number of case values in a
6643     switch statement.
6644
6645
6646
6647
6648     154) That is, the declaration either precedes the switch statement, or it follows the last case or
6649          default label associated with the switch that is in the block containing the declaration.
6650
6651 [page 148]
6652
6653 7   EXAMPLE        In the artificial program fragment
6654              switch (expr)
6655              {
6656                    int i = 4;
6657                    f(i);
6658              case 0:
6659                    i = 17;
6660                    /* falls through into default code */
6661              default:
6662                    printf("%d\n", i);
6663              }
6664     the object whose identifier is i exists with automatic storage duration (within the block) but is never
6665     initialized, and thus if the controlling expression has a nonzero value, the call to the printf function will
6666     access an indeterminate value. Similarly, the call to the function f cannot be reached.
6667
6668     6.8.5 Iteration statements
6669     Syntax
6670 1            iteration-statement:
6671                      while ( expression ) statement
6672                      do statement while ( expression ) ;
6673                      for ( expressionopt ; expressionopt ; expressionopt ) statement
6674                      for ( declaration expressionopt ; expressionopt ) statement
6675     Constraints
6676 2   The controlling expression of an iteration statement shall have scalar type.
6677 3   The declaration part of a for statement shall only declare identifiers for objects having
6678     storage class auto or register.
6679     Semantics
6680 4   An iteration statement causes a statement called the loop body to be executed repeatedly
6681     until the controlling expression compares equal to 0. The repetition occurs regardless of
6682     whether the loop body is entered from the iteration statement or by a jump.155)
6683 5   An iteration statement is a block whose scope is a strict subset of the scope of its
6684     enclosing block. The loop body is also a block whose scope is a strict subset of the scope
6685     of the iteration statement.
6686 6   An iteration statement whose controlling expression is not a constant expression,156) that
6687     performs no input/output operations, does not access volatile objects, and performs no
6688     synchronization or atomic operations in its body, controlling expression, or (in the case of
6689
6690     155) Code jumped over is not executed. In particular, the controlling expression of a for or while
6691          statement is not evaluated before entering the loop body, nor is clause-1 of a for statement.
6692     156) An omitted controlling expression is replaced by a nonzero constant, which is a constant expression.
6693
6694 [page 149]
6695
6696     a for statement) its expression-3, may be assumed by the implementation to
6697     terminate.157)
6698     6.8.5.1 The while statement
6699 1   The evaluation of the controlling expression takes place before each execution of the loop
6700     body.
6701     6.8.5.2 The do statement
6702 1   The evaluation of the controlling expression takes place after each execution of the loop
6703     body.
6704     6.8.5.3 The for statement
6705 1   The statement
6706              for ( clause-1 ; expression-2 ; expression-3 ) statement
6707     behaves as follows: The expression expression-2 is the controlling expression that is
6708     evaluated before each execution of the loop body. The expression expression-3 is
6709     evaluated as a void expression after each execution of the loop body. If clause-1 is a
6710     declaration, the scope of any identifiers it declares is the remainder of the declaration and
6711     the entire loop, including the other two expressions; it is reached in the order of execution
6712     before the first evaluation of the controlling expression. If clause-1 is an expression, it is
6713     evaluated as a void expression before the first evaluation of the controlling expression.158)
6714 2   Both clause-1 and expression-3 can be omitted. An omitted expression-2 is replaced by a
6715     nonzero constant.
6716     6.8.6 Jump statements
6717     Syntax
6718 1            jump-statement:
6719                     goto identifier ;
6720                     continue ;
6721                     break ;
6722                     return expressionopt ;
6723
6724
6725
6726
6727     157) This is intended to allow compiler transformations such as removal of empty loops even when
6728          termination cannot be proven.
6729     158) Thus, clause-1 specifies initialization for the loop, possibly declaring one or more variables for use in
6730          the loop; the controlling expression, expression-2, specifies an evaluation made before each iteration,
6731          such that execution of the loop continues until the expression compares equal to 0; and expression-3
6732          specifies an operation (such as incrementing) that is performed after each iteration.
6733
6734 [page 150]
6735
6736     Semantics
6737 2   A jump statement causes an unconditional jump to another place.
6738     6.8.6.1 The goto statement
6739     Constraints
6740 1   The identifier in a goto statement shall name a label located somewhere in the enclosing
6741     function. A goto statement shall not jump from outside the scope of an identifier having
6742     a variably modified type to inside the scope of that identifier.
6743     Semantics
6744 2   A goto statement causes an unconditional jump to the statement prefixed by the named
6745     label in the enclosing function.
6746 3   EXAMPLE 1 It is sometimes convenient to jump into the middle of a complicated set of statements. The
6747     following outline presents one possible approach to a problem based on these three assumptions:
6748       1.   The general initialization code accesses objects only visible to the current function.
6749       2.   The general initialization code is too large to warrant duplication.
6750       3. The code to determine the next operation is at the head of the loop. (To allow it to be reached by
6751          continue statements, for example.)
6752             /* ... */
6753             goto first_time;
6754             for (;;) {
6755                     // determine next operation
6756                     /* ... */
6757                     if (need to reinitialize) {
6758                             // reinitialize-only code
6759                             /* ... */
6760                     first_time:
6761                             // general initialization code
6762                             /* ... */
6763                             continue;
6764                     }
6765                     // handle other operations
6766                     /* ... */
6767             }
6768
6769
6770
6771
6772 [page 151]
6773
6774 4   EXAMPLE 2 A goto statement is not allowed to jump past any declarations of objects with variably
6775     modified types. A jump within the scope, however, is permitted.
6776             goto lab3;                         // invalid: going INTO scope of VLA.
6777             {
6778                   double a[n];
6779                   a[j] = 4.4;
6780             lab3:
6781                   a[j] = 3.3;
6782                   goto lab4;                   // valid: going WITHIN scope of VLA.
6783                   a[j] = 5.5;
6784             lab4:
6785                   a[j] = 6.6;
6786             }
6787             goto lab4;                         // invalid: going INTO scope of VLA.
6788
6789     6.8.6.2 The continue statement
6790     Constraints
6791 1   A continue statement shall appear only in or as a loop body.
6792     Semantics
6793 2   A continue statement causes a jump to the loop-continuation portion of the smallest
6794     enclosing iteration statement; that is, to the end of the loop body. More precisely, in each
6795     of the statements
6796     while (/* ... */) {                  do {                                 for (/* ... */) {
6797        /* ... */                            /* ... */                            /* ... */
6798        continue;                            continue;                            continue;
6799        /* ... */                            /* ... */                            /* ... */
6800     contin: ;                            contin: ;                            contin: ;
6801     }                                    } while (/* ... */);                 }
6802     unless the continue statement shown is in an enclosed iteration statement (in which
6803     case it is interpreted within that statement), it is equivalent to goto contin;.159)
6804     6.8.6.3 The break statement
6805     Constraints
6806 1   A break statement shall appear only in or as a switch body or loop body.
6807     Semantics
6808 2   A break statement terminates execution of the smallest enclosing switch or iteration
6809     statement.
6810
6811
6812
6813     159) Following the contin: label is a null statement.
6814
6815 [page 152]
6816
6817     6.8.6.4 The return statement
6818     Constraints
6819 1   A return statement with an expression shall not appear in a function whose return type
6820     is void. A return statement without an expression shall only appear in a function
6821     whose return type is void.
6822     Semantics
6823 2   A return statement terminates execution of the current function and returns control to
6824     its caller. A function may have any number of return statements.
6825 3   If a return statement with an expression is executed, the value of the expression is
6826     returned to the caller as the value of the function call expression. If the expression has a
6827     type different from the return type of the function in which it appears, the value is
6828     converted as if by assignment to an object having the return type of the function.160)
6829 4   EXAMPLE       In:
6830             struct s { double i; } f(void);
6831             union {
6832                   struct {
6833                         int f1;
6834                         struct s f2;
6835                   } u1;
6836                   struct {
6837                         struct s f3;
6838                         int f4;
6839                   } u2;
6840             } g;
6841             struct s f(void)
6842             {
6843                   return g.u1.f2;
6844             }
6845             /* ... */
6846             g.u2.f3 = f();
6847     there is no undefined behavior, although there would be if the assignment were done directly (without using
6848     a function call to fetch the value).
6849
6850
6851
6852
6853     160) The return statement is not an assignment. The overlap restriction of subclause 6.5.16.1 does not
6854          apply to the case of function return. The representation of floating-point values may have wider range
6855          or precision than implied by the type; a cast may be used to remove this extra range and precision.
6856
6857 [page 153]
6858
6859     6.9 External definitions
6860     Syntax
6861 1            translation-unit:
6862                      external-declaration
6863                      translation-unit external-declaration
6864              external-declaration:
6865                     function-definition
6866                     declaration
6867     Constraints
6868 2   The storage-class specifiers auto and register shall not appear in the declaration
6869     specifiers in an external declaration.
6870 3   There shall be no more than one external definition for each identifier declared with
6871     internal linkage in a translation unit. Moreover, if an identifier declared with internal
6872     linkage is used in an expression (other than as a part of the operand of a sizeof
6873     operator whose result is an integer constant), there shall be exactly one external definition
6874     for the identifier in the translation unit.
6875     Semantics
6876 4   As discussed in 5.1.1.1, the unit of program text after preprocessing is a translation unit,
6877     which consists of a sequence of external declarations. These are described as ''external''
6878     because they appear outside any function (and hence have file scope). As discussed in
6879     6.7, a declaration that also causes storage to be reserved for an object or a function named
6880     by the identifier is a definition.
6881 5   An external definition is an external declaration that is also a definition of a function
6882     (other than an inline definition) or an object. If an identifier declared with external
6883     linkage is used in an expression (other than as part of the operand of a sizeof operator
6884     whose result is an integer constant), somewhere in the entire program there shall be
6885     exactly one external definition for the identifier; otherwise, there shall be no more than
6886     one.161)
6887
6888
6889
6890
6891     161) Thus, if an identifier declared with external linkage is not used in an expression, there need be no
6892          external definition for it.
6893
6894 [page 154]
6895
6896     6.9.1 Function definitions
6897     Syntax
6898 1            function-definition:
6899                     declaration-specifiers declarator declaration-listopt compound-statement
6900              declaration-list:
6901                     declaration
6902                     declaration-list declaration
6903     Constraints
6904 2   The identifier declared in a function definition (which is the name of the function) shall
6905     have a function type, as specified by the declarator portion of the function definition.162)
6906 3   The return type of a function shall be void or a complete object type other than array
6907     type.
6908 4   The storage-class specifier, if any, in the declaration specifiers shall be either extern or
6909     static.
6910 5   If the declarator includes a parameter type list, the declaration of each parameter shall
6911     include an identifier, except for the special case of a parameter list consisting of a single
6912     parameter of type void, in which case there shall not be an identifier. No declaration list
6913     shall follow.
6914 6   If the declarator includes an identifier list, each declaration in the declaration list shall
6915     have at least one declarator, those declarators shall declare only identifiers from the
6916     identifier list, and every identifier in the identifier list shall be declared. An identifier
6917     declared as a typedef name shall not be redeclared as a parameter. The declarations in the
6918     declaration list shall contain no storage-class specifier other than register and no
6919     initializations.
6920
6921
6922
6923     162) The intent is that the type category in a function definition cannot be inherited from a typedef:
6924                   typedef int F(void);                          //   type F is ''function with no parameters
6925                                                                 //                  returning int''
6926                   F f, g;                                       //   f and g both have type compatible with F
6927                   F f { /* ... */ }                             //   WRONG: syntax/constraint error
6928                   F g() { /* ... */ }                           //   WRONG: declares that g returns a function
6929                   int f(void) { /* ... */ }                     //   RIGHT: f has type compatible with F
6930                   int g() { /* ... */ }                         //   RIGHT: g has type compatible with F
6931                   F *e(void) { /* ... */ }                      //   e returns a pointer to a function
6932                   F *((e))(void) { /* ... */ }                  //   same: parentheses irrelevant
6933                   int (*fp)(void);                              //   fp points to a function that has type F
6934                   F *Fp;                                        //   Fp points to a function that has type F
6935
6936
6937 [page 155]
6938
6939      Semantics
6940 7    The declarator in a function definition specifies the name of the function being defined
6941      and the identifiers of its parameters. If the declarator includes a parameter type list, the
6942      list also specifies the types of all the parameters; such a declarator also serves as a
6943      function prototype for later calls to the same function in the same translation unit. If the
6944      declarator includes an identifier list,163) the types of the parameters shall be declared in a
6945      following declaration list. In either case, the type of each parameter is adjusted as
6946      described in 6.7.6.3 for a parameter type list; the resulting type shall be a complete object
6947      type.
6948 8    If a function that accepts a variable number of arguments is defined without a parameter
6949      type list that ends with the ellipsis notation, the behavior is undefined.
6950 9    Each parameter has automatic storage duration; its identifier is an lvalue.164) The layout
6951      of the storage for parameters is unspecified.
6952 10   On entry to the function, the size expressions of each variably modified parameter are
6953      evaluated and the value of each argument expression is converted to the type of the
6954      corresponding parameter as if by assignment. (Array expressions and function
6955      designators as arguments were converted to pointers before the call.)
6956 11   After all parameters have been assigned, the compound statement that constitutes the
6957      body of the function definition is executed.
6958 12   If the } that terminates a function is reached, and the value of the function call is used by
6959      the caller, the behavior is undefined.
6960 13   EXAMPLE 1       In the following:
6961               extern int max(int a, int b)
6962               {
6963                     return a > b ? a : b;
6964               }
6965      extern is the storage-class specifier and int is the type specifier; max(int a, int b) is the
6966      function declarator; and
6967               { return a > b ? a : b; }
6968      is the function body. The following similar definition uses the identifier-list form for the parameter
6969      declarations:
6970
6971
6972
6973
6974      163) See ''future language directions'' (6.11.7).
6975      164) A parameter identifier cannot be redeclared in the function body except in an enclosed block.
6976
6977 [page 156]
6978
6979               extern int max(a, b)
6980               int a, b;
6981               {
6982                     return a > b ? a : b;
6983               }
6984      Here int a, b; is the declaration list for the parameters. The difference between these two definitions is
6985      that the first form acts as a prototype declaration that forces conversion of the arguments of subsequent calls
6986      to the function, whereas the second form does not.
6987
6988 14   EXAMPLE 2           To pass one function to another, one might say
6989                           int f(void);
6990                           /* ... */
6991                           g(f);
6992      Then the definition of g might read
6993               void g(int (*funcp)(void))
6994               {
6995                     /* ... */
6996                     (*funcp)(); /* or funcp(); ...                    */
6997               }
6998      or, equivalently,
6999               void g(int func(void))
7000               {
7001                     /* ... */
7002                     func(); /* or (*func)(); ...                   */
7003               }
7004
7005      6.9.2 External object definitions
7006      Semantics
7007 1    If the declaration of an identifier for an object has file scope and an initializer, the
7008      declaration is an external definition for the identifier.
7009 2    A declaration of an identifier for an object that has file scope without an initializer, and
7010      without a storage-class specifier or with the storage-class specifier static, constitutes a
7011      tentative definition. If a translation unit contains one or more tentative definitions for an
7012      identifier, and the translation unit contains no external definition for that identifier, then
7013      the behavior is exactly as if the translation unit contains a file scope declaration of that
7014      identifier, with the composite type as of the end of the translation unit, with an initializer
7015      equal to 0.
7016 3    If the declaration of an identifier for an object is a tentative definition and has internal
7017      linkage, the declared type shall not be an incomplete type.
7018
7019
7020
7021
7022 [page 157]
7023
7024 4   EXAMPLE 1
7025              int i1 = 1;                    // definition, external linkage
7026              static int i2 = 2;             // definition, internal linkage
7027              extern int i3 = 3;             // definition, external linkage
7028              int i4;                        // tentative definition, external linkage
7029              static int i5;                 // tentative definition, internal linkage
7030              int   i1;                      // valid tentative definition, refers to previous
7031              int   i2;                      // 6.2.2 renders undefined, linkage disagreement
7032              int   i3;                      // valid tentative definition, refers to previous
7033              int   i4;                      // valid tentative definition, refers to previous
7034              int   i5;                      // 6.2.2 renders undefined, linkage disagreement
7035              extern    int   i1;            // refers to previous, whose linkage is external
7036              extern    int   i2;            // refers to previous, whose linkage is internal
7037              extern    int   i3;            // refers to previous, whose linkage is external
7038              extern    int   i4;            // refers to previous, whose linkage is external
7039              extern    int   i5;            // refers to previous, whose linkage is internal
7040
7041 5   EXAMPLE 2       If at the end of the translation unit containing
7042              int i[];
7043     the array i still has incomplete type, the implicit initializer causes it to have one element, which is set to
7044     zero on program startup.
7045
7046
7047
7048
7049 [page 158]
7050
7051     6.10 Preprocessing directives
7052     Syntax
7053 1            preprocessing-file:
7054                     groupopt
7055              group:
7056                       group-part
7057                       group group-part
7058              group-part:
7059                     if-section
7060                     control-line
7061                     text-line
7062                     # non-directive
7063              if-section:
7064                       if-group elif-groupsopt else-groupopt endif-line
7065              if-group:
7066                      # if     constant-expression new-line groupopt
7067                      # ifdef identifier new-line groupopt
7068                      # ifndef identifier new-line groupopt
7069              elif-groups:
7070                      elif-group
7071                      elif-groups elif-group
7072              elif-group:
7073                      # elif       constant-expression new-line groupopt
7074              else-group:
7075                      # else       new-line groupopt
7076              endif-line:
7077                      # endif      new-line
7078
7079
7080
7081
7082 [page 159]
7083
7084              control-line:
7085                     # include pp-tokens new-line
7086                     # define identifier replacement-list new-line
7087                     # define identifier lparen identifier-listopt )
7088                                                     replacement-list new-line
7089                     # define identifier lparen ... ) replacement-list new-line
7090                     # define identifier lparen identifier-list , ... )
7091                                                     replacement-list new-line
7092                     # undef   identifier new-line
7093                     # line    pp-tokens new-line
7094                     # error   pp-tokensopt new-line
7095                     # pragma pp-tokensopt new-line
7096                     #         new-line
7097              text-line:
7098                      pp-tokensopt new-line
7099              non-directive:
7100                     pp-tokens new-line
7101              lparen:
7102                        a ( character not immediately preceded by white-space
7103              replacement-list:
7104                     pp-tokensopt
7105              pp-tokens:
7106                     preprocessing-token
7107                     pp-tokens preprocessing-token
7108              new-line:
7109                     the new-line character
7110     Description
7111 2   A preprocessing directive consists of a sequence of preprocessing tokens that satisfies the
7112     following constraints: The first token in the sequence is a # preprocessing token that (at
7113     the start of translation phase 4) is either the first character in the source file (optionally
7114     after white space containing no new-line characters) or that follows white space
7115     containing at least one new-line character. The last token in the sequence is the first new-
7116     line character that follows the first token in the sequence.165) A new-line character ends
7117     the preprocessing directive even if it occurs within what would otherwise be an
7118
7119     165) Thus, preprocessing directives are commonly called ''lines''. These ''lines'' have no other syntactic
7120          significance, as all white space is equivalent except in certain situations during preprocessing (see the
7121          # character string literal creation operator in 6.10.3.2, for example).
7122
7123 [page 160]
7124
7125     invocation of a function-like macro.
7126 3   A text line shall not begin with a # preprocessing token. A non-directive shall not begin
7127     with any of the directive names appearing in the syntax.
7128 4   When in a group that is skipped (6.10.1), the directive syntax is relaxed to allow any
7129     sequence of preprocessing tokens to occur between the directive name and the following
7130     new-line character.
7131     Constraints
7132 5   The only white-space characters that shall appear between preprocessing tokens within a
7133     preprocessing directive (from just after the introducing # preprocessing token through
7134     just before the terminating new-line character) are space and horizontal-tab (including
7135     spaces that have replaced comments or possibly other white-space characters in
7136     translation phase 3).
7137     Semantics
7138 6   The implementation can process and skip sections of source files conditionally, include
7139     other source files, and replace macros. These capabilities are called preprocessing,
7140     because conceptually they occur before translation of the resulting translation unit.
7141 7   The preprocessing tokens within a preprocessing directive are not subject to macro
7142     expansion unless otherwise stated.
7143 8   EXAMPLE        In:
7144               #define EMPTY
7145               EMPTY # include <file.h>
7146     the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not
7147     begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been
7148     replaced.
7149
7150     6.10.1 Conditional inclusion
7151     Constraints
7152 1   The expression that controls conditional inclusion shall be an integer constant expression
7153     except that: identifiers (including those lexically identical to keywords) are interpreted as *
7154     described below;166) and it may contain unary operator expressions of the form
7155          defined identifier
7156     or
7157          defined ( identifier )
7158     which evaluate to 1 if the identifier is currently defined as a macro name (that is, if it is
7159
7160
7161     166) Because the controlling constant expression is evaluated during translation phase 4, all identifiers
7162          either are or are not macro names -- there simply are no keywords, enumeration constants, etc.
7163
7164 [page 161]
7165
7166     predefined or if it has been the subject of a #define preprocessing directive without an
7167     intervening #undef directive with the same subject identifier), 0 if it is not.
7168 2   Each preprocessing token that remains (in the list of preprocessing tokens that will
7169     become the controlling expression) after all macro replacements have occurred shall be in
7170     the lexical form of a token (6.4).
7171     Semantics
7172 3   Preprocessing directives of the forms
7173        # if   constant-expression new-line groupopt
7174        # elif constant-expression new-line groupopt
7175     check whether the controlling constant expression evaluates to nonzero.
7176 4   Prior to evaluation, macro invocations in the list of preprocessing tokens that will become
7177     the controlling constant expression are replaced (except for those macro names modified
7178     by the defined unary operator), just as in normal text. If the token defined is
7179     generated as a result of this replacement process or use of the defined unary operator
7180     does not match one of the two specified forms prior to macro replacement, the behavior is
7181     undefined. After all replacements due to macro expansion and the defined unary
7182     operator have been performed, all remaining identifiers (including those lexically
7183     identical to keywords) are replaced with the pp-number 0, and then each preprocessing
7184     token is converted into a token. The resulting tokens compose the controlling constant
7185     expression which is evaluated according to the rules of 6.6. For the purposes of this
7186     token conversion and evaluation, all signed integer types and all unsigned integer types
7187     act as if they have the same representation as, respectively, the types intmax_t and
7188     uintmax_t defined in the header <stdint.h>.167) This includes interpreting
7189     character constants, which may involve converting escape sequences into execution
7190     character set members. Whether the numeric value for these character constants matches
7191     the value obtained when an identical character constant occurs in an expression (other
7192     than within a #if or #elif directive) is implementation-defined.168) Also, whether a
7193     single-character character constant may have a negative value is implementation-defined.
7194
7195
7196
7197
7198     167) Thus, on an implementation where INT_MAX is 0x7FFF and UINT_MAX is 0xFFFF, the constant
7199          0x8000 is signed and positive within a #if expression even though it would be unsigned in
7200          translation phase 7.
7201     168) Thus, the constant expression in the following #if directive and if statement is not guaranteed to
7202          evaluate to the same value in these two contexts.
7203            #if 'z' - 'a' == 25
7204            if ('z' - 'a' == 25)
7205
7206
7207 [page 162]
7208
7209 5   Preprocessing directives of the forms
7210        # ifdef identifier new-line groupopt
7211        # ifndef identifier new-line groupopt
7212     check whether the identifier is or is not currently defined as a macro name. Their
7213     conditions are equivalent to #if defined identifier and #if !defined identifier
7214     respectively.
7215 6   Each directive's condition is checked in order. If it evaluates to false (zero), the group
7216     that it controls is skipped: directives are processed only through the name that determines
7217     the directive in order to keep track of the level of nested conditionals; the rest of the
7218     directives' preprocessing tokens are ignored, as are the other preprocessing tokens in the
7219     group. Only the first group whose control condition evaluates to true (nonzero) is
7220     processed. If none of the conditions evaluates to true, and there is a #else directive, the
7221     group controlled by the #else is processed; lacking a #else directive, all the groups
7222     until the #endif are skipped.169)
7223     Forward references: macro replacement (6.10.3), source file inclusion (6.10.2), largest
7224     integer types (7.20.1.5).
7225     6.10.2 Source file inclusion
7226     Constraints
7227 1   A #include directive shall identify a header or source file that can be processed by the
7228     implementation.
7229     Semantics
7230 2   A preprocessing directive of the form
7231        # include <h-char-sequence> new-line
7232     searches a sequence of implementation-defined places for a header identified uniquely by
7233     the specified sequence between the < and > delimiters, and causes the replacement of that
7234     directive by the entire contents of the header. How the places are specified or the header
7235     identified is implementation-defined.
7236 3   A preprocessing directive of the form
7237        # include "q-char-sequence" new-line
7238     causes the replacement of that directive by the entire contents of the source file identified
7239     by the specified sequence between the " delimiters. The named source file is searched
7240
7241
7242     169) As indicated by the syntax, a preprocessing token shall not follow a #else or #endif directive
7243          before the terminating new-line character. However, comments may appear anywhere in a source file,
7244          including within a preprocessing directive.
7245
7246 [page 163]
7247
7248     for in an implementation-defined manner. If this search is not supported, or if the search
7249     fails, the directive is reprocessed as if it read
7250        # include <h-char-sequence> new-line
7251     with the identical contained sequence (including > characters, if any) from the original
7252     directive.
7253 4   A preprocessing directive of the form
7254        # include pp-tokens new-line
7255     (that does not match one of the two previous forms) is permitted. The preprocessing
7256     tokens after include in the directive are processed just as in normal text. (Each
7257     identifier currently defined as a macro name is replaced by its replacement list of
7258     preprocessing tokens.) The directive resulting after all replacements shall match one of
7259     the two previous forms.170) The method by which a sequence of preprocessing tokens
7260     between a < and a > preprocessing token pair or a pair of " characters is combined into a
7261     single header name preprocessing token is implementation-defined.
7262 5   The implementation shall provide unique mappings for sequences consisting of one or
7263     more nondigits or digits (6.4.2.1) followed by a period (.) and a single nondigit. The
7264     first character shall not be a digit. The implementation may ignore distinctions of
7265     alphabetical case and restrict the mapping to eight significant characters before the
7266     period.
7267 6   A #include preprocessing directive may appear in a source file that has been read
7268     because of a #include directive in another file, up to an implementation-defined
7269     nesting limit (see 5.2.4.1).
7270 7   EXAMPLE 1       The most common uses of #include preprocessing directives are as in the following:
7271              #include <stdio.h>
7272              #include "myprog.h"
7273
7274
7275
7276
7277     170) Note that adjacent string literals are not concatenated into a single string literal (see the translation
7278          phases in 5.1.1.2); thus, an expansion that results in two string literals is an invalid directive.
7279
7280 [page 164]
7281
7282 8   EXAMPLE 2      This illustrates macro-replaced #include directives:
7283               #if VERSION == 1
7284                     #define INCFILE          "vers1.h"
7285               #elif VERSION == 2
7286                     #define INCFILE          "vers2.h"        // and so on
7287               #else
7288                      #define INCFILE         "versN.h"
7289               #endif
7290               #include INCFILE
7291
7292     Forward references: macro replacement (6.10.3).
7293     6.10.3 Macro replacement
7294     Constraints
7295 1   Two replacement lists are identical if and only if the preprocessing tokens in both have
7296     the same number, ordering, spelling, and white-space separation, where all white-space
7297     separations are considered identical.
7298 2   An identifier currently defined as an object-like macro shall not be redefined by another
7299     #define preprocessing directive unless the second definition is an object-like macro
7300     definition and the two replacement lists are identical. Likewise, an identifier currently
7301     defined as a function-like macro shall not be redefined by another #define
7302     preprocessing directive unless the second definition is a function-like macro definition
7303     that has the same number and spelling of parameters, and the two replacement lists are
7304     identical.
7305 3   There shall be white-space between the identifier and the replacement list in the definition
7306     of an object-like macro.
7307 4   If the identifier-list in the macro definition does not end with an ellipsis, the number of
7308     arguments (including those arguments consisting of no preprocessing tokens) in an
7309     invocation of a function-like macro shall equal the number of parameters in the macro
7310     definition. Otherwise, there shall be more arguments in the invocation than there are
7311     parameters in the macro definition (excluding the ...). There shall exist a )
7312     preprocessing token that terminates the invocation.
7313 5   The identifier __VA_ARGS__ shall occur only in the replacement-list of a function-like
7314     macro that uses the ellipsis notation in the parameters.
7315 6   A parameter identifier in a function-like macro shall be uniquely declared within its
7316     scope.
7317     Semantics
7318 7   The identifier immediately following the define is called the macro name. There is one
7319     name space for macro names. Any white-space characters preceding or following the
7320     replacement list of preprocessing tokens are not considered part of the replacement list
7321
7322 [page 165]
7323
7324      for either form of macro.
7325 8    If a # preprocessing token, followed by an identifier, occurs lexically at the point at which
7326      a preprocessing directive could begin, the identifier is not subject to macro replacement.
7327 9    A preprocessing directive of the form
7328         # define identifier replacement-list new-line
7329      defines an object-like macro that causes each subsequent instance of the macro name171)
7330      to be replaced by the replacement list of preprocessing tokens that constitute the
7331      remainder of the directive. The replacement list is then rescanned for more macro names
7332      as specified below.
7333 10   A preprocessing directive of the form
7334         # define identifier lparen identifier-listopt ) replacement-list new-line
7335         # define identifier lparen ... ) replacement-list new-line
7336         # define identifier lparen identifier-list , ... ) replacement-list new-line
7337      defines a function-like macro with parameters, whose use is similar syntactically to a
7338      function call. The parameters are specified by the optional list of identifiers, whose scope
7339      extends from their declaration in the identifier list until the new-line character that
7340      terminates the #define preprocessing directive. Each subsequent instance of the
7341      function-like macro name followed by a ( as the next preprocessing token introduces the
7342      sequence of preprocessing tokens that is replaced by the replacement list in the definition
7343      (an invocation of the macro). The replaced sequence of preprocessing tokens is
7344      terminated by the matching ) preprocessing token, skipping intervening matched pairs of
7345      left and right parenthesis preprocessing tokens. Within the sequence of preprocessing
7346      tokens making up an invocation of a function-like macro, new-line is considered a normal
7347      white-space character.
7348 11   The sequence of preprocessing tokens bounded by the outside-most matching parentheses
7349      forms the list of arguments for the function-like macro. The individual arguments within
7350      the list are separated by comma preprocessing tokens, but comma preprocessing tokens
7351      between matching inner parentheses do not separate arguments. If there are sequences of
7352      preprocessing tokens within the list of arguments that would otherwise act as
7353      preprocessing directives,172) the behavior is undefined.
7354 12   If there is a ... in the identifier-list in the macro definition, then the trailing arguments,
7355      including any separating comma preprocessing tokens, are merged to form a single item:
7356
7357
7358      171) Since, by macro-replacement time, all character constants and string literals are preprocessing tokens,
7359           not sequences possibly containing identifier-like subsequences (see 5.1.1.2, translation phases), they
7360           are never scanned for macro names or parameters.
7361      172) Despite the name, a non-directive is a preprocessing directive.
7362
7363 [page 166]
7364
7365     the variable arguments. The number of arguments so combined is such that, following
7366     merger, the number of arguments is one more than the number of parameters in the macro
7367     definition (excluding the ...).
7368     6.10.3.1 Argument substitution
7369 1   After the arguments for the invocation of a function-like macro have been identified,
7370     argument substitution takes place. A parameter in the replacement list, unless preceded
7371     by a # or ## preprocessing token or followed by a ## preprocessing token (see below), is
7372     replaced by the corresponding argument after all macros contained therein have been
7373     expanded. Before being substituted, each argument's preprocessing tokens are
7374     completely macro replaced as if they formed the rest of the preprocessing file; no other
7375     preprocessing tokens are available.
7376 2   An identifier __VA_ARGS__ that occurs in the replacement list shall be treated as if it
7377     were a parameter, and the variable arguments shall form the preprocessing tokens used to
7378     replace it.
7379     6.10.3.2 The # operator
7380     Constraints
7381 1   Each # preprocessing token in the replacement list for a function-like macro shall be
7382     followed by a parameter as the next preprocessing token in the replacement list.
7383     Semantics
7384 2   If, in the replacement list, a parameter is immediately preceded by a # preprocessing
7385     token, both are replaced by a single character string literal preprocessing token that
7386     contains the spelling of the preprocessing token sequence for the corresponding
7387     argument. Each occurrence of white space between the argument's preprocessing tokens
7388     becomes a single space character in the character string literal. White space before the
7389     first preprocessing token and after the last preprocessing token composing the argument
7390     is deleted. Otherwise, the original spelling of each preprocessing token in the argument
7391     is retained in the character string literal, except for special handling for producing the
7392     spelling of string literals and character constants: a \ character is inserted before each "
7393     and \ character of a character constant or string literal (including the delimiting "
7394     characters), except that it is implementation-defined whether a \ character is inserted
7395     before the \ character beginning a universal character name. If the replacement that
7396     results is not a valid character string literal, the behavior is undefined. The character
7397     string literal corresponding to an empty argument is "". The order of evaluation of # and
7398     ## operators is unspecified.
7399
7400
7401
7402
7403 [page 167]
7404
7405     6.10.3.3 The ## operator
7406     Constraints
7407 1   A ## preprocessing token shall not occur at the beginning or at the end of a replacement
7408     list for either form of macro definition.
7409     Semantics
7410 2   If, in the replacement list of a function-like macro, a parameter is immediately preceded
7411     or followed by a ## preprocessing token, the parameter is replaced by the corresponding
7412     argument's preprocessing token sequence; however, if an argument consists of no
7413     preprocessing tokens, the parameter is replaced by a placemarker preprocessing token
7414     instead.173)
7415 3   For both object-like and function-like macro invocations, before the replacement list is
7416     reexamined for more macro names to replace, each instance of a ## preprocessing token
7417     in the replacement list (not from an argument) is deleted and the preceding preprocessing
7418     token is concatenated with the following preprocessing token. Placemarker
7419     preprocessing tokens are handled specially: concatenation of two placemarkers results in
7420     a single placemarker preprocessing token, and concatenation of a placemarker with a
7421     non-placemarker preprocessing token results in the non-placemarker preprocessing token.
7422     If the result is not a valid preprocessing token, the behavior is undefined. The resulting
7423     token is available for further macro replacement. The order of evaluation of ## operators
7424     is unspecified.
7425 4   EXAMPLE       In the following fragment:
7426             #define     hash_hash # ## #
7427             #define     mkstr(a) # a
7428             #define     in_between(a) mkstr(a)
7429             #define     join(c, d) in_between(c hash_hash d)
7430             char p[] = join(x, y); // equivalent to
7431                                    // char p[] = "x ## y";
7432     The expansion produces, at various stages:
7433             join(x, y)
7434             in_between(x hash_hash y)
7435             in_between(x ## y)
7436             mkstr(x ## y)
7437             "x ## y"
7438     In other words, expanding hash_hash produces a new token, consisting of two adjacent sharp signs, but
7439     this new token is not the ## operator.
7440
7441
7442     173) Placemarker preprocessing tokens do not appear in the syntax because they are temporary entities that
7443          exist only within translation phase 4.
7444
7445 [page 168]
7446
7447     6.10.3.4 Rescanning and further replacement
7448 1   After all parameters in the replacement list have been substituted and # and ##
7449     processing has taken place, all placemarker preprocessing tokens are removed. The
7450     resulting preprocessing token sequence is then rescanned, along with all subsequent
7451     preprocessing tokens of the source file, for more macro names to replace.
7452 2   If the name of the macro being replaced is found during this scan of the replacement list
7453     (not including the rest of the source file's preprocessing tokens), it is not replaced.
7454     Furthermore, if any nested replacements encounter the name of the macro being replaced,
7455     it is not replaced. These nonreplaced macro name preprocessing tokens are no longer
7456     available for further replacement even if they are later (re)examined in contexts in which
7457     that macro name preprocessing token would otherwise have been replaced.
7458 3   The resulting completely macro-replaced preprocessing token sequence is not processed
7459     as a preprocessing directive even if it resembles one, but all pragma unary operator
7460     expressions within it are then processed as specified in 6.10.9 below.
7461     6.10.3.5 Scope of macro definitions
7462 1   A macro definition lasts (independent of block structure) until a corresponding #undef
7463     directive is encountered or (if none is encountered) until the end of the preprocessing
7464     translation unit. Macro definitions have no significance after translation phase 4.
7465 2   A preprocessing directive of the form
7466        # undef identifier new-line
7467     causes the specified identifier no longer to be defined as a macro name. It is ignored if
7468     the specified identifier is not currently defined as a macro name.
7469 3   EXAMPLE 1      The simplest use of this facility is to define a ''manifest constant'', as in
7470             #define TABSIZE 100
7471             int table[TABSIZE];
7472
7473 4   EXAMPLE 2 The following defines a function-like macro whose value is the maximum of its arguments.
7474     It has the advantages of working for any compatible types of the arguments and of generating in-line code
7475     without the overhead of function calling. It has the disadvantages of evaluating one or the other of its
7476     arguments a second time (including side effects) and generating more code than a function if invoked
7477     several times. It also cannot have its address taken, as it has none.
7478             #define max(a, b) ((a) > (b) ? (a) : (b))
7479     The parentheses ensure that the arguments and the resulting expression are bound properly.
7480
7481
7482
7483
7484 [page 169]
7485
7486 5   EXAMPLE 3     To illustrate the rules for redefinition and reexamination, the sequence
7487              #define   x         3
7488              #define   f(a)      f(x * (a))
7489              #undef    x
7490              #define   x         2
7491              #define   g         f
7492              #define   z         z[0]
7493              #define   h         g(~
7494              #define   m(a)      a(w)
7495              #define   w         0,1
7496              #define   t(a)      a
7497              #define   p()       int
7498              #define   q(x)      x
7499              #define   r(x,y)    x ## y
7500              #define   str(x)    # x
7501              f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
7502              g(x+(3,4)-w) | h 5) & m
7503                    (f)^m(m);
7504              p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
7505              char c[2][6] = { str(hello), str() };
7506     results in
7507              f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
7508              f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
7509              int i[] = { 1, 23, 4, 5, };
7510              char c[2][6] = { "hello", "" };
7511
7512 6   EXAMPLE 4     To illustrate the rules for creating character string literals and concatenating tokens, the
7513     sequence
7514              #define str(s)      # s
7515              #define xstr(s)     str(s)
7516              #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \
7517                                      x ## s, x ## t)
7518              #define INCFILE(n) vers ## n
7519              #define glue(a, b) a ## b
7520              #define xglue(a, b) glue(a, b)
7521              #define HIGHLOW     "hello"
7522              #define LOW         LOW ", world"
7523              debug(1, 2);
7524              fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away
7525                    == 0) str(: @\n), s);
7526              #include xstr(INCFILE(2).h)
7527              glue(HIGH, LOW);
7528              xglue(HIGH, LOW)
7529     results in
7530
7531
7532
7533
7534 [page 170]
7535
7536              printf("x" "1" "= %d, x" "2" "= %s", x1, x2);
7537              fputs(
7538                "strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n",
7539                s);
7540              #include "vers2.h"    (after macro replacement, before file access)
7541              "hello";
7542              "hello" ", world"
7543     or, after concatenation of the character string literals,
7544              printf("x1= %d, x2= %s", x1, x2);
7545              fputs(
7546                "strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: @\n",
7547                s);
7548              #include "vers2.h"    (after macro replacement, before file access)
7549              "hello";
7550              "hello, world"
7551     Space around the # and ## tokens in the macro definition is optional.
7552
7553 7   EXAMPLE 5        To illustrate the rules for placemarker preprocessing tokens, the sequence
7554              #define t(x,y,z) x ## y ## z
7555              int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
7556                         t(10,,), t(,11,), t(,,12), t(,,) };
7557     results in
7558              int j[] = { 123, 45, 67, 89,
7559                          10, 11, 12, };
7560
7561 8   EXAMPLE 6        To demonstrate the redefinition rules, the following sequence is valid.
7562              #define      OBJ_LIKE      (1-1)
7563              #define      OBJ_LIKE      /* white space */ (1-1) /* other */
7564              #define      FUNC_LIKE(a)   ( a )
7565              #define      FUNC_LIKE( a )( /* note the white space */ \
7566                                           a /* other stuff on this line
7567                                               */ )
7568     But the following redefinitions are invalid:
7569              #define      OBJ_LIKE    (0)     // different token sequence
7570              #define      OBJ_LIKE    (1 - 1) // different white space
7571              #define      FUNC_LIKE(b) ( a ) // different parameter usage
7572              #define      FUNC_LIKE(b) ( b ) // different parameter spelling
7573
7574 9   EXAMPLE 7        Finally, to show the variable argument list macro facilities:
7575              #define debug(...)       fprintf(stderr, __VA_ARGS__)
7576              #define showlist(...)    puts(#__VA_ARGS__)
7577              #define report(test, ...) ((test)?puts(#test):\
7578                          printf(__VA_ARGS__))
7579              debug("Flag");
7580              debug("X = %d\n", x);
7581              showlist(The first, second, and third items.);
7582              report(x>y, "x is %d but y is %d", x, y);
7583
7584
7585 [page 171]
7586
7587     results in
7588              fprintf(stderr, "Flag" );
7589              fprintf(stderr, "X = %d\n", x );
7590              puts( "The first, second, and third items." );
7591              ((x>y)?puts("x>y"):
7592                          printf("x is %d but y is %d", x, y));
7593
7594     6.10.4 Line control
7595     Constraints
7596 1   The string literal of a #line directive, if present, shall be a character string literal.
7597     Semantics
7598 2   The line number of the current source line is one greater than the number of new-line
7599     characters read or introduced in translation phase 1 (5.1.1.2) while processing the source
7600     file to the current token.
7601 3   A preprocessing directive of the form
7602        # line digit-sequence new-line
7603     causes the implementation to behave as if the following sequence of source lines begins
7604     with a source line that has a line number as specified by the digit sequence (interpreted as
7605     a decimal integer). The digit sequence shall not specify zero, nor a number greater than
7606     2147483647.
7607 4   A preprocessing directive of the form
7608        # line digit-sequence "s-char-sequenceopt" new-line
7609     sets the presumed line number similarly and changes the presumed name of the source
7610     file to be the contents of the character string literal.
7611 5   A preprocessing directive of the form
7612        # line pp-tokens new-line
7613     (that does not match one of the two previous forms) is permitted. The preprocessing
7614     tokens after line on the directive are processed just as in normal text (each identifier
7615     currently defined as a macro name is replaced by its replacement list of preprocessing
7616     tokens). The directive resulting after all replacements shall match one of the two
7617     previous forms and is then processed as appropriate.
7618
7619
7620
7621
7622 [page 172]
7623
7624     6.10.5 Error directive
7625     Semantics
7626 1   A preprocessing directive of the form
7627        # error pp-tokensopt new-line
7628     causes the implementation to produce a diagnostic message that includes the specified
7629     sequence of preprocessing tokens.
7630     6.10.6 Pragma directive
7631     Semantics
7632 1   A preprocessing directive of the form
7633        # pragma pp-tokensopt new-line
7634     where the preprocessing token STDC does not immediately follow pragma in the
7635     directive (prior to any macro replacement)174) causes the implementation to behave in an
7636     implementation-defined manner. The behavior might cause translation to fail or cause the
7637     translator or the resulting program to behave in a non-conforming manner. Any such
7638     pragma that is not recognized by the implementation is ignored.
7639 2   If the preprocessing token STDC does immediately follow pragma in the directive (prior
7640     to any macro replacement), then no macro replacement is performed on the directive, and
7641     the directive shall have one of the following forms175) whose meanings are described
7642     elsewhere:
7643        #pragma STDC FP_CONTRACT on-off-switch
7644        #pragma STDC FENV_ACCESS on-off-switch
7645        #pragma STDC CX_LIMITED_RANGE on-off-switch
7646        on-off-switch: one of
7647                    ON     OFF           DEFAULT
7648     Forward references: the FP_CONTRACT pragma (7.12.2), the FENV_ACCESS pragma
7649     (7.6.1), the CX_LIMITED_RANGE pragma (7.3.4).
7650
7651
7652
7653
7654     174) An implementation is not required to perform macro replacement in pragmas, but it is permitted
7655          except for in standard pragmas (where STDC immediately follows pragma). If the result of macro
7656          replacement in a non-standard pragma has the same form as a standard pragma, the behavior is still
7657          implementation-defined; an implementation is permitted to behave as if it were the standard pragma,
7658          but is not required to.
7659     175) See ''future language directions'' (6.11.8).
7660
7661 [page 173]
7662
7663     6.10.7 Null directive
7664     Semantics
7665 1   A preprocessing directive of the form
7666        # new-line
7667     has no effect.
7668     6.10.8 Predefined macro names
7669 1   The values of the predefined macros listed in the following subclauses176) (except for
7670     __FILE__ and __LINE__) remain constant throughout the translation unit.
7671 2   None of these macro names, nor the identifier defined, shall be the subject of a
7672     #define or a #undef preprocessing directive. Any other predefined macro names
7673     shall begin with a leading underscore followed by an uppercase letter or a second
7674     underscore.
7675 3   The implementation shall not predefine the macro __cplusplus, nor shall it define it
7676     in any standard header.
7677     Forward references: standard headers (7.1.2).
7678     6.10.8.1 Mandatory macros
7679 1   The following macro names shall be defined by the implementation:
7680     __DATE__ The date of translation of the preprocessing translation unit: a character
7681                string literal of the form "Mmm dd yyyy", where the names of the
7682                months are the same as those generated by the asctime function, and the
7683                first character of dd is a space character if the value is less than 10. If the
7684                date of translation is not available, an implementation-defined valid date
7685                shall be supplied.
7686     __FILE__ The presumed name of the current source file (a character string literal).177)
7687     __LINE__ The presumed line number (within the current source file) of the current
7688                source line (an integer constant).177)
7689     __STDC__ The integer constant 1, intended to indicate a conforming implementation.
7690     __STDC_HOSTED__ The integer constant 1 if the implementation is a hosted
7691               implementation or the integer constant 0 if it is not.
7692
7693
7694
7695
7696     176) See ''future language directions'' (6.11.9).
7697     177) The presumed source file name and line number can be changed by the #line directive.
7698
7699 [page 174]
7700
7701     __STDC_VERSION__ The integer constant 201ymmL.178)
7702     __TIME__ The time of translation of the preprocessing translation unit: a character
7703                string literal of the form "hh:mm:ss" as in the time generated by the
7704                asctime function. If the time of translation is not available, an
7705                implementation-defined valid time shall be supplied.
7706     Forward references: the asctime function (7.26.3.1).
7707     6.10.8.2 Environment macros
7708 1   The following macro names are conditionally defined by the implementation:
7709     __STDC_ISO_10646__ An integer constant of the form yyyymmL (for example,
7710               199712L). If this symbol is defined, then every character in the Unicode
7711               required set, when stored in an object of type wchar_t, has the same
7712               value as the short identifier of that character. The Unicode required set
7713               consists of all the characters that are defined by ISO/IEC 10646, along with
7714               all amendments and technical corrigenda, as of the specified year and
7715               month. If some other encoding is used, the macro shall not be defined and
7716               the actual encoding used is implementation-defined.
7717     __STDC_MB_MIGHT_NEQ_WC__ The integer constant 1, intended to indicate that, in
7718               the encoding for wchar_t, a member of the basic character set need not
7719               have a code value equal to its value when used as the lone character in an
7720               integer character constant.
7721     __STDC_UTF_16__ The integer constant 1, intended to indicate that values of type
7722               char16_t are UTF-16 encoded. If some other encoding is used, the
7723               macro shall not be defined and the actual encoding used is implementation-
7724               defined.
7725     __STDC_UTF_32__ The integer constant 1, intended to indicate that values of type
7726               char32_t are UTF-32 encoded. If some other encoding is used, the
7727               macro shall not be defined and the actual encoding used is implementation-
7728               defined.
7729     Forward references: common definitions (7.19), unicode utilities (7.27).
7730
7731
7732
7733
7734     178) This macro was not specified in ISO/IEC 9899:1990 and was specified as 199409L in
7735          ISO/IEC 9899/AMD1:1995 and as 199901L in ISO/IEC 9899:1999. The intention is that this will
7736          remain an integer constant of type long int that is increased with each revision of this International
7737          Standard.
7738
7739 [page 175]
7740
7741     6.10.8.3 Conditional feature macros
7742 1   The following macro names are conditionally defined by the implementation:
7743     __STDC_ANALYZABLE__ The integer constant 1, intended to indicate conformance to
7744               the specifications in annex L (Analyzability).
7745     __STDC_IEC_559__ The integer constant 1, intended to indicate conformance to the
7746               specifications in annex F (IEC 60559 floating-point arithmetic).
7747     __STDC_IEC_559_COMPLEX__ The integer constant 1, intended to indicate
7748               adherence to the specifications in annex G (IEC 60559 compatible complex
7749               arithmetic).
7750     __STDC_LIB_EXT1__ The integer constant 201ymmL, intended to indicate support
7751               for the extensions defined in annex K (Bounds-checking interfaces).179)
7752     __STDC_NO_COMPLEX__ The integer constant 1, intended to indicate that the
7753               implementation does not support complex types or the <complex.h>
7754               header.
7755     __STDC_NO_THREADS__ The integer constant 1, intended to indicate that the
7756               implementation does not support atomic types (including the _Atomic
7757               type qualifier and the <stdatomic.h> header) or the <threads.h>
7758               header.
7759     __STDC_NO_VLA__ The integer constant 1, intended to indicate that the
7760               implementation does not support variable length arrays or variably
7761               modified types.
7762 2   An implementation that defines __STDC_NO_COMPLEX__ shall not define
7763     __STDC_IEC_559_COMPLEX__.
7764     6.10.9 Pragma operator
7765     Semantics
7766 1   A unary operator expression of the form:
7767        _Pragma ( string-literal )
7768     is processed as follows: The string literal is destringized by deleting the L prefix, if
7769     present, deleting the leading and trailing double-quotes, replacing each escape sequence
7770     \" by a double-quote, and replacing each escape sequence \\ by a single backslash. The
7771     resulting sequence of characters is processed through translation phase 3 to produce
7772     preprocessing tokens that are executed as if they were the pp-tokens in a pragma
7773
7774
7775     179) The intention is that this will remain an integer constant of type long int that is increased with
7776          each revision of this International Standard.
7777
7778 [page 176]
7779
7780     directive. The original four preprocessing tokens in the unary operator expression are
7781     removed.
7782 2   EXAMPLE       A directive of the form:
7783               #pragma listing on "..\listing.dir"
7784     can also be expressed as:
7785               _Pragma ( "listing on \"..\\listing.dir\"" )
7786     The latter form is processed in the same way whether it appears literally as shown, or results from macro
7787     replacement, as in:
7788               #define LISTING(x) PRAGMA(listing on #x)
7789               #define PRAGMA(x) _Pragma(#x)
7790               LISTING ( ..\listing.dir )
7791
7792
7793
7794
7795 [page 177]
7796
7797     6.11 Future language directions
7798     6.11.1 Floating types
7799 1   Future standardization may include additional floating-point types, including those with
7800     greater range, precision, or both than long double.
7801     6.11.2 Linkages of identifiers
7802 1   Declaring an identifier with internal linkage at file scope without the static storage-
7803     class specifier is an obsolescent feature.
7804     6.11.3 External names
7805 1   Restriction of the significance of an external name to fewer than 255 characters
7806     (considering each universal character name or extended source character as a single
7807     character) is an obsolescent feature that is a concession to existing implementations.
7808     6.11.4 Character escape sequences
7809 1   Lowercase letters as escape sequences are reserved for future standardization. Other
7810     characters may be used in extensions.
7811     6.11.5 Storage-class specifiers
7812 1   The placement of a storage-class specifier other than at the beginning of the declaration
7813     specifiers in a declaration is an obsolescent feature.
7814     6.11.6 Function declarators
7815 1   The use of function declarators with empty parentheses (not prototype-format parameter
7816     type declarators) is an obsolescent feature.
7817     6.11.7 Function definitions
7818 1   The use of function definitions with separate parameter identifier and declaration lists
7819     (not prototype-format parameter type and identifier declarators) is an obsolescent feature.
7820     6.11.8 Pragma directives
7821 1   Pragmas whose first preprocessing token is STDC are reserved for future standardization.
7822     6.11.9 Predefined macro names
7823 1   Macro names beginning with __STDC_ are reserved for future standardization.
7824
7825
7826
7827
7828 [page 178]
7829
7830
7831     7. Library
7832     7.1 Introduction
7833     7.1.1 Definitions of terms
7834 1   A string is a contiguous sequence of characters terminated by and including the first null
7835     character. The term multibyte string is sometimes used instead to emphasize special
7836     processing given to multibyte characters contained in the string or to avoid confusion
7837     with a wide string. A pointer to a string is a pointer to its initial (lowest addressed)
7838     character. The length of a string is the number of bytes preceding the null character and
7839     the value of a string is the sequence of the values of the contained characters, in order.
7840 2   The decimal-point character is the character used by functions that convert floating-point
7841     numbers to or from character sequences to denote the beginning of the fractional part of
7842     such character sequences.180) It is represented in the text and examples by a period, but
7843     may be changed by the setlocale function.
7844 3   A null wide character is a wide character with code value zero.
7845 4   A wide string is a contiguous sequence of wide characters terminated by and including
7846     the first null wide character. A pointer to a wide string is a pointer to its initial (lowest
7847     addressed) wide character. The length of a wide string is the number of wide characters
7848     preceding the null wide character and the value of a wide string is the sequence of code
7849     values of the contained wide characters, in order.
7850 5   A shift sequence is a contiguous sequence of bytes within a multibyte string that
7851     (potentially) causes a change in shift state (see 5.2.1.2). A shift sequence shall not have a
7852     corresponding wide character; it is instead taken to be an adjunct to an adjacent multibyte
7853     character.181)
7854     Forward references: character handling (7.4), the setlocale function (7.11.1.1).
7855
7856
7857
7858
7859     180) The functions that make use of the decimal-point character are the numeric conversion functions
7860          (7.22.1, 7.28.4.1) and the formatted input/output functions (7.21.6, 7.28.2).
7861     181) For state-dependent encodings, the values for MB_CUR_MAX and MB_LEN_MAX shall thus be large
7862          enough to count all the bytes in any complete multibyte character plus at least one adjacent shift
7863          sequence of maximum length. Whether these counts provide for more than one shift sequence is the
7864          implementation's choice.
7865
7866 [page 179]
7867
7868     7.1.2 Standard headers
7869 1   Each library function is declared, with a type that includes a prototype, in a header,182)
7870     whose contents are made available by the #include preprocessing directive. The
7871     header declares a set of related functions, plus any necessary types and additional macros
7872     needed to facilitate their use. Declarations of types described in this clause shall not
7873     include type qualifiers, unless explicitly stated otherwise.
7874 2   The standard headers are183)
7875            <assert.h>             <iso646.h>              <stdarg.h>              <string.h>
7876            <complex.h>            <limits.h>              <stdatomic.h>           <tgmath.h>
7877            <ctype.h>              <locale.h>              <stdbool.h>             <threads.h>
7878            <errno.h>              <math.h>                <stddef.h>              <time.h>
7879            <fenv.h>               <setjmp.h>              <stdint.h>              <uchar.h>
7880            <float.h>              <signal.h>              <stdio.h>               <wchar.h>
7881            <inttypes.h>           <stdalign.h>            <stdlib.h>              <wctype.h>
7882 3   If a file with the same name as one of the above < and > delimited sequences, not
7883     provided as part of the implementation, is placed in any of the standard places that are
7884     searched for included source files, the behavior is undefined.
7885 4   Standard headers may be included in any order; each may be included more than once in
7886     a given scope, with no effect different from being included only once, except that the
7887     effect of including <assert.h> depends on the definition of NDEBUG (see 7.2). If
7888     used, a header shall be included outside of any external declaration or definition, and it
7889     shall first be included before the first reference to any of the functions or objects it
7890     declares, or to any of the types or macros it defines. However, if an identifier is declared
7891     or defined in more than one header, the second and subsequent associated headers may be
7892     included after the initial reference to the identifier. The program shall not have any
7893     macros with names lexically identical to keywords currently defined prior to the
7894     inclusion.
7895 5   Any definition of an object-like macro described in this clause shall expand to code that is
7896     fully protected by parentheses where necessary, so that it groups in an arbitrary
7897     expression as if it were a single identifier.
7898 6   Any declaration of a library function shall have external linkage.
7899
7900
7901
7902
7903     182) A header is not necessarily a source file, nor are the < and > delimited sequences in header names
7904          necessarily valid source file names.
7905     183) The headers <complex.h>, <stdatomic.h>, and <threads.h> are conditional features that
7906          implementations need not support; see 6.10.8.3.
7907
7908 [page 180]
7909
7910 7   A summary of the contents of the standard headers is given in annex B.
7911     Forward references: diagnostics (7.2).
7912     7.1.3 Reserved identifiers
7913 1   Each header declares or defines all identifiers listed in its associated subclause, and
7914     optionally declares or defines identifiers listed in its associated future library directions
7915     subclause and identifiers which are always reserved either for any use or for use as file
7916     scope identifiers.
7917     -- All identifiers that begin with an underscore and either an uppercase letter or another
7918       underscore are always reserved for any use.
7919     -- All identifiers that begin with an underscore are always reserved for use as identifiers
7920       with file scope in both the ordinary and tag name spaces.
7921     -- Each macro name in any of the following subclauses (including the future library
7922       directions) is reserved for use as specified if any of its associated headers is included;
7923       unless explicitly stated otherwise (see 7.1.4).
7924     -- All identifiers with external linkage in any of the following subclauses (including the
7925       future library directions) and errno are always reserved for use as identifiers with
7926       external linkage.184)
7927     -- Each identifier with file scope listed in any of the following subclauses (including the
7928       future library directions) is reserved for use as a macro name and as an identifier with
7929       file scope in the same name space if any of its associated headers is included.
7930 2   No other identifiers are reserved. If the program declares or defines an identifier in a
7931     context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved
7932     identifier as a macro name, the behavior is undefined.
7933 3   If the program removes (with #undef) any macro definition of an identifier in the first
7934     group listed above, the behavior is undefined.
7935
7936
7937
7938
7939     184) The list of reserved identifiers with external linkage includes math_errhandling, setjmp,
7940          va_copy, and va_end.
7941
7942 [page 181]
7943
7944     7.1.4 Use of library functions
7945 1   Each of the following statements applies unless explicitly stated otherwise in the detailed
7946     descriptions that follow: If an argument to a function has an invalid value (such as a value
7947     outside the domain of the function, or a pointer outside the address space of the program,
7948     or a null pointer, or a pointer to non-modifiable storage when the corresponding
7949     parameter is not const-qualified) or a type (after promotion) not expected by a function
7950     with variable number of arguments, the behavior is undefined. If a function argument is
7951     described as being an array, the pointer actually passed to the function shall have a value
7952     such that all address computations and accesses to objects (that would be valid if the
7953     pointer did point to the first element of such an array) are in fact valid. Any function
7954     declared in a header may be additionally implemented as a function-like macro defined in
7955     the header, so if a library function is declared explicitly when its header is included, one
7956     of the techniques shown below can be used to ensure the declaration is not affected by
7957     such a macro. Any macro definition of a function can be suppressed locally by enclosing
7958     the name of the function in parentheses, because the name is then not followed by the left
7959     parenthesis that indicates expansion of a macro function name. For the same syntactic
7960     reason, it is permitted to take the address of a library function even if it is also defined as
7961     a macro.185) The use of #undef to remove any macro definition will also ensure that an
7962     actual function is referred to. Any invocation of a library function that is implemented as
7963     a macro shall expand to code that evaluates each of its arguments exactly once, fully
7964     protected by parentheses where necessary, so it is generally safe to use arbitrary
7965     expressions as arguments.186) Likewise, those function-like macros described in the
7966     following subclauses may be invoked in an expression anywhere a function with a
7967     compatible return type could be called.187) All object-like macros listed as expanding to
7968
7969
7970     185) This means that an implementation shall provide an actual function for each library function, even if it
7971          also provides a macro for that function.
7972     186) Such macros might not contain the sequence points that the corresponding function calls do.
7973     187) Because external identifiers and some macro names beginning with an underscore are reserved,
7974          implementations may provide special semantics for such names. For example, the identifier
7975          _BUILTIN_abs could be used to indicate generation of in-line code for the abs function. Thus, the
7976          appropriate header could specify
7977                    #define abs(x) _BUILTIN_abs(x)
7978           for a compiler whose code generator will accept it.
7979           In this manner, a user desiring to guarantee that a given library function such as abs will be a genuine
7980           function may write
7981                    #undef abs
7982           whether the implementation's header provides a macro implementation of abs or a built-in
7983           implementation. The prototype for the function, which precedes and is hidden by any macro
7984           definition, is thereby revealed also.
7985
7986 [page 182]
7987
7988     integer constant expressions shall additionally be suitable for use in #if preprocessing
7989     directives.
7990 2   Provided that a library function can be declared without reference to any type defined in a
7991     header, it is also permissible to declare the function and use it without including its
7992     associated header.
7993 3   There is a sequence point immediately before a library function returns.
7994 4   The functions in the standard library are not guaranteed to be reentrant and may modify
7995     objects with static or thread storage duration.188)
7996 5   Unless explicitly stated otherwise in the detailed descriptions that follow, library
7997     functions shall prevent data races as follows: A library function shall not directly or
7998     indirectly access objects accessible by threads other than the current thread unless the
7999     objects are accessed directly or indirectly via the function's arguments. A library
8000     function shall not directly or indirectly modify objects accessible by threads other than
8001     the current thread unless the objects are accessed directly or indirectly via the function's
8002     non-const arguments.189) Implementations may share their own internal objects between
8003     threads if the objects are not visible to users and are protected against data races.
8004 6   Unless otherwise specified, library functions shall perform all operations solely within the
8005     current thread if those operations have effects that are visible to users.190)
8006 7   EXAMPLE        The function atoi may be used in any of several ways:
8007     -- by use of its associated header (possibly generating a macro expansion)
8008                  #include <stdlib.h>
8009                  const char *str;
8010                  /* ... */
8011                  i = atoi(str);
8012     -- by use of its associated header (assuredly generating a true function reference)
8013
8014
8015
8016
8017     188) Thus, a signal handler cannot, in general, call standard library functions.
8018     189) This means, for example, that an implementation is not permitted to use a static object for internal
8019          purposes without synchronization because it could cause a data race even in programs that do not
8020          explicitly share objects between threads.
8021     190) This allows implementations to parallelize operations if there are no visible side effects.
8022
8023 [page 183]
8024
8025             #include <stdlib.h>
8026             #undef atoi
8027             const char *str;
8028             /* ... */
8029             i = atoi(str);
8030    or
8031             #include <stdlib.h>
8032             const char *str;
8033             /* ... */
8034             i = (atoi)(str);
8035 -- by explicit declaration
8036             extern int atoi(const char *);
8037             const char *str;
8038             /* ... */
8039             i = atoi(str);
8040
8041
8042
8043
8044 [page 184]
8045
8046     7.2 Diagnostics <assert.h>
8047 1   The header <assert.h> defines the assert and static_assert macros and
8048     refers to another macro,
8049             NDEBUG
8050     which is not defined by <assert.h>. If NDEBUG is defined as a macro name at the
8051     point in the source file where <assert.h> is included, the assert macro is defined
8052     simply as
8053             #define assert(ignore) ((void)0)
8054     The assert macro is redefined according to the current state of NDEBUG each time that
8055     <assert.h> is included.
8056 2   The assert macro shall be implemented as a macro, not as an actual function. If the
8057     macro definition is suppressed in order to access an actual function, the behavior is
8058     undefined.
8059 3   The macro
8060             static_assert
8061     expands to _Static_assert.
8062     7.2.1 Program diagnostics
8063     7.2.1.1 The assert macro
8064     Synopsis
8065 1           #include <assert.h>
8066             void assert(scalar expression);
8067     Description
8068 2   The assert macro puts diagnostic tests into programs; it expands to a void expression.
8069     When it is executed, if expression (which shall have a scalar type) is false (that is,
8070     compares equal to 0), the assert macro writes information about the particular call that
8071     failed (including the text of the argument, the name of the source file, the source line
8072     number, and the name of the enclosing function -- the latter are respectively the values of
8073     the preprocessing macros __FILE__ and __LINE__ and of the identifier
8074     __func__) on the standard error stream in an implementation-defined format.191) It
8075     then calls the abort function.
8076
8077
8078
8079     191) The message written might be of the form:
8080          Assertion failed: expression, function abc, file xyz, line nnn.
8081
8082
8083 [page 185]
8084
8085     Returns
8086 3   The assert macro returns no value.
8087     Forward references: the abort function (7.22.4.1).
8088
8089
8090
8091
8092 [page 186]
8093
8094     7.3 Complex arithmetic <complex.h>
8095     7.3.1 Introduction
8096 1   The header <complex.h> defines macros and declares functions that support complex
8097     arithmetic.192)
8098 2   Implementations that define the macro __STDC_NO_COMPLEX__ need not provide
8099     this header nor support any of its facilities.
8100 3   Each synopsis specifies a family of functions consisting of a principal function with one
8101     or more double complex parameters and a double complex or double return
8102     value; and other functions with the same name but with f and l suffixes which are
8103     corresponding functions with float and long double parameters and return values.
8104 4   The macro
8105              complex
8106     expands to _Complex; the macro
8107              _Complex_I
8108     expands to a constant expression of type const float _Complex, with the value of
8109     the imaginary unit.193)
8110 5   The macros
8111              imaginary
8112     and
8113              _Imaginary_I
8114     are defined if and only if the implementation supports imaginary types;194) if defined,
8115     they expand to _Imaginary and a constant expression of type const float
8116     _Imaginary with the value of the imaginary unit.
8117 6   The macro
8118              I
8119     expands to either _Imaginary_I or _Complex_I. If _Imaginary_I is not
8120     defined, I shall expand to _Complex_I.
8121 7   Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then
8122     redefine the macros complex, imaginary, and I.
8123
8124     192) See ''future library directions'' (7.30.1).
8125     193) The imaginary unit is a number i such that i 2 = -1.
8126     194) A specification for imaginary types is in informative annex G.
8127
8128 [page 187]
8129
8130     Forward references: IEC 60559-compatible complex arithmetic (annex G).
8131     7.3.2 Conventions
8132 1   Values are interpreted as radians, not degrees. An implementation may set errno but is
8133     not required to.
8134     7.3.3 Branch cuts
8135 1   Some of the functions below have branch cuts, across which the function is
8136     discontinuous. For implementations with a signed zero (including all IEC 60559
8137     implementations) that follow the specifications of annex G, the sign of zero distinguishes
8138     one side of a cut from another so the function is continuous (except for format
8139     limitations) as the cut is approached from either side. For example, for the square root
8140     function, which has a branch cut along the negative real axis, the top of the cut, with
8141     imaginary part +0, maps to the positive imaginary axis, and the bottom of the cut, with
8142     imaginary part -0, maps to the negative imaginary axis.
8143 2   Implementations that do not support a signed zero (see annex F) cannot distinguish the
8144     sides of branch cuts. These implementations shall map a cut so the function is continuous
8145     as the cut is approached coming around the finite endpoint of the cut in a counter
8146     clockwise direction. (Branch cuts for the functions specified here have just one finite
8147     endpoint.) For example, for the square root function, coming counter clockwise around
8148     the finite endpoint of the cut along the negative real axis approaches the cut from above,
8149     so the cut maps to the positive imaginary axis.
8150     7.3.4 The CX_LIMITED_RANGE pragma
8151     Synopsis
8152 1          #include <complex.h>
8153            #pragma STDC CX_LIMITED_RANGE on-off-switch
8154     Description
8155 2   The usual mathematical formulas for complex multiply, divide, and absolute value are
8156     problematic because of their treatment of infinities and because of undue overflow and
8157     underflow. The CX_LIMITED_RANGE pragma can be used to inform the
8158     implementation that (where the state is ''on'') the usual mathematical formulas are
8159     acceptable.195) The pragma can occur either outside external declarations or preceding all
8160     explicit declarations and statements inside a compound statement. When outside external
8161     declarations, the pragma takes effect from its occurrence until another
8162     CX_LIMITED_RANGE pragma is encountered, or until the end of the translation unit.
8163     When inside a compound statement, the pragma takes effect from its occurrence until
8164     another CX_LIMITED_RANGE pragma is encountered (including within a nested
8165     compound statement), or until the end of the compound statement; at the end of a
8166     compound statement the state for the pragma is restored to its condition just before the
8167
8168 [page 188]
8169
8170     compound statement. If this pragma is used in any other context, the behavior is
8171     undefined. The default state for the pragma is ''off''.
8172     7.3.5 Trigonometric functions
8173     7.3.5.1 The cacos functions
8174     Synopsis
8175 1           #include <complex.h>
8176             double complex cacos(double complex z);
8177             float complex cacosf(float complex z);
8178             long double complex cacosl(long double complex z);
8179     Description
8180 2   The cacos functions compute the complex arc cosine of z, with branch cuts outside the
8181     interval [-1, +1] along the real axis.
8182     Returns
8183 3   The cacos functions return the complex arc cosine value, in the range of a strip
8184     mathematically unbounded along the imaginary axis and in the interval [0, pi ] along the
8185     real axis.
8186     7.3.5.2 The casin functions
8187     Synopsis
8188 1           #include <complex.h>
8189             double complex casin(double complex z);
8190             float complex casinf(float complex z);
8191             long double complex casinl(long double complex z);
8192     Description
8193 2   The casin functions compute the complex arc sine of z, with branch cuts outside the
8194     interval [-1, +1] along the real axis.
8195     Returns
8196 3   The casin functions return the complex arc sine value, in the range of a strip
8197     mathematically unbounded along the imaginary axis and in the interval [-pi /2, +pi /2]
8198
8199     195) The purpose of the pragma is to allow the implementation to use the formulas:
8200             (x + iy) x (u + iv) = (xu - yv) + i(yu + xv)
8201             (x + iy) / (u + iv) = [(xu + yv) + i(yu - xv)]/(u2 + v 2 )
8202             | x + iy | = sqrt: x 2 + y 2
8203                          -----
8204          where the programmer can determine they are safe.
8205
8206 [page 189]
8207
8208     along the real axis.
8209     7.3.5.3 The catan functions
8210     Synopsis
8211 1          #include <complex.h>
8212            double complex catan(double complex z);
8213            float complex catanf(float complex z);
8214            long double complex catanl(long double complex z);
8215     Description
8216 2   The catan functions compute the complex arc tangent of z, with branch cuts outside the
8217     interval [-i, +i] along the imaginary axis.
8218     Returns
8219 3   The catan functions return the complex arc tangent value, in the range of a strip
8220     mathematically unbounded along the imaginary axis and in the interval [-pi /2, +pi /2]
8221     along the real axis.
8222     7.3.5.4 The ccos functions
8223     Synopsis
8224 1          #include <complex.h>
8225            double complex ccos(double complex z);
8226            float complex ccosf(float complex z);
8227            long double complex ccosl(long double complex z);
8228     Description
8229 2   The ccos functions compute the complex cosine of z.
8230     Returns
8231 3   The ccos functions return the complex cosine value.
8232     7.3.5.5 The csin functions
8233     Synopsis
8234 1          #include <complex.h>
8235            double complex csin(double complex z);
8236            float complex csinf(float complex z);
8237            long double complex csinl(long double complex z);
8238     Description
8239 2   The csin functions compute the complex sine of z.
8240
8241
8242
8243 [page 190]
8244
8245     Returns
8246 3   The csin functions return the complex sine value.
8247     7.3.5.6 The ctan functions
8248     Synopsis
8249 1           #include <complex.h>
8250             double complex ctan(double complex z);
8251             float complex ctanf(float complex z);
8252             long double complex ctanl(long double complex z);
8253     Description
8254 2   The ctan functions compute the complex tangent of z.
8255     Returns
8256 3   The ctan functions return the complex tangent value.
8257     7.3.6 Hyperbolic functions
8258     7.3.6.1 The cacosh functions
8259     Synopsis
8260 1           #include <complex.h>
8261             double complex cacosh(double complex z);
8262             float complex cacoshf(float complex z);
8263             long double complex cacoshl(long double complex z);
8264     Description
8265 2   The cacosh functions compute the complex arc hyperbolic cosine of z, with a branch
8266     cut at values less than 1 along the real axis.
8267     Returns
8268 3   The cacosh functions return the complex arc hyperbolic cosine value, in the range of a
8269     half-strip of nonnegative values along the real axis and in the interval [-ipi , +ipi ] along the
8270     imaginary axis.
8271     7.3.6.2 The casinh functions
8272     Synopsis
8273 1           #include <complex.h>
8274             double complex casinh(double complex z);
8275             float complex casinhf(float complex z);
8276             long double complex casinhl(long double complex z);
8277
8278
8279
8280 [page 191]
8281
8282     Description
8283 2   The casinh functions compute the complex arc hyperbolic sine of z, with branch cuts
8284     outside the interval [-i, +i] along the imaginary axis.
8285     Returns
8286 3   The casinh functions return the complex arc hyperbolic sine value, in the range of a
8287     strip mathematically unbounded along the real axis and in the interval [-ipi /2, +ipi /2]
8288     along the imaginary axis.
8289     7.3.6.3 The catanh functions
8290     Synopsis
8291 1          #include <complex.h>
8292            double complex catanh(double complex z);
8293            float complex catanhf(float complex z);
8294            long double complex catanhl(long double complex z);
8295     Description
8296 2   The catanh functions compute the complex arc hyperbolic tangent of z, with branch
8297     cuts outside the interval [-1, +1] along the real axis.
8298     Returns
8299 3   The catanh functions return the complex arc hyperbolic tangent value, in the range of a
8300     strip mathematically unbounded along the real axis and in the interval [-ipi /2, +ipi /2]
8301     along the imaginary axis.
8302     7.3.6.4 The ccosh functions
8303     Synopsis
8304 1          #include <complex.h>
8305            double complex ccosh(double complex z);
8306            float complex ccoshf(float complex z);
8307            long double complex ccoshl(long double complex z);
8308     Description
8309 2   The ccosh functions compute the complex hyperbolic cosine of z.
8310     Returns
8311 3   The ccosh functions return the complex hyperbolic cosine value.
8312
8313
8314
8315
8316 [page 192]
8317
8318     7.3.6.5 The csinh functions
8319     Synopsis
8320 1           #include <complex.h>
8321             double complex csinh(double complex z);
8322             float complex csinhf(float complex z);
8323             long double complex csinhl(long double complex z);
8324     Description
8325 2   The csinh functions compute the complex hyperbolic sine of z.
8326     Returns
8327 3   The csinh functions return the complex hyperbolic sine value.
8328     7.3.6.6 The ctanh functions
8329     Synopsis
8330 1           #include <complex.h>
8331             double complex ctanh(double complex z);
8332             float complex ctanhf(float complex z);
8333             long double complex ctanhl(long double complex z);
8334     Description
8335 2   The ctanh functions compute the complex hyperbolic tangent of z.
8336     Returns
8337 3   The ctanh functions return the complex hyperbolic tangent value.
8338     7.3.7 Exponential and logarithmic functions
8339     7.3.7.1 The cexp functions
8340     Synopsis
8341 1           #include <complex.h>
8342             double complex cexp(double complex z);
8343             float complex cexpf(float complex z);
8344             long double complex cexpl(long double complex z);
8345     Description
8346 2   The cexp functions compute the complex base-e exponential of z.
8347     Returns
8348 3   The cexp functions return the complex base-e exponential value.
8349
8350
8351
8352 [page 193]
8353
8354     7.3.7.2 The clog functions
8355     Synopsis
8356 1          #include <complex.h>
8357            double complex clog(double complex z);
8358            float complex clogf(float complex z);
8359            long double complex clogl(long double complex z);
8360     Description
8361 2   The clog functions compute the complex natural (base-e) logarithm of z, with a branch
8362     cut along the negative real axis.
8363     Returns
8364 3   The clog functions return the complex natural logarithm value, in the range of a strip
8365     mathematically unbounded along the real axis and in the interval [-ipi , +ipi ] along the
8366     imaginary axis.
8367     7.3.8 Power and absolute-value functions
8368     7.3.8.1 The cabs functions
8369     Synopsis
8370 1          #include <complex.h>
8371            double cabs(double complex z);
8372            float cabsf(float complex z);
8373            long double cabsl(long double complex z);
8374     Description
8375 2   The cabs functions compute the complex absolute value (also called norm, modulus, or
8376     magnitude) of z.
8377     Returns
8378 3   The cabs functions return the complex absolute value.
8379     7.3.8.2 The cpow functions
8380     Synopsis
8381 1          #include <complex.h>
8382            double complex cpow(double complex x, double complex y);
8383            float complex cpowf(float complex x, float complex y);
8384            long double complex cpowl(long double complex x,
8385                 long double complex y);
8386
8387
8388
8389
8390 [page 194]
8391
8392     Description
8393 2   The cpow functions compute the complex power function xy , with a branch cut for the
8394     first parameter along the negative real axis.
8395     Returns
8396 3   The cpow functions return the complex power function value.
8397     7.3.8.3 The csqrt functions
8398     Synopsis
8399 1           #include <complex.h>
8400             double complex csqrt(double complex z);
8401             float complex csqrtf(float complex z);
8402             long double complex csqrtl(long double complex z);
8403     Description
8404 2   The csqrt functions compute the complex square root of z, with a branch cut along the
8405     negative real axis.
8406     Returns
8407 3   The csqrt functions return the complex square root value, in the range of the right half-
8408     plane (including the imaginary axis).
8409     7.3.9 Manipulation functions
8410     7.3.9.1 The carg functions
8411     Synopsis
8412 1           #include <complex.h>
8413             double carg(double complex z);
8414             float cargf(float complex z);
8415             long double cargl(long double complex z);
8416     Description
8417 2   The carg functions compute the argument (also called phase angle) of z, with a branch
8418     cut along the negative real axis.
8419     Returns
8420 3   The carg functions return the value of the argument in the interval [-pi , +pi ].
8421
8422
8423
8424
8425 [page 195]
8426
8427     7.3.9.2 The cimag functions
8428     Synopsis
8429 1          #include <complex.h>
8430            double cimag(double complex z);
8431            float cimagf(float complex z);
8432            long double cimagl(long double complex z);
8433     Description
8434 2   The cimag functions compute the imaginary part of z.196)
8435     Returns
8436 3   The cimag functions return the imaginary part value (as a real).
8437     7.3.9.3 The CMPLX macros
8438     Synopsis
8439 1          #include <complex.h>
8440            double complex CMPLX(double x, double y);
8441            float complex CMPLXF(float x, float y);
8442            long double complex CMPLXL(long double x, long double y);
8443     Description
8444 2   The CMPLX macros expand to an expression of the specified complex type, with the real
8445     part having the (converted) value of x and the imaginary part having the (converted)
8446     value of y.
8447     Recommended practice
8448 3   The resulting expression should be suitable for use as an initializer for an object with
8449     static or thread storage duration, provided both arguments are likewise suitable.
8450     Returns
8451 4   The CMPLX macros return the complex value x + i y.
8452 5   NOTE    These macros act as if the implementation supported imaginary types and the definitions were:
8453           #define CMPLX(x, y)  ((double complex)((double)(x) + \
8454                                         _Imaginary_I * (double)(y)))
8455           #define CMPLXF(x, y) ((float complex)((float)(x) + \
8456                                         _Imaginary_I * (float)(y)))
8457           #define CMPLXL(x, y) ((long double complex)((long double)(x) + \
8458                                         _Imaginary_I * (long double)(y)))
8459
8460
8461
8462
8463     196) For a variable z of complex type, z == creal(z) + cimag(z)*I.
8464
8465 [page 196]
8466
8467     7.3.9.4 The conj functions
8468     Synopsis
8469 1           #include <complex.h>
8470             double complex conj(double complex z);
8471             float complex conjf(float complex z);
8472             long double complex conjl(long double complex z);
8473     Description
8474 2   The conj functions compute the complex conjugate of z, by reversing the sign of its
8475     imaginary part.
8476     Returns
8477 3   The conj functions return the complex conjugate value.
8478     7.3.9.5 The cproj functions
8479     Synopsis
8480 1           #include <complex.h>
8481             double complex cproj(double complex z);
8482             float complex cprojf(float complex z);
8483             long double complex cprojl(long double complex z);
8484     Description
8485 2   The cproj functions compute a projection of z onto the Riemann sphere: z projects to
8486     z except that all complex infinities (even those with one infinite part and one NaN part)
8487     project to positive infinity on the real axis. If z has an infinite part, then cproj(z) is
8488     equivalent to
8489             INFINITY + I * copysign(0.0, cimag(z))
8490     Returns
8491 3   The cproj functions return the value of the projection onto the Riemann sphere.
8492     7.3.9.6 The creal functions
8493     Synopsis
8494 1           #include <complex.h>
8495             double creal(double complex z);
8496             float crealf(float complex z);
8497             long double creall(long double complex z);
8498     Description
8499 2   The creal functions compute the real part of z.197)
8500
8501
8502 [page 197]
8503
8504     Returns
8505 3   The creal functions return the real part value.
8506
8507
8508
8509
8510     197) For a variable z of complex type, z == creal(z) + cimag(z)*I.
8511
8512 [page 198]
8513
8514     7.4 Character handling <ctype.h>
8515 1   The header <ctype.h> declares several functions useful for classifying and mapping
8516     characters.198) In all cases the argument is an int, the value of which shall be
8517     representable as an unsigned char or shall equal the value of the macro EOF. If the
8518     argument has any other value, the behavior is undefined.
8519 2   The behavior of these functions is affected by the current locale. Those functions that
8520     have locale-specific aspects only when not in the "C" locale are noted below.
8521 3   The term printing character refers to a member of a locale-specific set of characters, each
8522     of which occupies one printing position on a display device; the term control character
8523     refers to a member of a locale-specific set of characters that are not printing
8524     characters.199) All letters and digits are printing characters.
8525     Forward references: EOF (7.21.1), localization (7.11).
8526     7.4.1 Character classification functions
8527 1   The functions in this subclause return nonzero (true) if and only if the value of the
8528     argument c conforms to that in the description of the function.
8529     7.4.1.1 The isalnum function
8530     Synopsis
8531 1            #include <ctype.h>
8532              int isalnum(int c);
8533     Description
8534 2   The isalnum function tests for any character for which isalpha or isdigit is true.
8535     7.4.1.2 The isalpha function
8536     Synopsis
8537 1            #include <ctype.h>
8538              int isalpha(int c);
8539     Description
8540 2   The isalpha function tests for any character for which isupper or islower is true,
8541     or any character that is one of a locale-specific set of alphabetic characters for which
8542
8543
8544
8545     198) See ''future library directions'' (7.30.2).
8546     199) In an implementation that uses the seven-bit US ASCII character set, the printing characters are those
8547          whose values lie from 0x20 (space) through 0x7E (tilde); the control characters are those whose
8548          values lie from 0 (NUL) through 0x1F (US), and the character 0x7F (DEL).
8549
8550 [page 199]
8551
8552     none of iscntrl, isdigit, ispunct, or isspace is true.200) In the "C" locale,
8553     isalpha returns true only for the characters for which isupper or islower is true.
8554     7.4.1.3 The isblank function
8555     Synopsis
8556 1           #include <ctype.h>
8557             int isblank(int c);
8558     Description
8559 2   The isblank function tests for any character that is a standard blank character or is one
8560     of a locale-specific set of characters for which isspace is true and that is used to
8561     separate words within a line of text. The standard blank characters are the following:
8562     space (' '), and horizontal tab ('\t'). In the "C" locale, isblank returns true only
8563     for the standard blank characters.
8564     7.4.1.4 The iscntrl function
8565     Synopsis
8566 1           #include <ctype.h>
8567             int iscntrl(int c);
8568     Description
8569 2   The iscntrl function tests for any control character.
8570     7.4.1.5 The isdigit function
8571     Synopsis
8572 1           #include <ctype.h>
8573             int isdigit(int c);
8574     Description
8575 2   The isdigit function tests for any decimal-digit character (as defined in 5.2.1).
8576     7.4.1.6 The isgraph function
8577     Synopsis
8578 1           #include <ctype.h>
8579             int isgraph(int c);
8580
8581
8582
8583
8584     200) The functions islower and isupper test true or false separately for each of these additional
8585          characters; all four combinations are possible.
8586
8587 [page 200]
8588
8589     Description
8590 2   The isgraph function tests for any printing character except space (' ').
8591     7.4.1.7 The islower function
8592     Synopsis
8593 1           #include <ctype.h>
8594             int islower(int c);
8595     Description
8596 2   The islower function tests for any character that is a lowercase letter or is one of a
8597     locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or
8598     isspace is true. In the "C" locale, islower returns true only for the lowercase
8599     letters (as defined in 5.2.1).
8600     7.4.1.8 The isprint function
8601     Synopsis
8602 1           #include <ctype.h>
8603             int isprint(int c);
8604     Description
8605 2   The isprint function tests for any printing character including space (' ').
8606     7.4.1.9 The ispunct function
8607     Synopsis
8608 1           #include <ctype.h>
8609             int ispunct(int c);
8610     Description
8611 2   The ispunct function tests for any printing character that is one of a locale-specific set
8612     of punctuation characters for which neither isspace nor isalnum is true. In the "C"
8613     locale, ispunct returns true for every printing character for which neither isspace
8614     nor isalnum is true.
8615     7.4.1.10 The isspace function
8616     Synopsis
8617 1           #include <ctype.h>
8618             int isspace(int c);
8619     Description
8620 2   The isspace function tests for any character that is a standard white-space character or
8621     is one of a locale-specific set of characters for which isalnum is false. The standard
8622
8623 [page 201]
8624
8625     white-space characters are the following: space (' '), form feed ('\f'), new-line
8626     ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). In the
8627     "C" locale, isspace returns true only for the standard white-space characters.
8628     7.4.1.11 The isupper function
8629     Synopsis
8630 1          #include <ctype.h>
8631            int isupper(int c);
8632     Description
8633 2   The isupper function tests for any character that is an uppercase letter or is one of a
8634     locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or
8635     isspace is true. In the "C" locale, isupper returns true only for the uppercase
8636     letters (as defined in 5.2.1).
8637     7.4.1.12 The isxdigit function
8638     Synopsis
8639 1          #include <ctype.h>
8640            int isxdigit(int c);
8641     Description
8642 2   The isxdigit function tests for any hexadecimal-digit character (as defined in 6.4.4.1).
8643     7.4.2 Character case mapping functions
8644     7.4.2.1 The tolower function
8645     Synopsis
8646 1          #include <ctype.h>
8647            int tolower(int c);
8648     Description
8649 2   The tolower function converts an uppercase letter to a corresponding lowercase letter.
8650     Returns
8651 3   If the argument is a character for which isupper is true and there are one or more
8652     corresponding characters, as specified by the current locale, for which islower is true,
8653     the tolower function returns one of the corresponding characters (always the same one
8654     for any given locale); otherwise, the argument is returned unchanged.
8655
8656
8657
8658
8659 [page 202]
8660
8661     7.4.2.2 The toupper function
8662     Synopsis
8663 1           #include <ctype.h>
8664             int toupper(int c);
8665     Description
8666 2   The toupper function converts a lowercase letter to a corresponding uppercase letter.
8667     Returns
8668 3   If the argument is a character for which islower is true and there are one or more
8669     corresponding characters, as specified by the current locale, for which isupper is true,
8670     the toupper function returns one of the corresponding characters (always the same one
8671     for any given locale); otherwise, the argument is returned unchanged.
8672
8673
8674
8675
8676 [page 203]
8677
8678     7.5 Errors <errno.h>
8679 1   The header <errno.h> defines several macros, all relating to the reporting of error
8680     conditions.
8681 2   The macros are
8682              EDOM
8683              EILSEQ
8684              ERANGE
8685     which expand to integer constant expressions with type int, distinct positive values, and
8686     which are suitable for use in #if preprocessing directives; and
8687              errno
8688     which expands to a modifiable lvalue201) that has type int and thread local storage
8689     duration, the value of which is set to a positive error number by several library functions.
8690     If a macro definition is suppressed in order to access an actual object, or a program
8691     defines an identifier with the name errno, the behavior is undefined.
8692 3   The value of errno in the initial thread is zero at program startup (the initial value of
8693     errno in other threads is an indeterminate value), but is never set to zero by any library
8694     function.202) The value of errno may be set to nonzero by a library function call
8695     whether or not there is an error, provided the use of errno is not documented in the
8696     description of the function in this International Standard.
8697 4   Additional macro definitions, beginning with E and a digit or E and an uppercase
8698     letter,203) may also be specified by the implementation.
8699
8700
8701
8702
8703     201) The macro errno need not be the identifier of an object. It might expand to a modifiable lvalue
8704          resulting from a function call (for example, *errno()).
8705     202) Thus, a program that uses errno for error checking should set it to zero before a library function call,
8706          then inspect it before a subsequent library function call. Of course, a library function can save the
8707          value of errno on entry and then set it to zero, as long as the original value is restored if errno's
8708          value is still zero just before the return.
8709     203) See ''future library directions'' (7.30.3).
8710
8711 [page 204]
8712
8713     7.6 Floating-point environment <fenv.h>
8714 1   The header <fenv.h> defines several macros, and declares types and functions that
8715     provide access to the floating-point environment. The floating-point environment refers
8716     collectively to any floating-point status flags and control modes supported by the
8717     implementation.204) A floating-point status flag is a system variable whose value is set
8718     (but never cleared) when a floating-point exception is raised, which occurs as a side effect
8719     of exceptional floating-point arithmetic to provide auxiliary information.205) A floating-
8720     point control mode is a system variable whose value may be set by the user to affect the
8721     subsequent behavior of floating-point arithmetic.
8722 2   The floating-point environment has thread storage duration. The initial state for a
8723     thread's floating-point environment is the current state of the floating-point environment
8724     of the thread that creates it at the time of creation.
8725 3   Certain programming conventions support the intended model of use for the floating-
8726     point environment:206)
8727     -- a function call does not alter its caller's floating-point control modes, clear its caller's
8728       floating-point status flags, nor depend on the state of its caller's floating-point status
8729       flags unless the function is so documented;
8730     -- a function call is assumed to require default floating-point control modes, unless its
8731       documentation promises otherwise;
8732     -- a function call is assumed to have the potential for raising floating-point exceptions,
8733       unless its documentation promises otherwise.
8734 4   The type
8735             fenv_t
8736     represents the entire floating-point environment.
8737 5   The type
8738             fexcept_t
8739     represents the floating-point status flags collectively, including any status the
8740     implementation associates with the flags.
8741
8742
8743     204) This header is designed to support the floating-point exception status flags and directed-rounding
8744          control modes required by IEC 60559, and other similar floating-point state information. It is also
8745          designed to facilitate code portability among all systems.
8746     205) A floating-point status flag is not an object and can be set more than once within an expression.
8747     206) With these conventions, a programmer can safely assume default floating-point control modes (or be
8748          unaware of them). The responsibilities associated with accessing the floating-point environment fall
8749          on the programmer or program that does so explicitly.
8750
8751 [page 205]
8752
8753 6   Each of the macros
8754              FE_DIVBYZERO
8755              FE_INEXACT
8756              FE_INVALID
8757              FE_OVERFLOW
8758              FE_UNDERFLOW
8759     is defined if and only if the implementation supports the floating-point exception by
8760     means of the functions in 7.6.2.207) Additional implementation-defined floating-point
8761     exceptions, with macro definitions beginning with FE_ and an uppercase letter, may also
8762     be specified by the implementation. The defined macros expand to integer constant
8763     expressions with values such that bitwise ORs of all combinations of the macros result in
8764     distinct values, and furthermore, bitwise ANDs of all combinations of the macros result in
8765     zero.208)
8766 7   The macro
8767              FE_ALL_EXCEPT
8768     is simply the bitwise OR of all floating-point exception macros defined by the
8769     implementation. If no such macros are defined, FE_ALL_EXCEPT shall be defined as 0.
8770 8   Each of the macros
8771              FE_DOWNWARD
8772              FE_TONEAREST
8773              FE_TOWARDZERO
8774              FE_UPWARD
8775     is defined if and only if the implementation supports getting and setting the represented
8776     rounding direction by means of the fegetround and fesetround functions.
8777     Additional implementation-defined rounding directions, with macro definitions beginning
8778     with FE_ and an uppercase letter, may also be specified by the implementation. The
8779     defined macros expand to integer constant expressions whose values are distinct
8780     nonnegative values.209)
8781 9   The macro
8782
8783
8784
8785     207) The implementation supports a floating-point exception if there are circumstances where a call to at
8786          least one of the functions in 7.6.2, using the macro as the appropriate argument, will succeed. It is not
8787          necessary for all the functions to succeed all the time.
8788     208) The macros should be distinct powers of two.
8789     209) Even though the rounding direction macros may expand to constants corresponding to the values of
8790          FLT_ROUNDS, they are not required to do so.
8791
8792 [page 206]
8793
8794               FE_DFL_ENV
8795      represents the default floating-point environment -- the one installed at program startup
8796      -- and has type ''pointer to const-qualified fenv_t''. It can be used as an argument to
8797      <fenv.h> functions that manage the floating-point environment.
8798 10   Additional implementation-defined environments, with macro definitions beginning with
8799      FE_ and an uppercase letter, and having type ''pointer to const-qualified fenv_t'', may
8800      also be specified by the implementation.
8801      7.6.1 The FENV_ACCESS pragma
8802      Synopsis
8803 1             #include <fenv.h>
8804               #pragma STDC FENV_ACCESS on-off-switch
8805      Description
8806 2    The FENV_ACCESS pragma provides a means to inform the implementation when a
8807      program might access the floating-point environment to test floating-point status flags or
8808      run under non-default floating-point control modes.210) The pragma shall occur either
8809      outside external declarations or preceding all explicit declarations and statements inside a
8810      compound statement. When outside external declarations, the pragma takes effect from
8811      its occurrence until another FENV_ACCESS pragma is encountered, or until the end of
8812      the translation unit. When inside a compound statement, the pragma takes effect from its
8813      occurrence until another FENV_ACCESS pragma is encountered (including within a
8814      nested compound statement), or until the end of the compound statement; at the end of a
8815      compound statement the state for the pragma is restored to its condition just before the
8816      compound statement. If this pragma is used in any other context, the behavior is
8817      undefined. If part of a program tests floating-point status flags, sets floating-point control
8818      modes, or runs under non-default mode settings, but was translated with the state for the
8819      FENV_ACCESS pragma ''off'', the behavior is undefined. The default state (''on'' or
8820      ''off'') for the pragma is implementation-defined. (When execution passes from a part of
8821      the program translated with FENV_ACCESS ''off'' to a part translated with
8822      FENV_ACCESS ''on'', the state of the floating-point status flags is unspecified and the
8823      floating-point control modes have their default settings.)
8824
8825
8826
8827
8828      210) The purpose of the FENV_ACCESS pragma is to allow certain optimizations that could subvert flag
8829           tests and mode changes (e.g., global common subexpression elimination, code motion, and constant
8830           folding). In general, if the state of FENV_ACCESS is ''off'', the translator can assume that default
8831           modes are in effect and the flags are not tested.
8832
8833 [page 207]
8834
8835 3   EXAMPLE
8836             #include <fenv.h>
8837             void f(double x)
8838             {
8839                   #pragma STDC FENV_ACCESS ON
8840                   void g(double);
8841                   void h(double);
8842                   /* ... */
8843                   g(x + 1);
8844                   h(x + 1);
8845                   /* ... */
8846             }
8847 4   If the function g might depend on status flags set as a side effect of the first x + 1, or if the second
8848     x + 1 might depend on control modes set as a side effect of the call to function g, then the program shall
8849     contain an appropriately placed invocation of #pragma STDC FENV_ACCESS ON.211)
8850
8851     7.6.2 Floating-point exceptions
8852 1   The following functions provide access to the floating-point status flags.212) The int
8853     input argument for the functions represents a subset of floating-point exceptions, and can
8854     be zero or the bitwise OR of one or more floating-point exception macros, for example
8855     FE_OVERFLOW | FE_INEXACT. For other argument values the behavior of these
8856     functions is undefined.
8857     7.6.2.1 The feclearexcept function
8858     Synopsis
8859 1           #include <fenv.h>
8860             int feclearexcept(int excepts);
8861     Description
8862 2   The feclearexcept function attempts to clear the supported floating-point exceptions
8863     represented by its argument.
8864     Returns
8865 3   The feclearexcept function returns zero if the excepts argument is zero or if all
8866     the specified exceptions were successfully cleared. Otherwise, it returns a nonzero value.
8867
8868
8869     211) The side effects impose a temporal ordering that requires two evaluations of x + 1. On the other
8870          hand, without the #pragma STDC FENV_ACCESS ON pragma, and assuming the default state is
8871          ''off'', just one evaluation of x + 1 would suffice.
8872     212) The functions fetestexcept, feraiseexcept, and feclearexcept support the basic
8873          abstraction of flags that are either set or clear. An implementation may endow floating-point status
8874          flags with more information -- for example, the address of the code which first raised the floating-
8875          point exception; the functions fegetexceptflag and fesetexceptflag deal with the full
8876          content of flags.
8877
8878 [page 208]
8879
8880     7.6.2.2 The fegetexceptflag function
8881     Synopsis
8882 1            #include <fenv.h>
8883              int fegetexceptflag(fexcept_t *flagp,
8884                   int excepts);
8885     Description
8886 2   The fegetexceptflag function attempts to store an implementation-defined
8887     representation of the states of the floating-point status flags indicated by the argument
8888     excepts in the object pointed to by the argument flagp.
8889     Returns
8890 3   The fegetexceptflag function returns zero if the representation was successfully
8891     stored. Otherwise, it returns a nonzero value.
8892     7.6.2.3 The feraiseexcept function
8893     Synopsis
8894 1            #include <fenv.h>
8895              int feraiseexcept(int excepts);
8896     Description
8897 2   The feraiseexcept function attempts to raise the supported floating-point exceptions
8898     represented by its argument.213) The order in which these floating-point exceptions are
8899     raised is unspecified, except as stated in F.8.6. Whether the feraiseexcept function
8900     additionally raises the ''inexact'' floating-point exception whenever it raises the
8901     ''overflow'' or ''underflow'' floating-point exception is implementation-defined.
8902     Returns
8903 3   The feraiseexcept function returns zero if the excepts argument is zero or if all
8904     the specified exceptions were successfully raised. Otherwise, it returns a nonzero value.
8905
8906
8907
8908
8909     213) The effect is intended to be similar to that of floating-point exceptions raised by arithmetic operations.
8910          Hence, enabled traps for floating-point exceptions raised by this function are taken. The specification
8911          in F.8.6 is in the same spirit.
8912
8913 [page 209]
8914
8915     7.6.2.4 The fesetexceptflag function
8916     Synopsis
8917 1           #include <fenv.h>
8918             int fesetexceptflag(const fexcept_t *flagp,
8919                  int excepts);
8920     Description
8921 2   The fesetexceptflag function attempts to set the floating-point status flags
8922     indicated by the argument excepts to the states stored in the object pointed to by
8923     flagp. The value of *flagp shall have been set by a previous call to
8924     fegetexceptflag whose second argument represented at least those floating-point
8925     exceptions represented by the argument excepts. This function does not raise floating-
8926     point exceptions, but only sets the state of the flags.
8927     Returns
8928 3   The fesetexceptflag function returns zero if the excepts argument is zero or if
8929     all the specified flags were successfully set to the appropriate state. Otherwise, it returns
8930     a nonzero value.
8931     7.6.2.5 The fetestexcept function
8932     Synopsis
8933 1           #include <fenv.h>
8934             int fetestexcept(int excepts);
8935     Description
8936 2   The fetestexcept function determines which of a specified subset of the floating-
8937     point exception flags are currently set. The excepts argument specifies the floating-
8938     point status flags to be queried.214)
8939     Returns
8940 3   The fetestexcept function returns the value of the bitwise OR of the floating-point
8941     exception macros corresponding to the currently set floating-point exceptions included in
8942     excepts.
8943 4   EXAMPLE       Call f if ''invalid'' is set, then g if ''overflow'' is set:
8944
8945
8946
8947
8948     214) This mechanism allows testing several floating-point exceptions with just one function call.
8949
8950 [page 210]
8951
8952             #include <fenv.h>
8953             /* ... */
8954             {
8955                     #pragma STDC FENV_ACCESS ON
8956                     int set_excepts;
8957                     feclearexcept(FE_INVALID | FE_OVERFLOW);
8958                     // maybe raise exceptions
8959                     set_excepts = fetestexcept(FE_INVALID | FE_OVERFLOW);
8960                     if (set_excepts & FE_INVALID) f();
8961                     if (set_excepts & FE_OVERFLOW) g();
8962                     /* ... */
8963             }
8964
8965     7.6.3 Rounding
8966 1   The fegetround and fesetround functions provide control of rounding direction
8967     modes.
8968     7.6.3.1 The fegetround function
8969     Synopsis
8970 1           #include <fenv.h>
8971             int fegetround(void);
8972     Description
8973 2   The fegetround function gets the current rounding direction.
8974     Returns
8975 3   The fegetround function returns the value of the rounding direction macro
8976     representing the current rounding direction or a negative value if there is no such
8977     rounding direction macro or the current rounding direction is not determinable.
8978     7.6.3.2 The fesetround function
8979     Synopsis
8980 1           #include <fenv.h>
8981             int fesetround(int round);
8982     Description
8983 2   The fesetround function establishes the rounding direction represented by its
8984     argument round. If the argument is not equal to the value of a rounding direction macro,
8985     the rounding direction is not changed.
8986     Returns
8987 3   The fesetround function returns zero if and only if the requested rounding direction
8988     was established.
8989
8990
8991 [page 211]
8992
8993 4   EXAMPLE Save, set, and restore the rounding direction. Report an error and abort if setting the
8994     rounding direction fails.
8995            #include <fenv.h>
8996            #include <assert.h>
8997            void f(int round_dir)
8998            {
8999                  #pragma STDC FENV_ACCESS ON
9000                  int save_round;
9001                  int setround_ok;
9002                  save_round = fegetround();
9003                  setround_ok = fesetround(round_dir);
9004                  assert(setround_ok == 0);
9005                  /* ... */
9006                  fesetround(save_round);
9007                  /* ... */
9008            }
9009
9010     7.6.4 Environment
9011 1   The functions in this section manage the floating-point environment -- status flags and
9012     control modes -- as one entity.
9013     7.6.4.1 The fegetenv function
9014     Synopsis
9015 1          #include <fenv.h>
9016            int fegetenv(fenv_t *envp);
9017     Description
9018 2   The fegetenv function attempts to store the current floating-point environment in the
9019     object pointed to by envp.
9020     Returns
9021 3   The fegetenv function returns zero if the environment was successfully stored.
9022     Otherwise, it returns a nonzero value.
9023     7.6.4.2 The feholdexcept function
9024     Synopsis
9025 1          #include <fenv.h>
9026            int feholdexcept(fenv_t *envp);
9027     Description
9028 2   The feholdexcept function saves the current floating-point environment in the object
9029     pointed to by envp, clears the floating-point status flags, and then installs a non-stop
9030     (continue on floating-point exceptions) mode, if available, for all floating-point
9031     exceptions.215)
9032
9033 [page 212]
9034
9035     Returns
9036 3   The feholdexcept function returns zero if and only if non-stop floating-point
9037     exception handling was successfully installed.
9038     7.6.4.3 The fesetenv function
9039     Synopsis
9040 1           #include <fenv.h>
9041             int fesetenv(const fenv_t *envp);
9042     Description
9043 2   The fesetenv function attempts to establish the floating-point environment represented
9044     by the object pointed to by envp. The argument envp shall point to an object set by a
9045     call to fegetenv or feholdexcept, or equal a floating-point environment macro.
9046     Note that fesetenv merely installs the state of the floating-point status flags
9047     represented through its argument, and does not raise these floating-point exceptions.
9048     Returns
9049 3   The fesetenv function returns zero if the environment was successfully established.
9050     Otherwise, it returns a nonzero value.
9051     7.6.4.4 The feupdateenv function
9052     Synopsis
9053 1           #include <fenv.h>
9054             int feupdateenv(const fenv_t *envp);
9055     Description
9056 2   The feupdateenv function attempts to save the currently raised floating-point
9057     exceptions in its automatic storage, install the floating-point environment represented by
9058     the object pointed to by envp, and then raise the saved floating-point exceptions. The
9059     argument envp shall point to an object set by a call to feholdexcept or fegetenv,
9060     or equal a floating-point environment macro.
9061     Returns
9062 3   The feupdateenv function returns zero if all the actions were successfully carried out.
9063     Otherwise, it returns a nonzero value.
9064
9065
9066
9067
9068     215) IEC 60559 systems have a default non-stop mode, and typically at least one other mode for trap
9069          handling or aborting; if the system provides only the non-stop mode then installing it is trivial. For
9070          such systems, the feholdexcept function can be used in conjunction with the feupdateenv
9071          function to write routines that hide spurious floating-point exceptions from their callers.
9072
9073 [page 213]
9074
9075 4   EXAMPLE   Hide spurious underflow floating-point exceptions:
9076           #include <fenv.h>
9077           double f(double x)
9078           {
9079                 #pragma STDC FENV_ACCESS ON
9080                 double result;
9081                 fenv_t save_env;
9082                 if (feholdexcept(&save_env))
9083                       return /* indication of an environmental problem */;
9084                 // compute result
9085                 if (/* test spurious underflow */)
9086                       if (feclearexcept(FE_UNDERFLOW))
9087                                return /* indication of an environmental problem */;
9088                 if (feupdateenv(&save_env))
9089                       return /* indication of an environmental problem */;
9090                 return result;
9091           }
9092
9093
9094
9095
9096 [page 214]
9097
9098     7.7 Characteristics of floating types <float.h>
9099 1   The header <float.h> defines several macros that expand to various limits and
9100     parameters of the standard floating-point types.
9101 2   The macros, their meanings, and the constraints (or restrictions) on their values are listed
9102     in 5.2.4.2.2.
9103
9104
9105
9106
9107 [page 215]
9108
9109     7.8 Format conversion of integer types <inttypes.h>
9110 1   The header <inttypes.h> includes the header <stdint.h> and extends it with
9111     additional facilities provided by hosted implementations.
9112 2   It declares functions for manipulating greatest-width integers and converting numeric
9113     character strings to greatest-width integers, and it declares the type
9114              imaxdiv_t
9115     which is a structure type that is the type of the value returned by the imaxdiv function.
9116     For each type declared in <stdint.h>, it defines corresponding macros for conversion
9117     specifiers for use with the formatted input/output functions.216)
9118     Forward references: integer types <stdint.h> (7.20), formatted input/output
9119     functions (7.21.6), formatted wide character input/output functions (7.28.2).
9120     7.8.1 Macros for format specifiers
9121 1   Each of the following object-like macros expands to a character string literal containing a *
9122     conversion specifier, possibly modified by a length modifier, suitable for use within the
9123     format argument of a formatted input/output function when converting the corresponding
9124     integer type. These macro names have the general form of PRI (character string literals
9125     for the fprintf and fwprintf family) or SCN (character string literals for the
9126     fscanf and fwscanf family),217) followed by the conversion specifier, followed by a
9127     name corresponding to a similar type name in 7.20.1. In these names, N represents the
9128     width of the type as described in 7.20.1. For example, PRIdFAST32 can be used in a
9129     format string to print the value of an integer of type int_fast32_t.
9130 2   The fprintf macros for signed integers are:
9131            PRIdN             PRIdLEASTN                PRIdFASTN          PRIdMAX             PRIdPTR
9132            PRIiN             PRIiLEASTN                PRIiFASTN          PRIiMAX             PRIiPTR
9133 3   The fprintf macros for unsigned integers are:
9134            PRIoN             PRIoLEASTN                PRIoFASTN          PRIoMAX             PRIoPTR
9135            PRIuN             PRIuLEASTN                PRIuFASTN          PRIuMAX             PRIuPTR
9136            PRIxN             PRIxLEASTN                PRIxFASTN          PRIxMAX             PRIxPTR
9137            PRIXN             PRIXLEASTN                PRIXFASTN          PRIXMAX             PRIXPTR
9138 4   The fscanf macros for signed integers are:
9139
9140
9141
9142     216) See ''future library directions'' (7.30.4).
9143     217) Separate macros are given for use with fprintf and fscanf functions because, in the general case,
9144          different format specifiers may be required for fprintf and fscanf, even when the type is the
9145          same.
9146
9147 [page 216]
9148
9149            SCNdN           SCNdLEASTN               SCNdFASTN              SCNdMAX             SCNdPTR
9150            SCNiN           SCNiLEASTN               SCNiFASTN              SCNiMAX             SCNiPTR
9151 5   The fscanf macros for unsigned integers are:
9152            SCNoN           SCNoLEASTN               SCNoFASTN              SCNoMAX             SCNoPTR
9153            SCNuN           SCNuLEASTN               SCNuFASTN              SCNuMAX             SCNuPTR
9154            SCNxN           SCNxLEASTN               SCNxFASTN              SCNxMAX             SCNxPTR
9155 6   For each type that the implementation provides in <stdint.h>, the corresponding
9156     fprintf macros shall be defined and the corresponding fscanf macros shall be
9157     defined unless the implementation does not have a suitable fscanf length modifier for
9158     the type.
9159 7   EXAMPLE
9160             #include <inttypes.h>
9161             #include <wchar.h>
9162             int main(void)
9163             {
9164                   uintmax_t i = UINTMAX_MAX;    // this type always exists
9165                   wprintf(L"The largest integer value is %020"
9166                         PRIxMAX "\n", i);
9167                   return 0;
9168             }
9169
9170     7.8.2 Functions for greatest-width integer types
9171     7.8.2.1 The imaxabs function
9172     Synopsis
9173 1           #include <inttypes.h>
9174             intmax_t imaxabs(intmax_t j);
9175     Description
9176 2   The imaxabs function computes the absolute value of an integer j. If the result cannot
9177     be represented, the behavior is undefined.218)
9178     Returns
9179 3   The imaxabs function returns the absolute value.
9180
9181
9182
9183
9184     218) The absolute value of the most negative number cannot be represented in two's complement.
9185
9186 [page 217]
9187
9188     7.8.2.2 The imaxdiv function
9189     Synopsis
9190 1          #include <inttypes.h>
9191            imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
9192     Description
9193 2   The imaxdiv function computes numer / denom and numer % denom in a single
9194     operation.
9195     Returns
9196 3   The imaxdiv function returns a structure of type imaxdiv_t comprising both the
9197     quotient and the remainder. The structure shall contain (in either order) the members
9198     quot (the quotient) and rem (the remainder), each of which has type intmax_t. If
9199     either part of the result cannot be represented, the behavior is undefined.
9200     7.8.2.3 The strtoimax and strtoumax functions
9201     Synopsis
9202 1          #include <inttypes.h>
9203            intmax_t strtoimax(const char * restrict nptr,
9204                 char ** restrict endptr, int base);
9205            uintmax_t strtoumax(const char * restrict nptr,
9206                 char ** restrict endptr, int base);
9207     Description
9208 2   The strtoimax and strtoumax functions are equivalent to the strtol, strtoll,
9209     strtoul, and strtoull functions, except that the initial portion of the string is
9210     converted to intmax_t and uintmax_t representation, respectively.
9211     Returns
9212 3   The strtoimax and strtoumax functions return the converted value, if any. If no
9213     conversion could be performed, zero is returned. If the correct value is outside the range
9214     of representable values, INTMAX_MAX, INTMAX_MIN, or UINTMAX_MAX is returned
9215     (according to the return type and sign of the value, if any), and the value of the macro
9216     ERANGE is stored in errno.
9217     Forward references: the strtol, strtoll, strtoul, and strtoull functions
9218     (7.22.1.4).
9219
9220
9221
9222
9223 [page 218]
9224
9225     7.8.2.4 The wcstoimax and wcstoumax functions
9226     Synopsis
9227 1           #include <stddef.h>           // for wchar_t
9228             #include <inttypes.h>
9229             intmax_t wcstoimax(const wchar_t * restrict nptr,
9230                  wchar_t ** restrict endptr, int base);
9231             uintmax_t wcstoumax(const wchar_t * restrict nptr,
9232                  wchar_t ** restrict endptr, int base);
9233     Description
9234 2   The wcstoimax and wcstoumax functions are equivalent to the wcstol, wcstoll,
9235     wcstoul, and wcstoull functions except that the initial portion of the wide string is
9236     converted to intmax_t and uintmax_t representation, respectively.
9237     Returns
9238 3   The wcstoimax function returns the converted value, if any. If no conversion could be
9239     performed, zero is returned. If the correct value is outside the range of representable
9240     values, INTMAX_MAX, INTMAX_MIN, or UINTMAX_MAX is returned (according to the
9241     return type and sign of the value, if any), and the value of the macro ERANGE is stored in
9242     errno.
9243     Forward references: the wcstol, wcstoll, wcstoul, and wcstoull functions
9244     (7.28.4.1.2).
9245
9246
9247
9248
9249 [page 219]
9250
9251     7.9 Alternative spellings <iso646.h>
9252 1   The header <iso646.h> defines the following eleven macros (on the left) that expand
9253     to the corresponding tokens (on the right):
9254           and           &&
9255           and_eq        &=
9256           bitand        &
9257           bitor         |
9258           compl         ~
9259           not           !
9260           not_eq        !=
9261           or            ||
9262           or_eq         |=
9263           xor           ^
9264           xor_eq        ^=
9265
9266
9267
9268
9269 [page 220]
9270
9271     7.10 Sizes of integer types <limits.h>
9272 1   The header <limits.h> defines several macros that expand to various limits and
9273     parameters of the standard integer types.
9274 2   The macros, their meanings, and the constraints (or restrictions) on their values are listed
9275     in 5.2.4.2.1.
9276
9277
9278
9279
9280 [page 221]
9281
9282     7.11 Localization <locale.h>
9283 1   The header <locale.h> declares two functions, one type, and defines several macros.
9284 2   The type is
9285            struct lconv
9286     which contains members related to the formatting of numeric values. The structure shall
9287     contain at least the following members, in any order. The semantics of the members and
9288     their normal ranges are explained in 7.11.2.1. In the "C" locale, the members shall have
9289     the values specified in the comments.
9290            char   *decimal_point;                 //   "."
9291            char   *thousands_sep;                 //   ""
9292            char   *grouping;                      //   ""
9293            char   *mon_decimal_point;             //   ""
9294            char   *mon_thousands_sep;             //   ""
9295            char   *mon_grouping;                  //   ""
9296            char   *positive_sign;                 //   ""
9297            char   *negative_sign;                 //   ""
9298            char   *currency_symbol;               //   ""
9299            char   frac_digits;                    //   CHAR_MAX
9300            char   p_cs_precedes;                  //   CHAR_MAX
9301            char   n_cs_precedes;                  //   CHAR_MAX
9302            char   p_sep_by_space;                 //   CHAR_MAX
9303            char   n_sep_by_space;                 //   CHAR_MAX
9304            char   p_sign_posn;                    //   CHAR_MAX
9305            char   n_sign_posn;                    //   CHAR_MAX
9306            char   *int_curr_symbol;               //   ""
9307            char   int_frac_digits;                //   CHAR_MAX
9308            char   int_p_cs_precedes;              //   CHAR_MAX
9309            char   int_n_cs_precedes;              //   CHAR_MAX
9310            char   int_p_sep_by_space;             //   CHAR_MAX
9311            char   int_n_sep_by_space;             //   CHAR_MAX
9312            char   int_p_sign_posn;                //   CHAR_MAX
9313            char   int_n_sign_posn;                //   CHAR_MAX
9314
9315
9316
9317
9318 [page 222]
9319
9320 3   The macros defined are NULL (described in 7.19); and
9321              LC_ALL
9322              LC_COLLATE
9323              LC_CTYPE
9324              LC_MONETARY
9325              LC_NUMERIC
9326              LC_TIME
9327     which expand to integer constant expressions with distinct values, suitable for use as the
9328     first argument to the setlocale function.219) Additional macro definitions, beginning
9329     with the characters LC_ and an uppercase letter,220) may also be specified by the
9330     implementation.
9331     7.11.1 Locale control
9332     7.11.1.1 The setlocale function
9333     Synopsis
9334 1            #include <locale.h>
9335              char *setlocale(int category, const char *locale);
9336     Description
9337 2   The setlocale function selects the appropriate portion of the program's locale as
9338     specified by the category and locale arguments. The setlocale function may be
9339     used to change or query the program's entire current locale or portions thereof. The value
9340     LC_ALL for category names the program's entire locale; the other values for
9341     category name only a portion of the program's locale. LC_COLLATE affects the
9342     behavior of the strcoll and strxfrm functions. LC_CTYPE affects the behavior of
9343     the character handling functions221) and the multibyte and wide character functions.
9344     LC_MONETARY affects the monetary formatting information returned by the
9345     localeconv function. LC_NUMERIC affects the decimal-point character for the
9346     formatted input/output functions and the string conversion functions, as well as the
9347     nonmonetary formatting information returned by the localeconv function. LC_TIME
9348     affects the behavior of the strftime and wcsftime functions.
9349 3   A value of "C" for locale specifies the minimal environment for C translation; a value
9350     of "" for locale specifies the locale-specific native environment. Other
9351     implementation-defined strings may be passed as the second argument to setlocale.
9352
9353     219) ISO/IEC 9945-2 specifies locale and charmap formats that may be used to specify locales for C.
9354     220) See ''future library directions'' (7.30.5).
9355     221) The only functions in 7.4 whose behavior is not affected by the current locale are isdigit and
9356          isxdigit.
9357
9358 [page 223]
9359
9360 4   At program startup, the equivalent of
9361             setlocale(LC_ALL, "C");
9362     is executed.
9363 5   A call to the setlocale function may introduce a data race with other calls to the
9364     setlocale function or with calls to functions that are affected by the current locale.
9365     The implementation shall behave as if no library function calls the setlocale function.
9366     Returns
9367 6   If a pointer to a string is given for locale and the selection can be honored, the
9368     setlocale function returns a pointer to the string associated with the specified
9369     category for the new locale. If the selection cannot be honored, the setlocale
9370     function returns a null pointer and the program's locale is not changed.
9371 7   A null pointer for locale causes the setlocale function to return a pointer to the
9372     string associated with the category for the program's current locale; the program's
9373     locale is not changed.222)
9374 8   The pointer to string returned by the setlocale function is such that a subsequent call
9375     with that string value and its associated category will restore that part of the program's
9376     locale. The string pointed to shall not be modified by the program, but may be
9377     overwritten by a subsequent call to the setlocale function.
9378     Forward references: formatted input/output functions (7.21.6), multibyte/wide
9379     character conversion functions (7.22.7), multibyte/wide string conversion functions
9380     (7.22.8), numeric conversion functions (7.22.1), the strcoll function (7.23.4.3), the
9381     strftime function (7.26.3.5), the strxfrm function (7.23.4.5).
9382     7.11.2 Numeric formatting convention inquiry
9383     7.11.2.1 The localeconv function
9384     Synopsis
9385 1           #include <locale.h>
9386             struct lconv *localeconv(void);
9387     Description
9388 2   The localeconv function sets the components of an object with type struct lconv
9389     with values appropriate for the formatting of numeric quantities (monetary and otherwise)
9390     according to the rules of the current locale.
9391
9392
9393
9394     222) The implementation shall arrange to encode in a string the various categories due to a heterogeneous
9395          locale when category has the value LC_ALL.
9396
9397 [page 224]
9398
9399 3   The members of the structure with type char * are pointers to strings, any of which
9400     (except decimal_point) can point to "", to indicate that the value is not available in
9401     the current locale or is of zero length. Apart from grouping and mon_grouping, the
9402     strings shall start and end in the initial shift state. The members with type char are
9403     nonnegative numbers, any of which can be CHAR_MAX to indicate that the value is not
9404     available in the current locale. The members include the following:
9405     char *decimal_point
9406               The decimal-point character used to format nonmonetary quantities.
9407     char *thousands_sep
9408               The character used to separate groups of digits before the decimal-point
9409               character in formatted nonmonetary quantities.
9410     char *grouping
9411               A string whose elements indicate the size of each group of digits in
9412               formatted nonmonetary quantities.
9413     char *mon_decimal_point
9414               The decimal-point used to format monetary quantities.
9415     char *mon_thousands_sep
9416               The separator for groups of digits before the decimal-point in formatted
9417               monetary quantities.
9418     char *mon_grouping
9419               A string whose elements indicate the size of each group of digits in
9420               formatted monetary quantities.
9421     char *positive_sign
9422               The string used to indicate a nonnegative-valued formatted monetary
9423               quantity.
9424     char *negative_sign
9425               The string used to indicate a negative-valued formatted monetary quantity.
9426     char *currency_symbol
9427               The local currency symbol applicable to the current locale.
9428     char frac_digits
9429               The number of fractional digits (those after the decimal-point) to be
9430               displayed in a locally formatted monetary quantity.
9431     char p_cs_precedes
9432               Set to 1 or 0 if the currency_symbol respectively precedes or
9433               succeeds the value for a nonnegative locally formatted monetary quantity.
9434
9435
9436
9437 [page 225]
9438
9439 char n_cs_precedes
9440           Set to 1 or 0 if the currency_symbol respectively precedes or
9441           succeeds the value for a negative locally formatted monetary quantity.
9442 char p_sep_by_space
9443           Set to a value indicating the separation of the currency_symbol, the
9444           sign string, and the value for a nonnegative locally formatted monetary
9445           quantity.
9446 char n_sep_by_space
9447           Set to a value indicating the separation of the currency_symbol, the
9448           sign string, and the value for a negative locally formatted monetary
9449           quantity.
9450 char p_sign_posn
9451           Set to a value indicating the positioning of the positive_sign for a
9452           nonnegative locally formatted monetary quantity.
9453 char n_sign_posn
9454           Set to a value indicating the positioning of the negative_sign for a
9455           negative locally formatted monetary quantity.
9456 char *int_curr_symbol
9457           The international currency symbol applicable to the current locale. The
9458           first three characters contain the alphabetic international currency symbol
9459           in accordance with those specified in ISO 4217. The fourth character
9460           (immediately preceding the null character) is the character used to separate
9461           the international currency symbol from the monetary quantity.
9462 char int_frac_digits
9463           The number of fractional digits (those after the decimal-point) to be
9464           displayed in an internationally formatted monetary quantity.
9465 char int_p_cs_precedes
9466           Set to 1 or 0 if the int_curr_symbol respectively precedes or
9467           succeeds the value for a nonnegative internationally formatted monetary
9468           quantity.
9469 char int_n_cs_precedes
9470           Set to 1 or 0 if the int_curr_symbol respectively precedes or
9471           succeeds the value for a negative internationally formatted monetary
9472           quantity.
9473 char int_p_sep_by_space
9474           Set to a value indicating the separation of the int_curr_symbol, the
9475           sign string, and the value for a nonnegative internationally formatted
9476           monetary quantity.
9477 [page 226]
9478
9479     char int_n_sep_by_space
9480               Set to a value indicating the separation of the int_curr_symbol, the
9481               sign string, and the value for a negative internationally formatted monetary
9482               quantity.
9483     char int_p_sign_posn
9484               Set to a value indicating the positioning of the positive_sign for a
9485               nonnegative internationally formatted monetary quantity.
9486     char int_n_sign_posn
9487               Set to a value indicating the positioning of the negative_sign for a
9488               negative internationally formatted monetary quantity.
9489 4   The elements of grouping and mon_grouping are interpreted according to the
9490     following:
9491     CHAR_MAX      No further grouping is to be performed.
9492     0             The previous element is to be repeatedly used for the remainder of the
9493                   digits.
9494     other         The integer value is the number of digits that compose the current group.
9495                   The next element is examined to determine the size of the next group of
9496                   digits before the current group.
9497 5   The values of p_sep_by_space, n_sep_by_space, int_p_sep_by_space,
9498     and int_n_sep_by_space are interpreted according to the following:
9499     0   No space separates the currency symbol and value.
9500     1   If the currency symbol and sign string are adjacent, a space separates them from the
9501         value; otherwise, a space separates the currency symbol from the value.
9502     2   If the currency symbol and sign string are adjacent, a space separates them;
9503         otherwise, a space separates the sign string from the value.
9504     For int_p_sep_by_space and int_n_sep_by_space, the fourth character of
9505     int_curr_symbol is used instead of a space.
9506 6   The values of p_sign_posn, n_sign_posn, int_p_sign_posn,                            and
9507     int_n_sign_posn are interpreted according to the following:
9508     0   Parentheses surround the quantity and currency symbol.
9509     1   The sign string precedes the quantity and currency symbol.
9510     2   The sign string succeeds the quantity and currency symbol.
9511     3   The sign string immediately precedes the currency symbol.
9512     4   The sign string immediately succeeds the currency symbol.
9513
9514
9515 [page 227]
9516
9517 7    The implementation shall behave as if no library function calls the localeconv
9518      function.
9519      Returns
9520 8    The localeconv function returns a pointer to the filled-in object. The structure
9521      pointed to by the return value shall not be modified by the program, but may be
9522      overwritten by a subsequent call to the localeconv function. In addition, calls to the
9523      setlocale function with categories LC_ALL, LC_MONETARY, or LC_NUMERIC may
9524      overwrite the contents of the structure.
9525 9    EXAMPLE 1 The following table illustrates rules which may well be used by four countries to format
9526      monetary quantities.
9527                                    Local format                                     International format
9528
9529      Country            Positive                  Negative                    Positive               Negative
9530
9531      Country1     1.234,56 mk             -1.234,56 mk                  FIM   1.234,56         FIM -1.234,56
9532      Country2     L.1.234                 -L.1.234                      ITL   1.234            -ITL 1.234
9533      Country3     fl. 1.234,56              fl. -1.234,56                   NLG   1.234,56         NLG -1.234,56
9534      Country4     SFrs.1,234.56           SFrs.1,234.56C                CHF   1,234.56         CHF 1,234.56C
9535 10   For these four countries, the respective values for the monetary members of the structure returned by
9536      localeconv could be:
9537                                        Country1              Country2              Country3            Country4
9538
9539      mon_decimal_point                 ","                   ""                   ","                 "."
9540      mon_thousands_sep                 "."                   "."                  "."                 ","
9541      mon_grouping                      "\3"                  "\3"                 "\3"                "\3"
9542      positive_sign                     ""                    ""                   ""                  ""
9543      negative_sign                     "-"                   "-"                  "-"                 "C"
9544      currency_symbol                   "mk"                  "L."                 "\u0192"            "SFrs."
9545      frac_digits                       2                     0                    2                   2
9546      p_cs_precedes                     0                     1                    1                   1
9547      n_cs_precedes                     0                     1                    1                   1
9548      p_sep_by_space                    1                     0                    1                   0
9549      n_sep_by_space                    1                     0                    2                   0
9550      p_sign_posn                       1                     1                    1                   1
9551      n_sign_posn                       1                     1                    4                   2
9552      int_curr_symbol                   "FIM "                "ITL "               "NLG "              "CHF "
9553      int_frac_digits                   2                     0                    2                   2
9554      int_p_cs_precedes                 1                     1                    1                   1
9555      int_n_cs_precedes                 1                     1                    1                   1
9556      int_p_sep_by_space                1                     1                    1                   1
9557      int_n_sep_by_space                2                     1                    2                   1
9558      int_p_sign_posn                   1                     1                    1                   1
9559      int_n_sign_posn                   4                     1                    4                   2
9560
9561
9562
9563
9564 [page 228]
9565
9566 11   EXAMPLE 2 The following table illustrates how the cs_precedes, sep_by_space, and sign_posn members
9567      affect the formatted value.
9568                                                                    p_sep_by_space
9569
9570      p_cs_precedes           p_sign_posn                0                   1                  2
9571
9572                      0                    0         (1.25$)            (1.25 $)            (1.25$)
9573                                           1         +1.25$             +1.25 $             + 1.25$
9574                                           2         1.25$+             1.25 $+             1.25$ +
9575                                           3         1.25+$             1.25 +$             1.25+ $
9576                                           4         1.25$+             1.25 $+             1.25$ +
9577
9578                      1                    0         ($1.25)            ($ 1.25)            ($1.25)
9579                                           1         +$1.25             +$ 1.25             + $1.25
9580                                           2         $1.25+             $ 1.25+             $1.25 +
9581                                           3         +$1.25             +$ 1.25             + $1.25
9582                                           4         $+1.25             $+ 1.25             $ +1.25
9583
9584
9585
9586
9587 [page 229]
9588
9589     7.12 Mathematics <math.h>
9590 1   The header <math.h> declares two types and many mathematical functions and defines
9591     several macros. Most synopses specify a family of functions consisting of a principal
9592     function with one or more double parameters, a double return value, or both; and
9593     other functions with the same name but with f and l suffixes, which are corresponding
9594     functions with float and long double parameters, return values, or both.223)
9595     Integer arithmetic functions and conversion functions are discussed later.
9596 2   The types
9597             float_t
9598             double_t
9599     are floating types at least as wide as float and double, respectively, and such that
9600     double_t is at least as wide as float_t. If FLT_EVAL_METHOD equals 0,
9601     float_t and double_t are float and double, respectively; if
9602     FLT_EVAL_METHOD equals 1, they are both double; if FLT_EVAL_METHOD equals
9603     2, they are both long double; and for other values of FLT_EVAL_METHOD, they are
9604     otherwise implementation-defined.224)
9605 3   The macro
9606             HUGE_VAL
9607     expands to a positive double constant expression, not necessarily representable as a
9608     float. The macros
9609             HUGE_VALF
9610             HUGE_VALL
9611     are respectively float and long double analogs of HUGE_VAL.225)
9612 4   The macro
9613             INFINITY
9614     expands to a constant expression of type float representing positive or unsigned
9615     infinity, if available; else to a positive constant of type float that overflows at
9616
9617
9618
9619     223) Particularly on systems with wide expression evaluation, a <math.h> function might pass arguments
9620          and return values in wider format than the synopsis prototype indicates.
9621     224) The types float_t and double_t are intended to be the implementation's most efficient types at
9622          least as wide as float and double, respectively. For FLT_EVAL_METHOD equal 0, 1, or 2, the
9623          type float_t is the narrowest type used by the implementation to evaluate floating expressions.
9624     225) HUGE_VAL, HUGE_VALF, and HUGE_VALL can be positive infinities in an implementation that
9625          supports infinities.
9626
9627 [page 230]
9628
9629     translation time.226)
9630 5   The macro
9631              NAN
9632     is defined if and only if the implementation supports quiet NaNs for the float type. It
9633     expands to a constant expression of type float representing a quiet NaN.
9634 6   The number classification macros
9635              FP_INFINITE
9636              FP_NAN
9637              FP_NORMAL
9638              FP_SUBNORMAL
9639              FP_ZERO
9640     represent the mutually exclusive kinds of floating-point values. They expand to integer
9641     constant expressions with distinct values. Additional implementation-defined floating-
9642     point classifications, with macro definitions beginning with FP_ and an uppercase letter,
9643     may also be specified by the implementation.
9644 7   The macro
9645              FP_FAST_FMA
9646     is optionally defined. If defined, it indicates that the fma function generally executes
9647     about as fast as, or faster than, a multiply and an add of double operands.227) The
9648     macros
9649              FP_FAST_FMAF
9650              FP_FAST_FMAL
9651     are, respectively, float and long double analogs of FP_FAST_FMA. If defined,
9652     these macros expand to the integer constant 1.
9653 8   The macros
9654              FP_ILOGB0
9655              FP_ILOGBNAN
9656     expand to integer constant expressions whose values are returned by ilogb(x) if x is
9657     zero or NaN, respectively. The value of FP_ILOGB0 shall be either INT_MIN or
9658     -INT_MAX. The value of FP_ILOGBNAN shall be either INT_MAX or INT_MIN.
9659
9660
9661     226) In this case, using INFINITY will violate the constraint in 6.4.4 and thus require a diagnostic.
9662     227) Typically, the FP_FAST_FMA macro is defined if and only if the fma function is implemented
9663          directly with a hardware multiply-add instruction. Software implementations are expected to be
9664          substantially slower.
9665
9666 [page 231]
9667
9668 9   The macros
9669             MATH_ERRNO
9670             MATH_ERREXCEPT
9671     expand to the integer constants 1 and 2, respectively; the macro
9672             math_errhandling
9673     expands to an expression that has type int and the value MATH_ERRNO,
9674     MATH_ERREXCEPT, or the bitwise OR of both. The value of math_errhandling is
9675     constant for the duration of the program. It is unspecified whether
9676     math_errhandling is a macro or an identifier with external linkage. If a macro
9677     definition is suppressed or a program defines an identifier with the name
9678     math_errhandling, the behavior is undefined.               If the expression
9679     math_errhandling & MATH_ERREXCEPT can be nonzero, the implementation
9680     shall define the macros FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in
9681     <fenv.h>.
9682     7.12.1 Treatment of error conditions
9683 1   The behavior of each of the functions in <math.h> is specified for all representable
9684     values of its input arguments, except where stated otherwise. Each function shall execute
9685     as if it were a single operation without raising SIGFPE and without generating any of the
9686     floating-point exceptions ''invalid'', ''divide-by-zero'', or ''overflow'' except to reflect
9687     the result of the function.
9688 2   For all functions, a domain error occurs if an input argument is outside the domain over
9689     which the mathematical function is defined. The description of each function lists any
9690     required domain errors; an implementation may define additional domain errors, provided
9691     that such errors are consistent with the mathematical definition of the function.228) On a
9692     domain error, the function returns an implementation-defined value; if the integer
9693     expression math_errhandling & MATH_ERRNO is nonzero, the integer expression
9694     errno acquires the value EDOM; if the integer expression math_errhandling &
9695     MATH_ERREXCEPT is nonzero, the ''invalid'' floating-point exception is raised.
9696 3   Similarly, a pole error (also known as a singularity or infinitary) occurs if the
9697     mathematical function has an exact infinite result as the finite input argument(s) are
9698     approached in the limit (for example, log(0.0)). The description of each function lists
9699     any required pole errors; an implementation may define additional pole errors, provided
9700     that such errors are consistent with the mathematical definition of the function. On a pole
9701     error, the function returns an implementation-defined value; if the integer expression
9702
9703
9704     228) In an implementation that supports infinities, this allows an infinity as an argument to be a domain
9705          error if the mathematical domain of the function does not include the infinity.
9706
9707 [page 232]
9708
9709     math_errhandling & MATH_ERRNO is nonzero, the integer expression errno
9710     acquires the value ERANGE; if the integer expression math_errhandling &
9711     MATH_ERREXCEPT is nonzero, the ''divide-by-zero'' floating-point exception is raised.
9712 4   Likewise, a range error occurs if the mathematical result of the function cannot be
9713     represented in an object of the specified type, due to extreme magnitude.
9714 5   A floating result overflows if the magnitude of the mathematical result is finite but so
9715     large that the mathematical result cannot be represented without extraordinary roundoff
9716     error in an object of the specified type. If a floating result overflows and default rounding
9717     is in effect, then the function returns the value of the macro HUGE_VAL, HUGE_VALF, or *
9718     HUGE_VALL according to the return type, with the same sign as the correct value of the
9719     function; if the integer expression math_errhandling & MATH_ERRNO is nonzero,
9720     the integer expression errno acquires the value ERANGE; if the integer expression
9721     math_errhandling & MATH_ERREXCEPT is nonzero, the ''overflow'' floating-
9722     point exception is raised.
9723 6   The result underflows if the magnitude of the mathematical result is so small that the
9724     mathematical result cannot be represented, without extraordinary roundoff error, in an
9725     object of the specified type.229) If the result underflows, the function returns an
9726     implementation-defined value whose magnitude is no greater than the smallest
9727     normalized positive number in the specified type; if the integer expression
9728     math_errhandling & MATH_ERRNO is nonzero, whether errno acquires the
9729     value    ERANGE       is    implementation-defined;     if   the  integer   expression
9730     math_errhandling & MATH_ERREXCEPT is nonzero, whether the ''underflow''
9731     floating-point exception is raised is implementation-defined.
9732 7   If a domain, pole, or range error occurs and the integer expression
9733     math_errhandling & MATH_ERRNO is zero,230) then errno shall either be set to
9734     the value corresponding to the error or left unmodified. If no such error occurs, errno
9735     shall be left unmodified regardless of the setting of math_errhandling.
9736
9737
9738
9739
9740     229) The term underflow here is intended to encompass both ''gradual underflow'' as in IEC 60559 and
9741          also ''flush-to-zero'' underflow.
9742     230) Math errors are being indicated by the floating-point exception flags rather than by errno.
9743
9744 [page 233]
9745
9746     7.12.2 The FP_CONTRACT pragma
9747     Synopsis
9748 1            #include <math.h>
9749              #pragma STDC FP_CONTRACT on-off-switch
9750     Description
9751 2   The FP_CONTRACT pragma can be used to allow (if the state is ''on'') or disallow (if the
9752     state is ''off'') the implementation to contract expressions (6.5). Each pragma can occur
9753     either outside external declarations or preceding all explicit declarations and statements
9754     inside a compound statement. When outside external declarations, the pragma takes
9755     effect from its occurrence until another FP_CONTRACT pragma is encountered, or until
9756     the end of the translation unit. When inside a compound statement, the pragma takes
9757     effect from its occurrence until another FP_CONTRACT pragma is encountered
9758     (including within a nested compound statement), or until the end of the compound
9759     statement; at the end of a compound statement the state for the pragma is restored to its
9760     condition just before the compound statement. If this pragma is used in any other
9761     context, the behavior is undefined. The default state (''on'' or ''off'') for the pragma is
9762     implementation-defined.
9763     7.12.3 Classification macros
9764 1   In the synopses in this subclause, real-floating indicates that the argument shall be an
9765     expression of real floating type.
9766     7.12.3.1 The fpclassify macro
9767     Synopsis
9768 1            #include <math.h>
9769              int fpclassify(real-floating x);
9770     Description
9771 2   The fpclassify macro classifies its argument value as NaN, infinite, normal,
9772     subnormal, zero, or into another implementation-defined category. First, an argument
9773     represented in a format wider than its semantic type is converted to its semantic type.
9774     Then classification is based on the type of the argument.231)
9775     Returns
9776 3   The fpclassify macro returns the value of the number classification macro
9777     appropriate to the value of its argument.                                *
9778
9779
9780     231) Since an expression can be evaluated with more range and precision than its type has, it is important to
9781          know the type that classification is based on. For example, a normal long double value might
9782          become subnormal when converted to double, and zero when converted to float.
9783
9784 [page 234]
9785
9786     7.12.3.2 The isfinite macro
9787     Synopsis
9788 1           #include <math.h>
9789             int isfinite(real-floating x);
9790     Description
9791 2   The isfinite macro determines whether its argument has a finite value (zero,
9792     subnormal, or normal, and not infinite or NaN). First, an argument represented in a
9793     format wider than its semantic type is converted to its semantic type. Then determination
9794     is based on the type of the argument.
9795     Returns
9796 3   The isfinite macro returns a nonzero value if and only if its argument has a finite
9797     value.
9798     7.12.3.3 The isinf macro
9799     Synopsis
9800 1           #include <math.h>
9801             int isinf(real-floating x);
9802     Description
9803 2   The isinf macro determines whether its argument value is an infinity (positive or
9804     negative). First, an argument represented in a format wider than its semantic type is
9805     converted to its semantic type. Then determination is based on the type of the argument.
9806     Returns
9807 3   The isinf macro returns a nonzero value if and only if its argument has an infinite
9808     value.
9809     7.12.3.4 The isnan macro
9810     Synopsis
9811 1           #include <math.h>
9812             int isnan(real-floating x);
9813     Description
9814 2   The isnan macro determines whether its argument value is a NaN. First, an argument
9815     represented in a format wider than its semantic type is converted to its semantic type.
9816     Then determination is based on the type of the argument.232)
9817
9818
9819     232) For the isnan macro, the type for determination does not matter unless the implementation supports
9820          NaNs in the evaluation type but not in the semantic type.
9821
9822 [page 235]
9823
9824     Returns
9825 3   The isnan macro returns a nonzero value if and only if its argument has a NaN value.
9826     7.12.3.5 The isnormal macro
9827     Synopsis
9828 1           #include <math.h>
9829             int isnormal(real-floating x);
9830     Description
9831 2   The isnormal macro determines whether its argument value is normal (neither zero,
9832     subnormal, infinite, nor NaN). First, an argument represented in a format wider than its
9833     semantic type is converted to its semantic type. Then determination is based on the type
9834     of the argument.
9835     Returns
9836 3   The isnormal macro returns a nonzero value if and only if its argument has a normal
9837     value.
9838     7.12.3.6 The signbit macro
9839     Synopsis
9840 1           #include <math.h>
9841             int signbit(real-floating x);
9842     Description
9843 2   The signbit macro determines whether the sign of its argument value is negative.233)
9844     Returns
9845 3   The signbit macro returns a nonzero value if and only if the sign of its argument value
9846     is negative.
9847
9848
9849
9850
9851     233) The signbit macro reports the sign of all values, including infinities, zeros, and NaNs. If zero is
9852          unsigned, it is treated as positive.
9853
9854 [page 236]
9855
9856     7.12.4 Trigonometric functions
9857     7.12.4.1 The acos functions
9858     Synopsis
9859 1           #include <math.h>
9860             double acos(double x);
9861             float acosf(float x);
9862             long double acosl(long double x);
9863     Description
9864 2   The acos functions compute the principal value of the arc cosine of x. A domain error
9865     occurs for arguments not in the interval [-1, +1].
9866     Returns
9867 3   The acos functions return arccos x in the interval [0, pi ] radians.
9868     7.12.4.2 The asin functions
9869     Synopsis
9870 1           #include <math.h>
9871             double asin(double x);
9872             float asinf(float x);
9873             long double asinl(long double x);
9874     Description
9875 2   The asin functions compute the principal value of the arc sine of x. A domain error
9876     occurs for arguments not in the interval [-1, +1].
9877     Returns
9878 3   The asin functions return arcsin x in the interval [-pi /2, +pi /2] radians.
9879     7.12.4.3 The atan functions
9880     Synopsis
9881 1           #include <math.h>
9882             double atan(double x);
9883             float atanf(float x);
9884             long double atanl(long double x);
9885     Description
9886 2   The atan functions compute the principal value of the arc tangent of x.
9887
9888
9889
9890
9891 [page 237]
9892
9893     Returns
9894 3   The atan functions return arctan x in the interval [-pi /2, +pi /2] radians.
9895     7.12.4.4 The atan2 functions
9896     Synopsis
9897 1          #include <math.h>
9898            double atan2(double y, double x);
9899            float atan2f(float y, float x);
9900            long double atan2l(long double y, long double x);
9901     Description
9902 2   The atan2 functions compute the value of the arc tangent of y/x, using the signs of both
9903     arguments to determine the quadrant of the return value. A domain error may occur if
9904     both arguments are zero.
9905     Returns
9906 3   The atan2 functions return arctan y/x in the interval [-pi , +pi ] radians.
9907     7.12.4.5 The cos functions
9908     Synopsis
9909 1          #include <math.h>
9910            double cos(double x);
9911            float cosf(float x);
9912            long double cosl(long double x);
9913     Description
9914 2   The cos functions compute the cosine of x (measured in radians).
9915     Returns
9916 3   The cos functions return cos x.
9917     7.12.4.6 The sin functions
9918     Synopsis
9919 1          #include <math.h>
9920            double sin(double x);
9921            float sinf(float x);
9922            long double sinl(long double x);
9923     Description
9924 2   The sin functions compute the sine of x (measured in radians).
9925
9926
9927
9928 [page 238]
9929
9930     Returns
9931 3   The sin functions return sin x.
9932     7.12.4.7 The tan functions
9933     Synopsis
9934 1           #include <math.h>
9935             double tan(double x);
9936             float tanf(float x);
9937             long double tanl(long double x);
9938     Description
9939 2   The tan functions return the tangent of x (measured in radians).
9940     Returns
9941 3   The tan functions return tan x.
9942     7.12.5 Hyperbolic functions
9943     7.12.5.1 The acosh functions
9944     Synopsis
9945 1           #include <math.h>
9946             double acosh(double x);
9947             float acoshf(float x);
9948             long double acoshl(long double x);
9949     Description
9950 2   The acosh functions compute the (nonnegative) arc hyperbolic cosine of x. A domain
9951     error occurs for arguments less than 1.
9952     Returns
9953 3   The acosh functions return arcosh x in the interval [0, +(inf)].
9954     7.12.5.2 The asinh functions
9955     Synopsis
9956 1           #include <math.h>
9957             double asinh(double x);
9958             float asinhf(float x);
9959             long double asinhl(long double x);
9960     Description
9961 2   The asinh functions compute the arc hyperbolic sine of x.
9962
9963
9964 [page 239]
9965
9966     Returns
9967 3   The asinh functions return arsinh x.
9968     7.12.5.3 The atanh functions
9969     Synopsis
9970 1          #include <math.h>
9971            double atanh(double x);
9972            float atanhf(float x);
9973            long double atanhl(long double x);
9974     Description
9975 2   The atanh functions compute the arc hyperbolic tangent of x. A domain error occurs
9976     for arguments not in the interval [-1, +1]. A pole error may occur if the argument equals
9977     -1 or +1.
9978     Returns
9979 3   The atanh functions return artanh x.
9980     7.12.5.4 The cosh functions
9981     Synopsis
9982 1          #include <math.h>
9983            double cosh(double x);
9984            float coshf(float x);
9985            long double coshl(long double x);
9986     Description
9987 2   The cosh functions compute the hyperbolic cosine of x. A range error occurs if the
9988     magnitude of x is too large.
9989     Returns
9990 3   The cosh functions return cosh x.
9991     7.12.5.5 The sinh functions
9992     Synopsis
9993 1          #include <math.h>
9994            double sinh(double x);
9995            float sinhf(float x);
9996            long double sinhl(long double x);
9997     Description
9998 2   The sinh functions compute the hyperbolic sine of x. A range error occurs if the
9999     magnitude of x is too large.
10000 [page 240]
10001
10002     Returns
10003 3   The sinh functions return sinh x.
10004     7.12.5.6 The tanh functions
10005     Synopsis
10006 1           #include <math.h>
10007             double tanh(double x);
10008             float tanhf(float x);
10009             long double tanhl(long double x);
10010     Description
10011 2   The tanh functions compute the hyperbolic tangent of x.
10012     Returns
10013 3   The tanh functions return tanh x.
10014     7.12.6 Exponential and logarithmic functions
10015     7.12.6.1 The exp functions
10016     Synopsis
10017 1           #include <math.h>
10018             double exp(double x);
10019             float expf(float x);
10020             long double expl(long double x);
10021     Description
10022 2   The exp functions compute the base-e exponential of x. A range error occurs if the
10023     magnitude of x is too large.
10024     Returns
10025 3   The exp functions return ex .
10026     7.12.6.2 The exp2 functions
10027     Synopsis
10028 1           #include <math.h>
10029             double exp2(double x);
10030             float exp2f(float x);
10031             long double exp2l(long double x);
10032     Description
10033 2   The exp2 functions compute the base-2 exponential of x. A range error occurs if the
10034     magnitude of x is too large.
10035
10036 [page 241]
10037
10038     Returns
10039 3   The exp2 functions return 2x .
10040     7.12.6.3 The expm1 functions
10041     Synopsis
10042 1           #include <math.h>
10043             double expm1(double x);
10044             float expm1f(float x);
10045             long double expm1l(long double x);
10046     Description
10047 2   The expm1 functions compute the base-e exponential of the argument, minus 1. A range
10048     error occurs if x is too large.234)
10049     Returns
10050 3   The expm1 functions return ex - 1.
10051     7.12.6.4 The frexp functions
10052     Synopsis
10053 1           #include <math.h>
10054             double frexp(double value, int *exp);
10055             float frexpf(float value, int *exp);
10056             long double frexpl(long double value, int *exp);
10057     Description
10058 2   The frexp functions break a floating-point number into a normalized fraction and an
10059     integral power of 2. They store the integer in the int object pointed to by exp.
10060     Returns
10061 3   If value is not a floating-point number or if the integral power of 2 is outside the range
10062     of int, the results are unspecified. Otherwise, the frexp functions return the value x,
10063     such that x has a magnitude in the interval [1/2, 1) or zero, and value equals x x 2*exp .
10064     If value is zero, both parts of the result are zero.
10065
10066
10067
10068
10069     234) For small magnitude x, expm1(x) is expected to be more accurate than exp(x) - 1.
10070
10071 [page 242]
10072
10073     7.12.6.5 The ilogb functions
10074     Synopsis
10075 1           #include <math.h>
10076             int ilogb(double x);
10077             int ilogbf(float x);
10078             int ilogbl(long double x);
10079     Description
10080 2   The ilogb functions extract the exponent of x as a signed int value. If x is zero they
10081     compute the value FP_ILOGB0; if x is infinite they compute the value INT_MAX; if x is
10082     a NaN they compute the value FP_ILOGBNAN; otherwise, they are equivalent to calling
10083     the corresponding logb function and casting the returned value to type int. A domain
10084     error or range error may occur if x is zero, infinite, or NaN. If the correct value is outside
10085     the range of the return type, the numeric result is unspecified.
10086     Returns
10087 3   The ilogb functions return the exponent of x as a signed int value.
10088     Forward references: the logb functions (7.12.6.11).
10089     7.12.6.6 The ldexp functions
10090     Synopsis
10091 1           #include <math.h>
10092             double ldexp(double x, int exp);
10093             float ldexpf(float x, int exp);
10094             long double ldexpl(long double x, int exp);
10095     Description
10096 2   The ldexp functions multiply a floating-point number by an integral power of 2. A
10097     range error may occur.
10098     Returns
10099 3   The ldexp functions return x x 2exp .
10100     7.12.6.7 The log functions
10101     Synopsis
10102 1           #include <math.h>
10103             double log(double x);
10104             float logf(float x);
10105             long double logl(long double x);
10106
10107
10108
10109 [page 243]
10110
10111     Description
10112 2   The log functions compute the base-e (natural) logarithm of x. A domain error occurs if
10113     the argument is negative. A pole error may occur if the argument is zero.
10114     Returns
10115 3   The log functions return loge x.
10116     7.12.6.8 The log10 functions
10117     Synopsis
10118 1           #include <math.h>
10119             double log10(double x);
10120             float log10f(float x);
10121             long double log10l(long double x);
10122     Description
10123 2   The log10 functions compute the base-10 (common) logarithm of x. A domain error
10124     occurs if the argument is negative. A pole error may occur if the argument is zero.
10125     Returns
10126 3   The log10 functions return log10 x.
10127     7.12.6.9 The log1p functions
10128     Synopsis
10129 1           #include <math.h>
10130             double log1p(double x);
10131             float log1pf(float x);
10132             long double log1pl(long double x);
10133     Description
10134 2   The log1p functions compute the base-e (natural) logarithm of 1 plus the argument.235)
10135     A domain error occurs if the argument is less than -1. A pole error may occur if the
10136     argument equals -1.
10137     Returns
10138 3   The log1p functions return loge (1 + x).
10139
10140
10141
10142
10143     235) For small magnitude x, log1p(x) is expected to be more accurate than log(1 + x).
10144
10145 [page 244]
10146
10147     7.12.6.10 The log2 functions
10148     Synopsis
10149 1           #include <math.h>
10150             double log2(double x);
10151             float log2f(float x);
10152             long double log2l(long double x);
10153     Description
10154 2   The log2 functions compute the base-2 logarithm of x. A domain error occurs if the
10155     argument is less than zero. A pole error may occur if the argument is zero.
10156     Returns
10157 3   The log2 functions return log2 x.
10158     7.12.6.11 The logb functions
10159     Synopsis
10160 1           #include <math.h>
10161             double logb(double x);
10162             float logbf(float x);
10163             long double logbl(long double x);
10164     Description
10165 2   The logb functions extract the exponent of x, as a signed integer value in floating-point
10166     format. If x is subnormal it is treated as though it were normalized; thus, for positive
10167     finite x,
10168           1 <= x x FLT_RADIX-logb(x) < FLT_RADIX
10169     A domain error or pole error may occur if the argument is zero.
10170     Returns
10171 3   The logb functions return the signed exponent of x.
10172     7.12.6.12 The modf functions
10173     Synopsis
10174 1           #include <math.h>
10175             double modf(double value, double *iptr);
10176             float modff(float value, float *iptr);
10177             long double modfl(long double value, long double *iptr);
10178     Description
10179 2   The modf functions break the argument value into integral and fractional parts, each of
10180     which has the same type and sign as the argument. They store the integral part (in
10181 [page 245]
10182
10183     floating-point format) in the object pointed to by iptr.
10184     Returns
10185 3   The modf functions return the signed fractional part of value.
10186     7.12.6.13 The scalbn and scalbln functions
10187     Synopsis
10188 1          #include <math.h>
10189            double scalbn(double x, int n);
10190            float scalbnf(float x, int n);
10191            long double scalbnl(long double x, int n);
10192            double scalbln(double x, long int n);
10193            float scalblnf(float x, long int n);
10194            long double scalblnl(long double x, long int n);
10195     Description
10196 2   The scalbn and scalbln functions compute x x FLT_RADIXn efficiently, not
10197     normally by computing FLT_RADIXn explicitly. A range error may occur.
10198     Returns
10199 3   The scalbn and scalbln functions return x x FLT_RADIXn .
10200     7.12.7 Power and absolute-value functions
10201     7.12.7.1 The cbrt functions
10202     Synopsis
10203 1          #include <math.h>
10204            double cbrt(double x);
10205            float cbrtf(float x);
10206            long double cbrtl(long double x);
10207     Description
10208 2   The cbrt functions compute the real cube root of x.
10209     Returns
10210 3   The cbrt functions return x1/3 .
10211
10212
10213
10214
10215 [page 246]
10216
10217     7.12.7.2 The fabs functions
10218     Synopsis
10219 1           #include <math.h>
10220             double fabs(double x);
10221             float fabsf(float x);
10222             long double fabsl(long double x);
10223     Description
10224 2   The fabs functions compute the absolute value of a floating-point number x.
10225     Returns
10226 3   The fabs functions return | x |.
10227     7.12.7.3 The hypot functions
10228     Synopsis
10229 1           #include <math.h>
10230             double hypot(double x, double y);
10231             float hypotf(float x, float y);
10232             long double hypotl(long double x, long double y);
10233     Description
10234 2   The hypot functions compute the square root of the sum of the squares of x and y,
10235     without undue overflow or underflow. A range error may occur.
10236 3   Returns
10237 4   The hypot functions return sqrt:x2 + y2 .
10238                                -
10239                                -----
10240     7.12.7.4 The pow functions
10241     Synopsis
10242 1           #include <math.h>
10243             double pow(double x, double y);
10244             float powf(float x, float y);
10245             long double powl(long double x, long double y);
10246     Description
10247 2   The pow functions compute x raised to the power y. A domain error occurs if x is finite
10248     and negative and y is finite and not an integer value. A range error may occur. A domain
10249     error may occur if x is zero and y is zero. A domain error or pole error may occur if x is
10250     zero and y is less than zero.
10251
10252
10253
10254
10255 [page 247]
10256
10257     Returns
10258 3   The pow functions return xy .
10259     7.12.7.5 The sqrt functions
10260     Synopsis
10261 1          #include <math.h>
10262            double sqrt(double x);
10263            float sqrtf(float x);
10264            long double sqrtl(long double x);
10265     Description
10266 2   The sqrt functions compute the nonnegative square root of x. A domain error occurs if
10267     the argument is less than zero.
10268     Returns
10269 3   The sqrt functions return sqrt:x.
10270                               -
10271                               -
10272     7.12.8 Error and gamma functions
10273     7.12.8.1 The erf functions
10274     Synopsis
10275 1          #include <math.h>
10276            double erf(double x);
10277            float erff(float x);
10278            long double erfl(long double x);
10279     Description
10280 2   The erf functions compute the error function of x.
10281     Returns
10282 3                                      2        x
10283                                             (integral)       e-t dt.
10284                                                       2
10285     The erf functions return erf x =
10286                                        sqrt:pi
10287                                        -
10288                                        -    0
10289
10290     7.12.8.2 The erfc functions
10291     Synopsis
10292 1          #include <math.h>
10293            double erfc(double x);
10294            float erfcf(float x);
10295            long double erfcl(long double x);
10296     Description
10297 2   The erfc functions compute the complementary error function of x. A range error
10298     occurs if x is too large.
10299 [page 248]
10300
10301     Returns
10302 3                                                       2       (inf)
10303                                                             (integral)       e-t dt.
10304                                                                       2
10305     The erfc functions return erfc x = 1 - erf x =
10306                                                      sqrt:pi
10307                                                      -
10308                                                      -      x
10309
10310     7.12.8.3 The lgamma functions
10311     Synopsis
10312 1           #include <math.h>
10313             double lgamma(double x);
10314             float lgammaf(float x);
10315             long double lgammal(long double x);
10316     Description
10317 2   The lgamma functions compute the natural logarithm of the absolute value of gamma of
10318     x. A range error occurs if x is too large. A pole error may occur if x is a negative integer
10319     or zero.
10320     Returns
10321 3   The lgamma functions return loge | (Gamma)(x) |.
10322     7.12.8.4 The tgamma functions
10323     Synopsis
10324 1           #include <math.h>
10325             double tgamma(double x);
10326             float tgammaf(float x);
10327             long double tgammal(long double x);
10328     Description
10329 2   The tgamma functions compute the gamma function of x. A domain error or pole error
10330     may occur if x is a negative integer or zero. A range error occurs if the magnitude of x is
10331     too large and may occur if the magnitude of x is too small.
10332     Returns
10333 3   The tgamma functions return (Gamma)(x).
10334
10335
10336
10337
10338 [page 249]
10339
10340     7.12.9 Nearest integer functions
10341     7.12.9.1 The ceil functions
10342     Synopsis
10343 1          #include <math.h>
10344            double ceil(double x);
10345            float ceilf(float x);
10346            long double ceill(long double x);
10347     Description
10348 2   The ceil functions compute the smallest integer value not less than x.
10349     Returns
10350 3   The ceil functions return [^x^], expressed as a floating-point number.
10351     7.12.9.2 The floor functions
10352     Synopsis
10353 1          #include <math.h>
10354            double floor(double x);
10355            float floorf(float x);
10356            long double floorl(long double x);
10357     Description
10358 2   The floor functions compute the largest integer value not greater than x.
10359     Returns
10360 3   The floor functions return [_x_], expressed as a floating-point number.
10361     7.12.9.3 The nearbyint functions
10362     Synopsis
10363 1          #include <math.h>
10364            double nearbyint(double x);
10365            float nearbyintf(float x);
10366            long double nearbyintl(long double x);
10367     Description
10368 2   The nearbyint functions round their argument to an integer value in floating-point
10369     format, using the current rounding direction and without raising the ''inexact'' floating-
10370     point exception.
10371
10372
10373
10374
10375 [page 250]
10376
10377     Returns
10378 3   The nearbyint functions return the rounded integer value.
10379     7.12.9.4 The rint functions
10380     Synopsis
10381 1           #include <math.h>
10382             double rint(double x);
10383             float rintf(float x);
10384             long double rintl(long double x);
10385     Description
10386 2   The rint functions differ from the nearbyint functions (7.12.9.3) only in that the
10387     rint functions may raise the ''inexact'' floating-point exception if the result differs in
10388     value from the argument.
10389     Returns
10390 3   The rint functions return the rounded integer value.
10391     7.12.9.5 The lrint and llrint functions
10392     Synopsis
10393 1           #include <math.h>
10394             long int lrint(double x);
10395             long int lrintf(float x);
10396             long int lrintl(long double x);
10397             long long int llrint(double x);
10398             long long int llrintf(float x);
10399             long long int llrintl(long double x);
10400     Description
10401 2   The lrint and llrint functions round their argument to the nearest integer value,
10402     rounding according to the current rounding direction. If the rounded value is outside the
10403     range of the return type, the numeric result is unspecified and a domain error or range
10404     error may occur.
10405     Returns
10406 3   The lrint and llrint functions return the rounded integer value.
10407
10408
10409
10410
10411 [page 251]
10412
10413     7.12.9.6 The round functions
10414     Synopsis
10415 1          #include <math.h>
10416            double round(double x);
10417            float roundf(float x);
10418            long double roundl(long double x);
10419     Description
10420 2   The round functions round their argument to the nearest integer value in floating-point
10421     format, rounding halfway cases away from zero, regardless of the current rounding
10422     direction.
10423     Returns
10424 3   The round functions return the rounded integer value.
10425     7.12.9.7 The lround and llround functions
10426     Synopsis
10427 1          #include <math.h>
10428            long int lround(double x);
10429            long int lroundf(float x);
10430            long int lroundl(long double x);
10431            long long int llround(double x);
10432            long long int llroundf(float x);
10433            long long int llroundl(long double x);
10434     Description
10435 2   The lround and llround functions round their argument to the nearest integer value,
10436     rounding halfway cases away from zero, regardless of the current rounding direction. If
10437     the rounded value is outside the range of the return type, the numeric result is unspecified
10438     and a domain error or range error may occur.
10439     Returns
10440 3   The lround and llround functions return the rounded integer value.
10441     7.12.9.8 The trunc functions
10442     Synopsis
10443 1          #include <math.h>
10444            double trunc(double x);
10445            float truncf(float x);
10446            long double truncl(long double x);
10447
10448
10449 [page 252]
10450
10451     Description
10452 2   The trunc functions round their argument to the integer value, in floating format,
10453     nearest to but no larger in magnitude than the argument.
10454     Returns
10455 3   The trunc functions return the truncated integer value.
10456     7.12.10 Remainder functions
10457     7.12.10.1 The fmod functions
10458     Synopsis
10459 1            #include <math.h>
10460              double fmod(double x, double y);
10461              float fmodf(float x, float y);
10462              long double fmodl(long double x, long double y);
10463     Description
10464 2   The fmod functions compute the floating-point remainder of x/y.
10465     Returns
10466 3   The fmod functions return the value x - ny, for some integer n such that, if y is nonzero,
10467     the result has the same sign as x and magnitude less than the magnitude of y. If y is zero,
10468     whether a domain error occurs or the fmod functions return zero is implementation-
10469     defined.
10470     7.12.10.2 The remainder functions
10471     Synopsis
10472 1            #include <math.h>
10473              double remainder(double x, double y);
10474              float remainderf(float x, float y);
10475              long double remainderl(long double x, long double y);
10476     Description
10477 2   The remainder functions compute the remainder x REM y required by IEC 60559.236)
10478
10479
10480
10481
10482     236) ''When y != 0, the remainder r = x REM y is defined regardless of the rounding mode by the
10483          mathematical relation r = x - ny, where n is the integer nearest the exact value of x/y; whenever
10484          | n - x/y | = 1/2, then n is even. If r = 0, its sign shall be that of x.'' This definition is applicable for *
10485          all implementations.
10486
10487 [page 253]
10488
10489     Returns
10490 3   The remainder functions return x REM y. If y is zero, whether a domain error occurs
10491     or the functions return zero is implementation defined.
10492     7.12.10.3 The remquo functions
10493     Synopsis
10494 1          #include <math.h>
10495            double remquo(double x, double y, int *quo);
10496            float remquof(float x, float y, int *quo);
10497            long double remquol(long double x, long double y,
10498                 int *quo);
10499     Description
10500 2   The remquo functions compute the same remainder as the remainder functions. In
10501     the object pointed to by quo they store a value whose sign is the sign of x/y and whose
10502     magnitude is congruent modulo 2n to the magnitude of the integral quotient of x/y, where
10503     n is an implementation-defined integer greater than or equal to 3.
10504     Returns
10505 3   The remquo functions return x REM y. If y is zero, the value stored in the object
10506     pointed to by quo is unspecified and whether a domain error occurs or the functions
10507     return zero is implementation defined.
10508     7.12.11 Manipulation functions
10509     7.12.11.1 The copysign functions
10510     Synopsis
10511 1          #include <math.h>
10512            double copysign(double x, double y);
10513            float copysignf(float x, float y);
10514            long double copysignl(long double x, long double y);
10515     Description
10516 2   The copysign functions produce a value with the magnitude of x and the sign of y.
10517     They produce a NaN (with the sign of y) if x is a NaN. On implementations that
10518     represent a signed zero but do not treat negative zero consistently in arithmetic
10519     operations, the copysign functions regard the sign of zero as positive.
10520     Returns
10521 3   The copysign functions return a value with the magnitude of x and the sign of y.
10522
10523
10524
10525 [page 254]
10526
10527     7.12.11.2 The nan functions
10528     Synopsis
10529 1           #include <math.h>
10530             double nan(const char *tagp);
10531             float nanf(const char *tagp);
10532             long double nanl(const char *tagp);
10533     Description
10534 2   The call nan("n-char-sequence") is equivalent to strtod("NAN(n-char-
10535     sequence)",     (char**)       NULL); the call nan("") is equivalent to
10536     strtod("NAN()", (char**) NULL). If tagp does not point to an n-char
10537     sequence or an empty string, the call is equivalent to strtod("NAN", (char**)
10538     NULL). Calls to nanf and nanl are equivalent to the corresponding calls to strtof
10539     and strtold.
10540     Returns
10541 3   The nan functions return a quiet NaN, if available, with content indicated through tagp.
10542     If the implementation does not support quiet NaNs, the functions return zero.
10543     Forward references: the strtod, strtof, and strtold functions (7.22.1.3).
10544     7.12.11.3 The nextafter functions
10545     Synopsis
10546 1           #include <math.h>
10547             double nextafter(double x, double y);
10548             float nextafterf(float x, float y);
10549             long double nextafterl(long double x, long double y);
10550     Description
10551 2   The nextafter functions determine the next representable value, in the type of the
10552     function, after x in the direction of y, where x and y are first converted to the type of the
10553     function.237) The nextafter functions return y if x equals y. A range error may occur
10554     if the magnitude of x is the largest finite value representable in the type and the result is
10555     infinite or not representable in the type.
10556     Returns
10557 3   The nextafter functions return the next representable value in the specified format
10558     after x in the direction of y.
10559
10560
10561     237) The argument values are converted to the type of the function, even by a macro implementation of the
10562          function.
10563
10564 [page 255]
10565
10566     7.12.11.4 The nexttoward functions
10567     Synopsis
10568 1           #include <math.h>
10569             double nexttoward(double x, long double y);
10570             float nexttowardf(float x, long double y);
10571             long double nexttowardl(long double x, long double y);
10572     Description
10573 2   The nexttoward functions are equivalent to the nextafter functions except that the
10574     second parameter has type long double and the functions return y converted to the
10575     type of the function if x equals y.238)
10576     7.12.12 Maximum, minimum, and positive difference functions
10577     7.12.12.1 The fdim functions
10578     Synopsis
10579 1           #include <math.h>
10580             double fdim(double x, double y);
10581             float fdimf(float x, float y);
10582             long double fdiml(long double x, long double y);
10583     Description
10584 2   The fdim functions determine the positive difference between their arguments:
10585           {x - y if x > y
10586           {
10587           {+0     if x <= y
10588     A range error may occur.
10589     Returns
10590 3   The fdim functions return the positive difference value.
10591     7.12.12.2 The fmax functions
10592     Synopsis
10593 1           #include <math.h>
10594             double fmax(double x, double y);
10595             float fmaxf(float x, float y);
10596             long double fmaxl(long double x, long double y);
10597
10598
10599
10600     238) The result of the nexttoward functions is determined in the type of the function, without loss of
10601          range or precision in a floating second argument.
10602
10603 [page 256]
10604
10605     Description
10606 2   The fmax functions determine the maximum numeric value of their arguments.239)
10607     Returns
10608 3   The fmax functions return the maximum numeric value of their arguments.
10609     7.12.12.3 The fmin functions
10610     Synopsis
10611 1           #include <math.h>
10612             double fmin(double x, double y);
10613             float fminf(float x, float y);
10614             long double fminl(long double x, long double y);
10615     Description
10616 2   The fmin functions determine the minimum numeric value of their arguments.240)
10617     Returns
10618 3   The fmin functions return the minimum numeric value of their arguments.
10619     7.12.13 Floating multiply-add
10620     7.12.13.1 The fma functions
10621     Synopsis
10622 1           #include <math.h>
10623             double fma(double x, double y, double z);
10624             float fmaf(float x, float y, float z);
10625             long double fmal(long double x, long double y,
10626                  long double z);
10627     Description
10628 2   The fma functions compute (x x y) + z, rounded as one ternary operation: they compute
10629     the value (as if) to infinite precision and round once to the result format, according to the
10630     current rounding mode. A range error may occur.
10631     Returns
10632 3   The fma functions return (x x y) + z, rounded as one ternary operation.
10633
10634
10635
10636
10637     239) NaN arguments are treated as missing data: if one argument is a NaN and the other numeric, then the
10638          fmax functions choose the numeric value. See F.10.9.2.
10639     240) The fmin functions are analogous to the fmax functions in their treatment of NaNs.
10640
10641 [page 257]
10642
10643     7.12.14 Comparison macros
10644 1   The relational and equality operators support the usual mathematical relationships
10645     between numeric values. For any ordered pair of numeric values exactly one of the
10646     relationships -- less, greater, and equal -- is true. Relational operators may raise the
10647     ''invalid'' floating-point exception when argument values are NaNs. For a NaN and a
10648     numeric value, or for two NaNs, just the unordered relationship is true.241) The following
10649     subclauses provide macros that are quiet (non floating-point exception raising) versions
10650     of the relational operators, and other comparison macros that facilitate writing efficient
10651     code that accounts for NaNs without suffering the ''invalid'' floating-point exception. In
10652     the synopses in this subclause, real-floating indicates that the argument shall be an
10653     expression of real floating type242) (both arguments need not have the same type).243)
10654     7.12.14.1 The isgreater macro
10655     Synopsis
10656 1            #include <math.h>
10657              int isgreater(real-floating x, real-floating y);
10658     Description
10659 2   The isgreater macro determines whether its first argument is greater than its second
10660     argument. The value of isgreater(x, y) is always equal to (x) > (y); however,
10661     unlike (x) > (y), isgreater(x, y) does not raise the ''invalid'' floating-point
10662     exception when x and y are unordered.
10663     Returns
10664 3   The isgreater macro returns the value of (x) > (y).
10665     7.12.14.2 The isgreaterequal macro
10666     Synopsis
10667 1            #include <math.h>
10668              int isgreaterequal(real-floating x, real-floating y);
10669
10670
10671
10672
10673     241) IEC 60559 requires that the built-in relational operators raise the ''invalid'' floating-point exception if
10674          the operands compare unordered, as an error indicator for programs written without consideration of
10675          NaNs; the result in these cases is false.
10676     242) If any argument is of integer type, or any other type that is not a real floating type, the behavior is
10677          undefined.
10678     243) Whether an argument represented in a format wider than its semantic type is converted to the semantic
10679          type is unspecified.
10680
10681 [page 258]
10682
10683     Description
10684 2   The isgreaterequal macro determines whether its first argument is greater than or
10685     equal to its second argument. The value of isgreaterequal(x, y) is always equal
10686     to (x) >= (y); however, unlike (x) >= (y), isgreaterequal(x, y) does
10687     not raise the ''invalid'' floating-point exception when x and y are unordered.
10688     Returns
10689 3   The isgreaterequal macro returns the value of (x) >= (y).
10690     7.12.14.3 The isless macro
10691     Synopsis
10692 1           #include <math.h>
10693             int isless(real-floating x, real-floating y);
10694     Description
10695 2   The isless macro determines whether its first argument is less than its second
10696     argument. The value of isless(x, y) is always equal to (x) < (y); however,
10697     unlike (x) < (y), isless(x, y) does not raise the ''invalid'' floating-point
10698     exception when x and y are unordered.
10699     Returns
10700 3   The isless macro returns the value of (x) < (y).
10701     7.12.14.4 The islessequal macro
10702     Synopsis
10703 1           #include <math.h>
10704             int islessequal(real-floating x, real-floating y);
10705     Description
10706 2   The islessequal macro determines whether its first argument is less than or equal to
10707     its second argument. The value of islessequal(x, y) is always equal to
10708     (x) <= (y); however, unlike (x) <= (y), islessequal(x, y) does not raise
10709     the ''invalid'' floating-point exception when x and y are unordered.
10710     Returns
10711 3   The islessequal macro returns the value of (x) <= (y).
10712
10713
10714
10715
10716 [page 259]
10717
10718     7.12.14.5 The islessgreater macro
10719     Synopsis
10720 1          #include <math.h>
10721            int islessgreater(real-floating x, real-floating y);
10722     Description
10723 2   The islessgreater macro determines whether its first argument is less than or
10724     greater than its second argument. The islessgreater(x, y) macro is similar to
10725     (x) < (y) || (x) > (y); however, islessgreater(x, y) does not raise
10726     the ''invalid'' floating-point exception when x and y are unordered (nor does it evaluate x
10727     and y twice).
10728     Returns
10729 3   The islessgreater macro returns the value of (x) < (y) || (x) > (y).
10730     7.12.14.6 The isunordered macro
10731     Synopsis
10732 1          #include <math.h>
10733            int isunordered(real-floating x, real-floating y);
10734     Description
10735 2   The isunordered macro determines whether its arguments are unordered.
10736     Returns
10737 3   The isunordered macro returns 1 if its arguments are unordered and 0 otherwise.
10738
10739
10740
10741
10742 [page 260]
10743
10744     7.13 Nonlocal jumps <setjmp.h>
10745 1   The header <setjmp.h> defines the macro setjmp, and declares one function and
10746     one type, for bypassing the normal function call and return discipline.244)
10747 2   The type declared is
10748             jmp_buf
10749     which is an array type suitable for holding the information needed to restore a calling
10750     environment. The environment of a call to the setjmp macro consists of information
10751     sufficient for a call to the longjmp function to return execution to the correct block and
10752     invocation of that block, were it called recursively. It does not include the state of the
10753     floating-point status flags, of open files, or of any other component of the abstract
10754     machine.
10755 3   It is unspecified whether setjmp is a macro or an identifier declared with external
10756     linkage. If a macro definition is suppressed in order to access an actual function, or a
10757     program defines an external identifier with the name setjmp, the behavior is undefined.
10758     7.13.1 Save calling environment
10759     7.13.1.1 The setjmp macro
10760     Synopsis
10761 1           #include <setjmp.h>
10762             int setjmp(jmp_buf env);
10763     Description
10764 2   The setjmp macro saves its calling environment in its jmp_buf argument for later use
10765     by the longjmp function.
10766     Returns
10767 3   If the return is from a direct invocation, the setjmp macro returns the value zero. If the
10768     return is from a call to the longjmp function, the setjmp macro returns a nonzero
10769     value.
10770     Environmental limits
10771 4   An invocation of the setjmp macro shall appear only in one of the following contexts:
10772     -- the entire controlling expression of a selection or iteration statement;
10773     -- one operand of a relational or equality operator with the other operand an integer
10774       constant expression, with the resulting expression being the entire controlling
10775
10776
10777     244) These functions are useful for dealing with unusual conditions encountered in a low-level function of
10778          a program.
10779
10780 [page 261]
10781
10782         expression of a selection or iteration statement;
10783     -- the operand of a unary ! operator with the resulting expression being the entire
10784       controlling expression of a selection or iteration statement; or
10785     -- the entire expression of an expression statement (possibly cast to void).
10786 5   If the invocation appears in any other context, the behavior is undefined.
10787     7.13.2 Restore calling environment
10788     7.13.2.1 The longjmp function
10789     Synopsis
10790 1            #include <setjmp.h>
10791              _Noreturn void longjmp(jmp_buf env, int val);
10792     Description
10793 2   The longjmp function restores the environment saved by the most recent invocation of
10794     the setjmp macro in the same invocation of the program with the corresponding
10795     jmp_buf argument. If there has been no such invocation, or if the function containing
10796     the invocation of the setjmp macro has terminated execution245) in the interim, or if the
10797     invocation of the setjmp macro was within the scope of an identifier with variably
10798     modified type and execution has left that scope in the interim, the behavior is undefined.
10799 3   All accessible objects have values, and all other components of the abstract machine246)
10800     have state, as of the time the longjmp function was called, except that the values of
10801     objects of automatic storage duration that are local to the function containing the
10802     invocation of the corresponding setjmp macro that do not have volatile-qualified type
10803     and have been changed between the setjmp invocation and longjmp call are
10804     indeterminate.
10805     Returns
10806 4   After longjmp is completed, program execution continues as if the corresponding
10807     invocation of the setjmp macro had just returned the value specified by val. The
10808     longjmp function cannot cause the setjmp macro to return the value 0; if val is 0,
10809     the setjmp macro returns the value 1.
10810 5   EXAMPLE The longjmp function that returns control back to the point of the setjmp invocation
10811     might cause memory associated with a variable length array object to be squandered.
10812
10813
10814
10815
10816     245) For example, by executing a return statement or because another longjmp call has caused a
10817          transfer to a setjmp invocation in a function earlier in the set of nested calls.
10818     246) This includes, but is not limited to, the floating-point status flags and the state of open files.
10819
10820 [page 262]
10821
10822         #include <setjmp.h>
10823         jmp_buf buf;
10824         void g(int n);
10825         void h(int n);
10826         int n = 6;
10827         void f(void)
10828         {
10829               int x[n];          // valid: f is not terminated
10830               setjmp(buf);
10831               g(n);
10832         }
10833         void g(int n)
10834         {
10835               int a[n];          // a may remain allocated
10836               h(n);
10837         }
10838         void h(int n)
10839         {
10840               int b[n];          // b may remain allocated
10841               longjmp(buf, 2);   // might cause memory loss
10842         }
10843
10844
10845
10846
10847 [page 263]
10848
10849     7.14 Signal handling <signal.h>
10850 1   The header <signal.h> declares a type and two functions and defines several macros,
10851     for handling various signals (conditions that may be reported during program execution).
10852 2   The type defined is
10853              sig_atomic_t
10854     which is the (possibly volatile-qualified) integer type of an object that can be accessed as
10855     an atomic entity, even in the presence of asynchronous interrupts.
10856 3   The macros defined are
10857              SIG_DFL
10858              SIG_ERR
10859              SIG_IGN
10860     which expand to constant expressions with distinct values that have type compatible with
10861     the second argument to, and the return value of, the signal function, and whose values
10862     compare unequal to the address of any declarable function; and the following, which
10863     expand to positive integer constant expressions with type int and distinct values that are
10864     the signal numbers, each corresponding to the specified condition:
10865              SIGABRT abnormal termination, such as is initiated by the abort function
10866              SIGFPE        an erroneous arithmetic operation, such as zero divide or an operation
10867                            resulting in overflow
10868              SIGILL        detection of an invalid function image, such as an invalid instruction
10869              SIGINT        receipt of an interactive attention signal
10870              SIGSEGV an invalid access to storage
10871              SIGTERM a termination request sent to the program
10872 4   An implementation need not generate any of these signals, except as a result of explicit
10873     calls to the raise function. Additional signals and pointers to undeclarable functions,
10874     with macro definitions beginning, respectively, with the letters SIG and an uppercase
10875     letter or with SIG_ and an uppercase letter,247) may also be specified by the
10876     implementation. The complete set of signals, their semantics, and their default handling
10877     is implementation-defined; all signal numbers shall be positive.
10878
10879
10880
10881
10882     247) See ''future library directions'' (7.30.6). The names of the signal numbers reflect the following terms
10883          (respectively): abort, floating-point exception, illegal instruction, interrupt, segmentation violation,
10884          and termination.
10885
10886 [page 264]
10887
10888     7.14.1 Specify signal handling
10889     7.14.1.1 The signal function
10890     Synopsis
10891 1           #include <signal.h>
10892             void (*signal(int sig, void (*func)(int)))(int);
10893     Description
10894 2   The signal function chooses one of three ways in which receipt of the signal number
10895     sig is to be subsequently handled. If the value of func is SIG_DFL, default handling
10896     for that signal will occur. If the value of func is SIG_IGN, the signal will be ignored.
10897     Otherwise, func shall point to a function to be called when that signal occurs. An
10898     invocation of such a function because of a signal, or (recursively) of any further functions
10899     called by that invocation (other than functions in the standard library),248) is called a
10900     signal handler.
10901 3   When a signal occurs and func points to a function, it is implementation-defined
10902     whether the equivalent of signal(sig, SIG_DFL); is executed or the
10903     implementation prevents some implementation-defined set of signals (at least including
10904     sig) from occurring until the current signal handling has completed; in the case of
10905     SIGILL, the implementation may alternatively define that no action is taken. Then the
10906     equivalent of (*func)(sig); is executed. If and when the function returns, if the
10907     value of sig is SIGFPE, SIGILL, SIGSEGV, or any other implementation-defined
10908     value corresponding to a computational exception, the behavior is undefined; otherwise
10909     the program will resume execution at the point it was interrupted.
10910 4   If the signal occurs as the result of calling the abort or raise function, the signal
10911     handler shall not call the raise function.
10912 5   If the signal occurs other than as the result of calling the abort or raise function, the
10913     behavior is undefined if the signal handler refers to any object with static or thread
10914     storage duration that is not a lock-free atomic object other than by assigning a value to an
10915     object declared as volatile sig_atomic_t, or the signal handler calls any function
10916     in the standard library other than the abort function, the _Exit function, the
10917     quick_exit function, or the signal function with the first argument equal to the
10918     signal number corresponding to the signal that caused the invocation of the handler.
10919     Furthermore, if such a call to the signal function results in a SIG_ERR return, the
10920     value of errno is indeterminate.249)
10921
10922
10923     248) This includes functions called indirectly via standard library functions (e.g., a SIGABRT handler
10924          called via the abort function).
10925     249) If any signal is generated by an asynchronous signal handler, the behavior is undefined.
10926
10927 [page 265]
10928
10929 6   At program startup, the equivalent of
10930            signal(sig, SIG_IGN);
10931     may be executed for some signals selected in an implementation-defined manner; the
10932     equivalent of
10933            signal(sig, SIG_DFL);
10934     is executed for all other signals defined by the implementation.
10935 7   The implementation shall behave as if no library function calls the signal function.
10936     Returns
10937 8   If the request can be honored, the signal function returns the value of func for the
10938     most recent successful call to signal for the specified signal sig. Otherwise, a value of
10939     SIG_ERR is returned and a positive value is stored in errno.
10940     Forward references: the abort function (7.22.4.1), the exit function (7.22.4.4), the
10941     _Exit function (7.22.4.5), the quick_exit function (7.22.4.7).
10942     7.14.2 Send signal
10943     7.14.2.1 The raise function
10944     Synopsis
10945 1          #include <signal.h>
10946            int raise(int sig);
10947     Description
10948 2   The raise function carries out the actions described in 7.14.1.1 for the signal sig. If a
10949     signal handler is called, the raise function shall not return until after the signal handler
10950     does.
10951     Returns
10952 3   The raise function returns zero if successful, nonzero if unsuccessful.
10953
10954
10955
10956
10957 [page 266]
10958
10959     7.15 Alignment <stdalign.h>
10960 1   The header <stdalign.h> defines two macros.
10961 2   The macro
10962             alignas
10963     expands to _Alignas.
10964 3   The remaining macro is suitable for use in #if preprocessing directives. It is
10965             __alignas_is_defined
10966     which expands to the integer constant 1.
10967
10968
10969
10970
10971 [page 267]
10972
10973     7.16 Variable arguments <stdarg.h>
10974 1   The header <stdarg.h> declares a type and defines four macros, for advancing
10975     through a list of arguments whose number and types are not known to the called function
10976     when it is translated.
10977 2   A function may be called with a variable number of arguments of varying types. As
10978     described in 6.9.1, its parameter list contains one or more parameters. The rightmost
10979     parameter plays a special role in the access mechanism, and will be designated parmN in
10980     this description.
10981 3   The type declared is
10982             va_list
10983     which is a complete object type suitable for holding information needed by the macros
10984     va_start, va_arg, va_end, and va_copy. If access to the varying arguments is
10985     desired, the called function shall declare an object (generally referred to as ap in this
10986     subclause) having type va_list. The object ap may be passed as an argument to
10987     another function; if that function invokes the va_arg macro with parameter ap, the
10988     value of ap in the calling function is indeterminate and shall be passed to the va_end
10989     macro prior to any further reference to ap.250)
10990     7.16.1 Variable argument list access macros
10991 1   The va_start and va_arg macros described in this subclause shall be implemented
10992     as macros, not functions. It is unspecified whether va_copy and va_end are macros or
10993     identifiers declared with external linkage. If a macro definition is suppressed in order to
10994     access an actual function, or a program defines an external identifier with the same name,
10995     the behavior is undefined. Each invocation of the va_start and va_copy macros
10996     shall be matched by a corresponding invocation of the va_end macro in the same
10997     function.
10998     7.16.1.1 The va_arg macro
10999     Synopsis
11000 1           #include <stdarg.h>
11001             type va_arg(va_list ap, type);
11002     Description
11003 2   The va_arg macro expands to an expression that has the specified type and the value of
11004     the next argument in the call. The parameter ap shall have been initialized by the
11005     va_start or va_copy macro (without an intervening invocation of the va_end
11006
11007     250) It is permitted to create a pointer to a va_list and pass that pointer to another function, in which
11008          case the original function may make further use of the original list after the other function returns.
11009
11010 [page 268]
11011
11012     macro for the same ap). Each invocation of the va_arg macro modifies ap so that the
11013     values of successive arguments are returned in turn. The parameter type shall be a type
11014     name specified such that the type of a pointer to an object that has the specified type can
11015     be obtained simply by postfixing a * to type. If there is no actual next argument, or if
11016     type is not compatible with the type of the actual next argument (as promoted according
11017     to the default argument promotions), the behavior is undefined, except for the following
11018     cases:
11019     -- one type is a signed integer type, the other type is the corresponding unsigned integer
11020       type, and the value is representable in both types;
11021     -- one type is pointer to void and the other is a pointer to a character type.
11022     Returns
11023 3   The first invocation of the va_arg macro after that of the va_start macro returns the
11024     value of the argument after that specified by parmN . Successive invocations return the
11025     values of the remaining arguments in succession.
11026     7.16.1.2 The va_copy macro
11027     Synopsis
11028 1           #include <stdarg.h>
11029             void va_copy(va_list dest, va_list src);
11030     Description
11031 2   The va_copy macro initializes dest as a copy of src, as if the va_start macro had
11032     been applied to dest followed by the same sequence of uses of the va_arg macro as
11033     had previously been used to reach the present state of src. Neither the va_copy nor
11034     va_start macro shall be invoked to reinitialize dest without an intervening
11035     invocation of the va_end macro for the same dest.
11036     Returns
11037 3   The va_copy macro returns no value.
11038     7.16.1.3 The va_end macro
11039     Synopsis
11040 1           #include <stdarg.h>
11041             void va_end(va_list ap);
11042     Description
11043 2   The va_end macro facilitates a normal return from the function whose variable
11044     argument list was referred to by the expansion of the va_start macro, or the function
11045     containing the expansion of the va_copy macro, that initialized the va_list ap. The
11046     va_end macro may modify ap so that it is no longer usable (without being reinitialized
11047
11048 [page 269]
11049
11050     by the va_start or va_copy macro). If there is no corresponding invocation of the
11051     va_start or va_copy macro, or if the va_end macro is not invoked before the
11052     return, the behavior is undefined.
11053     Returns
11054 3   The va_end macro returns no value.
11055     7.16.1.4 The va_start macro
11056     Synopsis
11057 1           #include <stdarg.h>
11058             void va_start(va_list ap, parmN);
11059     Description
11060 2   The va_start macro shall be invoked before any access to the unnamed arguments.
11061 3   The va_start macro initializes ap for subsequent use by the va_arg and va_end
11062     macros. Neither the va_start nor va_copy macro shall be invoked to reinitialize ap
11063     without an intervening invocation of the va_end macro for the same ap.
11064 4   The parameter parmN is the identifier of the rightmost parameter in the variable
11065     parameter list in the function definition (the one just before the , ...). If the parameter
11066     parmN is declared with the register storage class, with a function or array type, or
11067     with a type that is not compatible with the type that results after application of the default
11068     argument promotions, the behavior is undefined.
11069     Returns
11070 5   The va_start macro returns no value.
11071 6   EXAMPLE 1 The function f1 gathers into an array a list of arguments that are pointers to strings (but not
11072     more than MAXARGS arguments), then passes the array as a single argument to function f2. The number of
11073     pointers is specified by the first argument to f1.
11074             #include <stdarg.h>
11075             #define MAXARGS   31
11076             void f1(int n_ptrs, ...)
11077             {
11078                   va_list ap;
11079                   char *array[MAXARGS];
11080                   int ptr_no = 0;
11081
11082
11083
11084
11085 [page 270]
11086
11087                       if (n_ptrs > MAXARGS)
11088                             n_ptrs = MAXARGS;
11089                       va_start(ap, n_ptrs);
11090                       while (ptr_no < n_ptrs)
11091                             array[ptr_no++] = va_arg(ap, char *);
11092                       va_end(ap);
11093                       f2(n_ptrs, array);
11094              }
11095     Each call to f1 is required to have visible the definition of the function or a declaration such as
11096              void f1(int, ...);
11097
11098 7   EXAMPLE 2 The function f3 is similar, but saves the status of the variable argument list after the
11099     indicated number of arguments; after f2 has been called once with the whole list, the trailing part of the list
11100     is gathered again and passed to function f4.
11101              #include <stdarg.h>
11102              #define MAXARGS 31
11103              void f3(int n_ptrs, int f4_after, ...)
11104              {
11105                    va_list ap, ap_save;
11106                    char *array[MAXARGS];
11107                    int ptr_no = 0;
11108                    if (n_ptrs > MAXARGS)
11109                          n_ptrs = MAXARGS;
11110                    va_start(ap, f4_after);
11111                    while (ptr_no < n_ptrs) {
11112                          array[ptr_no++] = va_arg(ap, char *);
11113                          if (ptr_no == f4_after)
11114                                va_copy(ap_save, ap);
11115                    }
11116                    va_end(ap);
11117                    f2(n_ptrs, array);
11118                       // Now process the saved copy.
11119                       n_ptrs -= f4_after;
11120                       ptr_no = 0;
11121                       while (ptr_no < n_ptrs)
11122                             array[ptr_no++] = va_arg(ap_save, char *);
11123                       va_end(ap_save);
11124                       f4(n_ptrs, array);
11125              }
11126
11127
11128
11129
11130 [page 271]
11131
11132     7.17 Atomics <stdatomic.h>
11133     7.17.1 Introduction
11134 1   The header <stdatomic.h> defines several macros and declares several types and
11135     functions for performing atomic operations on data shared between threads.
11136 2   Implementations that define the macro __STDC_NO_THREADS__ need not provide
11137     this header nor support any of its facilities.
11138 3   The macros defined are the atomic lock-free macros
11139            ATOMIC_CHAR_LOCK_FREE
11140            ATOMIC_CHAR16_T_LOCK_FREE
11141            ATOMIC_CHAR32_T_LOCK_FREE
11142            ATOMIC_WCHAR_T_LOCK_FREE
11143            ATOMIC_SHORT_LOCK_FREE
11144            ATOMIC_INT_LOCK_FREE
11145            ATOMIC_LONG_LOCK_FREE
11146            ATOMIC_LLONG_LOCK_FREE
11147            ATOMIC_ADDRESS_LOCK_FREE
11148     which indicate the lock-free property of the corresponding atomic types (both signed and
11149     unsigned); and
11150            ATOMIC_FLAG_INIT
11151     which expands to an initializer for an object of type atomic_flag.
11152 4   The types include
11153            memory_order
11154     which is an enumerated type whose enumerators identify memory ordering constraints;
11155            atomic_flag
11156     which is a structure type representing a lock-free, primitive atomic flag;
11157            atomic_bool
11158     which is a structure type representing the atomic analog of the type _Bool;
11159            atomic_address
11160     which is a structure type representing the atomic analog of a pointer type; and several
11161     atomic analogs of integer types.
11162 5   In the following operation definitions:
11163     -- An A refers to one of the atomic types.
11164
11165
11166 [page 272]
11167
11168     -- A C refers to its corresponding non-atomic type. The atomic_address atomic
11169       type corresponds to the void * non-atomic type.
11170     -- An M refers to the type of the other argument for arithmetic operations. For atomic
11171       integer types, M is C. For atomic address types, M is ptrdiff_t.
11172     -- The functions not ending in _explicit have the same semantics as the
11173       corresponding _explicit function with memory_order_seq_cst for the
11174       memory_order argument.
11175 6   NOTE Many operations are volatile-qualified. The ''volatile as device register'' semantics have not
11176     changed in the standard. This qualification means that volatility is preserved when applying these
11177     operations to volatile objects.
11178
11179     7.17.2 Initialization
11180     7.17.2.1 The ATOMIC_VAR_INIT macro
11181     Synopsis
11182 1           #include <stdatomic.h>
11183             #define ATOMIC_VAR_INIT(C value)
11184     Description
11185 2   The ATOMIC_VAR_INIT macro expands to a token sequence suitable for initializing an
11186     atomic object of a type that is initialization-compatible with value. An atomic object
11187     with automatic storage duration that is not explicitly initialized using
11188     ATOMIC_VAR_INIT is initially in an indeterminate state; however, the default (zero)
11189     initialization for objects with static or thread-local storage duration is guaranteed to
11190     produce a valid state.
11191 3   Concurrent access to the variable being initialized, even via an atomic operation,
11192     constitutes a data race.
11193 4   EXAMPLE
11194             atomic_int guide = ATOMIC_VAR_INIT(42);
11195
11196     7.17.2.2 The atomic_init generic function
11197     Synopsis
11198 1           #include <stdatomic.h>
11199             void atomic_init(volatile A *obj, C value);
11200     Description
11201 2   The atomic_init generic function initializes the atomic object pointed to by obj to
11202     the value value, while also initializing any additional state that the implementation
11203     might need to carry for the atomic object.
11204
11205
11206
11207 [page 273]
11208
11209 3   Although this function initializes an atomic object, it does not avoid data races;
11210     concurrent access to the variable being initialized, even via an atomic operation,
11211     constitutes a data race.
11212     Returns
11213 4   The atomic_init generic function returns no value.
11214 5   EXAMPLE
11215             atomic_int guide;
11216             atomic_init(&guide, 42);
11217
11218     7.17.3 Order and consistency
11219 1   The enumerated type memory_order specifies the detailed regular (non-atomic)
11220     memory synchronization operations as defined in 5.1.2.4 and may provide for operation
11221     ordering. Its enumeration constants are as follows:
11222             memory_order_relaxed
11223             memory_order_consume
11224             memory_order_acquire
11225             memory_order_release
11226             memory_order_acq_rel
11227             memory_order_seq_cst
11228 2   For memory_order_relaxed, no operation orders memory.
11229 3   For       memory_order_release,       memory_order_acq_rel,             and
11230     memory_order_seq_cst, a store operation performs a release operation on the
11231     affected memory location.
11232 4   For       memory_order_acquire,       memory_order_acq_rel,             and
11233     memory_order_seq_cst, a load operation performs an acquire operation on the
11234     affected memory location.
11235 5   For memory_order_consume, a load operation performs a consume operation on the
11236     affected memory location.
11237 6   For memory_order_seq_cst, there shall be a single total order S on all operations,
11238     consistent with the ''happens before'' order and modification orders for all affected
11239     locations, such that each memory_order_seq_cst operation that loads a value
11240     observes either the last preceding modification according to this order S, or the result of
11241     an operation that is not memory_order_seq_cst.
11242 7   NOTE 1 Although it is not explicitly required that S include lock operations, it can always be extended to
11243     an order that does include lock and unlock operations, since the ordering between those is already included
11244     in the ''happens before'' ordering.
11245
11246 8   NOTE 2 Atomic operations specifying memory_order_relaxed are relaxed only with respect to
11247     memory ordering. Implementations must still guarantee that any given atomic access to a particular atomic
11248
11249 [page 274]
11250
11251      object be indivisible with respect to all other atomic accesses to that object.
11252
11253 9    For an atomic operation B that reads the value of an atomic object M, if there is a
11254      memory_order_seq_cst fence X sequenced before B, then B observes either the
11255      last memory_order_seq_cst modification of M preceding X in the total order S or
11256      a later modification of M in its modification order.
11257 10   For atomic operations A and B on an atomic object M, where A modifies M and B takes
11258      its value, if there is a memory_order_seq_cst fence X such that A is sequenced
11259      before X and B follows X in S, then B observes either the effects of A or a later
11260      modification of M in its modification order.
11261 11   For atomic operations A and B on an atomic object M, where A modifies M and B takes
11262      its value, if there are memory_order_seq_cst fences X and Y such that A is
11263      sequenced before X, Y is sequenced before B, and X precedes Y in S, then B observes
11264      either the effects of A or a later modification of M in its modification order.
11265 12   Atomic read-modify-write operations shall always read the last value (in the modification
11266      order) stored before the write associated with the read-modify-write operation.
11267 13   An atomic store shall only store a value that has been computed from constants and
11268      program input values by a finite sequence of program evaluations, such that each
11269      evaluation observes the values of variables as computed by the last prior assignment in
11270      the sequence.251) The ordering of evaluations in this sequence shall be such that
11271      -- If an evaluation B observes a value computed by A in a different thread, then B does
11272        not happen before A.
11273      -- If an evaluation A is included in the sequence, then all evaluations that assign to the
11274        same variable and happen before A are also included.
11275 14   NOTE 3 The second requirement disallows ''out-of-thin-air'', or ''speculative'' stores of atomics when
11276      relaxed atomics are used. Since unordered operations are involved, evaluations may appear in this
11277      sequence out of thread order. For example, with x and y initially zero,
11278               // Thread 1:
11279               r1 = atomic_load_explicit(&y, memory_order_relaxed);
11280               atomic_store_explicit(&x, r1, memory_order_relaxed);
11281
11282               // Thread 2:
11283               r2 = atomic_load_explicit(&x, memory_order_relaxed);
11284               atomic_store_explicit(&y, 42, memory_order_relaxed);
11285      is allowed to produce r1 == 42 && r2 == 42. The sequence of evaluations justifying this consists of:
11286
11287
11288
11289
11290      251) Among other implications, atomic variables shall not decay.
11291
11292 [page 275]
11293
11294              atomic_store_explicit(&y, 42,               memory_order_relaxed);
11295              r1 = atomic_load_explicit(&y,               memory_order_relaxed);
11296              atomic_store_explicit(&x, r1,               memory_order_relaxed);
11297              r2 = atomic_load_explicit(&x,               memory_order_relaxed);
11298      On the other hand,
11299              // Thread 1:
11300              r1 = atomic_load_explicit(&y, memory_order_relaxed);
11301              atomic_store_explicit(&x, r1, memory_order_relaxed);
11302
11303              // Thread 2:
11304              r2 = atomic_load_explicit(&x, memory_order_relaxed);
11305              atomic_store_explicit(&y, r2, memory_order_relaxed);
11306      is not allowed to produce r1 == 42 && r2 = 42, since there is no sequence of evaluations that results
11307      in the computation of 42. In the absence of ''relaxed'' operations and read-modify-write operations with
11308      weaker than memory_order_acq_rel ordering, the second requirement has no impact.
11309
11310      Recommended practice
11311 15   The requirements do not forbid r1 == 42 && r2 == 42 in the following example,
11312      with x and y initially zero:
11313              // Thread 1:
11314              r1 = atomic_load_explicit(&x, memory_order_relaxed);
11315              if (r1 == 42)
11316                   atomic_store_explicit(&y, r1, memory_order_relaxed);
11317
11318              // Thread 2:
11319              r2 = atomic_load_explicit(&y, memory_order_relaxed);
11320              if (r2 == 42)
11321                   atomic_store_explicit(&x, 42, memory_order_relaxed);
11322      However, this is not useful behavior, and implementations should not allow it.
11323 16   Implementations should make atomic stores visible to atomic loads within a reasonable
11324      amount of time.
11325      7.17.3.1 The kill_dependency macro
11326      Synopsis
11327 1            #include <stdatomic.h>
11328              type kill_dependency(type y);
11329      Description
11330 2    The kill_dependency macro terminates a dependency chain; the argument does not
11331      carry a dependency to the return value.
11332
11333
11334
11335 [page 276]
11336
11337     Returns
11338 3   The kill_dependency macro returns the value of y.
11339     7.17.4 Fences
11340 1   This subclause introduces synchronization primitives called fences. Fences can have
11341     acquire semantics, release semantics, or both. A fence with acquire semantics is called
11342     an acquire fence; a fence with release semantics is called a release fence.
11343 2   A release fence A synchronizes with an acquire fence B if there exist atomic operations
11344     X and Y , both operating on some atomic object M, such that A is sequenced before X, X
11345     modifies M, Y is sequenced before B, and Y reads the value written by X or a value
11346     written by any side effect in the hypothetical release sequence X would head if it were a
11347     release operation.
11348 3   A release fence A synchronizes with an atomic operation B that performs an acquire
11349     operation on an atomic object M if there exists an atomic operation X such that A is
11350     sequenced before X, X modifies M, and B reads the value written by X or a value written
11351     by any side effect in the hypothetical release sequence X would head if it were a release
11352     operation.
11353 4   An atomic operation A that is a release operation on an atomic object M synchronizes
11354     with an acquire fence B if there exists some atomic operation X on M such that X is
11355     sequenced before B and reads the value written by A or a value written by any side effect
11356     in the release sequence headed by A.
11357     7.17.4.1 The atomic_thread_fence function
11358     Synopsis
11359 1           #include <stdatomic.h>
11360             void atomic_thread_fence(memory_order order);
11361     Description
11362 2   Depending on the value of order, this operation:
11363     -- has no effects, if order == memory_order_relaxed;
11364     -- is an acquire fence, if order == memory_order_acquire or order ==
11365       memory_order_consume;
11366     -- is a release fence, if order == memory_order_release;
11367     -- is both an acquire fence              and   a    release   fence,    if   order     ==
11368       memory_order_acq_rel;
11369     -- is a sequentially consistent acquire and release fence, if order                    ==
11370       memory_order_seq_cst.
11371
11372
11373 [page 277]
11374
11375     Returns
11376 3   The atomic_thread_fence function returns no value.
11377     7.17.4.2 The atomic_signal_fence function
11378     Synopsis
11379 1           #include <stdatomic.h>
11380             void atomic_signal_fence(memory_order order);
11381     Description
11382 2   Equivalent to atomic_thread_fence(order), except that ''synchronizes with''
11383     relationships are established only between a thread and a signal handler executed in the
11384     same thread.
11385 3   NOTE 1 The atomic_signal_fence function can be used to specify the order in which actions
11386     performed by the thread become visible to the signal handler.
11387
11388 4   NOTE 2 Compiler optimizations and reorderings of loads and stores are inhibited in the same way as with
11389     atomic_thread_fence, but the hardware fence instructions that atomic_thread_fence would
11390     have inserted are not emitted.
11391
11392     Returns
11393 5   The atomic_signal_fence function returns no value.
11394     7.17.5 Lock-free property
11395 1   The atomic lock-free macros indicate the lock-free property of integer and address atomic
11396     types. A value of 0 indicates that the type is never lock-free; a value of 1 indicates that
11397     the type is sometimes lock-free; a value of 2 indicates that the type is always lock-free.
11398 2   NOTE Operations that are lock-free should also be address-free. That is, atomic operations on the same
11399     memory location via two different addresses will communicate atomically. The implementation should not
11400     depend on any per-process state. This restriction enables communication via memory mapped into a
11401     process more than once and memory shared between two processes.
11402
11403     7.17.5.1 The atomic_is_lock_free generic function
11404     Synopsis
11405 1           #include <stdatomic.h>
11406             _Bool atomic_is_lock_free(atomic_type const volatile *obj);
11407     Description
11408 2   The atomic_is_lock_free generic function indicates whether or not the object
11409     pointed to by obj is lock-free. atomic_type can be any atomic type.
11410     Returns
11411 3   The atomic_is_lock_free generic function returns nonzero (true) if and only if the
11412     object's operations are lock-free. The result of a lock-free query on one object cannot be
11413
11414 [page 278]
11415
11416     inferred from the result of a lock-free query on another object.
11417     7.17.6 Atomic integer and address types
11418 1   For each line in the following table, the atomic type name is declared as the
11419     corresponding direct type.
11420
11421
11422
11423
11424 [page 279]
11425
11426                Atomic type name                              Direct type
11427            atomic_char                           _Atomic    char
11428            atomic_schar                          _Atomic    signed char
11429            atomic_uchar                          _Atomic    unsigned char
11430            atomic_short                          _Atomic    short
11431            atomic_ushort                         _Atomic    unsigned short
11432            atomic_int                            _Atomic    int
11433            atomic_uint                           _Atomic    unsigned int
11434            atomic_long                           _Atomic    long
11435            atomic_ulong                          _Atomic    unsigned long
11436            atomic_llong                          _Atomic    long long
11437            atomic_ullong                         _Atomic    unsigned long long
11438            atomic_char16_t                       _Atomic    char16_t
11439            atomic_char32_t                       _Atomic    char32_t
11440            atomic_wchar_t                        _Atomic    wchar_t
11441            atomic_int_least8_t                   _Atomic    int_least8_t
11442            atomic_uint_least8_t                  _Atomic    uint_least8_t
11443            atomic_int_least16_t                  _Atomic    int_least16_t
11444            atomic_uint_least16_t                 _Atomic    uint_least16_t
11445            atomic_int_least32_t                  _Atomic    int_least32_t
11446            atomic_uint_least32_t                 _Atomic    uint_least32_t
11447            atomic_int_least64_t                  _Atomic    int_least64_t
11448            atomic_uint_least64_t                 _Atomic    uint_least64_t
11449            atomic_int_fast8_t                    _Atomic    int_fast8_t
11450            atomic_uint_fast8_t                   _Atomic    uint_fast8_t
11451            atomic_int_fast16_t                   _Atomic    int_fast16_t
11452            atomic_uint_fast16_t                  _Atomic    uint_fast16_t
11453            atomic_int_fast32_t                   _Atomic    int_fast32_t
11454            atomic_uint_fast32_t                  _Atomic    uint_fast32_t
11455            atomic_int_fast64_t                   _Atomic    int_fast64_t
11456            atomic_uint_fast64_t                  _Atomic    uint_fast64_t
11457            atomic_intptr_t                       _Atomic    intptr_t
11458            atomic_uintptr_t                      _Atomic    uintptr_t
11459            atomic_size_t                         _Atomic    size_t
11460            atomic_ptrdiff_t                      _Atomic    ptrdiff_t
11461            atomic_intmax_t                       _Atomic    intmax_t
11462            atomic_uintmax_t                      _Atomic    uintmax_t
11463 2   The semantics of the operations on these types are defined in 7.17.7.
11464 3   The atomic_bool type provides an atomic boolean.
11465
11466
11467 [page 280]
11468
11469 4   The atomic_address type provides atomic void * operations. The unit of
11470     addition/subtraction shall be one byte.
11471 5   NOTE The representation of atomic integer and address types need not have the same size as their
11472     corresponding regular types. They should have the same size whenever possible, as it eases effort required
11473     to port existing code.
11474
11475     7.17.7 Operations on atomic types
11476 1   There are only a few kinds of operations on atomic types, though there are many
11477     instances of those kinds. This subclause specifies each general kind.
11478     7.17.7.1 The atomic_store generic functions
11479     Synopsis
11480 1           #include <stdatomic.h>
11481             void atomic_store(volatile A *object, C desired);
11482             void atomic_store_explicit(volatile A *object,
11483                  C desired, memory_order order);
11484     Description
11485 2   The      order      argument    shall    not    be    memory_order_acquire,
11486     memory_order_consume, nor memory_order_acq_rel. Atomically replace the
11487     value pointed to by object with the value of desired. Memory is affected according
11488     to the value of order.
11489     Returns
11490 3   The atomic_store generic functions return no value.
11491     7.17.7.2 The atomic_load generic functions
11492     Synopsis
11493 1           #include <stdatomic.h>
11494             C atomic_load(volatile A *object);
11495             C atomic_load_explicit(volatile A *object,
11496                  memory_order order);
11497     Description
11498 2   The order argument shall not be memory_order_release nor
11499     memory_order_acq_rel. Memory is affected according to the value of order.
11500     Returns
11501     Atomically returns the value pointed to by object.
11502
11503
11504
11505
11506 [page 281]
11507
11508     7.17.7.3 The atomic_exchange generic functions
11509     Synopsis
11510 1            #include <stdatomic.h>
11511              C atomic_exchange(volatile A *object, C desired);
11512              C atomic_exchange_explicit(volatile A *object,
11513                   C desired, memory_order order);
11514     Description
11515 2   Atomically replace the value pointed to by object with desired. Memory is affected
11516     according to the value of order. These operations are read-modify-write operations
11517     (5.1.2.4).
11518     Returns
11519 3   Atomically returns the value pointed to by object immediately before the effects.
11520     7.17.7.4 The atomic_compare_exchange generic functions
11521     Synopsis
11522 1            #include <stdatomic.h>
11523              _Bool atomic_compare_exchange_strong(volatile A *object,
11524                   C *expected, C desired);
11525              _Bool atomic_compare_exchange_strong_explicit(
11526                   volatile A *object, C *expected, C desired,
11527                   memory_order success, memory_order failure);
11528              _Bool atomic_compare_exchange_weak(volatile A *object,
11529                   C *expected, C desired);
11530              _Bool atomic_compare_exchange_weak_explicit(
11531                   volatile A *object, C *expected, C desired,
11532                   memory_order success, memory_order failure);
11533     Description
11534 2   The failure argument shall not be memory_order_release nor
11535     memory_order_acq_rel. The failure argument shall be no stronger than the
11536     success argument. Atomically, compares the value pointed to by object for equality
11537     with that in expected, and if true, replaces the value pointed to by object with
11538     desired, and if false, updates the value in expected with the value pointed to by
11539     object. Further, if the comparison is true, memory is affected according to the value of
11540     success, and if the comparison is false, memory is affected according to the value of
11541     failure. These operations are atomic read-modify-write operations (5.1.2.4).
11542 3   NOTE 1    The effect of the compare-and-exchange operations is
11543
11544
11545
11546
11547 [page 282]
11548
11549              if (*object == *expected)
11550                    *object = desired;
11551              else
11552                    *expected = *object;
11553
11554 4   The weak compare-and-exchange operations may fail spuriously, that is, return zero
11555     while leaving the value pointed to by expected unchanged.
11556 5   NOTE 2 This spurious failure enables implementation of compare-and-exchange on a broader class of
11557     machines, e.g. load-locked store-conditional machines.
11558
11559 6   EXAMPLE         A consequence of spurious failure is that nearly all uses of weak compare-and-exchange will
11560     be in a loop.
11561              exp = atomic_load(&cur);
11562              do {
11563                    des = function(exp);
11564              } while (!atomic_compare_exchange_weak(&cur, &exp, des));
11565     When a compare-and-exchange is in a loop, the weak version will yield better performance on some
11566     platforms. When a weak compare-and-exchange would require a loop and a strong one would not, the
11567     strong one is preferable.
11568
11569     Returns
11570 7   The result of the comparison.
11571     7.17.7.5 The atomic_fetch and modify generic functions
11572 1   The following operations perform arithmetic and bitwise computations. All of these
11573     operations are applicable to an object of any atomic integer type. Only addition and
11574     subtraction are applicable to atomic_address. None of these operations is applicable
11575     to atomic_bool. The key, operator, and computation correspondence is:
11576      key            op          computation
11577      add            +       addition
11578      sub            -       subtraction
11579      or             |       bitwise inclusive or
11580      xor            ^       bitwise exclusive or
11581      and            &       bitwise and
11582     Synopsis
11583 2            #include <stdatomic.h>
11584              C atomic_fetch_key(volatile A *object, M operand);
11585              C atomic_fetch_key_explicit(volatile A *object,
11586                   M operand, memory_order order);
11587     Description
11588 3   Atomically replaces the value pointed to by object with the result of the computation
11589     applied to the value pointed to by object and the given operand. Memory is affected
11590     according to the value of order. These operations are atomic read-modify-write
11591 [page 283]
11592
11593     operations (5.1.2.4). For signed integer types, arithmetic is defined to use two's
11594     complement representation with silent wrap-around on overflow; there are no undefined
11595     results. For address types, the result may be an undefined address, but the operations
11596     otherwise have no undefined behavior.
11597     Returns
11598 4   Atomically, the value pointed to by object immediately before the effects.
11599 5   NOTE The operation of the atomic_fetch and modify generic functions are nearly equivalent to the
11600     operation of the corresponding op= compound assignment operators. The only differences are that the
11601     compound assignment operators are not guaranteed to operate atomically, and the value yielded by a
11602     compound assignment operator is the updated value of the object, whereas the value returned by the
11603     atomic_fetch and modify generic functions is the previous value of the atomic object.
11604
11605     7.17.8 Atomic flag type and operations
11606 1   The atomic_flag type provides the classic test-and-set functionality. It has two
11607     states, set and clear.
11608 2   Operations on an object of type atomic_flag shall be lock free.
11609 3   NOTE Hence the operations should also be address-free. No other type requires lock-free operations, so
11610     the atomic_flag type is the minimum hardware-implemented type needed to conform to this
11611     International standard. The remaining types can be emulated with atomic_flag, though with less than
11612     ideal properties.
11613
11614 4   The macro ATOMIC_FLAG_INIT may be used to initialize an atomic_flag to the
11615     clear state. An atomic_flag that is not explicitly initialized with
11616     ATOMIC_FLAG_INIT is initially in an indeterminate state.
11617 5   EXAMPLE
11618             atomic_flag guard = ATOMIC_FLAG_INIT;
11619
11620     7.17.8.1 The atomic_flag_test_and_set functions
11621     Synopsis
11622 1           #include <stdatomic.h>
11623             bool atomic_flag_test_and_set(
11624                  volatile atomic_flag *object);
11625             bool atomic_flag_test_and_set_explicit(
11626                  volatile atomic_flag *object, memory_order order);
11627     Description
11628 2   Atomically sets the value pointed to by object to true. Memory is affected according
11629     to the value of order. These operations are atomic read-modify-write operations
11630     (5.1.2.4).
11631
11632
11633
11634
11635 [page 284]
11636
11637     Returns
11638 3   Atomically, the value of the object immediately before the effects.
11639     7.17.8.2 The atomic_flag_clear functions
11640     Synopsis
11641 1           #include <stdatomic.h>
11642             void atomic_flag_clear(volatile atomic_flag *object);
11643             void atomic_flag_clear_explicit(
11644                  volatile atomic_flag *object, memory_order order);
11645     Description
11646 2   The order argument shall not be memory_order_acquire nor
11647     memory_order_acq_rel. Atomically sets the value pointed to by object to false.
11648     Memory is affected according to the value of order.
11649     Returns
11650 3   The atomic_flag_clear functions return no value.
11651
11652
11653
11654
11655 [page 285]
11656
11657     7.18 Boolean type and values <stdbool.h>
11658 1   The header <stdbool.h> defines four macros.
11659 2   The macro
11660              bool
11661     expands to _Bool.
11662 3   The remaining three macros are suitable for use in #if preprocessing directives. They
11663     are
11664              true
11665     which expands to the integer constant 1,
11666              false
11667     which expands to the integer constant 0, and
11668              __bool_true_false_are_defined
11669     which expands to the integer constant 1.
11670 4   Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then
11671     redefine the macros bool, true, and false.252)
11672
11673
11674
11675
11676     252) See ''future library directions'' (7.30.7).
11677
11678 [page 286]
11679
11680     7.19 Common definitions <stddef.h>
11681 1   The header <stddef.h> defines the following macros and declares the following types.
11682     Some are also defined in other headers, as noted in their respective subclauses.
11683 2   The types are
11684             ptrdiff_t
11685     which is the signed integer type of the result of subtracting two pointers;
11686             size_t
11687     which is the unsigned integer type of the result of the sizeof operator;
11688             max_align_t
11689     which is an object type whose alignment is as great as is supported by the implementation
11690     in all contexts; and
11691             wchar_t
11692     which is an integer type whose range of values can represent distinct codes for all
11693     members of the largest extended character set specified among the supported locales; the
11694     null character shall have the code value zero. Each member of the basic character set
11695     shall have a code value equal to its value when used as the lone character in an integer
11696     character      constant     if     an      implementation      does      not      define
11697     __STDC_MB_MIGHT_NEQ_WC__.
11698 3   The macros are
11699             NULL
11700     which expands to an implementation-defined null pointer constant; and
11701             offsetof(type, member-designator)
11702     which expands to an integer constant expression that has type size_t, the value of
11703     which is the offset in bytes, to the structure member (designated by member-designator),
11704     from the beginning of its structure (designated by type). The type and member designator
11705     shall be such that given
11706             static type t;
11707     then the expression &(t.member-designator) evaluates to an address constant. (If the
11708     specified member is a bit-field, the behavior is undefined.)
11709     Recommended practice
11710 4   The types used for size_t and ptrdiff_t should not have an integer conversion rank
11711     greater than that of signed long int unless the implementation supports objects
11712     large enough to make this necessary.
11713
11714 [page 287]
11715
11716 Forward references: localization (7.11).
11717
11718
11719
11720
11721 [page 288]
11722
11723     7.20 Integer types <stdint.h>
11724 1   The header <stdint.h> declares sets of integer types having specified widths, and
11725     defines corresponding sets of macros.253) It also defines macros that specify limits of
11726     integer types corresponding to types defined in other standard headers.
11727 2   Types are defined in the following categories:
11728     -- integer types having certain exact widths;
11729     -- integer types having at least certain specified widths;
11730     -- fastest integer types having at least certain specified widths;
11731     -- integer types wide enough to hold pointers to objects;
11732     -- integer types having greatest width.
11733     (Some of these types may denote the same type.)
11734 3   Corresponding macros specify limits of the declared types and construct suitable
11735     constants.
11736 4   For each type described herein that the implementation provides,254) <stdint.h> shall
11737     declare that typedef name and define the associated macros. Conversely, for each type
11738     described herein that the implementation does not provide, <stdint.h> shall not
11739     declare that typedef name nor shall it define the associated macros. An implementation
11740     shall provide those types described as ''required'', but need not provide any of the others
11741     (described as ''optional'').
11742     7.20.1 Integer types
11743 1   When typedef names differing only in the absence or presence of the initial u are defined,
11744     they shall denote corresponding signed and unsigned types as described in 6.2.5; an
11745     implementation providing one of these corresponding types shall also provide the other.
11746 2   In the following descriptions, the symbol N represents an unsigned decimal integer with
11747     no leading zeros (e.g., 8 or 24, but not 04 or 048).
11748
11749
11750
11751
11752     253) See ''future library directions'' (7.30.8).
11753     254) Some of these types may denote implementation-defined extended integer types.
11754
11755 [page 289]
11756
11757     7.20.1.1 Exact-width integer types
11758 1   The typedef name intN_t designates a signed integer type with width N , no padding
11759     bits, and a two's complement representation. Thus, int8_t denotes such a signed
11760     integer type with a width of exactly 8 bits.
11761 2   The typedef name uintN_t designates an unsigned integer type with width N and no
11762     padding bits. Thus, uint24_t denotes such an unsigned integer type with a width of
11763     exactly 24 bits.
11764 3   These types are optional. However, if an implementation provides integer types with
11765     widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a
11766     two's complement representation, it shall define the corresponding typedef names.
11767     7.20.1.2 Minimum-width integer types
11768 1   The typedef name int_leastN_t designates a signed integer type with a width of at
11769     least N , such that no signed integer type with lesser size has at least the specified width.
11770     Thus, int_least32_t denotes a signed integer type with a width of at least 32 bits.
11771 2   The typedef name uint_leastN_t designates an unsigned integer type with a width
11772     of at least N , such that no unsigned integer type with lesser size has at least the specified
11773     width. Thus, uint_least16_t denotes an unsigned integer type with a width of at
11774     least 16 bits.
11775 3   The following types are required:
11776              int_least8_t                                      uint_least8_t
11777              int_least16_t                                     uint_least16_t
11778              int_least32_t                                     uint_least32_t
11779              int_least64_t                                     uint_least64_t
11780     All other types of this form are optional.
11781     7.20.1.3 Fastest minimum-width integer types
11782 1   Each of the following types designates an integer type that is usually fastest255) to operate
11783     with among all integer types that have at least the specified width.
11784 2   The typedef name int_fastN_t designates the fastest signed integer type with a width
11785     of at least N . The typedef name uint_fastN_t designates the fastest unsigned integer
11786     type with a width of at least N .
11787
11788
11789
11790
11791     255) The designated type is not guaranteed to be fastest for all purposes; if the implementation has no clear
11792          grounds for choosing one type over another, it will simply pick some integer type satisfying the
11793          signedness and width requirements.
11794
11795 [page 290]
11796
11797 3   The following types are required:
11798             int_fast8_t                                    uint_fast8_t
11799             int_fast16_t                                   uint_fast16_t
11800             int_fast32_t                                   uint_fast32_t
11801             int_fast64_t                                   uint_fast64_t
11802     All other types of this form are optional.
11803     7.20.1.4 Integer types capable of holding object pointers
11804 1   The following type designates a signed integer type with the property that any valid
11805     pointer to void can be converted to this type, then converted back to pointer to void,
11806     and the result will compare equal to the original pointer:
11807             intptr_t
11808     The following type designates an unsigned integer type with the property that any valid
11809     pointer to void can be converted to this type, then converted back to pointer to void,
11810     and the result will compare equal to the original pointer:
11811             uintptr_t
11812     These types are optional.
11813     7.20.1.5 Greatest-width integer types
11814 1   The following type designates a signed integer type capable of representing any value of
11815     any signed integer type:
11816             intmax_t
11817     The following type designates an unsigned integer type capable of representing any value
11818     of any unsigned integer type:
11819             uintmax_t
11820     These types are required.
11821     7.20.2 Limits of specified-width integer types
11822 1   The following object-like macros specify the minimum and maximum limits of the types *
11823     declared in <stdint.h>. Each macro name corresponds to a similar type name in
11824     7.20.1.
11825 2   Each instance of any defined macro shall be replaced by a constant expression suitable
11826     for use in #if preprocessing directives, and this expression shall have the same type as
11827     would an expression that is an object of the corresponding type converted according to
11828     the integer promotions. Its implementation-defined value shall be equal to or greater in
11829     magnitude (absolute value) than the corresponding value given below, with the same sign,
11830     except where stated to be exactly the given value.
11831
11832 [page 291]
11833
11834     7.20.2.1 Limits of exact-width integer types
11835 1   -- minimum values of exact-width signed integer types
11836           INTN_MIN                                  exactly -(2 N -1 )
11837     -- maximum values of exact-width signed integer types
11838           INTN_MAX                                  exactly 2 N -1 - 1
11839     -- maximum values of exact-width unsigned integer types
11840        UINTN_MAX                                    exactly 2 N - 1
11841     7.20.2.2 Limits of minimum-width integer types
11842 1   -- minimum values of minimum-width signed integer types
11843           INT_LEASTN_MIN                                    -(2 N -1 - 1)
11844     -- maximum values of minimum-width signed integer types
11845           INT_LEASTN_MAX                                    2 N -1 - 1
11846     -- maximum values of minimum-width unsigned integer types
11847        UINT_LEASTN_MAX                                      2N - 1
11848     7.20.2.3 Limits of fastest minimum-width integer types
11849 1   -- minimum values of fastest minimum-width signed integer types
11850           INT_FASTN_MIN                                     -(2 N -1 - 1)
11851     -- maximum values of fastest minimum-width signed integer types
11852        INT_FASTN_MAX                                        2 N -1 - 1
11853     -- maximum values of fastest minimum-width unsigned integer types
11854        UINT_FASTN_MAX                                       2N - 1
11855     7.20.2.4 Limits of integer types capable of holding object pointers
11856 1   -- minimum value of pointer-holding signed integer type
11857           INTPTR_MIN                                        -(215 - 1)
11858     -- maximum value of pointer-holding signed integer type
11859        INTPTR_MAX                                           215 - 1
11860     -- maximum value of pointer-holding unsigned integer type
11861        UINTPTR_MAX                                          216 - 1
11862
11863
11864
11865 [page 292]
11866
11867     7.20.2.5 Limits of greatest-width integer types
11868 1   -- minimum value of greatest-width signed integer type
11869         INTMAX_MIN                                                    -(263 - 1)
11870     -- maximum value of greatest-width signed integer type
11871         INTMAX_MAX                                                    263 - 1
11872     -- maximum value of greatest-width unsigned integer type
11873         UINTMAX_MAX                                                   264 - 1
11874     7.20.3 Limits of other integer types
11875 1   The following object-like macros specify the minimum and maximum limits of integer *
11876     types corresponding to types defined in other standard headers.
11877 2   Each instance of these macros shall be replaced by a constant expression suitable for use
11878     in #if preprocessing directives, and this expression shall have the same type as would an
11879     expression that is an object of the corresponding type converted according to the integer
11880     promotions. Its implementation-defined value shall be equal to or greater in magnitude
11881     (absolute value) than the corresponding value given below, with the same sign. An
11882     implementation shall define only the macros corresponding to those typedef names it
11883     actually provides.256)
11884     -- limits of ptrdiff_t
11885         PTRDIFF_MIN                                                 -65535
11886         PTRDIFF_MAX                                                 +65535
11887     -- limits of sig_atomic_t
11888         SIG_ATOMIC_MIN                                              see below
11889         SIG_ATOMIC_MAX                                              see below
11890     -- limit of size_t
11891         SIZE_MAX                                                      65535
11892     -- limits of wchar_t
11893         WCHAR_MIN                                                   see below
11894         WCHAR_MAX                                                   see below
11895     -- limits of wint_t
11896
11897
11898
11899
11900     256) A freestanding implementation need not provide all of these types.
11901
11902 [page 293]
11903
11904         WINT_MIN                                              see below
11905         WINT_MAX                                              see below
11906 3   If sig_atomic_t (see 7.14) is defined as a signed integer type, the value of
11907     SIG_ATOMIC_MIN shall be no greater than -127 and the value of SIG_ATOMIC_MAX
11908     shall be no less than 127; otherwise, sig_atomic_t is defined as an unsigned integer
11909     type, and the value of SIG_ATOMIC_MIN shall be 0 and the value of
11910     SIG_ATOMIC_MAX shall be no less than 255.
11911 4   If wchar_t (see 7.19) is defined as a signed integer type, the value of WCHAR_MIN
11912     shall be no greater than -127 and the value of WCHAR_MAX shall be no less than 127;
11913     otherwise, wchar_t is defined as an unsigned integer type, and the value of
11914     WCHAR_MIN shall be 0 and the value of WCHAR_MAX shall be no less than 255.257)
11915 5   If wint_t (see 7.28) is defined as a signed integer type, the value of WINT_MIN shall
11916     be no greater than -32767 and the value of WINT_MAX shall be no less than 32767;
11917     otherwise, wint_t is defined as an unsigned integer type, and the value of WINT_MIN
11918     shall be 0 and the value of WINT_MAX shall be no less than 65535.
11919     7.20.4 Macros for integer constants
11920 1   The following function-like macros expand to integer constants suitable for initializing *
11921     objects that have integer types corresponding to types defined in <stdint.h>. Each
11922     macro name corresponds to a similar type name in 7.20.1.2 or 7.20.1.5.
11923 2   The argument in any instance of these macros shall be an unsuffixed integer constant (as
11924     defined in 6.4.4.1) with a value that does not exceed the limits for the corresponding type.
11925 3   Each invocation of one of these macros shall expand to an integer constant expression
11926     suitable for use in #if preprocessing directives. The type of the expression shall have
11927     the same type as would an expression of the corresponding type converted according to
11928     the integer promotions. The value of the expression shall be that of the argument.
11929     7.20.4.1 Macros for minimum-width integer constants
11930 1   The macro INTN_C(value) shall expand to an integer constant expression
11931     corresponding to the type int_leastN_t. The macro UINTN_C(value) shall expand
11932     to an integer constant expression corresponding to the type uint_leastN_t. For
11933     example, if uint_least64_t is a name for the type unsigned long long int,
11934     then UINT64_C(0x123) might expand to the integer constant 0x123ULL.
11935
11936
11937
11938
11939     257) The values WCHAR_MIN and WCHAR_MAX do not necessarily correspond to members of the extended
11940          character set.
11941
11942 [page 294]
11943
11944     7.20.4.2 Macros for greatest-width integer constants
11945 1   The following macro expands to an integer constant expression having the value specified
11946     by its argument and the type intmax_t:
11947             INTMAX_C(value)
11948     The following macro expands to an integer constant expression having the value specified
11949     by its argument and the type uintmax_t:
11950             UINTMAX_C(value)
11951
11952
11953
11954
11955 [page 295]
11956
11957     7.21 Input/output <stdio.h>
11958     7.21.1 Introduction
11959 1   The header <stdio.h> defines several macros, and declares three types and many
11960     functions for performing input and output.
11961 2   The types declared are size_t (described in 7.19);
11962            FILE
11963     which is an object type capable of recording all the information needed to control a
11964     stream, including its file position indicator, a pointer to its associated buffer (if any), an
11965     error indicator that records whether a read/write error has occurred, and an end-of-file
11966     indicator that records whether the end of the file has been reached; and
11967            fpos_t
11968     which is a complete object type other than an array type capable of recording all the
11969     information needed to specify uniquely every position within a file.
11970 3   The macros are NULL (described in 7.19);
11971            _IOFBF
11972            _IOLBF
11973            _IONBF
11974     which expand to integer constant expressions with distinct values, suitable for use as the
11975     third argument to the setvbuf function;
11976            BUFSIZ
11977     which expands to an integer constant expression that is the size of the buffer used by the
11978     setbuf function;
11979            EOF
11980     which expands to an integer constant expression, with type int and a negative value, that
11981     is returned by several functions to indicate end-of-file, that is, no more input from a
11982     stream;
11983            FOPEN_MAX
11984     which expands to an integer constant expression that is the minimum number of files that
11985     the implementation guarantees can be open simultaneously;
11986            FILENAME_MAX
11987     which expands to an integer constant expression that is the size needed for an array of
11988     char large enough to hold the longest file name string that the implementation
11989
11990
11991
11992 [page 296]
11993
11994     guarantees can be opened;258)
11995             L_tmpnam
11996     which expands to an integer constant expression that is the size needed for an array of
11997     char large enough to hold a temporary file name string generated by the tmpnam
11998     function;
11999             SEEK_CUR
12000             SEEK_END
12001             SEEK_SET
12002     which expand to integer constant expressions with distinct values, suitable for use as the
12003     third argument to the fseek function;
12004             TMP_MAX
12005     which expands to an integer constant expression that is the minimum number of unique
12006     file names that can be generated by the tmpnam function;
12007             stderr
12008             stdin
12009             stdout
12010     which are expressions of type ''pointer to FILE'' that point to the FILE objects
12011     associated, respectively, with the standard error, input, and output streams.
12012 4   The header <wchar.h> declares a number of functions useful for wide character input
12013     and output. The wide character input/output functions described in that subclause
12014     provide operations analogous to most of those described here, except that the
12015     fundamental units internal to the program are wide characters. The external
12016     representation (in the file) is a sequence of ''generalized'' multibyte characters, as
12017     described further in 7.21.3.
12018 5   The input/output functions are given the following collective terms:
12019     -- The wide character input functions -- those functions described in 7.28 that perform
12020       input into wide characters and wide strings: fgetwc, fgetws, getwc, getwchar,
12021       fwscanf, wscanf, vfwscanf, and vwscanf.
12022     -- The wide character output functions -- those functions described in 7.28 that perform
12023       output from wide characters and wide strings: fputwc, fputws, putwc,
12024       putwchar, fwprintf, wprintf, vfwprintf, and vwprintf.
12025
12026
12027     258) If the implementation imposes no practical limit on the length of file name strings, the value of
12028          FILENAME_MAX should instead be the recommended size of an array intended to hold a file name
12029          string. Of course, file name string contents are subject to other system-specific constraints; therefore
12030          all possible strings of length FILENAME_MAX cannot be expected to be opened successfully.
12031
12032 [page 297]
12033
12034     -- The wide character input/output functions -- the union of the ungetwc function, the
12035       wide character input functions, and the wide character output functions.
12036     -- The byte input/output functions -- those functions described in this subclause that
12037       perform input/output: fgetc, fgets, fprintf, fputc, fputs, fread,
12038       fscanf, fwrite, getc, getchar, printf, putc, putchar, puts, scanf, *
12039       ungetc, vfprintf, vfscanf, vprintf, and vscanf.
12040     Forward references: files (7.21.3), the fseek function (7.21.9.2), streams (7.21.2), the
12041     tmpnam function (7.21.4.4), <wchar.h> (7.28).
12042     7.21.2 Streams
12043 1   Input and output, whether to or from physical devices such as terminals and tape drives,
12044     or whether to or from files supported on structured storage devices, are mapped into
12045     logical data streams, whose properties are more uniform than their various inputs and
12046     outputs. Two forms of mapping are supported, for text streams and for binary
12047     streams.259)
12048 2   A text stream is an ordered sequence of characters composed into lines, each line
12049     consisting of zero or more characters plus a terminating new-line character. Whether the
12050     last line requires a terminating new-line character is implementation-defined. Characters
12051     may have to be added, altered, or deleted on input and output to conform to differing
12052     conventions for representing text in the host environment. Thus, there need not be a one-
12053     to-one correspondence between the characters in a stream and those in the external
12054     representation. Data read in from a text stream will necessarily compare equal to the data
12055     that were earlier written out to that stream only if: the data consist only of printing
12056     characters and the control characters horizontal tab and new-line; no new-line character is
12057     immediately preceded by space characters; and the last character is a new-line character.
12058     Whether space characters that are written out immediately before a new-line character
12059     appear when read in is implementation-defined.
12060 3   A binary stream is an ordered sequence of characters that can transparently record
12061     internal data. Data read in from a binary stream shall compare equal to the data that were
12062     earlier written out to that stream, under the same implementation. Such a stream may,
12063     however, have an implementation-defined number of null characters appended to the end
12064     of the stream.
12065 4   Each stream has an orientation. After a stream is associated with an external file, but
12066     before any operations are performed on it, the stream is without orientation. Once a wide
12067     character input/output function has been applied to a stream without orientation, the
12068
12069
12070     259) An implementation need not distinguish between text streams and binary streams. In such an
12071          implementation, there need be no new-line characters in a text stream nor any limit to the length of a
12072          line.
12073
12074 [page 298]
12075
12076     stream becomes a wide-oriented stream. Similarly, once a byte input/output function has
12077     been applied to a stream without orientation, the stream becomes a byte-oriented stream.
12078     Only a call to the freopen function or the fwide function can otherwise alter the
12079     orientation of a stream. (A successful call to freopen removes any orientation.)260)
12080 5   Byte input/output functions shall not be applied to a wide-oriented stream and wide
12081     character input/output functions shall not be applied to a byte-oriented stream. The
12082     remaining stream operations do not affect, and are not affected by, a stream's orientation,
12083     except for the following additional restrictions:
12084     -- Binary wide-oriented streams have the file-positioning restrictions ascribed to both
12085       text and binary streams.
12086     -- For wide-oriented streams, after a successful call to a file-positioning function that
12087       leaves the file position indicator prior to the end-of-file, a wide character output
12088       function can overwrite a partial multibyte character; any file contents beyond the
12089       byte(s) written are henceforth indeterminate.
12090 6   Each wide-oriented stream has an associated mbstate_t object that stores the current
12091     parse state of the stream. A successful call to fgetpos stores a representation of the
12092     value of this mbstate_t object as part of the value of the fpos_t object. A later
12093     successful call to fsetpos using the same stored fpos_t value restores the value of
12094     the associated mbstate_t object as well as the position within the controlled stream.
12095     Environmental limits
12096 7   An implementation shall support text files with lines containing at least 254 characters,
12097     including the terminating new-line character. The value of the macro BUFSIZ shall be at
12098     least 256.
12099     Forward references: the freopen function (7.21.5.4), the fwide function (7.28.3.5),
12100     mbstate_t (7.29.1), the fgetpos function (7.21.9.1), the fsetpos function
12101     (7.21.9.3).
12102
12103
12104
12105
12106     260) The three predefined streams stdin, stdout, and stderr are unoriented at program startup.
12107
12108 [page 299]
12109
12110     7.21.3 Files
12111 1   A stream is associated with an external file (which may be a physical device) by opening
12112     a file, which may involve creating a new file. Creating an existing file causes its former
12113     contents to be discarded, if necessary. If a file can support positioning requests (such as a
12114     disk file, as opposed to a terminal), then a file position indicator associated with the
12115     stream is positioned at the start (character number zero) of the file, unless the file is
12116     opened with append mode in which case it is implementation-defined whether the file
12117     position indicator is initially positioned at the beginning or the end of the file. The file
12118     position indicator is maintained by subsequent reads, writes, and positioning requests, to
12119     facilitate an orderly progression through the file.
12120 2   Binary files are not truncated, except as defined in 7.21.5.3. Whether a write on a text
12121     stream causes the associated file to be truncated beyond that point is implementation-
12122     defined.
12123 3   When a stream is unbuffered, characters are intended to appear from the source or at the
12124     destination as soon as possible. Otherwise characters may be accumulated and
12125     transmitted to or from the host environment as a block. When a stream is fully buffered,
12126     characters are intended to be transmitted to or from the host environment as a block when
12127     a buffer is filled. When a stream is line buffered, characters are intended to be
12128     transmitted to or from the host environment as a block when a new-line character is
12129     encountered. Furthermore, characters are intended to be transmitted as a block to the host
12130     environment when a buffer is filled, when input is requested on an unbuffered stream, or
12131     when input is requested on a line buffered stream that requires the transmission of
12132     characters from the host environment. Support for these characteristics is
12133     implementation-defined, and may be affected via the setbuf and setvbuf functions.
12134 4   A file may be disassociated from a controlling stream by closing the file. Output streams
12135     are flushed (any unwritten buffer contents are transmitted to the host environment) before
12136     the stream is disassociated from the file. The value of a pointer to a FILE object is
12137     indeterminate after the associated file is closed (including the standard text streams).
12138     Whether a file of zero length (on which no characters have been written by an output
12139     stream) actually exists is implementation-defined.
12140 5   The file may be subsequently reopened, by the same or another program execution, and
12141     its contents reclaimed or modified (if it can be repositioned at its start). If the main
12142     function returns to its original caller, or if the exit function is called, all open files are
12143     closed (hence all output streams are flushed) before program termination. Other paths to
12144     program termination, such as calling the abort function, need not close all files
12145     properly.
12146 6   The address of the FILE object used to control a stream may be significant; a copy of a
12147     FILE object need not serve in place of the original.
12148
12149 [page 300]
12150
12151 7    At program startup, three text streams are predefined and need not be opened explicitly
12152      -- standard input (for reading conventional input), standard output (for writing
12153      conventional output), and standard error (for writing diagnostic output). As initially
12154      opened, the standard error stream is not fully buffered; the standard input and standard
12155      output streams are fully buffered if and only if the stream can be determined not to refer
12156      to an interactive device.
12157 8    Functions that open additional (nontemporary) files require a file name, which is a string.
12158      The rules for composing valid file names are implementation-defined. Whether the same
12159      file can be simultaneously open multiple times is also implementation-defined.
12160 9    Although both text and binary wide-oriented streams are conceptually sequences of wide
12161      characters, the external file associated with a wide-oriented stream is a sequence of
12162      multibyte characters, generalized as follows:
12163      -- Multibyte encodings within files may contain embedded null bytes (unlike multibyte
12164        encodings valid for use internal to the program).
12165      -- A file need not begin nor end in the initial shift state.261)
12166 10   Moreover, the encodings used for multibyte characters may differ among files. Both the
12167      nature and choice of such encodings are implementation-defined.
12168 11   The wide character input functions read multibyte characters from the stream and convert
12169      them to wide characters as if they were read by successive calls to the fgetwc function.
12170      Each conversion occurs as if by a call to the mbrtowc function, with the conversion state
12171      described by the stream's own mbstate_t object. The byte input functions read
12172      characters from the stream as if by successive calls to the fgetc function.
12173 12   The wide character output functions convert wide characters to multibyte characters and
12174      write them to the stream as if they were written by successive calls to the fputwc
12175      function. Each conversion occurs as if by a call to the wcrtomb function, with the
12176      conversion state described by the stream's own mbstate_t object. The byte output
12177      functions write characters to the stream as if by successive calls to the fputc function.
12178 13   In some cases, some of the byte input/output functions also perform conversions between
12179      multibyte characters and wide characters. These conversions also occur as if by calls to
12180      the mbrtowc and wcrtomb functions.
12181 14   An encoding error occurs if the character sequence presented to the underlying
12182      mbrtowc function does not form a valid (generalized) multibyte character, or if the code
12183      value passed to the underlying wcrtomb does not correspond to a valid (generalized)
12184
12185
12186      261) Setting the file position indicator to end-of-file, as with fseek(file, 0, SEEK_END), has
12187           undefined behavior for a binary stream (because of possible trailing null characters) or for any stream
12188           with state-dependent encoding that does not assuredly end in the initial shift state.
12189
12190 [page 301]
12191
12192      multibyte character. The wide character input/output functions and the byte input/output
12193      functions store the value of the macro EILSEQ in errno if and only if an encoding error
12194      occurs.
12195      Environmental limits
12196 15   The value of FOPEN_MAX shall be at least eight, including the three standard text
12197      streams.
12198      Forward references: the exit function (7.22.4.4), the fgetc function (7.21.7.1), the
12199      fopen function (7.21.5.3), the fputc function (7.21.7.3), the setbuf function
12200      (7.21.5.5), the setvbuf function (7.21.5.6), the fgetwc function (7.28.3.1), the
12201      fputwc function (7.28.3.3), conversion state (7.28.6), the mbrtowc function
12202      (7.28.6.3.2), the wcrtomb function (7.28.6.3.3).
12203      7.21.4 Operations on files
12204      7.21.4.1 The remove function
12205      Synopsis
12206 1           #include <stdio.h>
12207             int remove(const char *filename);
12208      Description
12209 2    The remove function causes the file whose name is the string pointed to by filename
12210      to be no longer accessible by that name. A subsequent attempt to open that file using that
12211      name will fail, unless it is created anew. If the file is open, the behavior of the remove
12212      function is implementation-defined.
12213      Returns
12214 3    The remove function returns zero if the operation succeeds, nonzero if it fails.
12215      7.21.4.2 The rename function
12216      Synopsis
12217 1           #include <stdio.h>
12218             int rename(const char *old, const char *new);
12219      Description
12220 2    The rename function causes the file whose name is the string pointed to by old to be
12221      henceforth known by the name given by the string pointed to by new. The file named
12222      old is no longer accessible by that name. If a file named by the string pointed to by new
12223      exists prior to the call to the rename function, the behavior is implementation-defined.
12224
12225
12226
12227
12228 [page 302]
12229
12230     Returns
12231 3   The rename function returns zero if the operation succeeds, nonzero if it fails,262) in
12232     which case if the file existed previously it is still known by its original name.
12233     7.21.4.3 The tmpfile function
12234     Synopsis
12235 1           #include <stdio.h>
12236             FILE *tmpfile(void);
12237     Description
12238 2   The tmpfile function creates a temporary binary file that is different from any other
12239     existing file and that will automatically be removed when it is closed or at program
12240     termination. If the program terminates abnormally, whether an open temporary file is
12241     removed is implementation-defined. The file is opened for update with "wb+" mode.
12242     Recommended practice
12243 3   It should be possible to open at least TMP_MAX temporary files during the lifetime of the
12244     program (this limit may be shared with tmpnam) and there should be no limit on the
12245     number simultaneously open other than this limit and any limit on the number of open
12246     files (FOPEN_MAX).
12247     Returns
12248 4   The tmpfile function returns a pointer to the stream of the file that it created. If the file
12249     cannot be created, the tmpfile function returns a null pointer.
12250     Forward references: the fopen function (7.21.5.3).
12251     7.21.4.4 The tmpnam function
12252     Synopsis
12253 1           #include <stdio.h>
12254             char *tmpnam(char *s);
12255     Description
12256 2   The tmpnam function generates a string that is a valid file name and that is not the same
12257     as the name of an existing file.263) The function is potentially capable of generating at
12258
12259
12260     262) Among the reasons the implementation may cause the rename function to fail are that the file is open
12261          or that it is necessary to copy its contents to effectuate its renaming.
12262     263) Files created using strings generated by the tmpnam function are temporary only in the sense that
12263          their names should not collide with those generated by conventional naming rules for the
12264          implementation. It is still necessary to use the remove function to remove such files when their use
12265          is ended, and before program termination.
12266
12267 [page 303]
12268
12269     least TMP_MAX different strings, but any or all of them may already be in use by existing
12270     files and thus not be suitable return values.
12271 3   The tmpnam function generates a different string each time it is called.
12272 4   Calls to the tmpnam function with a null pointer argument may introduce data races with
12273     each other. The implementation shall behave as if no library function calls the tmpnam
12274     function.
12275     Returns
12276 5   If no suitable string can be generated, the tmpnam function returns a null pointer.
12277     Otherwise, if the argument is a null pointer, the tmpnam function leaves its result in an
12278     internal static object and returns a pointer to that object (subsequent calls to the tmpnam
12279     function may modify the same object). If the argument is not a null pointer, it is assumed
12280     to point to an array of at least L_tmpnam chars; the tmpnam function writes its result
12281     in that array and returns the argument as its value.
12282     Environmental limits
12283 6   The value of the macro TMP_MAX shall be at least 25.
12284     7.21.5 File access functions
12285     7.21.5.1 The fclose function
12286     Synopsis
12287 1          #include <stdio.h>
12288            int fclose(FILE *stream);
12289     Description
12290 2   A successful call to the fclose function causes the stream pointed to by stream to be
12291     flushed and the associated file to be closed. Any unwritten buffered data for the stream
12292     are delivered to the host environment to be written to the file; any unread buffered data
12293     are discarded. Whether or not the call succeeds, the stream is disassociated from the file
12294     and any buffer set by the setbuf or setvbuf function is disassociated from the stream
12295     (and deallocated if it was automatically allocated).
12296     Returns
12297 3   The fclose function returns zero if the stream was successfully closed, or EOF if any
12298     errors were detected.
12299
12300
12301
12302
12303 [page 304]
12304
12305     7.21.5.2 The fflush function
12306     Synopsis
12307 1           #include <stdio.h>
12308             int fflush(FILE *stream);
12309     Description
12310 2   If stream points to an output stream or an update stream in which the most recent
12311     operation was not input, the fflush function causes any unwritten data for that stream
12312     to be delivered to the host environment to be written to the file; otherwise, the behavior is
12313     undefined.
12314 3   If stream is a null pointer, the fflush function performs this flushing action on all
12315     streams for which the behavior is defined above.
12316     Returns
12317 4   The fflush function sets the error indicator for the stream and returns EOF if a write
12318     error occurs, otherwise it returns zero.
12319     Forward references: the fopen function (7.21.5.3).
12320     7.21.5.3 The fopen function
12321     Synopsis
12322 1           #include <stdio.h>
12323             FILE *fopen(const char * restrict filename,
12324                  const char * restrict mode);
12325     Description
12326 2   The fopen function opens the file whose name is the string pointed to by filename,
12327     and associates a stream with it.
12328 3   The argument mode points to a string. If the string is one of the following, the file is
12329     open in the indicated mode. Otherwise, the behavior is undefined.264)
12330     r                     open text file for reading
12331     w                     truncate to zero length or create text file for writing
12332     wx                    create text file for writing
12333     a                     append; open or create text file for writing at end-of-file
12334     rb                    open binary file for reading
12335     wb                    truncate to zero length or create binary file for writing
12336
12337
12338     264) If the string begins with one of the above sequences, the implementation might choose to ignore the
12339          remaining characters, or it might use them to select different kinds of a file (some of which might not
12340          conform to the properties in 7.21.2).
12341
12342 [page 305]
12343
12344     wbx               create binary file for writing
12345     ab                append; open or create binary file for writing at end-of-file
12346     r+                open text file for update (reading and writing)
12347     w+                truncate to zero length or create text file for update
12348     w+x               create text file for update
12349     a+                append; open or create text file for update, writing at end-of-file
12350     r+b or rb+        open binary file for update (reading and writing)
12351     w+b or wb+        truncate to zero length or create binary file for update
12352     w+bx or wb+x      create binary file for update
12353     a+b or ab+        append; open or create binary file for update, writing at end-of-file
12354 4   Opening a file with read mode ('r' as the first character in the mode argument) fails if
12355     the file does not exist or cannot be read.
12356 5   Opening a file with exclusive mode ('x' as the last character in the mode argument)
12357     fails if the file already exists or cannot be created. Otherwise, the file is created with
12358     exclusive (also known as non-shared) access to the extent that the underlying system
12359     supports exclusive access.
12360 6   Opening a file with append mode ('a' as the first character in the mode argument)
12361     causes all subsequent writes to the file to be forced to the then current end-of-file,
12362     regardless of intervening calls to the fseek function. In some implementations, opening
12363     a binary file with append mode ('b' as the second or third character in the above list of
12364     mode argument values) may initially position the file position indicator for the stream
12365     beyond the last data written, because of null character padding.
12366 7   When a file is opened with update mode ('+' as the second or third character in the
12367     above list of mode argument values), both input and output may be performed on the
12368     associated stream. However, output shall not be directly followed by input without an
12369     intervening call to the fflush function or to a file positioning function (fseek,
12370     fsetpos, or rewind), and input shall not be directly followed by output without an
12371     intervening call to a file positioning function, unless the input operation encounters end-
12372     of-file. Opening (or creating) a text file with update mode may instead open (or create) a
12373     binary stream in some implementations.
12374 8   When opened, a stream is fully buffered if and only if it can be determined not to refer to
12375     an interactive device. The error and end-of-file indicators for the stream are cleared.
12376     Returns
12377 9   The fopen function returns a pointer to the object controlling the stream. If the open
12378     operation fails, fopen returns a null pointer.
12379     Forward references: file positioning functions (7.21.9).
12380
12381
12382
12383 [page 306]
12384
12385     7.21.5.4 The freopen function
12386     Synopsis
12387 1           #include <stdio.h>
12388             FILE *freopen(const char * restrict filename,
12389                  const char * restrict mode,
12390                  FILE * restrict stream);
12391     Description
12392 2   The freopen function opens the file whose name is the string pointed to by filename
12393     and associates the stream pointed to by stream with it. The mode argument is used just
12394     as in the fopen function.265)
12395 3   If filename is a null pointer, the freopen function attempts to change the mode of
12396     the stream to that specified by mode, as if the name of the file currently associated with
12397     the stream had been used. It is implementation-defined which changes of mode are
12398     permitted (if any), and under what circumstances.
12399 4   The freopen function first attempts to close any file that is associated with the specified
12400     stream. Failure to close the file is ignored. The error and end-of-file indicators for the
12401     stream are cleared.
12402     Returns
12403 5   The freopen function returns a null pointer if the open operation fails. Otherwise,
12404     freopen returns the value of stream.
12405     7.21.5.5 The setbuf function
12406     Synopsis
12407 1           #include <stdio.h>
12408             void setbuf(FILE * restrict stream,
12409                  char * restrict buf);
12410     Description
12411 2   Except that it returns no value, the setbuf function is equivalent to the setvbuf
12412     function invoked with the values _IOFBF for mode and BUFSIZ for size, or (if buf
12413     is a null pointer), with the value _IONBF for mode.
12414
12415
12416
12417
12418     265) The primary use of the freopen function is to change the file associated with a standard text stream
12419          (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value
12420          returned by the fopen function may be assigned.
12421
12422 [page 307]
12423
12424     Returns
12425 3   The setbuf function returns no value.
12426     Forward references: the setvbuf function (7.21.5.6).
12427     7.21.5.6 The setvbuf function
12428     Synopsis
12429 1           #include <stdio.h>
12430             int setvbuf(FILE * restrict stream,
12431                  char * restrict buf,
12432                  int mode, size_t size);
12433     Description
12434 2   The setvbuf function may be used only after the stream pointed to by stream has
12435     been associated with an open file and before any other operation (other than an
12436     unsuccessful call to setvbuf) is performed on the stream. The argument mode
12437     determines how stream will be buffered, as follows: _IOFBF causes input/output to be
12438     fully buffered; _IOLBF causes input/output to be line buffered; _IONBF causes
12439     input/output to be unbuffered. If buf is not a null pointer, the array it points to may be
12440     used instead of a buffer allocated by the setvbuf function266) and the argument size
12441     specifies the size of the array; otherwise, size may determine the size of a buffer
12442     allocated by the setvbuf function. The contents of the array at any time are
12443     indeterminate.
12444     Returns
12445 3   The setvbuf function returns zero on success, or nonzero if an invalid value is given
12446     for mode or if the request cannot be honored.
12447
12448
12449
12450
12451     266) The buffer has to have a lifetime at least as great as the open stream, so the stream should be closed
12452          before a buffer that has automatic storage duration is deallocated upon block exit.
12453
12454 [page 308]
12455
12456     7.21.6 Formatted input/output functions
12457 1   The formatted input/output functions shall behave as if there is a sequence point after the
12458     actions associated with each specifier.267)
12459     7.21.6.1 The fprintf function
12460     Synopsis
12461 1            #include <stdio.h>
12462              int fprintf(FILE * restrict stream,
12463                   const char * restrict format, ...);
12464     Description
12465 2   The fprintf function writes output to the stream pointed to by stream, under control
12466     of the string pointed to by format that specifies how subsequent arguments are
12467     converted for output. If there are insufficient arguments for the format, the behavior is
12468     undefined. If the format is exhausted while arguments remain, the excess arguments are
12469     evaluated (as always) but are otherwise ignored. The fprintf function returns when
12470     the end of the format string is encountered.
12471 3   The format shall be a multibyte character sequence, beginning and ending in its initial
12472     shift state. The format is composed of zero or more directives: ordinary multibyte
12473     characters (not %), which are copied unchanged to the output stream; and conversion
12474     specifications, each of which results in fetching zero or more subsequent arguments,
12475     converting them, if applicable, according to the corresponding conversion specifier, and
12476     then writing the result to the output stream.
12477 4   Each conversion specification is introduced by the character %. After the %, the following
12478     appear in sequence:
12479     -- Zero or more flags (in any order) that modify the meaning of the conversion
12480       specification.
12481     -- An optional minimum field width. If the converted value has fewer characters than the
12482       field width, it is padded with spaces (by default) on the left (or right, if the left
12483       adjustment flag, described later, has been given) to the field width. The field width
12484       takes the form of an asterisk * (described later) or a nonnegative decimal integer.268)
12485     -- An optional precision that gives the minimum number of digits to appear for the d, i,
12486       o, u, x, and X conversions, the number of digits to appear after the decimal-point
12487       character for a, A, e, E, f, and F conversions, the maximum number of significant
12488       digits for the g and G conversions, or the maximum number of bytes to be written for
12489
12490
12491     267) The fprintf functions perform writes to memory for the %n specifier.
12492     268) Note that 0 is taken as a flag, not as the beginning of a field width.
12493
12494 [page 309]
12495
12496         s conversions. The precision takes the form of a period (.) followed either by an
12497         asterisk * (described later) or by an optional decimal integer; if only the period is
12498         specified, the precision is taken as zero. If a precision appears with any other
12499         conversion specifier, the behavior is undefined.
12500     -- An optional length modifier that specifies the size of the argument.
12501     -- A conversion specifier character that specifies the type of conversion to be applied.
12502 5   As noted above, a field width, or precision, or both, may be indicated by an asterisk. In
12503     this case, an int argument supplies the field width or precision. The arguments
12504     specifying field width, or precision, or both, shall appear (in that order) before the
12505     argument (if any) to be converted. A negative field width argument is taken as a - flag
12506     followed by a positive field width. A negative precision argument is taken as if the
12507     precision were omitted.
12508 6   The flag characters and their meanings are:
12509     -       The result of the conversion is left-justified within the field. (It is right-justified if
12510             this flag is not specified.)
12511     +       The result of a signed conversion always begins with a plus or minus sign. (It
12512             begins with a sign only when a negative value is converted if this flag is not
12513             specified.)269)
12514     space If the first character of a signed conversion is not a sign, or if a signed conversion
12515           results in no characters, a space is prefixed to the result. If the space and + flags
12516           both appear, the space flag is ignored.
12517     #       The result is converted to an ''alternative form''. For o conversion, it increases
12518             the precision, if and only if necessary, to force the first digit of the result to be a
12519             zero (if the value and precision are both 0, a single 0 is printed). For x (or X)
12520             conversion, a nonzero result has 0x (or 0X) prefixed to it. For a, A, e, E, f, F, g,
12521             and G conversions, the result of converting a floating-point number always
12522             contains a decimal-point character, even if no digits follow it. (Normally, a
12523             decimal-point character appears in the result of these conversions only if a digit
12524             follows it.) For g and G conversions, trailing zeros are not removed from the
12525             result. For other conversions, the behavior is undefined.
12526     0       For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros
12527             (following any indication of sign or base) are used to pad to the field width rather
12528             than performing space padding, except when converting an infinity or NaN. If the
12529             0 and - flags both appear, the 0 flag is ignored. For d, i, o, u, x, and X
12530
12531
12532     269) The results of all floating conversions of a negative zero, and of negative values that round to zero,
12533          include a minus sign.
12534
12535 [page 310]
12536
12537               conversions, if a precision is specified, the 0 flag is ignored. For other
12538               conversions, the behavior is undefined.
12539 7   The length modifiers and their meanings are:
12540     hh            Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12541                   signed char or unsigned char argument (the argument will have
12542                   been promoted according to the integer promotions, but its value shall be
12543                   converted to signed char or unsigned char before printing); or that
12544                   a following n conversion specifier applies to a pointer to a signed char
12545                   argument.
12546     h             Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12547                   short int or unsigned short int argument (the argument will
12548                   have been promoted according to the integer promotions, but its value shall
12549                   be converted to short int or unsigned short int before printing);
12550                   or that a following n conversion specifier applies to a pointer to a short
12551                   int argument.
12552     l (ell)       Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12553                   long int or unsigned long int argument; that a following n
12554                   conversion specifier applies to a pointer to a long int argument; that a
12555                   following c conversion specifier applies to a wint_t argument; that a
12556                   following s conversion specifier applies to a pointer to a wchar_t
12557                   argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion
12558                   specifier.
12559     ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12560                  long long int or unsigned long long int argument; or that a
12561                  following n conversion specifier applies to a pointer to a long long int
12562                  argument.
12563     j             Specifies that a following d, i, o, u, x, or X conversion specifier applies to
12564                   an intmax_t or uintmax_t argument; or that a following n conversion
12565                   specifier applies to a pointer to an intmax_t argument.
12566     z             Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12567                   size_t or the corresponding signed integer type argument; or that a
12568                   following n conversion specifier applies to a pointer to a signed integer type
12569                   corresponding to size_t argument.
12570     t             Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12571                   ptrdiff_t or the corresponding unsigned integer type argument; or that a
12572                   following n conversion specifier applies to a pointer to a ptrdiff_t
12573                   argument.
12574
12575
12576 [page 311]
12577
12578     L              Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
12579                    applies to a long double argument.
12580     If a length modifier appears with any conversion specifier other than as specified above,
12581     the behavior is undefined.
12582 8   The conversion specifiers and their meanings are:
12583     d,i          The int argument is converted to signed decimal in the style [-]dddd. The
12584                  precision specifies the minimum number of digits to appear; if the value
12585                  being converted can be represented in fewer digits, it is expanded with
12586                  leading zeros. The default precision is 1. The result of converting a zero
12587                  value with a precision of zero is no characters.
12588     o,u,x,X The unsigned int argument is converted to unsigned octal (o), unsigned
12589             decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; the
12590             letters abcdef are used for x conversion and the letters ABCDEF for X
12591             conversion. The precision specifies the minimum number of digits to appear;
12592             if the value being converted can be represented in fewer digits, it is expanded
12593             with leading zeros. The default precision is 1. The result of converting a
12594             zero value with a precision of zero is no characters.
12595     f,F          A double argument representing a floating-point number is converted to
12596                  decimal notation in the style [-]ddd.ddd, where the number of digits after
12597                  the decimal-point character is equal to the precision specification. If the
12598                  precision is missing, it is taken as 6; if the precision is zero and the # flag is
12599                  not specified, no decimal-point character appears. If a decimal-point
12600                  character appears, at least one digit appears before it. The value is rounded to
12601                  the appropriate number of digits.
12602                  A double argument representing an infinity is converted in one of the styles
12603                  [-]inf or [-]infinity -- which style is implementation-defined. A
12604                  double argument representing a NaN is converted in one of the styles
12605                  [-]nan or [-]nan(n-char-sequence) -- which style, and the meaning of
12606                  any n-char-sequence, is implementation-defined. The F conversion specifier
12607                  produces INF, INFINITY, or NAN instead of inf, infinity, or nan,
12608                  respectively.270)
12609     e,E          A double argument representing a floating-point number is converted in the
12610                  style [-]d.ddd e(+-)dd, where there is one digit (which is nonzero if the
12611                  argument is nonzero) before the decimal-point character and the number of
12612                  digits after it is equal to the precision; if the precision is missing, it is taken as
12613
12614
12615     270) When applied to infinite and NaN values, the -, +, and space flag characters have their usual meaning;
12616          the # and 0 flag characters have no effect.
12617
12618 [page 312]
12619
12620               6; if the precision is zero and the # flag is not specified, no decimal-point
12621               character appears. The value is rounded to the appropriate number of digits.
12622               The E conversion specifier produces a number with E instead of e
12623               introducing the exponent. The exponent always contains at least two digits,
12624               and only as many more digits as necessary to represent the exponent. If the
12625               value is zero, the exponent is zero.
12626               A double argument representing an infinity or NaN is converted in the style
12627               of an f or F conversion specifier.
12628 g,G           A double argument representing a floating-point number is converted in
12629               style f or e (or in style F or E in the case of a G conversion specifier),
12630               depending on the value converted and the precision. Let P equal the
12631               precision if nonzero, 6 if the precision is omitted, or 1 if the precision is zero.
12632               Then, if a conversion with style E would have an exponent of X:
12633               -- if P > X >= -4, the conversion is with style f (or F) and precision
12634                 P - (X + 1).
12635               -- otherwise, the conversion is with style e (or E) and precision P - 1.
12636               Finally, unless the # flag is used, any trailing zeros are removed from the
12637               fractional portion of the result and the decimal-point character is removed if
12638               there is no fractional portion remaining.
12639               A double argument representing an infinity or NaN is converted in the style
12640               of an f or F conversion specifier.
12641 a,A           A double argument representing a floating-point number is converted in the
12642               style [-]0xh.hhhh p(+-)d, where there is one hexadecimal digit (which is
12643               nonzero if the argument is a normalized floating-point number and is
12644               otherwise unspecified) before the decimal-point character271) and the number
12645               of hexadecimal digits after it is equal to the precision; if the precision is
12646               missing and FLT_RADIX is a power of 2, then the precision is sufficient for
12647               an exact representation of the value; if the precision is missing and
12648               FLT_RADIX is not a power of 2, then the precision is sufficient to
12649
12650
12651
12652
12653 271) Binary implementations can choose the hexadecimal digit to the left of the decimal-point character so
12654      that subsequent digits align to nibble (4-bit) boundaries.
12655
12656 [page 313]
12657
12658               distinguish272) values of type double, except that trailing zeros may be
12659               omitted; if the precision is zero and the # flag is not specified, no decimal-
12660               point character appears. The letters abcdef are used for a conversion and
12661               the letters ABCDEF for A conversion. The A conversion specifier produces a
12662               number with X and P instead of x and p. The exponent always contains at
12663               least one digit, and only as many more digits as necessary to represent the
12664               decimal exponent of 2. If the value is zero, the exponent is zero.
12665               A double argument representing an infinity or NaN is converted in the style
12666               of an f or F conversion specifier.
12667 c             If no l length modifier is present, the int argument is converted to an
12668               unsigned char, and the resulting character is written.
12669               If an l length modifier is present, the wint_t argument is converted as if by
12670               an ls conversion specification with no precision and an argument that points
12671               to the initial element of a two-element array of wchar_t, the first element
12672               containing the wint_t argument to the lc conversion specification and the
12673               second a null wide character.
12674 s             If no l length modifier is present, the argument shall be a pointer to the initial
12675               element of an array of character type.273) Characters from the array are
12676               written up to (but not including) the terminating null character. If the
12677               precision is specified, no more than that many bytes are written. If the
12678               precision is not specified or is greater than the size of the array, the array shall
12679               contain a null character.
12680               If an l length modifier is present, the argument shall be a pointer to the initial
12681               element of an array of wchar_t type. Wide characters from the array are
12682               converted to multibyte characters (each as if by a call to the wcrtomb
12683               function, with the conversion state described by an mbstate_t object
12684               initialized to zero before the first wide character is converted) up to and
12685               including a terminating null wide character. The resulting multibyte
12686               characters are written up to (but not including) the terminating null character
12687               (byte). If no precision is specified, the array shall contain a null wide
12688               character. If a precision is specified, no more than that many bytes are
12689               written (including shift sequences, if any), and the array shall contain a null
12690               wide character if, to equal the multibyte character sequence length given by
12691
12692 272) The precision p is sufficient to distinguish values of the source type if 16 p-1 > b n where b is
12693      FLT_RADIX and n is the number of base-b digits in the significand of the source type. A smaller p
12694      might suffice depending on the implementation's scheme for determining the digit to the left of the
12695      decimal-point character.
12696 273) No special provisions are made for multibyte characters.
12697
12698 [page 314]
12699
12700                     the precision, the function would need to access a wide character one past the
12701                     end of the array. In no case is a partial multibyte character written.274)
12702      p              The argument shall be a pointer to void. The value of the pointer is
12703                     converted to a sequence of printing characters, in an implementation-defined
12704                     manner.
12705      n              The argument shall be a pointer to signed integer into which is written the
12706                     number of characters written to the output stream so far by this call to
12707                     fprintf. No argument is converted, but one is consumed. If the conversion
12708                     specification includes any flags, a field width, or a precision, the behavior is
12709                     undefined.
12710      %              A % character is written. No argument is converted. The complete
12711                     conversion specification shall be %%.
12712 9    If a conversion specification is invalid, the behavior is undefined.275) If any argument is
12713      not the correct type for the corresponding conversion specification, the behavior is
12714      undefined.
12715 10   In no case does a nonexistent or small field width cause truncation of a field; if the result
12716      of a conversion is wider than the field width, the field is expanded to contain the
12717      conversion result.
12718 11   For a and A conversions, if FLT_RADIX is a power of 2, the value is correctly rounded
12719      to a hexadecimal floating number with the given precision.
12720      Recommended practice
12721 12   For a and A conversions, if FLT_RADIX is not a power of 2 and the result is not exactly
12722      representable in the given precision, the result should be one of the two adjacent numbers
12723      in hexadecimal floating style with the given precision, with the extra stipulation that the
12724      error should have a correct sign for the current rounding direction.
12725 13   For e, E, f, F, g, and G conversions, if the number of significant decimal digits is at most
12726      DECIMAL_DIG, then the result should be correctly rounded.276) If the number of
12727      significant decimal digits is more than DECIMAL_DIG but the source value is exactly
12728      representable with DECIMAL_DIG digits, then the result should be an exact
12729      representation with trailing zeros. Otherwise, the source value is bounded by two
12730      adjacent decimal strings L < U, both having DECIMAL_DIG significant digits; the value
12731
12732
12733      274) Redundant shift sequences may result if multibyte characters have a state-dependent encoding.
12734      275) See ''future library directions'' (7.30.9).
12735      276) For binary-to-decimal conversion, the result format's values are the numbers representable with the
12736           given format specifier. The number of significant digits is determined by the format specifier, and in
12737           the case of fixed-point conversion by the source value as well.
12738
12739 [page 315]
12740
12741      of the resultant decimal string D should satisfy L <= D <= U, with the extra stipulation that
12742      the error should have a correct sign for the current rounding direction.
12743      Returns
12744 14   The fprintf function returns the number of characters transmitted, or a negative value
12745      if an output or encoding error occurred.
12746      Environmental limits
12747 15   The number of characters that can be produced by any single conversion shall be at least
12748      4095.
12749 16   EXAMPLE 1         To print a date and time in the form ''Sunday, July 3, 10:02'' followed by pi to five decimal
12750      places:
12751               #include <math.h>
12752               #include <stdio.h>
12753               /* ... */
12754               char *weekday, *month;      // pointers to strings
12755               int day, hour, min;
12756               fprintf(stdout, "%s, %s %d, %.2d:%.2d\n",
12757                       weekday, month, day, hour, min);
12758               fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0));
12759
12760 17   EXAMPLE 2 In this example, multibyte characters do not have a state-dependent encoding, and the
12761      members of the extended character set that consist of more than one byte each consist of exactly two bytes,
12762      the first of which is denoted here by a and the second by an uppercase letter.
12763 18   Given the following wide string with length seven,
12764               static wchar_t wstr[] = L" X Yabc Z W";
12765      the seven calls
12766               fprintf(stdout,          "|1234567890123|\n");
12767               fprintf(stdout,          "|%13ls|\n", wstr);
12768               fprintf(stdout,          "|%-13.9ls|\n", wstr);
12769               fprintf(stdout,          "|%13.10ls|\n", wstr);
12770               fprintf(stdout,          "|%13.11ls|\n", wstr);
12771               fprintf(stdout,          "|%13.15ls|\n", &wstr[2]);
12772               fprintf(stdout,          "|%13lc|\n", (wint_t) wstr[5]);
12773      will print the following seven lines:
12774               |1234567890123|
12775               |   X Yabc Z W|
12776               | X Yabc Z    |
12777               |     X Yabc Z|
12778               |   X Yabc Z W|
12779               |      abc Z W|
12780               |            Z|
12781
12782      Forward references: conversion state (7.28.6), the wcrtomb function (7.28.6.3.3).
12783
12784
12785
12786 [page 316]
12787
12788     7.21.6.2 The fscanf function
12789     Synopsis
12790 1           #include <stdio.h>
12791             int fscanf(FILE * restrict stream,
12792                  const char * restrict format, ...);
12793     Description
12794 2   The fscanf function reads input from the stream pointed to by stream, under control
12795     of the string pointed to by format that specifies the admissible input sequences and how
12796     they are to be converted for assignment, using subsequent arguments as pointers to the
12797     objects to receive the converted input. If there are insufficient arguments for the format,
12798     the behavior is undefined. If the format is exhausted while arguments remain, the excess
12799     arguments are evaluated (as always) but are otherwise ignored.
12800 3   The format shall be a multibyte character sequence, beginning and ending in its initial
12801     shift state. The format is composed of zero or more directives: one or more white-space
12802     characters, an ordinary multibyte character (neither % nor a white-space character), or a
12803     conversion specification. Each conversion specification is introduced by the character %.
12804     After the %, the following appear in sequence:
12805     -- An optional assignment-suppressing character *.
12806     -- An optional decimal integer greater than zero that specifies the maximum field width
12807       (in characters).
12808     -- An optional length modifier that specifies the size of the receiving object.
12809     -- A conversion specifier character that specifies the type of conversion to be applied.
12810 4   The fscanf function executes each directive of the format in turn. When all directives
12811     have been executed, or if a directive fails (as detailed below), the function returns.
12812     Failures are described as input failures (due to the occurrence of an encoding error or the
12813     unavailability of input characters), or matching failures (due to inappropriate input).
12814 5   A directive composed of white-space character(s) is executed by reading input up to the
12815     first non-white-space character (which remains unread), or until no more characters can
12816     be read.
12817 6   A directive that is an ordinary multibyte character is executed by reading the next
12818     characters of the stream. If any of those characters differ from the ones composing the
12819     directive, the directive fails and the differing and subsequent characters remain unread.
12820     Similarly, if end-of-file, an encoding error, or a read error prevents a character from being
12821     read, the directive fails.
12822 7   A directive that is a conversion specification defines a set of matching input sequences, as
12823     described below for each specifier. A conversion specification is executed in the
12824
12825 [page 317]
12826
12827      following steps:
12828 8    Input white-space characters (as specified by the isspace function) are skipped, unless
12829      the specification includes a [, c, or n specifier.277)
12830 9    An input item is read from the stream, unless the specification includes an n specifier. An
12831      input item is defined as the longest sequence of input characters which does not exceed
12832      any specified field width and which is, or is a prefix of, a matching input sequence.278)
12833      The first character, if any, after the input item remains unread. If the length of the input
12834      item is zero, the execution of the directive fails; this condition is a matching failure unless
12835      end-of-file, an encoding error, or a read error prevented input from the stream, in which
12836      case it is an input failure.
12837 10   Except in the case of a % specifier, the input item (or, in the case of a %n directive, the
12838      count of input characters) is converted to a type appropriate to the conversion specifier. If
12839      the input item is not a matching sequence, the execution of the directive fails: this
12840      condition is a matching failure. Unless assignment suppression was indicated by a *, the
12841      result of the conversion is placed in the object pointed to by the first argument following
12842      the format argument that has not already received a conversion result. If this object
12843      does not have an appropriate type, or if the result of the conversion cannot be represented
12844      in the object, the behavior is undefined.
12845 11   The length modifiers and their meanings are:
12846      hh             Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12847                     to an argument with type pointer to signed char or unsigned char.
12848      h              Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12849                     to an argument with type pointer to short int or unsigned short
12850                     int.
12851      l (ell)        Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12852                     to an argument with type pointer to long int or unsigned long
12853                     int; that a following a, A, e, E, f, F, g, or G conversion specifier applies to
12854                     an argument with type pointer to double; or that a following c, s, or [
12855                     conversion specifier applies to an argument with type pointer to wchar_t.
12856      ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12857                   to an argument with type pointer to long long int or unsigned
12858                   long long int.
12859
12860
12861
12862      277) These white-space characters are not counted against a specified field width.
12863      278) fscanf pushes back at most one input character onto the input stream. Therefore, some sequences
12864           that are acceptable to strtod, strtol, etc., are unacceptable to fscanf.
12865
12866 [page 318]
12867
12868      j            Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12869                   to an argument with type pointer to intmax_t or uintmax_t.
12870      z            Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12871                   to an argument with type pointer to size_t or the corresponding signed
12872                   integer type.
12873      t            Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12874                   to an argument with type pointer to ptrdiff_t or the corresponding
12875                   unsigned integer type.
12876      L            Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
12877                   applies to an argument with type pointer to long double.
12878      If a length modifier appears with any conversion specifier other than as specified above,
12879      the behavior is undefined.
12880 12   The conversion specifiers and their meanings are:
12881      d           Matches an optionally signed decimal integer, whose format is the same as
12882                  expected for the subject sequence of the strtol function with the value 10
12883                  for the base argument. The corresponding argument shall be a pointer to
12884                  signed integer.
12885      i           Matches an optionally signed integer, whose format is the same as expected
12886                  for the subject sequence of the strtol function with the value 0 for the
12887                  base argument. The corresponding argument shall be a pointer to signed
12888                  integer.
12889      o           Matches an optionally signed octal integer, whose format is the same as
12890                  expected for the subject sequence of the strtoul function with the value 8
12891                  for the base argument. The corresponding argument shall be a pointer to
12892                  unsigned integer.
12893      u           Matches an optionally signed decimal integer, whose format is the same as
12894                  expected for the subject sequence of the strtoul function with the value 10
12895                  for the base argument. The corresponding argument shall be a pointer to
12896                  unsigned integer.
12897      x           Matches an optionally signed hexadecimal integer, whose format is the same
12898                  as expected for the subject sequence of the strtoul function with the value
12899                  16 for the base argument. The corresponding argument shall be a pointer to
12900                  unsigned integer.
12901      a,e,f,g Matches an optionally signed floating-point number, infinity, or NaN, whose
12902              format is the same as expected for the subject sequence of the strtod
12903              function. The corresponding argument shall be a pointer to floating.
12904
12905
12906 [page 319]
12907
12908 c             Matches a sequence of characters of exactly the number specified by the field
12909               width (1 if no field width is present in the directive).279)
12910               If no l length modifier is present, the corresponding argument shall be a
12911               pointer to the initial element of a character array large enough to accept the
12912               sequence. No null character is added.
12913               If an l length modifier is present, the input shall be a sequence of multibyte
12914               characters that begins in the initial shift state. Each multibyte character in the
12915               sequence is converted to a wide character as if by a call to the mbrtowc
12916               function, with the conversion state described by an mbstate_t object
12917               initialized to zero before the first multibyte character is converted. The
12918               corresponding argument shall be a pointer to the initial element of an array of
12919               wchar_t large enough to accept the resulting sequence of wide characters.
12920               No null wide character is added.
12921 s             Matches a sequence of non-white-space characters.279)
12922               If no l length modifier is present, the corresponding argument shall be a
12923               pointer to the initial element of a character array large enough to accept the
12924               sequence and a terminating null character, which will be added automatically.
12925               If an l length modifier is present, the input shall be a sequence of multibyte
12926               characters that begins in the initial shift state. Each multibyte character is
12927               converted to a wide character as if by a call to the mbrtowc function, with
12928               the conversion state described by an mbstate_t object initialized to zero
12929               before the first multibyte character is converted. The corresponding argument
12930               shall be a pointer to the initial element of an array of wchar_t large enough
12931               to accept the sequence and the terminating null wide character, which will be
12932               added automatically.
12933 [             Matches a nonempty sequence of characters from a set of expected characters
12934               (the scanset).279)
12935               If no l length modifier is present, the corresponding argument shall be a
12936               pointer to the initial element of a character array large enough to accept the
12937               sequence and a terminating null character, which will be added automatically.
12938               If an l length modifier is present, the input shall be a sequence of multibyte
12939               characters that begins in the initial shift state. Each multibyte character is
12940               converted to a wide character as if by a call to the mbrtowc function, with
12941               the conversion state described by an mbstate_t object initialized to zero
12942
12943 279) No special provisions are made for multibyte characters in the matching rules used by the c, s, and [
12944      conversion specifiers -- the extent of the input field is determined on a byte-by-byte basis. The
12945      resulting field is nevertheless a sequence of multibyte characters that begins in the initial shift state.
12946
12947 [page 320]
12948
12949                     before the first multibyte character is converted. The corresponding argument
12950                     shall be a pointer to the initial element of an array of wchar_t large enough
12951                     to accept the sequence and the terminating null wide character, which will be
12952                     added automatically.
12953                     The conversion specifier includes all subsequent characters in the format
12954                     string, up to and including the matching right bracket (]). The characters
12955                     between the brackets (the scanlist) compose the scanset, unless the character
12956                     after the left bracket is a circumflex (^), in which case the scanset contains all
12957                     characters that do not appear in the scanlist between the circumflex and the
12958                     right bracket. If the conversion specifier begins with [] or [^], the right
12959                     bracket character is in the scanlist and the next following right bracket
12960                     character is the matching right bracket that ends the specification; otherwise
12961                     the first following right bracket character is the one that ends the
12962                     specification. If a - character is in the scanlist and is not the first, nor the
12963                     second where the first character is a ^, nor the last character, the behavior is
12964                     implementation-defined.
12965      p              Matches an implementation-defined set of sequences, which should be the
12966                     same as the set of sequences that may be produced by the %p conversion of
12967                     the fprintf function. The corresponding argument shall be a pointer to a
12968                     pointer to void. The input item is converted to a pointer value in an
12969                     implementation-defined manner. If the input item is a value converted earlier
12970                     during the same program execution, the pointer that results shall compare
12971                     equal to that value; otherwise the behavior of the %p conversion is undefined.
12972      n              No input is consumed. The corresponding argument shall be a pointer to
12973                     signed integer into which is to be written the number of characters read from
12974                     the input stream so far by this call to the fscanf function. Execution of a
12975                     %n directive does not increment the assignment count returned at the
12976                     completion of execution of the fscanf function. No argument is converted,
12977                     but one is consumed. If the conversion specification includes an assignment-
12978                     suppressing character or a field width, the behavior is undefined.
12979      %              Matches a single % character; no conversion or assignment occurs. The
12980                     complete conversion specification shall be %%.
12981 13   If a conversion specification is invalid, the behavior is undefined.280)
12982 14   The conversion specifiers A, E, F, G, and X are also valid and behave the same as,
12983      respectively, a, e, f, g, and x.
12984
12985
12986
12987      280) See ''future library directions'' (7.30.9).
12988
12989 [page 321]
12990
12991 15   Trailing white space (including new-line characters) is left unread unless matched by a
12992      directive. The success of literal matches and suppressed assignments is not directly
12993      determinable other than via the %n directive.
12994      Returns
12995 16   The fscanf function returns the value of the macro EOF if an input failure occurs
12996      before the first conversion (if any) has completed. Otherwise, the function returns the
12997      number of input items assigned, which can be fewer than provided for, or even zero, in
12998      the event of an early matching failure.
12999 17   EXAMPLE 1        The call:
13000               #include <stdio.h>
13001               /* ... */
13002               int n, i; float x; char name[50];
13003               n = fscanf(stdin, "%d%f%s", &i, &x, name);
13004      with the input line:
13005               25 54.32E-1 thompson
13006      will assign to n the value 3, to i the value 25, to x the value 5.432, and to name the sequence
13007      thompson\0.
13008
13009 18   EXAMPLE 2        The call:
13010               #include <stdio.h>
13011               /* ... */
13012               int i; float x; char name[50];
13013               fscanf(stdin, "%2d%f%*d %[0123456789]", &i, &x, name);
13014      with input:
13015               56789 0123 56a72
13016      will assign to i the value 56 and to x the value 789.0, will skip 0123, and will assign to name the
13017      sequence 56\0. The next character read from the input stream will be a.
13018
13019 19   EXAMPLE 3        To accept repeatedly from stdin a quantity, a unit of measure, and an item name:
13020               #include <stdio.h>
13021               /* ... */
13022               int count; float quant; char units[21], item[21];
13023               do {
13024                       count = fscanf(stdin, "%f%20s of %20s", &quant, units, item);
13025                       fscanf(stdin,"%*[^\n]");
13026               } while (!feof(stdin) && !ferror(stdin));
13027 20   If the stdin stream contains the following lines:
13028               2 quarts of oil
13029               -12.8degrees Celsius
13030               lots of luck
13031               10.0LBS     of
13032               dirt
13033               100ergs of energy
13034
13035 [page 322]
13036
13037      the execution of the above example will be analogous to the following assignments:
13038                quant     =   2; strcpy(units, "quarts"); strcpy(item, "oil");
13039                count     =   3;
13040                quant     =   -12.8; strcpy(units, "degrees");
13041                count     =   2; // "C" fails to match "o"
13042                count     =   0; // "l" fails to match "%f"
13043                quant     =   10.0; strcpy(units, "LBS"); strcpy(item, "dirt");
13044                count     =   3;
13045                count     =   0; // "100e" fails to match "%f"
13046                count     =   EOF;
13047
13048 21   EXAMPLE 4         In:
13049                #include <stdio.h>
13050                /* ... */
13051                int d1, d2, n1, n2, i;
13052                i = sscanf("123", "%d%n%n%d", &d1, &n1, &n2, &d2);
13053      the value 123 is assigned to d1 and the value 3 to n1. Because %n can never get an input failure the value
13054      of 3 is also assigned to n2. The value of d2 is not affected. The value 1 is assigned to i.
13055
13056 22   EXAMPLE 5 In these examples, multibyte characters do have a state-dependent encoding, and the
13057      members of the extended character set that consist of more than one byte each consist of exactly two bytes,
13058      the first of which is denoted here by a and the second by an uppercase letter, but are only recognized as
13059      such when in the alternate shift state. The shift sequences are denoted by (uparrow) and (downarrow), in which the first causes
13060      entry into the alternate shift state.
13061 23   After the call:
13062                #include <stdio.h>
13063                /* ... */
13064                char str[50];
13065                fscanf(stdin, "a%s", str);
13066      with the input line:
13067                a(uparrow) X Y(downarrow) bc
13068      str will contain (uparrow) X Y(downarrow)\0 assuming that none of the bytes of the shift sequences (or of the multibyte
13069      characters, in the more general case) appears to be a single-byte white-space character.
13070 24   In contrast, after the call:
13071                #include <stdio.h>
13072                #include <stddef.h>
13073                /* ... */
13074                wchar_t wstr[50];
13075                fscanf(stdin, "a%ls", wstr);
13076      with the same input line, wstr will contain the two wide characters that correspond to X and Y and a
13077      terminating null wide character.
13078 25   However, the call:
13079
13080
13081
13082
13083 [page 323]
13084
13085              #include <stdio.h>
13086              #include <stddef.h>
13087              /* ... */
13088              wchar_t wstr[50];
13089              fscanf(stdin, "a(uparrow) X(downarrow)%ls", wstr);
13090      with the same input line will return zero due to a matching failure against the (downarrow) sequence in the format
13091      string.
13092 26   Assuming that the first byte of the multibyte character X is the same as the first byte of the multibyte
13093      character Y, after the call:
13094              #include <stdio.h>
13095              #include <stddef.h>
13096              /* ... */
13097              wchar_t wstr[50];
13098              fscanf(stdin, "a(uparrow) Y(downarrow)%ls", wstr);
13099      with the same input line, zero will again be returned, but stdin will be left with a partially consumed
13100      multibyte character.
13101
13102      Forward references: the strtod, strtof, and strtold functions (7.22.1.3), the
13103      strtol, strtoll, strtoul, and strtoull functions (7.22.1.4), conversion state
13104      (7.28.6), the wcrtomb function (7.28.6.3.3).
13105      7.21.6.3 The printf function
13106      Synopsis
13107 1            #include <stdio.h>
13108              int printf(const char * restrict format, ...);
13109      Description
13110 2    The printf function is equivalent to fprintf with the argument stdout interposed
13111      before the arguments to printf.
13112      Returns
13113 3    The printf function returns the number of characters transmitted, or a negative value if
13114      an output or encoding error occurred.
13115      7.21.6.4 The scanf function
13116      Synopsis
13117 1            #include <stdio.h>
13118              int scanf(const char * restrict format, ...);
13119      Description
13120 2    The scanf function is equivalent to fscanf with the argument stdin interposed
13121      before the arguments to scanf.
13122
13123
13124
13125 [page 324]
13126
13127     Returns
13128 3   The scanf function returns the value of the macro EOF if an input failure occurs before
13129     the first conversion (if any) has completed. Otherwise, the scanf function returns the
13130     number of input items assigned, which can be fewer than provided for, or even zero, in
13131     the event of an early matching failure.
13132     7.21.6.5 The snprintf function
13133     Synopsis
13134 1           #include <stdio.h>
13135             int snprintf(char * restrict s, size_t n,
13136                  const char * restrict format, ...);
13137     Description
13138 2   The snprintf function is equivalent to fprintf, except that the output is written into
13139     an array (specified by argument s) rather than to a stream. If n is zero, nothing is written,
13140     and s may be a null pointer. Otherwise, output characters beyond the n-1st are
13141     discarded rather than being written to the array, and a null character is written at the end
13142     of the characters actually written into the array. If copying takes place between objects
13143     that overlap, the behavior is undefined.
13144     Returns
13145 3   The snprintf function returns the number of characters that would have been written
13146     had n been sufficiently large, not counting the terminating null character, or a negative
13147     value if an encoding error occurred. Thus, the null-terminated output has been
13148     completely written if and only if the returned value is nonnegative and less than n.
13149     7.21.6.6 The sprintf function
13150     Synopsis
13151 1           #include <stdio.h>
13152             int sprintf(char * restrict s,
13153                  const char * restrict format, ...);
13154     Description
13155 2   The sprintf function is equivalent to fprintf, except that the output is written into
13156     an array (specified by the argument s) rather than to a stream. A null character is written
13157     at the end of the characters written; it is not counted as part of the returned value. If
13158     copying takes place between objects that overlap, the behavior is undefined.
13159     Returns
13160 3   The sprintf function returns the number of characters written in the array, not
13161     counting the terminating null character, or a negative value if an encoding error occurred.
13162
13163 [page 325]
13164
13165     7.21.6.7 The sscanf function
13166     Synopsis
13167 1          #include <stdio.h>
13168            int sscanf(const char * restrict s,
13169                 const char * restrict format, ...);
13170     Description
13171 2   The sscanf function is equivalent to fscanf, except that input is obtained from a
13172     string (specified by the argument s) rather than from a stream. Reaching the end of the
13173     string is equivalent to encountering end-of-file for the fscanf function. If copying
13174     takes place between objects that overlap, the behavior is undefined.
13175     Returns
13176 3   The sscanf function returns the value of the macro EOF if an input failure occurs
13177     before the first conversion (if any) has completed. Otherwise, the sscanf function
13178     returns the number of input items assigned, which can be fewer than provided for, or even
13179     zero, in the event of an early matching failure.
13180     7.21.6.8 The vfprintf function
13181     Synopsis
13182 1          #include <stdarg.h>
13183            #include <stdio.h>
13184            int vfprintf(FILE * restrict stream,
13185                 const char * restrict format,
13186                 va_list arg);
13187     Description
13188 2   The vfprintf function is equivalent to fprintf, with the variable argument list
13189     replaced by arg, which shall have been initialized by the va_start macro (and
13190     possibly subsequent va_arg calls). The vfprintf function does not invoke the
13191     va_end macro.281)
13192     Returns
13193 3   The vfprintf function returns the number of characters transmitted, or a negative
13194     value if an output or encoding error occurred.
13195 4   EXAMPLE       The following shows the use of the vfprintf function in a general error-reporting routine.
13196
13197
13198
13199
13200     281) As the functions vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf, and
13201          vsscanf invoke the va_arg macro, the value of arg after the return is indeterminate.
13202
13203 [page 326]
13204
13205             #include <stdarg.h>
13206             #include <stdio.h>
13207             void error(char *function_name, char *format, ...)
13208             {
13209                   va_list args;
13210                   va_start(args, format);
13211                   // print out name of function causing error
13212                   fprintf(stderr, "ERROR in %s: ", function_name);
13213                   // print out remainder of message
13214                   vfprintf(stderr, format, args);
13215                   va_end(args);
13216             }
13217
13218     7.21.6.9 The vfscanf function
13219     Synopsis
13220 1           #include <stdarg.h>
13221             #include <stdio.h>
13222             int vfscanf(FILE * restrict stream,
13223                  const char * restrict format,
13224                  va_list arg);
13225     Description
13226 2   The vfscanf function is equivalent to fscanf, with the variable argument list
13227     replaced by arg, which shall have been initialized by the va_start macro (and
13228     possibly subsequent va_arg calls). The vfscanf function does not invoke the
13229     va_end macro.281)
13230     Returns
13231 3   The vfscanf function returns the value of the macro EOF if an input failure occurs
13232     before the first conversion (if any) has completed. Otherwise, the vfscanf function
13233     returns the number of input items assigned, which can be fewer than provided for, or even
13234     zero, in the event of an early matching failure.
13235     7.21.6.10 The vprintf function
13236     Synopsis
13237 1           #include <stdarg.h>
13238             #include <stdio.h>
13239             int vprintf(const char * restrict format,
13240                  va_list arg);
13241     Description
13242 2   The vprintf function is equivalent to printf, with the variable argument list
13243     replaced by arg, which shall have been initialized by the va_start macro (and
13244
13245 [page 327]
13246
13247     possibly subsequent va_arg calls). The vprintf function does not invoke the
13248     va_end macro.281)
13249     Returns
13250 3   The vprintf function returns the number of characters transmitted, or a negative value
13251     if an output or encoding error occurred.
13252     7.21.6.11 The vscanf function
13253     Synopsis
13254 1          #include <stdarg.h>
13255            #include <stdio.h>
13256            int vscanf(const char * restrict format,
13257                 va_list arg);
13258     Description
13259 2   The vscanf function is equivalent to scanf, with the variable argument list replaced
13260     by arg, which shall have been initialized by the va_start macro (and possibly
13261     subsequent va_arg calls). The vscanf function does not invoke the va_end
13262     macro.281)
13263     Returns
13264 3   The vscanf function returns the value of the macro EOF if an input failure occurs
13265     before the first conversion (if any) has completed. Otherwise, the vscanf function
13266     returns the number of input items assigned, which can be fewer than provided for, or even
13267     zero, in the event of an early matching failure.
13268     7.21.6.12 The vsnprintf function
13269     Synopsis
13270 1          #include <stdarg.h>
13271            #include <stdio.h>
13272            int vsnprintf(char * restrict s, size_t n,
13273                 const char * restrict format,
13274                 va_list arg);
13275     Description
13276 2   The vsnprintf function is equivalent to snprintf, with the variable argument list
13277     replaced by arg, which shall have been initialized by the va_start macro (and
13278     possibly subsequent va_arg calls). The vsnprintf function does not invoke the
13279     va_end macro.281) If copying takes place between objects that overlap, the behavior is
13280     undefined.
13281
13282
13283
13284 [page 328]
13285
13286     Returns
13287 3   The vsnprintf function returns the number of characters that would have been written
13288     had n been sufficiently large, not counting the terminating null character, or a negative
13289     value if an encoding error occurred. Thus, the null-terminated output has been
13290     completely written if and only if the returned value is nonnegative and less than n.
13291     7.21.6.13 The vsprintf function
13292     Synopsis
13293 1           #include <stdarg.h>
13294             #include <stdio.h>
13295             int vsprintf(char * restrict s,
13296                  const char * restrict format,
13297                  va_list arg);
13298     Description
13299 2   The vsprintf function is equivalent to sprintf, with the variable argument list
13300     replaced by arg, which shall have been initialized by the va_start macro (and
13301     possibly subsequent va_arg calls). The vsprintf function does not invoke the
13302     va_end macro.281) If copying takes place between objects that overlap, the behavior is
13303     undefined.
13304     Returns
13305 3   The vsprintf function returns the number of characters written in the array, not
13306     counting the terminating null character, or a negative value if an encoding error occurred.
13307     7.21.6.14 The vsscanf function
13308     Synopsis
13309 1           #include <stdarg.h>
13310             #include <stdio.h>
13311             int vsscanf(const char * restrict s,
13312                  const char * restrict format,
13313                  va_list arg);
13314     Description
13315 2   The vsscanf function is equivalent to sscanf, with the variable argument list
13316     replaced by arg, which shall have been initialized by the va_start macro (and
13317     possibly subsequent va_arg calls). The vsscanf function does not invoke the
13318     va_end macro.281)
13319     Returns
13320 3   The vsscanf function returns the value of the macro EOF if an input failure occurs
13321     before the first conversion (if any) has completed. Otherwise, the vsscanf function
13322 [page 329]
13323
13324     returns the number of input items assigned, which can be fewer than provided for, or even
13325     zero, in the event of an early matching failure.
13326     7.21.7 Character input/output functions
13327     7.21.7.1 The fgetc function
13328     Synopsis
13329 1           #include <stdio.h>
13330             int fgetc(FILE *stream);
13331     Description
13332 2   If the end-of-file indicator for the input stream pointed to by stream is not set and a
13333     next character is present, the fgetc function obtains that character as an unsigned
13334     char converted to an int and advances the associated file position indicator for the
13335     stream (if defined).
13336     Returns
13337 3   If the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-
13338     of-file indicator for the stream is set and the fgetc function returns EOF. Otherwise, the
13339     fgetc function returns the next character from the input stream pointed to by stream.
13340     If a read error occurs, the error indicator for the stream is set and the fgetc function
13341     returns EOF.282)
13342     7.21.7.2 The fgets function
13343     Synopsis
13344 1           #include <stdio.h>
13345             char *fgets(char * restrict s, int n,
13346                  FILE * restrict stream);
13347     Description
13348 2   The fgets function reads at most one less than the number of characters specified by n
13349     from the stream pointed to by stream into the array pointed to by s. No additional
13350     characters are read after a new-line character (which is retained) or after end-of-file. A
13351     null character is written immediately after the last character read into the array.
13352     Returns
13353 3   The fgets function returns s if successful. If end-of-file is encountered and no
13354     characters have been read into the array, the contents of the array remain unchanged and a
13355     null pointer is returned. If a read error occurs during the operation, the array contents are
13356     indeterminate and a null pointer is returned.
13357
13358     282) An end-of-file and a read error can be distinguished by use of the feof and ferror functions.
13359
13360 [page 330]
13361
13362     7.21.7.3 The fputc function
13363     Synopsis
13364 1           #include <stdio.h>
13365             int fputc(int c, FILE *stream);
13366     Description
13367 2   The fputc function writes the character specified by c (converted to an unsigned
13368     char) to the output stream pointed to by stream, at the position indicated by the
13369     associated file position indicator for the stream (if defined), and advances the indicator
13370     appropriately. If the file cannot support positioning requests, or if the stream was opened
13371     with append mode, the character is appended to the output stream.
13372     Returns
13373 3   The fputc function returns the character written. If a write error occurs, the error
13374     indicator for the stream is set and fputc returns EOF.
13375     7.21.7.4 The fputs function
13376     Synopsis
13377 1           #include <stdio.h>
13378             int fputs(const char * restrict s,
13379                  FILE * restrict stream);
13380     Description
13381 2   The fputs function writes the string pointed to by s to the stream pointed to by
13382     stream. The terminating null character is not written.
13383     Returns
13384 3   The fputs function returns EOF if a write error occurs; otherwise it returns a
13385     nonnegative value.
13386     7.21.7.5 The getc function
13387     Synopsis
13388 1           #include <stdio.h>
13389             int getc(FILE *stream);
13390     Description
13391 2   The getc function is equivalent to fgetc, except that if it is implemented as a macro, it
13392     may evaluate stream more than once, so the argument should never be an expression
13393     with side effects.
13394
13395
13396
13397
13398 [page 331]
13399
13400     Returns
13401 3   The getc function returns the next character from the input stream pointed to by
13402     stream. If the stream is at end-of-file, the end-of-file indicator for the stream is set and
13403     getc returns EOF. If a read error occurs, the error indicator for the stream is set and
13404     getc returns EOF.
13405     7.21.7.6 The getchar function
13406     Synopsis
13407 1          #include <stdio.h>
13408            int getchar(void);
13409     Description
13410 2   The getchar function is equivalent to getc with the argument stdin.
13411     Returns
13412 3   The getchar function returns the next character from the input stream pointed to by
13413     stdin. If the stream is at end-of-file, the end-of-file indicator for the stream is set and
13414     getchar returns EOF. If a read error occurs, the error indicator for the stream is set and
13415     getchar returns EOF.                                                                       *
13416     7.21.7.7 The putc function
13417     Synopsis
13418 1          #include <stdio.h>
13419            int putc(int c, FILE *stream);
13420     Description
13421 2   The putc function is equivalent to fputc, except that if it is implemented as a macro, it
13422     may evaluate stream more than once, so that argument should never be an expression
13423     with side effects.
13424     Returns
13425 3   The putc function returns the character written. If a write error occurs, the error
13426     indicator for the stream is set and putc returns EOF.
13427     7.21.7.8 The putchar function
13428     Synopsis
13429 1          #include <stdio.h>
13430            int putchar(int c);
13431     Description
13432 2   The putchar function is equivalent to putc with the second argument stdout.
13433
13434
13435 [page 332]
13436
13437     Returns
13438 3   The putchar function returns the character written. If a write error occurs, the error
13439     indicator for the stream is set and putchar returns EOF.
13440     7.21.7.9 The puts function
13441     Synopsis
13442 1           #include <stdio.h>
13443             int puts(const char *s);
13444     Description
13445 2   The puts function writes the string pointed to by s to the stream pointed to by stdout,
13446     and appends a new-line character to the output. The terminating null character is not
13447     written.
13448     Returns
13449 3   The puts function returns EOF if a write error occurs; otherwise it returns a nonnegative
13450     value.
13451     7.21.7.10 The ungetc function
13452     Synopsis
13453 1           #include <stdio.h>
13454             int ungetc(int c, FILE *stream);
13455     Description
13456 2   The ungetc function pushes the character specified by c (converted to an unsigned
13457     char) back onto the input stream pointed to by stream. Pushed-back characters will be
13458     returned by subsequent reads on that stream in the reverse order of their pushing. A
13459     successful intervening call (with the stream pointed to by stream) to a file positioning
13460     function (fseek, fsetpos, or rewind) discards any pushed-back characters for the
13461     stream. The external storage corresponding to the stream is unchanged.
13462 3   One character of pushback is guaranteed. If the ungetc function is called too many
13463     times on the same stream without an intervening read or file positioning operation on that
13464     stream, the operation may fail.
13465 4   If the value of c equals that of the macro EOF, the operation fails and the input stream is
13466     unchanged.
13467 5   A successful call to the ungetc function clears the end-of-file indicator for the stream.
13468     The value of the file position indicator for the stream after reading or discarding all
13469     pushed-back characters shall be the same as it was before the characters were pushed
13470     back. For a text stream, the value of its file position indicator after a successful call to the
13471     ungetc function is unspecified until all pushed-back characters are read or discarded.
13472
13473 [page 333]
13474
13475     For a binary stream, its file position indicator is decremented by each successful call to
13476     the ungetc function; if its value was zero before a call, it is indeterminate after the
13477     call.283)
13478     Returns
13479 6   The ungetc function returns the character pushed back after conversion, or EOF if the
13480     operation fails.
13481     Forward references: file positioning functions (7.21.9).
13482     7.21.8 Direct input/output functions
13483     7.21.8.1 The fread function
13484     Synopsis
13485 1            #include <stdio.h>
13486              size_t fread(void * restrict ptr,
13487                   size_t size, size_t nmemb,
13488                   FILE * restrict stream);
13489     Description
13490 2   The fread function reads, into the array pointed to by ptr, up to nmemb elements
13491     whose size is specified by size, from the stream pointed to by stream. For each
13492     object, size calls are made to the fgetc function and the results stored, in the order
13493     read, in an array of unsigned char exactly overlaying the object. The file position
13494     indicator for the stream (if defined) is advanced by the number of characters successfully
13495     read. If an error occurs, the resulting value of the file position indicator for the stream is
13496     indeterminate. If a partial element is read, its value is indeterminate.
13497     Returns
13498 3   The fread function returns the number of elements successfully read, which may be
13499     less than nmemb if a read error or end-of-file is encountered. If size or nmemb is zero,
13500     fread returns zero and the contents of the array and the state of the stream remain
13501     unchanged.
13502
13503
13504
13505
13506     283) See ''future library directions'' (7.30.9).
13507
13508 [page 334]
13509
13510     7.21.8.2 The fwrite function
13511     Synopsis
13512 1           #include <stdio.h>
13513             size_t fwrite(const void * restrict ptr,
13514                  size_t size, size_t nmemb,
13515                  FILE * restrict stream);
13516     Description
13517 2   The fwrite function writes, from the array pointed to by ptr, up to nmemb elements
13518     whose size is specified by size, to the stream pointed to by stream. For each object,
13519     size calls are made to the fputc function, taking the values (in order) from an array of
13520     unsigned char exactly overlaying the object. The file position indicator for the
13521     stream (if defined) is advanced by the number of characters successfully written. If an
13522     error occurs, the resulting value of the file position indicator for the stream is
13523     indeterminate.
13524     Returns
13525 3   The fwrite function returns the number of elements successfully written, which will be
13526     less than nmemb only if a write error is encountered. If size or nmemb is zero,
13527     fwrite returns zero and the state of the stream remains unchanged.
13528     7.21.9 File positioning functions
13529     7.21.9.1 The fgetpos function
13530     Synopsis
13531 1           #include <stdio.h>
13532             int fgetpos(FILE * restrict stream,
13533                  fpos_t * restrict pos);
13534     Description
13535 2   The fgetpos function stores the current values of the parse state (if any) and file
13536     position indicator for the stream pointed to by stream in the object pointed to by pos.
13537     The values stored contain unspecified information usable by the fsetpos function for
13538     repositioning the stream to its position at the time of the call to the fgetpos function.
13539     Returns
13540 3   If successful, the fgetpos function returns zero; on failure, the fgetpos function
13541     returns nonzero and stores an implementation-defined positive value in errno.
13542     Forward references: the fsetpos function (7.21.9.3).
13543
13544
13545
13546
13547 [page 335]
13548
13549     7.21.9.2 The fseek function
13550     Synopsis
13551 1          #include <stdio.h>
13552            int fseek(FILE *stream, long int offset, int whence);
13553     Description
13554 2   The fseek function sets the file position indicator for the stream pointed to by stream.
13555     If a read or write error occurs, the error indicator for the stream is set and fseek fails.
13556 3   For a binary stream, the new position, measured in characters from the beginning of the
13557     file, is obtained by adding offset to the position specified by whence. The specified
13558     position is the beginning of the file if whence is SEEK_SET, the current value of the file
13559     position indicator if SEEK_CUR, or end-of-file if SEEK_END. A binary stream need not
13560     meaningfully support fseek calls with a whence value of SEEK_END.
13561 4   For a text stream, either offset shall be zero, or offset shall be a value returned by
13562     an earlier successful call to the ftell function on a stream associated with the same file
13563     and whence shall be SEEK_SET.
13564 5   After determining the new position, a successful call to the fseek function undoes any
13565     effects of the ungetc function on the stream, clears the end-of-file indicator for the
13566     stream, and then establishes the new position. After a successful fseek call, the next
13567     operation on an update stream may be either input or output.
13568     Returns
13569 6   The fseek function returns nonzero only for a request that cannot be satisfied.
13570     Forward references: the ftell function (7.21.9.4).
13571     7.21.9.3 The fsetpos function
13572     Synopsis
13573 1          #include <stdio.h>
13574            int fsetpos(FILE *stream, const fpos_t *pos);
13575     Description
13576 2   The fsetpos function sets the mbstate_t object (if any) and file position indicator
13577     for the stream pointed to by stream according to the value of the object pointed to by
13578     pos, which shall be a value obtained from an earlier successful call to the fgetpos
13579     function on a stream associated with the same file. If a read or write error occurs, the
13580     error indicator for the stream is set and fsetpos fails.
13581 3   A successful call to the fsetpos function undoes any effects of the ungetc function
13582     on the stream, clears the end-of-file indicator for the stream, and then establishes the new
13583     parse state and position. After a successful fsetpos call, the next operation on an
13584
13585 [page 336]
13586
13587     update stream may be either input or output.
13588     Returns
13589 4   If successful, the fsetpos function returns zero; on failure, the fsetpos function
13590     returns nonzero and stores an implementation-defined positive value in errno.
13591     7.21.9.4 The ftell function
13592     Synopsis
13593 1           #include <stdio.h>
13594             long int ftell(FILE *stream);
13595     Description
13596 2   The ftell function obtains the current value of the file position indicator for the stream
13597     pointed to by stream. For a binary stream, the value is the number of characters from
13598     the beginning of the file. For a text stream, its file position indicator contains unspecified
13599     information, usable by the fseek function for returning the file position indicator for the
13600     stream to its position at the time of the ftell call; the difference between two such
13601     return values is not necessarily a meaningful measure of the number of characters written
13602     or read.
13603     Returns
13604 3   If successful, the ftell function returns the current value of the file position indicator
13605     for the stream. On failure, the ftell function returns -1L and stores an
13606     implementation-defined positive value in errno.
13607     7.21.9.5 The rewind function
13608     Synopsis
13609 1           #include <stdio.h>
13610             void rewind(FILE *stream);
13611     Description
13612 2   The rewind function sets the file position indicator for the stream pointed to by
13613     stream to the beginning of the file. It is equivalent to
13614             (void)fseek(stream, 0L, SEEK_SET)
13615     except that the error indicator for the stream is also cleared.
13616     Returns
13617 3   The rewind function returns no value.
13618
13619
13620
13621
13622 [page 337]
13623
13624     7.21.10 Error-handling functions
13625     7.21.10.1 The clearerr function
13626     Synopsis
13627 1          #include <stdio.h>
13628            void clearerr(FILE *stream);
13629     Description
13630 2   The clearerr function clears the end-of-file and error indicators for the stream pointed
13631     to by stream.
13632     Returns
13633 3   The clearerr function returns no value.
13634     7.21.10.2 The feof function
13635     Synopsis
13636 1          #include <stdio.h>
13637            int feof(FILE *stream);
13638     Description
13639 2   The feof function tests the end-of-file indicator for the stream pointed to by stream.
13640     Returns
13641 3   The feof function returns nonzero if and only if the end-of-file indicator is set for
13642     stream.
13643     7.21.10.3 The ferror function
13644     Synopsis
13645 1          #include <stdio.h>
13646            int ferror(FILE *stream);
13647     Description
13648 2   The ferror function tests the error indicator for the stream pointed to by stream.
13649     Returns
13650 3   The ferror function returns nonzero if and only if the error indicator is set for
13651     stream.
13652
13653
13654
13655
13656 [page 338]
13657
13658     7.21.10.4 The perror function
13659     Synopsis
13660 1           #include <stdio.h>
13661             void perror(const char *s);
13662     Description
13663 2   The perror function maps the error number in the integer expression errno to an
13664     error message. It writes a sequence of characters to the standard error stream thus: first
13665     (if s is not a null pointer and the character pointed to by s is not the null character), the
13666     string pointed to by s followed by a colon (:) and a space; then an appropriate error
13667     message string followed by a new-line character. The contents of the error message
13668     strings are the same as those returned by the strerror function with argument errno.
13669     Returns
13670 3   The perror function returns no value.
13671     Forward references: the strerror function (7.23.6.2).
13672
13673
13674
13675
13676 [page 339]
13677
13678     7.22 General utilities <stdlib.h>
13679 1   The header <stdlib.h> declares five types and several functions of general utility, and
13680     defines several macros.284)
13681 2   The types declared are size_t and wchar_t (both described in 7.19),
13682              div_t
13683     which is a structure type that is the type of the value returned by the div function,
13684              ldiv_t
13685     which is a structure type that is the type of the value returned by the ldiv function, and
13686              lldiv_t
13687     which is a structure type that is the type of the value returned by the lldiv function.
13688 3   The macros defined are NULL (described in 7.19);
13689              EXIT_FAILURE
13690     and
13691              EXIT_SUCCESS
13692     which expand to integer constant expressions that can be used as the argument to the
13693     exit function to return unsuccessful or successful termination status, respectively, to the
13694     host environment;
13695              RAND_MAX
13696     which expands to an integer constant expression that is the maximum value returned by
13697     the rand function; and
13698              MB_CUR_MAX
13699     which expands to a positive integer expression with type size_t that is the maximum
13700     number of bytes in a multibyte character for the extended character set specified by the
13701     current locale (category LC_CTYPE), which is never greater than MB_LEN_MAX.
13702
13703
13704
13705
13706     284) See ''future library directions'' (7.30.10).
13707
13708 [page 340]
13709
13710     7.22.1 Numeric conversion functions
13711 1   The functions atof, atoi, atol, and atoll need not affect the value of the integer
13712     expression errno on an error. If the value of the result cannot be represented, the
13713     behavior is undefined.
13714     7.22.1.1 The atof function
13715     Synopsis
13716 1           #include <stdlib.h>
13717             double atof(const char *nptr);
13718     Description
13719 2   The atof function converts the initial portion of the string pointed to by nptr to
13720     double representation. Except for the behavior on error, it is equivalent to
13721             strtod(nptr, (char **)NULL)
13722     Returns
13723 3   The atof function returns the converted value.
13724     Forward references: the strtod, strtof, and strtold functions (7.22.1.3).
13725     7.22.1.2 The atoi, atol, and atoll functions
13726     Synopsis
13727 1           #include <stdlib.h>
13728             int atoi(const char *nptr);
13729             long int atol(const char *nptr);
13730             long long int atoll(const char *nptr);
13731     Description
13732 2   The atoi, atol, and atoll functions convert the initial portion of the string pointed
13733     to by nptr to int, long int, and long long int representation, respectively.
13734     Except for the behavior on error, they are equivalent to
13735             atoi: (int)strtol(nptr, (char **)NULL, 10)
13736             atol: strtol(nptr, (char **)NULL, 10)
13737             atoll: strtoll(nptr, (char **)NULL, 10)
13738     Returns
13739 3   The atoi, atol, and atoll functions return the converted value.
13740     Forward references: the strtol, strtoll, strtoul, and strtoull functions
13741     (7.22.1.4).
13742
13743
13744
13745 [page 341]
13746
13747     7.22.1.3 The strtod, strtof, and strtold functions
13748     Synopsis
13749 1          #include <stdlib.h>
13750            double strtod(const char * restrict nptr,
13751                 char ** restrict endptr);
13752            float strtof(const char * restrict nptr,
13753                 char ** restrict endptr);
13754            long double strtold(const char * restrict nptr,
13755                 char ** restrict endptr);
13756     Description
13757 2   The strtod, strtof, and strtold functions convert the initial portion of the string
13758     pointed to by nptr to double, float, and long double representation,
13759     respectively. First, they decompose the input string into three parts: an initial, possibly
13760     empty, sequence of white-space characters (as specified by the isspace function), a
13761     subject sequence resembling a floating-point constant or representing an infinity or NaN;
13762     and a final string of one or more unrecognized characters, including the terminating null
13763     character of the input string. Then, they attempt to convert the subject sequence to a
13764     floating-point number, and return the result.
13765 3   The expected form of the subject sequence is an optional plus or minus sign, then one of
13766     the following:
13767     -- a nonempty sequence of decimal digits optionally containing a decimal-point
13768       character, then an optional exponent part as defined in 6.4.4.2;
13769     -- a 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing a
13770       decimal-point character, then an optional binary exponent part as defined in 6.4.4.2;
13771     -- INF or INFINITY, ignoring case
13772     -- NAN or NAN(n-char-sequenceopt), ignoring case in the NAN part, where:
13773                n-char-sequence:
13774                       digit
13775                       nondigit
13776                       n-char-sequence digit
13777                       n-char-sequence nondigit
13778     The subject sequence is defined as the longest initial subsequence of the input string,
13779     starting with the first non-white-space character, that is of the expected form. The subject
13780     sequence contains no characters if the input string is not of the expected form.
13781 4   If the subject sequence has the expected form for a floating-point number, the sequence of
13782     characters starting with the first digit or the decimal-point character (whichever occurs
13783     first) is interpreted as a floating constant according to the rules of 6.4.4.2, except that the
13784 [page 342]
13785
13786     decimal-point character is used in place of a period, and that if neither an exponent part
13787     nor a decimal-point character appears in a decimal floating point number, or if a binary
13788     exponent part does not appear in a hexadecimal floating point number, an exponent part
13789     of the appropriate type with value zero is assumed to follow the last digit in the string. If
13790     the subject sequence begins with a minus sign, the sequence is interpreted as negated.285)
13791     A character sequence INF or INFINITY is interpreted as an infinity, if representable in
13792     the return type, else like a floating constant that is too large for the range of the return
13793     type. A character sequence NAN or NAN(n-char-sequenceopt), is interpreted as a quiet
13794     NaN, if supported in the return type, else like a subject sequence part that does not have
13795     the expected form; the meaning of the n-char sequences is implementation-defined.286) A
13796     pointer to the final string is stored in the object pointed to by endptr, provided that
13797     endptr is not a null pointer.
13798 5   If the subject sequence has the hexadecimal form and FLT_RADIX is a power of 2, the
13799     value resulting from the conversion is correctly rounded.
13800 6   In other than the "C" locale, additional locale-specific subject sequence forms may be
13801     accepted.
13802 7   If the subject sequence is empty or does not have the expected form, no conversion is
13803     performed; the value of nptr is stored in the object pointed to by endptr, provided
13804     that endptr is not a null pointer.
13805     Recommended practice
13806 8   If the subject sequence has the hexadecimal form, FLT_RADIX is not a power of 2, and
13807     the result is not exactly representable, the result should be one of the two numbers in the
13808     appropriate internal format that are adjacent to the hexadecimal floating source value,
13809     with the extra stipulation that the error should have a correct sign for the current rounding
13810     direction.
13811 9   If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in
13812     <float.h>) significant digits, the result should be correctly rounded. If the subject
13813     sequence D has the decimal form and more than DECIMAL_DIG significant digits,
13814     consider the two bounding, adjacent decimal strings L and U, both having
13815     DECIMAL_DIG significant digits, such that the values of L, D, and U satisfy L <= D <= U.
13816     The result should be one of the (equal or adjacent) values that would be obtained by
13817     correctly rounding L and U according to the current rounding direction, with the extra
13818
13819     285) It is unspecified whether a minus-signed sequence is converted to a negative number directly or by
13820          negating the value resulting from converting the corresponding unsigned sequence (see F.5); the two
13821          methods may yield different results if rounding is toward positive or negative infinity. In either case,
13822          the functions honor the sign of zero if floating-point arithmetic supports signed zeros.
13823     286) An implementation may use the n-char sequence to determine extra information to be represented in
13824          the NaN's significand.
13825
13826 [page 343]
13827
13828      stipulation that the error with respect to D should have a correct sign for the current
13829      rounding direction.287)
13830      Returns
13831 10   The functions return the converted value, if any. If no conversion could be performed,
13832      zero is returned. If the correct value overflows and default rounding is in effect (7.12.1),
13833      plus or minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the
13834      return type and sign of the value), and the value of the macro ERANGE is stored in
13835      errno. If the result underflows (7.12.1), the functions return a value whose magnitude is
13836      no greater than the smallest normalized positive number in the return type; whether
13837      errno acquires the value ERANGE is implementation-defined.
13838      7.22.1.4 The strtol, strtoll, strtoul, and strtoull functions
13839      Synopsis
13840 1            #include <stdlib.h>
13841              long int strtol(
13842                   const char * restrict nptr,
13843                   char ** restrict endptr,
13844                   int base);
13845              long long int strtoll(
13846                   const char * restrict nptr,
13847                   char ** restrict endptr,
13848                   int base);
13849              unsigned long int strtoul(
13850                   const char * restrict nptr,
13851                   char ** restrict endptr,
13852                   int base);
13853              unsigned long long int strtoull(
13854                   const char * restrict nptr,
13855                   char ** restrict endptr,
13856                   int base);
13857      Description
13858 2    The strtol, strtoll, strtoul, and strtoull functions convert the initial
13859      portion of the string pointed to by nptr to long int, long long int, unsigned
13860      long int, and unsigned long long int representation, respectively. First,
13861      they decompose the input string into three parts: an initial, possibly empty, sequence of
13862      white-space characters (as specified by the isspace function), a subject sequence
13863
13864
13865      287) DECIMAL_DIG, defined in <float.h>, should be sufficiently large that L and U will usually round
13866           to the same internal floating value, but if not will round to adjacent values.
13867
13868 [page 344]
13869
13870     resembling an integer represented in some radix determined by the value of base, and a
13871     final string of one or more unrecognized characters, including the terminating null
13872     character of the input string. Then, they attempt to convert the subject sequence to an
13873     integer, and return the result.
13874 3   If the value of base is zero, the expected form of the subject sequence is that of an
13875     integer constant as described in 6.4.4.1, optionally preceded by a plus or minus sign, but
13876     not including an integer suffix. If the value of base is between 2 and 36 (inclusive), the
13877     expected form of the subject sequence is a sequence of letters and digits representing an
13878     integer with the radix specified by base, optionally preceded by a plus or minus sign,
13879     but not including an integer suffix. The letters from a (or A) through z (or Z) are
13880     ascribed the values 10 through 35; only letters and digits whose ascribed values are less
13881     than that of base are permitted. If the value of base is 16, the characters 0x or 0X may
13882     optionally precede the sequence of letters and digits, following the sign if present.
13883 4   The subject sequence is defined as the longest initial subsequence of the input string,
13884     starting with the first non-white-space character, that is of the expected form. The subject
13885     sequence contains no characters if the input string is empty or consists entirely of white
13886     space, or if the first non-white-space character is other than a sign or a permissible letter
13887     or digit.
13888 5   If the subject sequence has the expected form and the value of base is zero, the sequence
13889     of characters starting with the first digit is interpreted as an integer constant according to
13890     the rules of 6.4.4.1. If the subject sequence has the expected form and the value of base
13891     is between 2 and 36, it is used as the base for conversion, ascribing to each letter its value
13892     as given above. If the subject sequence begins with a minus sign, the value resulting from
13893     the conversion is negated (in the return type). A pointer to the final string is stored in the
13894     object pointed to by endptr, provided that endptr is not a null pointer.
13895 6   In other than the "C" locale, additional locale-specific subject sequence forms may be
13896     accepted.
13897 7   If the subject sequence is empty or does not have the expected form, no conversion is
13898     performed; the value of nptr is stored in the object pointed to by endptr, provided
13899     that endptr is not a null pointer.
13900     Returns
13901 8   The strtol, strtoll, strtoul, and strtoull functions return the converted
13902     value, if any. If no conversion could be performed, zero is returned. If the correct value
13903     is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
13904     LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type
13905     and sign of the value, if any), and the value of the macro ERANGE is stored in errno.
13906
13907
13908
13909
13910 [page 345]
13911
13912     7.22.2 Pseudo-random sequence generation functions
13913     7.22.2.1 The rand function
13914     Synopsis
13915 1           #include <stdlib.h>
13916             int rand(void);
13917     Description
13918 2   The rand function computes a sequence of pseudo-random integers in the range 0 to
13919     RAND_MAX.288)
13920 3   The rand function is not required to avoid data races. The implementation shall behave
13921     as if no library function calls the rand function.
13922     Returns
13923 4   The rand function returns a pseudo-random integer.
13924     Environmental limits
13925 5   The value of the RAND_MAX macro shall be at least 32767.
13926     7.22.2.2 The srand function
13927     Synopsis
13928 1           #include <stdlib.h>
13929             void srand(unsigned int seed);
13930     Description
13931 2   The srand function uses the argument as a seed for a new sequence of pseudo-random
13932     numbers to be returned by subsequent calls to rand. If srand is then called with the
13933     same seed value, the sequence of pseudo-random numbers shall be repeated. If rand is
13934     called before any calls to srand have been made, the same sequence shall be generated
13935     as when srand is first called with a seed value of 1.
13936 3   The implementation shall behave as if no library function calls the srand function.
13937     Returns
13938 4   The srand function returns no value.
13939
13940
13941
13942
13943     288) There are no guarantees as to the quality of the random sequence produced and some implementations
13944          are known to produce sequences with distressingly non-random low-order bits. Applications with
13945          particular requirements should use a generator that is known to be sufficient for their needs.
13946
13947 [page 346]
13948
13949 5   EXAMPLE       The following functions define a portable implementation of rand and srand.
13950             static unsigned long int next = 1;
13951             int rand(void)   // RAND_MAX assumed to be 32767
13952             {
13953                   next = next * 1103515245 + 12345;
13954                   return (unsigned int)(next/65536) % 32768;
13955             }
13956             void srand(unsigned int seed)
13957             {
13958                   next = seed;
13959             }
13960
13961     7.22.3 Memory management functions
13962 1   The order and contiguity of storage allocated by successive calls to the
13963     aligned_alloc, calloc, malloc, and realloc functions is unspecified. The
13964     pointer returned if the allocation succeeds is suitably aligned so that it may be assigned to
13965     a pointer to any type of object with a fundamental alignment requirement and then used
13966     to access such an object or an array of such objects in the space allocated (until the space
13967     is explicitly deallocated). The lifetime of an allocated object extends from the allocation
13968     until the deallocation. Each such allocation shall yield a pointer to an object disjoint from
13969     any other object. The pointer returned points to the start (lowest byte address) of the
13970     allocated space. If the space cannot be allocated, a null pointer is returned. If the size of
13971     the space requested is zero, the behavior is implementation-defined: either a null pointer
13972     is returned, or the behavior is as if the size were some nonzero value, except that the
13973     returned pointer shall not be used to access an object.
13974     7.22.3.1 The aligned_alloc function
13975     Synopsis
13976 1           #include <stdlib.h>
13977             void *aligned_alloc(size_t alignment, size_t size);
13978     Description
13979 2   The aligned_alloc function allocates space for an object whose alignment is
13980     specified by alignment, whose size is specified by size, and whose value is
13981     indeterminate. The value of alignment shall be a valid alignment supported by the
13982     implementation and the value of size shall be an integral multiple of alignment.
13983     Returns
13984 3   The aligned_alloc function returns either a null pointer or a pointer to the allocated
13985     space.
13986
13987
13988
13989
13990 [page 347]
13991
13992     7.22.3.2 The calloc function
13993     Synopsis
13994 1           #include <stdlib.h>
13995             void *calloc(size_t nmemb, size_t size);
13996     Description
13997 2   The calloc function allocates space for an array of nmemb objects, each of whose size
13998     is size. The space is initialized to all bits zero.289)
13999     Returns
14000 3   The calloc function returns either a null pointer or a pointer to the allocated space.
14001     7.22.3.3 The free function
14002     Synopsis
14003 1           #include <stdlib.h>
14004             void free(void *ptr);
14005     Description
14006 2   The free function causes the space pointed to by ptr to be deallocated, that is, made
14007     available for further allocation. If ptr is a null pointer, no action occurs. Otherwise, if
14008     the argument does not match a pointer earlier returned by a memory management
14009     function, or if the space has been deallocated by a call to free or realloc, the
14010     behavior is undefined.
14011     Returns
14012 3   The free function returns no value.
14013     7.22.3.4 The malloc function
14014     Synopsis
14015 1           #include <stdlib.h>
14016             void *malloc(size_t size);
14017     Description
14018 2   The malloc function allocates space for an object whose size is specified by size and
14019     whose value is indeterminate.
14020
14021
14022
14023
14024     289) Note that this need not be the same as the representation of floating-point zero or a null pointer
14025          constant.
14026
14027 [page 348]
14028
14029     Returns
14030 3   The malloc function returns either a null pointer or a pointer to the allocated space.
14031     7.22.3.5 The realloc function
14032     Synopsis
14033 1           #include <stdlib.h>
14034             void *realloc(void *ptr, size_t size);
14035     Description
14036 2   The realloc function deallocates the old object pointed to by ptr and returns a
14037     pointer to a new object that has the size specified by size. The contents of the new
14038     object shall be the same as that of the old object prior to deallocation, up to the lesser of
14039     the new and old sizes. Any bytes in the new object beyond the size of the old object have
14040     indeterminate values.
14041 3   If ptr is a null pointer, the realloc function behaves like the malloc function for the
14042     specified size. Otherwise, if ptr does not match a pointer earlier returned by a memory
14043     management function, or if the space has been deallocated by a call to the free or
14044     realloc function, the behavior is undefined. If memory for the new object cannot be
14045     allocated, the old object is not deallocated and its value is unchanged.
14046     Returns
14047 4   The realloc function returns a pointer to the new object (which may have the same
14048     value as a pointer to the old object), or a null pointer if the new object could not be
14049     allocated.
14050     7.22.4 Communication with the environment
14051     7.22.4.1 The abort function
14052     Synopsis
14053 1           #include <stdlib.h>
14054             _Noreturn void abort(void);
14055     Description
14056 2   The abort function causes abnormal program termination to occur, unless the signal
14057     SIGABRT is being caught and the signal handler does not return. Whether open streams
14058     with unwritten buffered data are flushed, open streams are closed, or temporary files are
14059     removed is implementation-defined. An implementation-defined form of the status
14060     unsuccessful termination is returned to the host environment by means of the function
14061     call raise(SIGABRT).
14062
14063
14064
14065
14066 [page 349]
14067
14068     Returns
14069 3   The abort function does not return to its caller.
14070     7.22.4.2 The atexit function
14071     Synopsis
14072 1          #include <stdlib.h>
14073            int atexit(void (*func)(void));
14074     Description
14075 2   The atexit function registers the function pointed to by func, to be called without
14076     arguments at normal program termination.290)
14077     Environmental limits
14078 3   The implementation shall support the registration of at least 32 functions.
14079     Returns
14080 4   The atexit function returns zero if the registration succeeds, nonzero if it fails.
14081     Forward references: the at_quick_exit function (7.22.4.3), the exit function
14082     (7.22.4.4).
14083     7.22.4.3 The at_quick_exit function
14084     Synopsis
14085 1          #include <stdlib.h>
14086            int at_quick_exit(void (*func)(void));
14087     Description
14088 2   The at_quick_exit function registers the function pointed to by func, to be called
14089     without arguments should quick_exit be called.291)
14090     Environmental limits
14091 3   The implementation shall support the registration of at least 32 functions.
14092     Returns
14093 4   The at_quick_exit function returns zero if the registration succeeds, nonzero if it
14094     fails.
14095     Forward references: the quick_exit function (7.22.4.7).
14096
14097
14098     290) The atexit function registrations are distinct from the at_quick_exit registrations, so
14099          applications may need to call both registration functions with the same argument.
14100     291) The at_quick_exit function registrations are distinct from the atexit registrations, so
14101          applications may need to call both registration functions with the same argument.
14102
14103 [page 350]
14104
14105     7.22.4.4 The exit function
14106     Synopsis
14107 1           #include <stdlib.h>
14108             _Noreturn void exit(int status);
14109     Description
14110 2   The exit function causes normal program termination to occur. No functions registered
14111     by the at_quick_exit function are called. If a program calls the exit function
14112     more than once, or calls the quick_exit function in addition to the exit function, the
14113     behavior is undefined.
14114 3   First, all functions registered by the atexit function are called, in the reverse order of
14115     their registration,292) except that a function is called after any previously registered
14116     functions that had already been called at the time it was registered. If, during the call to
14117     any such function, a call to the longjmp function is made that would terminate the call
14118     to the registered function, the behavior is undefined.
14119 4   Next, all open streams with unwritten buffered data are flushed, all open streams are
14120     closed, and all files created by the tmpfile function are removed.
14121 5   Finally, control is returned to the host environment. If the value of status is zero or
14122     EXIT_SUCCESS, an implementation-defined form of the status successful termination is
14123     returned. If the value of status is EXIT_FAILURE, an implementation-defined form
14124     of the status unsuccessful termination is returned. Otherwise the status returned is
14125     implementation-defined.
14126     Returns
14127 6   The exit function cannot return to its caller.
14128     7.22.4.5 The _Exit function
14129     Synopsis
14130 1           #include <stdlib.h>
14131             _Noreturn void _Exit(int status);
14132     Description
14133 2   The _Exit function causes normal program termination to occur and control to be
14134     returned to the host environment. No functions registered by the atexit function, the
14135     at_quick_exit function, or signal handlers registered by the signal function are
14136     called. The status returned to the host environment is determined in the same way as for
14137
14138
14139     292) Each function is called as many times as it was registered, and in the correct order with respect to
14140          other registered functions.
14141
14142 [page 351]
14143
14144     the exit function (7.22.4.4). Whether open streams with unwritten buffered data are
14145     flushed, open streams are closed, or temporary files are removed is implementation-
14146     defined.
14147     Returns
14148 3   The _Exit function cannot return to its caller.
14149     7.22.4.6 The getenv function
14150     Synopsis
14151 1           #include <stdlib.h>
14152             char *getenv(const char *name);
14153     Description
14154 2   The getenv function searches an environment list, provided by the host environment,
14155     for a string that matches the string pointed to by name. The set of environment names
14156     and the method for altering the environment list are implementation-defined. The
14157     getenv function need not avoid data races with other threads of execution that modify
14158     the environment list.293)
14159 3   The implementation shall behave as if no library function calls the getenv function.
14160     Returns
14161 4   The getenv function returns a pointer to a string associated with the matched list
14162     member. The string pointed to shall not be modified by the program, but may be
14163     overwritten by a subsequent call to the getenv function. If the specified name cannot
14164     be found, a null pointer is returned.
14165     7.22.4.7 The quick_exit function
14166     Synopsis
14167 1           #include <stdlib.h>
14168             _Noreturn void quick_exit(int status);
14169     Description
14170 2   The quick_exit function causes normal program termination to occur. No functions
14171     registered by the atexit function or signal handlers registered by the signal function
14172     are called. If a program calls the quick_exit function more than once, or calls the
14173     exit function in addition to the quick_exit function, the behavior is undefined.
14174 3   The quick_exit function first calls all functions registered by the at_quick_exit
14175     function, in the reverse order of their registration,294) except that a function is called after
14176
14177
14178     293) Many implementations provide non-standard functions that modify the environment list.
14179
14180 [page 352]
14181
14182     any previously registered functions that had already been called at the time it was
14183     registered. If, during the call to any such function, a call to the longjmp function is
14184     made that would terminate the call to the registered function, the behavior is undefined.
14185 4   Then control is returned to the host environment by means of the function call
14186     _Exit(status).
14187     Returns
14188 5   The quick_exit function cannot return to its caller.
14189     7.22.4.8 The system function
14190     Synopsis
14191 1           #include <stdlib.h>
14192             int system(const char *string);
14193     Description
14194 2   If string is a null pointer, the system function determines whether the host
14195     environment has a command processor. If string is not a null pointer, the system
14196     function passes the string pointed to by string to that command processor to be
14197     executed in a manner which the implementation shall document; this might then cause the
14198     program calling system to behave in a non-conforming manner or to terminate.
14199     Returns
14200 3   If the argument is a null pointer, the system function returns nonzero only if a
14201     command processor is available. If the argument is not a null pointer, and the system
14202     function does return, it returns an implementation-defined value.
14203     7.22.5 Searching and sorting utilities
14204 1   These utilities make use of a comparison function to search or sort arrays of unspecified
14205     type. Where an argument declared as size_t nmemb specifies the length of the array
14206     for a function, nmemb can have the value zero on a call to that function; the comparison
14207     function is not called, a search finds no matching element, and sorting performs no
14208     rearrangement. Pointer arguments on such a call shall still have valid values, as described
14209     in 7.1.4.
14210 2   The implementation shall ensure that the second argument of the comparison function
14211     (when called from bsearch), or both arguments (when called from qsort), are
14212     pointers to elements of the array.295) The first argument when called from bsearch
14213     shall equal key.
14214
14215
14216
14217     294) Each function is called as many times as it was registered, and in the correct order with respect to
14218          other registered functions.
14219
14220 [page 353]
14221
14222 3   The comparison function shall not alter the contents of the array. The implementation
14223     may reorder elements of the array between calls to the comparison function, but shall not
14224     alter the contents of any individual element.
14225 4   When the same objects (consisting of size bytes, irrespective of their current positions
14226     in the array) are passed more than once to the comparison function, the results shall be
14227     consistent with one another. That is, for qsort they shall define a total ordering on the
14228     array, and for bsearch the same object shall always compare the same way with the
14229     key.
14230 5   A sequence point occurs immediately before and immediately after each call to the
14231     comparison function, and also between any call to the comparison function and any
14232     movement of the objects passed as arguments to that call.
14233     7.22.5.1 The bsearch function
14234     Synopsis
14235 1            #include <stdlib.h>
14236              void *bsearch(const void *key, const void *base,
14237                   size_t nmemb, size_t size,
14238                   int (*compar)(const void *, const void *));
14239     Description
14240 2   The bsearch function searches an array of nmemb objects, the initial element of which
14241     is pointed to by base, for an element that matches the object pointed to by key. The
14242     size of each element of the array is specified by size.
14243 3   The comparison function pointed to by compar is called with two arguments that point
14244     to the key object and to an array element, in that order. The function shall return an
14245     integer less than, equal to, or greater than zero if the key object is considered,
14246     respectively, to be less than, to match, or to be greater than the array element. The array
14247     shall consist of: all the elements that compare less than, all the elements that compare
14248     equal to, and all the elements that compare greater than the key object, in that order.296)
14249     Returns
14250 4   The bsearch function returns a pointer to a matching element of the array, or a null
14251     pointer if no match is found. If two elements compare as equal, which element is
14252
14253
14254     295) That is, if the value passed is p, then the following expressions are always nonzero:
14255                   ((char *)p - (char *)base) % size == 0
14256                   (char *)p >= (char *)base
14257                   (char *)p < (char *)base + nmemb * size
14258
14259     296) In practice, the entire array is sorted according to the comparison function.
14260
14261 [page 354]
14262
14263     matched is unspecified.
14264     7.22.5.2 The qsort function
14265     Synopsis
14266 1           #include <stdlib.h>
14267             void qsort(void *base, size_t nmemb, size_t size,
14268                  int (*compar)(const void *, const void *));
14269     Description
14270 2   The qsort function sorts an array of nmemb objects, the initial element of which is
14271     pointed to by base. The size of each object is specified by size.
14272 3   The contents of the array are sorted into ascending order according to a comparison
14273     function pointed to by compar, which is called with two arguments that point to the
14274     objects being compared. The function shall return an integer less than, equal to, or
14275     greater than zero if the first argument is considered to be respectively less than, equal to,
14276     or greater than the second.
14277 4   If two elements compare as equal, their order in the resulting sorted array is unspecified.
14278     Returns
14279 5   The qsort function returns no value.
14280     7.22.6 Integer arithmetic functions
14281     7.22.6.1 The abs, labs and llabs functions
14282     Synopsis
14283 1           #include <stdlib.h>
14284             int abs(int j);
14285             long int labs(long int j);
14286             long long int llabs(long long int j);
14287     Description
14288 2   The abs, labs, and llabs functions compute the absolute value of an integer j. If the
14289     result cannot be represented, the behavior is undefined.297)
14290     Returns
14291 3   The abs, labs, and llabs, functions return the absolute value.
14292
14293
14294
14295
14296     297) The absolute value of the most negative number cannot be represented in two's complement.
14297
14298 [page 355]
14299
14300     7.22.6.2 The div, ldiv, and lldiv functions
14301     Synopsis
14302 1            #include <stdlib.h>
14303              div_t div(int numer, int denom);
14304              ldiv_t ldiv(long int numer, long int denom);
14305              lldiv_t lldiv(long long int numer, long long int denom);
14306     Description
14307 2   The div, ldiv, and lldiv, functions compute numer / denom and numer %
14308     denom in a single operation.
14309     Returns
14310 3   The div, ldiv, and lldiv functions return a structure of type div_t, ldiv_t, and
14311     lldiv_t, respectively, comprising both the quotient and the remainder. The structures
14312     shall contain (in either order) the members quot (the quotient) and rem (the remainder),
14313     each of which has the same type as the arguments numer and denom. If either part of
14314     the result cannot be represented, the behavior is undefined.
14315     7.22.7 Multibyte/wide character conversion functions
14316 1   The behavior of the multibyte character functions is affected by the LC_CTYPE category
14317     of the current locale. For a state-dependent encoding, each function is placed into its
14318     initial conversion state at program startup and can be returned to that state by a call for
14319     which its character pointer argument, s, is a null pointer. Subsequent calls with s as
14320     other than a null pointer cause the internal conversion state of the function to be altered as
14321     necessary. A call with s as a null pointer causes these functions to return a nonzero value
14322     if encodings have state dependency, and zero otherwise.298) Changing the LC_CTYPE
14323     category causes the conversion state of these functions to be indeterminate.
14324     7.22.7.1 The mblen function
14325     Synopsis
14326 1            #include <stdlib.h>
14327              int mblen(const char *s, size_t n);
14328     Description
14329 2   If s is not a null pointer, the mblen function determines the number of bytes contained
14330     in the multibyte character pointed to by s. Except that the conversion state of the
14331     mbtowc function is not affected, it is equivalent to
14332
14333
14334
14335     298) If the locale employs special bytes to change the shift state, these bytes do not produce separate wide
14336          character codes, but are grouped with an adjacent multibyte character.
14337
14338 [page 356]
14339
14340             mbtowc((wchar_t *)0, (const char *)0, 0);
14341             mbtowc((wchar_t *)0, s, n);
14342 3   The implementation shall behave as if no library function calls the mblen function.
14343     Returns
14344 4   If s is a null pointer, the mblen function returns a nonzero or zero value, if multibyte
14345     character encodings, respectively, do or do not have state-dependent encodings. If s is
14346     not a null pointer, the mblen function either returns 0 (if s points to the null character),
14347     or returns the number of bytes that are contained in the multibyte character (if the next n
14348     or fewer bytes form a valid multibyte character), or returns -1 (if they do not form a valid
14349     multibyte character).
14350     Forward references: the mbtowc function (7.22.7.2).
14351     7.22.7.2 The mbtowc function
14352     Synopsis
14353 1           #include <stdlib.h>
14354             int mbtowc(wchar_t * restrict pwc,
14355                  const char * restrict s,
14356                  size_t n);
14357     Description
14358 2   If s is not a null pointer, the mbtowc function inspects at most n bytes beginning with
14359     the byte pointed to by s to determine the number of bytes needed to complete the next
14360     multibyte character (including any shift sequences). If the function determines that the
14361     next multibyte character is complete and valid, it determines the value of the
14362     corresponding wide character and then, if pwc is not a null pointer, stores that value in
14363     the object pointed to by pwc. If the corresponding wide character is the null wide
14364     character, the function is left in the initial conversion state.
14365 3   The implementation shall behave as if no library function calls the mbtowc function.
14366     Returns
14367 4   If s is a null pointer, the mbtowc function returns a nonzero or zero value, if multibyte
14368     character encodings, respectively, do or do not have state-dependent encodings. If s is
14369     not a null pointer, the mbtowc function either returns 0 (if s points to the null character),
14370     or returns the number of bytes that are contained in the converted multibyte character (if
14371     the next n or fewer bytes form a valid multibyte character), or returns -1 (if they do not
14372     form a valid multibyte character).
14373 5   In no case will the value returned be greater than n or the value of the MB_CUR_MAX
14374     macro.
14375
14376
14377 [page 357]
14378
14379     7.22.7.3 The wctomb function
14380     Synopsis
14381 1          #include <stdlib.h>
14382            int wctomb(char *s, wchar_t wc);
14383     Description
14384 2   The wctomb function determines the number of bytes needed to represent the multibyte
14385     character corresponding to the wide character given by wc (including any shift
14386     sequences), and stores the multibyte character representation in the array whose first
14387     element is pointed to by s (if s is not a null pointer). At most MB_CUR_MAX characters
14388     are stored. If wc is a null wide character, a null byte is stored, preceded by any shift
14389     sequence needed to restore the initial shift state, and the function is left in the initial
14390     conversion state.
14391 3   The implementation shall behave as if no library function calls the wctomb function.
14392     Returns
14393 4   If s is a null pointer, the wctomb function returns a nonzero or zero value, if multibyte
14394     character encodings, respectively, do or do not have state-dependent encodings. If s is
14395     not a null pointer, the wctomb function returns -1 if the value of wc does not correspond
14396     to a valid multibyte character, or returns the number of bytes that are contained in the
14397     multibyte character corresponding to the value of wc.
14398 5   In no case will the value returned be greater than the value of the MB_CUR_MAX macro.
14399     7.22.8 Multibyte/wide string conversion functions
14400 1   The behavior of the multibyte string functions is affected by the LC_CTYPE category of
14401     the current locale.
14402     7.22.8.1 The mbstowcs function
14403     Synopsis
14404 1          #include <stdlib.h>
14405            size_t mbstowcs(wchar_t * restrict pwcs,
14406                 const char * restrict s,
14407                 size_t n);
14408     Description
14409 2   The mbstowcs function converts a sequence of multibyte characters that begins in the
14410     initial shift state from the array pointed to by s into a sequence of corresponding wide
14411     characters and stores not more than n wide characters into the array pointed to by pwcs.
14412     No multibyte characters that follow a null character (which is converted into a null wide
14413     character) will be examined or converted. Each multibyte character is converted as if by
14414     a call to the mbtowc function, except that the conversion state of the mbtowc function is
14415 [page 358]
14416
14417     not affected.
14418 3   No more than n elements will be modified in the array pointed to by pwcs. If copying
14419     takes place between objects that overlap, the behavior is undefined.
14420     Returns
14421 4   If an invalid multibyte character is encountered, the mbstowcs function returns
14422     (size_t)(-1). Otherwise, the mbstowcs function returns the number of array
14423     elements modified, not including a terminating null wide character, if any.299)
14424     7.22.8.2 The wcstombs function
14425     Synopsis
14426 1            #include <stdlib.h>
14427              size_t wcstombs(char * restrict s,
14428                   const wchar_t * restrict pwcs,
14429                   size_t n);
14430     Description
14431 2   The wcstombs function converts a sequence of wide characters from the array pointed
14432     to by pwcs into a sequence of corresponding multibyte characters that begins in the
14433     initial shift state, and stores these multibyte characters into the array pointed to by s,
14434     stopping if a multibyte character would exceed the limit of n total bytes or if a null
14435     character is stored. Each wide character is converted as if by a call to the wctomb
14436     function, except that the conversion state of the wctomb function is not affected.
14437 3   No more than n bytes will be modified in the array pointed to by s. If copying takes place
14438     between objects that overlap, the behavior is undefined.
14439     Returns
14440 4   If a wide character is encountered that does not correspond to a valid multibyte character,
14441     the wcstombs function returns (size_t)(-1). Otherwise, the wcstombs function
14442     returns the number of bytes modified, not including a terminating null character, if
14443     any.299)
14444
14445
14446
14447
14448     299) The array will not be null-terminated if the value returned is n.
14449
14450 [page 359]
14451
14452     7.23 String handling <string.h>
14453     7.23.1 String function conventions
14454 1   The header <string.h> declares one type and several functions, and defines one
14455     macro useful for manipulating arrays of character type and other objects treated as arrays
14456     of character type.300) The type is size_t and the macro is NULL (both described in
14457     7.19). Various methods are used for determining the lengths of the arrays, but in all cases
14458     a char * or void * argument points to the initial (lowest addressed) character of the
14459     array. If an array is accessed beyond the end of an object, the behavior is undefined.
14460 2   Where an argument declared as size_t n specifies the length of the array for a
14461     function, n can have the value zero on a call to that function. Unless explicitly stated
14462     otherwise in the description of a particular function in this subclause, pointer arguments
14463     on such a call shall still have valid values, as described in 7.1.4. On such a call, a
14464     function that locates a character finds no occurrence, a function that compares two
14465     character sequences returns zero, and a function that copies characters copies zero
14466     characters.
14467 3   For all functions in this subclause, each character shall be interpreted as if it had the type
14468     unsigned char (and therefore every possible object representation is valid and has a
14469     different value).
14470     7.23.2 Copying functions
14471     7.23.2.1 The memcpy function
14472     Synopsis
14473 1            #include <string.h>
14474              void *memcpy(void * restrict s1,
14475                   const void * restrict s2,
14476                   size_t n);
14477     Description
14478 2   The memcpy function copies n characters from the object pointed to by s2 into the
14479     object pointed to by s1. If copying takes place between objects that overlap, the behavior
14480     is undefined.
14481     Returns
14482 3   The memcpy function returns the value of s1.
14483
14484
14485
14486
14487     300) See ''future library directions'' (7.30.11).
14488
14489 [page 360]
14490
14491     7.23.2.2 The memmove function
14492     Synopsis
14493 1           #include <string.h>
14494             void *memmove(void *s1, const void *s2, size_t n);
14495     Description
14496 2   The memmove function copies n characters from the object pointed to by s2 into the
14497     object pointed to by s1. Copying takes place as if the n characters from the object
14498     pointed to by s2 are first copied into a temporary array of n characters that does not
14499     overlap the objects pointed to by s1 and s2, and then the n characters from the
14500     temporary array are copied into the object pointed to by s1.
14501     Returns
14502 3   The memmove function returns the value of s1.
14503     7.23.2.3 The strcpy function
14504     Synopsis
14505 1           #include <string.h>
14506             char *strcpy(char * restrict s1,
14507                  const char * restrict s2);
14508     Description
14509 2   The strcpy function copies the string pointed to by s2 (including the terminating null
14510     character) into the array pointed to by s1. If copying takes place between objects that
14511     overlap, the behavior is undefined.
14512     Returns
14513 3   The strcpy function returns the value of s1.
14514     7.23.2.4 The strncpy function
14515     Synopsis
14516 1           #include <string.h>
14517             char *strncpy(char * restrict s1,
14518                  const char * restrict s2,
14519                  size_t n);
14520     Description
14521 2   The strncpy function copies not more than n characters (characters that follow a null
14522     character are not copied) from the array pointed to by s2 to the array pointed to by
14523
14524
14525
14526
14527 [page 361]
14528
14529     s1.301) If copying takes place between objects that overlap, the behavior is undefined.
14530 3   If the array pointed to by s2 is a string that is shorter than n characters, null characters
14531     are appended to the copy in the array pointed to by s1, until n characters in all have been
14532     written.
14533     Returns
14534 4   The strncpy function returns the value of s1.
14535     7.23.3 Concatenation functions
14536     7.23.3.1 The strcat function
14537     Synopsis
14538 1            #include <string.h>
14539              char *strcat(char * restrict s1,
14540                   const char * restrict s2);
14541     Description
14542 2   The strcat function appends a copy of the string pointed to by s2 (including the
14543     terminating null character) to the end of the string pointed to by s1. The initial character
14544     of s2 overwrites the null character at the end of s1. If copying takes place between
14545     objects that overlap, the behavior is undefined.
14546     Returns
14547 3   The strcat function returns the value of s1.
14548     7.23.3.2 The strncat function
14549     Synopsis
14550 1            #include <string.h>
14551              char *strncat(char * restrict s1,
14552                   const char * restrict s2,
14553                   size_t n);
14554     Description
14555 2   The strncat function appends not more than n characters (a null character and
14556     characters that follow it are not appended) from the array pointed to by s2 to the end of
14557     the string pointed to by s1. The initial character of s2 overwrites the null character at the
14558     end of s1. A terminating null character is always appended to the result.302) If copying
14559
14560     301) Thus, if there is no null character in the first n characters of the array pointed to by s2, the result will
14561          not be null-terminated.
14562     302) Thus, the maximum number of characters that can end up in the array pointed to by s1 is
14563          strlen(s1)+n+1.
14564
14565 [page 362]
14566
14567     takes place between objects that overlap, the behavior is undefined.
14568     Returns
14569 3   The strncat function returns the value of s1.
14570     Forward references: the strlen function (7.23.6.3).
14571     7.23.4 Comparison functions
14572 1   The sign of a nonzero value returned by the comparison functions memcmp, strcmp,
14573     and strncmp is determined by the sign of the difference between the values of the first
14574     pair of characters (both interpreted as unsigned char) that differ in the objects being
14575     compared.
14576     7.23.4.1 The memcmp function
14577     Synopsis
14578 1           #include <string.h>
14579             int memcmp(const void *s1, const void *s2, size_t n);
14580     Description
14581 2   The memcmp function compares the first n characters of the object pointed to by s1 to
14582     the first n characters of the object pointed to by s2.303)
14583     Returns
14584 3   The memcmp function returns an integer greater than, equal to, or less than zero,
14585     accordingly as the object pointed to by s1 is greater than, equal to, or less than the object
14586     pointed to by s2.
14587     7.23.4.2 The strcmp function
14588     Synopsis
14589 1           #include <string.h>
14590             int strcmp(const char *s1, const char *s2);
14591     Description
14592 2   The strcmp function compares the string pointed to by s1 to the string pointed to by
14593     s2.
14594     Returns
14595 3   The strcmp function returns an integer greater than, equal to, or less than zero,
14596     accordingly as the string pointed to by s1 is greater than, equal to, or less than the string
14597
14598     303) The contents of ''holes'' used as padding for purposes of alignment within structure objects are
14599          indeterminate. Strings shorter than their allocated space and unions may also cause problems in
14600          comparison.
14601
14602 [page 363]
14603
14604     pointed to by s2.
14605     7.23.4.3 The strcoll function
14606     Synopsis
14607 1          #include <string.h>
14608            int strcoll(const char *s1, const char *s2);
14609     Description
14610 2   The strcoll function compares the string pointed to by s1 to the string pointed to by
14611     s2, both interpreted as appropriate to the LC_COLLATE category of the current locale.
14612     Returns
14613 3   The strcoll function returns an integer greater than, equal to, or less than zero,
14614     accordingly as the string pointed to by s1 is greater than, equal to, or less than the string
14615     pointed to by s2 when both are interpreted as appropriate to the current locale.
14616     7.23.4.4 The strncmp function
14617     Synopsis
14618 1          #include <string.h>
14619            int strncmp(const char *s1, const char *s2, size_t n);
14620     Description
14621 2   The strncmp function compares not more than n characters (characters that follow a
14622     null character are not compared) from the array pointed to by s1 to the array pointed to
14623     by s2.
14624     Returns
14625 3   The strncmp function returns an integer greater than, equal to, or less than zero,
14626     accordingly as the possibly null-terminated array pointed to by s1 is greater than, equal
14627     to, or less than the possibly null-terminated array pointed to by s2.
14628     7.23.4.5 The strxfrm function
14629     Synopsis
14630 1          #include <string.h>
14631            size_t strxfrm(char * restrict s1,
14632                 const char * restrict s2,
14633                 size_t n);
14634     Description
14635 2   The strxfrm function transforms the string pointed to by s2 and places the resulting
14636     string into the array pointed to by s1. The transformation is such that if the strcmp
14637     function is applied to two transformed strings, it returns a value greater than, equal to, or
14638
14639 [page 364]
14640
14641     less than zero, corresponding to the result of the strcoll function applied to the same
14642     two original strings. No more than n characters are placed into the resulting array
14643     pointed to by s1, including the terminating null character. If n is zero, s1 is permitted to
14644     be a null pointer. If copying takes place between objects that overlap, the behavior is
14645     undefined.
14646     Returns
14647 3   The strxfrm function returns the length of the transformed string (not including the
14648     terminating null character). If the value returned is n or more, the contents of the array
14649     pointed to by s1 are indeterminate.
14650 4   EXAMPLE The value of the following expression is the size of the array needed to hold the
14651     transformation of the string pointed to by s.
14652             1 + strxfrm(NULL, s, 0)
14653
14654     7.23.5 Search functions
14655     7.23.5.1 The memchr function
14656     Synopsis
14657 1           #include <string.h>
14658             void *memchr(const void *s, int c, size_t n);
14659     Description
14660 2   The memchr function locates the first occurrence of c (converted to an unsigned
14661     char) in the initial n characters (each interpreted as unsigned char) of the object
14662     pointed to by s. The implementation shall behave as if it reads the characters sequentially
14663     and stops as soon as a matching character is found.
14664     Returns
14665 3   The memchr function returns a pointer to the located character, or a null pointer if the
14666     character does not occur in the object.
14667     7.23.5.2 The strchr function
14668     Synopsis
14669 1           #include <string.h>
14670             char *strchr(const char *s, int c);
14671     Description
14672 2   The strchr function locates the first occurrence of c (converted to a char) in the
14673     string pointed to by s. The terminating null character is considered to be part of the
14674     string.
14675
14676
14677
14678 [page 365]
14679
14680     Returns
14681 3   The strchr function returns a pointer to the located character, or a null pointer if the
14682     character does not occur in the string.
14683     7.23.5.3 The strcspn function
14684     Synopsis
14685 1          #include <string.h>
14686            size_t strcspn(const char *s1, const char *s2);
14687     Description
14688 2   The strcspn function computes the length of the maximum initial segment of the string
14689     pointed to by s1 which consists entirely of characters not from the string pointed to by
14690     s2.
14691     Returns
14692 3   The strcspn function returns the length of the segment.
14693     7.23.5.4 The strpbrk function
14694     Synopsis
14695 1          #include <string.h>
14696            char *strpbrk(const char *s1, const char *s2);
14697     Description
14698 2   The strpbrk function locates the first occurrence in the string pointed to by s1 of any
14699     character from the string pointed to by s2.
14700     Returns
14701 3   The strpbrk function returns a pointer to the character, or a null pointer if no character
14702     from s2 occurs in s1.
14703     7.23.5.5 The strrchr function
14704     Synopsis
14705 1          #include <string.h>
14706            char *strrchr(const char *s, int c);
14707     Description
14708 2   The strrchr function locates the last occurrence of c (converted to a char) in the
14709     string pointed to by s. The terminating null character is considered to be part of the
14710     string.
14711
14712
14713
14714
14715 [page 366]
14716
14717     Returns
14718 3   The strrchr function returns a pointer to the character, or a null pointer if c does not
14719     occur in the string.
14720     7.23.5.6 The strspn function
14721     Synopsis
14722 1           #include <string.h>
14723             size_t strspn(const char *s1, const char *s2);
14724     Description
14725 2   The strspn function computes the length of the maximum initial segment of the string
14726     pointed to by s1 which consists entirely of characters from the string pointed to by s2.
14727     Returns
14728 3   The strspn function returns the length of the segment.
14729     7.23.5.7 The strstr function
14730     Synopsis
14731 1           #include <string.h>
14732             char *strstr(const char *s1, const char *s2);
14733     Description
14734 2   The strstr function locates the first occurrence in the string pointed to by s1 of the
14735     sequence of characters (excluding the terminating null character) in the string pointed to
14736     by s2.
14737     Returns
14738 3   The strstr function returns a pointer to the located string, or a null pointer if the string
14739     is not found. If s2 points to a string with zero length, the function returns s1.
14740     7.23.5.8 The strtok function
14741     Synopsis
14742 1           #include <string.h>
14743             char *strtok(char * restrict s1,
14744                  const char * restrict s2);
14745     Description
14746 2   A sequence of calls to the strtok function breaks the string pointed to by s1 into a
14747     sequence of tokens, each of which is delimited by a character from the string pointed to
14748     by s2. The first call in the sequence has a non-null first argument; subsequent calls in the
14749     sequence have a null first argument. The separator string pointed to by s2 may be
14750     different from call to call.
14751 [page 367]
14752
14753 3   The first call in the sequence searches the string pointed to by s1 for the first character
14754     that is not contained in the current separator string pointed to by s2. If no such character
14755     is found, then there are no tokens in the string pointed to by s1 and the strtok function
14756     returns a null pointer. If such a character is found, it is the start of the first token.
14757 4   The strtok function then searches from there for a character that is contained in the
14758     current separator string. If no such character is found, the current token extends to the
14759     end of the string pointed to by s1, and subsequent searches for a token will return a null
14760     pointer. If such a character is found, it is overwritten by a null character, which
14761     terminates the current token. The strtok function saves a pointer to the following
14762     character, from which the next search for a token will start.
14763 5   Each subsequent call, with a null pointer as the value of the first argument, starts
14764     searching from the saved pointer and behaves as described above.
14765 6   The strtok function is not required to avoid data races. The implementation shall
14766     behave as if no library function calls the strtok function.
14767     Returns
14768 7   The strtok function returns a pointer to the first character of a token, or a null pointer
14769     if there is no token.
14770 8   EXAMPLE
14771            #include <string.h>
14772            static char str[] = "?a???b,,,#c";
14773            char *t;
14774            t   =   strtok(str, "?");      //   t   points to the token "a"
14775            t   =   strtok(NULL, ",");     //   t   points to the token "??b"
14776            t   =   strtok(NULL, "#,");    //   t   points to the token "c"
14777            t   =   strtok(NULL, "?");     //   t   is a null pointer
14778
14779     7.23.6 Miscellaneous functions
14780     7.23.6.1 The memset function
14781     Synopsis
14782 1          #include <string.h>
14783            void *memset(void *s, int c, size_t n);
14784     Description
14785 2   The memset function copies the value of c (converted to an unsigned char) into
14786     each of the first n characters of the object pointed to by s.
14787     Returns
14788 3   The memset function returns the value of s.
14789
14790
14791
14792 [page 368]
14793
14794     7.23.6.2 The strerror function
14795     Synopsis
14796 1           #include <string.h>
14797             char *strerror(int errnum);
14798     Description
14799 2   The strerror function maps the number in errnum to a message string. Typically,
14800     the values for errnum come from errno, but strerror shall map any value of type
14801     int to a message.
14802 3   The strerror function is not required to avoid data races. The implementation shall
14803     behave as if no library function calls the strerror function.
14804     Returns
14805 4   The strerror function returns a pointer to the string, the contents of which are locale-
14806     specific. The array pointed to shall not be modified by the program, but may be
14807     overwritten by a subsequent call to the strerror function.
14808     7.23.6.3 The strlen function
14809     Synopsis
14810 1           #include <string.h>
14811             size_t strlen(const char *s);
14812     Description
14813 2   The strlen function computes the length of the string pointed to by s.
14814     Returns
14815 3   The strlen function returns the number of characters that precede the terminating null
14816     character.
14817
14818
14819
14820
14821 [page 369]
14822
14823     7.24 Type-generic math <tgmath.h>
14824 1   The header <tgmath.h> includes the headers <math.h> and <complex.h> and
14825     defines several type-generic macros.
14826 2   Of the <math.h> and <complex.h> functions without an f (float) or l (long
14827     double) suffix, several have one or more parameters whose corresponding real type is
14828     double. For each such function, except modf, there is a corresponding type-generic
14829     macro.304) The parameters whose corresponding real type is double in the function
14830     synopsis are generic parameters. Use of the macro invokes a function whose
14831     corresponding real type and type domain are determined by the arguments for the generic
14832     parameters.305)
14833 3   Use of the macro invokes a function whose generic parameters have the corresponding
14834     real type determined as follows:
14835     -- First, if any argument for generic parameters has type long double, the type
14836       determined is long double.
14837     -- Otherwise, if any argument for generic parameters has type double or is of integer
14838       type, the type determined is double.
14839     -- Otherwise, the type determined is float.
14840 4   For each unsuffixed function in <math.h> for which there is a function in
14841     <complex.h> with the same name except for a c prefix, the corresponding type-
14842     generic macro (for both functions) has the same name as the function in <math.h>. The
14843     corresponding type-generic macro for fabs and cabs is fabs.
14844
14845
14846
14847
14848     304) Like other function-like macros in Standard libraries, each type-generic macro can be suppressed to
14849          make available the corresponding ordinary function.
14850     305) If the type of the argument is not compatible with the type of the parameter for the selected function,
14851          the behavior is undefined.
14852
14853 [page 370]
14854
14855              <math.h>         <complex.h>              type-generic
14856               function           function                 macro
14857                acos              cacos                   acos
14858                asin              casin                   asin
14859                atan              catan                   atan
14860                acosh             cacosh                  acosh
14861                asinh             casinh                  asinh
14862                atanh             catanh                  atanh
14863                cos               ccos                    cos
14864                sin               csin                    sin
14865                tan               ctan                    tan
14866                cosh              ccosh                   cosh
14867                sinh              csinh                   sinh
14868                tanh              ctanh                   tanh
14869                exp               cexp                    exp
14870                log               clog                    log
14871                pow               cpow                    pow
14872                sqrt              csqrt                   sqrt
14873                fabs              cabs                    fabs
14874     If at least one argument for a generic parameter is complex, then use of the macro invokes
14875     a complex function; otherwise, use of the macro invokes a real function.
14876 5   For each unsuffixed function in <math.h> without a c-prefixed counterpart in
14877     <complex.h> (except modf), the corresponding type-generic macro has the same
14878     name as the function. These type-generic macros are:
14879             atan2              fma                  llround              remainder
14880             cbrt               fmax                 log10                remquo
14881             ceil               fmin                 log1p                rint
14882             copysign           fmod                 log2                 round
14883             erf                frexp                logb                 scalbn
14884             erfc               hypot                lrint                scalbln
14885             exp2               ilogb                lround               tgamma
14886             expm1              ldexp                nearbyint            trunc
14887             fdim               lgamma               nextafter
14888             floor              llrint               nexttoward
14889     If all arguments for generic parameters are real, then use of the macro invokes a real
14890     function; otherwise, use of the macro results in undefined behavior.
14891
14892
14893
14894
14895 [page 371]
14896
14897 6   For each unsuffixed function in <complex.h> that is not a c-prefixed counterpart to a
14898     function in <math.h>, the corresponding type-generic macro has the same name as the
14899     function. These type-generic macros are:
14900            carg                     conj                     creal
14901            cimag                    cproj
14902     Use of the macro with any real or complex argument invokes a complex function.
14903 7   EXAMPLE       With the declarations
14904             #include <tgmath.h>
14905             int n;
14906             float f;
14907             double d;
14908             long double ld;
14909             float complex fc;
14910             double complex dc;
14911             long double complex ldc;
14912     functions invoked by use of type-generic macros are shown in the following table:
14913                      macro use                                  invokes
14914                 exp(n)                              exp(n), the function
14915                 acosh(f)                            acoshf(f)
14916                 sin(d)                              sin(d), the function
14917                 atan(ld)                            atanl(ld)
14918                 log(fc)                             clogf(fc)
14919                 sqrt(dc)                            csqrt(dc)
14920                 pow(ldc, f)                         cpowl(ldc, f)
14921                 remainder(n, n)                     remainder(n, n), the function
14922                 nextafter(d, f)                     nextafter(d, f), the function
14923                 nexttoward(f, ld)                   nexttowardf(f, ld)
14924                 copysign(n, ld)                     copysignl(n, ld)
14925                 ceil(fc)                            undefined behavior
14926                 rint(dc)                            undefined behavior
14927                 fmax(ldc, ld)                       undefined behavior
14928                 carg(n)                             carg(n), the function
14929                 cproj(f)                            cprojf(f)
14930                 creal(d)                            creal(d), the function
14931                 cimag(ld)                           cimagl(ld)
14932                 fabs(fc)                            cabsf(fc)
14933                 carg(dc)                            carg(dc), the function
14934                 cproj(ldc)                          cprojl(ldc)
14935
14936
14937
14938
14939 [page 372]
14940
14941     7.25 Threads <threads.h>
14942     7.25.1 Introduction
14943 1   The header <threads.h> defines macros, and declares types, enumeration constants,
14944     and functions that support multiple threads of execution.
14945 2   Implementations that define the macro __STDC_NO_THREADS__ need not provide
14946     this header nor support any of its facilities.
14947 3   The macros are
14948             ONCE_FLAG_INIT
14949     which expands to a value that can be used to initialize an object of type once_flag;
14950     and
14951             TSS_DTOR_ITERATIONS
14952     which expands to an integer constant expression representing the maximum number of
14953     times that destructors will be called when a thread terminates.
14954 4   The types are
14955             cnd_t
14956     which is a complete object type that holds an identifier for a condition variable;
14957             thrd_t
14958     which is a complete object type that holds an identifier for a thread;
14959             tss_t
14960     which is a complete object type that holds an identifier for a thread-specific storage
14961     pointer;
14962             mtx_t
14963     which is a complete object type that holds an identifier for a mutex;
14964             tss_dtor_t
14965     which is the function pointer type void (*)(void*), used for a destructor for a
14966     thread-specific storage pointer;
14967             thrd_start_t
14968     which is the function pointer type int (*)(void*) that is passed to thrd_create
14969     to create a new thread;
14970             once_flag
14971     which is a complete object type that holds a flag for use by call_once; and
14972
14973
14974 [page 373]
14975
14976            xtime
14977     which is a structure type that holds a time specified in seconds and nanoseconds. The
14978     structure shall contain at least the following members, in any order.
14979            time_t sec;
14980            long nsec;
14981 5   The enumeration constants are
14982            mtx_plain
14983     which is passed to mtx_init to create a mutex object that supports neither timeout nor
14984     test and return;
14985            mtx_recursive
14986     which is passed to mtx_init to create a mutex object that supports recursive locking;
14987            mtx_timed
14988     which is passed to mtx_init to create a mutex object that supports timeout;
14989            mtx_try
14990     which is passed to mtx_init to create a mutex object that supports test and return;
14991            thrd_timeout
14992     which is returned by a timed wait function to indicate that the time specified in the call
14993     was reached without acquiring the requested resource;
14994            thrd_success
14995     which is returned by a function to indicate that the requested operation succeeded;
14996            thrd_busy
14997     which is returned by a function to indicate that the requested operation failed because a
14998     resource requested by a test and return function is already in use;
14999            thrd_error
15000     which is returned by a function to indicate that the requested operation failed; and
15001            thrd_nomem
15002     which is returned by a function to indicate that the requested operation failed because it
15003     was unable to allocate memory.
15004
15005
15006
15007
15008 [page 374]
15009
15010     7.25.2 Initialization functions
15011     7.25.2.1 The call_once function
15012     Synopsis
15013 1           #include <threads.h>
15014             void call_once(once_flag *flag, void (*func)(void));
15015     Description
15016 2   The call_once function uses the once_flag pointed to by flag to ensure that
15017     func is called exactly once, the first time the call_once function is called with that
15018     value of flag. Completion of an effective call to the call_once function synchronizes
15019     with all subsequent calls to the call_once function with the same value of flag.
15020     Returns
15021 3   The call_once function returns no value.
15022     7.25.3 Condition variable functions
15023     7.25.3.1 The cnd_broadcast function
15024     Synopsis
15025 1           #include <threads.h>
15026             int cnd_broadcast(cnd_t *cond);
15027     Description
15028 2   The cnd_broadcast function unblocks all of the threads that are blocked on the
15029     condition variable pointed to by cond at the time of the call. If no threads are blocked
15030     on the condition variable pointed to by cond at the time of the call, the function does
15031     nothing.
15032     Returns
15033 3   The cnd_broadcast function returns thrd_success on success, or thrd_error
15034     if the request could not be honored.
15035     7.25.3.2 The cnd_destroy function
15036     Synopsis
15037 1           #include <threads.h>
15038             void cnd_destroy(cnd_t *cond);
15039     Description
15040 2   The cnd_destroy function releases all resources used by the condition variable
15041     pointed to by cond. The cnd_destroy function requires that no threads be blocked
15042     waiting for the condition variable pointed to by cond.
15043
15044 [page 375]
15045
15046     Returns
15047 3   The cnd_destroy function returns no value.
15048     7.25.3.3 The cnd_init function
15049     Synopsis
15050 1          #include <threads.h>
15051            int cnd_init(cnd_t *cond);
15052     Description
15053 2   The cnd_init function creates a condition variable. If it succeeds it sets the variable
15054     pointed to by cond to a value that uniquely identifies the newly created condition
15055     variable. A thread that calls cnd_wait on a newly created condition variable will
15056     block.
15057     Returns
15058 3   The cnd_init function returns thrd_success on success, or thrd_nomem if no
15059     memory could be allocated for the newly created condition, or thrd_error if the
15060     request could not be honored.
15061     7.25.3.4 The cnd_signal function
15062     Synopsis
15063 1          #include <threads.h>
15064            int cnd_signal(cnd_t *cond);
15065     Description
15066 2   The cnd_signal function unblocks one of the threads that are blocked on the
15067     condition variable pointed to by cond at the time of the call. If no threads are blocked
15068     on the condition variable at the time of the call, the function does nothing and return
15069     success.
15070     Returns
15071 3   The cnd_signal function returns thrd_success on success or thrd_error if
15072     the request could not be honored.
15073     7.25.3.5 The cnd_timedwait function
15074     Synopsis
15075 1          #include <threads.h>
15076            int cnd_timedwait(cnd_t *cond, mtx_t *mtx,
15077                 const xtime *xt);
15078
15079
15080
15081
15082 [page 376]
15083
15084     Description
15085 2   The cnd_timedwait function atomically unlocks the mutex pointed to by mtx and
15086     endeavors to block until the condition variable pointed to by cond is signaled by a call to
15087     cnd_signal or to cnd_broadcast, or until after the time specified by the xtime
15088     object pointed to by xt. When the calling thread becomes unblocked it locks the variable
15089     pointed to by mtx before it returns. The cnd_timedwait function requires that the
15090     mutex pointed to by mtx be locked by the calling thread.
15091     Returns
15092 3   The cnd_timedwait function returns thrd_success upon success, or
15093     thrd_timeout if the time specified in the call was reached without acquiring the
15094     requested resource, or thrd_error if the request could not be honored.
15095     7.25.3.6 The cnd_wait function
15096     Synopsis
15097 1           #include <threads.h>
15098             int cnd_wait(cnd_t *cond, mtx_t *mtx);
15099     Description
15100 2   The cnd_wait function atomically unlocks the mutex pointed to by mtx and endeavors
15101     to block until the condition variable pointed to by cond is signaled by a call to
15102     cnd_signal or to cnd_broadcast. When the calling thread becomes unblocked it
15103     locks the mutex pointed to by mtx before it returns. If the mutex pointed to by mtx is
15104     not locked by the calling thread, the cnd_wait function will act as if the abort
15105     function is called.
15106     Returns
15107 3   The cnd_wait function returns thrd_success on success or thrd_error if the
15108     request could not be honored.
15109     7.25.4 Mutex functions
15110     7.25.4.1 The mtx_destroy function
15111     Synopsis
15112 1           #include <threads.h>
15113             void mtx_destroy(mtx_t *mtx);
15114     Description
15115 2   The mtx_destroy function releases any resources used by the mutex pointed to by
15116     mtx. No threads can be blocked waiting for the mutex pointed to by mtx.
15117
15118
15119
15120 [page 377]
15121
15122     Returns
15123 3   The mtx_destroy function returns no value.
15124     7.25.4.2 The mtx_init function
15125     Synopsis
15126 1          #include <threads.h>
15127            int mtx_init(mtx_t *mtx, int type);
15128     Description
15129 2   The mtx_init function creates a mutex object with properties indicated by type,
15130     which must have one of the six values:
15131     mtx_plain for a simple non-recursive mutex,
15132     mtx_timed for a non-recursive mutex that supports timeout,
15133     mtx_try      for a non-recursive mutex that supports test and return,
15134     mtx_plain | mtx_recursive for a simple recursive mutex,
15135     mtx_timed | mtx_recursive for a recursive mutex that supports timeout, or
15136     mtx_try | mtx_recursive for a recursive mutex that supports test and return.
15137 3   If the mtx_init function succeeds, it sets the mutex pointed to by mtx to a value that
15138     uniquely identifies the newly created mutex.
15139     Returns
15140 4   The mtx_init function returns thrd_success on success, or thrd_error if the
15141     request could not be honored.
15142     7.25.4.3 The mtx_lock function
15143     Synopsis
15144 1          #include <threads.h>
15145            int mtx_lock(mtx_t *mtx);
15146     Description
15147 2   The mtx_lock function blocks until it locks the mutex pointed to by mtx. If the mutex
15148     is non-recursive, it shall not be locked by the calling thread. Prior calls to mtx_unlock
15149     on the same mutex shall synchronize with this operation.
15150     Returns
15151 3   The mtx_lock function returns thrd_success on success, or thrd_busy if the
15152     resource requested is already in use, or thrd_error if the request could not be
15153     honored.
15154
15155
15156
15157
15158 [page 378]
15159
15160     7.25.4.4 The mtx_timedlock function
15161     Synopsis
15162 1           #include <threads.h>
15163             int mtx_timedlock(mtx_t *mtx, const xtime *xt);
15164     Description
15165 2   The mtx_timedlock function endeavors to block until it locks the mutex pointed to by
15166     mtx or until the time specified by the xtime object xt has passed. The specified mutex
15167     shall support timeout. If the operation succeeds, prior calls to mtx_unlock on the same
15168     mutex shall synchronize with this operation.
15169     Returns
15170 3   The mtx_timedlock function returns thrd_success on success, or thrd_busy
15171     if the resource requested is already in use, or thrd_timeout if the time specified was
15172     reached without acquiring the requested resource, or thrd_error if the request could
15173     not be honored.
15174     7.25.4.5 The mtx_trylock function
15175     Synopsis
15176 1           #include <threads.h>
15177             int mtx_trylock(mtx_t *mtx);
15178     Description
15179 2   The mtx_trylock function endeavors to lock the mutex pointed to by mtx. The
15180     specified mutex shall support either test and return or timeout. If the mutex is already
15181     locked, the function returns without blocking. If the operation succeeds, prior calls to
15182     mtx_unlock on the same mutex shall synchronize with this operation.
15183     Returns
15184 3   The mtx_trylock function returns thrd_success on success, or thrd_busy if
15185     the resource requested is already in use, or thrd_error if the request could not be
15186     honored.
15187     7.25.4.6 The mtx_unlock function
15188     Synopsis
15189 1           #include <threads.h>
15190             int mtx_unlock(mtx_t *mtx);
15191     Description
15192 2   The mtx_unlock function unlocks the mutex pointed to by mtx. The mutex pointed to
15193     by mtx shall be locked by the calling thread.
15194
15195 [page 379]
15196
15197     Returns
15198 3   The mtx_unlock function returns thrd_success on success or thrd_error if
15199     the request could not be honored.
15200     7.25.5 Thread functions
15201     7.25.5.1 The thrd_create function
15202     Synopsis
15203 1          #include <threads.h>
15204            int thrd_create(thrd_t *thr, thrd_start_t func,
15205                 void *arg);
15206     Description
15207 2   The thrd_create function creates a new thread executing func(arg). If the
15208     thrd_create function succeeds, it sets the object pointed to by thr to the identifier of
15209     the newly created thread. (A thread's identifier may be reused for a different thread once
15210     the original thread has exited and either been detached or joined to another thread.) The
15211     completion of the thrd_create function synchronizes with the beginning of the
15212     execution of the new thread.
15213     Returns
15214 3   The thrd_create function returns thrd_success on success, or thrd_nomem if
15215     no memory could be allocated for the thread requested, or thrd_error if the request
15216     could not be honored.
15217     7.25.5.2 The thrd_current function
15218     Synopsis
15219 1          #include <threads.h>
15220            thrd_t thrd_current(void);
15221     Description
15222 2   The thrd_current function identifies the thread that called it.
15223     Returns
15224 3   The thrd_current function returns the identifier of the thread that called it.
15225     7.25.5.3 The thrd_detach function
15226     Synopsis
15227 1          #include <threads.h>
15228            int thrd_detach(thrd_t thr);
15229
15230
15231
15232 [page 380]
15233
15234     Description
15235 2   The thrd_detach function tells the operating system to dispose of any resources
15236     allocated to the thread identified by thr when that thread terminates. The thread
15237     identified by thr shall not have been previously detached or joined with another thread.
15238     Returns
15239 3   The thrd_detach function returns thrd_success on success or thrd_error if
15240     the request could not be honored.
15241     7.25.5.4 The thrd_equal function
15242     Synopsis
15243 1           #include <threads.h>
15244             int thrd_equal(thrd_t thr0, thrd_t thr1);
15245     Description
15246 2   The thrd_equal function will determine whether the thread identified by thr0 refers
15247     to the thread identified by thr1.
15248     Returns
15249 3   The thrd_equal function returns zero if the thread thr0 and the thread thr1 refer to
15250     different threads. Otherwise the thrd_equal function returns a nonzero value.
15251     7.25.5.5 The thrd_exit function
15252     Synopsis
15253 1           #include <threads.h>
15254             void thrd_exit(int res);
15255     Description
15256 2   The thrd_exit function terminates execution of the calling thread and sets its result
15257     code to res.
15258     Returns
15259 3   The thrd_exit function returns no value.
15260     7.25.5.6 The thrd_join function
15261     Synopsis
15262 1           #include <threads.h>
15263             int thrd_join(thrd_t thr, int *res);
15264     Description
15265 2   The thrd_join function joins the thread identified by thr with the current thread by
15266     blocking until the other thread has terminated. If the parameter res is not a null pointer,
15267
15268 [page 381]
15269
15270     it stores the thread's result code in the integer pointed to by res. The termination of the
15271     other thread synchronizes with the completion of the thrd_join function. The thread
15272     identified by thr shall not have been previously detached or joined with another thread.
15273     Returns
15274 3   The thrd_join function returns thrd_success on success or thrd_error if the
15275     request could not be honored.
15276     7.25.5.7 The thrd_sleep function
15277     Synopsis
15278 1          #include <threads.h>
15279            void thrd_sleep(const xtime *xt);
15280     Description
15281 2   The thrd_sleep function suspends execution of the calling thread until after the time
15282     specified by the xtime object pointed to by xt.
15283     Returns
15284 3   The thrd_sleep function returns no value.
15285     7.25.5.8 The thrd_yield function
15286     Synopsis
15287 1          #include <threads.h>
15288            void thrd_yield(void);
15289     Description
15290 2   The thrd_yield function endeavors to permit other threads to run, even if the current
15291     thread would ordinarily continue to run.
15292     Returns
15293 3   The thrd_yield function returns no value.
15294     7.25.6 Thread-specific storage functions
15295     7.25.6.1 The tss_create function
15296     Synopsis
15297 1          #include <threads.h>
15298            int tss_create(tss_t *key, tss_dtor_t dtor);
15299     Description
15300 2   The tss_create function creates a thread-specific storage pointer with destructor
15301     dtor, which may be null.
15302
15303
15304 [page 382]
15305
15306     Returns
15307 3   If the tss_create function is successful, it sets the thread-specific storage pointed to
15308     by key to a value that uniquely identifies the newly created pointer and returns
15309     thrd_success; otherwise, thrd_error is returned and the thread-specific storage
15310     pointed to by key is set to an undefined value.
15311     7.25.6.2 The tss_delete function
15312     Synopsis
15313 1           #include <threads.h>
15314             void tss_delete(tss_t key);
15315     Description
15316 2   The tss_delete function releases any resources used by the thread-specific storage
15317     identified by key.
15318     Returns
15319 3   The tss_delete function returns no value.
15320     7.25.6.3 The tss_get function
15321     Synopsis
15322 1           #include <threads.h>
15323             void *tss_get(tss_t key);
15324     Description
15325 2   The tss_get function returns the value for the current thread held in the thread-specific
15326     storage identified by key.
15327     Returns
15328 3   The tss_get function returns the value for the current thread if successful, or zero if
15329     unsuccessful.
15330     7.25.6.4 The tss_set function
15331     Synopsis
15332 1           #include <threads.h>
15333             int tss_set(tss_t key, void *val);
15334     Description
15335 2   The tss_set function sets the value for the current thread held in the thread-specific
15336     storage identified by key to val.
15337
15338
15339
15340
15341 [page 383]
15342
15343     Returns
15344 3   The tss_set function returns thrd_success on success or thrd_error if the
15345     request could not be honored.
15346     7.25.7 Time functions
15347     7.25.7.1 The xtime_get function
15348     Synopsis
15349 1           #include <threads.h>
15350             int xtime_get(xtime *xt, int base);
15351     Description
15352 2   The xtime_get function sets the xtime object pointed to by xt to hold the current
15353     time based on the time base base.
15354     Returns
15355 3   If the xtime_get function is successful it returns the nonzero value base, which must
15356     be TIME_UTC; otherwise, it returns zero.306)
15357
15358
15359
15360
15361     306) Although an xtime object describes times with nanosecond resolution, the actual resolution in an
15362          xtime object is system dependent.
15363
15364 [page 384]
15365
15366     7.26 Date and time <time.h>
15367     7.26.1 Components of time
15368 1   The header <time.h> defines two macros, and declares several types and functions for
15369     manipulating time. Many functions deal with a calendar time that represents the current
15370     date (according to the Gregorian calendar) and time. Some functions deal with local
15371     time, which is the calendar time expressed for some specific time zone, and with Daylight
15372     Saving Time, which is a temporary change in the algorithm for determining local time.
15373     The local time zone and Daylight Saving Time are implementation-defined.
15374 2   The macros defined are NULL (described in 7.19); and
15375             CLOCKS_PER_SEC
15376     which expands to an expression with type clock_t (described below) that is the
15377     number per second of the value returned by the clock function.
15378 3   The types declared are size_t (described in 7.19);
15379             clock_t
15380     and
15381             time_t
15382     which are arithmetic types capable of representing times; and
15383             struct tm
15384     which holds the components of a calendar time, called the broken-down time.
15385 4   The range and precision of times representable in clock_t and time_t are
15386     implementation-defined. The tm structure shall contain at least the following members,
15387     in any order. The semantics of the members and their normal ranges are expressed in the
15388     comments.307)
15389             int    tm_sec;           //   seconds after the minute -- [0, 60]
15390             int    tm_min;           //   minutes after the hour -- [0, 59]
15391             int    tm_hour;          //   hours since midnight -- [0, 23]
15392             int    tm_mday;          //   day of the month -- [1, 31]
15393             int    tm_mon;           //   months since January -- [0, 11]
15394             int    tm_year;          //   years since 1900
15395             int    tm_wday;          //   days since Sunday -- [0, 6]
15396             int    tm_yday;          //   days since January 1 -- [0, 365]
15397             int    tm_isdst;         //   Daylight Saving Time flag
15398
15399
15400
15401     307) The range [0, 60] for tm_sec allows for a positive leap second.
15402
15403 [page 385]
15404
15405     The value of tm_isdst is positive if Daylight Saving Time is in effect, zero if Daylight
15406     Saving Time is not in effect, and negative if the information is not available.
15407     7.26.2 Time manipulation functions
15408     7.26.2.1 The clock function
15409     Synopsis
15410 1           #include <time.h>
15411             clock_t clock(void);
15412     Description
15413 2   The clock function determines the processor time used.
15414     Returns
15415 3   The clock function returns the implementation's best approximation to the processor
15416     time used by the program since the beginning of an implementation-defined era related
15417     only to the program invocation. To determine the time in seconds, the value returned by
15418     the clock function should be divided by the value of the macro CLOCKS_PER_SEC. If
15419     the processor time used is not available or its value cannot be represented, the function
15420     returns the value (clock_t)(-1).308)
15421     7.26.2.2 The difftime function
15422     Synopsis
15423 1           #include <time.h>
15424             double difftime(time_t time1, time_t time0);
15425     Description
15426 2   The difftime function computes the difference between two calendar times: time1 -
15427     time0.
15428     Returns
15429 3   The difftime function returns the difference expressed in seconds as a double.
15430
15431
15432
15433
15434     308) In order to measure the time spent in a program, the clock function should be called at the start of
15435          the program and its return value subtracted from the value returned by subsequent calls.
15436
15437 [page 386]
15438
15439     7.26.2.3 The mktime function
15440     Synopsis
15441 1           #include <time.h>
15442             time_t mktime(struct tm *timeptr);
15443     Description
15444 2   The mktime function converts the broken-down time, expressed as local time, in the
15445     structure pointed to by timeptr into a calendar time value with the same encoding as
15446     that of the values returned by the time function. The original values of the tm_wday
15447     and tm_yday components of the structure are ignored, and the original values of the
15448     other components are not restricted to the ranges indicated above.309) On successful
15449     completion, the values of the tm_wday and tm_yday components of the structure are
15450     set appropriately, and the other components are set to represent the specified calendar
15451     time, but with their values forced to the ranges indicated above; the final value of
15452     tm_mday is not set until tm_mon and tm_year are determined.
15453     Returns
15454 3   The mktime function returns the specified calendar time encoded as a value of type
15455     time_t. If the calendar time cannot be represented, the function returns the value
15456     (time_t)(-1).
15457 4   EXAMPLE       What day of the week is July 4, 2001?
15458             #include <stdio.h>
15459             #include <time.h>
15460             static const char *const wday[] = {
15461                     "Sunday", "Monday", "Tuesday", "Wednesday",
15462                     "Thursday", "Friday", "Saturday", "-unknown-"
15463             };
15464             struct tm time_str;
15465             /* ... */
15466
15467
15468
15469
15470     309) Thus, a positive or zero value for tm_isdst causes the mktime function to presume initially that
15471          Daylight Saving Time, respectively, is or is not in effect for the specified time. A negative value
15472          causes it to attempt to determine whether Daylight Saving Time is in effect for the specified time.
15473
15474 [page 387]
15475
15476            time_str.tm_year   = 2001 - 1900;
15477            time_str.tm_mon    = 7 - 1;
15478            time_str.tm_mday   = 4;
15479            time_str.tm_hour   = 0;
15480            time_str.tm_min    = 0;
15481            time_str.tm_sec    = 1;
15482            time_str.tm_isdst = -1;
15483            if (mktime(&time_str) == (time_t)(-1))
15484                  time_str.tm_wday = 7;
15485            printf("%s\n", wday[time_str.tm_wday]);
15486
15487     7.26.2.4 The time function
15488     Synopsis
15489 1          #include <time.h>
15490            time_t time(time_t *timer);
15491     Description
15492 2   The time function determines the current calendar time. The encoding of the value is
15493     unspecified.
15494     Returns
15495 3   The time function returns the implementation's best approximation to the current
15496     calendar time. The value (time_t)(-1) is returned if the calendar time is not
15497     available. If timer is not a null pointer, the return value is also assigned to the object it
15498     points to.
15499     7.26.3 Time conversion functions
15500 1   Except for the strftime function, these functions each return a pointer to one of two
15501     types of static objects: a broken-down time structure or an array of char. Execution of
15502     any of the functions that return a pointer to one of these object types may overwrite the
15503     information in any object of the same type pointed to by the value returned from any
15504     previous call to any of them and the functions are not required to avoid data races. The
15505     implementation shall behave as if no other library functions call these functions.
15506     7.26.3.1 The asctime function
15507     Synopsis
15508 1          #include <time.h>
15509            char *asctime(const struct tm *timeptr);
15510     Description
15511 2   The asctime function converts the broken-down time in the structure pointed to by
15512     timeptr into a string in the form
15513            Sun Sep 16 01:03:52 1973\n\0
15514
15515 [page 388]
15516
15517     using the equivalent of the following algorithm.
15518     char *asctime(const struct tm *timeptr)
15519     {
15520          static const char wday_name[7][3] = {
15521               "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
15522          };
15523          static const char mon_name[12][3] = {
15524               "Jan", "Feb", "Mar", "Apr", "May", "Jun",
15525               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
15526          };
15527          static char result[26];
15528             sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
15529                  wday_name[timeptr->tm_wday],
15530                  mon_name[timeptr->tm_mon],
15531                  timeptr->tm_mday, timeptr->tm_hour,
15532                  timeptr->tm_min, timeptr->tm_sec,
15533                  1900 + timeptr->tm_year);
15534             return result;
15535     }
15536 3   If any of the fields of the broken-down time contain values that are outside their normal
15537     ranges,310) the behavior of the asctime function is undefined. Likewise, if the
15538     calculated year exceeds four digits or is less than the year 1000, the behavior is
15539     undefined.
15540     Returns
15541 4   The asctime function returns a pointer to the string.
15542     7.26.3.2 The ctime function
15543     Synopsis
15544 1           #include <time.h>
15545             char *ctime(const time_t *timer);
15546     Description
15547 2   The ctime function converts the calendar time pointed to by timer to local time in the
15548     form of a string. It is equivalent to
15549             asctime(localtime(timer))
15550
15551
15552
15553     310) See 7.26.1.
15554
15555 [page 389]
15556
15557     Returns
15558 3   The ctime function returns the pointer returned by the asctime function with that
15559     broken-down time as argument.
15560     Forward references: the localtime function (7.26.3.4).
15561     7.26.3.3 The gmtime function
15562     Synopsis
15563 1          #include <time.h>
15564            struct tm *gmtime(const time_t *timer);
15565     Description
15566 2   The gmtime function converts the calendar time pointed to by timer into a broken-
15567     down time, expressed as UTC.
15568     Returns
15569 3   The gmtime function returns a pointer to the broken-down time, or a null pointer if the
15570     specified time cannot be converted to UTC.
15571     7.26.3.4 The localtime function
15572     Synopsis
15573 1          #include <time.h>
15574            struct tm *localtime(const time_t *timer);
15575     Description
15576 2   The localtime function converts the calendar time pointed to by timer into a
15577     broken-down time, expressed as local time.
15578     Returns
15579 3   The localtime function returns a pointer to the broken-down time, or a null pointer if
15580     the specified time cannot be converted to local time.
15581     7.26.3.5 The strftime function
15582     Synopsis
15583 1          #include <time.h>
15584            size_t strftime(char * restrict s,
15585                 size_t maxsize,
15586                 const char * restrict format,
15587                 const struct tm * restrict timeptr);
15588
15589
15590
15591
15592 [page 390]
15593
15594     Description
15595 2   The strftime function places characters into the array pointed to by s as controlled by
15596     the string pointed to by format. The format shall be a multibyte character sequence,
15597     beginning and ending in its initial shift state. The format string consists of zero or
15598     more conversion specifiers and ordinary multibyte characters. A conversion specifier
15599     consists of a % character, possibly followed by an E or O modifier character (described
15600     below), followed by a character that determines the behavior of the conversion specifier.
15601     All ordinary multibyte characters (including the terminating null character) are copied
15602     unchanged into the array. If copying takes place between objects that overlap, the
15603     behavior is undefined. No more than maxsize characters are placed into the array.
15604 3   Each conversion specifier is replaced by appropriate characters as described in the
15605     following list. The appropriate characters are determined using the LC_TIME category
15606     of the current locale and by the values of zero or more members of the broken-down time
15607     structure pointed to by timeptr, as specified in brackets in the description. If any of
15608     the specified values is outside the normal range, the characters stored are unspecified.
15609     %a   is replaced by the locale's abbreviated weekday name. [tm_wday]
15610     %A   is replaced by the locale's full weekday name. [tm_wday]
15611     %b   is replaced by the locale's abbreviated month name. [tm_mon]
15612     %B   is replaced by the locale's full month name. [tm_mon]
15613     %c   is replaced by the locale's appropriate date and time representation. [all specified
15614          in 7.26.1]
15615     %C   is replaced by the year divided by 100 and truncated to an integer, as a decimal
15616          number (00-99). [tm_year]
15617     %d   is replaced by the day of the month as a decimal number (01-31). [tm_mday]
15618     %D   is equivalent to ''%m/%d/%y''. [tm_mon, tm_mday, tm_year]
15619     %e   is replaced by the day of the month as a decimal number (1-31); a single digit is
15620          preceded by a space. [tm_mday]
15621     %F   is equivalent to ''%Y-%m-%d'' (the ISO 8601 date format). [tm_year, tm_mon,
15622          tm_mday]
15623     %g   is replaced by the last 2 digits of the week-based year (see below) as a decimal
15624          number (00-99). [tm_year, tm_wday, tm_yday]
15625     %G   is replaced by the week-based year (see below) as a decimal number (e.g., 1997).
15626          [tm_year, tm_wday, tm_yday]
15627     %h   is equivalent to ''%b''. [tm_mon]
15628     %H   is replaced by the hour (24-hour clock) as a decimal number (00-23). [tm_hour]
15629     %I   is replaced by the hour (12-hour clock) as a decimal number (01-12). [tm_hour]
15630     %j   is replaced by the day of the year as a decimal number (001-366). [tm_yday]
15631     %m   is replaced by the month as a decimal number (01-12). [tm_mon]
15632     %M   is replaced by the minute as a decimal number (00-59). [tm_min]
15633     %n   is replaced by a new-line character.
15634
15635 [page 391]
15636
15637     %p    is replaced by the locale's equivalent of the AM/PM designations associated with a
15638           12-hour clock. [tm_hour]
15639     %r    is replaced by the locale's 12-hour clock time. [tm_hour, tm_min, tm_sec]
15640     %R    is equivalent to ''%H:%M''. [tm_hour, tm_min]
15641     %S    is replaced by the second as a decimal number (00-60). [tm_sec]
15642     %t    is replaced by a horizontal-tab character.
15643     %T    is equivalent to ''%H:%M:%S'' (the ISO 8601 time format). [tm_hour, tm_min,
15644           tm_sec]
15645     %u    is replaced by the ISO 8601 weekday as a decimal number (1-7), where Monday
15646           is 1. [tm_wday]
15647     %U    is replaced by the week number of the year (the first Sunday as the first day of week
15648           1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
15649     %V    is replaced by the ISO 8601 week number (see below) as a decimal number
15650           (01-53). [tm_year, tm_wday, tm_yday]
15651     %w    is replaced by the weekday as a decimal number (0-6), where Sunday is 0.
15652           [tm_wday]
15653     %W    is replaced by the week number of the year (the first Monday as the first day of
15654           week 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
15655     %x    is replaced by the locale's appropriate date representation. [all specified in 7.26.1]
15656     %X    is replaced by the locale's appropriate time representation. [all specified in 7.26.1]
15657     %y    is replaced by the last 2 digits of the year as a decimal number (00-99).
15658           [tm_year]
15659     %Y    is replaced by the year as a decimal number (e.g., 1997). [tm_year]
15660     %z    is replaced by the offset from UTC in the ISO 8601 format ''-0430'' (meaning 4
15661           hours 30 minutes behind UTC, west of Greenwich), or by no characters if no time
15662           zone is determinable. [tm_isdst]
15663     %Z    is replaced by the locale's time zone name or abbreviation, or by no characters if no
15664           time zone is determinable. [tm_isdst]
15665     %%    is replaced by %.
15666 4   Some conversion specifiers can be modified by the inclusion of an E or O modifier
15667     character to indicate an alternative format or specification. If the alternative format or
15668     specification does not exist for the current locale, the modifier is ignored.
15669     %Ec is replaced by the locale's alternative date and time representation.
15670     %EC is replaced by the name of the base year (period) in the locale's alternative
15671         representation.
15672     %Ex is replaced by the locale's alternative date representation.
15673     %EX is replaced by the locale's alternative time representation.
15674     %Ey is replaced by the offset from %EC (year only) in the locale's alternative
15675         representation.
15676     %EY is replaced by the locale's full alternative year representation.
15677
15678 [page 392]
15679
15680     %Od is replaced by the day of the month, using the locale's alternative numeric symbols
15681         (filled as needed with leading zeros, or with leading spaces if there is no alternative
15682         symbol for zero).
15683     %Oe is replaced by the day of the month, using the locale's alternative numeric symbols
15684         (filled as needed with leading spaces).
15685     %OH is replaced by the hour (24-hour clock), using the locale's alternative numeric
15686         symbols.
15687     %OI is replaced by the hour (12-hour clock), using the locale's alternative numeric
15688         symbols.
15689     %Om is replaced by the month, using the locale's alternative numeric symbols.
15690     %OM is replaced by the minutes, using the locale's alternative numeric symbols.
15691     %OS is replaced by the seconds, using the locale's alternative numeric symbols.
15692     %Ou is replaced by the ISO 8601 weekday as a number in the locale's alternative
15693         representation, where Monday is 1.
15694     %OU is replaced by the week number, using the locale's alternative numeric symbols.
15695     %OV is replaced by the ISO 8601 week number, using the locale's alternative numeric
15696         symbols.
15697     %Ow is replaced by the weekday as a number, using the locale's alternative numeric
15698         symbols.
15699     %OW is replaced by the week number of the year, using the locale's alternative numeric
15700         symbols.
15701     %Oy is replaced by the last 2 digits of the year, using the locale's alternative numeric
15702         symbols.
15703 5   %g, %G, and %V give values according to the ISO 8601 week-based year. In this system,
15704     weeks begin on a Monday and week 1 of the year is the week that includes January 4th,
15705     which is also the week that includes the first Thursday of the year, and is also the first
15706     week that contains at least four days in the year. If the first Monday of January is the
15707     2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year; thus,
15708     for Saturday 2nd January 1999, %G is replaced by 1998 and %V is replaced by 53. If
15709     December 29th, 30th, or 31st is a Monday, it and any following days are part of week 1 of
15710     the following year. Thus, for Tuesday 30th December 1997, %G is replaced by 1998 and
15711     %V is replaced by 01.
15712 6   If a conversion specifier is not one of the above, the behavior is undefined.
15713 7   In the "C" locale, the E and O modifiers are ignored and the replacement strings for the
15714     following specifiers are:
15715     %a the first three characters of %A.
15716     %A one of ''Sunday'', ''Monday'', ... , ''Saturday''.
15717     %b the first three characters of %B.
15718     %B one of ''January'', ''February'', ... , ''December''.
15719     %c equivalent to ''%a %b %e %T %Y''.
15720 [page 393]
15721
15722     %p    one of ''AM'' or ''PM''.
15723     %r    equivalent to ''%I:%M:%S %p''.
15724     %x    equivalent to ''%m/%d/%y''.
15725     %X    equivalent to %T.
15726     %Z    implementation-defined.
15727     Returns
15728 8   If the total number of resulting characters including the terminating null character is not
15729     more than maxsize, the strftime function returns the number of characters placed
15730     into the array pointed to by s not including the terminating null character. Otherwise,
15731     zero is returned and the contents of the array are indeterminate.
15732
15733
15734
15735
15736 [page 394]
15737
15738     7.27 Unicode utilities <uchar.h>
15739 1   The header <uchar.h> declares types and functions for manipulating Unicode
15740     characters.
15741 2   The types declared are mbstate_t (described in 7.29.1) and size_t (described in
15742     7.19);
15743             char16_t
15744     which is an unsigned integer type used for 16-bit characters and is the same type as
15745     uint_least16_t (described in 7.20.1.2); and
15746             char32_t
15747     which is an unsigned integer type used for 32-bit characters and is the same type as
15748     uint_least32_t (also described in 7.20.1.2).
15749     7.27.1 Restartable multibyte/wide character conversion functions
15750 1   These functions have a parameter, ps, of type pointer to mbstate_t that points to an
15751     object that can completely describe the current conversion state of the associated
15752     multibyte character sequence, which the functions alter as necessary. If ps is a null
15753     pointer, each function uses its own internal mbstate_t object instead, which is
15754     initialized at program startup to the initial conversion state; the functions are not required
15755     to avoid data races in this case. The implementation behaves as if no library function
15756     calls these functions with a null pointer for ps.
15757     7.27.1.1 The mbrtoc16 function
15758     Synopsis
15759 1           #include <uchar.h>
15760             size_t mbrtoc16(char16_t * restrict pc16,
15761                  const char * restrict s, size_t n,
15762                  mbstate_t * restrict ps);
15763     Description
15764 2   If s is a null pointer, the mbrtoc16 function is equivalent to the call:
15765                    mbrtoc16(NULL, "", 1, ps)
15766     In this case, the values of the parameters pc16 and n are ignored.
15767 3   If s is not a null pointer, the mbrtoc16 function inspects at most n bytes beginning with
15768     the byte pointed to by s to determine the number of bytes needed to complete the next
15769     multibyte character (including any shift sequences). If the function determines that the
15770     next multibyte character is complete and valid, it determines the values of the
15771     corresponding wide characters and then, if pc16 is not a null pointer, stores the value of
15772     the first (or only) such character in the object pointed to by pc16. Subsequent calls will
15773 [page 395]
15774
15775     store successive wide characters without consuming any additional input until all the
15776     characters have been stored. If the corresponding wide character is the null wide
15777     character, the resulting state described is the initial conversion state.
15778     Returns
15779 4   The mbrtoc16 function returns the first of the following that applies (given the current
15780     conversion state):
15781     0                     if the next n or fewer bytes complete the multibyte character that
15782                           corresponds to the null wide character (which is the value stored).
15783     between 1 and n inclusive if the next n or fewer bytes complete a valid multibyte
15784                        character (which is the value stored); the value returned is the number
15785                        of bytes that complete the multibyte character.
15786     (size_t)(-3) if the next character resulting from a previous call has been stored (no
15787                  bytes from the input have been consumed by this call).
15788     (size_t)(-2) if the next n bytes contribute to an incomplete (but potentially valid)
15789                  multibyte character, and all n bytes have been processed (no value is
15790                  stored).311)
15791     (size_t)(-1) if an encoding error occurs, in which case the next n or fewer bytes
15792                  do not contribute to a complete and valid multibyte character (no
15793                  value is stored); the value of the macro EILSEQ is stored in errno,
15794                  and the conversion state is unspecified.
15795     7.27.1.2 The c16rtomb function
15796     Synopsis
15797 1           #include <uchar.h>
15798             size_t c16rtomb(char * restrict s, char16_t c16,
15799                  mbstate_t * restrict ps);
15800     Description
15801 2   If s is a null pointer, the c16rtomb function is equivalent to the call
15802                     c16rtomb(buf, L'\0', ps)
15803     where buf is an internal buffer.
15804 3   If s is not a null pointer, the c16rtomb function determines the number of bytes needed
15805     to represent the multibyte character that corresponds to the wide character given by c16
15806     (including any shift sequences), and stores the multibyte character representation in the
15807
15808
15809     311) When n has at least the value of the MB_CUR_MAX macro, this case can only occur if s points at a
15810          sequence of redundant shift sequences (for implementations with state-dependent encodings).
15811
15812 [page 396]
15813
15814     array whose first element is pointed to by s. At most MB_CUR_MAX bytes are stored. If
15815     c16 is a null wide character, a null byte is stored, preceded by any shift sequence needed
15816     to restore the initial shift state; the resulting state described is the initial conversion state.
15817     Returns
15818 4   The c16rtomb function returns the number of bytes stored in the array object (including
15819     any shift sequences). When c16 is not a valid wide character, an encoding error occurs:
15820     the function stores the value of the macro EILSEQ in errno and returns
15821     (size_t)(-1); the conversion state is unspecified.
15822     7.27.1.3 The mbrtoc32 function
15823     Synopsis
15824 1           #include <uchar.h>
15825             size_t mbrtoc32(char32_t * restrict pc32,
15826                  const char * restrict s, size_t n,
15827                  mbstate_t * restrict ps);
15828     Description
15829 2   If s is a null pointer, the mbrtoc32 function is equivalent to the call:
15830                     mbrtoc32(NULL, "", 1, ps)
15831     In this case, the values of the parameters pc32 and n are ignored.
15832 3   If s is not a null pointer, the mbrtoc32 function inspects at most n bytes beginning with
15833     the byte pointed to by s to determine the number of bytes needed to complete the next
15834     multibyte character (including any shift sequences). If the function determines that the
15835     next multibyte character is complete and valid, it determines the values of the
15836     corresponding wide characters and then, if pc32 is not a null pointer, stores the value of
15837     the first (or only) such character in the object pointed to by pc32. Subsequent calls will
15838     store successive wide characters without consuming any additional input until all the
15839     characters have been stored. If the corresponding wide character is the null wide
15840     character, the resulting state described is the initial conversion state.
15841     Returns
15842 4   The mbrtoc32 function returns the first of the following that applies (given the current
15843     conversion state):
15844     0                    if the next n or fewer bytes complete the multibyte character that
15845                          corresponds to the null wide character (which is the value stored).
15846     between 1 and n inclusive if the next n or fewer bytes complete a valid multibyte
15847                        character (which is the value stored); the value returned is the number
15848                        of bytes that complete the multibyte character.
15849
15850
15851 [page 397]
15852
15853     (size_t)(-3) if the next character resulting from a previous call has been stored (no
15854                  bytes from the input have been consumed by this call).
15855     (size_t)(-2) if the next n bytes contribute to an incomplete (but potentially valid)
15856                  multibyte character, and all n bytes have been processed (no value is
15857                  stored).312)
15858     (size_t)(-1) if an encoding error occurs, in which case the next n or fewer bytes
15859                  do not contribute to a complete and valid multibyte character (no
15860                  value is stored); the value of the macro EILSEQ is stored in errno,
15861                  and the conversion state is unspecified.
15862     7.27.1.4 The c32rtomb function
15863     Synopsis
15864 1           #include <uchar.h>
15865             size_t c32rtomb(char * restrict s, char32_t c32,
15866                  mbstate_t * restrict ps);
15867     Description
15868 2   If s is a null pointer, the c32rtomb function is equivalent to the call
15869                     c32rtomb(buf, L'\0', ps)
15870     where buf is an internal buffer.
15871 3   If s is not a null pointer, the c32rtomb function determines the number of bytes needed
15872     to represent the multibyte character that corresponds to the wide character given by c32
15873     (including any shift sequences), and stores the multibyte character representation in the
15874     array whose first element is pointed to by s. At most MB_CUR_MAX bytes are stored. If
15875     c32 is a null wide character, a null byte is stored, preceded by any shift sequence needed
15876     to restore the initial shift state; the resulting state described is the initial conversion state.
15877     Returns
15878 4   The c32rtomb function returns the number of bytes stored in the array object (including
15879     any shift sequences). When c32 is not a valid wide character, an encoding error occurs:
15880     the function stores the value of the macro EILSEQ in errno and returns
15881     (size_t)(-1); the conversion state is unspecified.
15882
15883
15884
15885
15886     312) When n has at least the value of the MB_CUR_MAX macro, this case can only occur if s points at a
15887          sequence of redundant shift sequences (for implementations with state-dependent encodings).
15888
15889 [page 398]
15890
15891     7.28 Extended multibyte and wide character utilities <wchar.h>
15892     7.28.1 Introduction
15893 1   The header <wchar.h> defines four macros, and declares four data types, one tag, and
15894     many functions.313)
15895 2   The types declared are wchar_t and size_t (both described in 7.19);
15896               mbstate_t
15897     which is a complete object type other than an array type that can hold the conversion state
15898     information necessary to convert between sequences of multibyte characters and wide
15899     characters;
15900              wint_t
15901     which is an integer type unchanged by default argument promotions that can hold any
15902     value corresponding to members of the extended character set, as well as at least one
15903     value that does not correspond to any member of the extended character set (see WEOF
15904     below);314) and
15905              struct tm
15906     which is declared as an incomplete structure type (the contents are described in 7.26.1).
15907 3   The macros defined are NULL (described in 7.19); WCHAR_MIN and WCHAR_MAX
15908     (described in 7.20.3); and
15909              WEOF
15910     which expands to a constant expression of type wint_t whose value does not
15911     correspond to any member of the extended character set.315) It is accepted (and returned)
15912     by several functions in this subclause to indicate end-of-file, that is, no more input from a
15913     stream. It is also used as a wide character value that does not correspond to any member
15914     of the extended character set.
15915 4   The functions declared are grouped as follows:
15916     -- Functions that perform input and output of wide characters, or multibyte characters,
15917       or both;
15918     -- Functions that provide wide string numeric conversion;
15919     -- Functions that perform general wide string manipulation;
15920
15921
15922     313) See ''future library directions'' (7.30.12).
15923     314) wchar_t and wint_t can be the same integer type.
15924     315) The value of the macro WEOF may differ from that of EOF and need not be negative.
15925
15926 [page 399]
15927
15928     -- Functions for wide string date and time conversion; and
15929     -- Functions that provide extended capabilities for conversion between multibyte and
15930       wide character sequences.
15931 5   Unless explicitly stated otherwise, if the execution of a function described in this
15932     subclause causes copying to take place between objects that overlap, the behavior is
15933     undefined.
15934     7.28.2 Formatted wide character input/output functions
15935 1   The formatted wide character input/output functions shall behave as if there is a sequence
15936     point after the actions associated with each specifier.316)
15937     7.28.2.1 The fwprintf function
15938     Synopsis
15939 1           #include <stdio.h>
15940             #include <wchar.h>
15941             int fwprintf(FILE * restrict stream,
15942                  const wchar_t * restrict format, ...);
15943     Description
15944 2   The fwprintf function writes output to the stream pointed to by stream, under
15945     control of the wide string pointed to by format that specifies how subsequent arguments
15946     are converted for output. If there are insufficient arguments for the format, the behavior
15947     is undefined. If the format is exhausted while arguments remain, the excess arguments
15948     are evaluated (as always) but are otherwise ignored. The fwprintf function returns
15949     when the end of the format string is encountered.
15950 3   The format is composed of zero or more directives: ordinary wide characters (not %),
15951     which are copied unchanged to the output stream; and conversion specifications, each of
15952     which results in fetching zero or more subsequent arguments, converting them, if
15953     applicable, according to the corresponding conversion specifier, and then writing the
15954     result to the output stream.
15955 4   Each conversion specification is introduced by the wide character %. After the %, the
15956     following appear in sequence:
15957     -- Zero or more flags (in any order) that modify the meaning of the conversion
15958       specification.
15959     -- An optional minimum field width. If the converted value has fewer wide characters
15960       than the field width, it is padded with spaces (by default) on the left (or right, if the
15961
15962
15963     316) The fwprintf functions perform writes to memory for the %n specifier.
15964
15965 [page 400]
15966
15967         left adjustment flag, described later, has been given) to the field width. The field
15968         width takes the form of an asterisk * (described later) or a nonnegative decimal
15969         integer.317)
15970     -- An optional precision that gives the minimum number of digits to appear for the d, i,
15971       o, u, x, and X conversions, the number of digits to appear after the decimal-point
15972       wide character for a, A, e, E, f, and F conversions, the maximum number of
15973       significant digits for the g and G conversions, or the maximum number of wide
15974       characters to be written for s conversions. The precision takes the form of a period
15975       (.) followed either by an asterisk * (described later) or by an optional decimal
15976       integer; if only the period is specified, the precision is taken as zero. If a precision
15977       appears with any other conversion specifier, the behavior is undefined.
15978     -- An optional length modifier that specifies the size of the argument.
15979     -- A conversion specifier wide character that specifies the type of conversion to be
15980       applied.
15981 5   As noted above, a field width, or precision, or both, may be indicated by an asterisk. In
15982     this case, an int argument supplies the field width or precision. The arguments
15983     specifying field width, or precision, or both, shall appear (in that order) before the
15984     argument (if any) to be converted. A negative field width argument is taken as a - flag
15985     followed by a positive field width. A negative precision argument is taken as if the
15986     precision were omitted.
15987 6   The flag wide characters and their meanings are:
15988     -        The result of the conversion is left-justified within the field. (It is right-justified if
15989              this flag is not specified.)
15990     +        The result of a signed conversion always begins with a plus or minus sign. (It
15991              begins with a sign only when a negative value is converted if this flag is not
15992              specified.)318)
15993     space If the first wide character of a signed conversion is not a sign, or if a signed
15994           conversion results in no wide characters, a space is prefixed to the result. If the
15995           space and + flags both appear, the space flag is ignored.
15996     #        The result is converted to an ''alternative form''. For o conversion, it increases
15997              the precision, if and only if necessary, to force the first digit of the result to be a
15998              zero (if the value and precision are both 0, a single 0 is printed). For x (or X)
15999              conversion, a nonzero result has 0x (or 0X) prefixed to it. For a, A, e, E, f, F, g,
16000
16001
16002     317) Note that 0 is taken as a flag, not as the beginning of a field width.
16003     318) The results of all floating conversions of a negative zero, and of negative values that round to zero,
16004          include a minus sign.
16005
16006 [page 401]
16007
16008               and G conversions, the result of converting a floating-point number always
16009               contains a decimal-point wide character, even if no digits follow it. (Normally, a
16010               decimal-point wide character appears in the result of these conversions only if a
16011               digit follows it.) For g and G conversions, trailing zeros are not removed from the
16012               result. For other conversions, the behavior is undefined.
16013     0         For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros
16014               (following any indication of sign or base) are used to pad to the field width rather
16015               than performing space padding, except when converting an infinity or NaN. If the
16016               0 and - flags both appear, the 0 flag is ignored. For d, i, o, u, x, and X
16017               conversions, if a precision is specified, the 0 flag is ignored. For other
16018               conversions, the behavior is undefined.
16019 7   The length modifiers and their meanings are:
16020     hh             Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
16021                    signed char or unsigned char argument (the argument will have
16022                    been promoted according to the integer promotions, but its value shall be
16023                    converted to signed char or unsigned char before printing); or that
16024                    a following n conversion specifier applies to a pointer to a signed char
16025                    argument.
16026     h              Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
16027                    short int or unsigned short int argument (the argument will
16028                    have been promoted according to the integer promotions, but its value shall
16029                    be converted to short int or unsigned short int before printing);
16030                    or that a following n conversion specifier applies to a pointer to a short
16031                    int argument.
16032     l (ell)        Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
16033                    long int or unsigned long int argument; that a following n
16034                    conversion specifier applies to a pointer to a long int argument; that a
16035                    following c conversion specifier applies to a wint_t argument; that a
16036                    following s conversion specifier applies to a pointer to a wchar_t
16037                    argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion
16038                    specifier.
16039     ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
16040                  long long int or unsigned long long int argument; or that a
16041                  following n conversion specifier applies to a pointer to a long long int
16042                  argument.
16043     j              Specifies that a following d, i, o, u, x, or X conversion specifier applies to
16044                    an intmax_t or uintmax_t argument; or that a following n conversion
16045                    specifier applies to a pointer to an intmax_t argument.
16046
16047 [page 402]
16048
16049     z            Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
16050                  size_t or the corresponding signed integer type argument; or that a
16051                  following n conversion specifier applies to a pointer to a signed integer type
16052                  corresponding to size_t argument.
16053     t            Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
16054                  ptrdiff_t or the corresponding unsigned integer type argument; or that a
16055                  following n conversion specifier applies to a pointer to a ptrdiff_t
16056                  argument.
16057     L            Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
16058                  applies to a long double argument.
16059     If a length modifier appears with any conversion specifier other than as specified above,
16060     the behavior is undefined.
16061 8   The conversion specifiers and their meanings are:
16062     d,i         The int argument is converted to signed decimal in the style [-]dddd. The
16063                 precision specifies the minimum number of digits to appear; if the value
16064                 being converted can be represented in fewer digits, it is expanded with
16065                 leading zeros. The default precision is 1. The result of converting a zero
16066                 value with a precision of zero is no wide characters.
16067     o,u,x,X The unsigned int argument is converted to unsigned octal (o), unsigned
16068             decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; the
16069             letters abcdef are used for x conversion and the letters ABCDEF for X
16070             conversion. The precision specifies the minimum number of digits to appear;
16071             if the value being converted can be represented in fewer digits, it is expanded
16072             with leading zeros. The default precision is 1. The result of converting a
16073             zero value with a precision of zero is no wide characters.
16074     f,F         A double argument representing a floating-point number is converted to
16075                 decimal notation in the style [-]ddd.ddd, where the number of digits after
16076                 the decimal-point wide character is equal to the precision specification. If the
16077                 precision is missing, it is taken as 6; if the precision is zero and the # flag is
16078                 not specified, no decimal-point wide character appears. If a decimal-point
16079                 wide character appears, at least one digit appears before it. The value is
16080                 rounded to the appropriate number of digits.
16081                 A double argument representing an infinity is converted in one of the styles
16082                 [-]inf or [-]infinity -- which style is implementation-defined. A
16083                 double argument representing a NaN is converted in one of the styles
16084                 [-]nan or [-]nan(n-wchar-sequence) -- which style, and the meaning of
16085                 any n-wchar-sequence, is implementation-defined. The F conversion
16086                 specifier produces INF, INFINITY, or NAN instead of inf, infinity, or
16087
16088 [page 403]
16089
16090              nan, respectively.319)
16091 e,E          A double argument representing a floating-point number is converted in the
16092              style [-]d.ddd e(+-)dd, where there is one digit (which is nonzero if the
16093              argument is nonzero) before the decimal-point wide character and the number
16094              of digits after it is equal to the precision; if the precision is missing, it is taken
16095              as 6; if the precision is zero and the # flag is not specified, no decimal-point
16096              wide character appears. The value is rounded to the appropriate number of
16097              digits. The E conversion specifier produces a number with E instead of e
16098              introducing the exponent. The exponent always contains at least two digits,
16099              and only as many more digits as necessary to represent the exponent. If the
16100              value is zero, the exponent is zero.
16101              A double argument representing an infinity or NaN is converted in the style
16102              of an f or F conversion specifier.
16103 g,G          A double argument representing a floating-point number is converted in
16104              style f or e (or in style F or E in the case of a G conversion specifier),
16105              depending on the value converted and the precision. Let P equal the
16106              precision if nonzero, 6 if the precision is omitted, or 1 if the precision is zero.
16107              Then, if a conversion with style E would have an exponent of X:
16108              -- if P > X >= -4, the conversion is with style f (or F) and precision
16109                P - (X + 1).
16110              -- otherwise, the conversion is with style e (or E) and precision P - 1.
16111              Finally, unless the # flag is used, any trailing zeros are removed from the
16112              fractional portion of the result and the decimal-point wide character is
16113              removed if there is no fractional portion remaining.
16114              A double argument representing an infinity or NaN is converted in the style
16115              of an f or F conversion specifier.
16116 a,A          A double argument representing a floating-point number is converted in the
16117              style [-]0xh.hhhh p(+-)d, where there is one hexadecimal digit (which is
16118              nonzero if the argument is a normalized floating-point number and is
16119              otherwise unspecified) before the decimal-point wide character320) and the
16120              number of hexadecimal digits after it is equal to the precision; if the precision
16121              is missing and FLT_RADIX is a power of 2, then the precision is sufficient
16122
16123
16124 319) When applied to infinite and NaN values, the -, +, and space flag wide characters have their usual
16125      meaning; the # and 0 flag wide characters have no effect.
16126 320) Binary implementations can choose the hexadecimal digit to the left of the decimal-point wide
16127      character so that subsequent digits align to nibble (4-bit) boundaries.
16128
16129 [page 404]
16130
16131              for an exact representation of the value; if the precision is missing and
16132              FLT_RADIX is not a power of 2, then the precision is sufficient to
16133              distinguish321) values of type double, except that trailing zeros may be
16134              omitted; if the precision is zero and the # flag is not specified, no decimal-
16135              point wide character appears. The letters abcdef are used for a conversion
16136              and the letters ABCDEF for A conversion. The A conversion specifier
16137              produces a number with X and P instead of x and p. The exponent always
16138              contains at least one digit, and only as many more digits as necessary to
16139              represent the decimal exponent of 2. If the value is zero, the exponent is
16140              zero.
16141              A double argument representing an infinity or NaN is converted in the style
16142              of an f or F conversion specifier.
16143 c            If no l length modifier is present, the int argument is converted to a wide
16144              character as if by calling btowc and the resulting wide character is written.
16145              If an l length modifier is present, the wint_t argument is converted to
16146              wchar_t and written.
16147 s            If no l length modifier is present, the argument shall be a pointer to the initial
16148              element of a character array containing a multibyte character sequence
16149              beginning in the initial shift state. Characters from the array are converted as
16150              if by repeated calls to the mbrtowc function, with the conversion state
16151              described by an mbstate_t object initialized to zero before the first
16152              multibyte character is converted, and written up to (but not including) the
16153              terminating null wide character. If the precision is specified, no more than
16154              that many wide characters are written. If the precision is not specified or is
16155              greater than the size of the converted array, the converted array shall contain a
16156              null wide character.
16157              If an l length modifier is present, the argument shall be a pointer to the initial
16158              element of an array of wchar_t type. Wide characters from the array are
16159              written up to (but not including) a terminating null wide character. If the
16160              precision is specified, no more than that many wide characters are written. If
16161              the precision is not specified or is greater than the size of the array, the array
16162              shall contain a null wide character.
16163 p            The argument shall be a pointer to void. The value of the pointer is
16164              converted to a sequence of printing wide characters, in an implementation-
16165
16166 321) The precision p is sufficient to distinguish values of the source type if 16 p-1 > b n where b is
16167      FLT_RADIX and n is the number of base-b digits in the significand of the source type. A smaller p
16168      might suffice depending on the implementation's scheme for determining the digit to the left of the
16169      decimal-point wide character.
16170
16171 [page 405]
16172
16173                     defined manner.
16174      n              The argument shall be a pointer to signed integer into which is written the
16175                     number of wide characters written to the output stream so far by this call to
16176                     fwprintf. No argument is converted, but one is consumed. If the
16177                     conversion specification includes any flags, a field width, or a precision, the
16178                     behavior is undefined.
16179      %              A % wide character is written. No argument is converted. The complete
16180                     conversion specification shall be %%.
16181 9    If a conversion specification is invalid, the behavior is undefined.322) If any argument is
16182      not the correct type for the corresponding conversion specification, the behavior is
16183      undefined.
16184 10   In no case does a nonexistent or small field width cause truncation of a field; if the result
16185      of a conversion is wider than the field width, the field is expanded to contain the
16186      conversion result.
16187 11   For a and A conversions, if FLT_RADIX is a power of 2, the value is correctly rounded
16188      to a hexadecimal floating number with the given precision.
16189      Recommended practice
16190 12   For a and A conversions, if FLT_RADIX is not a power of 2 and the result is not exactly
16191      representable in the given precision, the result should be one of the two adjacent numbers
16192      in hexadecimal floating style with the given precision, with the extra stipulation that the
16193      error should have a correct sign for the current rounding direction.
16194 13   For e, E, f, F, g, and G conversions, if the number of significant decimal digits is at most
16195      DECIMAL_DIG, then the result should be correctly rounded.323) If the number of
16196      significant decimal digits is more than DECIMAL_DIG but the source value is exactly
16197      representable with DECIMAL_DIG digits, then the result should be an exact
16198      representation with trailing zeros. Otherwise, the source value is bounded by two
16199      adjacent decimal strings L < U, both having DECIMAL_DIG significant digits; the value
16200      of the resultant decimal string D should satisfy L <= D <= U, with the extra stipulation that
16201      the error should have a correct sign for the current rounding direction.
16202      Returns
16203 14   The fwprintf function returns the number of wide characters transmitted, or a negative
16204      value if an output or encoding error occurred.
16205
16206      322) See ''future library directions'' (7.30.12).
16207      323) For binary-to-decimal conversion, the result format's values are the numbers representable with the
16208           given format specifier. The number of significant digits is determined by the format specifier, and in
16209           the case of fixed-point conversion by the source value as well.
16210
16211 [page 406]
16212
16213      Environmental limits
16214 15   The number of wide characters that can be produced by any single conversion shall be at
16215      least 4095.
16216 16   EXAMPLE       To print a date and time in the form ''Sunday, July 3, 10:02'' followed by pi to five decimal
16217      places:
16218              #include <math.h>
16219              #include <stdio.h>
16220              #include <wchar.h>
16221              /* ... */
16222              wchar_t *weekday, *month; // pointers to wide strings
16223              int day, hour, min;
16224              fwprintf(stdout, L"%ls, %ls %d, %.2d:%.2d\n",
16225                      weekday, month, day, hour, min);
16226              fwprintf(stdout, L"pi = %.5f\n", 4 * atan(1.0));
16227
16228      Forward references:          the btowc function (7.28.6.1.1), the mbrtowc function
16229      (7.28.6.3.2).
16230      7.28.2.2 The fwscanf function
16231      Synopsis
16232 1            #include <stdio.h>
16233              #include <wchar.h>
16234              int fwscanf(FILE * restrict stream,
16235                   const wchar_t * restrict format, ...);
16236      Description
16237 2    The fwscanf function reads input from the stream pointed to by stream, under
16238      control of the wide string pointed to by format that specifies the admissible input
16239      sequences and how they are to be converted for assignment, using subsequent arguments
16240      as pointers to the objects to receive the converted input. If there are insufficient
16241      arguments for the format, the behavior is undefined. If the format is exhausted while
16242      arguments remain, the excess arguments are evaluated (as always) but are otherwise
16243      ignored.
16244 3    The format is composed of zero or more directives: one or more white-space wide
16245      characters, an ordinary wide character (neither % nor a white-space wide character), or a
16246      conversion specification. Each conversion specification is introduced by the wide
16247      character %. After the %, the following appear in sequence:
16248      -- An optional assignment-suppressing wide character *.
16249      -- An optional decimal integer greater than zero that specifies the maximum field width
16250        (in wide characters).
16251
16252
16253
16254 [page 407]
16255
16256      -- An optional length modifier that specifies the size of the receiving object.
16257      -- A conversion specifier wide character that specifies the type of conversion to be
16258        applied.
16259 4    The fwscanf function executes each directive of the format in turn. When all directives
16260      have been executed, or if a directive fails (as detailed below), the function returns.
16261      Failures are described as input failures (due to the occurrence of an encoding error or the
16262      unavailability of input characters), or matching failures (due to inappropriate input).
16263 5    A directive composed of white-space wide character(s) is executed by reading input up to
16264      the first non-white-space wide character (which remains unread), or until no more wide
16265      characters can be read.
16266 6    A directive that is an ordinary wide character is executed by reading the next wide
16267      character of the stream. If that wide character differs from the directive, the directive
16268      fails and the differing and subsequent wide characters remain unread. Similarly, if end-
16269      of-file, an encoding error, or a read error prevents a wide character from being read, the
16270      directive fails.
16271 7    A directive that is a conversion specification defines a set of matching input sequences, as
16272      described below for each specifier. A conversion specification is executed in the
16273      following steps:
16274 8    Input white-space wide characters (as specified by the iswspace function) are skipped,
16275      unless the specification includes a [, c, or n specifier.324)
16276 9    An input item is read from the stream, unless the specification includes an n specifier. An
16277      input item is defined as the longest sequence of input wide characters which does not
16278      exceed any specified field width and which is, or is a prefix of, a matching input
16279      sequence.325) The first wide character, if any, after the input item remains unread. If the
16280      length of the input item is zero, the execution of the directive fails; this condition is a
16281      matching failure unless end-of-file, an encoding error, or a read error prevented input
16282      from the stream, in which case it is an input failure.
16283 10   Except in the case of a % specifier, the input item (or, in the case of a %n directive, the
16284      count of input wide characters) is converted to a type appropriate to the conversion
16285      specifier. If the input item is not a matching sequence, the execution of the directive fails:
16286      this condition is a matching failure. Unless assignment suppression was indicated by a *,
16287      the result of the conversion is placed in the object pointed to by the first argument
16288      following the format argument that has not already received a conversion result. If this
16289
16290
16291      324) These white-space wide characters are not counted against a specified field width.
16292      325) fwscanf pushes back at most one input wide character onto the input stream. Therefore, some
16293           sequences that are acceptable to wcstod, wcstol, etc., are unacceptable to fwscanf.
16294
16295 [page 408]
16296
16297      object does not have an appropriate type, or if the result of the conversion cannot be
16298      represented in the object, the behavior is undefined.
16299 11   The length modifiers and their meanings are:
16300      hh           Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16301                   to an argument with type pointer to signed char or unsigned char.
16302      h            Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16303                   to an argument with type pointer to short int or unsigned short
16304                   int.
16305      l (ell)      Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16306                   to an argument with type pointer to long int or unsigned long
16307                   int; that a following a, A, e, E, f, F, g, or G conversion specifier applies to
16308                   an argument with type pointer to double; or that a following c, s, or [
16309                   conversion specifier applies to an argument with type pointer to wchar_t.
16310      ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16311                   to an argument with type pointer to long long int or unsigned
16312                   long long int.
16313      j            Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16314                   to an argument with type pointer to intmax_t or uintmax_t.
16315      z            Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16316                   to an argument with type pointer to size_t or the corresponding signed
16317                   integer type.
16318      t            Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16319                   to an argument with type pointer to ptrdiff_t or the corresponding
16320                   unsigned integer type.
16321      L            Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
16322                   applies to an argument with type pointer to long double.
16323      If a length modifier appears with any conversion specifier other than as specified above,
16324      the behavior is undefined.
16325 12   The conversion specifiers and their meanings are:
16326      d           Matches an optionally signed decimal integer, whose format is the same as
16327                  expected for the subject sequence of the wcstol function with the value 10
16328                  for the base argument. The corresponding argument shall be a pointer to
16329                  signed integer.
16330      i           Matches an optionally signed integer, whose format is the same as expected
16331                  for the subject sequence of the wcstol function with the value 0 for the
16332                  base argument. The corresponding argument shall be a pointer to signed
16333
16334 [page 409]
16335
16336           integer.
16337 o         Matches an optionally signed octal integer, whose format is the same as
16338           expected for the subject sequence of the wcstoul function with the value 8
16339           for the base argument. The corresponding argument shall be a pointer to
16340           unsigned integer.
16341 u         Matches an optionally signed decimal integer, whose format is the same as
16342           expected for the subject sequence of the wcstoul function with the value 10
16343           for the base argument. The corresponding argument shall be a pointer to
16344           unsigned integer.
16345 x         Matches an optionally signed hexadecimal integer, whose format is the same
16346           as expected for the subject sequence of the wcstoul function with the value
16347           16 for the base argument. The corresponding argument shall be a pointer to
16348           unsigned integer.
16349 a,e,f,g Matches an optionally signed floating-point number, infinity, or NaN, whose
16350         format is the same as expected for the subject sequence of the wcstod
16351         function. The corresponding argument shall be a pointer to floating.
16352 c         Matches a sequence of wide characters of exactly the number specified by the
16353           field width (1 if no field width is present in the directive).
16354           If no l length modifier is present, characters from the input field are
16355           converted as if by repeated calls to the wcrtomb function, with the
16356           conversion state described by an mbstate_t object initialized to zero
16357           before the first wide character is converted. The corresponding argument
16358           shall be a pointer to the initial element of a character array large enough to
16359           accept the sequence. No null character is added.
16360           If an l length modifier is present, the corresponding argument shall be a
16361           pointer to the initial element of an array of wchar_t large enough to accept
16362           the sequence. No null wide character is added.
16363 s         Matches a sequence of non-white-space wide characters.
16364           If no l length modifier is present, characters from the input field are
16365           converted as if by repeated calls to the wcrtomb function, with the
16366           conversion state described by an mbstate_t object initialized to zero
16367           before the first wide character is converted. The corresponding argument
16368           shall be a pointer to the initial element of a character array large enough to
16369           accept the sequence and a terminating null character, which will be added
16370           automatically.
16371           If an l length modifier is present, the corresponding argument shall be a
16372           pointer to the initial element of an array of wchar_t large enough to accept
16373
16374 [page 410]
16375
16376             the sequence and the terminating null wide character, which will be added
16377             automatically.
16378 [           Matches a nonempty sequence of wide characters from a set of expected
16379             characters (the scanset).
16380             If no l length modifier is present, characters from the input field are
16381             converted as if by repeated calls to the wcrtomb function, with the
16382             conversion state described by an mbstate_t object initialized to zero
16383             before the first wide character is converted. The corresponding argument
16384             shall be a pointer to the initial element of a character array large enough to
16385             accept the sequence and a terminating null character, which will be added
16386             automatically.
16387             If an l length modifier is present, the corresponding argument shall be a
16388             pointer to the initial element of an array of wchar_t large enough to accept
16389             the sequence and the terminating null wide character, which will be added
16390             automatically.
16391             The conversion specifier includes all subsequent wide characters in the
16392             format string, up to and including the matching right bracket (]). The wide
16393             characters between the brackets (the scanlist) compose the scanset, unless the
16394             wide character after the left bracket is a circumflex (^), in which case the
16395             scanset contains all wide characters that do not appear in the scanlist between
16396             the circumflex and the right bracket. If the conversion specifier begins with
16397             [] or [^], the right bracket wide character is in the scanlist and the next
16398             following right bracket wide character is the matching right bracket that ends
16399             the specification; otherwise the first following right bracket wide character is
16400             the one that ends the specification. If a - wide character is in the scanlist and
16401             is not the first, nor the second where the first wide character is a ^, nor the
16402             last character, the behavior is implementation-defined.
16403 p           Matches an implementation-defined set of sequences, which should be the
16404             same as the set of sequences that may be produced by the %p conversion of
16405             the fwprintf function. The corresponding argument shall be a pointer to a
16406             pointer to void. The input item is converted to a pointer value in an
16407             implementation-defined manner. If the input item is a value converted earlier
16408             during the same program execution, the pointer that results shall compare
16409             equal to that value; otherwise the behavior of the %p conversion is undefined.
16410 n           No input is consumed. The corresponding argument shall be a pointer to
16411             signed integer into which is to be written the number of wide characters read
16412             from the input stream so far by this call to the fwscanf function. Execution
16413             of a %n directive does not increment the assignment count returned at the
16414             completion of execution of the fwscanf function. No argument is
16415 [page 411]
16416
16417                     converted, but one is consumed. If the conversion specification includes an
16418                     assignment-suppressing wide character or a field width, the behavior is
16419                     undefined.
16420      %              Matches a single % wide character; no conversion or assignment occurs. The
16421                     complete conversion specification shall be %%.
16422 13   If a conversion specification is invalid, the behavior is undefined.326)
16423 14   The conversion specifiers A, E, F, G, and X are also valid and behave the same as,
16424      respectively, a, e, f, g, and x.
16425 15   Trailing white space (including new-line wide characters) is left unread unless matched
16426      by a directive. The success of literal matches and suppressed assignments is not directly
16427      determinable other than via the %n directive.
16428      Returns
16429 16   The fwscanf function returns the value of the macro EOF if an input failure occurs
16430      before the first conversion (if any) has completed. Otherwise, the function returns the
16431      number of input items assigned, which can be fewer than provided for, or even zero, in
16432      the event of an early matching failure.
16433 17   EXAMPLE 1        The call:
16434               #include <stdio.h>
16435               #include <wchar.h>
16436               /* ... */
16437               int n, i; float x; wchar_t name[50];
16438               n = fwscanf(stdin, L"%d%f%ls", &i, &x, name);
16439      with the input line:
16440               25 54.32E-1 thompson
16441      will assign to n the value 3, to i the value 25, to x the value 5.432, and to name the sequence
16442      thompson\0.
16443
16444 18   EXAMPLE 2        The call:
16445               #include <stdio.h>
16446               #include <wchar.h>
16447               /* ... */
16448               int i; float x; double y;
16449               fwscanf(stdin, L"%2d%f%*d %lf", &i, &x, &y);
16450      with input:
16451               56789 0123 56a72
16452      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
16453      56.0. The next wide character read from the input stream will be a.
16454
16455
16456      326) See ''future library directions'' (7.30.12).
16457
16458 [page 412]
16459
16460     Forward references: the wcstod, wcstof, and wcstold functions (7.28.4.1.1), the
16461     wcstol, wcstoll, wcstoul, and wcstoull functions (7.28.4.1.2), the wcrtomb
16462     function (7.28.6.3.3).
16463     7.28.2.3 The swprintf function
16464     Synopsis
16465 1           #include <wchar.h>
16466             int swprintf(wchar_t * restrict s,
16467                  size_t n,
16468                  const wchar_t * restrict format, ...);
16469     Description
16470 2   The swprintf function is equivalent to fwprintf, except that the argument s
16471     specifies an array of wide characters into which the generated output is to be written,
16472     rather than written to a stream. No more than n wide characters are written, including a
16473     terminating null wide character, which is always added (unless n is zero).
16474     Returns
16475 3   The swprintf function returns the number of wide characters written in the array, not
16476     counting the terminating null wide character, or a negative value if an encoding error
16477     occurred or if n or more wide characters were requested to be written.
16478     7.28.2.4 The swscanf function
16479     Synopsis
16480 1           #include <wchar.h>
16481             int swscanf(const wchar_t * restrict s,
16482                  const wchar_t * restrict format, ...);
16483     Description
16484 2   The swscanf function is equivalent to fwscanf, except that the argument s specifies a
16485     wide string from which the input is to be obtained, rather than from a stream. Reaching
16486     the end of the wide string is equivalent to encountering end-of-file for the fwscanf
16487     function.
16488     Returns
16489 3   The swscanf function returns the value of the macro EOF if an input failure occurs
16490     before the first conversion (if any) has completed. Otherwise, the swscanf function
16491     returns the number of input items assigned, which can be fewer than provided for, or even
16492     zero, in the event of an early matching failure.
16493
16494
16495
16496
16497 [page 413]
16498
16499     7.28.2.5 The vfwprintf function
16500     Synopsis
16501 1          #include <stdarg.h>
16502            #include <stdio.h>
16503            #include <wchar.h>
16504            int vfwprintf(FILE * restrict stream,
16505                 const wchar_t * restrict format,
16506                 va_list arg);
16507     Description
16508 2   The vfwprintf function is equivalent to fwprintf, with the variable argument list
16509     replaced by arg, which shall have been initialized by the va_start macro (and
16510     possibly subsequent va_arg calls). The vfwprintf function does not invoke the
16511     va_end macro.327)
16512     Returns
16513 3   The vfwprintf function returns the number of wide characters transmitted, or a
16514     negative value if an output or encoding error occurred.
16515 4   EXAMPLE       The following shows the use of the vfwprintf function in a general error-reporting
16516     routine.
16517            #include <stdarg.h>
16518            #include <stdio.h>
16519            #include <wchar.h>
16520            void error(char *function_name, wchar_t *format, ...)
16521            {
16522                  va_list args;
16523                     va_start(args, format);
16524                     // print out name of function causing error
16525                     fwprintf(stderr, L"ERROR in %s: ", function_name);
16526                     // print out remainder of message
16527                     vfwprintf(stderr, format, args);
16528                     va_end(args);
16529            }
16530
16531
16532
16533
16534     327) As the functions vfwprintf, vswprintf, vfwscanf, vwprintf, vwscanf, and vswscanf
16535          invoke the va_arg macro, the value of arg after the return is indeterminate.
16536
16537 [page 414]
16538
16539     7.28.2.6 The vfwscanf function
16540     Synopsis
16541 1           #include <stdarg.h>
16542             #include <stdio.h>
16543             #include <wchar.h>
16544             int vfwscanf(FILE * restrict stream,
16545                  const wchar_t * restrict format,
16546                  va_list arg);
16547     Description
16548 2   The vfwscanf function is equivalent to fwscanf, with the variable argument list
16549     replaced by arg, which shall have been initialized by the va_start macro (and
16550     possibly subsequent va_arg calls). The vfwscanf function does not invoke the
16551     va_end macro.327)
16552     Returns
16553 3   The vfwscanf function returns the value of the macro EOF if an input failure occurs
16554     before the first conversion (if any) has completed. Otherwise, the vfwscanf function
16555     returns the number of input items assigned, which can be fewer than provided for, or even
16556     zero, in the event of an early matching failure.
16557     7.28.2.7 The vswprintf function
16558     Synopsis
16559 1           #include <stdarg.h>
16560             #include <wchar.h>
16561             int vswprintf(wchar_t * restrict s,
16562                  size_t n,
16563                  const wchar_t * restrict format,
16564                  va_list arg);
16565     Description
16566 2   The vswprintf function is equivalent to swprintf, with the variable argument list
16567     replaced by arg, which shall have been initialized by the va_start macro (and
16568     possibly subsequent va_arg calls). The vswprintf function does not invoke the
16569     va_end macro.327)
16570     Returns
16571 3   The vswprintf function returns the number of wide characters written in the array, not
16572     counting the terminating null wide character, or a negative value if an encoding error
16573     occurred or if n or more wide characters were requested to be generated.
16574
16575
16576 [page 415]
16577
16578     7.28.2.8 The vswscanf function
16579     Synopsis
16580 1          #include <stdarg.h>
16581            #include <wchar.h>
16582            int vswscanf(const wchar_t * restrict s,
16583                 const wchar_t * restrict format,
16584                 va_list arg);
16585     Description
16586 2   The vswscanf function is equivalent to swscanf, with the variable argument list
16587     replaced by arg, which shall have been initialized by the va_start macro (and
16588     possibly subsequent va_arg calls). The vswscanf function does not invoke the
16589     va_end macro.327)
16590     Returns
16591 3   The vswscanf function returns the value of the macro EOF if an input failure occurs
16592     before the first conversion (if any) has completed. Otherwise, the vswscanf function
16593     returns the number of input items assigned, which can be fewer than provided for, or even
16594     zero, in the event of an early matching failure.
16595     7.28.2.9 The vwprintf function
16596     Synopsis
16597 1          #include <stdarg.h>
16598            #include <wchar.h>
16599            int vwprintf(const wchar_t * restrict format,
16600                 va_list arg);
16601     Description
16602 2   The vwprintf function is equivalent to wprintf, with the variable argument list
16603     replaced by arg, which shall have been initialized by the va_start macro (and
16604     possibly subsequent va_arg calls). The vwprintf function does not invoke the
16605     va_end macro.327)
16606     Returns
16607 3   The vwprintf function returns the number of wide characters transmitted, or a negative
16608     value if an output or encoding error occurred.
16609
16610
16611
16612
16613 [page 416]
16614
16615     7.28.2.10 The vwscanf function
16616     Synopsis
16617 1           #include <stdarg.h>
16618             #include <wchar.h>
16619             int vwscanf(const wchar_t * restrict format,
16620                  va_list arg);
16621     Description
16622 2   The vwscanf function is equivalent to wscanf, with the variable argument list
16623     replaced by arg, which shall have been initialized by the va_start macro (and
16624     possibly subsequent va_arg calls). The vwscanf function does not invoke the
16625     va_end macro.327)
16626     Returns
16627 3   The vwscanf function returns the value of the macro EOF if an input failure occurs
16628     before the first conversion (if any) has completed. Otherwise, the vwscanf function
16629     returns the number of input items assigned, which can be fewer than provided for, or even
16630     zero, in the event of an early matching failure.
16631     7.28.2.11 The wprintf function
16632     Synopsis
16633 1           #include <wchar.h>
16634             int wprintf(const wchar_t * restrict format, ...);
16635     Description
16636 2   The wprintf function is equivalent to fwprintf with the argument stdout
16637     interposed before the arguments to wprintf.
16638     Returns
16639 3   The wprintf function returns the number of wide characters transmitted, or a negative
16640     value if an output or encoding error occurred.
16641     7.28.2.12 The wscanf function
16642     Synopsis
16643 1           #include <wchar.h>
16644             int wscanf(const wchar_t * restrict format, ...);
16645     Description
16646 2   The wscanf function is equivalent to fwscanf with the argument stdin interposed
16647     before the arguments to wscanf.
16648
16649
16650 [page 417]
16651
16652     Returns
16653 3   The wscanf function returns the value of the macro EOF if an input failure occurs
16654     before the first conversion (if any) has completed. Otherwise, the wscanf function
16655     returns the number of input items assigned, which can be fewer than provided for, or even
16656     zero, in the event of an early matching failure.
16657     7.28.3 Wide character input/output functions
16658     7.28.3.1 The fgetwc function
16659     Synopsis
16660 1           #include <stdio.h>
16661             #include <wchar.h>
16662             wint_t fgetwc(FILE *stream);
16663     Description
16664 2   If the end-of-file indicator for the input stream pointed to by stream is not set and a
16665     next wide character is present, the fgetwc function obtains that wide character as a
16666     wchar_t converted to a wint_t and advances the associated file position indicator for
16667     the stream (if defined).
16668     Returns
16669 3   If the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-
16670     of-file indicator for the stream is set and the fgetwc function returns WEOF. Otherwise,
16671     the fgetwc function returns the next wide character from the input stream pointed to by
16672     stream. If a read error occurs, the error indicator for the stream is set and the fgetwc
16673     function returns WEOF. If an encoding error occurs (including too few bytes), the value of
16674     the macro EILSEQ is stored in errno and the fgetwc function returns WEOF.328)
16675     7.28.3.2 The fgetws function
16676     Synopsis
16677 1           #include <stdio.h>
16678             #include <wchar.h>
16679             wchar_t *fgetws(wchar_t * restrict s,
16680                  int n, FILE * restrict stream);
16681     Description
16682 2   The fgetws function reads at most one less than the number of wide characters
16683     specified by n from the stream pointed to by stream into the array pointed to by s. No
16684
16685
16686     328) An end-of-file and a read error can be distinguished by use of the feof and ferror functions.
16687          Also, errno will be set to EILSEQ by input/output functions only if an encoding error occurs.
16688
16689 [page 418]
16690
16691     additional wide characters are read after a new-line wide character (which is retained) or
16692     after end-of-file. A null wide character is written immediately after the last wide
16693     character read into the array.
16694     Returns
16695 3   The fgetws function returns s if successful. If end-of-file is encountered and no
16696     characters have been read into the array, the contents of the array remain unchanged and a
16697     null pointer is returned. If a read or encoding error occurs during the operation, the array
16698     contents are indeterminate and a null pointer is returned.
16699     7.28.3.3 The fputwc function
16700     Synopsis
16701 1           #include <stdio.h>
16702             #include <wchar.h>
16703             wint_t fputwc(wchar_t c, FILE *stream);
16704     Description
16705 2   The fputwc function writes the wide character specified by c to the output stream
16706     pointed to by stream, at the position indicated by the associated file position indicator
16707     for the stream (if defined), and advances the indicator appropriately. If the file cannot
16708     support positioning requests, or if the stream was opened with append mode, the
16709     character is appended to the output stream.
16710     Returns
16711 3   The fputwc function returns the wide character written. If a write error occurs, the
16712     error indicator for the stream is set and fputwc returns WEOF. If an encoding error
16713     occurs, the value of the macro EILSEQ is stored in errno and fputwc returns WEOF.
16714     7.28.3.4 The fputws function
16715     Synopsis
16716 1           #include <stdio.h>
16717             #include <wchar.h>
16718             int fputws(const wchar_t * restrict s,
16719                  FILE * restrict stream);
16720     Description
16721 2   The fputws function writes the wide string pointed to by s to the stream pointed to by
16722     stream. The terminating null wide character is not written.
16723     Returns
16724 3   The fputws function returns EOF if a write or encoding error occurs; otherwise, it
16725     returns a nonnegative value.
16726
16727 [page 419]
16728
16729     7.28.3.5 The fwide function
16730     Synopsis
16731 1           #include <stdio.h>
16732             #include <wchar.h>
16733             int fwide(FILE *stream, int mode);
16734     Description
16735 2   The fwide function determines the orientation of the stream pointed to by stream. If
16736     mode is greater than zero, the function first attempts to make the stream wide oriented. If
16737     mode is less than zero, the function first attempts to make the stream byte oriented.329)
16738     Otherwise, mode is zero and the function does not alter the orientation of the stream.
16739     Returns
16740 3   The fwide function returns a value greater than zero if, after the call, the stream has
16741     wide orientation, a value less than zero if the stream has byte orientation, or zero if the
16742     stream has no orientation.
16743     7.28.3.6 The getwc function
16744     Synopsis
16745 1           #include <stdio.h>
16746             #include <wchar.h>
16747             wint_t getwc(FILE *stream);
16748     Description
16749 2   The getwc function is equivalent to fgetwc, except that if it is implemented as a
16750     macro, it may evaluate stream more than once, so the argument should never be an
16751     expression with side effects.
16752     Returns
16753 3   The getwc function returns the next wide character from the input stream pointed to by
16754     stream, or WEOF.
16755     7.28.3.7 The getwchar function
16756     Synopsis
16757 1           #include <wchar.h>
16758             wint_t getwchar(void);
16759
16760
16761
16762
16763     329) If the orientation of the stream has already been determined, fwide does not change it.
16764
16765 [page 420]
16766
16767     Description
16768 2   The getwchar function is equivalent to getwc with the argument stdin.
16769     Returns
16770 3   The getwchar function returns the next wide character from the input stream pointed to
16771     by stdin, or WEOF.
16772     7.28.3.8 The putwc function
16773     Synopsis
16774 1           #include <stdio.h>
16775             #include <wchar.h>
16776             wint_t putwc(wchar_t c, FILE *stream);
16777     Description
16778 2   The putwc function is equivalent to fputwc, except that if it is implemented as a
16779     macro, it may evaluate stream more than once, so that argument should never be an
16780     expression with side effects.
16781     Returns
16782 3   The putwc function returns the wide character written, or WEOF.
16783     7.28.3.9 The putwchar function
16784     Synopsis
16785 1           #include <wchar.h>
16786             wint_t putwchar(wchar_t c);
16787     Description
16788 2   The putwchar function is equivalent to putwc with the second argument stdout.
16789     Returns
16790 3   The putwchar function returns the character written, or WEOF.
16791     7.28.3.10 The ungetwc function
16792     Synopsis
16793 1           #include <stdio.h>
16794             #include <wchar.h>
16795             wint_t ungetwc(wint_t c, FILE *stream);
16796     Description
16797 2   The ungetwc function pushes the wide character specified by c back onto the input
16798     stream pointed to by stream. Pushed-back wide characters will be returned by
16799     subsequent reads on that stream in the reverse order of their pushing. A successful
16800
16801 [page 421]
16802
16803     intervening call (with the stream pointed to by stream) to a file positioning function
16804     (fseek, fsetpos, or rewind) discards any pushed-back wide characters for the
16805     stream. The external storage corresponding to the stream is unchanged.
16806 3   One wide character of pushback is guaranteed, even if the call to the ungetwc function
16807     follows just after a call to a formatted wide character input function fwscanf,
16808     vfwscanf, vwscanf, or wscanf. If the ungetwc function is called too many times
16809     on the same stream without an intervening read or file positioning operation on that
16810     stream, the operation may fail.
16811 4   If the value of c equals that of the macro WEOF, the operation fails and the input stream is
16812     unchanged.
16813 5   A successful call to the ungetwc function clears the end-of-file indicator for the stream.
16814     The value of the file position indicator for the stream after reading or discarding all
16815     pushed-back wide characters is the same as it was before the wide characters were pushed
16816     back. For a text or binary stream, the value of its file position indicator after a successful
16817     call to the ungetwc function is unspecified until all pushed-back wide characters are
16818     read or discarded.
16819     Returns
16820 6   The ungetwc function returns the wide character pushed back, or WEOF if the operation
16821     fails.
16822     7.28.4 General wide string utilities
16823 1   The header <wchar.h> declares a number of functions useful for wide string
16824     manipulation. Various methods are used for determining the lengths of the arrays, but in
16825     all cases a wchar_t * argument points to the initial (lowest addressed) element of the
16826     array. If an array is accessed beyond the end of an object, the behavior is undefined.
16827 2   Where an argument declared as size_t n determines the length of the array for a
16828     function, n can have the value zero on a call to that function. Unless explicitly stated
16829     otherwise in the description of a particular function in this subclause, pointer arguments
16830     on such a call shall still have valid values, as described in 7.1.4. On such a call, a
16831     function that locates a wide character finds no occurrence, a function that compares two
16832     wide character sequences returns zero, and a function that copies wide characters copies
16833     zero wide characters.
16834
16835
16836
16837
16838 [page 422]
16839
16840     7.28.4.1 Wide string numeric conversion functions
16841     7.28.4.1.1 The wcstod, wcstof, and wcstold functions
16842     Synopsis
16843 1           #include <wchar.h>
16844             double wcstod(const wchar_t * restrict nptr,
16845                  wchar_t ** restrict endptr);
16846             float wcstof(const wchar_t * restrict nptr,
16847                  wchar_t ** restrict endptr);
16848             long double wcstold(const wchar_t * restrict nptr,
16849                  wchar_t ** restrict endptr);
16850     Description
16851 2   The wcstod, wcstof, and wcstold functions convert the initial portion of the wide
16852     string pointed to by nptr to double, float, and long double representation,
16853     respectively. First, they decompose the input string into three parts: an initial, possibly
16854     empty, sequence of white-space wide characters (as specified by the iswspace
16855     function), a subject sequence resembling a floating-point constant or representing an
16856     infinity or NaN; and a final wide string of one or more unrecognized wide characters,
16857     including the terminating null wide character of the input wide string. Then, they attempt
16858     to convert the subject sequence to a floating-point number, and return the result.
16859 3   The expected form of the subject sequence is an optional plus or minus sign, then one of
16860     the following:
16861     -- a nonempty sequence of decimal digits optionally containing a decimal-point wide
16862       character, then an optional exponent part as defined for the corresponding single-byte
16863       characters in 6.4.4.2;
16864     -- a 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing a
16865       decimal-point wide character, then an optional binary exponent part as defined in
16866       6.4.4.2;
16867     -- INF or INFINITY, or any other wide string equivalent except for case
16868     -- NAN or NAN(n-wchar-sequenceopt), or any other wide string equivalent except for
16869       case in the NAN part, where:
16870                n-wchar-sequence:
16871                      digit
16872                      nondigit
16873                      n-wchar-sequence digit
16874                      n-wchar-sequence nondigit
16875     The subject sequence is defined as the longest initial subsequence of the input wide
16876     string, starting with the first non-white-space wide character, that is of the expected form.
16877 [page 423]
16878
16879     The subject sequence contains no wide characters if the input wide string is not of the
16880     expected form.
16881 4   If the subject sequence has the expected form for a floating-point number, the sequence of
16882     wide characters starting with the first digit or the decimal-point wide character
16883     (whichever occurs first) is interpreted as a floating constant according to the rules of
16884     6.4.4.2, except that the decimal-point wide character is used in place of a period, and that
16885     if neither an exponent part nor a decimal-point wide character appears in a decimal
16886     floating point number, or if a binary exponent part does not appear in a hexadecimal
16887     floating point number, an exponent part of the appropriate type with value zero is
16888     assumed to follow the last digit in the string. If the subject sequence begins with a minus
16889     sign, the sequence is interpreted as negated.330) A wide character sequence INF or
16890     INFINITY is interpreted as an infinity, if representable in the return type, else like a
16891     floating constant that is too large for the range of the return type. A wide character
16892     sequence NAN or NAN(n-wchar-sequenceopt) is interpreted as a quiet NaN, if supported
16893     in the return type, else like a subject sequence part that does not have the expected form;
16894     the meaning of the n-wchar sequences is implementation-defined.331) A pointer to the
16895     final wide string is stored in the object pointed to by endptr, provided that endptr is
16896     not a null pointer.
16897 5   If the subject sequence has the hexadecimal form and FLT_RADIX is a power of 2, the
16898     value resulting from the conversion is correctly rounded.
16899 6   In other than the "C" locale, additional locale-specific subject sequence forms may be
16900     accepted.
16901 7   If the subject sequence is empty or does not have the expected form, no conversion is
16902     performed; the value of nptr is stored in the object pointed to by endptr, provided
16903     that endptr is not a null pointer.
16904     Recommended practice
16905 8   If the subject sequence has the hexadecimal form, FLT_RADIX is not a power of 2, and
16906     the result is not exactly representable, the result should be one of the two numbers in the
16907     appropriate internal format that are adjacent to the hexadecimal floating source value,
16908     with the extra stipulation that the error should have a correct sign for the current rounding
16909     direction.
16910
16911
16912
16913     330) It is unspecified whether a minus-signed sequence is converted to a negative number directly or by
16914          negating the value resulting from converting the corresponding unsigned sequence (see F.5); the two
16915          methods may yield different results if rounding is toward positive or negative infinity. In either case,
16916          the functions honor the sign of zero if floating-point arithmetic supports signed zeros.
16917     331) An implementation may use the n-wchar sequence to determine extra information to be represented in
16918          the NaN's significand.
16919
16920 [page 424]
16921
16922 9    If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in
16923      <float.h>) significant digits, the result should be correctly rounded. If the subject
16924      sequence D has the decimal form and more than DECIMAL_DIG significant digits,
16925      consider the two bounding, adjacent decimal strings L and U, both having
16926      DECIMAL_DIG significant digits, such that the values of L, D, and U satisfy L <= D <= U.
16927      The result should be one of the (equal or adjacent) values that would be obtained by
16928      correctly rounding L and U according to the current rounding direction, with the extra
16929      stipulation that the error with respect to D should have a correct sign for the current
16930      rounding direction.332)
16931      Returns
16932 10   The functions return the converted value, if any. If no conversion could be performed,
16933      zero is returned. If the correct value overflows and default rounding is in effect (7.12.1),
16934      plus or minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the
16935      return type and sign of the value), and the value of the macro ERANGE is stored in
16936      errno. If the result underflows (7.12.1), the functions return a value whose magnitude is
16937      no greater than the smallest normalized positive number in the return type; whether
16938      errno acquires the value ERANGE is implementation-defined.
16939
16940
16941
16942
16943      332) DECIMAL_DIG, defined in <float.h>, should be sufficiently large that L and U will usually round
16944           to the same internal floating value, but if not will round to adjacent values.
16945
16946 [page 425]
16947
16948     7.28.4.1.2 The wcstol, wcstoll, wcstoul, and wcstoull functions
16949     Synopsis
16950 1          #include <wchar.h>
16951            long int wcstol(
16952                 const wchar_t * restrict nptr,
16953                 wchar_t ** restrict endptr,
16954                 int base);
16955            long long int wcstoll(
16956                 const wchar_t * restrict nptr,
16957                 wchar_t ** restrict endptr,
16958                 int base);
16959            unsigned long int wcstoul(
16960                 const wchar_t * restrict nptr,
16961                 wchar_t ** restrict endptr,
16962                 int base);
16963            unsigned long long int wcstoull(
16964                 const wchar_t * restrict nptr,
16965                 wchar_t ** restrict endptr,
16966                 int base);
16967     Description
16968 2   The wcstol, wcstoll, wcstoul, and wcstoull functions convert the initial
16969     portion of the wide string pointed to by nptr to long int, long long int,
16970     unsigned long int, and unsigned long long int representation,
16971     respectively. First, they decompose the input string into three parts: an initial, possibly
16972     empty, sequence of white-space wide characters (as specified by the iswspace
16973     function), a subject sequence resembling an integer represented in some radix determined
16974     by the value of base, and a final wide string of one or more unrecognized wide
16975     characters, including the terminating null wide character of the input wide string. Then,
16976     they attempt to convert the subject sequence to an integer, and return the result.
16977 3   If the value of base is zero, the expected form of the subject sequence is that of an
16978     integer constant as described for the corresponding single-byte characters in 6.4.4.1,
16979     optionally preceded by a plus or minus sign, but not including an integer suffix. If the
16980     value of base is between 2 and 36 (inclusive), the expected form of the subject sequence
16981     is a sequence of letters and digits representing an integer with the radix specified by
16982     base, optionally preceded by a plus or minus sign, but not including an integer suffix.
16983     The letters from a (or A) through z (or Z) are ascribed the values 10 through 35; only
16984     letters and digits whose ascribed values are less than that of base are permitted. If the
16985     value of base is 16, the wide characters 0x or 0X may optionally precede the sequence
16986     of letters and digits, following the sign if present.
16987
16988 [page 426]
16989
16990 4   The subject sequence is defined as the longest initial subsequence of the input wide
16991     string, starting with the first non-white-space wide character, that is of the expected form.
16992     The subject sequence contains no wide characters if the input wide string is empty or
16993     consists entirely of white space, or if the first non-white-space wide character is other
16994     than a sign or a permissible letter or digit.
16995 5   If the subject sequence has the expected form and the value of base is zero, the sequence
16996     of wide characters starting with the first digit is interpreted as an integer constant
16997     according to the rules of 6.4.4.1. If the subject sequence has the expected form and the
16998     value of base is between 2 and 36, it is used as the base for conversion, ascribing to each
16999     letter its value as given above. If the subject sequence begins with a minus sign, the value
17000     resulting from the conversion is negated (in the return type). A pointer to the final wide
17001     string is stored in the object pointed to by endptr, provided that endptr is not a null
17002     pointer.
17003 6   In other than the "C" locale, additional locale-specific subject sequence forms may be
17004     accepted.
17005 7   If the subject sequence is empty or does not have the expected form, no conversion is
17006     performed; the value of nptr is stored in the object pointed to by endptr, provided
17007     that endptr is not a null pointer.
17008     Returns
17009 8   The wcstol, wcstoll, wcstoul, and wcstoull functions return the converted
17010     value, if any. If no conversion could be performed, zero is returned. If the correct value
17011     is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
17012     LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type
17013     sign of the value, if any), and the value of the macro ERANGE is stored in errno.
17014     7.28.4.2 Wide string copying functions
17015     7.28.4.2.1 The wcscpy function
17016     Synopsis
17017 1           #include <wchar.h>
17018             wchar_t *wcscpy(wchar_t * restrict s1,
17019                  const wchar_t * restrict s2);
17020     Description
17021 2   The wcscpy function copies the wide string pointed to by s2 (including the terminating
17022     null wide character) into the array pointed to by s1.
17023     Returns
17024 3   The wcscpy function returns the value of s1.
17025
17026
17027 [page 427]
17028
17029     7.28.4.2.2 The wcsncpy function
17030     Synopsis
17031 1            #include <wchar.h>
17032              wchar_t *wcsncpy(wchar_t * restrict s1,
17033                   const wchar_t * restrict s2,
17034                   size_t n);
17035     Description
17036 2   The wcsncpy function copies not more than n wide characters (those that follow a null
17037     wide character are not copied) from the array pointed to by s2 to the array pointed to by
17038     s1.333)
17039 3   If the array pointed to by s2 is a wide string that is shorter than n wide characters, null
17040     wide characters are appended to the copy in the array pointed to by s1, until n wide
17041     characters in all have been written.
17042     Returns
17043 4   The wcsncpy function returns the value of s1.
17044     7.28.4.2.3 The wmemcpy function
17045     Synopsis
17046 1            #include <wchar.h>
17047              wchar_t *wmemcpy(wchar_t * restrict s1,
17048                   const wchar_t * restrict s2,
17049                   size_t n);
17050     Description
17051 2   The wmemcpy function copies n wide characters from the object pointed to by s2 to the
17052     object pointed to by s1.
17053     Returns
17054 3   The wmemcpy function returns the value of s1.
17055
17056
17057
17058
17059     333) Thus, if there is no null wide character in the first n wide characters of the array pointed to by s2, the
17060          result will not be null-terminated.
17061
17062 [page 428]
17063
17064     7.28.4.2.4 The wmemmove function
17065     Synopsis
17066 1           #include <wchar.h>
17067             wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2,
17068                  size_t n);
17069     Description
17070 2   The wmemmove function copies n wide characters from the object pointed to by s2 to
17071     the object pointed to by s1. Copying takes place as if the n wide characters from the
17072     object pointed to by s2 are first copied into a temporary array of n wide characters that
17073     does not overlap the objects pointed to by s1 or s2, and then the n wide characters from
17074     the temporary array are copied into the object pointed to by s1.
17075     Returns
17076 3   The wmemmove function returns the value of s1.
17077     7.28.4.3 Wide string concatenation functions
17078     7.28.4.3.1 The wcscat function
17079     Synopsis
17080 1           #include <wchar.h>
17081             wchar_t *wcscat(wchar_t * restrict s1,
17082                  const wchar_t * restrict s2);
17083     Description
17084 2   The wcscat function appends a copy of the wide string pointed to by s2 (including the
17085     terminating null wide character) to the end of the wide string pointed to by s1. The initial
17086     wide character of s2 overwrites the null wide character at the end of s1.
17087     Returns
17088 3   The wcscat function returns the value of s1.
17089     7.28.4.3.2 The wcsncat function
17090     Synopsis
17091 1           #include <wchar.h>
17092             wchar_t *wcsncat(wchar_t * restrict s1,
17093                  const wchar_t * restrict s2,
17094                  size_t n);
17095     Description
17096 2   The wcsncat function appends not more than n wide characters (a null wide character
17097     and those that follow it are not appended) from the array pointed to by s2 to the end of
17098
17099 [page 429]
17100
17101     the wide string pointed to by s1. The initial wide character of s2 overwrites the null
17102     wide character at the end of s1. A terminating null wide character is always appended to
17103     the result.334)
17104     Returns
17105 3   The wcsncat function returns the value of s1.
17106     7.28.4.4 Wide string comparison functions
17107 1   Unless explicitly stated otherwise, the functions described in this subclause order two
17108     wide characters the same way as two integers of the underlying integer type designated
17109     by wchar_t.
17110     7.28.4.4.1 The wcscmp function
17111     Synopsis
17112 1           #include <wchar.h>
17113             int wcscmp(const wchar_t *s1, const wchar_t *s2);
17114     Description
17115 2   The wcscmp function compares the wide string pointed to by s1 to the wide string
17116     pointed to by s2.
17117     Returns
17118 3   The wcscmp function returns an integer greater than, equal to, or less than zero,
17119     accordingly as the wide string pointed to by s1 is greater than, equal to, or less than the
17120     wide string pointed to by s2.
17121     7.28.4.4.2 The wcscoll function
17122     Synopsis
17123 1           #include <wchar.h>
17124             int wcscoll(const wchar_t *s1, const wchar_t *s2);
17125     Description
17126 2   The wcscoll function compares the wide string pointed to by s1 to the wide string
17127     pointed to by s2, both interpreted as appropriate to the LC_COLLATE category of the
17128     current locale.
17129     Returns
17130 3   The wcscoll function returns an integer greater than, equal to, or less than zero,
17131     accordingly as the wide string pointed to by s1 is greater than, equal to, or less than the
17132
17133
17134     334) Thus, the maximum number of wide characters that can end up in the array pointed to by s1 is
17135          wcslen(s1)+n+1.
17136
17137 [page 430]
17138
17139     wide string pointed to by s2 when both are interpreted as appropriate to the current
17140     locale.
17141     7.28.4.4.3 The wcsncmp function
17142     Synopsis
17143 1           #include <wchar.h>
17144             int wcsncmp(const wchar_t *s1, const wchar_t *s2,
17145                  size_t n);
17146     Description
17147 2   The wcsncmp function compares not more than n wide characters (those that follow a
17148     null wide character are not compared) from the array pointed to by s1 to the array
17149     pointed to by s2.
17150     Returns
17151 3   The wcsncmp function returns an integer greater than, equal to, or less than zero,
17152     accordingly as the possibly null-terminated array pointed to by s1 is greater than, equal
17153     to, or less than the possibly null-terminated array pointed to by s2.
17154     7.28.4.4.4 The wcsxfrm function
17155     Synopsis
17156 1           #include <wchar.h>
17157             size_t wcsxfrm(wchar_t * restrict s1,
17158                  const wchar_t * restrict s2,
17159                  size_t n);
17160     Description
17161 2   The wcsxfrm function transforms the wide string pointed to by s2 and places the
17162     resulting wide string into the array pointed to by s1. The transformation is such that if
17163     the wcscmp function is applied to two transformed wide strings, it returns a value greater
17164     than, equal to, or less than zero, corresponding to the result of the wcscoll function
17165     applied to the same two original wide strings. No more than n wide characters are placed
17166     into the resulting array pointed to by s1, including the terminating null wide character. If
17167     n is zero, s1 is permitted to be a null pointer.
17168     Returns
17169 3   The wcsxfrm function returns the length of the transformed wide string (not including
17170     the terminating null wide character). If the value returned is n or greater, the contents of
17171     the array pointed to by s1 are indeterminate.
17172 4   EXAMPLE The value of the following expression is the length of the array needed to hold the
17173     transformation of the wide string pointed to by s:
17174
17175
17176 [page 431]
17177
17178            1 + wcsxfrm(NULL, s, 0)
17179
17180     7.28.4.4.5 The wmemcmp function
17181     Synopsis
17182 1          #include <wchar.h>
17183            int wmemcmp(const wchar_t *s1, const wchar_t *s2,
17184                 size_t n);
17185     Description
17186 2   The wmemcmp function compares the first n wide characters of the object pointed to by
17187     s1 to the first n wide characters of the object pointed to by s2.
17188     Returns
17189 3   The wmemcmp function returns an integer greater than, equal to, or less than zero,
17190     accordingly as the object pointed to by s1 is greater than, equal to, or less than the object
17191     pointed to by s2.
17192     7.28.4.5 Wide string search functions
17193     7.28.4.5.1 The wcschr function
17194     Synopsis
17195 1          #include <wchar.h>
17196            wchar_t *wcschr(const wchar_t *s, wchar_t c);
17197     Description
17198 2   The wcschr function locates the first occurrence of c in the wide string pointed to by s.
17199     The terminating null wide character is considered to be part of the wide string.
17200     Returns
17201 3   The wcschr function returns a pointer to the located wide character, or a null pointer if
17202     the wide character does not occur in the wide string.
17203     7.28.4.5.2 The wcscspn function
17204     Synopsis
17205 1          #include <wchar.h>
17206            size_t wcscspn(const wchar_t *s1, const wchar_t *s2);
17207     Description
17208 2   The wcscspn function computes the length of the maximum initial segment of the wide
17209     string pointed to by s1 which consists entirely of wide characters not from the wide
17210     string pointed to by s2.
17211
17212
17213
17214 [page 432]
17215
17216     Returns
17217 3   The wcscspn function returns the length of the segment.
17218     7.28.4.5.3 The wcspbrk function
17219     Synopsis
17220 1           #include <wchar.h>
17221             wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2);
17222     Description
17223 2   The wcspbrk function locates the first occurrence in the wide string pointed to by s1 of
17224     any wide character from the wide string pointed to by s2.
17225     Returns
17226 3   The wcspbrk function returns a pointer to the wide character in s1, or a null pointer if
17227     no wide character from s2 occurs in s1.
17228     7.28.4.5.4 The wcsrchr function
17229     Synopsis
17230 1           #include <wchar.h>
17231             wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
17232     Description
17233 2   The wcsrchr function locates the last occurrence of c in the wide string pointed to by
17234     s. The terminating null wide character is considered to be part of the wide string.
17235     Returns
17236 3   The wcsrchr function returns a pointer to the wide character, or a null pointer if c does
17237     not occur in the wide string.
17238     7.28.4.5.5 The wcsspn function
17239     Synopsis
17240 1           #include <wchar.h>
17241             size_t wcsspn(const wchar_t *s1, const wchar_t *s2);
17242     Description
17243 2   The wcsspn function computes the length of the maximum initial segment of the wide
17244     string pointed to by s1 which consists entirely of wide characters from the wide string
17245     pointed to by s2.
17246     Returns
17247 3   The wcsspn function returns the length of the segment.
17248
17249
17250 [page 433]
17251
17252     7.28.4.5.6 The wcsstr function
17253     Synopsis
17254 1          #include <wchar.h>
17255            wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);
17256     Description
17257 2   The wcsstr function locates the first occurrence in the wide string pointed to by s1 of
17258     the sequence of wide characters (excluding the terminating null wide character) in the
17259     wide string pointed to by s2.
17260     Returns
17261 3   The wcsstr function returns a pointer to the located wide string, or a null pointer if the
17262     wide string is not found. If s2 points to a wide string with zero length, the function
17263     returns s1.
17264     7.28.4.5.7 The wcstok function
17265     Synopsis
17266 1          #include <wchar.h>
17267            wchar_t *wcstok(wchar_t * restrict s1,
17268                 const wchar_t * restrict s2,
17269                 wchar_t ** restrict ptr);
17270     Description
17271 2   A sequence of calls to the wcstok function breaks the wide string pointed to by s1 into
17272     a sequence of tokens, each of which is delimited by a wide character from the wide string
17273     pointed to by s2. The third argument points to a caller-provided wchar_t pointer into
17274     which the wcstok function stores information necessary for it to continue scanning the
17275     same wide string.
17276 3   The first call in a sequence has a non-null first argument and stores an initial value in the
17277     object pointed to by ptr. Subsequent calls in the sequence have a null first argument and
17278     the object pointed to by ptr is required to have the value stored by the previous call in
17279     the sequence, which is then updated. The separator wide string pointed to by s2 may be
17280     different from call to call.
17281 4   The first call in the sequence searches the wide string pointed to by s1 for the first wide
17282     character that is not contained in the current separator wide string pointed to by s2. If no
17283     such wide character is found, then there are no tokens in the wide string pointed to by s1
17284     and the wcstok function returns a null pointer. If such a wide character is found, it is
17285     the start of the first token.
17286 5   The wcstok function then searches from there for a wide character that is contained in
17287     the current separator wide string. If no such wide character is found, the current token
17288 [page 434]
17289
17290     extends to the end of the wide string pointed to by s1, and subsequent searches in the
17291     same wide string for a token return a null pointer. If such a wide character is found, it is
17292     overwritten by a null wide character, which terminates the current token.
17293 6   In all cases, the wcstok function stores sufficient information in the pointer pointed to
17294     by ptr so that subsequent calls, with a null pointer for s1 and the unmodified pointer
17295     value for ptr, shall start searching just past the element overwritten by a null wide
17296     character (if any).
17297     Returns
17298 7   The wcstok function returns a pointer to the first wide character of a token, or a null
17299     pointer if there is no token.
17300 8   EXAMPLE
17301             #include <wchar.h>
17302             static wchar_t str1[] = L"?a???b,,,#c";
17303             static wchar_t str2[] = L"\t \t";
17304             wchar_t *t, *ptr1, *ptr2;
17305             t   =   wcstok(str1,   L"?", &ptr1);         //   t   points to the token L"a"
17306             t   =   wcstok(NULL,   L",", &ptr1);         //   t   points to the token L"??b"
17307             t   =   wcstok(str2,   L" \t", &ptr2);       //   t   is a null pointer
17308             t   =   wcstok(NULL,   L"#,", &ptr1);        //   t   points to the token L"c"
17309             t   =   wcstok(NULL,   L"?", &ptr1);         //   t   is a null pointer
17310
17311     7.28.4.5.8 The wmemchr function
17312     Synopsis
17313 1           #include <wchar.h>
17314             wchar_t *wmemchr(const wchar_t *s, wchar_t c,
17315                  size_t n);
17316     Description
17317 2   The wmemchr function locates the first occurrence of c in the initial n wide characters of
17318     the object pointed to by s.
17319     Returns
17320 3   The wmemchr function returns a pointer to the located wide character, or a null pointer if
17321     the wide character does not occur in the object.
17322
17323
17324
17325
17326 [page 435]
17327
17328     7.28.4.6 Miscellaneous functions
17329     7.28.4.6.1 The wcslen function
17330     Synopsis
17331 1          #include <wchar.h>
17332            size_t wcslen(const wchar_t *s);
17333     Description
17334 2   The wcslen function computes the length of the wide string pointed to by s.
17335     Returns
17336 3   The wcslen function returns the number of wide characters that precede the terminating
17337     null wide character.
17338     7.28.4.6.2 The wmemset function
17339     Synopsis
17340 1          #include <wchar.h>
17341            wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);
17342     Description
17343 2   The wmemset function copies the value of c into each of the first n wide characters of
17344     the object pointed to by s.
17345     Returns
17346 3   The wmemset function returns the value of s.
17347     7.28.5 Wide character time conversion functions
17348     7.28.5.1 The wcsftime function
17349     Synopsis
17350 1          #include <time.h>
17351            #include <wchar.h>
17352            size_t wcsftime(wchar_t * restrict s,
17353                 size_t maxsize,
17354                 const wchar_t * restrict format,
17355                 const struct tm * restrict timeptr);
17356     Description
17357 2   The wcsftime function is equivalent to the strftime function, except that:
17358     -- The argument s points to the initial element of an array of wide characters into which
17359       the generated output is to be placed.
17360
17361
17362 [page 436]
17363
17364     -- The argument maxsize indicates the limiting number of wide characters.
17365     -- The argument format is a wide string and the conversion specifiers are replaced by
17366       corresponding sequences of wide characters.
17367     -- The return value indicates the number of wide characters.
17368     Returns
17369 3   If the total number of resulting wide characters including the terminating null wide
17370     character is not more than maxsize, the wcsftime function returns the number of
17371     wide characters placed into the array pointed to by s not including the terminating null
17372     wide character. Otherwise, zero is returned and the contents of the array are
17373     indeterminate.
17374     7.28.6 Extended multibyte/wide character conversion utilities
17375 1   The header <wchar.h> declares an extended set of functions useful for conversion
17376     between multibyte characters and wide characters.
17377 2   Most of the following functions -- those that are listed as ''restartable'', 7.28.6.3 and
17378     7.28.6.4 -- take as a last argument a pointer to an object of type mbstate_t that is used
17379     to describe the current conversion state from a particular multibyte character sequence to
17380     a wide character sequence (or the reverse) under the rules of a particular setting for the
17381     LC_CTYPE category of the current locale.
17382 3   The initial conversion state corresponds, for a conversion in either direction, to the
17383     beginning of a new multibyte character in the initial shift state. A zero-valued
17384     mbstate_t object is (at least) one way to describe an initial conversion state. A zero-
17385     valued mbstate_t object can be used to initiate conversion involving any multibyte
17386     character sequence, in any LC_CTYPE category setting. If an mbstate_t object has
17387     been altered by any of the functions described in this subclause, and is then used with a
17388     different multibyte character sequence, or in the other conversion direction, or with a
17389     different LC_CTYPE category setting than on earlier function calls, the behavior is
17390     undefined.335)
17391 4   On entry, each function takes the described conversion state (either internal or pointed to
17392     by an argument) as current. The conversion state described by the referenced object is
17393     altered as needed to track the shift state, and the position within a multibyte character, for
17394     the associated multibyte character sequence.
17395
17396
17397
17398
17399     335) Thus, a particular mbstate_t object can be used, for example, with both the mbrtowc and
17400          mbsrtowcs functions as long as they are used to step sequentially through the same multibyte
17401          character string.
17402
17403 [page 437]
17404
17405     7.28.6.1 Single-byte/wide character conversion functions
17406     7.28.6.1.1 The btowc function
17407     Synopsis
17408 1          #include <wchar.h>                                                                        *
17409            wint_t btowc(int c);
17410     Description
17411 2   The btowc function determines whether c constitutes a valid single-byte character in the
17412     initial shift state.
17413     Returns
17414 3   The btowc function returns WEOF if c has the value EOF or if (unsigned char)c
17415     does not constitute a valid single-byte character in the initial shift state. Otherwise, it
17416     returns the wide character representation of that character.
17417     7.28.6.1.2 The wctob function
17418     Synopsis
17419 1          #include <wchar.h>                                                                        *
17420            int wctob(wint_t c);
17421     Description
17422 2   The wctob function determines whether c corresponds to a member of the extended
17423     character set whose multibyte character representation is a single byte when in the initial
17424     shift state.
17425     Returns
17426 3   The wctob function returns EOF if c does not correspond to a multibyte character with
17427     length one in the initial shift state. Otherwise, it returns the single-byte representation of
17428     that character as an unsigned char converted to an int.
17429     7.28.6.2 Conversion state functions
17430     7.28.6.2.1 The mbsinit function
17431     Synopsis
17432 1          #include <wchar.h>
17433            int mbsinit(const mbstate_t *ps);
17434     Description
17435 2   If ps is not a null pointer, the mbsinit function determines whether the referenced
17436     mbstate_t object describes an initial conversion state.
17437
17438
17439
17440 [page 438]
17441
17442     Returns
17443 3   The mbsinit function returns nonzero if ps is a null pointer or if the referenced object
17444     describes an initial conversion state; otherwise, it returns zero.
17445     7.28.6.3 Restartable multibyte/wide character conversion functions
17446 1   These functions differ from the corresponding multibyte character functions of 7.22.7
17447     (mblen, mbtowc, and wctomb) in that they have an extra parameter, ps, of type
17448     pointer to mbstate_t that points to an object that can completely describe the current
17449     conversion state of the associated multibyte character sequence. If ps is a null pointer,
17450     each function uses its own internal mbstate_t object instead, which is initialized at
17451     program startup to the initial conversion state; the functions are not required to avoid data
17452     races in this case. The implementation behaves as if no library function calls these
17453     functions with a null pointer for ps.
17454 2   Also unlike their corresponding functions, the return value does not represent whether the
17455     encoding is state-dependent.
17456     7.28.6.3.1 The mbrlen function
17457     Synopsis
17458 1           #include <wchar.h>
17459             size_t mbrlen(const char * restrict s,
17460                  size_t n,
17461                  mbstate_t * restrict ps);
17462     Description
17463 2   The mbrlen function is equivalent to the call:
17464             mbrtowc(NULL, s, n, ps != NULL ? ps : &internal)
17465     where internal is the mbstate_t object for the mbrlen function, except that the
17466     expression designated by ps is evaluated only once.
17467     Returns
17468 3   The mbrlen function returns a value between zero and n, inclusive, (size_t)(-2),
17469     or (size_t)(-1).
17470     Forward references: the mbrtowc function (7.28.6.3.2).
17471
17472
17473
17474
17475 [page 439]
17476
17477     7.28.6.3.2 The mbrtowc function
17478     Synopsis
17479 1           #include <wchar.h>
17480             size_t mbrtowc(wchar_t * restrict pwc,
17481                  const char * restrict s,
17482                  size_t n,
17483                  mbstate_t * restrict ps);
17484     Description
17485 2   If s is a null pointer, the mbrtowc function is equivalent to the call:
17486                     mbrtowc(NULL, "", 1, ps)
17487     In this case, the values of the parameters pwc and n are ignored.
17488 3   If s is not a null pointer, the mbrtowc function inspects at most n bytes beginning with
17489     the byte pointed to by s to determine the number of bytes needed to complete the next
17490     multibyte character (including any shift sequences). If the function determines that the
17491     next multibyte character is complete and valid, it determines the value of the
17492     corresponding wide character and then, if pwc is not a null pointer, stores that value in
17493     the object pointed to by pwc. If the corresponding wide character is the null wide
17494     character, the resulting state described is the initial conversion state.
17495     Returns
17496 4   The mbrtowc function returns the first of the following that applies (given the current
17497     conversion state):
17498     0                     if the next n or fewer bytes complete the multibyte character that
17499                           corresponds to the null wide character (which is the value stored).
17500     between 1 and n inclusive if the next n or fewer bytes complete a valid multibyte
17501                        character (which is the value stored); the value returned is the number
17502                        of bytes that complete the multibyte character.
17503     (size_t)(-2) if the next n bytes contribute to an incomplete (but potentially valid)
17504                  multibyte character, and all n bytes have been processed (no value is
17505                  stored).336)
17506     (size_t)(-1) if an encoding error occurs, in which case the next n or fewer bytes
17507                  do not contribute to a complete and valid multibyte character (no
17508                  value is stored); the value of the macro EILSEQ is stored in errno,
17509                  and the conversion state is unspecified.
17510
17511     336) When n has at least the value of the MB_CUR_MAX macro, this case can only occur if s points at a
17512          sequence of redundant shift sequences (for implementations with state-dependent encodings).
17513
17514 [page 440]
17515
17516     7.28.6.3.3 The wcrtomb function
17517     Synopsis
17518 1           #include <wchar.h>
17519             size_t wcrtomb(char * restrict s,
17520                  wchar_t wc,
17521                  mbstate_t * restrict ps);
17522     Description
17523 2   If s is a null pointer, the wcrtomb function is equivalent to the call
17524                     wcrtomb(buf, L'\0', ps)
17525     where buf is an internal buffer.
17526 3   If s is not a null pointer, the wcrtomb function determines the number of bytes needed
17527     to represent the multibyte character that corresponds to the wide character given by wc
17528     (including any shift sequences), and stores the multibyte character representation in the
17529     array whose first element is pointed to by s. At most MB_CUR_MAX bytes are stored. If
17530     wc is a null wide character, a null byte is stored, preceded by any shift sequence needed
17531     to restore the initial shift state; the resulting state described is the initial conversion state.
17532     Returns
17533 4   The wcrtomb function returns the number of bytes stored in the array object (including
17534     any shift sequences). When wc is not a valid wide character, an encoding error occurs:
17535     the function stores the value of the macro EILSEQ in errno and returns
17536     (size_t)(-1); the conversion state is unspecified.
17537     7.28.6.4 Restartable multibyte/wide string conversion functions
17538 1   These functions differ from the corresponding multibyte string functions of 7.22.8
17539     (mbstowcs and wcstombs) in that they have an extra parameter, ps, of type pointer to
17540     mbstate_t that points to an object that can completely describe the current conversion
17541     state of the associated multibyte character sequence. If ps is a null pointer, each function
17542     uses its own internal mbstate_t object instead, which is initialized at program startup
17543     to the initial conversion state; the functions are not required to avoid data races in this
17544     case. The implementation behaves as if no library function calls these functions with a
17545     null pointer for ps.
17546 2   Also unlike their corresponding functions, the conversion source parameter, src, has a
17547     pointer-to-pointer type. When the function is storing the results of conversions (that is,
17548     when dst is not a null pointer), the pointer object pointed to by this parameter is updated
17549     to reflect the amount of the source processed by that invocation.
17550
17551
17552
17553
17554 [page 441]
17555
17556     7.28.6.4.1 The mbsrtowcs function
17557     Synopsis
17558 1            #include <wchar.h>
17559              size_t mbsrtowcs(wchar_t * restrict dst,
17560                   const char ** restrict src,
17561                   size_t len,
17562                   mbstate_t * restrict ps);
17563     Description
17564 2   The mbsrtowcs function converts a sequence of multibyte characters that begins in the
17565     conversion state described by the object pointed to by ps, from the array indirectly
17566     pointed to by src into a sequence of corresponding wide characters. If dst is not a null
17567     pointer, the converted characters are stored into the array pointed to by dst. Conversion
17568     continues up to and including a terminating null character, which is also stored.
17569     Conversion stops earlier in two cases: when a sequence of bytes is encountered that does
17570     not form a valid multibyte character, or (if dst is not a null pointer) when len wide
17571     characters have been stored into the array pointed to by dst.337) Each conversion takes
17572     place as if by a call to the mbrtowc function.
17573 3   If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
17574     pointer (if conversion stopped due to reaching a terminating null character) or the address
17575     just past the last multibyte character converted (if any). If conversion stopped due to
17576     reaching a terminating null character and if dst is not a null pointer, the resulting state
17577     described is the initial conversion state.
17578     Returns
17579 4   If the input conversion encounters a sequence of bytes that do not form a valid multibyte
17580     character, an encoding error occurs: the mbsrtowcs function stores the value of the
17581     macro EILSEQ in errno and returns (size_t)(-1); the conversion state is
17582     unspecified. Otherwise, it returns the number of multibyte characters successfully
17583     converted, not including the terminating null character (if any).
17584
17585
17586
17587
17588     337) Thus, the value of len is ignored if dst is a null pointer.
17589
17590 [page 442]
17591
17592     7.28.6.4.2 The wcsrtombs function
17593     Synopsis
17594 1           #include <wchar.h>
17595             size_t wcsrtombs(char * restrict dst,
17596                  const wchar_t ** restrict src,
17597                  size_t len,
17598                  mbstate_t * restrict ps);
17599     Description
17600 2   The wcsrtombs function converts a sequence of wide characters from the array
17601     indirectly pointed to by src into a sequence of corresponding multibyte characters that
17602     begins in the conversion state described by the object pointed to by ps. If dst is not a
17603     null pointer, the converted characters are then stored into the array pointed to by dst.
17604     Conversion continues up to and including a terminating null wide character, which is also
17605     stored. Conversion stops earlier in two cases: when a wide character is reached that does
17606     not correspond to a valid multibyte character, or (if dst is not a null pointer) when the
17607     next multibyte character would exceed the limit of len total bytes to be stored into the
17608     array pointed to by dst. Each conversion takes place as if by a call to the wcrtomb
17609     function.338)
17610 3   If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
17611     pointer (if conversion stopped due to reaching a terminating null wide character) or the
17612     address just past the last wide character converted (if any). If conversion stopped due to
17613     reaching a terminating null wide character, the resulting state described is the initial
17614     conversion state.
17615     Returns
17616 4   If conversion stops because a wide character is reached that does not correspond to a
17617     valid multibyte character, an encoding error occurs: the wcsrtombs function stores the
17618     value of the macro EILSEQ in errno and returns (size_t)(-1); the conversion
17619     state is unspecified. Otherwise, it returns the number of bytes in the resulting multibyte
17620     character sequence, not including the terminating null character (if any).
17621
17622
17623
17624
17625     338) If conversion stops because a terminating null wide character has been reached, the bytes stored
17626          include those necessary to reach the initial shift state immediately before the null byte.
17627
17628 [page 443]
17629
17630     7.29 Wide character classification and mapping utilities <wctype.h>
17631     7.29.1 Introduction
17632 1   The header <wctype.h> defines one macro, and declares three data types and many
17633     functions.339)
17634 2   The types declared are
17635              wint_t
17636     described in 7.28.1;
17637              wctrans_t
17638     which is a scalar type that can hold values which represent locale-specific character
17639     mappings; and
17640              wctype_t
17641     which is a scalar type that can hold values which represent locale-specific character
17642     classifications.
17643 3   The macro defined is WEOF (described in 7.28.1).
17644 4   The functions declared are grouped as follows:
17645     -- Functions that provide wide character classification;
17646     -- Extensible functions that provide wide character classification;
17647     -- Functions that provide wide character case mapping;
17648     -- Extensible functions that provide wide character mapping.
17649 5   For all functions described in this subclause that accept an argument of type wint_t, the
17650     value shall be representable as a wchar_t or shall equal the value of the macro WEOF. If
17651     this argument has any other value, the behavior is undefined.
17652 6   The behavior of these functions is affected by the LC_CTYPE category of the current
17653     locale.
17654
17655
17656
17657
17658     339) See ''future library directions'' (7.30.13).
17659
17660 [page 444]
17661
17662     7.29.2 Wide character classification utilities
17663 1   The header <wctype.h> declares several functions useful for classifying wide
17664     characters.
17665 2   The term printing wide character refers to a member of a locale-specific set of wide
17666     characters, each of which occupies at least one printing position on a display device. The
17667     term control wide character refers to a member of a locale-specific set of wide characters
17668     that are not printing wide characters.
17669     7.29.2.1 Wide character classification functions
17670 1   The functions in this subclause return nonzero (true) if and only if the value of the
17671     argument wc conforms to that in the description of the function.
17672 2   Each of the following functions returns true for each wide character that corresponds (as
17673     if by a call to the wctob function) to a single-byte character for which the corresponding
17674     character classification function from 7.4.1 returns true, except that the iswgraph and
17675     iswpunct functions may differ with respect to wide characters other than L' ' that are
17676     both printing and white-space wide characters.340)
17677     Forward references: the wctob function (7.28.6.1.2).
17678     7.29.2.1.1 The iswalnum function
17679     Synopsis
17680 1           #include <wctype.h>
17681             int iswalnum(wint_t wc);
17682     Description
17683 2   The iswalnum function tests for any wide character for which iswalpha or
17684     iswdigit is true.
17685     7.29.2.1.2 The iswalpha function
17686     Synopsis
17687 1           #include <wctype.h>
17688             int iswalpha(wint_t wc);
17689     Description
17690 2   The iswalpha function tests for any wide character for which iswupper or
17691     iswlower is true, or any wide character that is one of a locale-specific set of alphabetic
17692
17693     340) For example, if the expression isalpha(wctob(wc)) evaluates to true, then the call
17694          iswalpha(wc) also returns true. But, if the expression isgraph(wctob(wc)) evaluates to true
17695          (which cannot occur for wc == L' ' of course), then either iswgraph(wc) or iswprint(wc)
17696          && iswspace(wc) is true, but not both.
17697
17698 [page 445]
17699
17700     wide characters for which none of iswcntrl, iswdigit, iswpunct, or iswspace
17701     is true.341)
17702     7.29.2.1.3 The iswblank function
17703     Synopsis
17704 1           #include <wctype.h>
17705             int iswblank(wint_t wc);
17706     Description
17707 2   The iswblank function tests for any wide character that is a standard blank wide
17708     character or is one of a locale-specific set of wide characters for which iswspace is true
17709     and that is used to separate words within a line of text. The standard blank wide
17710     characters are the following: space (L' '), and horizontal tab (L'\t'). In the "C"
17711     locale, iswblank returns true only for the standard blank characters.
17712     7.29.2.1.4 The iswcntrl function
17713     Synopsis
17714 1           #include <wctype.h>
17715             int iswcntrl(wint_t wc);
17716     Description
17717 2   The iswcntrl function tests for any control wide character.
17718     7.29.2.1.5 The iswdigit function
17719     Synopsis
17720 1           #include <wctype.h>
17721             int iswdigit(wint_t wc);
17722     Description
17723 2   The iswdigit function tests for any wide character that corresponds to a decimal-digit
17724     character (as defined in 5.2.1).
17725     7.29.2.1.6 The iswgraph function
17726     Synopsis
17727 1           #include <wctype.h>
17728             int iswgraph(wint_t wc);
17729
17730
17731
17732
17733     341) The functions iswlower and iswupper test true or false separately for each of these additional
17734          wide characters; all four combinations are possible.
17735
17736 [page 446]
17737
17738     Description
17739 2   The iswgraph function tests for any wide character for which iswprint is true and
17740     iswspace is false.342)
17741     7.29.2.1.7 The iswlower function
17742     Synopsis
17743 1           #include <wctype.h>
17744             int iswlower(wint_t wc);
17745     Description
17746 2   The iswlower function tests for any wide character that corresponds to a lowercase
17747     letter or is one of a locale-specific set of wide characters for which none of iswcntrl,
17748     iswdigit, iswpunct, or iswspace is true.
17749     7.29.2.1.8 The iswprint function
17750     Synopsis
17751 1           #include <wctype.h>
17752             int iswprint(wint_t wc);
17753     Description
17754 2   The iswprint function tests for any printing wide character.
17755     7.29.2.1.9 The iswpunct function
17756     Synopsis
17757 1           #include <wctype.h>
17758             int iswpunct(wint_t wc);
17759     Description
17760 2   The iswpunct function tests for any printing wide character that is one of a locale-
17761     specific set of punctuation wide characters for which neither iswspace nor iswalnum
17762     is true.342)
17763     7.29.2.1.10 The iswspace function
17764     Synopsis
17765 1           #include <wctype.h>
17766             int iswspace(wint_t wc);
17767
17768
17769
17770     342) Note that the behavior of the iswgraph and iswpunct functions may differ from their
17771          corresponding functions in 7.4.1 with respect to printing, white-space, single-byte execution
17772          characters other than ' '.
17773
17774 [page 447]
17775
17776     Description
17777 2   The iswspace function tests for any wide character that corresponds to a locale-specific
17778     set of white-space wide characters for which none of iswalnum, iswgraph, or
17779     iswpunct is true.
17780     7.29.2.1.11 The iswupper function
17781     Synopsis
17782 1          #include <wctype.h>
17783            int iswupper(wint_t wc);
17784     Description
17785 2   The iswupper function tests for any wide character that corresponds to an uppercase
17786     letter or is one of a locale-specific set of wide characters for which none of iswcntrl,
17787     iswdigit, iswpunct, or iswspace is true.
17788     7.29.2.1.12 The iswxdigit function
17789     Synopsis
17790 1          #include <wctype.h>
17791            int iswxdigit(wint_t wc);
17792     Description
17793 2   The iswxdigit function tests for any wide character that corresponds to a
17794     hexadecimal-digit character (as defined in 6.4.4.1).
17795     7.29.2.2 Extensible wide character classification functions
17796 1   The functions wctype and iswctype provide extensible wide character classification
17797     as well as testing equivalent to that performed by the functions described in the previous
17798     subclause (7.29.2.1).
17799     7.29.2.2.1 The iswctype function
17800     Synopsis
17801 1          #include <wctype.h>
17802            int iswctype(wint_t wc, wctype_t desc);
17803     Description
17804 2   The iswctype function determines whether the wide character wc has the property
17805     described by desc. The current setting of the LC_CTYPE category shall be the same as
17806     during the call to wctype that returned the value desc.
17807 3   Each of the following expressions has a truth-value equivalent to the call to the wide
17808     character classification function (7.29.2.1) in the comment that follows the expression:
17809
17810
17811 [page 448]
17812
17813             iswctype(wc,      wctype("alnum"))              //   iswalnum(wc)
17814             iswctype(wc,      wctype("alpha"))              //   iswalpha(wc)
17815             iswctype(wc,      wctype("blank"))              //   iswblank(wc)
17816             iswctype(wc,      wctype("cntrl"))              //   iswcntrl(wc)
17817             iswctype(wc,      wctype("digit"))              //   iswdigit(wc)
17818             iswctype(wc,      wctype("graph"))              //   iswgraph(wc)
17819             iswctype(wc,      wctype("lower"))              //   iswlower(wc)
17820             iswctype(wc,      wctype("print"))              //   iswprint(wc)
17821             iswctype(wc,      wctype("punct"))              //   iswpunct(wc)
17822             iswctype(wc,      wctype("space"))              //   iswspace(wc)
17823             iswctype(wc,      wctype("upper"))              //   iswupper(wc)
17824             iswctype(wc,      wctype("xdigit"))             //   iswxdigit(wc)
17825     Returns
17826 4   The iswctype function returns nonzero (true) if and only if the value of the wide
17827     character wc has the property described by desc. If desc is zero, the iswctype
17828     function returns zero (false).
17829     Forward references: the wctype function (7.29.2.2.2).
17830     7.29.2.2.2 The wctype function
17831     Synopsis
17832 1           #include <wctype.h>
17833             wctype_t wctype(const char *property);
17834     Description
17835 2   The wctype function constructs a value with type wctype_t that describes a class of
17836     wide characters identified by the string argument property.
17837 3   The strings listed in the description of the iswctype function shall be valid in all
17838     locales as property arguments to the wctype function.
17839     Returns
17840 4   If property identifies a valid class of wide characters according to the LC_CTYPE
17841     category of the current locale, the wctype function returns a nonzero value that is valid
17842     as the second argument to the iswctype function; otherwise, it returns zero.
17843
17844
17845
17846
17847 [page 449]
17848
17849     7.29.3 Wide character case mapping utilities
17850 1   The header <wctype.h> declares several functions useful for mapping wide characters.
17851     7.29.3.1 Wide character case mapping functions
17852     7.29.3.1.1 The towlower function
17853     Synopsis
17854 1          #include <wctype.h>
17855            wint_t towlower(wint_t wc);
17856     Description
17857 2   The towlower function converts an uppercase letter to a corresponding lowercase letter.
17858     Returns
17859 3   If the argument is a wide character for which iswupper is true and there are one or
17860     more corresponding wide characters, as specified by the current locale, for which
17861     iswlower is true, the towlower function returns one of the corresponding wide
17862     characters (always the same one for any given locale); otherwise, the argument is
17863     returned unchanged.
17864     7.29.3.1.2 The towupper function
17865     Synopsis
17866 1          #include <wctype.h>
17867            wint_t towupper(wint_t wc);
17868     Description
17869 2   The towupper function converts a lowercase letter to a corresponding uppercase letter.
17870     Returns
17871 3   If the argument is a wide character for which iswlower is true and there are one or
17872     more corresponding wide characters, as specified by the current locale, for which
17873     iswupper is true, the towupper function returns one of the corresponding wide
17874     characters (always the same one for any given locale); otherwise, the argument is
17875     returned unchanged.
17876     7.29.3.2 Extensible wide character case mapping functions
17877 1   The functions wctrans and towctrans provide extensible wide character mapping as
17878     well as case mapping equivalent to that performed by the functions described in the
17879     previous subclause (7.29.3.1).
17880
17881
17882
17883
17884 [page 450]
17885
17886     7.29.3.2.1 The towctrans function
17887     Synopsis
17888 1           #include <wctype.h>
17889             wint_t towctrans(wint_t wc, wctrans_t desc);
17890     Description
17891 2   The towctrans function maps the wide character wc using the mapping described by
17892     desc. The current setting of the LC_CTYPE category shall be the same as during the call
17893     to wctrans that returned the value desc.
17894 3   Each of the following expressions behaves the same as the call to the wide character case
17895     mapping function (7.29.3.1) in the comment that follows the expression:
17896             towctrans(wc, wctrans("tolower"))                     // towlower(wc)
17897             towctrans(wc, wctrans("toupper"))                     // towupper(wc)
17898     Returns
17899 4   The towctrans function returns the mapped value of wc using the mapping described
17900     by desc. If desc is zero, the towctrans function returns the value of wc.
17901     7.29.3.2.2 The wctrans function
17902     Synopsis
17903 1           #include <wctype.h>
17904             wctrans_t wctrans(const char *property);
17905     Description
17906 2   The wctrans function constructs a value with type wctrans_t that describes a
17907     mapping between wide characters identified by the string argument property.
17908 3   The strings listed in the description of the towctrans function shall be valid in all
17909     locales as property arguments to the wctrans function.
17910     Returns
17911 4   If property identifies a valid mapping of wide characters according to the LC_CTYPE
17912     category of the current locale, the wctrans function returns a nonzero value that is valid
17913     as the second argument to the towctrans function; otherwise, it returns zero.
17914
17915
17916
17917
17918 [page 451]
17919
17920     7.30 Future library directions
17921 1   The following names are grouped under individual headers for convenience. All external
17922     names described below are reserved no matter what headers are included by the program.
17923     7.30.1 Complex arithmetic <complex.h>
17924 1   The function names
17925           cerf               cexpm1              clog2
17926           cerfc              clog10              clgamma
17927           cexp2              clog1p              ctgamma
17928     and the same names suffixed with f or l may be added to the declarations in the
17929     <complex.h> header.
17930     7.30.2 Character handling <ctype.h>
17931 1   Function names that begin with either is or to, and a lowercase letter may be added to
17932     the declarations in the <ctype.h> header.
17933     7.30.3 Errors <errno.h>
17934 1   Macros that begin with E and a digit or E and an uppercase letter may be added to the
17935     declarations in the <errno.h> header.
17936     7.30.4 Format conversion of integer types <inttypes.h>
17937 1   Macro names beginning with PRI or SCN followed by any lowercase letter or X may be
17938     added to the macros defined in the <inttypes.h> header.
17939     7.30.5 Localization <locale.h>
17940 1   Macros that begin with LC_ and an uppercase letter may be added to the definitions in
17941     the <locale.h> header.
17942     7.30.6 Signal handling <signal.h>
17943 1   Macros that begin with either SIG and an uppercase letter or SIG_ and an uppercase
17944     letter may be added to the definitions in the <signal.h> header.
17945     7.30.7 Boolean type and values <stdbool.h>
17946 1   The ability to undefine and perhaps then redefine the macros bool, true, and false is
17947     an obsolescent feature.
17948     7.30.8 Integer types <stdint.h>
17949 1   Typedef names beginning with int or uint and ending with _t may be added to the
17950     types defined in the <stdint.h> header. Macro names beginning with INT or UINT
17951     and ending with _MAX, _MIN, or _C may be added to the macros defined in the
17952     <stdint.h> header.
17953
17954 [page 452]
17955
17956     7.30.9 Input/output <stdio.h>
17957 1   Lowercase letters may be added to the conversion specifiers and length modifiers in
17958     fprintf and fscanf. Other characters may be used in extensions.
17959 2   The use of ungetc on a binary stream where the file position indicator is zero prior to *
17960     the call is an obsolescent feature.
17961     7.30.10 General utilities <stdlib.h>
17962 1   Function names that begin with str and a lowercase letter may be added to the
17963     declarations in the <stdlib.h> header.
17964     7.30.11 String handling <string.h>
17965 1   Function names that begin with str, mem, or wcs and a lowercase letter may be added
17966     to the declarations in the <string.h> header.
17967     7.30.12 Extended multibyte and wide character utilities <wchar.h>
17968 1   Function names that begin with wcs and a lowercase letter may be added to the
17969     declarations in the <wchar.h> header.
17970 2   Lowercase letters may be added to the conversion specifiers and length modifiers in
17971     fwprintf and fwscanf. Other characters may be used in extensions.
17972     7.30.13 Wide character classification and mapping utilities
17973     <wctype.h>
17974 1   Function names that begin with is or to and a lowercase letter may be added to the
17975     declarations in the <wctype.h> header.
17976
17977
17978
17979
17980 [page 453]
17981
17982                                                  Annex A
17983                                                (informative)
17984                                 Language syntax summary
17985 1   NOTE   The notation is described in 6.1.
17986
17987     A.1 Lexical grammar
17988     A.1.1 Lexical elements
17989     (6.4) token:
17990                    keyword
17991                    identifier
17992                    constant
17993                    string-literal
17994                    punctuator
17995     (6.4) preprocessing-token:
17996                   header-name
17997                   identifier
17998                   pp-number
17999                   character-constant
18000                   string-literal
18001                   punctuator
18002                   each non-white-space character that cannot be one of the above
18003
18004
18005
18006
18007 [page 454]
18008
18009 A.1.2 Keywords
18010 (6.4.1) keyword: one of
18011               alignof                     goto                  union
18012               auto                        if                    unsigned
18013               break                       inline                void
18014               case                        int                   volatile
18015               char                        long                  while
18016               const                       register              _Alignas
18017               continue                    restrict              _Atomic
18018               default                     return                _Bool
18019               do                          short                 _Complex
18020               double                      signed                _Generic
18021               else                        sizeof                _Imaginary
18022               enum                        static                _Noreturn
18023               extern                      struct                _Static_assert
18024               float                       switch                _Thread_local
18025               for                         typedef
18026 A.1.3 Identifiers
18027 (6.4.2.1) identifier:
18028                identifier-nondigit
18029                identifier identifier-nondigit
18030                identifier digit
18031 (6.4.2.1) identifier-nondigit:
18032                nondigit
18033                universal-character-name
18034                other implementation-defined characters
18035 (6.4.2.1) nondigit: one of
18036               _ a b          c    d   e    f   g   h    i   j   k   l   m
18037                    n o       p    q   r    s   t   u    v   w   x   y   z
18038                    A B       C    D   E    F   G   H    I   J   K   L   M
18039                    N O       P    Q   R    S   T   U    V   W   X   Y   Z
18040 (6.4.2.1) digit: one of
18041                0 1 2         3    4   5    6   7   8    9
18042
18043
18044
18045
18046 [page 455]
18047
18048 A.1.4 Universal character names
18049 (6.4.3) universal-character-name:
18050               \u hex-quad
18051               \U hex-quad hex-quad
18052 (6.4.3) hex-quad:
18053               hexadecimal-digit hexadecimal-digit
18054                            hexadecimal-digit hexadecimal-digit
18055 A.1.5 Constants
18056 (6.4.4) constant:
18057               integer-constant
18058               floating-constant
18059               enumeration-constant
18060               character-constant
18061 (6.4.4.1) integer-constant:
18062                decimal-constant integer-suffixopt
18063                octal-constant integer-suffixopt
18064                hexadecimal-constant integer-suffixopt
18065 (6.4.4.1) decimal-constant:
18066               nonzero-digit
18067               decimal-constant digit
18068 (6.4.4.1) octal-constant:
18069                0
18070                octal-constant octal-digit
18071 (6.4.4.1) hexadecimal-constant:
18072               hexadecimal-prefix hexadecimal-digit
18073               hexadecimal-constant hexadecimal-digit
18074 (6.4.4.1) hexadecimal-prefix: one of
18075               0x 0X
18076 (6.4.4.1) nonzero-digit: one of
18077               1 2 3 4 5              6      7   8   9
18078 (6.4.4.1) octal-digit: one of
18079                0 1 2 3           4   5      6   7
18080
18081
18082
18083
18084 [page 456]
18085
18086 (6.4.4.1) hexadecimal-digit: one of
18087               0 1 2 3 4 5                6    7    8   9
18088               a b c d e f
18089               A B C D E F
18090 (6.4.4.1) integer-suffix:
18091                unsigned-suffix long-suffixopt
18092                unsigned-suffix long-long-suffix
18093                long-suffix unsigned-suffixopt
18094                long-long-suffix unsigned-suffixopt
18095 (6.4.4.1) unsigned-suffix: one of
18096                u U
18097 (6.4.4.1) long-suffix: one of
18098                l L
18099 (6.4.4.1) long-long-suffix: one of
18100                ll LL
18101 (6.4.4.2) floating-constant:
18102                decimal-floating-constant
18103                hexadecimal-floating-constant
18104 (6.4.4.2) decimal-floating-constant:
18105               fractional-constant exponent-partopt floating-suffixopt
18106               digit-sequence exponent-part floating-suffixopt
18107 (6.4.4.2) hexadecimal-floating-constant:
18108               hexadecimal-prefix hexadecimal-fractional-constant
18109                             binary-exponent-part floating-suffixopt
18110               hexadecimal-prefix hexadecimal-digit-sequence
18111                             binary-exponent-part floating-suffixopt
18112 (6.4.4.2) fractional-constant:
18113                digit-sequenceopt . digit-sequence
18114                digit-sequence .
18115 (6.4.4.2) exponent-part:
18116               e signopt digit-sequence
18117               E signopt digit-sequence
18118 (6.4.4.2) sign: one of
18119                + -
18120
18121
18122
18123 [page 457]
18124
18125 (6.4.4.2) digit-sequence:
18126                digit
18127                digit-sequence digit
18128 (6.4.4.2) hexadecimal-fractional-constant:
18129               hexadecimal-digit-sequenceopt .
18130                              hexadecimal-digit-sequence
18131               hexadecimal-digit-sequence .
18132 (6.4.4.2) binary-exponent-part:
18133                p signopt digit-sequence
18134                P signopt digit-sequence
18135 (6.4.4.2) hexadecimal-digit-sequence:
18136               hexadecimal-digit
18137               hexadecimal-digit-sequence hexadecimal-digit
18138 (6.4.4.2) floating-suffix: one of
18139                f l F L
18140 (6.4.4.3) enumeration-constant:
18141               identifier
18142 (6.4.4.4) character-constant:
18143               ' c-char-sequence '
18144               L' c-char-sequence '
18145               u' c-char-sequence '
18146               U' c-char-sequence '
18147 (6.4.4.4) c-char-sequence:
18148                c-char
18149                c-char-sequence c-char
18150 (6.4.4.4) c-char:
18151                any member of the source character set except
18152                             the single-quote ', backslash \, or new-line character
18153                escape-sequence
18154 (6.4.4.4) escape-sequence:
18155               simple-escape-sequence
18156               octal-escape-sequence
18157               hexadecimal-escape-sequence
18158               universal-character-name
18159
18160
18161
18162
18163 [page 458]
18164
18165 (6.4.4.4) simple-escape-sequence: one of
18166               \' \" \? \\
18167               \a \b \f \n \r \t                   \v
18168 (6.4.4.4) octal-escape-sequence:
18169                \ octal-digit
18170                \ octal-digit octal-digit
18171                \ octal-digit octal-digit octal-digit
18172 (6.4.4.4) hexadecimal-escape-sequence:
18173               \x hexadecimal-digit
18174               hexadecimal-escape-sequence hexadecimal-digit
18175 A.1.6 String literals
18176 (6.4.5) string-literal:
18177                encoding-prefixopt " s-char-sequenceopt "
18178 (6.4.5) encoding-prefix:
18179               u8
18180               u
18181               U
18182               L
18183 (6.4.5) s-char-sequence:
18184                s-char
18185                s-char-sequence s-char
18186 (6.4.5) s-char:
18187                any member of the source character set except
18188                             the double-quote ", backslash \, or new-line character
18189                escape-sequence
18190 A.1.7 Punctuators
18191 (6.4.6) punctuator: one of
18192               [ ] ( ) { } . ->
18193               ++ -- & * + - ~ !
18194               / % << >> < > <= >=                      ==    !=    ^    |   &&   ||
18195               ? : ; ...
18196               = *= /= %= += -= <<=                     >>=    &=       ^=   |=
18197               , # ##
18198               <: :> <% %> %: %:%:
18199
18200
18201
18202
18203 [page 459]
18204
18205 A.1.8 Header names
18206 (6.4.7) header-name:
18207               < h-char-sequence >
18208               " q-char-sequence "
18209 (6.4.7) h-char-sequence:
18210               h-char
18211               h-char-sequence h-char
18212 (6.4.7) h-char:
18213               any member of the source character set except
18214                            the new-line character and >
18215 (6.4.7) q-char-sequence:
18216               q-char
18217               q-char-sequence q-char
18218 (6.4.7) q-char:
18219               any member of the source character set except
18220                            the new-line character and "
18221 A.1.9 Preprocessing numbers
18222 (6.4.8) pp-number:
18223               digit
18224               . digit
18225               pp-number   digit
18226               pp-number   identifier-nondigit
18227               pp-number   e sign
18228               pp-number   E sign
18229               pp-number   p sign
18230               pp-number   P sign
18231               pp-number   .
18232
18233
18234
18235
18236 [page 460]
18237
18238 A.2 Phrase structure grammar
18239 A.2.1 Expressions
18240 (6.5.1) primary-expression:
18241               identifier
18242               constant
18243               string-literal
18244               ( expression )
18245               generic-selection
18246 (6.5.1.1) generic-selection:
18247               _Generic ( assignment-expression , generic-assoc-list )
18248 (6.5.1.1) generic-assoc-list:
18249               generic-association
18250               generic-assoc-list , generic-association
18251 (6.5.1.1) generic-association:
18252               type-name : assignment-expression
18253               default : assignment-expression
18254 (6.5.2) postfix-expression:
18255               primary-expression
18256               postfix-expression [ expression ]
18257               postfix-expression ( argument-expression-listopt )
18258               postfix-expression . identifier
18259               postfix-expression -> identifier
18260               postfix-expression ++
18261               postfix-expression --
18262               ( type-name ) { initializer-list }
18263               ( type-name ) { initializer-list , }
18264 (6.5.2) argument-expression-list:
18265              assignment-expression
18266              argument-expression-list , assignment-expression
18267 (6.5.3) unary-expression:
18268               postfix-expression
18269               ++ unary-expression
18270               -- unary-expression
18271               unary-operator cast-expression
18272               sizeof unary-expression
18273               sizeof ( type-name )
18274               alignof ( type-name )
18275
18276 [page 461]
18277
18278 (6.5.3) unary-operator: one of
18279               & * + - ~                !
18280 (6.5.4) cast-expression:
18281                unary-expression
18282                ( type-name ) cast-expression
18283 (6.5.5) multiplicative-expression:
18284                cast-expression
18285                multiplicative-expression * cast-expression
18286                multiplicative-expression / cast-expression
18287                multiplicative-expression % cast-expression
18288 (6.5.6) additive-expression:
18289                multiplicative-expression
18290                additive-expression + multiplicative-expression
18291                additive-expression - multiplicative-expression
18292 (6.5.7) shift-expression:
18293                 additive-expression
18294                 shift-expression << additive-expression
18295                 shift-expression >> additive-expression
18296 (6.5.8) relational-expression:
18297                shift-expression
18298                relational-expression   <    shift-expression
18299                relational-expression   >    shift-expression
18300                relational-expression   <=   shift-expression
18301                relational-expression   >=   shift-expression
18302 (6.5.9) equality-expression:
18303                relational-expression
18304                equality-expression == relational-expression
18305                equality-expression != relational-expression
18306 (6.5.10) AND-expression:
18307              equality-expression
18308              AND-expression & equality-expression
18309 (6.5.11) exclusive-OR-expression:
18310               AND-expression
18311               exclusive-OR-expression ^ AND-expression
18312
18313
18314
18315
18316 [page 462]
18317
18318 (6.5.12) inclusive-OR-expression:
18319                exclusive-OR-expression
18320                inclusive-OR-expression | exclusive-OR-expression
18321 (6.5.13) logical-AND-expression:
18322               inclusive-OR-expression
18323               logical-AND-expression && inclusive-OR-expression
18324 (6.5.14) logical-OR-expression:
18325               logical-AND-expression
18326               logical-OR-expression || logical-AND-expression
18327 (6.5.15) conditional-expression:
18328               logical-OR-expression
18329               logical-OR-expression ? expression : conditional-expression
18330 (6.5.16) assignment-expression:
18331               conditional-expression
18332               unary-expression assignment-operator assignment-expression
18333 (6.5.16) assignment-operator: one of
18334               = *= /= %= +=                -=    <<=    >>=      &=    ^=   |=
18335 (6.5.17) expression:
18336               assignment-expression
18337               expression , assignment-expression
18338 (6.6) constant-expression:
18339               conditional-expression
18340 A.2.2 Declarations
18341 (6.7) declaration:
18342                declaration-specifiers init-declarator-listopt ;
18343                static_assert-declaration
18344 (6.7) declaration-specifiers:
18345                storage-class-specifier declaration-specifiersopt
18346                type-specifier declaration-specifiersopt
18347                type-qualifier declaration-specifiersopt
18348                function-specifier declaration-specifiersopt
18349                alignment-specifier declaration-specifiersopt
18350 (6.7) init-declarator-list:
18351                init-declarator
18352                init-declarator-list , init-declarator
18353
18354
18355 [page 463]
18356
18357 (6.7) init-declarator:
18358                declarator
18359                declarator = initializer
18360 (6.7.1) storage-class-specifier:
18361               typedef
18362               extern
18363               static
18364               _Thread_local
18365               auto
18366               register
18367 (6.7.2) type-specifier:
18368                void
18369                char
18370                short
18371                int
18372                long
18373                float
18374                double
18375                signed
18376                unsigned
18377                _Bool
18378                _Complex
18379                atomic-type-specifier
18380                struct-or-union-specifier
18381                enum-specifier
18382                typedef-name
18383 (6.7.2.1) struct-or-union-specifier:
18384                struct-or-union identifieropt { struct-declaration-list }
18385                struct-or-union identifier
18386 (6.7.2.1) struct-or-union:
18387                struct
18388                union
18389 (6.7.2.1) struct-declaration-list:
18390                struct-declaration
18391                struct-declaration-list struct-declaration
18392 (6.7.2.1) struct-declaration:
18393                specifier-qualifier-list struct-declarator-listopt ;
18394                static_assert-declaration
18395
18396 [page 464]
18397
18398 (6.7.2.1) specifier-qualifier-list:
18399                type-specifier specifier-qualifier-listopt
18400                type-qualifier specifier-qualifier-listopt
18401 (6.7.2.1) struct-declarator-list:
18402                struct-declarator
18403                struct-declarator-list , struct-declarator
18404 (6.7.2.1) struct-declarator:
18405                declarator
18406                declaratoropt : constant-expression
18407 (6.7.2.2) enum-specifier:
18408               enum identifieropt { enumerator-list }
18409               enum identifieropt { enumerator-list , }
18410               enum identifier
18411 (6.7.2.2) enumerator-list:
18412               enumerator
18413               enumerator-list , enumerator
18414 (6.7.2.2) enumerator:
18415               enumeration-constant
18416               enumeration-constant = constant-expression
18417 (6.7.2.4) atomic-type-specifier:
18418               _Atomic ( type-name )
18419 (6.7.3) type-qualifier:
18420               const
18421               restrict
18422               volatile
18423               _Atomic
18424 (6.7.4) function-specifier:
18425                inline
18426                _Noreturn
18427 (6.7.5) alignment-specifier:
18428               _Alignas ( type-name )
18429               _Alignas ( constant-expression )
18430 (6.7.6) declarator:
18431               pointeropt direct-declarator
18432
18433
18434
18435 [page 465]
18436
18437 (6.7.6) direct-declarator:
18438                identifier
18439                ( declarator )
18440                direct-declarator [ type-qualifier-listopt assignment-expressionopt ]
18441                direct-declarator [ static type-qualifier-listopt assignment-expression ]
18442                direct-declarator [ type-qualifier-list static assignment-expression ]
18443                direct-declarator [ type-qualifier-listopt * ]
18444                direct-declarator ( parameter-type-list )
18445                direct-declarator ( identifier-listopt )
18446 (6.7.6) pointer:
18447                * type-qualifier-listopt
18448                * type-qualifier-listopt pointer
18449 (6.7.6) type-qualifier-list:
18450               type-qualifier
18451               type-qualifier-list type-qualifier
18452 (6.7.6) parameter-type-list:
18453              parameter-list
18454              parameter-list , ...
18455 (6.7.6) parameter-list:
18456              parameter-declaration
18457              parameter-list , parameter-declaration
18458 (6.7.6) parameter-declaration:
18459              declaration-specifiers declarator
18460              declaration-specifiers abstract-declaratoropt
18461 (6.7.6) identifier-list:
18462                identifier
18463                identifier-list , identifier
18464 (6.7.7) type-name:
18465               specifier-qualifier-list abstract-declaratoropt
18466 (6.7.7) abstract-declarator:
18467               pointer
18468               pointeropt direct-abstract-declarator
18469
18470
18471
18472
18473 [page 466]
18474
18475 (6.7.7) direct-abstract-declarator:
18476                ( abstract-declarator )
18477                direct-abstract-declaratoropt [ type-qualifier-listopt
18478                               assignment-expressionopt ]
18479                direct-abstract-declaratoropt [ static type-qualifier-listopt
18480                               assignment-expression ]
18481                direct-abstract-declaratoropt [ type-qualifier-list static
18482                               assignment-expression ]
18483                direct-abstract-declaratoropt [ * ]
18484                direct-abstract-declaratoropt ( parameter-type-listopt )
18485 (6.7.8) typedef-name:
18486               identifier
18487 (6.7.9) initializer:
18488                 assignment-expression
18489                 { initializer-list }
18490                 { initializer-list , }
18491 (6.7.9) initializer-list:
18492                 designationopt initializer
18493                 initializer-list , designationopt initializer
18494 (6.7.9) designation:
18495               designator-list =
18496 (6.7.9) designator-list:
18497               designator
18498               designator-list designator
18499 (6.7.9) designator:
18500               [ constant-expression ]
18501               . identifier
18502 (6.7.10) static_assert-declaration:
18503                _Static_assert ( constant-expression , string-literal ) ;
18504
18505
18506
18507
18508 [page 467]
18509
18510 A.2.3 Statements
18511 (6.8) statement:
18512               labeled-statement
18513               compound-statement
18514               expression-statement
18515               selection-statement
18516               iteration-statement
18517               jump-statement
18518 (6.8.1) labeled-statement:
18519                identifier : statement
18520                case constant-expression : statement
18521                default : statement
18522 (6.8.2) compound-statement:
18523              { block-item-listopt }
18524 (6.8.2) block-item-list:
18525                block-item
18526                block-item-list block-item
18527 (6.8.2) block-item:
18528                declaration
18529                statement
18530 (6.8.3) expression-statement:
18531               expressionopt ;
18532 (6.8.4) selection-statement:
18533                if ( expression ) statement
18534                if ( expression ) statement else statement
18535                switch ( expression ) statement
18536 (6.8.5) iteration-statement:
18537                 while ( expression ) statement
18538                 do statement while ( expression ) ;
18539                 for ( expressionopt ; expressionopt ; expressionopt ) statement
18540                 for ( declaration expressionopt ; expressionopt ) statement
18541 (6.8.6) jump-statement:
18542               goto identifier ;
18543               continue ;
18544               break ;
18545               return expressionopt ;
18546
18547 [page 468]
18548
18549 A.2.4 External definitions
18550 (6.9) translation-unit:
18551                external-declaration
18552                translation-unit external-declaration
18553 (6.9) external-declaration:
18554                function-definition
18555                declaration
18556 (6.9.1) function-definition:
18557                declaration-specifiers declarator declaration-listopt compound-statement
18558 (6.9.1) declaration-list:
18559               declaration
18560               declaration-list declaration
18561 A.3 Preprocessing directives
18562 (6.10) preprocessing-file:
18563               groupopt
18564 (6.10) group:
18565                 group-part
18566                 group group-part
18567 (6.10) group-part:
18568               if-section
18569               control-line
18570               text-line
18571               # non-directive
18572 (6.10) if-section:
18573                 if-group elif-groupsopt else-groupopt endif-line
18574 (6.10) if-group:
18575                # if     constant-expression new-line groupopt
18576                # ifdef identifier new-line groupopt
18577                # ifndef identifier new-line groupopt
18578 (6.10) elif-groups:
18579                elif-group
18580                elif-groups elif-group
18581 (6.10) elif-group:
18582                # elif       constant-expression new-line groupopt
18583
18584
18585 [page 469]
18586
18587 (6.10) else-group:
18588                # else        new-line groupopt
18589 (6.10) endif-line:
18590                # endif       new-line
18591 (6.10) control-line:
18592               # include pp-tokens new-line
18593               # define identifier replacement-list new-line
18594               # define identifier lparen identifier-listopt )
18595                                               replacement-list new-line
18596               # define identifier lparen ... ) replacement-list new-line
18597               # define identifier lparen identifier-list , ... )
18598                                               replacement-list new-line
18599               # undef   identifier new-line
18600               # line    pp-tokens new-line
18601               # error   pp-tokensopt new-line
18602               # pragma pp-tokensopt new-line
18603               #         new-line
18604 (6.10) text-line:
18605                pp-tokensopt new-line
18606 (6.10) non-directive:
18607               pp-tokens new-line
18608 (6.10) lparen:
18609                  a ( character not immediately preceded by white-space
18610 (6.10) replacement-list:
18611               pp-tokensopt
18612 (6.10) pp-tokens:
18613               preprocessing-token
18614               pp-tokens preprocessing-token
18615 (6.10) new-line:
18616               the new-line character
18617
18618
18619
18620
18621 [page 470]
18622
18623                                Annex B
18624                              (informative)
18625                          Library summary
18626 B.1 Diagnostics <assert.h>
18627         NDEBUG
18628         static_assert
18629         void assert(scalar expression);
18630 B.2 Complex <complex.h>
18631         __STDC_NO_COMPLEX__           imaginary
18632         complex                         _Imaginary_I
18633         _Complex_I                      I
18634         #pragma STDC CX_LIMITED_RANGE on-off-switch
18635         double complex cacos(double complex z);
18636         float complex cacosf(float complex z);
18637         long double complex cacosl(long double complex z);
18638         double complex casin(double complex z);
18639         float complex casinf(float complex z);
18640         long double complex casinl(long double complex z);
18641         double complex catan(double complex z);
18642         float complex catanf(float complex z);
18643         long double complex catanl(long double complex z);
18644         double complex ccos(double complex z);
18645         float complex ccosf(float complex z);
18646         long double complex ccosl(long double complex z);
18647         double complex csin(double complex z);
18648         float complex csinf(float complex z);
18649         long double complex csinl(long double complex z);
18650         double complex ctan(double complex z);
18651         float complex ctanf(float complex z);
18652         long double complex ctanl(long double complex z);
18653         double complex cacosh(double complex z);
18654         float complex cacoshf(float complex z);
18655         long double complex cacoshl(long double complex z);
18656         double complex casinh(double complex z);
18657         float complex casinhf(float complex z);
18658         long double complex casinhl(long double complex z);
18659
18660 [page 471]
18661
18662       double complex catanh(double complex z);
18663       float complex catanhf(float complex z);
18664       long double complex catanhl(long double complex z);
18665       double complex ccosh(double complex z);
18666       float complex ccoshf(float complex z);
18667       long double complex ccoshl(long double complex z);
18668       double complex csinh(double complex z);
18669       float complex csinhf(float complex z);
18670       long double complex csinhl(long double complex z);
18671       double complex ctanh(double complex z);
18672       float complex ctanhf(float complex z);
18673       long double complex ctanhl(long double complex z);
18674       double complex cexp(double complex z);
18675       float complex cexpf(float complex z);
18676       long double complex cexpl(long double complex z);
18677       double complex clog(double complex z);
18678       float complex clogf(float complex z);
18679       long double complex clogl(long double complex z);
18680       double cabs(double complex z);
18681       float cabsf(float complex z);
18682       long double cabsl(long double complex z);
18683       double complex cpow(double complex x, double complex y);
18684       float complex cpowf(float complex x, float complex y);
18685       long double complex cpowl(long double complex x,
18686            long double complex y);
18687       double complex csqrt(double complex z);
18688       float complex csqrtf(float complex z);
18689       long double complex csqrtl(long double complex z);
18690       double carg(double complex z);
18691       float cargf(float complex z);
18692       long double cargl(long double complex z);
18693       double cimag(double complex z);
18694       float cimagf(float complex z);
18695       long double cimagl(long double complex z);
18696       double complex CMPLX(double x, double y);
18697       float complex CMPLXF(float x, float y);
18698       long double complex CMPLXL(long double x, long double y);
18699       double complex conj(double complex z);
18700       float complex conjf(float complex z);
18701       long double complex conjl(long double complex z);
18702       double complex cproj(double complex z);
18703
18704 [page 472]
18705
18706         float complex cprojf(float complex z);
18707         long double complex cprojl(long double complex z);
18708         double creal(double complex z);
18709         float crealf(float complex z);
18710         long double creall(long double complex z);
18711 B.3 Character handling <ctype.h>
18712         int   isalnum(int c);
18713         int   isalpha(int c);
18714         int   isblank(int c);
18715         int   iscntrl(int c);
18716         int   isdigit(int c);
18717         int   isgraph(int c);
18718         int   islower(int c);
18719         int   isprint(int c);
18720         int   ispunct(int c);
18721         int   isspace(int c);
18722         int   isupper(int c);
18723         int   isxdigit(int c);
18724         int   tolower(int c);
18725         int   toupper(int c);
18726 B.4 Errors <errno.h>
18727         EDOM           EILSEQ            ERANGE           errno
18728         __STDC_WANT_LIB_EXT1__
18729         errno_t
18730 B.5 Floating-point environment <fenv.h>
18731         fenv_t               FE_OVERFLOW             FE_TOWARDZERO
18732         fexcept_t            FE_UNDERFLOW            FE_UPWARD
18733         FE_DIVBYZERO         FE_ALL_EXCEPT           FE_DFL_ENV
18734         FE_INEXACT           FE_DOWNWARD
18735         FE_INVALID           FE_TONEAREST
18736         #pragma STDC FENV_ACCESS on-off-switch
18737         int feclearexcept(int excepts);
18738         int fegetexceptflag(fexcept_t *flagp, int excepts);
18739         int feraiseexcept(int excepts);
18740         int fesetexceptflag(const fexcept_t *flagp,
18741              int excepts);
18742         int fetestexcept(int excepts);
18743
18744 [page 473]
18745
18746       int   fegetround(void);
18747       int   fesetround(int round);
18748       int   fegetenv(fenv_t *envp);
18749       int   feholdexcept(fenv_t *envp);
18750       int   fesetenv(const fenv_t *envp);
18751       int   feupdateenv(const fenv_t *envp);
18752 B.6 Characteristics of floating types <float.h>
18753       FLT_ROUNDS              DBL_DIG                 FLT_MAX
18754       FLT_EVAL_METHOD         LDBL_DIG                DBL_MAX
18755       FLT_HAS_SUBNORM         FLT_MIN_EXP             LDBL_MAX
18756       DBL_HAS_SUBNORM         DBL_MIN_EXP             FLT_EPSILON
18757       LDBL_HAS_SUBNORM        LDBL_MIN_EXP            DBL_EPSILON
18758       FLT_RADIX               FLT_MIN_10_EXP          LDBL_EPSILON
18759       FLT_MANT_DIG            DBL_MIN_10_EXP          FLT_MIN
18760       DBL_MANT_DIG            LDBL_MIN_10_EXP         DBL_MIN
18761       LDBL_MANT_DIG           FLT_MAX_EXP             LDBL_MIN
18762       FLT_DECIMAL_DIG         DBL_MAX_EXP             FLT_TRUE_MIN
18763       DBL_DECIMAL_DIG         LDBL_MAX_EXP            DBL_TRUE_MIN
18764       LDBL_DECIMAL_DIG        FLT_MAX_10_EXP          LDBL_TRUE_MIN
18765       DECIMAL_DIG             DBL_MAX_10_EXP
18766       FLT_DIG                 LDBL_MAX_10_EXP
18767 B.7 Format conversion of integer types <inttypes.h>
18768       imaxdiv_t
18769       PRIdN         PRIdLEASTN       PRIdFASTN        PRIdMAX    PRIdPTR
18770       PRIiN         PRIiLEASTN       PRIiFASTN        PRIiMAX    PRIiPTR
18771       PRIoN         PRIoLEASTN       PRIoFASTN        PRIoMAX    PRIoPTR
18772       PRIuN         PRIuLEASTN       PRIuFASTN        PRIuMAX    PRIuPTR
18773       PRIxN         PRIxLEASTN       PRIxFASTN        PRIxMAX    PRIxPTR
18774       PRIXN         PRIXLEASTN       PRIXFASTN        PRIXMAX    PRIXPTR
18775       SCNdN         SCNdLEASTN       SCNdFASTN        SCNdMAX    SCNdPTR
18776       SCNiN         SCNiLEASTN       SCNiFASTN        SCNiMAX    SCNiPTR
18777       SCNoN         SCNoLEASTN       SCNoFASTN        SCNoMAX    SCNoPTR
18778       SCNuN         SCNuLEASTN       SCNuFASTN        SCNuMAX    SCNuPTR
18779       SCNxN         SCNxLEASTN       SCNxFASTN        SCNxMAX    SCNxPTR
18780       intmax_t imaxabs(intmax_t j);
18781       imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
18782       intmax_t strtoimax(const char * restrict nptr,
18783               char ** restrict endptr, int base);
18784
18785 [page 474]
18786
18787         uintmax_t strtoumax(const char * restrict nptr,
18788                 char ** restrict endptr, int base);
18789         intmax_t wcstoimax(const wchar_t * restrict nptr,
18790                 wchar_t ** restrict endptr, int base);
18791         uintmax_t wcstoumax(const wchar_t * restrict nptr,
18792                 wchar_t ** restrict endptr, int base);
18793 B.8 Alternative spellings <iso646.h>
18794         and            bitor             not_eq           xor
18795         and_eq         compl             or               xor_eq
18796         bitand         not               or_eq
18797 B.9 Sizes of integer types <limits.h>
18798         CHAR_BIT       CHAR_MAX          INT_MIN          ULONG_MAX
18799         SCHAR_MIN      MB_LEN_MAX        INT_MAX          LLONG_MIN
18800         SCHAR_MAX      SHRT_MIN          UINT_MAX         LLONG_MAX
18801         UCHAR_MAX      SHRT_MAX          LONG_MIN         ULLONG_MAX
18802         CHAR_MIN       USHRT_MAX         LONG_MAX
18803 B.10 Localization <locale.h>
18804         struct lconv   LC_ALL            LC_CTYPE         LC_NUMERIC
18805         NULL           LC_COLLATE        LC_MONETARY      LC_TIME
18806         char *setlocale(int category, const char *locale);
18807         struct lconv *localeconv(void);
18808 B.11 Mathematics <math.h>
18809         float_t              FP_INFINITE             FP_FAST_FMAL
18810         double_t             FP_NAN                  FP_ILOGB0
18811         HUGE_VAL             FP_NORMAL               FP_ILOGBNAN
18812         HUGE_VALF            FP_SUBNORMAL            MATH_ERRNO
18813         HUGE_VALL            FP_ZERO                 MATH_ERREXCEPT
18814         INFINITY             FP_FAST_FMA             math_errhandling
18815         NAN                  FP_FAST_FMAF
18816         #pragma STDC FP_CONTRACT on-off-switch
18817         int fpclassify(real-floating x);
18818         int isfinite(real-floating x);
18819         int isinf(real-floating x);
18820         int isnan(real-floating x);
18821         int isnormal(real-floating x);
18822         int signbit(real-floating x);
18823 [page 475]
18824
18825       double acos(double x);
18826       float acosf(float x);
18827       long double acosl(long double x);
18828       double asin(double x);
18829       float asinf(float x);
18830       long double asinl(long double x);
18831       double atan(double x);
18832       float atanf(float x);
18833       long double atanl(long double x);
18834       double atan2(double y, double x);
18835       float atan2f(float y, float x);
18836       long double atan2l(long double y, long double x);
18837       double cos(double x);
18838       float cosf(float x);
18839       long double cosl(long double x);
18840       double sin(double x);
18841       float sinf(float x);
18842       long double sinl(long double x);
18843       double tan(double x);
18844       float tanf(float x);
18845       long double tanl(long double x);
18846       double acosh(double x);
18847       float acoshf(float x);
18848       long double acoshl(long double x);
18849       double asinh(double x);
18850       float asinhf(float x);
18851       long double asinhl(long double x);
18852       double atanh(double x);
18853       float atanhf(float x);
18854       long double atanhl(long double x);
18855       double cosh(double x);
18856       float coshf(float x);
18857       long double coshl(long double x);
18858       double sinh(double x);
18859       float sinhf(float x);
18860       long double sinhl(long double x);
18861       double tanh(double x);
18862       float tanhf(float x);
18863       long double tanhl(long double x);
18864       double exp(double x);
18865       float expf(float x);
18866
18867 [page 476]
18868
18869         long double expl(long double x);
18870         double exp2(double x);
18871         float exp2f(float x);
18872         long double exp2l(long double x);
18873         double expm1(double x);
18874         float expm1f(float x);
18875         long double expm1l(long double x);
18876         double frexp(double value, int *exp);
18877         float frexpf(float value, int *exp);
18878         long double frexpl(long double value, int *exp);
18879         int ilogb(double x);
18880         int ilogbf(float x);
18881         int ilogbl(long double x);
18882         double ldexp(double x, int exp);
18883         float ldexpf(float x, int exp);
18884         long double ldexpl(long double x, int exp);
18885         double log(double x);
18886         float logf(float x);
18887         long double logl(long double x);
18888         double log10(double x);
18889         float log10f(float x);
18890         long double log10l(long double x);
18891         double log1p(double x);
18892         float log1pf(float x);
18893         long double log1pl(long double x);
18894         double log2(double x);
18895         float log2f(float x);
18896         long double log2l(long double x);
18897         double logb(double x);
18898         float logbf(float x);
18899         long double logbl(long double x);
18900         double modf(double value, double *iptr);
18901         float modff(float value, float *iptr);
18902         long double modfl(long double value, long double *iptr);
18903         double scalbn(double x, int n);
18904         float scalbnf(float x, int n);
18905         long double scalbnl(long double x, int n);
18906         double scalbln(double x, long int n);
18907         float scalblnf(float x, long int n);
18908         long double scalblnl(long double x, long int n);
18909         double cbrt(double x);
18910
18911 [page 477]
18912
18913       float cbrtf(float x);
18914       long double cbrtl(long double x);
18915       double fabs(double x);
18916       float fabsf(float x);
18917       long double fabsl(long double x);
18918       double hypot(double x, double y);
18919       float hypotf(float x, float y);
18920       long double hypotl(long double x, long double y);
18921       double pow(double x, double y);
18922       float powf(float x, float y);
18923       long double powl(long double x, long double y);
18924       double sqrt(double x);
18925       float sqrtf(float x);
18926       long double sqrtl(long double x);
18927       double erf(double x);
18928       float erff(float x);
18929       long double erfl(long double x);
18930       double erfc(double x);
18931       float erfcf(float x);
18932       long double erfcl(long double x);
18933       double lgamma(double x);
18934       float lgammaf(float x);
18935       long double lgammal(long double x);
18936       double tgamma(double x);
18937       float tgammaf(float x);
18938       long double tgammal(long double x);
18939       double ceil(double x);
18940       float ceilf(float x);
18941       long double ceill(long double x);
18942       double floor(double x);
18943       float floorf(float x);
18944       long double floorl(long double x);
18945       double nearbyint(double x);
18946       float nearbyintf(float x);
18947       long double nearbyintl(long double x);
18948       double rint(double x);
18949       float rintf(float x);
18950       long double rintl(long double x);
18951       long int lrint(double x);
18952       long int lrintf(float x);
18953       long int lrintl(long double x);
18954
18955 [page 478]
18956
18957         long long int llrint(double x);
18958         long long int llrintf(float x);
18959         long long int llrintl(long double x);
18960         double round(double x);
18961         float roundf(float x);
18962         long double roundl(long double x);
18963         long int lround(double x);
18964         long int lroundf(float x);
18965         long int lroundl(long double x);
18966         long long int llround(double x);
18967         long long int llroundf(float x);
18968         long long int llroundl(long double x);
18969         double trunc(double x);
18970         float truncf(float x);
18971         long double truncl(long double x);
18972         double fmod(double x, double y);
18973         float fmodf(float x, float y);
18974         long double fmodl(long double x, long double y);
18975         double remainder(double x, double y);
18976         float remainderf(float x, float y);
18977         long double remainderl(long double x, long double y);
18978         double remquo(double x, double y, int *quo);
18979         float remquof(float x, float y, int *quo);
18980         long double remquol(long double x, long double y,
18981              int *quo);
18982         double copysign(double x, double y);
18983         float copysignf(float x, float y);
18984         long double copysignl(long double x, long double y);
18985         double nan(const char *tagp);
18986         float nanf(const char *tagp);
18987         long double nanl(const char *tagp);
18988         double nextafter(double x, double y);
18989         float nextafterf(float x, float y);
18990         long double nextafterl(long double x, long double y);
18991         double nexttoward(double x, long double y);
18992         float nexttowardf(float x, long double y);
18993         long double nexttowardl(long double x, long double y);
18994         double fdim(double x, double y);
18995         float fdimf(float x, float y);
18996         long double fdiml(long double x, long double y);
18997         double fmax(double x, double y);
18998
18999 [page 479]
19000
19001       float fmaxf(float x, float y);
19002       long double fmaxl(long double x, long double y);
19003       double fmin(double x, double y);
19004       float fminf(float x, float y);
19005       long double fminl(long double x, long double y);
19006       double fma(double x, double y, double z);
19007       float fmaf(float x, float y, float z);
19008       long double fmal(long double x, long double y,
19009            long double z);
19010       int isgreater(real-floating x, real-floating y);
19011       int isgreaterequal(real-floating x, real-floating y);
19012       int isless(real-floating x, real-floating y);
19013       int islessequal(real-floating x, real-floating y);
19014       int islessgreater(real-floating x, real-floating y);
19015       int isunordered(real-floating x, real-floating y);
19016 B.12 Nonlocal jumps <setjmp.h>
19017       jmp_buf
19018       int setjmp(jmp_buf env);
19019       _Noreturn void longjmp(jmp_buf env, int val);
19020 B.13 Signal handling <signal.h>
19021       sig_atomic_t    SIG_IGN           SIGILL           SIGTERM
19022       SIG_DFL         SIGABRT           SIGINT
19023       SIG_ERR         SIGFPE            SIGSEGV
19024       void (*signal(int sig, void (*func)(int)))(int);
19025       int raise(int sig);
19026
19027
19028
19029
19030 [page 480]
19031
19032 B.14 Alignment <stdalign.h>
19033         alignas
19034         __alignas_is_defined
19035 B.15 Variable arguments <stdarg.h>
19036         va_list
19037         type va_arg(va_list ap, type);
19038         void va_copy(va_list dest, va_list src);
19039         void va_end(va_list ap);
19040         void va_start(va_list ap, parmN);
19041 B.16 Atomics <stdatomic.h>
19042         ATOMIC_CHAR_LOCK_FREE           atomic_uint
19043         ATOMIC_CHAR16_T_LOCK_FREE       atomic_long
19044         ATOMIC_CHAR32_T_LOCK_FREE       atomic_ulong
19045         ATOMIC_WCHAR_T_LOCK_FREE        atomic_llong
19046         ATOMIC_SHORT_LOCK_FREE          atomic_ullong
19047         ATOMIC_INT_LOCK_FREE            atomic_char16_t
19048         ATOMIC_LONG_LOCK_FREE           atomic_char32_t
19049         ATOMIC_LLONG_LOCK_FREE          atomic_wchar_t
19050         ATOMIC_ADDRESS_LOCK_FREE        atomic_int_least8_t
19051         ATOMIC_FLAG_INIT                atomic_uint_least8_t
19052         memory_order                    atomic_int_least16_t
19053         atomic_flag                     atomic_uint_least16_t
19054         atomic_bool                     atomic_int_least32_t
19055         atomic_address                  atomic_uint_least32_t
19056         memory_order_relaxed            atomic_int_least64_t
19057         memory_order_consume            atomic_uint_least64_t
19058         memory_order_acquire            atomic_int_fast8_t
19059         memory_order_release            atomic_uint_fast8_t
19060         memory_order_acq_rel            atomic_int_fast16_t
19061         memory_order_seq_cst            atomic_uint_fast16_t
19062         atomic_char                     atomic_int_fast32_t
19063         atomic_schar                    atomic_uint_fast32_t
19064         atomic_uchar                    atomic_int_fast64_t
19065         atomic_short                    atomic_uint_fast64_t
19066         atomic_ushort                   atomic_intptr_t
19067         atomic_int                      atomic_uintptr_t
19068
19069
19070
19071 [page 481]
19072
19073       atomic_size_t                     atomic_intmax_t
19074       atomic_ptrdiff_t                  atomic_uintmax_t
19075       #define ATOMIC_VAR_INIT(C value)
19076       void atomic_init(volatile A *obj, C value);
19077       type kill_dependency(type y);
19078       void atomic_thread_fence(memory_order order);
19079       void atomic_signal_fence(memory_order order);
19080       _Bool atomic_is_lock_free(atomic_type const volatile *obj);
19081       void atomic_store(volatile A *object, C desired);
19082       void atomic_store_explicit(volatile A *object,
19083             C desired, memory_order order);
19084       C atomic_load(volatile A *object);
19085       C atomic_load_explicit(volatile A *object,
19086             memory_order order);
19087       C atomic_exchange(volatile A *object, C desired);
19088       C atomic_exchange_explicit(volatile A *object,
19089             C desired, memory_order order);
19090       _Bool atomic_compare_exchange_strong(volatile A *object,
19091             C *expected, C desired);
19092       _Bool atomic_compare_exchange_strong_explicit(
19093             volatile A *object, C *expected, C desired,
19094             memory_order success, memory_order failure);
19095       _Bool atomic_compare_exchange_weak(volatile A *object,
19096             C *expected, C desired);
19097       _Bool atomic_compare_exchange_weak_explicit(
19098             volatile A *object, C *expected, C desired,
19099             memory_order success, memory_order failure);
19100       C atomic_fetch_key(volatile A *object, M operand);
19101       C atomic_fetch_key_explicit(volatile A *object,
19102             M operand, memory_order order);
19103       bool atomic_flag_test_and_set(
19104             volatile atomic_flag *object);
19105       bool atomic_flag_test_and_set_explicit(
19106             volatile atomic_flag *object, memory_order order);
19107       void atomic_flag_clear(volatile atomic_flag *object);
19108       void atomic_flag_clear_explicit(
19109             volatile atomic_flag *object, memory_order order);
19110
19111
19112
19113
19114 [page 482]
19115
19116 B.17 Boolean type and values <stdbool.h>
19117         bool
19118         true
19119         false
19120         __bool_true_false_are_defined
19121 B.18 Common definitions <stddef.h>
19122         ptrdiff_t       max_align_t       NULL
19123         size_t          wchar_t
19124         offsetof(type, member-designator)
19125         __STDC_WANT_LIB_EXT1__
19126         rsize_t
19127 B.19 Integer types <stdint.h>
19128         intN_t                INT_LEASTN_MIN          PTRDIFF_MAX
19129         uintN_t               INT_LEASTN_MAX          SIG_ATOMIC_MIN
19130         int_leastN_t          UINT_LEASTN_MAX         SIG_ATOMIC_MAX
19131         uint_leastN_t         INT_FASTN_MIN           SIZE_MAX
19132         int_fastN_t           INT_FASTN_MAX           WCHAR_MIN
19133         uint_fastN_t          UINT_FASTN_MAX          WCHAR_MAX
19134         intptr_t              INTPTR_MIN              WINT_MIN
19135         uintptr_t             INTPTR_MAX              WINT_MAX
19136         intmax_t              UINTPTR_MAX             INTN_C(value)
19137         uintmax_t             INTMAX_MIN              UINTN_C(value)
19138         INTN_MIN              INTMAX_MAX              INTMAX_C(value)
19139         INTN_MAX              UINTMAX_MAX             UINTMAX_C(value)
19140         UINTN_MAX             PTRDIFF_MIN
19141         __STDC_WANT_LIB_EXT1__
19142         RSIZE_MAX
19143
19144
19145
19146
19147 [page 483]
19148
19149 B.20 Input/output <stdio.h>
19150       size_t          _IOLBF            FILENAME_MAX     TMP_MAX
19151       FILE            _IONBF            L_tmpnam         stderr
19152       fpos_t          BUFSIZ            SEEK_CUR         stdin
19153       NULL            EOF               SEEK_END         stdout
19154       _IOFBF          FOPEN_MAX         SEEK_SET
19155       int remove(const char *filename);
19156       int rename(const char *old, const char *new);
19157       FILE *tmpfile(void);
19158       char *tmpnam(char *s);
19159       int fclose(FILE *stream);
19160       int fflush(FILE *stream);
19161       FILE *fopen(const char * restrict filename,
19162            const char * restrict mode);
19163       FILE *freopen(const char * restrict filename,
19164            const char * restrict mode,
19165            FILE * restrict stream);
19166       void setbuf(FILE * restrict stream,
19167            char * restrict buf);
19168       int setvbuf(FILE * restrict stream,
19169            char * restrict buf,
19170            int mode, size_t size);
19171       int fprintf(FILE * restrict stream,
19172            const char * restrict format, ...);
19173       int fscanf(FILE * restrict stream,
19174            const char * restrict format, ...);
19175       int printf(const char * restrict format, ...);
19176       int scanf(const char * restrict format, ...);
19177       int snprintf(char * restrict s, size_t n,
19178            const char * restrict format, ...);
19179       int sprintf(char * restrict s,
19180            const char * restrict format, ...);
19181       int sscanf(const char * restrict s,
19182            const char * restrict format, ...);
19183       int vfprintf(FILE * restrict stream,
19184            const char * restrict format, va_list arg);
19185       int vfscanf(FILE * restrict stream,
19186            const char * restrict format, va_list arg);
19187       int vprintf(const char * restrict format, va_list arg);
19188       int vscanf(const char * restrict format, va_list arg);
19189
19190 [page 484]
19191
19192         int vsnprintf(char * restrict s, size_t n,
19193              const char * restrict format, va_list arg);
19194         int vsprintf(char * restrict s,
19195              const char * restrict format, va_list arg);
19196         int vsscanf(const char * restrict s,
19197              const char * restrict format, va_list arg);
19198         int fgetc(FILE *stream);
19199         char *fgets(char * restrict s, int n,
19200              FILE * restrict stream);
19201         int fputc(int c, FILE *stream);
19202         int fputs(const char * restrict s,
19203              FILE * restrict stream);
19204         int getc(FILE *stream);
19205         int getchar(void);
19206         int putc(int c, FILE *stream);                                       *
19207         int putchar(int c);
19208         int puts(const char *s);
19209         int ungetc(int c, FILE *stream);
19210         size_t fread(void * restrict ptr,
19211              size_t size, size_t nmemb,
19212              FILE * restrict stream);
19213         size_t fwrite(const void * restrict ptr,
19214              size_t size, size_t nmemb,
19215              FILE * restrict stream);
19216         int fgetpos(FILE * restrict stream,
19217              fpos_t * restrict pos);
19218         int fseek(FILE *stream, long int offset, int whence);
19219         int fsetpos(FILE *stream, const fpos_t *pos);
19220         long int ftell(FILE *stream);
19221         void rewind(FILE *stream);
19222         void clearerr(FILE *stream);
19223         int feof(FILE *stream);
19224         int ferror(FILE *stream);
19225         void perror(const char *s);
19226         __STDC_WANT_LIB_EXT1__
19227         L_tmpnam_s    TMP_MAX_S         errno_t          rsize_t
19228         errno_t tmpfile_s(FILE * restrict * restrict streamptr);
19229         errno_t tmpnam_s(char *s, rsize_t maxsize);
19230
19231
19232
19233 [page 485]
19234
19235       errno_t fopen_s(FILE * restrict * restrict streamptr,
19236            const char * restrict filename,
19237            const char * restrict mode);
19238       errno_t freopen_s(FILE * restrict * restrict newstreamptr,
19239            const char * restrict filename,
19240            const char * restrict mode,
19241            FILE * restrict stream);
19242       int fprintf_s(FILE * restrict stream,
19243            const char * restrict format, ...);
19244       int fscanf_s(FILE * restrict stream,
19245            const char * restrict format, ...);
19246       int printf_s(const char * restrict format, ...);
19247       int scanf_s(const char * restrict format, ...);
19248       int snprintf_s(char * restrict s, rsize_t n,
19249            const char * restrict format, ...);
19250       int sprintf_s(char * restrict s, rsize_t n,
19251            const char * restrict format, ...);
19252       int sscanf_s(const char * restrict s,
19253            const char * restrict format, ...);
19254       int vfprintf_s(FILE * restrict stream,
19255            const char * restrict format,
19256            va_list arg);
19257       int vfscanf_s(FILE * restrict stream,
19258            const char * restrict format,
19259            va_list arg);
19260       int vprintf_s(const char * restrict format,
19261            va_list arg);
19262       int vscanf_s(const char * restrict format,
19263            va_list arg);
19264       int vsnprintf_s(char * restrict s, rsize_t n,
19265            const char * restrict format,
19266            va_list arg);
19267       int vsprintf_s(char * restrict s, rsize_t n,
19268            const char * restrict format,
19269            va_list arg);
19270       int vsscanf_s(const char * restrict s,
19271            const char * restrict format,
19272            va_list arg);
19273       char *gets_s(char *s, rsize_t n);
19274
19275
19276
19277 [page 486]
19278
19279 B.21 General utilities <stdlib.h>
19280         size_t       ldiv_t            EXIT_FAILURE     MB_CUR_MAX
19281         wchar_t      lldiv_t           EXIT_SUCCESS
19282         div_t        NULL              RAND_MAX
19283         double atof(const char *nptr);
19284         int atoi(const char *nptr);
19285         long int atol(const char *nptr);
19286         long long int atoll(const char *nptr);
19287         double strtod(const char * restrict nptr,
19288              char ** restrict endptr);
19289         float strtof(const char * restrict nptr,
19290              char ** restrict endptr);
19291         long double strtold(const char * restrict nptr,
19292              char ** restrict endptr);
19293         long int strtol(const char * restrict nptr,
19294              char ** restrict endptr, int base);
19295         long long int strtoll(const char * restrict nptr,
19296              char ** restrict endptr, int base);
19297         unsigned long int strtoul(
19298              const char * restrict nptr,
19299              char ** restrict endptr, int base);
19300         unsigned long long int strtoull(
19301              const char * restrict nptr,
19302              char ** restrict endptr, int base);
19303         int rand(void);
19304         void srand(unsigned int seed);
19305         void *aligned_alloc(size_t alignment, size_t size);
19306         void *calloc(size_t nmemb, size_t size);
19307         void free(void *ptr);
19308         void *malloc(size_t size);
19309         void *realloc(void *ptr, size_t size);
19310         _Noreturn void abort(void);
19311         int atexit(void (*func)(void));
19312         int at_quick_exit(void (*func)(void));
19313         _Noreturn void exit(int status);
19314         _Noreturn void _Exit(int status);
19315         char *getenv(const char *name);
19316         _Noreturn void quick_exit(int status);
19317         int system(const char *string);
19318
19319
19320 [page 487]
19321
19322       void *bsearch(const void *key, const void *base,
19323            size_t nmemb, size_t size,
19324            int (*compar)(const void *, const void *));
19325       void qsort(void *base, size_t nmemb, size_t size,
19326            int (*compar)(const void *, const void *));
19327       int abs(int j);
19328       long int labs(long int j);
19329       long long int llabs(long long int j);
19330       div_t div(int numer, int denom);
19331       ldiv_t ldiv(long int numer, long int denom);
19332       lldiv_t lldiv(long long int numer,
19333            long long int denom);
19334       int mblen(const char *s, size_t n);
19335       int mbtowc(wchar_t * restrict pwc,
19336            const char * restrict s, size_t n);
19337       int wctomb(char *s, wchar_t wchar);
19338       size_t mbstowcs(wchar_t * restrict pwcs,
19339            const char * restrict s, size_t n);
19340       size_t wcstombs(char * restrict s,
19341            const wchar_t * restrict pwcs, size_t n);
19342       __STDC_WANT_LIB_EXT1__
19343       errno_t
19344       rsize_t
19345       constraint_handler_t
19346       constraint_handler_t set_constraint_handler_s(
19347            constraint_handler_t handler);
19348       void abort_handler_s(
19349            const char * restrict msg,
19350            void * restrict ptr,
19351            errno_t error);
19352       void ignore_handler_s(
19353            const char * restrict msg,
19354            void * restrict ptr,
19355            errno_t error);
19356       errno_t getenv_s(size_t * restrict len,
19357                 char * restrict value, rsize_t maxsize,
19358                 const char * restrict name);
19359
19360
19361
19362
19363 [page 488]
19364
19365         void *bsearch_s(const void *key, const void *base,
19366              rsize_t nmemb, rsize_t size,
19367              int (*compar)(const void *k, const void *y,
19368                              void *context),
19369              void *context);
19370         errno_t qsort_s(void *base, rsize_t nmemb, rsize_t size,
19371              int (*compar)(const void *x, const void *y,
19372                              void *context),
19373              void *context);
19374         errno_t wctomb_s(int * restrict status,
19375              char * restrict s,
19376              rsize_t smax,
19377              wchar_t wc);
19378         errno_t mbstowcs_s(size_t * restrict retval,
19379              wchar_t * restrict dst, rsize_t dstmax,
19380              const char * restrict src, rsize_t len);
19381         errno_t wcstombs_s(size_t * restrict retval,
19382              char * restrict dst, rsize_t dstmax,
19383              const wchar_t * restrict src, rsize_t len);
19384 B.22 String handling <string.h>
19385         size_t
19386         NULL
19387         void *memcpy(void * restrict s1,
19388              const void * restrict s2, size_t n);
19389         void *memmove(void *s1, const void *s2, size_t n);
19390         char *strcpy(char * restrict s1,
19391              const char * restrict s2);
19392         char *strncpy(char * restrict s1,
19393              const char * restrict s2, size_t n);
19394         char *strcat(char * restrict s1,
19395              const char * restrict s2);
19396         char *strncat(char * restrict s1,
19397              const char * restrict s2, size_t n);
19398         int memcmp(const void *s1, const void *s2, size_t n);
19399         int strcmp(const char *s1, const char *s2);
19400         int strcoll(const char *s1, const char *s2);
19401         int strncmp(const char *s1, const char *s2, size_t n);
19402         size_t strxfrm(char * restrict s1,
19403              const char * restrict s2, size_t n);
19404         void *memchr(const void *s, int c, size_t n);
19405 [page 489]
19406
19407       char *strchr(const char *s, int c);
19408       size_t strcspn(const char *s1, const char *s2);
19409       char *strpbrk(const char *s1, const char *s2);
19410       char *strrchr(const char *s, int c);
19411       size_t strspn(const char *s1, const char *s2);
19412       char *strstr(const char *s1, const char *s2);
19413       char *strtok(char * restrict s1,
19414            const char * restrict s2);
19415       void *memset(void *s, int c, size_t n);
19416       char *strerror(int errnum);
19417       size_t strlen(const char *s);
19418       __STDC_WANT_LIB_EXT1__
19419       errno_t
19420       rsize_t
19421       errno_t memcpy_s(void * restrict s1, rsize_t s1max,
19422            const void * restrict s2, rsize_t n);
19423       errno_t memmove_s(void *s1, rsize_t s1max,
19424            const void *s2, rsize_t n);
19425       errno_t strcpy_s(char * restrict s1,
19426            rsize_t s1max,
19427            const char * restrict s2);
19428       errno_t strncpy_s(char * restrict s1,
19429            rsize_t s1max,
19430            const char * restrict s2,
19431            rsize_t n);
19432       errno_t strcat_s(char * restrict s1,
19433            rsize_t s1max,
19434            const char * restrict s2);
19435       errno_t strncat_s(char * restrict s1,
19436            rsize_t s1max,
19437            const char * restrict s2,
19438            rsize_t n);
19439       char *strtok_s(char * restrict s1,
19440            rsize_t * restrict s1max,
19441            const char * restrict s2,
19442            char ** restrict ptr);
19443       errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n)
19444       errno_t strerror_s(char *s, rsize_t maxsize,
19445            errno_t errnum);
19446       size_t strerrorlen_s(errno_t errnum);
19447
19448 [page 490]
19449
19450         size_t strnlen_s(const char *s, size_t maxsize);
19451 B.23 Type-generic math <tgmath.h>
19452         acos         sqrt              fmod             nextafter
19453         asin         fabs              frexp            nexttoward
19454         atan         atan2             hypot            remainder
19455         acosh        cbrt              ilogb            remquo
19456         asinh        ceil              ldexp            rint
19457         atanh        copysign          lgamma           round
19458         cos          erf               llrint           scalbn
19459         sin          erfc              llround          scalbln
19460         tan          exp2              log10            tgamma
19461         cosh         expm1             log1p            trunc
19462         sinh         fdim              log2             carg
19463         tanh         floor             logb             cimag
19464         exp          fma               lrint            conj
19465         log          fmax              lround           cproj
19466         pow          fmin              nearbyint        creal
19467 B.24 Threads <threads.h>
19468         ONCE_FLAG_INIT                 mtx_plain
19469         TSS_DTOR_ITERATIONS            mtx_recursive
19470         cnd_t                          mtx_timed
19471         thrd_t                         mtx_try
19472         tss_t                          thrd_timeout
19473         mtx_t                          thrd_success
19474         tss_dtor_t                     thrd_busy
19475         thrd_start_t                   thrd_error
19476         once_flag                      thrd_nomem
19477         xtime
19478       void call_once(once_flag *flag, void (*func)(void));
19479       int cnd_broadcast(cnd_t *cond);
19480       void cnd_destroy(cnd_t *cond);
19481       int cnd_init(cnd_t *cond);
19482       int cnd_signal(cnd_t *cond);
19483       int cnd_timedwait(cnd_t *cond, mtx_t *mtx,
19484            const xtime *xt);
19485       int cnd_wait(cnd_t *cond, mtx_t *mtx);
19486       void mtx_destroy(mtx_t *mtx);
19487       int mtx_init(mtx_t *mtx, int type);
19488       int mtx_lock(mtx_t *mtx);
19489 [page 491]
19490
19491       int mtx_timedlock(mtx_t *mtx, const xtime *xt);
19492       int mtx_trylock(mtx_t *mtx);
19493       int mtx_unlock(mtx_t *mtx);
19494       int thrd_create(thrd_t *thr, thrd_start_t func,
19495            void *arg);
19496       thrd_t thrd_current(void);
19497       int thrd_detach(thrd_t thr);
19498       int thrd_equal(thrd_t thr0, thrd_t thr1);
19499       void thrd_exit(int res);
19500       int thrd_join(thrd_t thr, int *res);
19501       void thrd_sleep(const xtime *xt);
19502       void thrd_yield(void);
19503       int tss_create(tss_t *key, tss_dtor_t dtor);
19504       void tss_delete(tss_t key);
19505       void *tss_get(tss_t key);
19506       int tss_set(tss_t key, void *val);
19507       int xtime_get(xtime *xt, int base);
19508 B.25 Date and time <time.h>
19509       NULL                  size_t                  time_t
19510       CLOCKS_PER_SEC        clock_t                 struct tm
19511       clock_t clock(void);
19512       double difftime(time_t time1, time_t time0);
19513       time_t mktime(struct tm *timeptr);
19514       time_t time(time_t *timer);
19515       char *asctime(const struct tm *timeptr);
19516       char *ctime(const time_t *timer);
19517       struct tm *gmtime(const time_t *timer);
19518       struct tm *localtime(const time_t *timer);
19519       size_t strftime(char * restrict s,
19520            size_t maxsize,
19521            const char * restrict format,
19522            const struct tm * restrict timeptr);
19523       __STDC_WANT_LIB_EXT1__
19524       errno_t
19525       rsize_t
19526       errno_t asctime_s(char *s, rsize_t maxsize,
19527            const struct tm *timeptr);
19528
19529
19530
19531 [page 492]
19532
19533         errno_t ctime_s(char *s, rsize_t maxsize,
19534              const time_t *timer);
19535         struct tm *gmtime_s(const time_t * restrict timer,
19536              struct tm * restrict result);
19537         struct tm *localtime_s(const time_t * restrict timer,
19538              struct tm * restrict result);
19539 B.26 Unicode utilities <uchar.h>
19540         mbstate_t     size_t            char16_t         char32_t
19541         size_t mbrtoc16(char16_t * restrict pc16,
19542              const char * restrict s, size_t n,
19543              mbstate_t * restrict ps);
19544         size_t c16rtomb(char * restrict s, char16_t c16,
19545              mbstate_t * restrict ps);
19546         size_t mbrtoc32(char32_t * restrict pc32,
19547              const char * restrict s, size_t n,
19548              mbstate_t * restrict ps);
19549         size_t c32rtomb(char * restrict s, char32_t c32,
19550              mbstate_t * restrict ps);
19551 B.27 Extended multibyte/wide character utilities <wchar.h>
19552         wchar_t             wint_t                  WCHAR_MAX
19553         size_t              struct tm               WCHAR_MIN
19554         mbstate_t           NULL                    WEOF
19555         int fwprintf(FILE * restrict stream,
19556              const wchar_t * restrict format, ...);
19557         int fwscanf(FILE * restrict stream,
19558              const wchar_t * restrict format, ...);
19559         int swprintf(wchar_t * restrict s, size_t n,
19560              const wchar_t * restrict format, ...);
19561         int swscanf(const wchar_t * restrict s,
19562              const wchar_t * restrict format, ...);
19563         int vfwprintf(FILE * restrict stream,
19564              const wchar_t * restrict format, va_list arg);
19565         int vfwscanf(FILE * restrict stream,
19566              const wchar_t * restrict format, va_list arg);
19567         int vswprintf(wchar_t * restrict s, size_t n,
19568              const wchar_t * restrict format, va_list arg);
19569
19570
19571
19572 [page 493]
19573
19574       int vswscanf(const wchar_t * restrict s,
19575            const wchar_t * restrict format, va_list arg);
19576       int vwprintf(const wchar_t * restrict format,
19577            va_list arg);
19578       int vwscanf(const wchar_t * restrict format,
19579            va_list arg);
19580       int wprintf(const wchar_t * restrict format, ...);
19581       int wscanf(const wchar_t * restrict format, ...);
19582       wint_t fgetwc(FILE *stream);
19583       wchar_t *fgetws(wchar_t * restrict s, int n,
19584            FILE * restrict stream);
19585       wint_t fputwc(wchar_t c, FILE *stream);
19586       int fputws(const wchar_t * restrict s,
19587            FILE * restrict stream);
19588       int fwide(FILE *stream, int mode);
19589       wint_t getwc(FILE *stream);
19590       wint_t getwchar(void);
19591       wint_t putwc(wchar_t c, FILE *stream);
19592       wint_t putwchar(wchar_t c);
19593       wint_t ungetwc(wint_t c, FILE *stream);
19594       double wcstod(const wchar_t * restrict nptr,
19595            wchar_t ** restrict endptr);
19596       float wcstof(const wchar_t * restrict nptr,
19597            wchar_t ** restrict endptr);
19598       long double wcstold(const wchar_t * restrict nptr,
19599            wchar_t ** restrict endptr);
19600       long int wcstol(const wchar_t * restrict nptr,
19601            wchar_t ** restrict endptr, int base);
19602       long long int wcstoll(const wchar_t * restrict nptr,
19603            wchar_t ** restrict endptr, int base);
19604       unsigned long int wcstoul(const wchar_t * restrict nptr,
19605            wchar_t ** restrict endptr, int base);
19606       unsigned long long int wcstoull(
19607            const wchar_t * restrict nptr,
19608            wchar_t ** restrict endptr, int base);
19609       wchar_t *wcscpy(wchar_t * restrict s1,
19610            const wchar_t * restrict s2);
19611       wchar_t *wcsncpy(wchar_t * restrict s1,
19612            const wchar_t * restrict s2, size_t n);
19613
19614
19615
19616 [page 494]
19617
19618         wchar_t *wmemcpy(wchar_t * restrict s1,
19619              const wchar_t * restrict s2, size_t n);
19620         wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2,
19621              size_t n);
19622         wchar_t *wcscat(wchar_t * restrict s1,
19623              const wchar_t * restrict s2);
19624         wchar_t *wcsncat(wchar_t * restrict s1,
19625              const wchar_t * restrict s2, size_t n);
19626         int wcscmp(const wchar_t *s1, const wchar_t *s2);
19627         int wcscoll(const wchar_t *s1, const wchar_t *s2);
19628         int wcsncmp(const wchar_t *s1, const wchar_t *s2,
19629              size_t n);
19630         size_t wcsxfrm(wchar_t * restrict s1,
19631              const wchar_t * restrict s2, size_t n);
19632         int wmemcmp(const wchar_t *s1, const wchar_t *s2,
19633              size_t n);
19634         wchar_t *wcschr(const wchar_t *s, wchar_t c);
19635         size_t wcscspn(const wchar_t *s1, const wchar_t *s2);
19636         wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2);
19637         wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
19638         size_t wcsspn(const wchar_t *s1, const wchar_t *s2);
19639         wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);
19640         wchar_t *wcstok(wchar_t * restrict s1,
19641              const wchar_t * restrict s2,
19642              wchar_t ** restrict ptr);
19643         wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n);
19644         size_t wcslen(const wchar_t *s);
19645         wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);
19646         size_t wcsftime(wchar_t * restrict s, size_t maxsize,
19647              const wchar_t * restrict format,
19648              const struct tm * restrict timeptr);
19649         wint_t btowc(int c);
19650         int wctob(wint_t c);
19651         int mbsinit(const mbstate_t *ps);
19652         size_t mbrlen(const char * restrict s, size_t n,
19653              mbstate_t * restrict ps);
19654         size_t mbrtowc(wchar_t * restrict pwc,
19655              const char * restrict s, size_t n,
19656              mbstate_t * restrict ps);
19657
19658
19659
19660 [page 495]
19661
19662       size_t wcrtomb(char * restrict s, wchar_t wc,
19663            mbstate_t * restrict ps);
19664       size_t mbsrtowcs(wchar_t * restrict dst,
19665            const char ** restrict src, size_t len,
19666            mbstate_t * restrict ps);
19667       size_t wcsrtombs(char * restrict dst,
19668            const wchar_t ** restrict src, size_t len,
19669            mbstate_t * restrict ps);
19670       __STDC_WANT_LIB_EXT1__
19671       errno_t
19672       rsize_t
19673       int fwprintf_s(FILE * restrict stream,
19674            const wchar_t * restrict format, ...);
19675       int fwscanf_s(FILE * restrict stream,
19676            const wchar_t * restrict format, ...);
19677       int snwprintf_s(wchar_t * restrict s,
19678            rsize_t n,
19679            const wchar_t * restrict format, ...);
19680       int swprintf_s(wchar_t * restrict s, rsize_t n,
19681            const wchar_t * restrict format, ...);
19682       int swscanf_s(const wchar_t * restrict s,
19683            const wchar_t * restrict format, ...);
19684       int vfwprintf_s(FILE * restrict stream,
19685            const wchar_t * restrict format,
19686            va_list arg);
19687       int vfwscanf_s(FILE * restrict stream,
19688            const wchar_t * restrict format, va_list arg);
19689       int vsnwprintf_s(wchar_t * restrict s,
19690            rsize_t n,
19691            const wchar_t * restrict format,
19692            va_list arg);
19693       int vswprintf_s(wchar_t * restrict s,
19694            rsize_t n,
19695            const wchar_t * restrict format,
19696            va_list arg);
19697       int vswscanf_s(const wchar_t * restrict s,
19698            const wchar_t * restrict format,
19699            va_list arg);
19700
19701
19702
19703 [page 496]
19704
19705         int vwprintf_s(const wchar_t * restrict format,
19706              va_list arg);
19707         int vwscanf_s(const wchar_t * restrict format,
19708              va_list arg);
19709         int wprintf_s(const wchar_t * restrict format, ...);
19710         int wscanf_s(const wchar_t * restrict format, ...);
19711         errno_t wcscpy_s(wchar_t * restrict s1,
19712              rsize_t s1max,
19713              const wchar_t * restrict s2);
19714         errno_t wcsncpy_s(wchar_t * restrict s1,
19715              rsize_t s1max,
19716              const wchar_t * restrict s2,
19717              rsize_t n);
19718         errno_t wmemcpy_s(wchar_t * restrict s1,
19719              rsize_t s1max,
19720              const wchar_t * restrict s2,
19721              rsize_t n);
19722         errno_t wmemmove_s(wchar_t *s1, rsize_t s1max,
19723              const wchar_t *s2, rsize_t n);
19724         errno_t wcscat_s(wchar_t * restrict s1,
19725              rsize_t s1max,
19726              const wchar_t * restrict s2);
19727         errno_t wcsncat_s(wchar_t * restrict s1,
19728              rsize_t s1max,
19729              const wchar_t * restrict s2,
19730              rsize_t n);
19731         wchar_t *wcstok_s(wchar_t * restrict s1,
19732              rsize_t * restrict s1max,
19733              const wchar_t * restrict s2,
19734              wchar_t ** restrict ptr);
19735         size_t wcsnlen_s(const wchar_t *s, size_t maxsize);
19736         errno_t wcrtomb_s(size_t * restrict retval,
19737              char * restrict s, rsize_t smax,
19738              wchar_t wc, mbstate_t * restrict ps);
19739         errno_t mbsrtowcs_s(size_t * restrict retval,
19740              wchar_t * restrict dst, rsize_t dstmax,
19741              const char ** restrict src, rsize_t len,
19742              mbstate_t * restrict ps);
19743
19744
19745
19746
19747 [page 497]
19748
19749       errno_t wcsrtombs_s(size_t * restrict retval,
19750            char * restrict dst, rsize_t dstmax,
19751            const wchar_t ** restrict src, rsize_t len,
19752            mbstate_t * restrict ps);
19753 B.28 Wide character classification and mapping utilities <wctype.h>
19754       wint_t          wctrans_t         wctype_t         WEOF
19755       int iswalnum(wint_t wc);
19756       int iswalpha(wint_t wc);
19757       int iswblank(wint_t wc);
19758       int iswcntrl(wint_t wc);
19759       int iswdigit(wint_t wc);
19760       int iswgraph(wint_t wc);
19761       int iswlower(wint_t wc);
19762       int iswprint(wint_t wc);
19763       int iswpunct(wint_t wc);
19764       int iswspace(wint_t wc);
19765       int iswupper(wint_t wc);
19766       int iswxdigit(wint_t wc);
19767       int iswctype(wint_t wc, wctype_t desc);
19768       wctype_t wctype(const char *property);
19769       wint_t towlower(wint_t wc);
19770       wint_t towupper(wint_t wc);
19771       wint_t towctrans(wint_t wc, wctrans_t desc);
19772       wctrans_t wctrans(const char *property);
19773
19774
19775
19776
19777 [page 498]
19778
19779                                           Annex C
19780                                         (informative)
19781                                       Sequence points
19782 1   The following are the sequence points described in 5.1.2.3:
19783     -- Between the evaluations of the function designator and actual arguments in a function
19784       call and the actual call. (6.5.2.2).
19785     -- Between the evaluations of the first and second operands of the following operators:
19786       logical AND && (6.5.13); logical OR || (6.5.14); comma , (6.5.17).                  *
19787     -- Between the evaluations of the first operand of the conditional ? : operator and
19788       whichever of the second and third operands is evaluated (6.5.15).
19789     -- The end of a full declarator: declarators (6.7.6);
19790     -- Between the evaluation of a full expression and the next full expression to be
19791       evaluated. The following are full expressions: an initializer that is not part of a
19792       compound literal (6.7.9); the expression in an expression statement (6.8.3); the
19793       controlling expression of a selection statement (if or switch) (6.8.4); the
19794       controlling expression of a while or do statement (6.8.5); each of the (optional)
19795       expressions of a for statement (6.8.5.3); the (optional) expression in a return
19796       statement (6.8.6.4).
19797     -- Immediately before a library function returns (7.1.4).
19798     -- After the actions associated with each formatted input/output function conversion
19799       specifier (7.21.6, 7.28.2).
19800     -- Immediately before and immediately after each call to a comparison function, and
19801       also between any call to a comparison function and any movement of the objects
19802       passed as arguments to that call (7.22.5).
19803
19804
19805
19806
19807 [page 499]
19808
19809                                          Annex D
19810                                         (normative)
19811                    Universal character names for identifiers
19812 1   This clause lists the hexadecimal code values that are valid in universal character names
19813     in identifiers.
19814     D.1 Ranges of characters allowed
19815 1   00A8, 00AA, 00AD, 00AF, 00B2-00B5, 00B7-00BA, 00BC-00BE, 00C0-00D6,
19816     00D8-00F6, 00F8-00FF
19817 2   0100-167F, 1681-180D, 180F-1FFF
19818 3   200B-200D, 202A-202E, 203F-2040, 2054, 2060-206F
19819 4   2070-218F, 2460-24FF, 2776-2793, 2C00-2DFF, 2E80-2FFF
19820 5   3004-3007, 3021-302F, 3031-303F
19821 6   3040-D7FF
19822 7   F900-FD3D, FD40-FDCF, FDF0-FE44, FE47-FFFD
19823 8   10000-1FFFD, 20000-2FFFD, 30000-3FFFD, 40000-4FFFD, 50000-5FFFD,
19824     60000-6FFFD, 70000-7FFFD, 80000-8FFFD, 90000-9FFFD, A0000-AFFFD,
19825     B0000-BFFFD, C0000-CFFFD, D0000-DFFFD, E0000-EFFFD
19826     D.2 Ranges of characters disallowed initially
19827 1   0300-036F, 1DC0-1DFF, 20D0-20FF, FE20-FE2F
19828
19829
19830
19831
19832 [page 500]
19833
19834                                          Annex E
19835                                        (informative)
19836                                 Implementation limits
19837 1   The contents of the header <limits.h> are given below, in alphabetical order. The
19838     minimum magnitudes shown shall be replaced by implementation-defined magnitudes
19839     with the same sign. The values shall all be constant expressions suitable for use in #if
19840     preprocessing directives. The components are described further in 5.2.4.2.1.
19841             #define    CHAR_BIT                               8
19842             #define    CHAR_MAX          UCHAR_MAX or SCHAR_MAX
19843             #define    CHAR_MIN                  0 or SCHAR_MIN
19844             #define    INT_MAX                           +32767
19845             #define    INT_MIN                           -32767
19846             #define    LONG_MAX                     +2147483647
19847             #define    LONG_MIN                     -2147483647
19848             #define    LLONG_MAX           +9223372036854775807
19849             #define    LLONG_MIN           -9223372036854775807
19850             #define    MB_LEN_MAX                             1
19851             #define    SCHAR_MAX                           +127
19852             #define    SCHAR_MIN                           -127
19853             #define    SHRT_MAX                          +32767
19854             #define    SHRT_MIN                          -32767
19855             #define    UCHAR_MAX                            255
19856             #define    USHRT_MAX                          65535
19857             #define    UINT_MAX                           65535
19858             #define    ULONG_MAX                     4294967295
19859             #define    ULLONG_MAX          18446744073709551615
19860 2   The contents of the header <float.h> are given below. All integer values, except
19861     FLT_ROUNDS, shall be constant expressions suitable for use in #if preprocessing
19862     directives; all floating values shall be constant expressions. The components are
19863     described further in 5.2.4.2.2.
19864 3   The values given in the following list shall be replaced by implementation-defined
19865     expressions:
19866             #define FLT_EVAL_METHOD
19867             #define FLT_ROUNDS
19868 4   The values given in the following list shall be replaced by implementation-defined
19869     constant expressions that are greater or equal in magnitude (absolute value) to those
19870     shown, with the same sign:
19871 [page 501]
19872
19873            #define    DLB_DECIMAL_DIG                                10
19874            #define    DBL_DIG                                        10
19875            #define    DBL_MANT_DIG
19876            #define    DBL_MAX_10_EXP                               +37
19877            #define    DBL_MAX_EXP
19878            #define    DBL_MIN_10_EXP                               -37
19879            #define    DBL_MIN_EXP
19880            #define    DECIMAL_DIG                                    10
19881            #define    FLT_DECIMAL_DIG                                 6
19882            #define    FLT_DIG                                         6
19883            #define    FLT_MANT_DIG
19884            #define    FLT_MAX_10_EXP                               +37
19885            #define    FLT_MAX_EXP
19886            #define    FLT_MIN_10_EXP                               -37
19887            #define    FLT_MIN_EXP
19888            #define    FLT_RADIX                                       2
19889            #define    LDLB_DECIMAL_DIG                               10
19890            #define    LDBL_DIG                                       10
19891            #define    LDBL_MANT_DIG
19892            #define    LDBL_MAX_10_EXP                              +37
19893            #define    LDBL_MAX_EXP
19894            #define    LDBL_MIN_10_EXP                              -37
19895            #define    LDBL_MIN_EXP
19896 5   The values given in the following list shall be replaced by implementation-defined
19897     constant expressions with values that are greater than or equal to those shown:
19898            #define DBL_MAX                                      1E+37
19899            #define FLT_MAX                                      1E+37
19900            #define LDBL_MAX                                     1E+37
19901 6   The values given in the following list shall be replaced by implementation-defined
19902     constant expressions with (positive) values that are less than or equal to those shown:
19903            #define    DBL_EPSILON                                1E-9
19904            #define    DBL_MIN                                   1E-37
19905            #define    FLT_EPSILON                                1E-5
19906            #define    FLT_MIN                                   1E-37
19907            #define    LDBL_EPSILON                               1E-9
19908            #define    LDBL_MIN                                  1E-37
19909
19910
19911
19912
19913 [page 502]
19914
19915                                                Annex F
19916                                               (normative)
19917                           IEC 60559 floating-point arithmetic
19918     F.1 Introduction
19919 1   This annex specifies C language support for the IEC 60559 floating-point standard. The
19920     IEC 60559 floating-point standard is specifically Binary floating-point arithmetic for
19921     microprocessor systems, second edition (IEC 60559:1989), previously designated
19922     IEC 559:1989 and as IEEE Standard for Binary Floating-Point Arithmetic
19923     (ANSI/IEEE 754-1985). IEEE Standard for Radix-Independent Floating-Point
19924     Arithmetic (ANSI/IEEE 854-1987) generalizes the binary standard to remove
19925     dependencies on radix and word length. IEC 60559 generally refers to the floating-point
19926     standard, as in IEC 60559 operation, IEC 60559 format, etc. An implementation that
19927     defines __STDC_IEC_559__ shall conform to the specifications in this annex.343)
19928     Where a binding between the C language and IEC 60559 is indicated, the
19929     IEC 60559-specified behavior is adopted by reference, unless stated otherwise. Since
19930     negative and positive infinity are representable in IEC 60559 formats, all real numbers lie
19931     within the range of representable values.
19932     F.2 Types
19933 1   The C floating types match the IEC 60559 formats as follows:
19934     -- The float type matches the IEC 60559 single format.
19935     -- The double type matches the IEC 60559 double format.
19936     -- The long double type matches an IEC 60559 extended format,344) else a
19937       non-IEC 60559 extended format, else the IEC 60559 double format.
19938     Any non-IEC 60559 extended format used for the long double type shall have more
19939     precision than IEC 60559 double and at least the range of IEC 60559 double.345)
19940
19941
19942
19943
19944     343) Implementations that do not define __STDC_IEC_559__ are not required to conform to these
19945          specifications.
19946     344) ''Extended'' is IEC 60559's double-extended data format. Extended refers to both the common 80-bit
19947          and quadruple 128-bit IEC 60559 formats.
19948     345) A non-IEC 60559 long double type is required to provide infinity and NaNs, as its values include
19949          all double values.
19950
19951 [page 503]
19952
19953     Recommended practice
19954 2   The long double type should match an IEC 60559 extended format.
19955     F.2.1 Infinities, signed zeros, and NaNs
19956 1   This specification does not define the behavior of signaling NaNs.346) It generally uses
19957     the term NaN to denote quiet NaNs. The NAN and INFINITY macros and the nan
19958     functions in <math.h> provide designations for IEC 60559 NaNs and infinities.
19959     F.3 Operators and functions
19960 1   C operators and functions provide IEC 60559 required and recommended facilities as
19961     listed below.
19962     -- The +, -, *, and / operators provide the IEC 60559 add, subtract, multiply, and
19963       divide operations.
19964     -- The sqrt functions in <math.h> provide the IEC 60559 square root operation.
19965     -- The remainder functions in <math.h> provide the IEC 60559 remainder
19966       operation. The remquo functions in <math.h> provide the same operation but
19967       with additional information.
19968     -- The rint functions in <math.h> provide the IEC 60559 operation that rounds a
19969       floating-point number to an integer value (in the same precision). The nearbyint
19970       functions in <math.h> provide the nearbyinteger function recommended in the
19971       Appendix to ANSI/IEEE 854.
19972     -- The conversions for floating types provide the IEC 60559 conversions between
19973       floating-point precisions.
19974     -- The conversions from integer to floating types provide the IEC 60559 conversions
19975       from integer to floating point.
19976     -- The conversions from floating to integer types provide IEC 60559-like conversions
19977       but always round toward zero.
19978     -- The lrint and llrint functions in <math.h> provide the IEC 60559
19979       conversions, which honor the directed rounding mode, from floating point to the
19980       long int and long long int integer formats. The lrint and llrint
19981       functions can be used to implement IEC 60559 conversions from floating to other
19982       integer formats.
19983     -- The translation time conversion of floating constants and the strtod, strtof,
19984       strtold, fprintf, fscanf, and related library functions in <stdlib.h>,
19985
19986
19987     346) Since NaNs created by IEC 60559 operations are always quiet, quiet NaNs (along with infinities) are
19988          sufficient for closure of the arithmetic.
19989
19990 [page 504]
19991
19992    <stdio.h>, and <wchar.h> provide IEC 60559 binary-decimal conversions. The
19993    strtold function in <stdlib.h> provides the conv function recommended in the
19994    Appendix to ANSI/IEEE 854.
19995 -- The relational and equality operators provide IEC 60559 comparisons. IEC 60559
19996   identifies a need for additional comparison predicates to facilitate writing code that
19997   accounts for NaNs. The comparison macros (isgreater, isgreaterequal,
19998   isless, islessequal, islessgreater, and isunordered) in <math.h>
19999   supplement the language operators to address this need. The islessgreater and
20000   isunordered macros provide respectively a quiet version of the <> predicate and
20001   the unordered predicate recommended in the Appendix to IEC 60559.
20002 -- The feclearexcept, feraiseexcept, and fetestexcept functions in
20003   <fenv.h> provide the facility to test and alter the IEC 60559 floating-point
20004   exception status flags. The fegetexceptflag and fesetexceptflag
20005   functions in <fenv.h> provide the facility to save and restore all five status flags at
20006   one time. These functions are used in conjunction with the type fexcept_t and the
20007   floating-point     exception      macros      (FE_INEXACT,         FE_DIVBYZERO,
20008   FE_UNDERFLOW, FE_OVERFLOW, FE_INVALID) also in <fenv.h>.
20009 -- The fegetround and fesetround functions in <fenv.h> provide the facility
20010   to select among the IEC 60559 directed rounding modes represented by the rounding
20011   direction macros in <fenv.h> (FE_TONEAREST, FE_UPWARD, FE_DOWNWARD,
20012   FE_TOWARDZERO) and the values 0, 1, 2, and 3 of FLT_ROUNDS are the
20013   IEC 60559 directed rounding modes.
20014 -- The fegetenv, feholdexcept, fesetenv, and feupdateenv functions in
20015   <fenv.h> provide a facility to manage the floating-point environment, comprising
20016   the IEC 60559 status flags and control modes.
20017 -- The copysign functions in <math.h> provide the copysign function
20018   recommended in the Appendix to IEC 60559.
20019 -- The fabs functions in <math.h> provide the abs function recommended in the
20020   Appendix to IEC 60559.
20021 -- The unary minus (-) operator provides the unary minus (-) operation recommended
20022   in the Appendix to IEC 60559.
20023 -- The scalbn and scalbln functions in <math.h> provide the scalb function
20024   recommended in the Appendix to IEC 60559.
20025 -- The logb functions in <math.h> provide the logb function recommended in the
20026   Appendix to IEC 60559, but following the newer specifications in ANSI/IEEE 854.
20027 -- The nextafter and nexttoward functions in <math.h> provide the nextafter
20028   function recommended in the Appendix to IEC 60559 (but with a minor change to
20029
20030 [page 505]
20031
20032         better handle signed zeros).
20033     -- The isfinite macro in <math.h> provides the finite function recommended in
20034       the Appendix to IEC 60559.
20035     -- The isnan macro in <math.h> provides the isnan function recommended in the
20036       Appendix to IEC 60559.
20037     -- The signbit macro and the fpclassify macro in <math.h>, used in
20038       conjunction with the number classification macros (FP_NAN, FP_INFINITE,
20039       FP_NORMAL, FP_SUBNORMAL, FP_ZERO), provide the facility of the class
20040       function recommended in the Appendix to IEC 60559 (except that the classification
20041       macros defined in 7.12.3 do not distinguish signaling from quiet NaNs).
20042     F.4 Floating to integer conversion
20043 1   If the integer type is _Bool, 6.3.1.2 applies and no floating-point exceptions are raised
20044     (even for NaN). Otherwise, if the floating value is infinite or NaN or if the integral part
20045     of the floating value exceeds the range of the integer type, then the ''invalid'' floating-
20046     point exception is raised and the resulting value is unspecified. Otherwise, the resulting
20047     value is determined by 6.3.1.4. Conversion of an integral floating value that does not
20048     exceed the range of the integer type raises no floating-point exceptions; whether
20049     conversion of a non-integral floating value raises the ''inexact'' floating-point exception is
20050     unspecified.347)
20051     F.5 Binary-decimal conversion
20052 1   Conversion from the widest supported IEC 60559 format to decimal with
20053     DECIMAL_DIG digits and back is the identity function.348)
20054 2   Conversions involving IEC 60559 formats follow all pertinent recommended practice. In
20055     particular, conversion between any supported IEC 60559 format and decimal with
20056     DECIMAL_DIG or fewer significant digits is correctly rounded (honoring the current
20057     rounding mode), which assures that conversion from the widest supported IEC 60559
20058     format to decimal with DECIMAL_DIG digits and back is the identity function.
20059
20060
20061
20062     347) ANSI/IEEE 854, but not IEC 60559 (ANSI/IEEE 754), directly specifies that floating-to-integer
20063          conversions raise the ''inexact'' floating-point exception for non-integer in-range values. In those
20064          cases where it matters, library functions can be used to effect such conversions with or without raising
20065          the ''inexact'' floating-point exception. See rint, lrint, llrint, and nearbyint in
20066          <math.h>.
20067     348) If the minimum-width IEC 60559 extended format (64 bits of precision) is supported,
20068          DECIMAL_DIG shall be at least 21. If IEC 60559 double (53 bits of precision) is the widest
20069          IEC 60559 format supported, then DECIMAL_DIG shall be at least 17. (By contrast, LDBL_DIG and
20070          DBL_DIG are 18 and 15, respectively, for these formats.)
20071
20072 [page 506]
20073
20074 3   Functions such as strtod that convert character sequences to floating types honor the
20075     rounding direction. Hence, if the rounding direction might be upward or downward, the
20076     implementation cannot convert a minus-signed sequence by negating the converted
20077     unsigned sequence.
20078     F.6 The return statement
20079     If the return expression is evaluated in a floating-point format different from the return
20080     type, the expression is converted as if by assignment349) to the return type of the function
20081     and the resulting value is returned to the caller.
20082     F.7 Contracted expressions
20083 1   A contracted expression is correctly rounded (once) and treats infinities, NaNs, signed
20084     zeros, subnormals, and the rounding directions in a manner consistent with the basic
20085     arithmetic operations covered by IEC 60559.
20086     Recommended practice
20087 2   A contracted expression should raise floating-point exceptions in a manner generally
20088     consistent with the basic arithmetic operations.                                    *
20089     F.8 Floating-point environment
20090 1   The floating-point environment defined in <fenv.h> includes the IEC 60559 floating-
20091     point exception status flags and directed-rounding control modes. It includes also
20092     IEC 60559 dynamic rounding precision and trap enablement modes, if the
20093     implementation supports them.350)
20094     F.8.1 Environment management
20095 1   IEC 60559 requires that floating-point operations implicitly raise floating-point exception
20096     status flags, and that rounding control modes can be set explicitly to affect result values of
20097     floating-point operations. When the state for the FENV_ACCESS pragma (defined in
20098     <fenv.h>) is ''on'', these changes to the floating-point state are treated as side effects
20099     which respect sequence points.351)
20100
20101
20102
20103
20104     349) Assignment removes any extra range and precision.
20105     350) This specification does not require dynamic rounding precision nor trap enablement modes.
20106     351) If the state for the FENV_ACCESS pragma is ''off'', the implementation is free to assume the floating-
20107          point control modes will be the default ones and the floating-point status flags will not be tested,
20108          which allows certain optimizations (see F.9).
20109
20110 [page 507]
20111
20112     F.8.2 Translation
20113 1   During translation the IEC 60559 default modes are in effect:
20114     -- The rounding direction mode is rounding to nearest.
20115     -- The rounding precision mode (if supported) is set so that results are not shortened.
20116     -- Trapping or stopping (if supported) is disabled on all floating-point exceptions.
20117     Recommended practice
20118 2   The implementation should produce a diagnostic message for each translation-time
20119     floating-point exception, other than ''inexact'';352) the implementation should then
20120     proceed with the translation of the program.
20121     F.8.3 Execution
20122 1   At program startup the floating-point environment is initialized as prescribed by
20123     IEC 60559:
20124     -- All floating-point exception status flags are cleared.
20125     -- The rounding direction mode is rounding to nearest.
20126     -- The dynamic rounding precision mode (if supported) is set so that results are not
20127       shortened.
20128     -- Trapping or stopping (if supported) is disabled on all floating-point exceptions.
20129     F.8.4 Constant expressions
20130 1   An arithmetic constant expression of floating type, other than one in an initializer for an
20131     object that has static or thread storage duration, is evaluated (as if) during execution; thus,
20132     it is affected by any operative floating-point control modes and raises floating-point
20133     exceptions as required by IEC 60559 (provided the state for the FENV_ACCESS pragma
20134     is ''on'').353)
20135 2   EXAMPLE
20136
20137
20138
20139     352) As floating constants are converted to appropriate internal representations at translation time, their
20140          conversion is subject to default rounding modes and raises no execution-time floating-point exceptions
20141          (even where the state of the FENV_ACCESS pragma is ''on''). Library functions, for example
20142          strtod, provide execution-time conversion of numeric strings.
20143     353) Where the state for the FENV_ACCESS pragma is ''on'', results of inexact expressions like 1.0/3.0
20144          are affected by rounding modes set at execution time, and expressions such as 0.0/0.0 and
20145          1.0/0.0 generate execution-time floating-point exceptions. The programmer can achieve the
20146          efficiency of translation-time evaluation through static initialization, such as
20147                   const static double one_third = 1.0/3.0;
20148
20149
20150 [page 508]
20151
20152              #include <fenv.h>
20153              #pragma STDC FENV_ACCESS ON
20154              void f(void)
20155              {
20156                    float w[] = { 0.0/0.0 };                  //   raises an exception
20157                    static float x = 0.0/0.0;                 //   does not raise an exception
20158                    float y = 0.0/0.0;                        //   raises an exception
20159                    double z = 0.0/0.0;                       //   raises an exception
20160                    /* ... */
20161              }
20162 3   For the static initialization, the division is done at translation time, raising no (execution-time) floating-
20163     point exceptions. On the other hand, for the three automatic initializations the invalid division occurs at
20164     execution time.
20165
20166     F.8.5 Initialization
20167 1   All computation for automatic initialization is done (as if) at execution time; thus, it is
20168     affected by any operative modes and raises floating-point exceptions as required by
20169     IEC 60559 (provided the state for the FENV_ACCESS pragma is ''on''). All computation
20170     for initialization of objects that have static or thread storage duration is done (as if) at
20171     translation time.
20172 2   EXAMPLE
20173              #include <fenv.h>
20174              #pragma STDC FENV_ACCESS ON
20175              void f(void)
20176              {
20177                    float u[] = { 1.1e75 };                  //   raises exceptions
20178                    static float v = 1.1e75;                 //   does not raise exceptions
20179                    float w = 1.1e75;                        //   raises exceptions
20180                    double x = 1.1e75;                       //   may raise exceptions
20181                    float y = 1.1e75f;                       //   may raise exceptions
20182                    long double z = 1.1e75;                  //   does not raise exceptions
20183                    /* ... */
20184              }
20185 3   The static initialization of v raises no (execution-time) floating-point exceptions because its computation is
20186     done at translation time. The automatic initialization of u and w require an execution-time conversion to
20187     float of the wider value 1.1e75, which raises floating-point exceptions. The automatic initializations
20188     of x and y entail execution-time conversion; however, in some expression evaluation methods, the
20189     conversions is not to a narrower format, in which case no floating-point exception is raised.354) The
20190     automatic initialization of z entails execution-time conversion, but not to a narrower format, so no floating-
20191     point exception is raised. Note that the conversions of the floating constants 1.1e75 and 1.1e75f to
20192
20193
20194
20195     354) Use of float_t and double_t variables increases the likelihood of translation-time computation.
20196          For example, the automatic initialization
20197                   double_t x = 1.1e75;
20198          could be done at translation time, regardless of the expression evaluation method.
20199
20200 [page 509]
20201
20202     their internal representations occur at translation time in all cases.
20203
20204     F.8.6 Changing the environment
20205 1   Operations defined in 6.5 and functions and macros defined for the standard libraries
20206     change floating-point status flags and control modes just as indicated by their
20207     specifications (including conformance to IEC 60559). They do not change flags or modes
20208     (so as to be detectable by the user) in any other cases.
20209 2   If the argument to the feraiseexcept function in <fenv.h> represents IEC 60559
20210     valid coincident floating-point exceptions for atomic operations (namely ''overflow'' and
20211     ''inexact'', or ''underflow'' and ''inexact''), then ''overflow'' or ''underflow'' is raised
20212     before ''inexact''.
20213     F.9 Optimization
20214 1   This section identifies code transformations that might subvert IEC 60559-specified
20215     behavior, and others that do not.
20216     F.9.1 Global transformations
20217 1   Floating-point arithmetic operations and external function calls may entail side effects
20218     which optimization shall honor, at least where the state of the FENV_ACCESS pragma is
20219     ''on''. The flags and modes in the floating-point environment may be regarded as global
20220     variables; floating-point operations (+, *, etc.) implicitly read the modes and write the
20221     flags.
20222 2   Concern about side effects may inhibit code motion and removal of seemingly useless
20223     code. For example, in
20224              #include <fenv.h>
20225              #pragma STDC FENV_ACCESS ON
20226              void f(double x)
20227              {
20228                   /* ... */
20229                   for (i = 0; i < n; i++) x + 1;
20230                   /* ... */
20231              }
20232     x + 1 might raise floating-point exceptions, so cannot be removed. And since the loop
20233     body might not execute (maybe 0 >= n), x + 1 cannot be moved out of the loop. (Of
20234     course these optimizations are valid if the implementation can rule out the nettlesome
20235     cases.)
20236 3   This specification does not require support for trap handlers that maintain information
20237     about the order or count of floating-point exceptions. Therefore, between function calls,
20238     floating-point exceptions need not be precise: the actual order and number of occurrences
20239     of floating-point exceptions (> 1) may vary from what the source code expresses. Thus,
20240 [page 510]
20241
20242     the preceding loop could be treated as
20243              if (0 < n) x + 1;
20244     F.9.2 Expression transformations
20245 1   x/2 (<->) x x 0.5          Although similar transformations involving inexact constants
20246                            generally do not yield numerically equivalent expressions, if the
20247                            constants are exact then such transformations can be made on
20248                            IEC 60559 machines and others that round perfectly.
20249     1 x x and x/1 (->) x The expressions 1 x x, x/1, and x are equivalent (on IEC 60559
20250                       machines, among others).355)
20251     x/x (->) 1.0             The expressions x/x and 1.0 are not equivalent if x can be zero,
20252                            infinite, or NaN.
20253     x - y (<->) x + (-y)       The expressions x - y, x + (-y), and (-y) + x are equivalent (on
20254                            IEC 60559 machines, among others).
20255     x - y (<->) -(y - x)       The expressions x - y and -(y - x) are not equivalent because 1 - 1
20256                            is +0 but -(1 - 1) is -0 (in the default rounding direction).356)
20257     x - x (->) 0.0           The expressions x - x and 0.0 are not equivalent if x is a NaN or
20258                            infinite.
20259     0 x x (->) 0.0           The expressions 0 x x and 0.0 are not equivalent if x is a NaN,
20260                            infinite, or -0.
20261     x+0(->) x                 The expressions x + 0 and x are not equivalent if x is -0, because
20262                            (-0) + (+0) yields +0 (in the default rounding direction), not -0.
20263     x-0(->) x                 (+0) - (+0) yields -0 when rounding is downward (toward -(inf)), but
20264                            +0 otherwise, and (-0) - (+0) always yields -0; so, if the state of the
20265                            FENV_ACCESS pragma is ''off'', promising default rounding, then
20266                            the implementation can replace x - 0 by x, even if x might be zero.
20267     -x (<->) 0 - x             The expressions -x and 0 - x are not equivalent if x is +0, because
20268                            -(+0) yields -0, but 0 - (+0) yields +0 (unless rounding is
20269                            downward).
20270
20271     355) Strict support for signaling NaNs -- not required by this specification -- would invalidate these and
20272          other transformations that remove arithmetic operators.
20273     356) IEC 60559 prescribes a signed zero to preserve mathematical identities across certain discontinuities.
20274          Examples include:
20275             1/(1/ (+-) (inf)) is (+-) (inf)
20276          and
20277             conj(csqrt(z)) is csqrt(conj(z)),
20278          for complex z.
20279
20280 [page 511]
20281
20282     F.9.3 Relational operators
20283 1   x != x (->) false           The expression x != x is true if x is a NaN.
20284     x = x (->) true            The expression x = x is false if x is a NaN.
20285     x < y (->) isless(x,y) (and similarly for <=, >, >=) Though numerically equal, these
20286                    expressions are not equivalent because of side effects when x or y is a
20287                    NaN and the state of the FENV_ACCESS pragma is ''on''. This
20288                    transformation, which would be desirable if extra code were required
20289                    to cause the ''invalid'' floating-point exception for unordered cases,
20290                    could be performed provided the state of the FENV_ACCESS pragma
20291                    is ''off''.
20292     The sense of relational operators shall be maintained. This includes handling unordered
20293     cases as expressed by the source code.
20294 2   EXAMPLE
20295              // calls g and raises ''invalid'' if a and b are unordered
20296              if (a < b)
20297                      f();
20298              else
20299                      g();
20300     is not equivalent to
20301              // calls f and raises ''invalid'' if a and b are unordered
20302              if (a >= b)
20303                      g();
20304              else
20305                      f();
20306     nor to
20307              // calls f without raising ''invalid'' if a and b are unordered
20308              if (isgreaterequal(a,b))
20309                      g();
20310              else
20311                      f();
20312     nor, unless the state of the FENV_ACCESS pragma is ''off'', to
20313              // calls g without raising ''invalid'' if a and b are unordered
20314              if (isless(a,b))
20315                      f();
20316              else
20317                      g();
20318     but is equivalent to
20319
20320
20321
20322
20323 [page 512]
20324
20325             if (!(a < b))
20326                   g();
20327             else
20328                   f();
20329
20330     F.9.4 Constant arithmetic
20331 1   The implementation shall honor floating-point exceptions raised by execution-time
20332     constant arithmetic wherever the state of the FENV_ACCESS pragma is ''on''. (See F.8.4
20333     and F.8.5.) An operation on constants that raises no floating-point exception can be
20334     folded during translation, except, if the state of the FENV_ACCESS pragma is ''on'', a
20335     further check is required to assure that changing the rounding direction to downward does
20336     not alter the sign of the result,357) and implementations that support dynamic rounding
20337     precision modes shall assure further that the result of the operation raises no floating-
20338     point exception when converted to the semantic type of the operation.
20339     F.10 Mathematics <math.h>
20340 1   This subclause contains specifications of <math.h> facilities that are particularly suited
20341     for IEC 60559 implementations.
20342 2   The Standard C macro HUGE_VAL and its float and long double analogs,
20343     HUGE_VALF and HUGE_VALL, expand to expressions whose values are positive
20344     infinities.
20345 3   Special cases for functions in <math.h> are covered directly or indirectly by
20346     IEC 60559. The functions that IEC 60559 specifies directly are identified in F.3. The
20347     other functions in <math.h> treat infinities, NaNs, signed zeros, subnormals, and
20348     (provided the state of the FENV_ACCESS pragma is ''on'') the floating-point status flags
20349     in a manner consistent with the basic arithmetic operations covered by IEC 60559.
20350 4   The expression math_errhandling & MATH_ERREXCEPT shall evaluate to a
20351     nonzero value.
20352 5   The ''invalid'' and ''divide-by-zero'' floating-point exceptions are raised as specified in
20353     subsequent subclauses of this annex.
20354 6   The ''overflow'' floating-point exception is raised whenever an infinity -- or, because of
20355     rounding direction, a maximal-magnitude finite number -- is returned in lieu of a value
20356     whose magnitude is too large.
20357 7   The ''underflow'' floating-point exception is raised whenever a result is tiny (essentially
20358     subnormal or zero) and suffers loss of accuracy.358)
20359
20360
20361     357) 0 - 0 yields -0 instead of +0 just when the rounding direction is downward.
20362     358) IEC 60559 allows different definitions of underflow. They all result in the same values, but differ on
20363          when the floating-point exception is raised.
20364
20365 [page 513]
20366
20367 8    Whether or when library functions raise the ''inexact'' floating-point exception is
20368      unspecified, unless explicitly specified otherwise.
20369 9    Whether or when library functions raise an undeserved ''underflow'' floating-point
20370      exception is unspecified.359) Otherwise, as implied by F.8.6, the <math.h> functions do
20371      not raise spurious floating-point exceptions (detectable by the user), other than the
20372      ''inexact'' floating-point exception.
20373 10   Whether the functions honor the rounding direction mode is implementation-defined,
20374      unless explicitly specified otherwise.
20375 11   Functions with a NaN argument return a NaN result and raise no floating-point exception,
20376      except where stated otherwise.
20377 12   The specifications in the following subclauses append to the definitions in <math.h>.
20378      For families of functions, the specifications apply to all of the functions even though only
20379      the principal function is shown. Unless otherwise specified, where the symbol ''(+-)''
20380      occurs in both an argument and the result, the result has the same sign as the argument.
20381      Recommended practice
20382 13   If a function with one or more NaN arguments returns a NaN result, the result should be
20383      the same as one of the NaN arguments (after possible type conversion), except perhaps
20384      for the sign.
20385      F.10.1 Trigonometric functions
20386      F.10.1.1 The acos functions
20387 1    -- acos(1) returns +0.
20388      -- acos(x) returns a NaN and raises the ''invalid'' floating-point exception for
20389        | x | > 1.
20390      F.10.1.2 The asin functions
20391 1    -- asin((+-)0) returns (+-)0.
20392      -- asin(x) returns a NaN and raises the ''invalid'' floating-point exception for
20393        | x | > 1.
20394
20395
20396
20397
20398      359) It is intended that undeserved ''underflow'' and ''inexact'' floating-point exceptions are raised only if
20399           avoiding them would be too costly.
20400
20401 [page 514]
20402
20403     F.10.1.3 The atan functions
20404 1   -- atan((+-)0) returns (+-)0.
20405     -- atan((+-)(inf)) returns (+-)pi /2.
20406     F.10.1.4 The atan2 functions
20407 1   -- atan2((+-)0, -0) returns (+-)pi .360)
20408     -- atan2((+-)0, +0) returns (+-)0.
20409     -- atan2((+-)0, x) returns (+-)pi for x < 0.
20410     -- atan2((+-)0, x) returns (+-)0 for x > 0.
20411     -- atan2(y, (+-)0) returns -pi /2 for y < 0.
20412     -- atan2(y, (+-)0) returns pi /2 for y > 0.
20413     -- atan2((+-)y, -(inf)) returns (+-)pi for finite y > 0.
20414     -- atan2((+-)y, +(inf)) returns (+-)0 for finite y > 0.
20415     -- atan2((+-)(inf), x) returns (+-)pi /2 for finite x.
20416     -- atan2((+-)(inf), -(inf)) returns (+-)3pi /4.
20417     -- atan2((+-)(inf), +(inf)) returns (+-)pi /4.
20418     F.10.1.5 The cos functions
20419 1   -- cos((+-)0) returns 1.
20420     -- cos((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
20421     F.10.1.6 The sin functions
20422 1   -- sin((+-)0) returns (+-)0.
20423     -- sin((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
20424     F.10.1.7 The tan functions
20425 1   -- tan((+-)0) returns (+-)0.
20426     -- tan((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
20427
20428
20429
20430
20431     360) atan2(0, 0) does not raise the ''invalid'' floating-point exception, nor does atan2( y , 0) raise
20432          the ''divide-by-zero'' floating-point exception.
20433
20434 [page 515]
20435
20436     F.10.2 Hyperbolic functions
20437     F.10.2.1 The acosh functions
20438 1   -- acosh(1) returns +0.
20439     -- acosh(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 1.
20440     -- acosh(+(inf)) returns +(inf).
20441     F.10.2.2 The asinh functions
20442 1   -- asinh((+-)0) returns (+-)0.
20443     -- asinh((+-)(inf)) returns (+-)(inf).
20444     F.10.2.3 The atanh functions
20445 1   -- atanh((+-)0) returns (+-)0.
20446     -- atanh((+-)1) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception.
20447     -- atanh(x) returns a NaN and raises the ''invalid'' floating-point exception for
20448       | x | > 1.
20449     F.10.2.4 The cosh functions
20450 1   -- cosh((+-)0) returns 1.
20451     -- cosh((+-)(inf)) returns +(inf).
20452     F.10.2.5 The sinh functions
20453 1   -- sinh((+-)0) returns (+-)0.
20454     -- sinh((+-)(inf)) returns (+-)(inf).
20455     F.10.2.6 The tanh functions
20456 1   -- tanh((+-)0) returns (+-)0.
20457     -- tanh((+-)(inf)) returns (+-)1.
20458     F.10.3 Exponential and logarithmic functions
20459     F.10.3.1 The exp functions
20460 1   -- exp((+-)0) returns 1.
20461     -- exp(-(inf)) returns +0.
20462     -- exp(+(inf)) returns +(inf).
20463
20464
20465
20466
20467 [page 516]
20468
20469     F.10.3.2 The exp2 functions
20470 1   -- exp2((+-)0) returns 1.
20471     -- exp2(-(inf)) returns +0.
20472     -- exp2(+(inf)) returns +(inf).
20473     F.10.3.3 The expm1 functions
20474 1   -- expm1((+-)0) returns (+-)0.
20475     -- expm1(-(inf)) returns -1.
20476     -- expm1(+(inf)) returns +(inf).
20477     F.10.3.4 The frexp functions
20478 1   -- frexp((+-)0, exp) returns (+-)0, and stores 0 in the object pointed to by exp.
20479     -- frexp((+-)(inf), exp) returns (+-)(inf), and stores an unspecified value in the object
20480       pointed to by exp.
20481     -- frexp(NaN, exp) stores an unspecified value in the object pointed to by exp
20482       (and returns a NaN).
20483 2   frexp raises no floating-point exceptions.
20484 3   When the radix of the argument is a power of 2, the returned value is exact and is
20485     independent of the current rounding direction mode.
20486 4   On a binary system, the body of the frexp function might be
20487             {
20488                    *exp = (value == 0) ? 0 : (int)(1 + logb(value));
20489                    return scalbn(value, -(*exp));
20490             }
20491     F.10.3.5 The ilogb functions
20492 1   When the correct result is representable in the range of the return type, the returned value
20493     is exact and is independent of the current rounding direction mode.
20494 2   If the correct result is outside the range of the return type, the numeric result is
20495     unspecified and the ''invalid'' floating-point exception is raised.
20496
20497
20498
20499
20500 [page 517]
20501
20502     F.10.3.6 The ldexp functions
20503 1   On a binary system, ldexp(x, exp) is equivalent to scalbn(x, exp).
20504     F.10.3.7 The log functions
20505 1   -- log((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
20506     -- log(1) returns +0.
20507     -- log(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
20508     -- log(+(inf)) returns +(inf).
20509     F.10.3.8 The log10 functions
20510 1   -- log10((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
20511     -- log10(1) returns +0.
20512     -- log10(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
20513     -- log10(+(inf)) returns +(inf).
20514     F.10.3.9 The log1p functions
20515 1   -- log1p((+-)0) returns (+-)0.
20516     -- log1p(-1) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
20517     -- log1p(x) returns a NaN and raises the ''invalid'' floating-point exception for
20518       x < -1.
20519     -- log1p(+(inf)) returns +(inf).
20520     F.10.3.10 The log2 functions
20521 1   -- log2((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
20522     -- log2(1) returns +0.
20523     -- log2(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
20524     -- log2(+(inf)) returns +(inf).
20525     F.10.3.11 The logb functions
20526 1   -- logb((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
20527     -- logb((+-)(inf)) returns +(inf).
20528 2   The returned value is exact and is independent of the current rounding direction mode.
20529
20530
20531
20532
20533 [page 518]
20534
20535     F.10.3.12 The modf functions
20536 1   -- modf((+-)x, iptr) returns a result with the same sign as x.
20537     -- modf((+-)(inf), iptr) returns (+-)0 and stores (+-)(inf) in the object pointed to by iptr.
20538     -- modf(NaN, iptr) stores a NaN in the object pointed to by iptr (and returns a
20539       NaN).
20540 2   The returned values are exact and are independent of the current rounding direction
20541     mode.
20542 3   modf behaves as though implemented by
20543             #include <math.h>
20544             #include <fenv.h>
20545             #pragma STDC FENV_ACCESS ON
20546             double modf(double value, double *iptr)
20547             {
20548                  int save_round = fegetround();
20549                  fesetround(FE_TOWARDZERO);
20550                  *iptr = nearbyint(value);
20551                  fesetround(save_round);
20552                  return copysign(
20553                       isinf(value) ? 0.0 :
20554                            value - (*iptr), value);
20555             }
20556     F.10.3.13 The scalbn and scalbln functions
20557 1   -- scalbn((+-)0, n) returns (+-)0.
20558     -- scalbn(x, 0) returns x.
20559     -- scalbn((+-)(inf), n) returns (+-)(inf).
20560 2   If the calculation does not overflow or underflow, the returned value is exact and
20561     independent of the current rounding direction mode.
20562
20563
20564
20565
20566 [page 519]
20567
20568     F.10.4 Power and absolute value functions
20569     F.10.4.1 The cbrt functions
20570 1   -- cbrt((+-)0) returns (+-)0.
20571     -- cbrt((+-)(inf)) returns (+-)(inf).
20572     F.10.4.2 The fabs functions
20573 1   -- fabs((+-)0) returns +0.
20574     -- fabs((+-)(inf)) returns +(inf).
20575 2   The returned value is exact and is independent of the current rounding direction mode.
20576     F.10.4.3 The hypot functions
20577 1   -- hypot(x, y), hypot(y, x), and hypot(x, -y) are equivalent.
20578     -- hypot(x, (+-)0) is equivalent to fabs(x).
20579     -- hypot((+-)(inf), y) returns +(inf), even if y is a NaN.
20580     F.10.4.4 The pow functions
20581 1   -- pow((+-)0, y) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception
20582       for y an odd integer < 0.
20583     -- pow((+-)0, y) returns +(inf) and raises the ''divide-by-zero'' floating-point exception
20584       for y < 0, finite, and not an odd integer.
20585     -- pow((+-)0, -(inf)) returns +(inf) and may raise the ''divide-by-zero'' floating-point
20586       exception.
20587     -- pow((+-)0, y) returns (+-)0 for y an odd integer > 0.
20588     -- pow((+-)0, y) returns +0 for y > 0 and not an odd integer.
20589     -- pow(-1, (+-)(inf)) returns 1.
20590     -- pow(+1, y) returns 1 for any y, even a NaN.
20591     -- pow(x, (+-)0) returns 1 for any x, even a NaN.
20592     -- pow(x, y) returns a NaN and raises the ''invalid'' floating-point exception for
20593       finite x < 0 and finite non-integer y.
20594     -- pow(x, -(inf)) returns +(inf) for | x | < 1.
20595     -- pow(x, -(inf)) returns +0 for | x | > 1.
20596     -- pow(x, +(inf)) returns +0 for | x | < 1.
20597     -- pow(x, +(inf)) returns +(inf) for | x | > 1.
20598
20599
20600 [page 520]
20601
20602     -- pow(-(inf), y) returns -0 for y an odd integer < 0.
20603     -- pow(-(inf), y) returns +0 for y < 0 and not an odd integer.
20604     -- pow(-(inf), y) returns -(inf) for y an odd integer > 0.
20605     -- pow(-(inf), y) returns +(inf) for y > 0 and not an odd integer.
20606     -- pow(+(inf), y) returns +0 for y < 0.
20607     -- pow(+(inf), y) returns +(inf) for y > 0.
20608     F.10.4.5 The sqrt functions
20609 1   sqrt is fully specified as a basic arithmetic operation in IEC 60559. The returned value
20610     is dependent on the current rounding direction mode.
20611     F.10.5 Error and gamma functions
20612     F.10.5.1 The erf functions
20613 1   -- erf((+-)0) returns (+-)0.
20614     -- erf((+-)(inf)) returns (+-)1.
20615     F.10.5.2 The erfc functions
20616 1   -- erfc(-(inf)) returns 2.
20617     -- erfc(+(inf)) returns +0.
20618     F.10.5.3 The lgamma functions
20619 1   -- lgamma(1) returns +0.
20620     -- lgamma(2) returns +0.
20621     -- lgamma(x) returns +(inf) and raises the ''divide-by-zero'' floating-point exception for
20622       x a negative integer or zero.
20623     -- lgamma(-(inf)) returns +(inf).
20624     -- lgamma(+(inf)) returns +(inf).
20625     F.10.5.4 The tgamma functions
20626 1   -- tgamma((+-)0) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception.
20627     -- tgamma(x) returns a NaN and raises the ''invalid'' floating-point exception for x a
20628       negative integer.
20629     -- tgamma(-(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
20630     -- tgamma(+(inf)) returns +(inf).
20631
20632
20633
20634 [page 521]
20635
20636     F.10.6 Nearest integer functions
20637     F.10.6.1 The ceil functions
20638 1   -- ceil((+-)0) returns (+-)0.
20639     -- ceil((+-)(inf)) returns (+-)(inf).
20640 2   The returned value is independent of the current rounding direction mode.
20641 3   The double version of ceil behaves as though implemented by
20642            #include <math.h>
20643            #include <fenv.h>
20644            #pragma STDC FENV_ACCESS ON
20645            double ceil(double x)
20646            {
20647                 double result;
20648                 int save_round = fegetround();
20649                 fesetround(FE_UPWARD);
20650                 result = rint(x); // or nearbyint instead of rint
20651                 fesetround(save_round);
20652                 return result;
20653            }
20654 4   The ceil functions may, but are not required to, raise the ''inexact'' floating-point
20655     exception for finite non-integer arguments, as this implementation does.
20656     F.10.6.2 The floor functions
20657 1   -- floor((+-)0) returns (+-)0.
20658     -- floor((+-)(inf)) returns (+-)(inf).
20659 2   The returned value and is independent of the current rounding direction mode.
20660 3   See the sample implementation for ceil in F.10.6.1. The floor functions may, but are
20661     not required to, raise the ''inexact'' floating-point exception for finite non-integer
20662     arguments, as that implementation does.
20663     F.10.6.3 The nearbyint functions
20664 1   The nearbyint functions use IEC 60559 rounding according to the current rounding
20665     direction. They do not raise the ''inexact'' floating-point exception if the result differs in
20666     value from the argument.
20667     -- nearbyint((+-)0) returns (+-)0 (for all rounding directions).
20668     -- nearbyint((+-)(inf)) returns (+-)(inf) (for all rounding directions).
20669
20670
20671
20672 [page 522]
20673
20674     F.10.6.4 The rint functions
20675 1   The rint functions differ from the nearbyint functions only in that they do raise the
20676     ''inexact'' floating-point exception if the result differs in value from the argument.
20677     F.10.6.5 The lrint and llrint functions
20678 1   The lrint and llrint functions provide floating-to-integer conversion as prescribed
20679     by IEC 60559. They round according to the current rounding direction. If the rounded
20680     value is outside the range of the return type, the numeric result is unspecified and the
20681     ''invalid'' floating-point exception is raised. When they raise no other floating-point
20682     exception and the result differs from the argument, they raise the ''inexact'' floating-point
20683     exception.
20684     F.10.6.6 The round functions
20685 1   -- round((+-)0) returns (+-)0.
20686     -- round((+-)(inf)) returns (+-)(inf).
20687 2   The returned value is independent of the current rounding direction mode.
20688 3   The double version of round behaves as though implemented by
20689             #include <math.h>
20690             #include <fenv.h>
20691             #pragma STDC FENV_ACCESS ON
20692             double round(double x)
20693             {
20694                  double result;
20695                  fenv_t save_env;
20696                  feholdexcept(&save_env);
20697                  result = rint(x);
20698                  if (fetestexcept(FE_INEXACT)) {
20699                       fesetround(FE_TOWARDZERO);
20700                       result = rint(copysign(0.5 + fabs(x), x));
20701                  }
20702                  feupdateenv(&save_env);
20703                  return result;
20704             }
20705     The round functions may, but are not required to, raise the ''inexact'' floating-point
20706     exception for finite non-integer numeric arguments, as this implementation does.
20707
20708
20709
20710
20711 [page 523]
20712
20713     F.10.6.7 The lround and llround functions
20714 1   The lround and llround functions differ from the lrint and llrint functions
20715     with the default rounding direction just in that the lround and llround functions
20716     round halfway cases away from zero and need not raise the ''inexact'' floating-point
20717     exception for non-integer arguments that round to within the range of the return type.
20718     F.10.6.8 The trunc functions
20719 1   The trunc functions use IEC 60559 rounding toward zero (regardless of the current
20720     rounding direction). The returned value is exact.
20721     -- trunc((+-)0) returns (+-)0.
20722     -- trunc((+-)(inf)) returns (+-)(inf).
20723 2   The returned value is independent of the current rounding direction mode. The trunc
20724     functions may, but are not required to, raise the ''inexact'' floating-point exception for
20725     finite non-integer arguments.
20726     F.10.7 Remainder functions
20727     F.10.7.1 The fmod functions
20728 1   -- fmod((+-)0, y) returns (+-)0 for y not zero.
20729     -- fmod(x, y) returns a NaN and raises the ''invalid'' floating-point exception for x
20730       infinite or y zero (and neither is a NaN).
20731     -- fmod(x, (+-)(inf)) returns x for x not infinite.
20732 2   When subnormal results are supported, the returned value is exact and is independent of
20733     the current rounding direction mode.
20734 3   The double version of fmod behaves as though implemented by
20735            #include <math.h>
20736            #include <fenv.h>
20737            #pragma STDC FENV_ACCESS ON
20738            double fmod(double x, double y)
20739            {
20740                 double result;
20741                 result = remainder(fabs(x), (y = fabs(y)));
20742                 if (signbit(result)) result += y;
20743                 return copysign(result, x);
20744            }
20745
20746
20747
20748
20749 [page 524]
20750
20751     F.10.7.2 The remainder functions
20752 1   The remainder functions are fully specified as a basic arithmetic operation in
20753     IEC 60559.
20754 2   When subnormal results are supported, the returned value is exact and is independent of
20755     the current rounding direction mode.
20756     F.10.7.3 The remquo functions
20757 1   The remquo functions follow the specifications for the remainder functions. They
20758     have no further specifications special to IEC 60559 implementations.
20759 2   When subnormal results are supported, the returned value is exact and is independent of
20760     the current rounding direction mode.
20761     F.10.8 Manipulation functions
20762     F.10.8.1 The copysign functions
20763 1   copysign is specified in the Appendix to IEC 60559.
20764 2   The returned value is exact and is independent of the current rounding direction mode.
20765     F.10.8.2 The nan functions
20766 1   All IEC 60559 implementations support quiet NaNs, in all floating formats.
20767 2   The returned value is exact and is independent of the current rounding direction mode.
20768     F.10.8.3 The nextafter functions
20769 1   -- nextafter(x, y) raises the ''overflow'' and ''inexact'' floating-point exceptions
20770       for x finite and the function value infinite.
20771     -- nextafter(x, y) raises the ''underflow'' and ''inexact'' floating-point
20772       exceptions for the function value subnormal or zero and x != y.
20773 2   Even though underflow or overflow can occur, the returned value is independent of the
20774     current rounding direction mode.
20775     F.10.8.4 The nexttoward functions
20776 1   No additional requirements beyond those on nextafter.
20777 2   Even though underflow or overflow can occur, the returned value is independent of the
20778     current rounding direction mode.
20779
20780
20781
20782
20783 [page 525]
20784
20785     F.10.9 Maximum, minimum, and positive difference functions
20786     F.10.9.1 The fdim functions
20787 1   No additional requirements.
20788     F.10.9.2 The fmax functions
20789 1   If just one argument is a NaN, the fmax functions return the other argument (if both
20790     arguments are NaNs, the functions return a NaN).
20791 2   The returned value is exact and is independent of the current rounding direction mode.
20792 3   The body of the fmax function might be361)
20793            { return (isgreaterequal(x, y) ||
20794                 isnan(y)) ? x : y; }
20795     F.10.9.3 The fmin functions
20796 1   The fmin functions are analogous to the fmax functions (see F.10.9.2).
20797 2   The returned value is exact and is independent of the current rounding direction mode.
20798     F.10.10 Floating multiply-add
20799     F.10.10.1 The fma functions
20800 1   -- fma(x, y, z) computes xy + z, correctly rounded once.
20801     -- fma(x, y, z) returns a NaN and optionally raises the ''invalid'' floating-point
20802       exception if one of x and y is infinite, the other is zero, and z is a NaN.
20803     -- fma(x, y, z) returns a NaN and raises the ''invalid'' floating-point exception if
20804       one of x and y is infinite, the other is zero, and z is not a NaN.
20805     -- fma(x, y, z) returns a NaN and raises the ''invalid'' floating-point exception if x
20806       times y is an exact infinity and z is also an infinity but with the opposite sign.
20807
20808
20809
20810
20811     361) Ideally, fmax would be sensitive to the sign of zero, for example fmax(-0.0, +0.0) would
20812          return +0; however, implementation in software might be impractical.
20813
20814 [page 526]
20815
20816     F.10.11 Comparison macros
20817 1   Relational operators and their corresponding comparison macros (7.12.14) produce
20818     equivalent result values, even if argument values are represented in wider formats. Thus,
20819     comparison macro arguments represented in formats wider than their semantic types are
20820     not converted to the semantic types, unless the wide evaluation method converts operands
20821     of relational operators to their semantic types. The standard wide evaluation methods
20822     characterized by FLT_EVAL_METHOD equal to 1 or 2 (5.2.4.2.2), do not convert
20823     operands of relational operators to their semantic types.
20824
20825
20826
20827
20828 [page 527]
20829
20830                                            Annex G
20831                                           (normative)
20832                    IEC 60559-compatible complex arithmetic
20833     G.1 Introduction
20834 1   This annex supplements annex F to specify complex arithmetic for compatibility with
20835     IEC 60559 real floating-point arithmetic. An implementation that defines *
20836     __STDC_IEC_559_COMPLEX__ shall conform to the specifications in this annex.362)
20837     G.2 Types
20838 1   There is a new keyword _Imaginary, which is used to specify imaginary types. It is
20839     used as a type specifier within declaration specifiers in the same way as _Complex is
20840     (thus, _Imaginary float is a valid type name).
20841 2   There are three imaginary types, designated as float _Imaginary, double
20842     _Imaginary, and long double _Imaginary. The imaginary types (along with
20843     the real floating and complex types) are floating types.
20844 3   For imaginary types, the corresponding real type is given by deleting the keyword
20845     _Imaginary from the type name.
20846 4   Each imaginary type has the same representation and alignment requirements as the
20847     corresponding real type. The value of an object of imaginary type is the value of the real
20848     representation times the imaginary unit.
20849 5   The imaginary type domain comprises the imaginary types.
20850     G.3 Conventions
20851 1   A complex or imaginary value with at least one infinite part is regarded as an infinity
20852     (even if its other part is a NaN). A complex or imaginary value is a finite number if each
20853     of its parts is a finite number (neither infinite nor NaN). A complex or imaginary value is
20854     a zero if each of its parts is a zero.
20855
20856
20857
20858
20859     362) Implementations that do not define __STDC_IEC_559_COMPLEX__ are not required to conform
20860          to these specifications.
20861
20862 [page 528]
20863
20864     G.4 Conversions
20865     G.4.1 Imaginary types
20866 1   Conversions among imaginary types follow rules analogous to those for real floating
20867     types.
20868     G.4.2 Real and imaginary
20869 1   When a value of imaginary type is converted to a real type other than _Bool,363) the
20870     result is a positive zero.
20871 2   When a value of real type is converted to an imaginary type, the result is a positive
20872     imaginary zero.
20873     G.4.3 Imaginary and complex
20874 1   When a value of imaginary type is converted to a complex type, the real part of the
20875     complex result value is a positive zero and the imaginary part of the complex result value
20876     is determined by the conversion rules for the corresponding real types.
20877 2   When a value of complex type is converted to an imaginary type, the real part of the
20878     complex value is discarded and the value of the imaginary part is converted according to
20879     the conversion rules for the corresponding real types.
20880     G.5 Binary operators
20881 1   The following subclauses supplement 6.5 in order to specify the type of the result for an
20882     operation with an imaginary operand.
20883 2   For most operand types, the value of the result of a binary operator with an imaginary or
20884     complex operand is completely determined, with reference to real arithmetic, by the usual
20885     mathematical formula. For some operand types, the usual mathematical formula is
20886     problematic because of its treatment of infinities and because of undue overflow or
20887     underflow; in these cases the result satisfies certain properties (specified in G.5.1), but is
20888     not completely determined.
20889
20890
20891
20892
20893     363) See 6.3.1.2.
20894
20895 [page 529]
20896
20897     G.5.1 Multiplicative operators
20898     Semantics
20899 1   If one operand has real type and the other operand has imaginary type, then the result has
20900     imaginary type. If both operands have imaginary type, then the result has real type. (If
20901     either operand has complex type, then the result has complex type.)
20902 2   If the operands are not both complex, then the result and floating-point exception
20903     behavior of the * operator is defined by the usual mathematical formula:
20904            *                  u                   iv                 u + iv
20905
20906            x                  xu                i(xv)            (xu) + i(xv)
20907
20908            iy               i(yu)                -yv            (-yv) + i(yu)
20909
20910            x + iy       (xu) + i(yu)        (-yv) + i(xv)
20911 3   If the second operand is not complex, then the result and floating-point exception
20912     behavior of the / operator is defined by the usual mathematical formula:
20913            /                   u                       iv
20914
20915            x                  x/u                 i(-x/v)
20916
20917            iy               i(y/u)                     y/v
20918
20919            x + iy       (x/u) + i(y/u)        (y/v) + i(-x/v)
20920 4   The * and / operators satisfy the following infinity properties for all real, imaginary, and
20921     complex operands:364)
20922     -- if one operand is an infinity and the other operand is a nonzero finite number or an
20923       infinity, then the result of the * operator is an infinity;
20924     -- if the first operand is an infinity and the second operand is a finite number, then the
20925       result of the / operator is an infinity;
20926     -- if the first operand is a finite number and the second operand is an infinity, then the
20927       result of the / operator is a zero;
20928
20929
20930
20931
20932     364) These properties are already implied for those cases covered in the tables, but are required for all cases
20933          (at least where the state for CX_LIMITED_RANGE is ''off'').
20934
20935 [page 530]
20936
20937     -- if the first operand is a nonzero finite number or an infinity and the second operand is
20938       a zero, then the result of the / operator is an infinity.
20939 5   If both operands of the * operator are complex or if the second operand of the / operator
20940     is complex, the operator raises floating-point exceptions if appropriate for the calculation
20941     of the parts of the result, and may raise spurious floating-point exceptions.
20942 6   EXAMPLE 1 Multiplication of double _Complex operands could be implemented as follows. Note
20943     that the imaginary unit I has imaginary type (see G.6).
20944              #include <math.h>
20945              #include <complex.h>
20946              /* Multiply z * w ... */
20947              double complex _Cmultd(double complex z, double complex w)
20948              {
20949                     #pragma STDC FP_CONTRACT OFF
20950                     double a, b, c, d, ac, bd, ad, bc, x, y;
20951                     a = creal(z); b = cimag(z);
20952                     c = creal(w); d = cimag(w);
20953                     ac = a * c;       bd = b * d;
20954                     ad = a * d;       bc = b * c;
20955                     x = ac - bd; y = ad + bc;
20956                     if (isnan(x) && isnan(y)) {
20957                             /* Recover infinities that computed as NaN+iNaN ... */
20958                             int recalc = 0;
20959                             if ( isinf(a) || isinf(b) ) { // z is infinite
20960                                     /* "Box" the infinity and change NaNs in the other factor to 0 */
20961                                     a = copysign(isinf(a) ? 1.0 : 0.0, a);
20962                                     b = copysign(isinf(b) ? 1.0 : 0.0, b);
20963                                     if (isnan(c)) c = copysign(0.0, c);
20964                                     if (isnan(d)) d = copysign(0.0, d);
20965                                     recalc = 1;
20966                             }
20967                             if ( isinf(c) || isinf(d) ) { // w is infinite
20968                                     /* "Box" the infinity and change NaNs in the other factor to 0 */
20969                                     c = copysign(isinf(c) ? 1.0 : 0.0, c);
20970                                     d = copysign(isinf(d) ? 1.0 : 0.0, d);
20971                                     if (isnan(a)) a = copysign(0.0, a);
20972                                     if (isnan(b)) b = copysign(0.0, b);
20973                                     recalc = 1;
20974                             }
20975                             if (!recalc && (isinf(ac) || isinf(bd) ||
20976                                                    isinf(ad) || isinf(bc))) {
20977                                     /* Recover infinities from overflow by changing NaNs to 0 ... */
20978                                     if (isnan(a)) a = copysign(0.0, a);
20979                                     if (isnan(b)) b = copysign(0.0, b);
20980                                     if (isnan(c)) c = copysign(0.0, c);
20981                                     if (isnan(d)) d = copysign(0.0, d);
20982                                     recalc = 1;
20983                             }
20984                             if (recalc) {
20985
20986 [page 531]
20987
20988                                       x = INFINITY * ( a * c - b * d );
20989                                       y = INFINITY * ( a * d + b * c );
20990                            }
20991                      }
20992                      return x + I * y;
20993             }
20994 7   This implementation achieves the required treatment of infinities at the cost of only one isnan test in
20995     ordinary (finite) cases. It is less than ideal in that undue overflow and underflow may occur.
20996
20997 8   EXAMPLE 2      Division of two double _Complex operands could be implemented as follows.
20998             #include <math.h>
20999             #include <complex.h>
21000             /* Divide z / w ... */
21001             double complex _Cdivd(double complex z, double complex w)
21002             {
21003                    #pragma STDC FP_CONTRACT OFF
21004                    double a, b, c, d, logbw, denom, x, y;
21005                    int ilogbw = 0;
21006                    a = creal(z); b = cimag(z);
21007                    c = creal(w); d = cimag(w);
21008                    logbw = logb(fmax(fabs(c), fabs(d)));
21009                    if (logbw == INFINITY) {
21010                           ilogbw = (int)logbw;
21011                           c = scalbn(c, -ilogbw); d = scalbn(d, -ilogbw);
21012                    }
21013                    denom = c * c + d * d;
21014                    x = scalbn((a * c + b * d) / denom, -ilogbw);
21015                    y = scalbn((b * c - a * d) / denom, -ilogbw);
21016                      /* Recover infinities and zeros that computed as NaN+iNaN;                 */
21017                      /* the only cases are nonzero/zero, infinite/finite, and finite/infinite, ... */
21018                      if (isnan(x) && isnan(y)) {
21019                            if ((denom == 0.0) &&
21020                                  (!isnan(a) || !isnan(b))) {
21021                                  x = copysign(INFINITY, c) * a;
21022                                  y = copysign(INFINITY, c) * b;
21023                            }
21024                            else if ((isinf(a) || isinf(b)) &&
21025                                  isfinite(c) && isfinite(d)) {
21026                                  a = copysign(isinf(a) ? 1.0 : 0.0,                        a);
21027                                  b = copysign(isinf(b) ? 1.0 : 0.0,                        b);
21028                                  x = INFINITY * ( a * c + b * d );
21029                                  y = INFINITY * ( b * c - a * d );
21030                            }
21031                            else if (isinf(logbw) &&
21032                                  isfinite(a) && isfinite(b)) {
21033                                  c = copysign(isinf(c) ? 1.0 : 0.0,                        c);
21034                                  d = copysign(isinf(d) ? 1.0 : 0.0,                        d);
21035                                  x = 0.0 * ( a * c + b * d );
21036                                  y = 0.0 * ( b * c - a * d );
21037
21038 [page 532]
21039
21040                            }
21041                      }
21042                      return x + I * y;
21043             }
21044 9   Scaling the denominator alleviates the main overflow and underflow problem, which is more serious than
21045     for multiplication. In the spirit of the multiplication example above, this code does not defend against
21046     overflow and underflow in the calculation of the numerator. Scaling with the scalbn function, instead of
21047     with division, provides better roundoff characteristics.
21048
21049     G.5.2 Additive operators
21050     Semantics
21051 1   If both operands have imaginary type, then the result has imaginary type. (If one operand
21052     has real type and the other operand has imaginary type, or if either operand has complex
21053     type, then the result has complex type.)
21054 2   In all cases the result and floating-point exception behavior of a + or - operator is defined
21055     by the usual mathematical formula:
21056            + or -              u                       iv                    u + iv
21057
21058            x                 x(+-)u                     x (+-) iv              (x (+-) u) (+-) iv
21059
21060            iy               (+-)u + iy                 i(y (+-) v)             (+-)u + i(y (+-) v)
21061
21062            x + iy         (x (+-) u) + iy            x + i(y (+-) v)        (x (+-) u) + i(y (+-) v)
21063     G.6 Complex arithmetic <complex.h>
21064 1   The macros
21065             imaginary
21066     and
21067             _Imaginary_I
21068     are defined, respectively, as _Imaginary and a constant expression of type const
21069     float _Imaginary with the value of the imaginary unit. The macro
21070             I
21071     is defined to be _Imaginary_I (not _Complex_I as stated in 7.3). Notwithstanding
21072     the provisions of 7.1.3, a program may undefine and then perhaps redefine the macro
21073     imaginary.
21074 2   This subclause contains specifications for the <complex.h> functions that are
21075     particularly suited to IEC 60559 implementations. For families of functions, the
21076     specifications apply to all of the functions even though only the principal function is
21077
21078 [page 533]
21079
21080     shown. Unless otherwise specified, where the symbol ''(+-)'' occurs in both an argument
21081     and the result, the result has the same sign as the argument.
21082 3   The functions are continuous onto both sides of their branch cuts, taking into account the
21083     sign of zero. For example, csqrt(-2 (+-) i0) = (+-)isqrt:2.  -
21084 4   Since complex and imaginary values are composed of real values, each function may be
21085     regarded as computing real values from real values. Except as noted, the functions treat
21086     real infinities, NaNs, signed zeros, subnormals, and the floating-point exception flags in a
21087     manner consistent with the specifications for real functions in F.10.365)
21088 5   The functions cimag, conj, cproj, and creal are fully specified for all
21089     implementations, including IEC 60559 ones, in 7.3.9. These functions raise no floating-
21090     point exceptions.
21091 6   Each of the functions cabs and carg is specified by a formula in terms of a real
21092     function (whose special cases are covered in annex F):
21093             cabs(x + iy) = hypot(x, y)
21094             carg(x + iy) = atan2(y, x)
21095 7   Each of the functions casin, catan, ccos, csin, and ctan is specified implicitly by
21096     a formula in terms of other complex functions (whose special cases are specified below):
21097             casin(z)        =   -i casinh(iz)
21098             catan(z)        =   -i catanh(iz)
21099             ccos(z)         =   ccosh(iz)
21100             csin(z)         =   -i csinh(iz)
21101             ctan(z)         =   -i ctanh(iz)
21102 8   For the other functions, the following subclauses specify behavior for special cases,
21103     including treatment of the ''invalid'' and ''divide-by-zero'' floating-point exceptions. For
21104     families of functions, the specifications apply to all of the functions even though only the
21105     principal function is shown. For a function f satisfying f (conj(z)) = conj( f (z)), the
21106     specifications for the upper half-plane imply the specifications for the lower half-plane; if
21107     the function f is also either even, f (-z) = f (z), or odd, f (-z) = - f (z), then the
21108     specifications for the first quadrant imply the specifications for the other three quadrants.
21109 9   In the following subclauses, cis(y) is defined as cos(y) + i sin(y).
21110
21111
21112
21113
21114     365) As noted in G.3, a complex value with at least one infinite part is regarded as an infinity even if its
21115          other part is a NaN.
21116
21117 [page 534]
21118
21119     G.6.1 Trigonometric functions
21120     G.6.1.1 The cacos functions
21121 1   -- cacos(conj(z)) = conj(cacos(z)).
21122     -- cacos((+-)0 + i0) returns pi /2 - i0.
21123     -- cacos((+-)0 + iNaN) returns pi /2 + iNaN.
21124     -- cacos(x + i (inf)) returns pi /2 - i (inf), for finite x.
21125     -- cacos(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21126       point exception, for nonzero finite x.
21127     -- cacos(-(inf) + iy) returns pi - i (inf), for positive-signed finite y.
21128     -- cacos(+(inf) + iy) returns +0 - i (inf), for positive-signed finite y.
21129     -- cacos(-(inf) + i (inf)) returns 3pi /4 - i (inf).
21130     -- cacos(+(inf) + i (inf)) returns pi /4 - i (inf).
21131     -- cacos((+-)(inf) + iNaN) returns NaN (+-) i (inf) (where the sign of the imaginary part of the
21132       result is unspecified).
21133     -- cacos(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21134       point exception, for finite y.
21135     -- cacos(NaN + i (inf)) returns NaN - i (inf).
21136     -- cacos(NaN + iNaN) returns NaN + iNaN.
21137     G.6.2 Hyperbolic functions
21138     G.6.2.1 The cacosh functions
21139 1   -- cacosh(conj(z)) = conj(cacosh(z)).
21140     -- cacosh((+-)0 + i0) returns +0 + ipi /2.
21141     -- cacosh(x + i (inf)) returns +(inf) + ipi /2, for finite x.
21142     -- cacosh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
21143       floating-point exception, for finite x.
21144     -- cacosh(-(inf) + iy) returns +(inf) + ipi , for positive-signed finite y.
21145     -- cacosh(+(inf) + iy) returns +(inf) + i0, for positive-signed finite y.
21146     -- cacosh(-(inf) + i (inf)) returns +(inf) + i3pi /4.
21147     -- cacosh(+(inf) + i (inf)) returns +(inf) + ipi /4.
21148     -- cacosh((+-)(inf) + iNaN) returns +(inf) + iNaN.
21149
21150
21151 [page 535]
21152
21153     -- cacosh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
21154       floating-point exception, for finite y.
21155     -- cacosh(NaN + i (inf)) returns +(inf) + iNaN.
21156     -- cacosh(NaN + iNaN) returns NaN + iNaN.
21157     G.6.2.2 The casinh functions
21158 1   -- casinh(conj(z)) = conj(casinh(z)) and casinh is odd.
21159     -- casinh(+0 + i0) returns 0 + i0.
21160     -- casinh(x + i (inf)) returns +(inf) + ipi /2 for positive-signed finite x.
21161     -- casinh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
21162       floating-point exception, for finite x.
21163     -- casinh(+(inf) + iy) returns +(inf) + i0 for positive-signed finite y.
21164     -- casinh(+(inf) + i (inf)) returns +(inf) + ipi /4.
21165     -- casinh(+(inf) + iNaN) returns +(inf) + iNaN.
21166     -- casinh(NaN + i0) returns NaN + i0.
21167     -- casinh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
21168       floating-point exception, for finite nonzero y.
21169     -- casinh(NaN + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result
21170       is unspecified).
21171     -- casinh(NaN + iNaN) returns NaN + iNaN.
21172     G.6.2.3 The catanh functions
21173 1   -- catanh(conj(z)) = conj(catanh(z)) and catanh is odd.
21174     -- catanh(+0 + i0) returns +0 + i0.
21175     -- catanh(+0 + iNaN) returns +0 + iNaN.
21176     -- catanh(+1 + i0) returns +(inf) + i0 and raises the ''divide-by-zero'' floating-point
21177       exception.
21178     -- catanh(x + i (inf)) returns +0 + ipi /2, for finite positive-signed x.
21179     -- catanh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
21180       floating-point exception, for nonzero finite x.
21181     -- catanh(+(inf) + iy) returns +0 + ipi /2, for finite positive-signed y.
21182     -- catanh(+(inf) + i (inf)) returns +0 + ipi /2.
21183     -- catanh(+(inf) + iNaN) returns +0 + iNaN.
21184
21185 [page 536]
21186
21187     -- catanh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
21188       floating-point exception, for finite y.
21189     -- catanh(NaN + i (inf)) returns (+-)0 + ipi /2 (where the sign of the real part of the result is
21190       unspecified).
21191     -- catanh(NaN + iNaN) returns NaN + iNaN.
21192     G.6.2.4 The ccosh functions
21193 1   -- ccosh(conj(z)) = conj(ccosh(z)) and ccosh is even.
21194     -- ccosh(+0 + i0) returns 1 + i0.
21195     -- ccosh(+0 + i (inf)) returns NaN (+-) i0 (where the sign of the imaginary part of the
21196       result is unspecified) and raises the ''invalid'' floating-point exception.
21197     -- ccosh(+0 + iNaN) returns NaN (+-) i0 (where the sign of the imaginary part of the
21198       result is unspecified).
21199     -- ccosh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
21200       exception, for finite nonzero x.
21201     -- ccosh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21202       point exception, for finite nonzero x.
21203     -- ccosh(+(inf) + i0) returns +(inf) + i0.
21204     -- ccosh(+(inf) + iy) returns +(inf) cis(y), for finite nonzero y.
21205     -- ccosh(+(inf) + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result is
21206       unspecified) and raises the ''invalid'' floating-point exception.
21207     -- ccosh(+(inf) + iNaN) returns +(inf) + iNaN.
21208     -- ccosh(NaN + i0) returns NaN (+-) i0 (where the sign of the imaginary part of the
21209       result is unspecified).
21210     -- ccosh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21211       point exception, for all nonzero numbers y.
21212     -- ccosh(NaN + iNaN) returns NaN + iNaN.
21213     G.6.2.5 The csinh functions
21214 1   -- csinh(conj(z)) = conj(csinh(z)) and csinh is odd.
21215     -- csinh(+0 + i0) returns +0 + i0.
21216     -- csinh(+0 + i (inf)) returns (+-)0 + iNaN (where the sign of the real part of the result is
21217       unspecified) and raises the ''invalid'' floating-point exception.
21218     -- csinh(+0 + iNaN) returns (+-)0 + iNaN (where the sign of the real part of the result is
21219       unspecified).
21220 [page 537]
21221
21222     -- csinh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
21223       exception, for positive finite x.
21224     -- csinh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21225       point exception, for finite nonzero x.
21226     -- csinh(+(inf) + i0) returns +(inf) + i0.
21227     -- csinh(+(inf) + iy) returns +(inf) cis(y), for positive finite y.
21228     -- csinh(+(inf) + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result is
21229       unspecified) and raises the ''invalid'' floating-point exception.
21230     -- csinh(+(inf) + iNaN) returns (+-)(inf) + iNaN (where the sign of the real part of the result
21231       is unspecified).
21232     -- csinh(NaN + i0) returns NaN + i0.
21233     -- csinh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21234       point exception, for all nonzero numbers y.
21235     -- csinh(NaN + iNaN) returns NaN + iNaN.
21236     G.6.2.6 The ctanh functions
21237 1   -- ctanh(conj(z)) = conj(ctanh(z))and ctanh is odd.
21238     -- ctanh(+0 + i0) returns +0 + i0.
21239     -- ctanh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
21240       exception, for finite x.
21241     -- ctanh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21242       point exception, for finite x.
21243     -- ctanh(+(inf) + iy) returns 1 + i0 sin(2y), for positive-signed finite y.
21244     -- ctanh(+(inf) + i (inf)) returns 1 (+-) i0 (where the sign of the imaginary part of the result
21245       is unspecified).
21246     -- ctanh(+(inf) + iNaN) returns 1 (+-) i0 (where the sign of the imaginary part of the
21247       result is unspecified).
21248     -- ctanh(NaN + i0) returns NaN + i0.
21249     -- ctanh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21250       point exception, for all nonzero numbers y.
21251     -- ctanh(NaN + iNaN) returns NaN + iNaN.
21252
21253
21254
21255
21256 [page 538]
21257
21258     G.6.3 Exponential and logarithmic functions
21259     G.6.3.1 The cexp functions
21260 1   -- cexp(conj(z)) = conj(cexp(z)).
21261     -- cexp((+-)0 + i0) returns 1 + i0.
21262     -- cexp(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
21263       exception, for finite x.
21264     -- cexp(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21265       point exception, for finite x.
21266     -- cexp(+(inf) + i0) returns +(inf) + i0.
21267     -- cexp(-(inf) + iy) returns +0 cis(y), for finite y.
21268     -- cexp(+(inf) + iy) returns +(inf) cis(y), for finite nonzero y.
21269     -- cexp(-(inf) + i (inf)) returns (+-)0 (+-) i0 (where the signs of the real and imaginary parts of
21270       the result are unspecified).
21271     -- cexp(+(inf) + i (inf)) returns (+-)(inf) + iNaN and raises the ''invalid'' floating-point
21272       exception (where the sign of the real part of the result is unspecified).
21273     -- cexp(-(inf) + iNaN) returns (+-)0 (+-) i0 (where the signs of the real and imaginary parts
21274       of the result are unspecified).
21275     -- cexp(+(inf) + iNaN) returns (+-)(inf) + iNaN (where the sign of the real part of the result
21276       is unspecified).
21277     -- cexp(NaN + i0) returns NaN + i0.
21278     -- cexp(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21279       point exception, for all nonzero numbers y.
21280     -- cexp(NaN + iNaN) returns NaN + iNaN.
21281     G.6.3.2 The clog functions
21282 1   -- clog(conj(z)) = conj(clog(z)).
21283     -- clog(-0 + i0) returns -(inf) + ipi and raises the ''divide-by-zero'' floating-point
21284       exception.
21285     -- clog(+0 + i0) returns -(inf) + i0 and raises the ''divide-by-zero'' floating-point
21286       exception.
21287     -- clog(x + i (inf)) returns +(inf) + ipi /2, for finite x.
21288     -- clog(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21289       point exception, for finite x.
21290
21291 [page 539]
21292
21293     -- clog(-(inf) + iy) returns +(inf) + ipi , for finite positive-signed y.
21294     -- clog(+(inf) + iy) returns +(inf) + i0, for finite positive-signed y.
21295     -- clog(-(inf) + i (inf)) returns +(inf) + i3pi /4.
21296     -- clog(+(inf) + i (inf)) returns +(inf) + ipi /4.
21297     -- clog((+-)(inf) + iNaN) returns +(inf) + iNaN.
21298     -- clog(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21299       point exception, for finite y.
21300     -- clog(NaN + i (inf)) returns +(inf) + iNaN.
21301     -- clog(NaN + iNaN) returns NaN + iNaN.
21302     G.6.4 Power and absolute-value functions
21303     G.6.4.1 The cpow functions
21304 1   The cpow functions raise floating-point exceptions if appropriate for the calculation of
21305     the parts of the result, and may also raise spurious floating-point exceptions.366)
21306     G.6.4.2 The csqrt functions
21307 1   -- csqrt(conj(z)) = conj(csqrt(z)).
21308     -- csqrt((+-)0 + i0) returns +0 + i0.
21309     -- csqrt(x + i (inf)) returns +(inf) + i (inf), for all x (including NaN).
21310     -- csqrt(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21311       point exception, for finite x.
21312     -- csqrt(-(inf) + iy) returns +0 + i (inf), for finite positive-signed y.
21313     -- csqrt(+(inf) + iy) returns +(inf) + i0, for finite positive-signed y.
21314     -- csqrt(-(inf) + iNaN) returns NaN (+-) i (inf) (where the sign of the imaginary part of the
21315       result is unspecified).
21316     -- csqrt(+(inf) + iNaN) returns +(inf) + iNaN.
21317     -- csqrt(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21318       point exception, for finite y.
21319     -- csqrt(NaN + iNaN) returns NaN + iNaN.
21320
21321
21322
21323
21324     366) This allows cpow( z , c ) to be implemented as cexp(c      clog( z )) without precluding
21325          implementations that treat special cases more carefully.
21326
21327 [page 540]
21328
21329     G.7 Type-generic math <tgmath.h>
21330 1   Type-generic macros that accept complex arguments also accept imaginary arguments. If
21331     an argument is imaginary, the macro expands to an expression whose type is real,
21332     imaginary, or complex, as appropriate for the particular function: if the argument is
21333     imaginary, then the types of cos, cosh, fabs, carg, cimag, and creal are real; the
21334     types of sin, tan, sinh, tanh, asin, atan, asinh, and atanh are imaginary; and
21335     the types of the others are complex.
21336 2   Given an imaginary argument, each of the type-generic macros cos, sin, tan, cosh,
21337     sinh, tanh, asin, atan, asinh, atanh is specified by a formula in terms of real
21338     functions:
21339             cos(iy)     =   cosh(y)
21340             sin(iy)     =   i sinh(y)
21341             tan(iy)     =   i tanh(y)
21342             cosh(iy)    =   cos(y)
21343             sinh(iy)    =   i sin(y)
21344             tanh(iy)    =   i tan(y)
21345             asin(iy)    =   i asinh(y)
21346             atan(iy)    =   i atanh(y)
21347             asinh(iy)   =   i asin(y)
21348             atanh(iy)   =   i atan(y)
21349
21350
21351
21352
21353 [page 541]
21354
21355                                           Annex H
21356                                         (informative)
21357                         Language independent arithmetic
21358     H.1 Introduction
21359 1   This annex documents the extent to which the C language supports the ISO/IEC 10967-1
21360     standard for language-independent arithmetic (LIA-1). LIA-1 is more general than
21361     IEC 60559 (annex F) in that it covers integer and diverse floating-point arithmetics.
21362     H.2 Types
21363 1   The relevant C arithmetic types meet the requirements of LIA-1 types if an
21364     implementation adds notification of exceptional arithmetic operations and meets the 1
21365     unit in the last place (ULP) accuracy requirement (LIA-1 subclause 5.2.8).
21366     H.2.1 Boolean type
21367 1   The LIA-1 data type Boolean is implemented by the C data type bool with values of
21368     true and false, all from <stdbool.h>.
21369     H.2.2 Integer types
21370 1   The signed C integer types int, long int, long long int, and the corresponding
21371     unsigned types are compatible with LIA-1. If an implementation adds support for the
21372     LIA-1 exceptional values ''integer_overflow'' and ''undefined'', then those types are
21373     LIA-1 conformant types. C's unsigned integer types are ''modulo'' in the LIA-1 sense
21374     in that overflows or out-of-bounds results silently wrap. An implementation that defines
21375     signed integer types as also being modulo need not detect integer overflow, in which case,
21376     only integer divide-by-zero need be detected.
21377 2   The parameters for the integer data types can be accessed by the following:
21378     maxint        INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX,
21379                   ULLONG_MAX
21380     minint        INT_MIN, LONG_MIN, LLONG_MIN
21381 3   The parameter ''bounded'' is always true, and is not provided. The parameter ''minint''
21382     is always 0 for the unsigned types, and is not provided for those types.
21383
21384
21385
21386
21387 [page 542]
21388
21389     H.2.2.1 Integer operations
21390 1   The integer operations on integer types are the following:
21391     addI           x + y
21392     subI           x - y
21393     mulI           x * y
21394     divI, divtI    x / y
21395     remI, remtI    x % y
21396     negI           -x
21397     absI           abs(x), labs(x), llabs(x)
21398     eqI            x == y
21399     neqI           x != y
21400     lssI           x < y
21401     leqI           x <= y
21402     gtrI           x > y
21403     geqI           x >= y
21404     where x and y are expressions of the same integer type.
21405     H.2.3 Floating-point types
21406 1   The C floating-point types float, double, and long double are compatible with
21407     LIA-1. If an implementation adds support for the LIA-1 exceptional values
21408     ''underflow'', ''floating_overflow'', and ''"undefined'', then those types are conformant
21409     with LIA-1. An implementation that uses IEC 60559 floating-point formats and
21410     operations (see annex F) along with IEC 60559 status flags and traps has LIA-1
21411     conformant types.
21412     H.2.3.1 Floating-point parameters
21413 1   The parameters for a floating point data type can be accessed by the following:
21414     r              FLT_RADIX
21415     p              FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG
21416     emax           FLT_MAX_EXP, DBL_MAX_EXP, LDBL_MAX_EXP
21417     emin           FLT_MIN_EXP, DBL_MIN_EXP, LDBL_MIN_EXP
21418 2   The derived constants for the floating point types are accessed by the following:
21419
21420
21421 [page 543]
21422
21423     fmax          FLT_MAX, DBL_MAX, LDBL_MAX
21424     fminN         FLT_MIN, DBL_MIN, LDBL_MIN
21425     epsilon       FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON
21426     rnd_style     FLT_ROUNDS
21427     H.2.3.2 Floating-point operations
21428 1   The floating-point operations on floating-point types are the following:
21429     addF          x + y
21430     subF          x - y
21431     mulF          x * y
21432     divF          x / y
21433     negF          -x
21434     absF          fabsf(x), fabs(x), fabsl(x)
21435     exponentF     1.f+logbf(x), 1.0+logb(x), 1.L+logbl(x)
21436     scaleF        scalbnf(x, n), scalbn(x, n), scalbnl(x, n),
21437                   scalblnf(x, li), scalbln(x, li), scalblnl(x, li)
21438     intpartF      modff(x, &y), modf(x, &y), modfl(x, &y)
21439     fractpartF    modff(x, &y), modf(x, &y), modfl(x, &y)
21440     eqF           x == y
21441     neqF          x != y
21442     lssF          x < y
21443     leqF          x <= y
21444     gtrF          x > y
21445     geqF          x >= y
21446     where x and y are expressions of the same floating point type, n is of type int, and li
21447     is of type long int.
21448     H.2.3.3 Rounding styles
21449 1   The C Standard requires all floating types to use the same radix and rounding style, so
21450     that only one identifier for each is provided to map to LIA-1.
21451 2   The FLT_ROUNDS parameter can be used to indicate the LIA-1 rounding styles:
21452     truncate      FLT_ROUNDS == 0
21453
21454
21455 [page 544]
21456
21457     nearest       FLT_ROUNDS == 1
21458     other         FLT_ROUNDS != 0 && FLT_ROUNDS != 1
21459     provided that an implementation extends FLT_ROUNDS to cover the rounding style used
21460     in all relevant LIA-1 operations, not just addition as in C.
21461     H.2.4 Type conversions
21462 1   The LIA-1 type conversions are the following type casts:
21463     cvtI' (->) I     (int)i, (long int)i, (long long int)i,
21464                   (unsigned int)i, (unsigned long int)i,
21465                   (unsigned long long int)i
21466     cvtF (->) I      (int)x, (long int)x, (long long int)x,
21467                   (unsigned int)x, (unsigned long int)x,
21468                   (unsigned long long int)x
21469     cvtI (->) F      (float)i, (double)i, (long double)i
21470     cvtF' (->) F     (float)x, (double)x, (long double)x
21471 2   In the above conversions from floating to integer, the use of (cast)x can be replaced with
21472     (cast)round(x), (cast)rint(x), (cast)nearbyint(x), (cast)trunc(x),
21473     (cast)ceil(x), or (cast)floor(x). In addition, C's floating-point to integer
21474     conversion functions, lrint(), llrint(), lround(), and llround(), can be
21475     used. They all meet LIA-1's requirements on floating to integer rounding for in-range
21476     values. For out-of-range values, the conversions shall silently wrap for the modulo types.
21477 3   The fmod() function is useful for doing silent wrapping to unsigned integer types, e.g.,
21478     fmod( fabs(rint(x)), 65536.0 ) or (0.0 <= (y = fmod( rint(x),
21479     65536.0 )) ? y : 65536.0 + y) will compute an integer value in the range 0.0
21480     to 65535.0 which can then be cast to unsigned short int. But, the
21481     remainder() function is not useful for doing silent wrapping to signed integer types,
21482     e.g., remainder( rint(x), 65536.0 ) will compute an integer value in the
21483     range -32767.0 to +32768.0 which is not, in general, in the range of signed short
21484     int.
21485 4   C's conversions (casts) from floating-point to floating-point can meet LIA-1
21486     requirements if an implementation uses round-to-nearest (IEC 60559 default).
21487 5   C's conversions (casts) from integer to floating-point can meet LIA-1 requirements if an
21488     implementation uses round-to-nearest.
21489
21490
21491
21492
21493 [page 545]
21494
21495     H.3 Notification
21496 1   Notification is the process by which a user or program is informed that an exceptional
21497     arithmetic operation has occurred. C's operations are compatible with LIA-1 in that C
21498     allows an implementation to cause a notification to occur when any arithmetic operation
21499     returns an exceptional value as defined in LIA-1 clause 5.
21500     H.3.1 Notification alternatives
21501 1   LIA-1 requires at least the following two alternatives for handling of notifications:
21502     setting indicators or trap-and-terminate. LIA-1 allows a third alternative: trap-and-
21503     resume.
21504 2   An implementation need only support a given notification alternative for the entire
21505     program. An implementation may support the ability to switch between notification
21506     alternatives during execution, but is not required to do so. An implementation can
21507     provide separate selection for each kind of notification, but this is not required.
21508 3   C allows an implementation to provide notification. C's SIGFPE (for traps) and
21509     FE_INVALID, FE_DIVBYZERO, FE_OVERFLOW, FE_UNDERFLOW (for indicators)
21510     can provide LIA-1 notification.
21511 4   C's signal handlers are compatible with LIA-1. Default handling of SIGFPE can
21512     provide trap-and-terminate behavior, except for those LIA-1 operations implemented by
21513     math library function calls. User-provided signal handlers for SIGFPE allow for trap-
21514     and-resume behavior with the same constraint.
21515     H.3.1.1 Indicators
21516 1   C's <fenv.h> status flags are compatible with the LIA-1 indicators.
21517 2   The following mapping is for floating-point types:
21518     undefined                FE_INVALID, FE_DIVBYZERO
21519     floating_overflow         FE_OVERFLOW
21520     underflow                FE_UNDERFLOW
21521 3   The floating-point indicator interrogation and manipulation operations are:
21522     set_indicators          feraiseexcept(i)
21523     clear_indicators        feclearexcept(i)
21524     test_indicators         fetestexcept(i)
21525     current_indicators      fetestexcept(FE_ALL_EXCEPT)
21526     where i is an expression of type int representing a subset of the LIA-1 indicators.
21527 4   C allows an implementation to provide the following LIA-1 required behavior: at
21528     program termination if any indicator is set the implementation shall send an unambiguous
21529 [page 546]
21530
21531     and ''hard to ignore'' message (see LIA-1 subclause 6.1.2)
21532 5   LIA-1 does not make the distinction between floating-point and integer for ''undefined''.
21533     This documentation makes that distinction because <fenv.h> covers only the floating-
21534     point indicators.
21535     H.3.1.2 Traps
21536 1   C is compatible with LIA-1's trap requirements for arithmetic operations, but not for
21537     math library functions (which are not permitted to invoke a user's signal handler for
21538     SIGFPE). An implementation can provide an alternative of notification through
21539     termination with a ''hard-to-ignore'' message (see LIA-1 subclause 6.1.3).
21540 2   LIA-1 does not require that traps be precise.
21541 3   C does require that SIGFPE be the signal corresponding to LIA-1 arithmetic exceptions,
21542     if there is any signal raised for them.
21543 4   C supports signal handlers for SIGFPE and allows trapping of LIA-1 arithmetic
21544     exceptions. When LIA-1 arithmetic exceptions do trap, C's signal-handler mechanism
21545     allows trap-and-terminate (either default implementation behavior or user replacement for
21546     it) or trap-and-resume, at the programmer's option.
21547
21548
21549
21550
21551 [page 547]
21552
21553                                            Annex I
21554                                         (informative)
21555                                    Common warnings
21556 1   An implementation may generate warnings in many situations, none of which are
21557     specified as part of this International Standard. The following are a few of the more
21558     common situations.
21559 2   -- A new struct or union type appears in a function prototype (6.2.1, 6.7.2.3).
21560     -- A block with initialization of an object that has automatic storage duration is jumped
21561       into (6.2.4).
21562     -- An implicit narrowing conversion is encountered, such as the assignment of a long
21563       int or a double to an int, or a pointer to void to a pointer to any type other than
21564       a character type (6.3).
21565     -- A hexadecimal floating constant cannot be represented exactly in its evaluation format
21566       (6.4.4.2).
21567     -- An integer character constant includes more than one character or a wide character
21568       constant includes more than one multibyte character (6.4.4.4).
21569     -- The characters /* are found in a comment (6.4.7).
21570     -- An ''unordered'' binary operator (not comma, &&, or ||) contains a side effect to an
21571       lvalue in one operand, and a side effect to, or an access to the value of, the identical
21572       lvalue in the other operand (6.5).
21573     -- A function is called but no prototype has been supplied (6.5.2.2).
21574     -- The arguments in a function call do not agree in number and type with those of the
21575       parameters in a function definition that is not a prototype (6.5.2.2).
21576     -- An object is defined but not used (6.7).
21577     -- A value is given to an object of an enumerated type other than by assignment of an
21578       enumeration constant that is a member of that type, or an enumeration object that has
21579       the same type, or the value of a function that returns the same enumerated type
21580       (6.7.2.2).
21581     -- An aggregate has a partly bracketed initialization (6.7.8).
21582     -- A statement cannot be reached (6.8).
21583     -- A statement with no apparent effect is encountered (6.8).
21584     -- A constant expression is used as the controlling expression of a selection statement
21585       (6.8.4).
21586 [page 548]
21587
21588 -- An incorrectly formed preprocessing group is encountered while skipping a
21589   preprocessing group (6.10.1).
21590 -- An unrecognized #pragma directive is encountered (6.10.6).
21591
21592
21593
21594
21595 [page 549]
21596
21597                                             Annex J
21598                                          (informative)
21599                                       Portability issues
21600 1   This annex collects some information about portability that appears in this International
21601     Standard.
21602     J.1 Unspecified behavior
21603 1   The following are unspecified:
21604     -- The manner and timing of static initialization (5.1.2).
21605     -- The termination status returned to the hosted environment if the return type of main
21606       is not compatible with int (5.1.2.2.3).
21607     -- The behavior of the display device if a printing character is written when the active
21608       position is at the final position of a line (5.2.2).
21609     -- The behavior of the display device if a backspace character is written when the active
21610       position is at the initial position of a line (5.2.2).
21611     -- The behavior of the display device if a horizontal tab character is written when the
21612       active position is at or past the last defined horizontal tabulation position (5.2.2).
21613     -- The behavior of the display device if a vertical tab character is written when the active
21614       position is at or past the last defined vertical tabulation position (5.2.2).
21615     -- How an extended source character that does not correspond to a universal character
21616       name counts toward the significant initial characters in an external identifier (5.2.4.1).
21617     -- Many aspects of the representations of types (6.2.6).
21618     -- The value of padding bytes when storing values in structures or unions (6.2.6.1).
21619     -- The values of bytes that correspond to union members other than the one last stored
21620       into (6.2.6.1).
21621     -- The representation used when storing a value in an object that has more than one
21622       object representation for that value (6.2.6.1).
21623     -- The values of any padding bits in integer representations (6.2.6.2).
21624     -- Whether certain operators can generate negative zeros and whether a negative zero
21625       becomes a normal zero when stored in an object (6.2.6.2).
21626     -- Whether two string literals result in distinct arrays (6.4.5).
21627     -- The order in which subexpressions are evaluated and the order in which side effects
21628       take place, except as specified for the function-call (), &&, ||, ? :, and comma
21629 [page 550]
21630
21631    operators (6.5).
21632 -- The order in which the function designator, arguments, and subexpressions within the
21633   arguments are evaluated in a function call (6.5.2.2).
21634 -- The order of side effects among compound literal initialization list expressions
21635   (6.5.2.5).
21636 -- The order in which the operands of an assignment operator are evaluated (6.5.16).
21637 -- The alignment of the addressable storage unit allocated to hold a bit-field (6.7.2.1).
21638 -- Whether a call to an inline function uses the inline definition or the external definition
21639   of the function (6.7.4).
21640 -- Whether or not a size expression is evaluated when it is part of the operand of a
21641   sizeof operator and changing the value of the size expression would not affect the
21642   result of the operator (6.7.6.2).
21643 -- The order in which any side effects occur among the initialization list expressions in
21644   an initializer (6.7.9).
21645 -- The layout of storage for function parameters (6.9.1).
21646 -- When a fully expanded macro replacement list contains a function-like macro name
21647   as its last preprocessing token and the next preprocessing token from the source file is
21648   a (, and the fully expanded replacement of that macro ends with the name of the first
21649   macro and the next preprocessing token from the source file is again a (, whether that
21650   is considered a nested replacement (6.10.3).
21651 -- The order in which # and ## operations are evaluated during macro substitution
21652   (6.10.3.2, 6.10.3.3).
21653 -- The state of the floating-point status flags when execution passes from a part of the *
21654   program translated with FENV_ACCESS ''off'' to a part translated with
21655   FENV_ACCESS ''on'' (7.6.1).
21656 -- The order in which feraiseexcept raises floating-point exceptions, except as
21657   stated in F.8.6 (7.6.2.3).
21658 -- Whether math_errhandling is a macro or an identifier with external linkage
21659   (7.12).
21660 -- The results of the frexp functions when the specified value is not a floating-point
21661   number (7.12.6.4).
21662 -- The numeric result of the ilogb functions when the correct value is outside the
21663   range of the return type (7.12.6.5, F.10.3.5).
21664 -- The result of rounding when the value is out of range (7.12.9.5, 7.12.9.7, F.10.6.5).
21665
21666
21667 [page 551]
21668
21669 -- The value stored by the remquo functions in the object pointed to by quo when y is
21670   zero (7.12.10.3).
21671 -- Whether a comparison macro argument that is represented in a format wider than its
21672   semantic type is converted to the semantic type (7.12.14).
21673 -- Whether setjmp is a macro or an identifier with external linkage (7.13).
21674 -- Whether va_copy and va_end are macros or identifiers with external linkage
21675   (7.16.1).
21676 -- The hexadecimal digit before the decimal point when a non-normalized floating-point
21677   number is printed with an a or A conversion specifier (7.21.6.1, 7.28.2.1).
21678 -- The value of the file position indicator after a successful call to the ungetc function
21679   for a text stream, or the ungetwc function for any stream, until all pushed-back
21680   characters are read or discarded (7.21.7.10, 7.28.3.10).
21681 -- The details of the value stored by the fgetpos function (7.21.9.1).
21682 -- The details of the value returned by the ftell function for a text stream (7.21.9.4).
21683 -- Whether the strtod, strtof, strtold, wcstod, wcstof, and wcstold
21684   functions convert a minus-signed sequence to a negative number directly or by
21685   negating the value resulting from converting the corresponding unsigned sequence
21686   (7.22.1.3, 7.28.4.1.1).
21687 -- The order and contiguity of storage allocated by successive calls to the calloc,
21688   malloc, and realloc functions (7.22.3).
21689 -- The amount of storage allocated by a successful call to the calloc, malloc, or
21690   realloc function when 0 bytes was requested (7.22.3).
21691 -- Which of two elements that compare as equal is matched by the bsearch function
21692   (7.22.5.1).
21693 -- The order of two elements that compare as equal in an array sorted by the qsort
21694   function (7.22.5.2).
21695 -- The encoding of the calendar time returned by the time function (7.26.2.4).
21696 -- The characters stored by the strftime or wcsftime function if any of the time
21697   values being converted is outside the normal range (7.26.3.5, 7.28.5.1).
21698 -- The conversion state after an encoding error occurs (7.28.6.3.2, 7.28.6.3.3, 7.28.6.4.1,
21699   7.28.6.4.2,
21700 -- The resulting value when the ''invalid'' floating-point exception is raised during
21701   IEC 60559 floating to integer conversion (F.4).
21702
21703
21704
21705 [page 552]
21706
21707     -- Whether conversion of non-integer IEC 60559 floating values to integer raises the
21708       ''inexact'' floating-point exception (F.4).
21709     -- Whether or when library functions in <math.h> raise the ''inexact'' floating-point
21710       exception in an IEC 60559 conformant implementation (F.10).
21711     -- Whether or when library functions in <math.h> raise an undeserved ''underflow''
21712       floating-point exception in an IEC 60559 conformant implementation (F.10).
21713     -- The exponent value stored by frexp for a NaN or infinity (F.10.3.4).
21714     -- The numeric result returned by the lrint, llrint, lround, and llround
21715       functions if the rounded value is outside the range of the return type (F.10.6.5,
21716       F.10.6.7).
21717     -- The sign of one part of the complex result of several math functions for certain
21718       special cases in IEC 60559 compatible implementations (G.6.1.1, G.6.2.2, G.6.2.3,
21719       G.6.2.4, G.6.2.5, G.6.2.6, G.6.3.1, G.6.4.2).
21720     J.2 Undefined behavior
21721 1   The behavior is undefined in the following circumstances:
21722     -- A ''shall'' or ''shall not'' requirement that appears outside of a constraint is violated
21723       (clause 4).
21724     -- A nonempty source file does not end in a new-line character which is not immediately
21725       preceded by a backslash character or ends in a partial preprocessing token or
21726       comment (5.1.1.2).
21727     -- Token concatenation produces a character sequence matching the syntax of a
21728       universal character name (5.1.1.2).
21729     -- A program in a hosted environment does not define a function named main using one
21730       of the specified forms (5.1.2.2.1).
21731     -- The execution of a program contains a data race (5.1.2.4).
21732     -- A character not in the basic source character set is encountered in a source file, except
21733       in an identifier, a character constant, a string literal, a header name, a comment, or a
21734       preprocessing token that is never converted to a token (5.2.1).
21735     -- An identifier, comment, string literal, character constant, or header name contains an
21736       invalid multibyte character or does not begin and end in the initial shift state (5.2.1.2).
21737     -- The same identifier has both internal and external linkage in the same translation unit
21738       (6.2.2).
21739     -- An object is referred to outside of its lifetime (6.2.4).
21740
21741
21742
21743 [page 553]
21744
21745 -- The value of a pointer to an object whose lifetime has ended is used (6.2.4).
21746 -- The value of an object with automatic storage duration is used while it is
21747   indeterminate (6.2.4, 6.7.9, 6.8).
21748 -- A trap representation is read by an lvalue expression that does not have character type
21749   (6.2.6.1).
21750 -- A trap representation is produced by a side effect that modifies any part of the object
21751   using an lvalue expression that does not have character type (6.2.6.1).
21752 -- The operands to certain operators are such that they could produce a negative zero
21753   result, but the implementation does not support negative zeros (6.2.6.2).
21754 -- Two declarations of the same object or function specify types that are not compatible
21755   (6.2.7).
21756 -- A program requires the formation of a composite type from a variable length array
21757   type whose size is specified by an expression that is not evaluated (6.2.7).
21758 -- Conversion to or from an integer type produces a value outside the range that can be
21759   represented (6.3.1.4).
21760 -- Demotion of one real floating type to another produces a value outside the range that
21761   can be represented (6.3.1.5).
21762 -- An lvalue does not designate an object when evaluated (6.3.2.1).
21763 -- A non-array lvalue with an incomplete type is used in a context that requires the value
21764   of the designated object (6.3.2.1).
21765 -- An lvalue designating an object of automatic storage duration that could have been
21766   declared with the register storage class is used in a context that requires the value
21767   of the designated object, but the object is uninitialized. (6.3.2.1).
21768 -- An lvalue having array type is converted to a pointer to the initial element of the
21769   array, and the array object has register storage class (6.3.2.1).
21770 -- An attempt is made to use the value of a void expression, or an implicit or explicit
21771   conversion (except to void) is applied to a void expression (6.3.2.2).
21772 -- Conversion of a pointer to an integer type produces a value outside the range that can
21773   be represented (6.3.2.3).
21774 -- Conversion between two pointer types produces a result that is incorrectly aligned
21775   (6.3.2.3).
21776 -- A pointer is used to call a function whose type is not compatible with the referenced
21777   type (6.3.2.3).
21778
21779
21780
21781 [page 554]
21782
21783 -- An unmatched ' or " character is encountered on a logical source line during
21784   tokenization (6.4).
21785 -- A reserved keyword token is used in translation phase 7 or 8 for some purpose other
21786   than as a keyword (6.4.1).
21787 -- A universal character name in an identifier does not designate a character whose
21788   encoding falls into one of the specified ranges (6.4.2.1).
21789 -- The initial character of an identifier is a universal character name designating a digit
21790   (6.4.2.1).
21791 -- Two identifiers differ only in nonsignificant characters (6.4.2.1).
21792 -- The identifier __func__ is explicitly declared (6.4.2.2).
21793 -- The program attempts to modify a string literal (6.4.5).
21794 -- The characters ', \, ", //, or /* occur in the sequence between the < and >
21795   delimiters, or the characters ', \, //, or /* occur in the sequence between the "
21796   delimiters, in a header name preprocessing token (6.4.7).
21797 -- A side effect on a scalar object is unsequenced relative to either a different side effect
21798   on the same scalar object or a value computation using the value of the same scalar
21799   object (6.5).
21800 -- An exceptional condition occurs during the evaluation of an expression (6.5).
21801 -- An object has its stored value accessed other than by an lvalue of an allowable type
21802   (6.5).
21803 -- For a call to a function without a function prototype in scope, the number of *
21804   arguments does not equal the number of parameters (6.5.2.2).
21805 -- For call to a function without a function prototype in scope where the function is
21806   defined with a function prototype, either the prototype ends with an ellipsis or the
21807   types of the arguments after promotion are not compatible with the types of the
21808   parameters (6.5.2.2).
21809 -- For a call to a function without a function prototype in scope where the function is not
21810   defined with a function prototype, the types of the arguments after promotion are not
21811   compatible with those of the parameters after promotion (with certain exceptions)
21812   (6.5.2.2).
21813 -- A function is defined with a type that is not compatible with the type (of the
21814   expression) pointed to by the expression that denotes the called function (6.5.2.2).
21815 -- A member of an atomic structure or union is accessed (6.5.2.3).
21816 -- The operand of the unary * operator has an invalid value (6.5.3.2).
21817
21818
21819 [page 555]
21820
21821 -- A pointer is converted to other than an integer or pointer type (6.5.4).
21822 -- The value of the second operand of the / or % operator is zero (6.5.5).
21823 -- Addition or subtraction of a pointer into, or just beyond, an array object and an
21824   integer type produces a result that does not point into, or just beyond, the same array
21825   object (6.5.6).
21826 -- Addition or subtraction of a pointer into, or just beyond, an array object and an
21827   integer type produces a result that points just beyond the array object and is used as
21828   the operand of a unary * operator that is evaluated (6.5.6).
21829 -- Pointers that do not point into, or just beyond, the same array object are subtracted
21830   (6.5.6).
21831 -- An array subscript is out of range, even if an object is apparently accessible with the
21832   given subscript (as in the lvalue expression a[1][7] given the declaration int
21833   a[4][5]) (6.5.6).
21834 -- The result of subtracting two pointers is not representable in an object of type
21835   ptrdiff_t (6.5.6).
21836 -- An expression is shifted by a negative number or by an amount greater than or equal
21837   to the width of the promoted expression (6.5.7).
21838 -- An expression having signed promoted type is left-shifted and either the value of the
21839   expression is negative or the result of shifting would be not be representable in the
21840   promoted type (6.5.7).
21841 -- Pointers that do not point to the same aggregate or union (nor just beyond the same
21842   array object) are compared using relational operators (6.5.8).
21843 -- An object is assigned to an inexactly overlapping object or to an exactly overlapping
21844   object with incompatible type (6.5.16.1).
21845 -- An expression that is required to be an integer constant expression does not have an
21846   integer type; has operands that are not integer constants, enumeration constants,
21847   character constants, sizeof expressions whose results are integer constants, or
21848   immediately-cast floating constants; or contains casts (outside operands to sizeof
21849   operators) other than conversions of arithmetic types to integer types (6.6).
21850 -- A constant expression in an initializer is not, or does not evaluate to, one of the
21851   following: an arithmetic constant expression, a null pointer constant, an address
21852   constant, or an address constant for a complete object type plus or minus an integer
21853   constant expression (6.6).
21854 -- An arithmetic constant expression does not have arithmetic type; has operands that
21855   are not integer constants, floating constants, enumeration constants, character
21856   constants, or sizeof expressions; or contains casts (outside operands to sizeof
21857
21858 [page 556]
21859
21860    operators) other than conversions of arithmetic types to arithmetic types (6.6).
21861 -- The value of an object is accessed by an array-subscript [], member-access . or ->,
21862   address &, or indirection * operator or a pointer cast in creating an address constant
21863   (6.6).
21864 -- An identifier for an object is declared with no linkage and the type of the object is
21865   incomplete after its declarator, or after its init-declarator if it has an initializer (6.7).
21866 -- A function is declared at block scope with an explicit storage-class specifier other
21867   than extern (6.7.1).
21868 -- A structure or union is defined as containing no named members, no anonymous
21869   structures, and no anonymous unions (6.7.2.1).
21870 -- An attempt is made to access, or generate a pointer to just past, a flexible array
21871   member of a structure when the referenced object provides no elements for that array
21872   (6.7.2.1).
21873 -- When the complete type is needed, an incomplete structure or union type is not
21874   completed in the same scope by another declaration of the tag that defines the content
21875   (6.7.2.3).
21876 -- An attempt is made to modify an object defined with a const-qualified type through
21877   use of an lvalue with non-const-qualified type (6.7.3).
21878 -- An attempt is made to refer to an object defined with a volatile-qualified type through
21879   use of an lvalue with non-volatile-qualified type (6.7.3).
21880 -- The specification of a function type includes any type qualifiers (6.7.3).                        *
21881 -- Two qualified types that are required to be compatible do not have the identically
21882   qualified version of a compatible type (6.7.3).
21883 -- An object which has been modified is accessed through a restrict-qualified pointer to
21884   a const-qualified type, or through a restrict-qualified pointer and another pointer that
21885   are not both based on the same object (6.7.3.1).
21886 -- A restrict-qualified pointer is assigned a value based on another restricted pointer
21887   whose associated block neither began execution before the block associated with this
21888   pointer, nor ended before the assignment (6.7.3.1).
21889 -- A function with external linkage is declared with an inline function specifier, but is
21890   not also defined in the same translation unit (6.7.4).
21891 -- A function declared with a _Noreturn function specifier returns to its caller (6.7.4).
21892 -- The definition of an object has an alignment specifier and another declaration of that
21893   object has a different alignment specifier (6.7.5).
21894
21895
21896 [page 557]
21897
21898 -- Declarations of an object in different translation units have different alignment
21899   specifiers (6.7.5).
21900 -- Two pointer types that are required to be compatible are not identically qualified, or
21901   are not pointers to compatible types (6.7.6.1).
21902 -- The size expression in an array declaration is not a constant expression and evaluates
21903   at program execution time to a nonpositive value (6.7.6.2).
21904 -- In a context requiring two array types to be compatible, they do not have compatible
21905   element types, or their size specifiers evaluate to unequal values (6.7.6.2).
21906 -- A declaration of an array parameter includes the keyword static within the [ and
21907   ] and the corresponding argument does not provide access to the first element of an
21908   array with at least the specified number of elements (6.7.6.3).
21909 -- A storage-class specifier or type qualifier modifies the keyword void as a function
21910   parameter type list (6.7.6.3).
21911 -- In a context requiring two function types to be compatible, they do not have
21912   compatible return types, or their parameters disagree in use of the ellipsis terminator
21913   or the number and type of parameters (after default argument promotion, when there
21914   is no parameter type list or when one type is specified by a function definition with an
21915   identifier list) (6.7.6.3).
21916 -- The value of an unnamed member of a structure or union is used (6.7.9).
21917 -- The initializer for a scalar is neither a single expression nor a single expression
21918   enclosed in braces (6.7.9).
21919 -- The initializer for a structure or union object that has automatic storage duration is
21920   neither an initializer list nor a single expression that has compatible structure or union
21921   type (6.7.9).
21922 -- The initializer for an aggregate or union, other than an array initialized by a string
21923   literal, is not a brace-enclosed list of initializers for its elements or members (6.7.9).
21924 -- An identifier with external linkage is used, but in the program there does not exist
21925   exactly one external definition for the identifier, or the identifier is not used and there
21926   exist multiple external definitions for the identifier (6.9).
21927 -- A function definition includes an identifier list, but the types of the parameters are not
21928   declared in a following declaration list (6.9.1).
21929 -- An adjusted parameter type in a function definition is not a complete object type
21930   (6.9.1).
21931 -- A function that accepts a variable number of arguments is defined without a
21932   parameter type list that ends with the ellipsis notation (6.9.1).
21933
21934 [page 558]
21935
21936 -- The } that terminates a function is reached, and the value of the function call is used
21937   by the caller (6.9.1).
21938 -- An identifier for an object with internal linkage and an incomplete type is declared
21939   with a tentative definition (6.9.2).
21940 -- The token defined is generated during the expansion of a #if or #elif
21941   preprocessing directive, or the use of the defined unary operator does not match
21942   one of the two specified forms prior to macro replacement (6.10.1).
21943 -- The #include preprocessing directive that results after expansion does not match
21944   one of the two header name forms (6.10.2).
21945 -- The character sequence in an #include preprocessing directive does not start with a
21946   letter (6.10.2).
21947 -- There are sequences of preprocessing tokens within the list of macro arguments that
21948   would otherwise act as preprocessing directives (6.10.3).
21949 -- The result of the preprocessing operator # is not a valid character string literal
21950   (6.10.3.2).
21951 -- The result of the preprocessing operator ## is not a valid preprocessing token
21952   (6.10.3.3).
21953 -- The #line preprocessing directive that results after expansion does not match one of
21954   the two well-defined forms, or its digit sequence specifies zero or a number greater
21955   than 2147483647 (6.10.4).
21956 -- A non-STDC #pragma preprocessing directive that is documented as causing
21957   translation failure or some other form of undefined behavior is encountered (6.10.6).
21958 -- A #pragma STDC preprocessing directive does not match one of the well-defined
21959   forms (6.10.6).
21960 -- The name of a predefined macro, or the identifier defined, is the subject of a
21961   #define or #undef preprocessing directive (6.10.8).
21962 -- An attempt is made to copy an object to an overlapping object by use of a library
21963   function, other than as explicitly allowed (e.g., memmove) (clause 7).
21964 -- A file with the same name as one of the standard headers, not provided as part of the
21965   implementation, is placed in any of the standard places that are searched for included
21966   source files (7.1.2).
21967 -- A header is included within an external declaration or definition (7.1.2).
21968 -- A function, object, type, or macro that is specified as being declared or defined by
21969   some standard header is used before any header that declares or defines it is included
21970   (7.1.2).
21971
21972 [page 559]
21973
21974 -- A standard header is included while a macro is defined with the same name as a
21975   keyword (7.1.2).
21976 -- The program attempts to declare a library function itself, rather than via a standard
21977   header, but the declaration does not have external linkage (7.1.2).
21978 -- The program declares or defines a reserved identifier, other than as allowed by 7.1.4
21979   (7.1.3).
21980 -- The program removes the definition of a macro whose name begins with an
21981   underscore and either an uppercase letter or another underscore (7.1.3).
21982 -- An argument to a library function has an invalid value or a type not expected by a
21983   function with variable number of arguments (7.1.4).
21984 -- The pointer passed to a library function array parameter does not have a value such
21985   that all address computations and object accesses are valid (7.1.4).
21986 -- The macro definition of assert is suppressed in order to access an actual function
21987   (7.2).
21988 -- The argument to the assert macro does not have a scalar type (7.2).
21989 -- The CX_LIMITED_RANGE, FENV_ACCESS, or FP_CONTRACT pragma is used in
21990   any context other than outside all external declarations or preceding all explicit
21991   declarations and statements inside a compound statement (7.3.4, 7.6.1, 7.12.2).
21992 -- The value of an argument to a character handling function is neither equal to the value
21993   of EOF nor representable as an unsigned char (7.4).
21994 -- A macro definition of errno is suppressed in order to access an actual object, or the
21995   program defines an identifier with the name errno (7.5).
21996 -- Part of the program tests floating-point status flags, sets floating-point control modes,
21997   or runs under non-default mode settings, but was translated with the state for the
21998   FENV_ACCESS pragma ''off'' (7.6.1).
21999 -- The exception-mask argument for one of the functions that provide access to the
22000   floating-point status flags has a nonzero value not obtained by bitwise OR of the
22001   floating-point exception macros (7.6.2).
22002 -- The fesetexceptflag function is used to set floating-point status flags that were
22003   not specified in the call to the fegetexceptflag function that provided the value
22004   of the corresponding fexcept_t object (7.6.2.4).
22005 -- The argument to fesetenv or feupdateenv is neither an object set by a call to
22006   fegetenv or feholdexcept, nor is it an environment macro (7.6.4.3, 7.6.4.4).
22007 -- The value of the result of an integer arithmetic or conversion function cannot be
22008   represented (7.8.2.1, 7.8.2.2, 7.8.2.3, 7.8.2.4, 7.22.6.1, 7.22.6.2, 7.22.1).
22009
22010 [page 560]
22011
22012 -- The program modifies the string pointed to by the value returned by the setlocale
22013   function (7.11.1.1).
22014 -- The program modifies the structure pointed to by the value returned by the
22015   localeconv function (7.11.2.1).
22016 -- A macro definition of math_errhandling is suppressed or the program defines
22017   an identifier with the name math_errhandling (7.12).
22018 -- An argument to a floating-point classification or comparison macro is not of real
22019   floating type (7.12.3, 7.12.14).
22020 -- A macro definition of setjmp is suppressed in order to access an actual function, or
22021   the program defines an external identifier with the name setjmp (7.13).
22022 -- An invocation of the setjmp macro occurs other than in an allowed context
22023   (7.13.2.1).
22024 -- The longjmp function is invoked to restore a nonexistent environment (7.13.2.1).
22025 -- After a longjmp, there is an attempt to access the value of an object of automatic
22026   storage duration that does not have volatile-qualified type, local to the function
22027   containing the invocation of the corresponding setjmp macro, that was changed
22028   between the setjmp invocation and longjmp call (7.13.2.1).
22029 -- The program specifies an invalid pointer to a signal handler function (7.14.1.1).
22030 -- A signal handler returns when the signal corresponded to a computational exception
22031   (7.14.1.1).
22032 -- A signal occurs as the result of calling the abort or raise function, and the signal
22033   handler calls the raise function (7.14.1.1).
22034 -- A signal occurs other than as the result of calling the abort or raise function, and
22035   the signal handler refers to an object with static or thread storage duration that is not a
22036   lock-free atomic object other than by assigning a value to an object declared as
22037   volatile sig_atomic_t, or calls any function in the standard library other
22038   than the abort function, the _Exit function, the quick_exit function, or the
22039   signal function (for the same signal number) (7.14.1.1).
22040 -- The value of errno is referred to after a signal occurred other than as the result of
22041   calling the abort or raise function and the corresponding signal handler obtained
22042   a SIG_ERR return from a call to the signal function (7.14.1.1).
22043 -- A signal is generated by an asynchronous signal handler (7.14.1.1).
22044 -- A function with a variable number of arguments attempts to access its varying
22045   arguments other than through a properly declared and initialized va_list object, or
22046   before the va_start macro is invoked (7.16, 7.16.1.1, 7.16.1.4).
22047
22048 [page 561]
22049
22050 -- The macro va_arg is invoked using the parameter ap that was passed to a function
22051   that invoked the macro va_arg with the same parameter (7.16).
22052 -- A macro definition of va_start, va_arg, va_copy, or va_end is suppressed in
22053   order to access an actual function, or the program defines an external identifier with
22054   the name va_copy or va_end (7.16.1).
22055 -- The va_start or va_copy macro is invoked without a corresponding invocation
22056   of the va_end macro in the same function, or vice versa (7.16.1, 7.16.1.2, 7.16.1.3,
22057   7.16.1.4).
22058 -- The type parameter to the va_arg macro is not such that a pointer to an object of
22059   that type can be obtained simply by postfixing a * (7.16.1.1).
22060 -- The va_arg macro is invoked when there is no actual next argument, or with a
22061   specified type that is not compatible with the promoted type of the actual next
22062   argument, with certain exceptions (7.16.1.1).
22063 -- The va_copy or va_start macro is called to initialize a va_list that was
22064   previously initialized by either macro without an intervening invocation of the
22065   va_end macro for the same va_list (7.16.1.2, 7.16.1.4).
22066 -- The parameter parmN of a va_start macro is declared with the register
22067   storage class, with a function or array type, or with a type that is not compatible with
22068   the type that results after application of the default argument promotions (7.16.1.4).
22069 -- The member designator parameter of an offsetof macro is an invalid right
22070   operand of the . operator for the type parameter, or designates a bit-field (7.19).
22071 -- The argument in an instance of one of the integer-constant macros is not a decimal,
22072   octal, or hexadecimal constant, or it has a value that exceeds the limits for the
22073   corresponding type (7.20.4).
22074 -- A byte input/output function is applied to a wide-oriented stream, or a wide character
22075   input/output function is applied to a byte-oriented stream (7.21.2).
22076 -- Use is made of any portion of a file beyond the most recent wide character written to
22077   a wide-oriented stream (7.21.2).
22078 -- The value of a pointer to a FILE object is used after the associated file is closed
22079   (7.21.3).
22080 -- The stream for the fflush function points to an input stream or to an update stream
22081   in which the most recent operation was input (7.21.5.2).
22082 -- The string pointed to by the mode argument in a call to the fopen function does not
22083   exactly match one of the specified character sequences (7.21.5.3).
22084 -- An output operation on an update stream is followed by an input operation without an
22085     intervening call to the fflush function or a file positioning function, or an input
22086 [page 562]
22087
22088    operation on an update stream is followed by an output operation with an intervening
22089    call to a file positioning function (7.21.5.3).
22090 -- An attempt is made to use the contents of the array that was supplied in a call to the
22091   setvbuf function (7.21.5.6).
22092 -- There are insufficient arguments for the format in a call to one of the formatted
22093   input/output functions, or an argument does not have an appropriate type (7.21.6.1,
22094   7.21.6.2, 7.28.2.1, 7.28.2.2).
22095 -- The format in a call to one of the formatted input/output functions or to the
22096   strftime or wcsftime function is not a valid multibyte character sequence that
22097   begins and ends in its initial shift state (7.21.6.1, 7.21.6.2, 7.26.3.5, 7.28.2.1, 7.28.2.2,
22098   7.28.5.1).
22099 -- In a call to one of the formatted output functions, a precision appears with a
22100   conversion specifier other than those described (7.21.6.1, 7.28.2.1).
22101 -- A conversion specification for a formatted output function uses an asterisk to denote
22102   an argument-supplied field width or precision, but the corresponding argument is not
22103   provided (7.21.6.1, 7.28.2.1).
22104 -- A conversion specification for a formatted output function uses a # or 0 flag with a
22105   conversion specifier other than those described (7.21.6.1, 7.28.2.1).
22106 -- A conversion specification for one of the formatted input/output functions uses a
22107   length modifier with a conversion specifier other than those described (7.21.6.1,
22108   7.21.6.2, 7.28.2.1, 7.28.2.2).
22109 -- An s conversion specifier is encountered by one of the formatted output functions,
22110   and the argument is missing the null terminator (unless a precision is specified that
22111   does not require null termination) (7.21.6.1, 7.28.2.1).
22112 -- An n conversion specification for one of the formatted input/output functions includes
22113   any flags, an assignment-suppressing character, a field width, or a precision (7.21.6.1,
22114   7.21.6.2, 7.28.2.1, 7.28.2.2).
22115 -- A % conversion specifier is encountered by one of the formatted input/output
22116   functions, but the complete conversion specification is not exactly %% (7.21.6.1,
22117   7.21.6.2, 7.28.2.1, 7.28.2.2).
22118 -- An invalid conversion specification is found in the format for one of the formatted
22119   input/output functions, or the strftime or wcsftime function (7.21.6.1, 7.21.6.2,
22120   7.26.3.5, 7.28.2.1, 7.28.2.2, 7.28.5.1).
22121 -- The number of characters transmitted by a formatted output function is greater than
22122   INT_MAX (7.21.6.1, 7.21.6.3, 7.21.6.8, 7.21.6.10).
22123
22124
22125 [page 563]
22126
22127 -- The result of a conversion by one of the formatted input functions cannot be
22128   represented in the corresponding object, or the receiving object does not have an
22129   appropriate type (7.21.6.2, 7.28.2.2).
22130 -- A c, s, or [ conversion specifier is encountered by one of the formatted input
22131   functions, and the array pointed to by the corresponding argument is not large enough
22132   to accept the input sequence (and a null terminator if the conversion specifier is s or
22133   [) (7.21.6.2, 7.28.2.2).
22134 -- A c, s, or [ conversion specifier with an l qualifier is encountered by one of the
22135   formatted input functions, but the input is not a valid multibyte character sequence
22136   that begins in the initial shift state (7.21.6.2, 7.28.2.2).
22137 -- The input item for a %p conversion by one of the formatted input functions is not a
22138   value converted earlier during the same program execution (7.21.6.2, 7.28.2.2).
22139 -- The vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf,
22140   vsscanf, vfwprintf, vfwscanf, vswprintf, vswscanf, vwprintf, or
22141   vwscanf function is called with an improperly initialized va_list argument, or
22142   the argument is used (other than in an invocation of va_end) after the function
22143   returns (7.21.6.8, 7.21.6.9, 7.21.6.10, 7.21.6.11, 7.21.6.12, 7.21.6.13, 7.21.6.14,
22144   7.28.2.5, 7.28.2.6, 7.28.2.7, 7.28.2.8, 7.28.2.9, 7.28.2.10).
22145 -- The contents of the array supplied in a call to the fgets or fgetws function are
22146   used after a read error occurred (7.21.7.2, 7.28.3.2).
22147 -- The file position indicator for a binary stream is used after a call to the ungetc
22148   function where its value was zero before the call (7.21.7.10).
22149 -- The file position indicator for a stream is used after an error occurred during a call to
22150   the fread or fwrite function (7.21.8.1, 7.21.8.2).
22151 -- A partial element read by a call to the fread function is used (7.21.8.1).
22152 -- The fseek function is called for a text stream with a nonzero offset and either the
22153   offset was not returned by a previous successful call to the ftell function on a
22154   stream associated with the same file or whence is not SEEK_SET (7.21.9.2).
22155 -- The fsetpos function is called to set a position that was not returned by a previous
22156   successful call to the fgetpos function on a stream associated with the same file
22157   (7.21.9.3).
22158 -- A non-null pointer returned by a call to the calloc, malloc, or realloc function
22159   with a zero requested size is used to access an object (7.22.3).
22160 -- The value of a pointer that refers to space deallocated by a call to the free or
22161   realloc function is used (7.22.3).
22162
22163
22164 [page 564]
22165
22166 -- The alignment requested of the aligned_alloc function is not valid or not
22167   supported by the implementation, or the size requested is not an integral multiple of
22168   the alignment (7.22.3.1).
22169 -- The pointer argument to the free or realloc function does not match a pointer
22170   earlier returned by a memory management function, or the space has been deallocated
22171   by a call to free or realloc (7.22.3.3, 7.22.3.5).
22172 -- The value of the object allocated by the malloc function is used (7.22.3.4).
22173 -- The value of any bytes in a new object allocated by the realloc function beyond
22174   the size of the old object are used (7.22.3.5).
22175 -- The program calls the exit or quick_exit function more than once, or calls both
22176   functions (7.22.4.4, 7.22.4.7).
22177 -- During the call to a function registered with the atexit or at_quick_exit
22178   function, a call is made to the longjmp function that would terminate the call to the
22179   registered function (7.22.4.4, 7.22.4.7).
22180 -- The string set up by the getenv or strerror function is modified by the program
22181   (7.22.4.6, 7.23.6.2).
22182 -- A command is executed through the system function in a way that is documented as
22183   causing termination or some other form of undefined behavior (7.22.4.8).
22184 -- A searching or sorting utility function is called with an invalid pointer argument, even
22185   if the number of elements is zero (7.22.5).
22186 -- The comparison function called by a searching or sorting utility function alters the
22187   contents of the array being searched or sorted, or returns ordering values
22188   inconsistently (7.22.5).
22189 -- The array being searched by the bsearch function does not have its elements in
22190   proper order (7.22.5.1).
22191 -- The current conversion state is used by a multibyte/wide character conversion
22192   function after changing the LC_CTYPE category (7.22.7).
22193 -- A string or wide string utility function is instructed to access an array beyond the end
22194   of an object (7.23.1, 7.28.4).
22195 -- A string or wide string utility function is called with an invalid pointer argument, even
22196   if the length is zero (7.23.1, 7.28.4).
22197 -- The contents of the destination array are used after a call to the strxfrm,
22198   strftime, wcsxfrm, or wcsftime function in which the specified length was
22199   too small to hold the entire null-terminated result (7.23.4.5, 7.26.3.5, 7.28.4.4.4,
22200   7.28.5.1).
22201
22202 [page 565]
22203
22204     -- The first argument in the very first call to the strtok or wcstok is a null pointer
22205       (7.23.5.8, 7.28.4.5.7).
22206     -- The type of an argument to a type-generic macro is not compatible with the type of
22207       the corresponding parameter of the selected function (7.24).
22208     -- A complex argument is supplied for a generic parameter of a type-generic macro that
22209       has no corresponding complex function (7.24).
22210     -- At least one field of the broken-down time passed to asctime contains a value
22211       outside its normal range, or the calculated year exceeds four digits or is less than the
22212       year 1000 (7.26.3.1).
22213     -- The argument corresponding to an s specifier without an l qualifier in a call to the
22214       fwprintf function does not point to a valid multibyte character sequence that
22215       begins in the initial shift state (7.28.2.11).
22216     -- In a call to the wcstok function, the object pointed to by ptr does not have the
22217       value stored by the previous call for the same wide string (7.28.4.5.7).
22218     -- An mbstate_t object is used inappropriately (7.28.6).
22219     -- The value of an argument of type wint_t to a wide character classification or case
22220       mapping function is neither equal to the value of WEOF nor representable as a
22221       wchar_t (7.29.1).
22222     -- The iswctype function is called using a different LC_CTYPE category from the
22223       one in effect for the call to the wctype function that returned the description
22224       (7.29.2.2.1).
22225     -- The towctrans function is called using a different LC_CTYPE category from the
22226       one in effect for the call to the wctrans function that returned the description
22227       (7.29.3.2.1).
22228     J.3 Implementation-defined behavior
22229 1   A conforming implementation is required to document its choice of behavior in each of
22230     the areas listed in this subclause. The following are implementation-defined:
22231
22232
22233
22234
22235 [page 566]
22236
22237     J.3.1 Translation
22238 1   -- How a diagnostic is identified (3.10, 5.1.1.3).
22239     -- Whether each nonempty sequence of white-space characters other than new-line is
22240       retained or replaced by one space character in translation phase 3 (5.1.1.2).
22241     J.3.2 Environment
22242 1   -- The mapping between physical source file multibyte characters and the source
22243       character set in translation phase 1 (5.1.1.2).
22244     -- The name and type of the function called at program startup in a freestanding
22245       environment (5.1.2.1).
22246     -- The effect of program termination in a freestanding environment (5.1.2.1).
22247     -- An alternative manner in which the main function may be defined (5.1.2.2.1).
22248     -- The values given to the strings pointed to by the argv argument to main (5.1.2.2.1).
22249     -- What constitutes an interactive device (5.1.2.3).
22250     -- Whether a program can have more than one thread of execution in a freestanding
22251       environment (5.1.2.4).
22252     -- The set of signals, their semantics, and their default handling (7.14).
22253     -- Signal values other than SIGFPE, SIGILL, and SIGSEGV that correspond to a
22254       computational exception (7.14.1.1).
22255     -- Signals for which the equivalent of signal(sig, SIG_IGN); is executed at
22256       program startup (7.14.1.1).
22257     -- The set of environment names and the method for altering the environment list used
22258       by the getenv function (7.22.4.6).
22259     -- The manner of execution of the string by the system function (7.22.4.8).
22260     J.3.3 Identifiers
22261 1   -- Which additional multibyte characters may appear in identifiers and their
22262       correspondence to universal character names (6.4.2).
22263     -- The number of significant initial characters in an identifier (5.2.4.1, 6.4.2).
22264
22265
22266
22267
22268 [page 567]
22269
22270     J.3.4 Characters
22271 1   -- The number of bits in a byte (3.6).
22272     -- The values of the members of the execution character set (5.2.1).
22273     -- The unique value of the member of the execution character set produced for each of
22274       the standard alphabetic escape sequences (5.2.2).
22275     -- The value of a char object into which has been stored any character other than a
22276       member of the basic execution character set (6.2.5).
22277     -- Which of signed char or unsigned char has the same range, representation,
22278       and behavior as ''plain'' char (6.2.5, 6.3.1.1).
22279     -- The mapping of members of the source character set (in character constants and string
22280       literals) to members of the execution character set (6.4.4.4, 5.1.1.2).
22281     -- The value of an integer character constant containing more than one character or
22282       containing a character or escape sequence that does not map to a single-byte
22283       execution character (6.4.4.4).
22284     -- The value of a wide character constant containing more than one multibyte character
22285       or a single multibyte character that maps to multiple members of the extended
22286       execution character set, or containing a multibyte character or escape sequence not
22287       represented in the extended execution character set (6.4.4.4).
22288     -- The current locale used to convert a wide character constant consisting of a single
22289       multibyte character that maps to a member of the extended execution character set
22290       into a corresponding wide character code (6.4.4.4).
22291     -- Whether differently-prefixed wide string literal tokens can be concatenated and, if so,
22292       the treatment of the resulting multibyte character sequence (6.4.5).
22293     -- The current locale used to convert a wide string literal into corresponding wide
22294       character codes (6.4.5).
22295     -- The value of a string literal containing a multibyte character or escape sequence not
22296       represented in the execution character set (6.4.5).
22297     -- The encoding of any of wchar_t, char16_t, and char32_t where the
22298       corresponding  standard   encoding macro      (__STDC_ISO_10646__,
22299       __STDC_UTF_16__, or __STDC_UTF_32__) is not defined (6.10.8.2).
22300
22301
22302
22303
22304 [page 568]
22305
22306     J.3.5 Integers
22307 1   -- Any extended integer types that exist in the implementation (6.2.5).
22308     -- Whether signed integer types are represented using sign and magnitude, two's
22309       complement, or ones' complement, and whether the extraordinary value is a trap
22310       representation or an ordinary value (6.2.6.2).
22311     -- The rank of any extended integer type relative to another extended integer type with
22312       the same precision (6.3.1.1).
22313     -- The result of, or the signal raised by, converting an integer to a signed integer type
22314       when the value cannot be represented in an object of that type (6.3.1.3).
22315     -- The results of some bitwise operations on signed integers (6.5).
22316     J.3.6 Floating point
22317 1   -- The accuracy of the floating-point operations and of the library functions in
22318       <math.h> and <complex.h> that return floating-point results (5.2.4.2.2).
22319     -- The accuracy of the conversions between floating-point internal representations and
22320       string representations performed by the library functions in <stdio.h>,
22321       <stdlib.h>, and <wchar.h> (5.2.4.2.2).
22322     -- The rounding behaviors characterized by non-standard values of FLT_ROUNDS
22323       (5.2.4.2.2).
22324     -- The evaluation methods characterized by non-standard negative values of
22325       FLT_EVAL_METHOD (5.2.4.2.2).
22326     -- The direction of rounding when an integer is converted to a floating-point number that
22327       cannot exactly represent the original value (6.3.1.4).
22328     -- The direction of rounding when a floating-point number is converted to a narrower
22329       floating-point number (6.3.1.5).
22330     -- How the nearest representable value or the larger or smaller representable value
22331       immediately adjacent to the nearest representable value is chosen for certain floating
22332       constants (6.4.4.2).
22333     -- Whether and how floating expressions are contracted when not disallowed by the
22334       FP_CONTRACT pragma (6.5).
22335     -- The default state for the FENV_ACCESS pragma (7.6.1).
22336     -- Additional floating-point exceptions, rounding           modes,     environments,   and
22337       classifications, and their macro names (7.6, 7.12).
22338     -- The default state for the FP_CONTRACT pragma (7.12.2).
22339
22340
22341 [page 569]
22342
22343     J.3.7 Arrays and pointers
22344 1   -- The result of converting a pointer to an integer or vice versa (6.3.2.3).
22345     -- The size of the result of subtracting two pointers to elements of the same array
22346       (6.5.6).
22347     J.3.8 Hints
22348 1   -- The extent to which suggestions made by using the register storage-class
22349       specifier are effective (6.7.1).
22350     -- The extent to which suggestions made by using the inline function specifier are
22351       effective (6.7.4).
22352     J.3.9 Structures, unions, enumerations, and bit-fields
22353 1   -- Whether a ''plain'' int bit-field is treated as a signed int bit-field or as an
22354       unsigned int bit-field (6.7.2, 6.7.2.1).
22355     -- Allowable bit-field types other than _Bool, signed int, and unsigned int
22356       (6.7.2.1).
22357     -- Whether atomic types are permitted for bit-fields (6.7.2.1).
22358     -- Whether a bit-field can straddle a storage-unit boundary (6.7.2.1).
22359     -- The order of allocation of bit-fields within a unit (6.7.2.1).
22360     -- The alignment of non-bit-field members of structures (6.7.2.1). This should present
22361       no problem unless binary data written by one implementation is read by another.
22362     -- The integer type compatible with each enumerated type (6.7.2.2).
22363     J.3.10 Qualifiers
22364 1   -- What constitutes an access to an object that has volatile-qualified type (6.7.3).
22365     J.3.11 Preprocessing directives
22366 1   -- The locations within #pragma directives where header name preprocessing tokens
22367       are recognized (6.4, 6.4.7).
22368     -- How sequences in both forms of header names are mapped to headers or external
22369       source file names (6.4.7).
22370     -- Whether the value of a character constant in a constant expression that controls
22371       conditional inclusion matches the value of the same character constant in the
22372       execution character set (6.10.1).
22373     -- Whether the value of a single-character character constant in a constant expression
22374       that controls conditional inclusion may have a negative value (6.10.1).
22375
22376
22377 [page 570]
22378
22379     -- The places that are searched for an included < > delimited header, and how the places
22380       are specified or the header is identified (6.10.2).
22381     -- How the named source file is searched for in an included " " delimited header
22382       (6.10.2).
22383     -- The method by which preprocessing tokens (possibly resulting from macro
22384       expansion) in a #include directive are combined into a header name (6.10.2).
22385     -- The nesting limit for #include processing (6.10.2).
22386     -- Whether the # operator inserts a \ character before the \ character that begins a
22387       universal character name in a character constant or string literal (6.10.3.2).
22388     -- The behavior on each recognized non-STDC #pragma directive (6.10.6).
22389     -- The definitions for __DATE__ and __TIME__ when respectively, the date and
22390       time of translation are not available (6.10.8.1).
22391     J.3.12 Library functions
22392 1   -- Any library facilities available to a freestanding program, other than the minimal set
22393       required by clause 4 (5.1.2.1).
22394     -- The format of the diagnostic printed by the assert macro (7.2.1.1).
22395     -- The representation of the floating-point               status   flags   stored   by   the
22396       fegetexceptflag function (7.6.2.2).
22397     -- Whether the feraiseexcept function raises the ''inexact'' floating-point
22398       exception in addition to the ''overflow'' or ''underflow'' floating-point exception
22399       (7.6.2.3).
22400     -- Strings other than "C" and "" that may be passed as the second argument to the
22401       setlocale function (7.11.1.1).
22402     -- The types defined for float_t and double_t when the value of the
22403       FLT_EVAL_METHOD macro is less than 0 (7.12).
22404     -- Domain errors for the mathematics functions, other than those required by this
22405       International Standard (7.12.1).
22406     -- The values returned by the mathematics functions on domain errors or pole errors
22407       (7.12.1).
22408     -- The values returned by the mathematics functions on underflow range errors, whether
22409       errno is set to the value of the macro ERANGE when the integer expression
22410       math_errhandling & MATH_ERRNO is nonzero, and whether the ''underflow''
22411       floating-point exception is raised when the integer expression math_errhandling
22412       & MATH_ERREXCEPT is nonzero. (7.12.1).
22413
22414 [page 571]
22415
22416 -- Whether a domain error occurs or zero is returned when an fmod function has a
22417   second argument of zero (7.12.10.1).
22418 -- Whether a domain error occurs or zero is returned when a remainder function has
22419   a second argument of zero (7.12.10.2).
22420 -- The base-2 logarithm of the modulus used by the remquo functions in reducing the
22421   quotient (7.12.10.3).
22422 -- Whether a domain error occurs or zero is returned when a remquo function has a
22423   second argument of zero (7.12.10.3).
22424 -- Whether the equivalent of signal(sig, SIG_DFL); is executed prior to the call
22425   of a signal handler, and, if not, the blocking of signals that is performed (7.14.1.1).
22426 -- The null pointer constant to which the macro NULL expands (7.19).
22427 -- Whether the last line of a text stream requires a terminating new-line character
22428   (7.21.2).
22429 -- Whether space characters that are written out to a text stream immediately before a
22430   new-line character appear when read in (7.21.2).
22431 -- The number of null characters that may be appended to data written to a binary
22432   stream (7.21.2).
22433 -- Whether the file position indicator of an append-mode stream is initially positioned at
22434   the beginning or end of the file (7.21.3).
22435 -- Whether a write on a text stream causes the associated file to be truncated beyond that
22436   point (7.21.3).
22437 -- The characteristics of file buffering (7.21.3).
22438 -- Whether a zero-length file actually exists (7.21.3).
22439 -- The rules for composing valid file names (7.21.3).
22440 -- Whether the same file can be simultaneously open multiple times (7.21.3).
22441 -- The nature and choice of encodings used for multibyte characters in files (7.21.3).
22442 -- The effect of the remove function on an open file (7.21.4.1).
22443 -- The effect if a file with the new name exists prior to a call to the rename function
22444   (7.21.4.2).
22445 -- Whether an open temporary file is removed upon abnormal program termination
22446   (7.21.4.3).
22447 -- Which changes of mode are permitted (if any), and under what circumstances
22448   (7.21.5.4).
22449
22450 [page 572]
22451
22452 -- The style used to print an infinity or NaN, and the meaning of any n-char or n-wchar
22453   sequence printed for a NaN (7.21.6.1, 7.28.2.1).
22454 -- The output for %p conversion in the fprintf or fwprintf function (7.21.6.1,
22455   7.28.2.1).
22456 -- The interpretation of a - character that is neither the first nor the last character, nor
22457   the second where a ^ character is the first, in the scanlist for %[ conversion in the
22458   fscanf or fwscanf function (7.21.6.2, 7.28.2.1).
22459 -- The set of sequences matched by a %p conversion and the interpretation of the
22460   corresponding input item in the fscanf or fwscanf function (7.21.6.2, 7.28.2.2).
22461 -- The value to which the macro errno is set by the fgetpos, fsetpos, or ftell
22462   functions on failure (7.21.9.1, 7.21.9.3, 7.21.9.4).
22463 -- The meaning of any n-char or n-wchar sequence in a string representing a NaN that is
22464   converted by the strtod, strtof, strtold, wcstod, wcstof, or wcstold
22465   function (7.22.1.3, 7.28.4.1.1).
22466 -- Whether or not the strtod, strtof, strtold, wcstod, wcstof, or wcstold
22467   function sets errno to ERANGE when underflow occurs (7.22.1.3, 7.28.4.1.1).
22468 -- Whether the calloc, malloc, and realloc functions return a null pointer or a
22469   pointer to an allocated object when the size requested is zero (7.22.3).
22470 -- Whether open streams with unwritten buffered data are flushed, open streams are
22471   closed, or temporary files are removed when the abort or _Exit function is called
22472   (7.22.4.1, 7.22.4.5).
22473 -- The termination status returned to the host environment by the abort, exit,
22474   _Exit, or quick_exit function (7.22.4.1, 7.22.4.4, 7.22.4.5, 7.22.4.7).
22475 -- The value returned by the system function when its argument is not a null pointer
22476   (7.22.4.8).
22477 -- The local time zone and Daylight Saving Time (7.26.1).
22478 -- The range and precision of times representable in clock_t and time_t (7.26).
22479 -- The era for the clock function (7.26.2.1).
22480 -- The replacement string for the %Z specifier to the strftime, and wcsftime
22481   functions in the "C" locale (7.26.3.5, 7.28.5.1).
22482 -- Whether the functions in <math.h> honor the rounding direction mode in an
22483   IEC 60559 conformant implementation, unless explicitly specified otherwise (F.10).
22484
22485
22486
22487
22488 [page 573]
22489
22490     J.3.13 Architecture
22491 1   -- The values or expressions assigned to the macros specified in the headers
22492       <float.h>, <limits.h>, and <stdint.h> (5.2.4.2, 7.20.2, 7.20.3).
22493     -- The result of attempting to indirectly access an object with automatic or thread
22494       storage duration from a thread other than the one with which it is associated (6.2.4).
22495     -- The number, order, and encoding of bytes in any object (when not explicitly specified
22496       in this International Standard) (6.2.6.1).
22497     -- Whether any extended alignments are supported and the contexts in which they are
22498       supported (6.2.8).
22499     -- Valid alignment values other than those returned by an alignof expression for
22500       fundamental types, if any (6.2.8).
22501     -- The value of the result of the sizeof and alignof operators (6.5.3.4).
22502     J.4 Locale-specific behavior
22503 1   The following characteristics of a hosted environment are locale-specific and are required
22504     to be documented by the implementation:
22505     -- Additional members of the source and execution character sets beyond the basic
22506       character set (5.2.1).
22507     -- The presence, meaning, and representation of additional multibyte characters in the
22508       execution character set beyond the basic character set (5.2.1.2).
22509     -- The shift states used for the encoding of multibyte characters (5.2.1.2).
22510     -- The direction of writing of successive printing characters (5.2.2).
22511     -- The decimal-point character (7.1.1).
22512     -- The set of printing characters (7.4, 7.29.2).
22513     -- The set of control characters (7.4, 7.29.2).
22514     -- The sets of characters tested for by the isalpha, isblank, islower, ispunct,
22515       isspace, isupper, iswalpha, iswblank, iswlower, iswpunct,
22516       iswspace, or iswupper functions (7.4.1.2, 7.4.1.3, 7.4.1.7, 7.4.1.9, 7.4.1.10,
22517       7.4.1.11, 7.29.2.1.2, 7.29.2.1.3, 7.29.2.1.7, 7.29.2.1.9, 7.29.2.1.10, 7.29.2.1.11).
22518     -- The native environment (7.11.1.1).
22519     -- Additional subject sequences accepted by the numeric conversion functions (7.22.1,
22520       7.28.4.1).
22521     -- The collation sequence of the execution character set (7.23.4.3, 7.28.4.4.2).
22522
22523
22524 [page 574]
22525
22526     -- The contents of the error message strings set up by the strerror function
22527       (7.23.6.2).
22528     -- The formats for time and date (7.26.3.5, 7.28.5.1).
22529     -- Character mappings that are supported by the towctrans function (7.29.1).
22530     -- Character classifications that are supported by the iswctype function (7.29.1).
22531     J.5 Common extensions
22532 1   The following extensions are widely used in many systems, but are not portable to all
22533     implementations. The inclusion of any extension that may cause a strictly conforming
22534     program to become invalid renders an implementation nonconforming. Examples of such
22535     extensions are new keywords, extra library functions declared in standard headers, or
22536     predefined macros with names that do not begin with an underscore.
22537     J.5.1 Environment arguments
22538 1   In a hosted environment, the main function receives a third argument, char *envp[],
22539     that points to a null-terminated array of pointers to char, each of which points to a string
22540     that provides information about the environment for this execution of the program
22541     (5.1.2.2.1).
22542     J.5.2 Specialized identifiers
22543 1   Characters other than the underscore _, letters, and digits, that are not part of the basic
22544     source character set (such as the dollar sign $, or characters in national character sets)
22545     may appear in an identifier (6.4.2).
22546     J.5.3 Lengths and cases of identifiers
22547 1   All characters in identifiers (with or without external linkage) are significant (6.4.2).
22548     J.5.4 Scopes of identifiers
22549 1   A function identifier, or the identifier of an object the declaration of which contains the
22550     keyword extern, has file scope (6.2.1).
22551     J.5.5 Writable string literals
22552 1   String literals are modifiable (in which case, identical string literals should denote distinct
22553     objects) (6.4.5).
22554
22555
22556
22557
22558 [page 575]
22559
22560     J.5.6 Other arithmetic types
22561 1   Additional arithmetic types, such as __int128 or double double, and their
22562     appropriate conversions are defined (6.2.5, 6.3.1). Additional floating types may have
22563     more range or precision than long double, may be used for evaluating expressions of
22564     other floating types, and may be used to define float_t or double_t.
22565     J.5.7 Function pointer casts
22566 1   A pointer to an object or to void may be cast to a pointer to a function, allowing data to
22567     be invoked as a function (6.5.4).
22568 2   A pointer to a function may be cast to a pointer to an object or to void, allowing a
22569     function to be inspected or modified (for example, by a debugger) (6.5.4).
22570     J.5.8 Extended bit-field types
22571 1   A bit-field may be declared with a type other than _Bool, unsigned int, or
22572     signed int, with an appropriate maximum width (6.7.2.1).
22573     J.5.9 The fortran keyword
22574 1   The fortran function specifier may be used in a function declaration to indicate that
22575     calls suitable for FORTRAN should be generated, or that a different representation for the
22576     external name is to be generated (6.7.4).
22577     J.5.10 The asm keyword
22578 1   The asm keyword may be used to insert assembly language directly into the translator
22579     output (6.8). The most common implementation is via a statement of the form:
22580            asm ( character-string-literal );
22581     J.5.11 Multiple external definitions
22582 1   There may be more than one external definition for the identifier of an object, with or
22583     without the explicit use of the keyword extern; if the definitions disagree, or more than
22584     one is initialized, the behavior is undefined (6.9.2).
22585     J.5.12 Predefined macro names
22586 1   Macro names that do not begin with an underscore, describing the translation and
22587     execution environments, are defined by the implementation before translation begins
22588     (6.10.8).
22589
22590
22591
22592
22593 [page 576]
22594
22595     J.5.13 Floating-point status flags
22596 1   If any floating-point status flags are set on normal termination after all calls to functions
22597     registered by the atexit function have been made (see 7.22.4.4), the implementation
22598     writes some diagnostics indicating the fact to the stderr stream, if it is still open,
22599     J.5.14 Extra arguments for signal handlers
22600 1   Handlers for specific signals are called with extra arguments in addition to the signal
22601     number (7.14.1.1).
22602     J.5.15 Additional stream types and file-opening modes
22603 1   Additional mappings from files to streams are supported (7.21.2).
22604 2   Additional file-opening modes may be specified by characters appended to the mode
22605     argument of the fopen function (7.21.5.3).
22606     J.5.16 Defined file position indicator
22607 1   The file position indicator is decremented by each successful call to the ungetc or
22608     ungetwc function for a text stream, except if its value was zero before a call (7.21.7.10,
22609     7.28.3.10).
22610     J.5.17 Math error reporting
22611 1   Functions declared in <complex.h> and <math.h> raise SIGFPE to report errors
22612     instead of, or in addition to, setting errno or raising floating-point exceptions (7.3,
22613     7.12).
22614
22615
22616
22617
22618 [page 577]
22619
22620                                            Annex K
22621                                           (normative)
22622                               Bounds-checking interfaces
22623     K.1 Background
22624 1   Traditionally, the C Library has contained many functions that trust the programmer to
22625     provide output character arrays big enough to hold the result being produced. Not only
22626     do these functions not check that the arrays are big enough, they frequently lack the
22627     information needed to perform such checks. While it is possible to write safe, robust, and
22628     error-free code using the existing library, the library tends to promote programming styles
22629     that lead to mysterious failures if a result is too big for the provided array.
22630 2   A common programming style is to declare character arrays large enough to handle most
22631     practical cases. However, if these arrays are not large enough to handle the resulting
22632     strings, data can be written past the end of the array overwriting other data and program
22633     structures. The program never gets any indication that a problem exists, and so never has
22634     a chance to recover or to fail gracefully.
22635 3   Worse, this style of programming has compromised the security of computers and
22636     networks. Buffer overflows can often be exploited to run arbitrary code with the
22637     permissions of the vulnerable (defective) program.
22638 4   If the programmer writes runtime checks to verify lengths before calling library
22639     functions, then those runtime checks frequently duplicate work done inside the library
22640     functions, which discover string lengths as a side effect of doing their job.
22641 5   This annex provides alternative library functions that promote safer, more secure
22642     programming. The alternative functions verify that output buffers are large enough for
22643     the intended result and return a failure indicator if they are not. Data is never written past
22644     the end of an array. All string results are null terminated.
22645 6   This annex also addresses another problem that complicates writing robust code:
22646     functions that are not reentrant because they return pointers to static objects owned by the
22647     function. Such functions can be troublesome since a previously returned result can
22648     change if the function is called again, perhaps by another thread.
22649
22650
22651
22652
22653 [page 578]
22654
22655     K.2 Scope
22656 1   This annex specifies a series of optional extensions that can be useful in the mitigation of
22657     security vulnerabilities in programs, and comprise new functions, macros, and types
22658     declared or defined in existing standard headers.
22659 2   An implementation that defines __STDC_LIB_EXT1__ shall conform to the
22660     specifications in this annex.367)
22661 3   Subclause K.3 should be read as if it were merged into the parallel structure of named
22662     subclauses of clause 7.
22663     K.3 Library
22664     K.3.1 Introduction
22665     K.3.1.1 Standard headers
22666 1   The functions, macros, and types declared or defined in K.3 and its subclauses are not
22667     declared or defined by their respective headers if __STDC_WANT_LIB_EXT1__ is
22668     defined as a macro which expands to the integer constant 0 at the point in the source file
22669     where the appropriate header is first included.
22670 2   The functions, macros, and types declared or defined in K.3 and its subclauses are
22671     declared and defined by their respective headers if __STDC_WANT_LIB_EXT1__ is
22672     defined as a macro which expands to the integer constant 1 at the point in the source file
22673     where the appropriate header is first included.368)
22674 3   It is implementation-defined whether the functions, macros, and types declared or defined
22675     in K.3 and its subclauses are declared or defined by their respective headers if
22676     __STDC_WANT_LIB_EXT1__ is not defined as a macro at the point in the source file
22677     where the appropriate header is first included.369)
22678 4   Within a preprocessing translation unit, __STDC_WANT_LIB_EXT1__ shall be
22679     defined identically for all inclusions of any headers from subclause K.3. If
22680     __STDC_WANT_LIB_EXT1__ is defined differently for any such inclusion, the
22681     implementation shall issue a diagnostic as if a preprocessor error directive were used.
22682
22683
22684     367) Implementations that do not define __STDC_LIB_EXT1__ are not required to conform to these
22685          specifications.
22686     368) Future revisions of this International Standard may define meanings for other values of
22687          __STDC_WANT_LIB_EXT1__.
22688     369) Subclause 7.1.3 reserves certain names and patterns of names that an implementation may use in
22689          headers. All other names are not reserved, and a conforming implementation is not permitted to use
22690          them. While some of the names defined in K.3 and its subclauses are reserved, others are not. If an
22691          unreserved name is defined in a header when __STDC_WANT_LIB_EXT1__ is defined as 0, the
22692          implementation is not conforming.
22693
22694 [page 579]
22695
22696     K.3.1.2 Reserved identifiers
22697 1   Each macro name in any of the following subclauses is reserved for use as specified if it
22698     is defined by any of its associated headers when included; unless explicitly stated
22699     otherwise (see 7.1.4).
22700 2   All identifiers with external linkage in any of the following subclauses are reserved for
22701     use as identifiers with external linkage if any of them are used by the program. None of
22702     them are reserved if none of them are used.
22703 3   Each identifier with file scope listed in any of the following subclauses is reserved for use
22704     as a macro name and as an identifier with file scope in the same name space if it is
22705     defined by any of its associated headers when included.
22706     K.3.1.3 Use of errno
22707 1   An implementation may set errno for the functions defined in this annex, but is not
22708     required to.
22709     K.3.1.4 Runtime-constraint violations
22710 1   Most functions in this annex include as part of their specification a list of runtime-
22711     constraints. These runtime-constraints are requirements on the program using the
22712     library.370)
22713 2   Implementations shall verify that the runtime-constraints for a function are not violated
22714     by the program. If a runtime-constraint is violated, the implementation shall call the
22715     currently registered runtime-constraint handler (see set_constraint_handler_s
22716     in <stdlib.h>). Multiple runtime-constraint violations in the same call to a library
22717     function result in only one call to the runtime-constraint handler. It is unspecified which
22718     one of the multiple runtime-constraint violations cause the handler to be called.
22719 3   If the runtime-constraints section for a function states an action to be performed when a
22720     runtime-constraint violation occurs, the function shall perform the action before calling
22721     the runtime-constraint handler. If the runtime-constraints section lists actions that are
22722     prohibited when a runtime-constraint violation occurs, then such actions are prohibited to
22723     the function both before calling the handler and after the handler returns.
22724 4   The runtime-constraint handler might not return. If the handler does return, the library
22725     function whose runtime-constraint was violated shall return some indication of failure as
22726     given by the returns section in the function's specification.
22727
22728
22729
22730     370) Although runtime-constraints replace many cases of undefined behavior, undefined behavior still
22731          exists in this annex. Implementations are free to detect any case of undefined behavior and treat it as a
22732          runtime-constraint violation by calling the runtime-constraint handler. This license comes directly
22733          from the definition of undefined behavior.
22734
22735 [page 580]
22736
22737     K.3.2 Errors <errno.h>
22738 1   The header <errno.h> defines a type.
22739 2   The type is
22740              errno_t
22741     which is type int.371)
22742     K.3.3 Common definitions <stddef.h>
22743 1   The header <stddef.h> defines a type.
22744 2   The type is
22745              rsize_t
22746     which is the type size_t.372)
22747     K.3.4 Integer types <stdint.h>
22748 1   The header <stdint.h> defines a macro.
22749 2   The macro is
22750              RSIZE_MAX
22751     which expands to a value373) of type size_t. Functions that have parameters of type
22752     rsize_t consider it a runtime-constraint violation if the values of those parameters are
22753     greater than RSIZE_MAX.
22754     Recommended practice
22755 3   Extremely large object sizes are frequently a sign that an object's size was calculated
22756     incorrectly. For example, negative numbers appear as very large positive numbers when
22757     converted to an unsigned type like size_t. Also, some implementations do not support
22758     objects as large as the maximum value that can be represented by type size_t.
22759 4   For those reasons, it is sometimes beneficial to restrict the range of object sizes to detect
22760     programming errors. For implementations targeting machines with large address spaces,
22761     it is recommended that RSIZE_MAX be defined as the smaller of the size of the largest
22762     object supported or (SIZE_MAX >> 1), even if this limit is smaller than the size of
22763     some legitimate, but very large, objects. Implementations targeting machines with small
22764     address spaces may wish to define RSIZE_MAX as SIZE_MAX, which means that there
22765
22766     371) As a matter of programming style, errno_t may be used as the type of something that deals only
22767          with the values that might be found in errno. For example, a function which returns the value of
22768          errno might be declared as having the return type errno_t.
22769     372) See the description of the RSIZE_MAX macro in <stdint.h>.
22770     373) The macro RSIZE_MAX need not expand to a constant expression.
22771
22772 [page 581]
22773
22774     is no object size that is considered a runtime-constraint violation.
22775     K.3.5 Input/output <stdio.h>
22776 1   The header <stdio.h> defines several macros and two types.
22777 2   The macros are
22778            L_tmpnam_s
22779     which expands to an integer constant expression that is the size needed for an array of
22780     char large enough to hold a temporary file name string generated by the tmpnam_s
22781     function;
22782            TMP_MAX_S
22783     which expands to an integer constant expression that is the maximum number of unique
22784     file names that can be generated by the tmpnam_s function.
22785 3   The types are
22786            errno_t
22787     which is type int; and
22788            rsize_t
22789     which is the type size_t.
22790     K.3.5.1 Operations on files
22791     K.3.5.1.1 The tmpfile_s function
22792     Synopsis
22793 1          #define __STDC_WANT_LIB_EXT1__ 1
22794            #include <stdio.h>
22795            errno_t tmpfile_s(FILE * restrict * restrict streamptr);
22796     Runtime-constraints
22797 2   streamptr shall not be a null pointer.
22798 3   If there is a runtime-constraint violation, tmpfile_s does not attempt to create a file.
22799     Description
22800 4   The tmpfile_s function creates a temporary binary file that is different from any other
22801     existing file and that will automatically be removed when it is closed or at program
22802     termination. If the program terminates abnormally, whether an open temporary file is
22803     removed is implementation-defined. The file is opened for update with "wb+" mode
22804     with the meaning that mode has in the fopen_s function (including the mode's effect
22805     on exclusive access and file permissions).
22806
22807
22808 [page 582]
22809
22810 5   If the file was created successfully, then the pointer to FILE pointed to by streamptr
22811     will be set to the pointer to the object controlling the opened file. Otherwise, the pointer
22812     to FILE pointed to by streamptr will be set to a null pointer.
22813     Recommended practice
22814     It should be possible to open at least TMP_MAX_S temporary files during the lifetime of
22815     the program (this limit may be shared with tmpnam_s) and there should be no limit on
22816     the number simultaneously open other than this limit and any limit on the number of open
22817     files (FOPEN_MAX).
22818     Returns
22819 6   The tmpfile_s function returns zero if it created the file. If it did not create the file or
22820     there was a runtime-constraint violation, tmpfile_s returns a nonzero value.
22821     K.3.5.1.2 The tmpnam_s function
22822     Synopsis
22823 1           #define __STDC_WANT_LIB_EXT1__ 1
22824             #include <stdio.h>
22825             errno_t tmpnam_s(char *s, rsize_t maxsize);
22826     Runtime-constraints
22827 2   s shall not be a null pointer. maxsize shall be less than or equal to RSIZE_MAX.
22828     maxsize shall be greater than the length of the generated file name string.
22829     Description
22830 3   The tmpnam_s function generates a string that is a valid file name and that is not the
22831     same as the name of an existing file.374) The function is potentially capable of generating
22832     TMP_MAX_S different strings, but any or all of them may already be in use by existing
22833     files and thus not be suitable return values. The lengths of these strings shall be less than
22834     the value of the L_tmpnam_s macro.
22835 4   The tmpnam_s function generates a different string each time it is called.
22836 5   It is assumed that s points to an array of at least maxsize characters. This array will be
22837     set to generated string, as specified below.
22838
22839
22840
22841     374) Files created using strings generated by the tmpnam_s function are temporary only in the sense that
22842          their names should not collide with those generated by conventional naming rules for the
22843          implementation. It is still necessary to use the remove function to remove such files when their use
22844          is ended, and before program termination. Implementations should take care in choosing the patterns
22845          used for names returned by tmpnam_s. For example, making a thread id part of the names avoids the
22846          race condition and possible conflict when multiple programs run simultaneously by the same user
22847          generate the same temporary file names.
22848
22849 [page 583]
22850
22851 6    The implementation shall behave as if no library function except tmpnam calls the
22852      tmpnam_s function.375)
22853      Recommended practice
22854 7    After a program obtains a file name using the tmpnam_s function and before the
22855      program creates a file with that name, the possibility exists that someone else may create
22856      a file with that same name. To avoid this race condition, the tmpfile_s function
22857      should be used instead of tmpnam_s when possible. One situation that requires the use
22858      of the tmpnam_s function is when the program needs to create a temporary directory
22859      rather than a temporary file.
22860      Returns
22861 8    If no suitable string can be generated, or if there is a runtime-constraint violation, the
22862      tmpnam_s function writes a null character to s[0] (only if s is not null and maxsize
22863      is greater than zero) and returns a nonzero value.
22864 9    Otherwise, the tmpnam_s function writes the string in the array pointed to by s and
22865      returns zero.
22866      Environmental limits
22867 10   The value of the macro TMP_MAX_S shall be at least 25.
22868      K.3.5.2 File access functions
22869      K.3.5.2.1 The fopen_s function
22870      Synopsis
22871 1           #define __STDC_WANT_LIB_EXT1__ 1
22872             #include <stdio.h>
22873             errno_t fopen_s(FILE * restrict * restrict streamptr,
22874                  const char * restrict filename,
22875                  const char * restrict mode);
22876      Runtime-constraints
22877 2    None of streamptr, filename, or mode shall be a null pointer.
22878 3    If there is a runtime-constraint violation, fopen_s does not attempt to open a file.
22879      Furthermore, if streamptr is not a null pointer, fopen_s sets *streamptr to the
22880      null pointer.
22881
22882
22883
22884
22885      375) An implementation may have tmpnam call tmpnam_s (perhaps so there is only one naming
22886           convention for temporary files), but this is not required.
22887
22888 [page 584]
22889
22890     Description
22891 4   The fopen_s function opens the file whose name is the string pointed to by
22892     filename, and associates a stream with it.
22893 5   The mode string shall be as described for fopen, with the addition that modes starting
22894     with the character 'w' or 'a' may be preceded by the character 'u', see below:
22895     uw             truncate to zero length or create text file for writing, default
22896                    permissions
22897     uwx            create text file for writing, default permissions
22898     ua             append; open or create text file for writing at end-of-file, default
22899                    permissions
22900     uwb            truncate to zero length or create binary file for writing, default
22901                    permissions
22902     uwbx           create binary file for writing, default permissions
22903     uab            append; open or create binary file for writing at end-of-file, default
22904                    permissions
22905     uw+            truncate to zero length or create text file for update, default
22906                    permissions
22907     uw+x           create text file for update, default permissions
22908     ua+            append; open or create text file for update, writing at end-of-file,
22909                    default permissions
22910     uw+b or uwb+   truncate to zero length or create binary file for update, default
22911                    permissions
22912     uw+bx or uwb+x create binary file for update, default permissions
22913     ua+b or uab+   append; open or create binary file for update, writing at end-of-file,
22914                    default permissions
22915 6   Opening a file with exclusive mode ('x' as the last character in the mode argument)
22916     fails if the file already exists or cannot be created.
22917 7   To the extent that the underlying system supports the concepts, files opened for writing
22918     shall be opened with exclusive (also known as non-shared) access. If the file is being
22919     created, and the first character of the mode string is not 'u', to the extent that the
22920     underlying system supports it, the file shall have a file permission that prevents other
22921     users on the system from accessing the file. If the file is being created and first character
22922     of the mode string is 'u', then by the time the file has been closed, it shall have the
22923     system default file access permissions.376)
22924 8   If the file was opened successfully, then the pointer to FILE pointed to by streamptr
22925     will be set to the pointer to the object controlling the opened file. Otherwise, the pointer
22926
22927
22928     376) These are the same permissions that the file would have been created with by fopen.
22929
22930 [page 585]
22931
22932     to FILE pointed to by streamptr will be set to a null pointer.
22933     Returns
22934 9   The fopen_s function returns zero if it opened the file. If it did not open the file or if
22935     there was a runtime-constraint violation, fopen_s returns a nonzero value.
22936     K.3.5.2.2 The freopen_s function
22937     Synopsis
22938 1          #define __STDC_WANT_LIB_EXT1__ 1
22939            #include <stdio.h>
22940            errno_t freopen_s(FILE * restrict * restrict newstreamptr,
22941                 const char * restrict filename,
22942                 const char * restrict mode,
22943                 FILE * restrict stream);
22944     Runtime-constraints
22945 2   None of newstreamptr, mode, and stream shall be a null pointer.
22946 3   If there is a runtime-constraint violation, freopen_s neither attempts to close any file
22947     associated with stream nor attempts to open a file. Furthermore, if newstreamptr is
22948     not a null pointer, fopen_s sets *newstreamptr to the null pointer.
22949     Description
22950 4   The freopen_s function opens the file whose name is the string pointed to by
22951     filename and associates the stream pointed to by stream with it. The mode
22952     argument has the same meaning as in the fopen_s function (including the mode's effect
22953     on exclusive access and file permissions).
22954 5   If filename is a null pointer, the freopen_s function attempts to change the mode of
22955     the stream to that specified by mode, as if the name of the file currently associated with
22956     the stream had been used. It is implementation-defined which changes of mode are
22957     permitted (if any), and under what circumstances.
22958 6   The freopen_s function first attempts to close any file that is associated with stream.
22959     Failure to close the file is ignored. The error and end-of-file indicators for the stream are
22960     cleared.
22961 7   If the file was opened successfully, then the pointer to FILE pointed to by
22962     newstreamptr will be set to the value of stream. Otherwise, the pointer to FILE
22963     pointed to by newstreamptr will be set to a null pointer.
22964     Returns
22965 8   The freopen_s function returns zero if it opened the file. If it did not open the file or
22966     there was a runtime-constraint violation, freopen_s returns a nonzero value.
22967
22968 [page 586]
22969
22970     K.3.5.3 Formatted input/output functions
22971 1   Unless explicitly stated otherwise, if the execution of a function described in this
22972     subclause causes copying to take place between objects that overlap, the objects take on
22973     unspecified values.
22974     K.3.5.3.1 The fprintf_s function
22975     Synopsis
22976 1            #define __STDC_WANT_LIB_EXT1__ 1
22977              #include <stdio.h>
22978              int fprintf_s(FILE * restrict stream,
22979                   const char * restrict format, ...);
22980     Runtime-constraints
22981 2   Neither stream nor format shall be a null pointer. The %n specifier377) (modified or
22982     not by flags, field width, or precision) shall not appear in the string pointed to by
22983     format. Any argument to fprintf_s corresponding to a %s specifier shall not be a
22984     null pointer.
22985 3   If there is a runtime-constraint violation,378) the fprintf_s function does not attempt
22986     to produce further output, and it is unspecified to what extent fprintf_s produced
22987     output before discovering the runtime-constraint violation.
22988     Description
22989 4   The fprintf_s function is equivalent to the fprintf function except for the explicit
22990     runtime-constraints listed above.
22991     Returns
22992 5   The fprintf_s function returns the number of characters transmitted, or a negative
22993     value if an output error, encoding error, or runtime-constraint violation occurred.
22994
22995
22996
22997
22998     377) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
22999          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23000          format string was %%n.
23001     378) Because an implementation may treat any undefined behavior as a runtime-constraint violation, an
23002          implementation may treat any unsupported specifiers in the string pointed to by format as a runtime-
23003          constraint violation.
23004
23005 [page 587]
23006
23007     K.3.5.3.2 The fscanf_s function
23008     Synopsis
23009 1           #define __STDC_WANT_LIB_EXT1__ 1
23010             #include <stdio.h>
23011             int fscanf_s(FILE * restrict stream,
23012                  const char * restrict format, ...);
23013     Runtime-constraints
23014 2   Neither stream nor format shall be a null pointer. Any argument indirected though in
23015     order to store converted input shall not be a null pointer.
23016 3   If there is a runtime-constraint violation,379) the fscanf_s function does not attempt to
23017     perform further input, and it is unspecified to what extent fscanf_s performed input
23018     before discovering the runtime-constraint violation.
23019     Description
23020 4   The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion
23021     specifiers apply to a pair of arguments (unless assignment suppression is indicated by a
23022     *). The first of these arguments is the same as for fscanf. That argument is
23023     immediately followed in the argument list by the second argument, which has type
23024     rsize_t and gives the number of elements in the array pointed to by the first argument
23025     of the pair. If the first argument points to a scalar object, it is considered to be an array of
23026     one element.380)
23027 5   A matching failure occurs if the number of elements in a receiving object is insufficient to
23028     hold the converted input (including any trailing null character).
23029     Returns
23030 6   The fscanf_s function returns the value of the macro EOF if an input failure occurs
23031     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23032
23033     379) Because an implementation may treat any undefined behavior as a runtime-constraint violation, an
23034          implementation may treat any unsupported specifiers in the string pointed to by format as a runtime-
23035          constraint violation.
23036     380) If the format is known at translation time, an implementation may issue a diagnostic for any argument
23037          used to store the result from a c, s, or [ conversion specifier if that argument is not followed by an
23038          argument of a type compatible with rsize_t. A limited amount of checking may be done if even if
23039          the format is not known at translation time. For example, an implementation may issue a diagnostic
23040          for each argument after format that has of type pointer to one of char, signed char,
23041          unsigned char, or void that is not followed by an argument of a type compatible with
23042          rsize_t. The diagnostic could warn that unless the pointer is being used with a conversion specifier
23043          using the hh length modifier, a length argument must follow the pointer argument. Another useful
23044          diagnostic could flag any non-pointer argument following format that did not have a type
23045          compatible with rsize_t.
23046
23047 [page 588]
23048
23049     fscanf_s function returns the number of input items assigned, which can be fewer than
23050     provided for, or even zero, in the event of an early matching failure.
23051 7   EXAMPLE 1        The call:
23052              #define __STDC_WANT_LIB_EXT1__ 1
23053              #include <stdio.h>
23054              /* ... */
23055              int n, i; float x; char name[50];
23056              n = fscanf_s(stdin, "%d%f%s", &i, &x, name, (rsize_t) 50);
23057     with the input line:
23058              25 54.32E-1 thompson
23059     will assign to n the value 3, to i the value 25, to x the value 5.432, and to name the sequence
23060     thompson\0.
23061
23062 8   EXAMPLE 2        The call:
23063              #define __STDC_WANT_LIB_EXT1__ 1
23064              #include <stdio.h>
23065              /* ... */
23066              int n; char s[5];
23067              n = fscanf_s(stdin, "%s", s, sizeof s);
23068     with the input line:
23069              hello
23070     will assign to n the value 0 since a matching failure occurred because the sequence hello\0 requires an
23071     array of six characters to store it.
23072
23073     K.3.5.3.3 The printf_s function
23074     Synopsis
23075 1            #define __STDC_WANT_LIB_EXT1__ 1
23076              #include <stdio.h>
23077              int printf_s(const char * restrict format, ...);
23078     Runtime-constraints
23079 2   format shall not be a null pointer. The %n specifier381) (modified or not by flags, field
23080     width, or precision) shall not appear in the string pointed to by format. Any argument
23081     to printf_s corresponding to a %s specifier shall not be a null pointer.
23082 3   If there is a runtime-constraint violation, the printf_s function does not attempt to
23083     produce further output, and it is unspecified to what extent printf_s produced output
23084     before discovering the runtime-constraint violation.
23085
23086
23087     381) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23088          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23089          format string was %%n.
23090
23091 [page 589]
23092
23093     Description
23094 4   The printf_s function is equivalent to the printf function except for the explicit
23095     runtime-constraints listed above.
23096     Returns
23097 5   The printf_s function returns the number of characters transmitted, or a negative
23098     value if an output error, encoding error, or runtime-constraint violation occurred.
23099     K.3.5.3.4 The scanf_s function
23100     Synopsis
23101 1          #define __STDC_WANT_LIB_EXT1__ 1
23102            #include <stdio.h>
23103            int scanf_s(const char * restrict format, ...);
23104     Runtime-constraints
23105 2   format shall not be a null pointer. Any argument indirected though in order to store
23106     converted input shall not be a null pointer.
23107 3   If there is a runtime-constraint violation, the scanf_s function does not attempt to
23108     perform further input, and it is unspecified to what extent scanf_s performed input
23109     before discovering the runtime-constraint violation.
23110     Description
23111 4   The scanf_s function is equivalent to fscanf_s with the argument stdin
23112     interposed before the arguments to scanf_s.
23113     Returns
23114 5   The scanf_s function returns the value of the macro EOF if an input failure occurs
23115     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23116     scanf_s function returns the number of input items assigned, which can be fewer than
23117     provided for, or even zero, in the event of an early matching failure.
23118     K.3.5.3.5 The snprintf_s function
23119     Synopsis
23120 1          #define __STDC_WANT_LIB_EXT1__ 1
23121            #include <stdio.h>
23122            int snprintf_s(char * restrict s, rsize_t n,
23123                 const char * restrict format, ...);
23124     Runtime-constraints
23125 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
23126     than RSIZE_MAX. The %n specifier382) (modified or not by flags, field width, or
23127     precision) shall not appear in the string pointed to by format. Any argument to
23128 [page 590]
23129
23130     snprintf_s corresponding to a %s specifier shall not be a null pointer. No encoding
23131     error shall occur.
23132 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
23133     than zero and less than RSIZE_MAX, then the snprintf_s function sets s[0] to the
23134     null character.
23135     Description
23136 4   The snprintf_s function is equivalent to the snprintf function except for the
23137     explicit runtime-constraints listed above.
23138 5   The snprintf_s function, unlike sprintf_s, will truncate the result to fit within the
23139     array pointed to by s.
23140     Returns
23141 6   The snprintf_s function returns the number of characters that would have been
23142     written had n been sufficiently large, not counting the terminating null character, or a
23143     negative value if a runtime-constraint violation occurred. Thus, the null-terminated
23144     output has been completely written if and only if the returned value is nonnegative and
23145     less than n.
23146     K.3.5.3.6 The sprintf_s function
23147     Synopsis
23148 1            #define __STDC_WANT_LIB_EXT1__ 1
23149              #include <stdio.h>
23150              int sprintf_s(char * restrict s, rsize_t n,
23151                   const char * restrict format, ...);
23152     Runtime-constraints
23153 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
23154     than RSIZE_MAX. The number of characters (including the trailing null) required for the
23155     result to be written to the array pointed to by s shall not be greater than n. The %n
23156     specifier383) (modified or not by flags, field width, or precision) shall not appear in the
23157     string pointed to by format. Any argument to sprintf_s corresponding to a %s
23158     specifier shall not be a null pointer. No encoding error shall occur.
23159
23160
23161
23162     382) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23163          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23164          format string was %%n.
23165     383) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23166          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23167          format string was %%n.
23168
23169 [page 591]
23170
23171 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
23172     than zero and less than RSIZE_MAX, then the sprintf_s function sets s[0] to the
23173     null character.
23174     Description
23175 4   The sprintf_s function is equivalent to the sprintf function except for the
23176     parameter n and the explicit runtime-constraints listed above.
23177 5   The sprintf_s function, unlike snprintf_s, treats a result too big for the array
23178     pointed to by s as a runtime-constraint violation.
23179     Returns
23180 6   If no runtime-constraint violation occurred, the sprintf_s function returns the number
23181     of characters written in the array, not counting the terminating null character. If an
23182     encoding error occurred, sprintf_s returns a negative value. If any other runtime-
23183     constraint violation occurred, sprintf_s returns zero.
23184     K.3.5.3.7 The sscanf_s function
23185     Synopsis
23186 1          #define __STDC_WANT_LIB_EXT1__ 1
23187            #include <stdio.h>
23188            int sscanf_s(const char * restrict s,
23189                 const char * restrict format, ...);
23190     Runtime-constraints
23191 2   Neither s nor format shall be a null pointer. Any argument indirected though in order
23192     to store converted input shall not be a null pointer.
23193 3   If there is a runtime-constraint violation, the sscanf_s function does not attempt to
23194     perform further input, and it is unspecified to what extent sscanf_s performed input
23195     before discovering the runtime-constraint violation.
23196     Description
23197 4   The sscanf_s function is equivalent to fscanf_s, except that input is obtained from
23198     a string (specified by the argument s) rather than from a stream. Reaching the end of the
23199     string is equivalent to encountering end-of-file for the fscanf_s function. If copying
23200     takes place between objects that overlap, the objects take on unspecified values.
23201     Returns
23202 5   The sscanf_s function returns the value of the macro EOF if an input failure occurs
23203     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23204     sscanf_s function returns the number of input items assigned, which can be fewer than
23205     provided for, or even zero, in the event of an early matching failure.
23206
23207 [page 592]
23208
23209     K.3.5.3.8 The vfprintf_s function
23210     Synopsis
23211 1            #define __STDC_WANT_LIB_EXT1__ 1
23212              #include <stdarg.h>
23213              #include <stdio.h>
23214              int vfprintf_s(FILE * restrict stream,
23215                   const char * restrict format,
23216                   va_list arg);
23217     Runtime-constraints
23218 2   Neither stream nor format shall be a null pointer. The %n specifier384) (modified or
23219     not by flags, field width, or precision) shall not appear in the string pointed to by
23220     format. Any argument to vfprintf_s corresponding to a %s specifier shall not be a
23221     null pointer.
23222 3   If there is a runtime-constraint violation, the vfprintf_s function does not attempt to
23223     produce further output, and it is unspecified to what extent vfprintf_s produced
23224     output before discovering the runtime-constraint violation.
23225     Description
23226 4   The vfprintf_s function is equivalent to the vfprintf function except for the
23227     explicit runtime-constraints listed above.
23228     Returns
23229 5   The vfprintf_s function returns the number of characters transmitted, or a negative
23230     value if an output error, encoding error, or runtime-constraint violation occurred.
23231     K.3.5.3.9 The vfscanf_s function
23232     Synopsis
23233 1            #define __STDC_WANT_LIB_EXT1__ 1
23234              #include <stdarg.h>
23235              #include <stdio.h>
23236              int vfscanf_s(FILE * restrict stream,
23237                   const char * restrict format,
23238                   va_list arg);
23239
23240
23241
23242
23243     384) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23244          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23245          format string was %%n.
23246
23247 [page 593]
23248
23249     Runtime-constraints
23250 2   Neither stream nor format shall be a null pointer. Any argument indirected though in
23251     order to store converted input shall not be a null pointer.
23252 3   If there is a runtime-constraint violation, the vfscanf_s function does not attempt to
23253     perform further input, and it is unspecified to what extent vfscanf_s performed input
23254     before discovering the runtime-constraint violation.
23255     Description
23256 4   The vfscanf_s function is equivalent to fscanf_s, with the variable argument list
23257     replaced by arg, which shall have been initialized by the va_start macro (and
23258     possibly subsequent va_arg calls). The vfscanf_s function does not invoke the
23259     va_end macro.385)
23260     Returns
23261 5   The vfscanf_s function returns the value of the macro EOF if an input failure occurs
23262     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23263     vfscanf_s function returns the number of input items assigned, which can be fewer
23264     than provided for, or even zero, in the event of an early matching failure.
23265     K.3.5.3.10 The vprintf_s function
23266     Synopsis
23267 1            #define __STDC_WANT_LIB_EXT1__ 1
23268              #include <stdarg.h>
23269              #include <stdio.h>
23270              int vprintf_s(const char * restrict format,
23271                   va_list arg);
23272     Runtime-constraints
23273 2   format shall not be a null pointer. The %n specifier386) (modified or not by flags, field
23274     width, or precision) shall not appear in the string pointed to by format. Any argument
23275     to vprintf_s corresponding to a %s specifier shall not be a null pointer.
23276 3   If there is a runtime-constraint violation, the vprintf_s function does not attempt to
23277     produce further output, and it is unspecified to what extent vprintf_s produced output
23278     before discovering the runtime-constraint violation.
23279
23280     385) As the functions vfprintf_s, vfscanf_s, vprintf_s, vscanf_s, vsnprintf_s,
23281          vsprintf_s, and vsscanf_s invoke the va_arg macro, the value of arg after the return is
23282          indeterminate.
23283     386) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23284          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23285          format string was %%n.
23286
23287 [page 594]
23288
23289     Description
23290 4   The vprintf_s function is equivalent to the vprintf function except for the explicit
23291     runtime-constraints listed above.
23292     Returns
23293 5   The vprintf_s function returns the number of characters transmitted, or a negative
23294     value if an output error, encoding error, or runtime-constraint violation occurred.
23295     K.3.5.3.11 The vscanf_s function
23296     Synopsis
23297 1           #define __STDC_WANT_LIB_EXT1__ 1
23298             #include <stdarg.h>
23299             #include <stdio.h>
23300             int vscanf_s(const char * restrict format,
23301                  va_list arg);
23302     Runtime-constraints
23303 2   format shall not be a null pointer. Any argument indirected though in order to store
23304     converted input shall not be a null pointer.
23305 3   If there is a runtime-constraint violation, the vscanf_s function does not attempt to
23306     perform further input, and it is unspecified to what extent vscanf_s performed input
23307     before discovering the runtime-constraint violation.
23308     Description
23309 4   The vscanf_s function is equivalent to scanf_s, with the variable argument list
23310     replaced by arg, which shall have been initialized by the va_start macro (and
23311     possibly subsequent va_arg calls). The vscanf_s function does not invoke the
23312     va_end macro.387)
23313     Returns
23314 5   The vscanf_s function returns the value of the macro EOF if an input failure occurs
23315     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23316     vscanf_s function returns the number of input items assigned, which can be fewer than
23317     provided for, or even zero, in the event of an early matching failure.
23318
23319
23320
23321
23322     387) As the functions vfprintf_s, vfscanf_s, vprintf_s, vscanf_s, vsnprintf_s,
23323          vsprintf_s, and vsscanf_s invoke the va_arg macro, the value of arg after the return is
23324          indeterminate.
23325
23326 [page 595]
23327
23328     K.3.5.3.12 The vsnprintf_s function
23329     Synopsis
23330 1            #define __STDC_WANT_LIB_EXT1__ 1
23331              #include <stdarg.h>
23332              #include <stdio.h>
23333              int vsnprintf_s(char * restrict s, rsize_t n,
23334                   const char * restrict format,
23335                   va_list arg);
23336     Runtime-constraints
23337 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
23338     than RSIZE_MAX. The %n specifier388) (modified or not by flags, field width, or
23339     precision) shall not appear in the string pointed to by format. Any argument to
23340     vsnprintf_s corresponding to a %s specifier shall not be a null pointer. No encoding
23341     error shall occur.
23342 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
23343     than zero and less than RSIZE_MAX, then the vsnprintf_s function sets s[0] to the
23344     null character.
23345     Description
23346 4   The vsnprintf_s function is equivalent to the vsnprintf function except for the
23347     explicit runtime-constraints listed above.
23348 5   The vsnprintf_s function, unlike vsprintf_s, will truncate the result to fit within
23349     the array pointed to by s.
23350     Returns
23351 6   The vsnprintf_s function returns the number of characters that would have been
23352     written had n been sufficiently large, not counting the terminating null character, or a
23353     negative value if a runtime-constraint violation occurred. Thus, the null-terminated
23354     output has been completely written if and only if the returned value is nonnegative and
23355     less than n.
23356
23357
23358
23359
23360     388) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23361          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23362          format string was %%n.
23363
23364 [page 596]
23365
23366     K.3.5.3.13 The vsprintf_s function
23367     Synopsis
23368 1            #define __STDC_WANT_LIB_EXT1__ 1
23369              #include <stdarg.h>
23370              #include <stdio.h>
23371              int vsprintf_s(char * restrict s, rsize_t n,
23372                   const char * restrict format,
23373                   va_list arg);
23374     Runtime-constraints
23375 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
23376     than RSIZE_MAX. The number of characters (including the trailing null) required for the
23377     result to be written to the array pointed to by s shall not be greater than n. The %n
23378     specifier389) (modified or not by flags, field width, or precision) shall not appear in the
23379     string pointed to by format. Any argument to vsprintf_s corresponding to a %s
23380     specifier shall not be a null pointer. No encoding error shall occur.
23381 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
23382     than zero and less than RSIZE_MAX, then the vsprintf_s function sets s[0] to the
23383     null character.
23384     Description
23385 4   The vsprintf_s function is equivalent to the vsprintf function except for the
23386     parameter n and the explicit runtime-constraints listed above.
23387 5   The vsprintf_s function, unlike vsnprintf_s, treats a result too big for the array
23388     pointed to by s as a runtime-constraint violation.
23389     Returns
23390 6   If no runtime-constraint violation occurred, the vsprintf_s function returns the
23391     number of characters written in the array, not counting the terminating null character. If
23392     an encoding error occurred, vsprintf_s returns a negative value. If any other
23393     runtime-constraint violation occurred, vsprintf_s returns zero.
23394
23395
23396
23397
23398     389) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23399          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23400          format string was %%n.
23401
23402 [page 597]
23403
23404     K.3.5.3.14 The vsscanf_s function
23405     Synopsis
23406 1          #define __STDC_WANT_LIB_EXT1__ 1
23407            #include <stdarg.h>
23408            #include <stdio.h>
23409            int vsscanf_s(const char * restrict s,
23410                 const char * restrict format,
23411                 va_list arg);
23412     Runtime-constraints
23413 2   Neither s nor format shall be a null pointer. Any argument indirected though in order
23414     to store converted input shall not be a null pointer.
23415 3   If there is a runtime-constraint violation, the vsscanf_s function does not attempt to
23416     perform further input, and it is unspecified to what extent vsscanf_s performed input
23417     before discovering the runtime-constraint violation.
23418     Description
23419 4   The vsscanf_s function is equivalent to sscanf_s, with the variable argument list
23420     replaced by arg, which shall have been initialized by the va_start macro (and
23421     possibly subsequent va_arg calls). The vsscanf_s function does not invoke the
23422     va_end macro.390)
23423     Returns
23424 5   The vsscanf_s function returns the value of the macro EOF if an input failure occurs
23425     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23426     vscanf_s function returns the number of input items assigned, which can be fewer than
23427     provided for, or even zero, in the event of an early matching failure.
23428     K.3.5.4 Character input/output functions
23429     K.3.5.4.1 The gets_s function
23430     Synopsis
23431 1          #define __STDC_WANT_LIB_EXT1__ 1
23432            #include <stdio.h>
23433            char *gets_s(char *s, rsize_t n);
23434
23435
23436
23437
23438     390) As the functions vfprintf_s, vfscanf_s, vprintf_s, vscanf_s, vsnprintf_s,
23439          vsprintf_s, and vsscanf_s invoke the va_arg macro, the value of arg after the return is
23440          indeterminate.
23441
23442 [page 598]
23443
23444     Runtime-constraints
23445 2   s shall not be a null pointer. n shall neither be equal to zero nor be greater than
23446     RSIZE_MAX. A new-line character, end-of-file, or read error shall occur within reading
23447     n-1 characters from stdin.391)
23448 3   If there is a runtime-constraint violation, s[0] is set to the null character, and characters
23449     are read and discarded from stdin until a new-line character is read, or end-of-file or a
23450     read error occurs.
23451     Description
23452 4   The gets_s function reads at most one less than the number of characters specified by n
23453     from the stream pointed to by stdin, into the array pointed to by s. No additional
23454     characters are read after a new-line character (which is discarded) or after end-of-file.
23455     The discarded new-line character does not count towards number of characters read. A
23456     null character is written immediately after the last character read into the array.
23457 5   If end-of-file is encountered and no characters have been read into the array, or if a read
23458     error occurs during the operation, then s[0] is set to the null character, and the other
23459     elements of s take unspecified values.
23460     Recommended practice
23461 6   The fgets function allows properly-written programs to safely process input lines too
23462     long to store in the result array. In general this requires that callers of fgets pay
23463     attention to the presence or absence of a new-line character in the result array. Consider
23464     using fgets (along with any needed processing based on new-line characters) instead of
23465     gets_s.
23466     Returns
23467 7   The gets_s function returns s if successful. If there was a runtime-constraint violation,
23468     or if end-of-file is encountered and no characters have been read into the array, or if a
23469     read error occurs during the operation, then a null pointer is returned.
23470
23471
23472
23473
23474     391) The gets_s function, unlike the historical gets function, makes it a runtime-constraint violation for
23475          a line of input to overflow the buffer to store it. Unlike the fgets function, gets_s maintains a
23476          one-to-one relationship between input lines and successful calls to gets_s. Programs that use gets
23477          expect such a relationship.
23478
23479 [page 599]
23480
23481     K.3.6 General utilities <stdlib.h>
23482 1   The header <stdlib.h> defines three types.
23483 2   The types are
23484             errno_t
23485     which is type int; and
23486             rsize_t
23487     which is the type size_t; and
23488             constraint_handler_t
23489     which has the following definition
23490             typedef void (*constraint_handler_t)(
23491                  const char * restrict msg,
23492                  void * restrict ptr,
23493                  errno_t error);
23494     K.3.6.1 Runtime-constraint handling
23495     K.3.6.1.1 The set_constraint_handler_s function
23496     Synopsis
23497 1           #define __STDC_WANT_LIB_EXT1__ 1
23498             #include <stdlib.h>
23499             constraint_handler_t set_constraint_handler_s(
23500                  constraint_handler_t handler);
23501     Description
23502 2   The set_constraint_handler_s function sets the runtime-constraint handler to
23503     be handler. The runtime-constraint handler is the function to be called when a library
23504     function detects a runtime-constraint violation. Only the most recent handler registered
23505     with set_constraint_handler_s is called when a runtime-constraint violation
23506     occurs.
23507 3   When the handler is called, it is passed the following arguments in the following order:
23508        1.   A pointer to a character string describing the runtime-constraint violation.
23509        2.   A null pointer or a pointer to an implementation defined object.
23510        3.   If the function calling the handler has a return type declared as errno_t, the
23511             return value of the function is passed. Otherwise, a positive value of type
23512             errno_t is passed.
23513
23514
23515
23516 [page 600]
23517
23518 4   The implementation has a default constraint handler that is used if no calls to the
23519     set_constraint_handler_s function have been made. The behavior of the
23520     default handler is implementation-defined, and it may cause the program to exit or abort.
23521 5   If the handler argument to set_constraint_handler_s is a null pointer, the
23522     implementation default handler becomes the current constraint handler.
23523     Returns
23524 6   The set_constraint_handler_s function returns a pointer to the previously
23525     registered handler.392)
23526     K.3.6.1.2 The abort_handler_s function
23527     Synopsis
23528 1           #define __STDC_WANT_LIB_EXT1__ 1
23529             #include <stdlib.h>
23530             void abort_handler_s(
23531                  const char * restrict msg,
23532                  void * restrict ptr,
23533                  errno_t error);
23534     Description
23535 2   A pointer to the abort_handler_s function shall be a suitable argument to the
23536     set_constraint_handler_s function.
23537 3   The abort_handler_s function writes a message on the standard error stream in an
23538     implementation-defined format. The message shall include the string pointed to by msg.
23539     The abort_handler_s function then calls the abort function.393)
23540     Returns
23541 4   The abort_handler_s function does not return to its caller.
23542
23543
23544
23545
23546     392) If the previous handler was registered by calling set_constraint_handler_s with a null
23547          pointer argument, a pointer to the implementation default handler is returned (not NULL).
23548     393) Many implementations invoke a debugger when the abort function is called.
23549
23550 [page 601]
23551
23552     K.3.6.1.3 The ignore_handler_s function
23553     Synopsis
23554 1           #define __STDC_WANT_LIB_EXT1__ 1
23555             #include <stdlib.h>
23556             void ignore_handler_s(
23557                  const char * restrict msg,
23558                  void * restrict ptr,
23559                  errno_t error);
23560     Description
23561 2   A pointer to the ignore_handler_s function shall be a suitable argument to the
23562     set_constraint_handler_s function.
23563 3   The ignore_handler_s function simply returns to its caller.394)
23564     Returns
23565 4   The ignore_handler_s function returns no value.
23566     K.3.6.2 Communication with the environment
23567     K.3.6.2.1 The getenv_s function
23568     Synopsis
23569 1           #define __STDC_WANT_LIB_EXT1__ 1
23570             #include <stdlib.h>
23571             errno_t getenv_s(size_t * restrict len,
23572                        char * restrict value, rsize_t maxsize,
23573                        const char * restrict name);
23574     Runtime-constraints
23575 2   name shall not be a null pointer. maxsize shall neither equal zero nor be greater than
23576     RSIZE_MAX. If maxsize is not equal to zero, then value shall not be a null pointer.
23577 3   If there is a runtime-constraint violation, the integer pointed to by len is set to 0 (if len
23578     is not null), and the environment list is not searched.
23579     Description
23580 4   The getenv_s function searches an environment list, provided by the host environment,
23581     for a string that matches the string pointed to by name.
23582
23583
23584     394) If the runtime-constraint handler is set to the ignore_handler_s function, any library function in
23585          which a runtime-constraint violation occurs will return to its caller. The caller can determine whether
23586          a runtime-constraint violation occurred based on the library function's specification (usually, the
23587          library function returns a nonzero errno_t).
23588
23589 [page 602]
23590
23591 5   If that name is found then getenv_s performs the following actions. If len is not a
23592     null pointer, the length of the string associated with the matched list member is stored in
23593     the integer pointed to by len. If the length of the associated string is less than maxsize,
23594     then the associated string is copied to the array pointed to by value.
23595 6   If that name is not found then getenv_s performs the following actions. If len is not
23596     a null pointer, zero is stored in the integer pointed to by len. If maxsize is greater than
23597     zero, then value[0] is set to the null character.
23598 7   The set of environment names and the method for altering the environment list are
23599     implementation-defined.
23600     Returns
23601 8   The getenv_s function returns zero if the specified name is found and the associated
23602     string was successfully stored in value. Otherwise, a nonzero value is returned.
23603     K.3.6.3 Searching and sorting utilities
23604 1   These utilities make use of a comparison function to search or sort arrays of unspecified
23605     type. Where an argument declared as size_t nmemb specifies the length of the array
23606     for a function, if nmemb has the value zero on a call to that function, then the comparison
23607     function is not called, a search finds no matching element, sorting performs no
23608     rearrangement, and the pointer to the array may be null.
23609 2   The implementation shall ensure that the second argument of the comparison function
23610     (when called from bsearch_s), or both arguments (when called from qsort_s), are
23611     pointers to elements of the array.395) The first argument when called from bsearch_s
23612     shall equal key.
23613 3   The comparison function shall not alter the contents of either the array or search key. The
23614     implementation may reorder elements of the array between calls to the comparison
23615     function, but shall not otherwise alter the contents of any individual element.
23616 4   When the same objects (consisting of size bytes, irrespective of their current positions
23617     in the array) are passed more than once to the comparison function, the results shall be
23618     consistent with one another. That is, for qsort_s they shall define a total ordering on
23619     the array, and for bsearch_s the same object shall always compare the same way with
23620     the key.
23621
23622
23623
23624
23625     395) That is, if the value passed is p, then the following expressions are always valid and nonzero:
23626                   ((char *)p - (char *)base) % size == 0
23627                   (char *)p >= (char *)base
23628                   (char *)p < (char *)base + nmemb * size
23629
23630
23631 [page 603]
23632
23633 5   A sequence point occurs immediately before and immediately after each call to the
23634     comparison function, and also between any call to the comparison function and any
23635     movement of the objects passed as arguments to that call.
23636     K.3.6.3.1 The bsearch_s function
23637     Synopsis
23638 1            #define __STDC_WANT_LIB_EXT1__ 1
23639              #include <stdlib.h>
23640              void *bsearch_s(const void *key, const void *base,
23641                   rsize_t nmemb, rsize_t size,
23642                   int (*compar)(const void *k, const void *y,
23643                                   void *context),
23644                   void *context);
23645     Runtime-constraints
23646 2   Neither nmemb nor size shall be greater than RSIZE_MAX. If nmemb is not equal to
23647     zero, then none of key, base, or compar shall be a null pointer.
23648 3   If there is a runtime-constraint violation, the bsearch_s function does not search the
23649     array.
23650     Description
23651 4   The bsearch_s function searches an array of nmemb objects, the initial element of
23652     which is pointed to by base, for an element that matches the object pointed to by key.
23653     The size of each element of the array is specified by size.
23654 5   The comparison function pointed to by compar is called with three arguments. The first
23655     two point to the key object and to an array element, in that order. The function shall
23656     return an integer less than, equal to, or greater than zero if the key object is considered,
23657     respectively, to be less than, to match, or to be greater than the array element. The array
23658     shall consist of: all the elements that compare less than, all the elements that compare
23659     equal to, and all the elements that compare greater than the key object, in that order.396)
23660     The third argument to the comparison function is the context argument passed to
23661     bsearch_s. The sole use of context by bsearch_s is to pass it to the comparison
23662     function.397)
23663
23664
23665
23666
23667     396) In practice, this means that the entire array has been sorted according to the comparison function.
23668     397) The context argument is for the use of the comparison function in performing its duties. For
23669          example, it might specify a collating sequence used by the comparison function.
23670
23671 [page 604]
23672
23673     Returns
23674 6   The bsearch_s function returns a pointer to a matching element of the array, or a null
23675     pointer if no match is found or there is a runtime-constraint violation. If two elements
23676     compare as equal, which element is matched is unspecified.
23677     K.3.6.3.2 The qsort_s function
23678     Synopsis
23679 1           #define __STDC_WANT_LIB_EXT1__ 1
23680             #include <stdlib.h>
23681             errno_t qsort_s(void *base, rsize_t nmemb, rsize_t size,
23682                  int (*compar)(const void *x, const void *y,
23683                                  void *context),
23684                  void *context);
23685     Runtime-constraints
23686 2   Neither nmemb nor size shall be greater than RSIZE_MAX. If nmemb is not equal to
23687     zero, then neither base nor compar shall be a null pointer.
23688 3   If there is a runtime-constraint violation, the qsort_s function does not sort the array.
23689     Description
23690 4   The qsort_s function sorts an array of nmemb objects, the initial element of which is
23691     pointed to by base. The size of each object is specified by size.
23692 5   The contents of the array are sorted into ascending order according to a comparison
23693     function pointed to by compar, which is called with three arguments. The first two
23694     point to the objects being compared. The function shall return an integer less than, equal
23695     to, or greater than zero if the first argument is considered to be respectively less than,
23696     equal to, or greater than the second. The third argument to the comparison function is the
23697     context argument passed to qsort_s. The sole use of context by qsort_s is to
23698     pass it to the comparison function.398)
23699 6   If two elements compare as equal, their relative order in the resulting sorted array is
23700     unspecified.
23701     Returns
23702 7   The qsort_s function returns zero if there was no runtime-constraint violation.
23703     Otherwise, a nonzero value is returned.
23704
23705
23706
23707
23708     398) The context argument is for the use of the comparison function in performing its duties. For
23709          example, it might specify a collating sequence used by the comparison function.
23710
23711 [page 605]
23712
23713     K.3.6.4 Multibyte/wide character conversion functions
23714 1   The behavior of the multibyte character functions is affected by the LC_CTYPE category
23715     of the current locale. For a state-dependent encoding, each function is placed into its
23716     initial conversion state by a call for which its character pointer argument, s, is a null
23717     pointer. Subsequent calls with s as other than a null pointer cause the internal conversion
23718     state of the function to be altered as necessary. A call with s as a null pointer causes
23719     these functions to set the int pointed to by their status argument to a nonzero value if
23720     encodings have state dependency, and zero otherwise.399) Changing the LC_CTYPE
23721     category causes the conversion state of these functions to be indeterminate.
23722     K.3.6.4.1 The wctomb_s function
23723     Synopsis
23724 1           #define __STDC_WANT_LIB_EXT1__ 1
23725             #include <stdlib.h>
23726             errno_t wctomb_s(int * restrict status,
23727                  char * restrict s,
23728                  rsize_t smax,
23729                  wchar_t wc);
23730     Runtime-constraints
23731 2   Let n denote the number of bytes needed to represent the multibyte character
23732     corresponding to the wide character given by wc (including any shift sequences).
23733 3   If s is not a null pointer, then smax shall not be less than n, and smax shall not be
23734     greater than RSIZE_MAX. If s is a null pointer, then smax shall equal zero.
23735 4   If there is a runtime-constraint violation, wctomb_s does not modify the int pointed to
23736     by status, and if s is not a null pointer, no more than smax elements in the array
23737     pointed to by s will be accessed.
23738     Description
23739 5   The wctomb_s function determines n and stores the multibyte character representation
23740     of wc in the array whose first element is pointed to by s (if s is not a null pointer). The
23741     number of characters stored never exceeds MB_CUR_MAX or smax. If wc is a null wide
23742     character, a null byte is stored, preceded by any shift sequence needed to restore the
23743     initial shift state, and the function is left in the initial conversion state.
23744 6   The implementation shall behave as if no library function calls the wctomb_s function.
23745
23746
23747
23748
23749     399) If the locale employs special bytes to change the shift state, these bytes do not produce separate wide
23750          character codes, but are grouped with an adjacent multibyte character.
23751
23752 [page 606]
23753
23754 7    If s is a null pointer, the wctomb_s function stores into the int pointed to by status a
23755      nonzero or zero value, if multibyte character encodings, respectively, do or do not have
23756      state-dependent encodings.
23757 8    If s is not a null pointer, the wctomb_s function stores into the int pointed to by
23758      status either n or -1 if wc, respectively, does or does not correspond to a valid
23759      multibyte character.
23760 9    In no case will the int pointed to by status be set to a value greater than the
23761      MB_CUR_MAX macro.
23762      Returns
23763 10   The wctomb_s function returns zero if successful, and a nonzero value if there was a
23764      runtime-constraint violation or wc did not correspond to a valid multibyte character.
23765      K.3.6.5 Multibyte/wide string conversion functions
23766 1    The behavior of the multibyte string functions is affected by the LC_CTYPE category of
23767      the current locale.
23768      K.3.6.5.1 The mbstowcs_s function
23769      Synopsis
23770 1            #include <stdlib.h>
23771              errno_t mbstowcs_s(size_t * restrict retval,
23772                   wchar_t * restrict dst, rsize_t dstmax,
23773                   const char * restrict src, rsize_t len);
23774      Runtime-constraints
23775 2    Neither retval nor src shall be a null pointer. If dst is not a null pointer, then
23776      neither len nor dstmax shall be greater than RSIZE_MAX. If dst is a null pointer,
23777      then dstmax shall equal zero. If dst is not a null pointer, then dstmax shall not equal
23778      zero. If dst is not a null pointer and len is not less than dstmax, then a null character
23779      shall occur within the first dstmax multibyte characters of the array pointed to by src.
23780 3    If there is a runtime-constraint violation, then mbstowcs_s does the following. If
23781      retval is not a null pointer, then mbstowcs_s sets *retval to (size_t)(-1). If
23782      dst is not a null pointer and dstmax is greater than zero and less than RSIZE_MAX,
23783      then mbstowcs_s sets dst[0] to the null wide character.
23784      Description
23785 4    The mbstowcs_s function converts a sequence of multibyte characters that begins in
23786      the initial shift state from the array pointed to by src into a sequence of corresponding
23787      wide characters. If dst is not a null pointer, the converted characters are stored into the
23788      array pointed to by dst. Conversion continues up to and including a terminating null
23789      character, which is also stored. Conversion stops earlier in two cases: when a sequence of
23790 [page 607]
23791
23792     bytes is encountered that does not form a valid multibyte character, or (if dst is not a
23793     null pointer) when len wide characters have been stored into the array pointed to by
23794     dst.400) If dst is not a null pointer and no null wide character was stored into the array
23795     pointed to by dst, then dst[len] is set to the null wide character. Each conversion
23796     takes place as if by a call to the mbrtowc function.
23797 5   Regardless of whether dst is or is not a null pointer, if the input conversion encounters a
23798     sequence of bytes that do not form a valid multibyte character, an encoding error occurs:
23799     the mbstowcs_s function stores the value (size_t)(-1) into *retval.
23800     Otherwise, the mbstowcs_s function stores into *retval the number of multibyte
23801     characters successfully converted, not including the terminating null character (if any).
23802 6   All elements following the terminating null wide character (if any) written by
23803     mbstowcs_s in the array of dstmax wide characters pointed to by dst take
23804     unspecified values when mbstowcs_s returns.401)
23805 7   If copying takes place between objects that overlap, the objects take on unspecified
23806     values.
23807     Returns
23808 8   The mbstowcs_s function returns zero if no runtime-constraint violation and no
23809     encoding error occurred. Otherwise, a nonzero value is returned.
23810     K.3.6.5.2 The wcstombs_s function
23811     Synopsis
23812 1            #include <stdlib.h>
23813              errno_t wcstombs_s(size_t * restrict retval,
23814                   char * restrict dst, rsize_t dstmax,
23815                   const wchar_t * restrict src, rsize_t len);
23816     Runtime-constraints
23817 2   Neither retval nor src shall be a null pointer. If dst is not a null pointer, then
23818     neither len nor dstmax shall be greater than RSIZE_MAX. If dst is a null pointer,
23819     then dstmax shall equal zero. If dst is not a null pointer, then dstmax shall not equal
23820     zero. If dst is not a null pointer and len is not less than dstmax, then the conversion
23821     shall have been stopped (see below) because a terminating null wide character was
23822     reached or because an encoding error occurred.
23823
23824
23825
23826
23827     400) Thus, the value of len is ignored if dst is a null pointer.
23828     401) This allows an implementation to attempt converting the multibyte string before discovering a
23829          terminating null character did not occur where required.
23830
23831 [page 608]
23832
23833 3   If there is a runtime-constraint violation, then wcstombs_s does the following. If
23834     retval is not a null pointer, then wcstombs_s sets *retval to (size_t)(-1). If
23835     dst is not a null pointer and dstmax is greater than zero and less than RSIZE_MAX,
23836     then wcstombs_s sets dst[0] to the null character.
23837     Description
23838 4   The wcstombs_s function converts a sequence of wide characters from the array
23839     pointed to by src into a sequence of corresponding multibyte characters that begins in
23840     the initial shift state. If dst is not a null pointer, the converted characters are then stored
23841     into the array pointed to by dst. Conversion continues up to and including a terminating
23842     null wide character, which is also stored. Conversion stops earlier in two cases:
23843     -- when a wide character is reached that does not correspond to a valid multibyte
23844       character;
23845     -- (if dst is not a null pointer) when the next multibyte character would exceed the
23846         limit of n total bytes to be stored into the array pointed to by dst. If the wide
23847         character being converted is the null wide character, then n is the lesser of len or
23848         dstmax. Otherwise, n is the lesser of len or dstmax-1.
23849     If the conversion stops without converting a null wide character and dst is not a null
23850     pointer, then a null character is stored into the array pointed to by dst immediately
23851     following any multibyte characters already stored. Each conversion takes place as if by a
23852     call to the wcrtomb function.402)
23853 5   Regardless of whether dst is or is not a null pointer, if the input conversion encounters a
23854     wide character that does not correspond to a valid multibyte character, an encoding error
23855     occurs: the wcstombs_s function stores the value (size_t)(-1) into *retval.
23856     Otherwise, the wcstombs_s function stores into *retval the number of bytes in the
23857     resulting multibyte character sequence, not including the terminating null character (if
23858     any).
23859 6   All elements following the terminating null character (if any) written by wcstombs_s
23860     in the array of dstmax elements pointed to by dst take unspecified values when
23861     wcstombs_s returns.403)
23862 7   If copying takes place between objects that overlap, the objects take on unspecified
23863     values.
23864
23865
23866     402) If conversion stops because a terminating null wide character has been reached, the bytes stored
23867          include those necessary to reach the initial shift state immediately before the null byte. However, if
23868          the conversion stops before a terminating null wide character has been reached, the result will be null
23869          terminated, but might not end in the initial shift state.
23870     403) When len is not less than dstmax, the implementation might fill the array before discovering a
23871          runtime-constraint violation.
23872
23873 [page 609]
23874
23875     Returns
23876 8   The wcstombs_s function returns zero if no runtime-constraint violation and no
23877     encoding error occurred. Otherwise, a nonzero value is returned.
23878     K.3.7 String handling <string.h>
23879 1   The header <string.h> defines two types.
23880 2   The types are
23881            errno_t
23882     which is type int; and
23883            rsize_t
23884     which is the type size_t.
23885     K.3.7.1 Copying functions
23886     K.3.7.1.1 The memcpy_s function
23887     Synopsis
23888 1          #define __STDC_WANT_LIB_EXT1__ 1
23889            #include <string.h>
23890            errno_t memcpy_s(void * restrict s1, rsize_t s1max,
23891                 const void * restrict s2, rsize_t n);
23892     Runtime-constraints
23893 2   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
23894     RSIZE_MAX. n shall not be greater than s1max. Copying shall not take place between
23895     objects that overlap.
23896 3   If there is a runtime-constraint violation, the memcpy_s function stores zeros in the first
23897     s1max characters of the object pointed to by s1 if s1 is not a null pointer and s1max is
23898     not greater than RSIZE_MAX.
23899     Description
23900 4   The memcpy_s function copies n characters from the object pointed to by s2 into the
23901     object pointed to by s1.
23902     Returns
23903 5   The memcpy_s function returns zero if there was no runtime-constraint violation.
23904     Otherwise, a nonzero value is returned.
23905
23906
23907
23908
23909 [page 610]
23910
23911     K.3.7.1.2 The memmove_s function
23912     Synopsis
23913 1           #define __STDC_WANT_LIB_EXT1__ 1
23914             #include <string.h>
23915             errno_t memmove_s(void *s1, rsize_t s1max,
23916                  const void *s2, rsize_t n);
23917     Runtime-constraints
23918 2   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
23919     RSIZE_MAX. n shall not be greater than s1max.
23920 3   If there is a runtime-constraint violation, the memmove_s function stores zeros in the
23921     first s1max characters of the object pointed to by s1 if s1 is not a null pointer and
23922     s1max is not greater than RSIZE_MAX.
23923     Description
23924 4   The memmove_s function copies n characters from the object pointed to by s2 into the
23925     object pointed to by s1. This copying takes place as if the n characters from the object
23926     pointed to by s2 are first copied into a temporary array of n characters that does not
23927     overlap the objects pointed to by s1 or s2, and then the n characters from the temporary
23928     array are copied into the object pointed to by s1.
23929     Returns
23930 5   The memmove_s function returns zero if there was no runtime-constraint violation.
23931     Otherwise, a nonzero value is returned.
23932     K.3.7.1.3 The strcpy_s function
23933     Synopsis
23934 1           #define __STDC_WANT_LIB_EXT1__ 1
23935             #include <string.h>
23936             errno_t strcpy_s(char * restrict s1,
23937                  rsize_t s1max,
23938                  const char * restrict s2);
23939     Runtime-constraints
23940 2   Neither s1 nor s2 shall be a null pointer. s1max shall not be greater than RSIZE_MAX.
23941     s1max shall not equal zero. s1max shall be greater than strnlen_s(s2, s1max).
23942     Copying shall not take place between objects that overlap.
23943 3   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
23944     greater than zero and not greater than RSIZE_MAX, then strcpy_s sets s1[0] to the
23945     null character.
23946
23947 [page 611]
23948
23949     Description
23950 4   The strcpy_s function copies the string pointed to by s2 (including the terminating
23951     null character) into the array pointed to by s1.
23952 5   All elements following the terminating null character (if any) written by strcpy_s in
23953     the array of s1max characters pointed to by s1 take unspecified values when
23954     strcpy_s returns.404)
23955     Returns
23956 6   The strcpy_s function returns zero405) if there was no runtime-constraint violation.
23957     Otherwise, a nonzero value is returned.
23958     K.3.7.1.4 The strncpy_s function
23959     Synopsis
23960 1           #define __STDC_WANT_LIB_EXT1__ 1
23961             #include <string.h>
23962             errno_t strncpy_s(char * restrict s1,
23963                  rsize_t s1max,
23964                  const char * restrict s2,
23965                  rsize_t n);
23966     Runtime-constraints
23967 2   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
23968     RSIZE_MAX. s1max shall not equal zero. If n is not less than s1max, then s1max
23969     shall be greater than strnlen_s(s2, s1max). Copying shall not take place between
23970     objects that overlap.
23971 3   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
23972     greater than zero and not greater than RSIZE_MAX, then strncpy_s sets s1[0] to the
23973     null character.
23974     Description
23975 4   The strncpy_s function copies not more than n successive characters (characters that
23976     follow a null character are not copied) from the array pointed to by s2 to the array
23977     pointed to by s1. If no null character was copied from s2, then s1[n] is set to a null
23978     character.
23979
23980
23981     404) This allows an implementation to copy characters from s2 to s1 while simultaneously checking if
23982          any of those characters are null. Such an approach might write a character to every element of s1
23983          before discovering that the first element should be set to the null character.
23984     405) A zero return value implies that all of the requested characters from the string pointed to by s2 fit
23985          within the array pointed to by s1 and that the result in s1 is null terminated.
23986
23987 [page 612]
23988
23989 5   All elements following the terminating null character (if any) written by strncpy_s in
23990     the array of s1max characters pointed to by s1 take unspecified values when
23991     strncpy_s returns.406)
23992     Returns
23993 6   The strncpy_s function returns zero407) if there was no runtime-constraint violation.
23994     Otherwise, a nonzero value is returned.
23995 7   EXAMPLE 1 The strncpy_s function can be used to copy a string without the danger that the result
23996     will not be null terminated or that characters will be written past the end of the destination array.
23997             #define __STDC_WANT_LIB_EXT1__ 1
23998             #include <string.h>
23999             /* ... */
24000             char src1[100] = "hello";
24001             char src2[7] = {'g', 'o', 'o', 'd', 'b', 'y', 'e'};
24002             char dst1[6], dst2[5], dst3[5];
24003             int r1, r2, r3;
24004             r1 = strncpy_s(dst1, 6, src1, 100);
24005             r2 = strncpy_s(dst2, 5, src2, 7);
24006             r3 = strncpy_s(dst3, 5, src2, 4);
24007     The first call will assign to r1 the value zero and to dst1 the sequence hello\0.
24008     The second call will assign to r2 a nonzero value and to dst2 the sequence \0.
24009     The third call will assign to r3 the value zero and to dst3 the sequence good\0.
24010
24011     K.3.7.2 Concatenation functions
24012     K.3.7.2.1 The strcat_s function
24013     Synopsis
24014 1           #define __STDC_WANT_LIB_EXT1__ 1
24015             #include <string.h>
24016             errno_t strcat_s(char * restrict s1,
24017                  rsize_t s1max,
24018                  const char * restrict s2);
24019     Runtime-constraints
24020 2   Let m denote the value s1max - strnlen_s(s1, s1max) upon entry to
24021     strcat_s.
24022
24023
24024
24025
24026     406) This allows an implementation to copy characters from s2 to s1 while simultaneously checking if
24027          any of those characters are null. Such an approach might write a character to every element of s1
24028          before discovering that the first element should be set to the null character.
24029     407) A zero return value implies that all of the requested characters from the string pointed to by s2 fit
24030          within the array pointed to by s1 and that the result in s1 is null terminated.
24031
24032 [page 613]
24033
24034 3   Neither s1 nor s2 shall be a null pointer. s1max shall not be greater than RSIZE_MAX.
24035     s1max shall not equal zero. m shall not equal zero.408) m shall be greater than
24036     strnlen_s(s2, m). Copying shall not take place between objects that overlap.
24037 4   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
24038     greater than zero and not greater than RSIZE_MAX, then strcat_s sets s1[0] to the
24039     null character.
24040     Description
24041 5   The strcat_s function appends a copy of the string pointed to by s2 (including the
24042     terminating null character) to the end of the string pointed to by s1. The initial character
24043     from s2 overwrites the null character at the end of s1.
24044 6   All elements following the terminating null character (if any) written by strcat_s in
24045     the array of s1max characters pointed to by s1 take unspecified values when
24046     strcat_s returns.409)
24047     Returns
24048 7   The strcat_s function returns zero410) if there was no runtime-constraint violation.
24049     Otherwise, a nonzero value is returned.
24050     K.3.7.2.2 The strncat_s function
24051     Synopsis
24052 1           #define __STDC_WANT_LIB_EXT1__ 1
24053             #include <string.h>
24054             errno_t strncat_s(char * restrict s1,
24055                  rsize_t s1max,
24056                  const char * restrict s2,
24057                  rsize_t n);
24058     Runtime-constraints
24059 2   Let m denote the value s1max - strnlen_s(s1, s1max) upon entry to
24060     strncat_s.
24061 3   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
24062     RSIZE_MAX. s1max shall not equal zero. m shall not equal zero.411) If n is not less
24063
24064
24065     408) Zero means that s1 was not null terminated upon entry to strcat_s.
24066     409) This allows an implementation to append characters from s2 to s1 while simultaneously checking if
24067          any of those characters are null. Such an approach might write a character to every element of s1
24068          before discovering that the first element should be set to the null character.
24069     410) A zero return value implies that all of the requested characters from the string pointed to by s2 were
24070          appended to the string pointed to by s1 and that the result in s1 is null terminated.
24071
24072 [page 614]
24073
24074     than m, then m shall be greater than strnlen_s(s2, m). Copying shall not take
24075     place between objects that overlap.
24076 4   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
24077     greater than zero and not greater than RSIZE_MAX, then strncat_s sets s1[0] to the
24078     null character.
24079     Description
24080 5   The strncat_s function appends not more than n successive characters (characters
24081     that follow a null character are not copied) from the array pointed to by s2 to the end of
24082     the string pointed to by s1. The initial character from s2 overwrites the null character at
24083     the end of s1. If no null character was copied from s2, then s1[s1max-m+n] is set to
24084     a null character.
24085 6   All elements following the terminating null character (if any) written by strncat_s in
24086     the array of s1max characters pointed to by s1 take unspecified values when
24087     strncat_s returns.412)
24088     Returns
24089 7   The strncat_s function returns zero413) if there was no runtime-constraint violation.
24090     Otherwise, a nonzero value is returned.
24091 8   EXAMPLE 1 The strncat_s function can be used to copy a string without the danger that the result
24092     will not be null terminated or that characters will be written past the end of the destination array.
24093             #define __STDC_WANT_LIB_EXT1__ 1
24094             #include <string.h>
24095             /* ... */
24096             char s1[100] = "good";
24097             char s2[6] = "hello";
24098             char s3[6] = "hello";
24099             char s4[7] = "abc";
24100             char s5[1000] = "bye";
24101             int r1, r2, r3, r4;
24102             r1 = strncat_s(s1, 100, s5, 1000);
24103             r2 = strncat_s(s2, 6, "", 1);
24104             r3 = strncat_s(s3, 6, "X", 2);
24105             r4 = strncat_s(s4, 7, "defghijklmn", 3);
24106     After the first call r1 will have the value zero and s1 will contain the sequence goodbye\0.
24107
24108
24109
24110     411) Zero means that s1 was not null terminated upon entry to strncat_s.
24111     412) This allows an implementation to append characters from s2 to s1 while simultaneously checking if
24112          any of those characters are null. Such an approach might write a character to every element of s1
24113          before discovering that the first element should be set to the null character.
24114     413) A zero return value implies that all of the requested characters from the string pointed to by s2 were
24115          appended to the string pointed to by s1 and that the result in s1 is null terminated.
24116
24117 [page 615]
24118
24119     After the second call r2 will have the value zero and s2 will contain the sequence hello\0.
24120     After the third call r3 will have a nonzero value and s3 will contain the sequence \0.
24121     After the fourth call r4 will have the value zero and s4 will contain the sequence abcdef\0.
24122
24123     K.3.7.3 Search functions
24124     K.3.7.3.1 The strtok_s function
24125     Synopsis
24126 1           #define __STDC_WANT_LIB_EXT1__ 1
24127             #include <string.h>
24128             char *strtok_s(char * restrict s1,
24129                  rsize_t * restrict s1max,
24130                  const char * restrict s2,
24131                  char ** restrict ptr);
24132     Runtime-constraints
24133 2   None of s1max, s2, or ptr shall be a null pointer. If s1 is a null pointer, then *ptr
24134     shall not be a null pointer. The value of *s1max shall not be greater than RSIZE_MAX.
24135     The end of the token found shall occur within the first *s1max characters of s1 for the
24136     first call, and shall occur within the first *s1max characters of where searching resumes
24137     on subsequent calls.
24138 3   If there is a runtime-constraint violation, the strtok_s function does not indirect
24139     through the s1 or s2 pointers, and does not store a value in the object pointed to by ptr.
24140     Description
24141 4   A sequence of calls to the strtok_s function breaks the string pointed to by s1 into a
24142     sequence of tokens, each of which is delimited by a character from the string pointed to
24143     by s2. The fourth argument points to a caller-provided char pointer into which the
24144     strtok_s function stores information necessary for it to continue scanning the same
24145     string.
24146 5   The first call in a sequence has a non-null first argument and s1max points to an object
24147     whose value is the number of elements in the character array pointed to by the first
24148     argument. The first call stores an initial value in the object pointed to by ptr and
24149     updates the value pointed to by s1max to reflect the number of elements that remain in
24150     relation to ptr. Subsequent calls in the sequence have a null first argument and the
24151     objects pointed to by s1max and ptr are required to have the values stored by the
24152     previous call in the sequence, which are then updated. The separator string pointed to by
24153     s2 may be different from call to call.
24154 6   The first call in the sequence searches the string pointed to by s1 for the first character
24155     that is not contained in the current separator string pointed to by s2. If no such character
24156     is found, then there are no tokens in the string pointed to by s1 and the strtok_s
24157     function returns a null pointer. If such a character is found, it is the start of the first token.
24158 [page 616]
24159
24160 7    The strtok_s function then searches from there for the first character in s1 that is
24161      contained in the current separator string. If no such character is found, the current token
24162      extends to the end of the string pointed to by s1, and subsequent searches in the same
24163      string for a token return a null pointer. If such a character is found, it is overwritten by a
24164      null character, which terminates the current token.
24165 8    In all cases, the strtok_s function stores sufficient information in the pointer pointed
24166      to by ptr so that subsequent calls, with a null pointer for s1 and the unmodified pointer
24167      value for ptr, shall start searching just past the element overwritten by a null character
24168      (if any).
24169      Returns
24170 9    The strtok_s function returns a pointer to the first character of a token, or a null
24171      pointer if there is no token or there is a runtime-constraint violation.
24172 10   EXAMPLE
24173              #define __STDC_WANT_LIB_EXT1__ 1
24174              #include <string.h>
24175              static char str1[] = "?a???b,,,#c";
24176              static char str2[] = "\t \t";
24177              char *t, *ptr1, *ptr2;
24178              rsize_t max1 = sizeof(str1);
24179              rsize_t max2 = sizeof(str2);
24180              t   =   strtok_s(str1,   &max1,   "?", &ptr1);        //   t   points to the token "a"
24181              t   =   strtok_s(NULL,   &max1,   ",", &ptr1);        //   t   points to the token "??b"
24182              t   =   strtok_s(str2,   &max2,   " \t", &ptr2);      //   t   is a null pointer
24183              t   =   strtok_s(NULL,   &max1,   "#,", &ptr1);       //   t   points to the token "c"
24184              t   =   strtok_s(NULL,   &max1,   "?", &ptr1);        //   t   is a null pointer
24185
24186      K.3.7.4 Miscellaneous functions
24187      K.3.7.4.1 The memset_s function
24188      Synopsis
24189 1            #define __STDC_WANT_LIB_EXT1__ 1
24190              #include <string.h>
24191              errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n)
24192      Runtime-constraints
24193 2    s shall not be a null pointer. Neither smax nor n shall be greater than RSIZE_MAX. n
24194      shall not be greater than smax.
24195 3    If there is a runtime-constraint violation, then if s is not a null pointer and smax is not
24196      greater than RSIZE_MAX, the memset_s function stores the value of c (converted to an
24197      unsigned char) into each of the first smax characters of the object pointed to by s.
24198
24199
24200
24201 [page 617]
24202
24203     Description
24204 4   The memset_s function copies the value of c (converted to an unsigned char) into
24205     each of the first n characters of the object pointed to by s. Unlike memset, any call to
24206     the memset_s function shall be evaluated strictly according to the rules of the abstract
24207     machine as described in (5.1.2.3). That is, any call to the memset_s function shall
24208     assume that the memory indicated by s and n may be accessible in the future and thus
24209     must contain the values indicated by c.
24210     Returns
24211 5   The memset_s function returns zero if there was no runtime-constraint violation.
24212     Otherwise, a nonzero value is returned.
24213     K.3.7.4.2 The strerror_s function
24214     Synopsis
24215 1          #define __STDC_WANT_LIB_EXT1__ 1
24216            #include <string.h>
24217            errno_t strerror_s(char *s, rsize_t maxsize,
24218                 errno_t errnum);
24219     Runtime-constraints
24220 2   s shall not be a null pointer. maxsize shall not be greater than RSIZE_MAX.
24221     maxsize shall not equal zero.
24222 3   If there is a runtime-constraint violation, then the array (if any) pointed to by s is not
24223     modified.
24224     Description
24225 4   The strerror_s function maps the number in errnum to a locale-specific message
24226     string. Typically, the values for errnum come from errno, but strerror_s shall
24227     map any value of type int to a message.
24228 5   If the length of the desired string is less than maxsize, then the string is copied to the
24229     array pointed to by s.
24230 6   Otherwise, if maxsize is greater than zero, then maxsize-1 characters are copied
24231     from the string to the array pointed to by s and then s[maxsize-1] is set to the null
24232     character. Then, if maxsize is greater than 3, then s[maxsize-2],
24233     s[maxsize-3], and s[maxsize-4] are set to the character period (.).
24234     Returns
24235 7   The strerror_s function returns zero if the length of the desired string was less than
24236     maxsize and there was no runtime-constraint violation. Otherwise, the strerror_s
24237     function returns a nonzero value.
24238
24239 [page 618]
24240
24241     K.3.7.4.3 The strerrorlen_s function
24242     Synopsis
24243 1           #define __STDC_WANT_LIB_EXT1__ 1
24244             #include <string.h>
24245             size_t strerrorlen_s(errno_t errnum);
24246     Description
24247 2   The strerrorlen_s function calculates the length of the (untruncated) locale-specific
24248     message string that the strerror_s function maps to errnum.
24249     Returns
24250 3   The strerrorlen_s function returns the number of characters (not including the null
24251     character) in the full message string.
24252     K.3.7.4.4 The strnlen_s function
24253     Synopsis
24254 1           #define __STDC_WANT_LIB_EXT1__ 1
24255             #include <string.h>
24256             size_t strnlen_s(const char *s, size_t maxsize);
24257     Description
24258 2   The strnlen_s function computes the length of the string pointed to by s.
24259     Returns
24260 3   If s is a null pointer,414) then the strnlen_s function returns zero.
24261 4   Otherwise, the strnlen_s function returns the number of characters that precede the
24262     terminating null character. If there is no null character in the first maxsize characters of
24263     s then strnlen_s returns maxsize. At most the first maxsize characters of s shall
24264     be accessed by strnlen_s.
24265
24266
24267
24268
24269     414) Note that the strnlen_s function has no runtime-constraints. This lack of runtime-constraints
24270          along with the values returned for a null pointer or an unterminated string argument make
24271          strnlen_s useful in algorithms that gracefully handle such exceptional data.
24272
24273 [page 619]
24274
24275     K.3.8 Date and time <time.h>
24276 1   The header <time.h> defines two types.
24277 2   The types are
24278             errno_t
24279     which is type int; and
24280             rsize_t
24281     which is the type size_t.
24282     K.3.8.1 Components of time
24283 1   A broken-down time is normalized if the values of the members of the tm structure are in
24284     their normal rages.415)
24285     K.3.8.2 Time conversion functions
24286 1   Like the strftime function, the asctime_s and ctime_s functions do not return a
24287     pointer to a static object, and other library functions are permitted to call them.
24288     K.3.8.2.1 The asctime_s function
24289     Synopsis
24290 1           #define __STDC_WANT_LIB_EXT1__ 1
24291             #include <time.h>
24292             errno_t asctime_s(char *s, rsize_t maxsize,
24293                  const struct tm *timeptr);
24294     Runtime-constraints
24295 2   Neither s nor timeptr shall be a null pointer. maxsize shall not be less than 26 and
24296     shall not be greater than RSIZE_MAX. The broken-down time pointed to by timeptr
24297     shall be normalized. The calendar year represented by the broken-down time pointed to
24298     by timeptr shall not be less than calendar year 0 and shall not be greater than calendar
24299     year 9999.
24300 3   If there is a runtime-constraint violation, there is no attempt to convert the time, and
24301     s[0] is set to a null character if s is not a null pointer and maxsize is not zero and is
24302     not greater than RSIZE_MAX.
24303     Description
24304 4   The asctime_s function converts the normalized broken-down time in the structure
24305     pointed to by timeptr into a 26 character (including the null character) string in the
24306
24307
24308     415) The normal ranges are defined in 7.26.1.
24309
24310 [page 620]
24311
24312     form
24313             Sun Sep 16 01:03:52 1973\n\0
24314     The fields making up this string are (in order):
24315        1.   The name of the day of the week represented by timeptr->tm_wday using the
24316             following three character weekday names: Sun, Mon, Tue, Wed, Thu, Fri, and Sat.
24317        2.   The character space.
24318        3. The name of the month represented by timeptr->tm_mon using the following
24319           three character month names: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct,
24320           Nov, and Dec.
24321        4.   The character space.
24322        5.   The value of timeptr->tm_mday as if printed using the fprintf format
24323             "%2d".
24324        6.   The character space.
24325        7.   The value of timeptr->tm_hour as if printed using the fprintf format
24326             "%.2d".
24327        8.   The character colon.
24328        9.   The value of timeptr->tm_min as if printed using the fprintf format
24329             "%.2d".
24330      10.    The character colon.
24331      11.    The value of timeptr->tm_sec as if printed using the fprintf format
24332             "%.2d".
24333      12.    The character space.
24334      13.    The value of timeptr->tm_year + 1900 as if printed using the fprintf
24335             format "%4d".
24336      14.    The character new line.
24337      15.    The null character.
24338     Recommended practice
24339     The strftime function allows more flexible formatting and supports locale-specific
24340     behavior. If you do not require the exact form of the result string produced by the
24341     asctime_s function, consider using the strftime function instead.
24342     Returns
24343 5   The asctime_s function returns zero if the time was successfully converted and stored
24344     into the array pointed to by s. Otherwise, it returns a nonzero value.
24345 [page 621]
24346
24347     K.3.8.2.2 The ctime_s function
24348     Synopsis
24349 1          #define __STDC_WANT_LIB_EXT1__ 1
24350            #include <time.h>
24351            errno_t ctime_s(char *s, rsize_t maxsize,
24352                 const time_t *timer);
24353     Runtime-constraints
24354 2   Neither s nor timer shall be a null pointer. maxsize shall not be less than 26 and
24355     shall not be greater than RSIZE_MAX.
24356 3   If there is a runtime-constraint violation, s[0] is set to a null character if s is not a null
24357     pointer and maxsize is not equal zero and is not greater than RSIZE_MAX.
24358     Description
24359 4   The ctime_s function converts the calendar time pointed to by timer to local time in
24360     the form of a string. It is equivalent to
24361            asctime_s(s, maxsize, localtime_s(timer))
24362     Recommended practice
24363     The strftime function allows more flexible formatting and supports locale-specific
24364     behavior. If you do not require the exact form of the result string produced by the
24365     ctime_s function, consider using the strftime function instead.
24366     Returns
24367 5   The ctime_s function returns zero if the time was successfully converted and stored
24368     into the array pointed to by s. Otherwise, it returns a nonzero value.
24369     K.3.8.2.3 The gmtime_s function
24370     Synopsis
24371 1          #define __STDC_WANT_LIB_EXT1__ 1
24372            #include <time.h>
24373            struct tm *gmtime_s(const time_t * restrict timer,
24374                 struct tm * restrict result);
24375     Runtime-constraints
24376 2   Neither timer nor result shall be a null pointer.
24377 3   If there is a runtime-constraint violation, there is no attempt to convert the time.
24378     Description
24379 4   The gmtime_s function converts the calendar time pointed to by timer into a broken-
24380     down time, expressed as UTC. The broken-down time is stored in the structure pointed
24381 [page 622]
24382
24383     to by result.
24384     Returns
24385 5   The gmtime_s function returns result, or a null pointer if the specified time cannot
24386     be converted to UTC or there is a runtime-constraint violation.
24387     K.3.8.2.4 The localtime_s function
24388     Synopsis
24389 1            #define __STDC_WANT_LIB_EXT1__ 1
24390              #include <time.h>
24391              struct tm *localtime_s(const time_t * restrict timer,
24392                   struct tm * restrict result);
24393     Runtime-constraints
24394 2   Neither timer nor result shall be a null pointer.
24395 3   If there is a runtime-constraint violation, there is no attempt to convert the time.
24396     Description
24397 4   The localtime_s function converts the calendar time pointed to by timer into a
24398     broken-down time, expressed as local time. The broken-down time is stored in the
24399     structure pointed to by result.
24400     Returns
24401 5   The localtime_s function returns result, or a null pointer if the specified time
24402     cannot be converted to local time or there is a runtime-constraint violation.
24403     K.3.9 Extended multibyte and wide character utilities <wchar.h>
24404 1   The header <wchar.h> defines two types.
24405 2   The types are
24406              errno_t
24407     which is type int; and
24408              rsize_t
24409     which is the type size_t.
24410 3   Unless explicitly stated otherwise, if the execution of a function described in this
24411     subclause causes copying to take place between objects that overlap, the objects take on
24412     unspecified values.
24413
24414
24415
24416
24417 [page 623]
24418
24419     K.3.9.1 Formatted wide character input/output functions
24420     K.3.9.1.1 The fwprintf_s function
24421     Synopsis
24422 1           #define __STDC_WANT_LIB_EXT1__ 1
24423             #include <wchar.h>
24424             int fwprintf_s(FILE * restrict stream,
24425                  const wchar_t * restrict format, ...);
24426     Runtime-constraints
24427 2   Neither stream nor format shall be a null pointer. The %n specifier416) (modified or
24428     not by flags, field width, or precision) shall not appear in the wide string pointed to by
24429     format. Any argument to fwprintf_s corresponding to a %s specifier shall not be a
24430     null pointer.
24431 3   If there is a runtime-constraint violation, the fwprintf_s function does not attempt to
24432     produce further output, and it is unspecified to what extent fwprintf_s produced
24433     output before discovering the runtime-constraint violation.
24434     Description
24435 4   The fwprintf_s function is equivalent to the fwprintf function except for the
24436     explicit runtime-constraints listed above.
24437     Returns
24438 5   The fwprintf_s function returns the number of wide characters transmitted, or a
24439     negative value if an output error, encoding error, or runtime-constraint violation occurred.
24440     K.3.9.1.2 The fwscanf_s function
24441     Synopsis
24442 1           #define __STDC_WANT_LIB_EXT1__ 1
24443             #include <stdio.h>
24444             #include <wchar.h>
24445             int fwscanf_s(FILE * restrict stream,
24446                  const wchar_t * restrict format, ...);
24447     Runtime-constraints
24448 2   Neither stream nor format shall be a null pointer. Any argument indirected though in
24449     order to store converted input shall not be a null pointer.
24450
24451
24452     416) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24453          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24454          example, if the entire format string was L"%%n".
24455
24456 [page 624]
24457
24458 3   If there is a runtime-constraint violation, the fwscanf_s function does not attempt to
24459     perform further input, and it is unspecified to what extent fwscanf_s performed input
24460     before discovering the runtime-constraint violation.
24461     Description
24462 4   The fwscanf_s function is equivalent to fwscanf except that the c, s, and [
24463     conversion specifiers apply to a pair of arguments (unless assignment suppression is
24464     indicated by a *). The first of these arguments is the same as for fwscanf. That
24465     argument is immediately followed in the argument list by the second argument, which has
24466     type size_t and gives the number of elements in the array pointed to by the first
24467     argument of the pair. If the first argument points to a scalar object, it is considered to be
24468     an array of one element.417)
24469 5   A matching failure occurs if the number of elements in a receiving object is insufficient to
24470     hold the converted input (including any trailing null character).
24471     Returns
24472 6   The fwscanf_s function returns the value of the macro EOF if an input failure occurs
24473     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24474     fwscanf_s function returns the number of input items assigned, which can be fewer
24475     than provided for, or even zero, in the event of an early matching failure.
24476     K.3.9.1.3 The snwprintf_s function
24477     Synopsis
24478 1           #define __STDC_WANT_LIB_EXT1__ 1
24479             #include <wchar.h>
24480             int snwprintf_s(wchar_t * restrict s,
24481                  rsize_t n,
24482                  const wchar_t * restrict format, ...);
24483     Runtime-constraints
24484 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
24485     than RSIZE_MAX. The %n specifier418) (modified or not by flags, field width, or
24486
24487     417) If the format is known at translation time, an implementation may issue a diagnostic for any argument
24488          used to store the result from a c, s, or [ conversion specifier if that argument is not followed by an
24489          argument of a type compatible with rsize_t. A limited amount of checking may be done if even if
24490          the format is not known at translation time. For example, an implementation may issue a diagnostic
24491          for each argument after format that has of type pointer to one of char, signed char,
24492          unsigned char, or void that is not followed by an argument of a type compatible with
24493          rsize_t. The diagnostic could warn that unless the pointer is being used with a conversion specifier
24494          using the hh length modifier, a length argument must follow the pointer argument. Another useful
24495          diagnostic could flag any non-pointer argument following format that did not have a type
24496          compatible with rsize_t.
24497
24498 [page 625]
24499
24500     precision) shall not appear in the wide string pointed to by format. Any argument to
24501     snwprintf_s corresponding to a %s specifier shall not be a null pointer. No encoding
24502     error shall occur.
24503 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
24504     than zero and less than RSIZE_MAX, then the snwprintf_s function sets s[0] to the
24505     null wide character.
24506     Description
24507 4   The snwprintf_s function is equivalent to the swprintf function except for the
24508     explicit runtime-constraints listed above.
24509 5   The snwprintf_s function, unlike swprintf_s, will truncate the result to fit within
24510     the array pointed to by s.
24511     Returns
24512 6   The snwprintf_s function returns the number of wide characters that would have
24513     been written had n been sufficiently large, not counting the terminating wide null
24514     character, or a negative value if a runtime-constraint violation occurred. Thus, the null-
24515     terminated output has been completely written if and only if the returned value is
24516     nonnegative and less than n.
24517     K.3.9.1.4 The swprintf_s function
24518     Synopsis
24519 1           #define __STDC_WANT_LIB_EXT1__ 1
24520             #include <wchar.h>
24521             int swprintf_s(wchar_t * restrict s, rsize_t n,
24522                  const wchar_t * restrict format, ...);
24523     Runtime-constraints
24524 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
24525     than RSIZE_MAX. The number of wide characters (including the trailing null) required
24526     for the result to be written to the array pointed to by s shall not be greater than n. The %n
24527     specifier419) (modified or not by flags, field width, or precision) shall not appear in the
24528     wide string pointed to by format. Any argument to swprintf_s corresponding to a
24529     %s specifier shall not be a null pointer. No encoding error shall occur.
24530
24531
24532     418) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24533          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24534          example, if the entire format string was L"%%n".
24535     419) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24536          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24537          example, if the entire format string was L"%%n".
24538
24539 [page 626]
24540
24541 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
24542     than zero and less than RSIZE_MAX, then the swprintf_s function sets s[0] to the
24543     null wide character.
24544     Description
24545 4   The swprintf_s function is equivalent to the swprintf function except for the
24546     explicit runtime-constraints listed above.
24547 5   The swprintf_s function, unlike snwprintf_s, treats a result too big for the array
24548     pointed to by s as a runtime-constraint violation.
24549     Returns
24550 6   If no runtime-constraint violation occurred, the swprintf_s function returns the
24551     number of wide characters written in the array, not counting the terminating null wide
24552     character. If an encoding error occurred or if n or more wide characters are requested to
24553     be written, swprintf_s returns a negative value. If any other runtime-constraint
24554     violation occurred, swprintf_s returns zero.
24555     K.3.9.1.5 The swscanf_s function
24556     Synopsis
24557 1           #define __STDC_WANT_LIB_EXT1__ 1
24558             #include <wchar.h>
24559             int swscanf_s(const wchar_t * restrict s,
24560                  const wchar_t * restrict format, ...);
24561     Runtime-constraints
24562 2   Neither s nor format shall be a null pointer. Any argument indirected though in order
24563     to store converted input shall not be a null pointer.
24564 3   If there is a runtime-constraint violation, the swscanf_s function does not attempt to
24565     perform further input, and it is unspecified to what extent swscanf_s performed input
24566     before discovering the runtime-constraint violation.
24567     Description
24568 4   The swscanf_s function is equivalent to fwscanf_s, except that the argument s
24569     specifies a wide string from which the input is to be obtained, rather than from a stream.
24570     Reaching the end of the wide string is equivalent to encountering end-of-file for the
24571     fwscanf_s function.
24572     Returns
24573 5   The swscanf_s function returns the value of the macro EOF if an input failure occurs
24574     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24575     swscanf_s function returns the number of input items assigned, which can be fewer
24576     than provided for, or even zero, in the event of an early matching failure.
24577 [page 627]
24578
24579     K.3.9.1.6 The vfwprintf_s function
24580     Synopsis
24581 1           #define __STDC_WANT_LIB_EXT1__ 1
24582             #include <stdarg.h>
24583             #include <stdio.h>
24584             #include <wchar.h>
24585             int vfwprintf_s(FILE * restrict stream,
24586                  const wchar_t * restrict format,
24587                  va_list arg);
24588     Runtime-constraints
24589 2   Neither stream nor format shall be a null pointer. The %n specifier420) (modified or
24590     not by flags, field width, or precision) shall not appear in the wide string pointed to by
24591     format. Any argument to vfwprintf_s corresponding to a %s specifier shall not be
24592     a null pointer.
24593 3   If there is a runtime-constraint violation, the vfwprintf_s function does not attempt
24594     to produce further output, and it is unspecified to what extent vfwprintf_s produced
24595     output before discovering the runtime-constraint violation.
24596     Description
24597 4   The vfwprintf_s function is equivalent to the vfwprintf function except for the
24598     explicit runtime-constraints listed above.
24599     Returns
24600 5   The vfwprintf_s function returns the number of wide characters transmitted, or a
24601     negative value if an output error, encoding error, or runtime-constraint violation occurred.
24602     K.3.9.1.7 The vfwscanf_s function
24603     Synopsis
24604 1           #define __STDC_WANT_LIB_EXT1__ 1
24605             #include <stdarg.h>
24606             #include <stdio.h>
24607             #include <wchar.h>
24608             int vfwscanf_s(FILE * restrict stream,
24609                  const wchar_t * restrict format, va_list arg);
24610
24611
24612
24613     420) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24614          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24615          example, if the entire format string was L"%%n".
24616
24617 [page 628]
24618
24619     Runtime-constraints
24620 2   Neither stream nor format shall be a null pointer. Any argument indirected though in
24621     order to store converted input shall not be a null pointer.
24622 3   If there is a runtime-constraint violation, the vfwscanf_s function does not attempt to
24623     perform further input, and it is unspecified to what extent vfwscanf_s performed input
24624     before discovering the runtime-constraint violation.
24625     Description
24626 4   The vfwscanf_s function is equivalent to fwscanf_s, with the variable argument
24627     list replaced by arg, which shall have been initialized by the va_start macro (and
24628     possibly subsequent va_arg calls). The vfwscanf_s function does not invoke the
24629     va_end macro.421)
24630     Returns
24631 5   The vfwscanf_s function returns the value of the macro EOF if an input failure occurs
24632     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24633     vfwscanf_s function returns the number of input items assigned, which can be fewer
24634     than provided for, or even zero, in the event of an early matching failure.
24635     K.3.9.1.8 The vsnwprintf_s function
24636     Synopsis
24637 1           #define __STDC_WANT_LIB_EXT1__ 1
24638             #include <stdarg.h>
24639             #include <wchar.h>
24640             int vsnwprintf_s(wchar_t * restrict s,
24641                  rsize_t n,
24642                  const wchar_t * restrict format,
24643                  va_list arg);
24644     Runtime-constraints
24645 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
24646     than RSIZE_MAX. The %n specifier422) (modified or not by flags, field width, or
24647     precision) shall not appear in the wide string pointed to by format. Any argument to
24648     vsnwprintf_s corresponding to a %s specifier shall not be a null pointer. No
24649     encoding error shall occur.
24650
24651     421) As the functions vfwscanf_s, vwscanf_s, and vswscanf_s invoke the va_arg macro, the
24652          value of arg after the return is indeterminate.
24653     422) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24654          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24655          example, if the entire format string was L"%%n".
24656
24657 [page 629]
24658
24659 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
24660     than zero and less than RSIZE_MAX, then the vsnwprintf_s function sets s[0] to
24661     the null wide character.
24662     Description
24663 4   The vsnwprintf_s function is equivalent to the vswprintf function except for the
24664     explicit runtime-constraints listed above.
24665 5   The vsnwprintf_s function, unlike vswprintf_s, will truncate the result to fit
24666     within the array pointed to by s.
24667     Returns
24668 6   The vsnwprintf_s function returns the number of wide characters that would have
24669     been written had n been sufficiently large, not counting the terminating null character, or
24670     a negative value if a runtime-constraint violation occurred. Thus, the null-terminated
24671     output has been completely written if and only if the returned value is nonnegative and
24672     less than n.
24673     K.3.9.1.9 The vswprintf_s function
24674     Synopsis
24675 1           #define __STDC_WANT_LIB_EXT1__ 1
24676             #include <stdarg.h>
24677             #include <wchar.h>
24678             int vswprintf_s(wchar_t * restrict s,
24679                  rsize_t n,
24680                  const wchar_t * restrict format,
24681                  va_list arg);
24682     Runtime-constraints
24683 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
24684     than RSIZE_MAX. The number of wide characters (including the trailing null) required
24685     for the result to be written to the array pointed to by s shall not be greater than n. The %n
24686     specifier423) (modified or not by flags, field width, or precision) shall not appear in the
24687     wide string pointed to by format. Any argument to vswprintf_s corresponding to a
24688     %s specifier shall not be a null pointer. No encoding error shall occur.
24689 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
24690     than zero and less than RSIZE_MAX, then the vswprintf_s function sets s[0] to the
24691     null wide character.
24692
24693     423) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24694          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24695          example, if the entire format string was L"%%n".
24696
24697 [page 630]
24698
24699     Description
24700 4   The vswprintf_s function is equivalent to the vswprintf function except for the
24701     explicit runtime-constraints listed above.
24702 5   The vswprintf_s function, unlike vsnwprintf_s, treats a result too big for the
24703     array pointed to by s as a runtime-constraint violation.
24704     Returns
24705 6   If no runtime-constraint violation occurred, the vswprintf_s function returns the
24706     number of wide characters written in the array, not counting the terminating null wide
24707     character. If an encoding error occurred or if n or more wide characters are requested to
24708     be written, vswprintf_s returns a negative value. If any other runtime-constraint
24709     violation occurred, vswprintf_s returns zero.
24710     K.3.9.1.10 The vswscanf_s function
24711     Synopsis
24712 1           #define __STDC_WANT_LIB_EXT1__ 1
24713             #include <stdarg.h>
24714             #include <wchar.h>
24715             int vswscanf_s(const wchar_t * restrict s,
24716                  const wchar_t * restrict format,
24717                  va_list arg);
24718     Runtime-constraints
24719 2   Neither s nor format shall be a null pointer. Any argument indirected though in order
24720     to store converted input shall not be a null pointer.
24721 3   If there is a runtime-constraint violation, the vswscanf_s function does not attempt to
24722     perform further input, and it is unspecified to what extent vswscanf_s performed input
24723     before discovering the runtime-constraint violation.
24724     Description
24725 4   The vswscanf_s function is equivalent to swscanf_s, with the variable argument
24726     list replaced by arg, which shall have been initialized by the va_start macro (and
24727     possibly subsequent va_arg calls). The vswscanf_s function does not invoke the
24728     va_end macro.424)
24729
24730
24731
24732
24733     424) As the functions vfwscanf_s, vwscanf_s, and vswscanf_s invoke the va_arg macro, the
24734          value of arg after the return is indeterminate.
24735
24736 [page 631]
24737
24738     Returns
24739 5   The vswscanf_s function returns the value of the macro EOF if an input failure occurs
24740     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24741     vswscanf_s function returns the number of input items assigned, which can be fewer
24742     than provided for, or even zero, in the event of an early matching failure.
24743     K.3.9.1.11 The vwprintf_s function
24744     Synopsis
24745 1           #define __STDC_WANT_LIB_EXT1__ 1
24746             #include <stdarg.h>
24747             #include <wchar.h>
24748             int vwprintf_s(const wchar_t * restrict format,
24749                  va_list arg);
24750     Runtime-constraints
24751 2   format shall not be a null pointer. The %n specifier425) (modified or not by flags, field
24752     width, or precision) shall not appear in the wide string pointed to by format. Any
24753     argument to vwprintf_s corresponding to a %s specifier shall not be a null pointer.
24754 3   If there is a runtime-constraint violation, the vwprintf_s function does not attempt to
24755     produce further output, and it is unspecified to what extent vwprintf_s produced
24756     output before discovering the runtime-constraint violation.
24757     Description
24758 4   The vwprintf_s function is equivalent to the vwprintf function except for the
24759     explicit runtime-constraints listed above.
24760     Returns
24761 5   The vwprintf_s function returns the number of wide characters transmitted, or a
24762     negative value if an output error, encoding error, or runtime-constraint violation occurred.
24763
24764
24765
24766
24767     425) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24768          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24769          example, if the entire format string was L"%%n".
24770
24771 [page 632]
24772
24773     K.3.9.1.12 The vwscanf_s function
24774     Synopsis
24775 1           #define __STDC_WANT_LIB_EXT1__ 1
24776             #include <stdarg.h>
24777             #include <wchar.h>
24778             int vwscanf_s(const wchar_t * restrict format,
24779                  va_list arg);
24780     Runtime-constraints
24781 2   format shall not be a null pointer. Any argument indirected though in order to store
24782     converted input shall not be a null pointer.
24783 3   If there is a runtime-constraint violation, the vwscanf_s function does not attempt to
24784     perform further input, and it is unspecified to what extent vwscanf_s performed input
24785     before discovering the runtime-constraint violation.
24786     Description
24787 4   The vwscanf_s function is equivalent to wscanf_s, with the variable argument list
24788     replaced by arg, which shall have been initialized by the va_start macro (and
24789     possibly subsequent va_arg calls). The vwscanf_s function does not invoke the
24790     va_end macro.426)
24791     Returns
24792 5   The vwscanf_s function returns the value of the macro EOF if an input failure occurs
24793     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24794     vwscanf_s function returns the number of input items assigned, which can be fewer
24795     than provided for, or even zero, in the event of an early matching failure.
24796     K.3.9.1.13 The wprintf_s function
24797     Synopsis
24798 1           #define __STDC_WANT_LIB_EXT1__ 1
24799             #include <wchar.h>
24800             int wprintf_s(const wchar_t * restrict format, ...);
24801     Runtime-constraints
24802 2   format shall not be a null pointer. The %n specifier427) (modified or not by flags, field
24803
24804     426) As the functions vfwscanf_s, vwscanf_s, and vswscanf_s invoke the va_arg macro, the
24805          value of arg after the return is indeterminate.
24806     427) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24807          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24808          example, if the entire format string was L"%%n".
24809
24810 [page 633]
24811
24812     width, or precision) shall not appear in the wide string pointed to by format. Any
24813     argument to wprintf_s corresponding to a %s specifier shall not be a null pointer.
24814 3   If there is a runtime-constraint violation, the wprintf_s function does not attempt to
24815     produce further output, and it is unspecified to what extent wprintf_s produced output
24816     before discovering the runtime-constraint violation.
24817     Description
24818 4   The wprintf_s function is equivalent to the wprintf function except for the explicit
24819     runtime-constraints listed above.
24820     Returns
24821 5   The wprintf_s function returns the number of wide characters transmitted, or a
24822     negative value if an output error, encoding error, or runtime-constraint violation occurred.
24823     K.3.9.1.14 The wscanf_s function
24824     Synopsis
24825 1          #define __STDC_WANT_LIB_EXT1__ 1
24826            #include <wchar.h>
24827            int wscanf_s(const wchar_t * restrict format, ...);
24828     Runtime-constraints
24829 2   format shall not be a null pointer. Any argument indirected though in order to store
24830     converted input shall not be a null pointer.
24831 3   If there is a runtime-constraint violation, the wscanf_s function does not attempt to
24832     perform further input, and it is unspecified to what extent wscanf_s performed input
24833     before discovering the runtime-constraint violation.
24834     Description
24835 4   The wscanf_s function is equivalent to fwscanf_s with the argument stdin
24836     interposed before the arguments to wscanf_s.
24837     Returns
24838 5   The wscanf_s function returns the value of the macro EOF if an input failure occurs
24839     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24840     wscanf_s function returns the number of input items assigned, which can be fewer than
24841     provided for, or even zero, in the event of an early matching failure.
24842
24843
24844
24845
24846 [page 634]
24847
24848     K.3.9.2 General wide string utilities
24849     K.3.9.2.1 Wide string copying functions
24850     K.3.9.2.1.1 The wcscpy_s function
24851     Synopsis
24852 1           #define __STDC_WANT_LIB_EXT1__ 1
24853             #include <wchar.h>
24854             errno_t wcscpy_s(wchar_t * restrict s1,
24855                  rsize_t s1max,
24856                  const wchar_t * restrict s2);
24857     Runtime-constraints
24858 2   Neither s1 nor s2 shall be a null pointer. s1max shall not be greater than RSIZE_MAX.
24859     s1max shall not equal zero. s1max shall be greater than wcsnlen_s(s2, s1max).
24860     Copying shall not take place between objects that overlap.
24861 3   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
24862     greater than zero and not greater than RSIZE_MAX, then wcscpy_s sets s1[0] to the
24863     null wide character.
24864     Description
24865 4   The wcscpy_s function copies the wide string pointed to by s2 (including the
24866     terminating null wide character) into the array pointed to by s1.
24867 5   All elements following the terminating null wide character (if any) written by
24868     wcscpy_s in the array of s1max wide characters pointed to by s1 take unspecified
24869     values when wcscpy_s returns.428)
24870     Returns
24871 6   The wcscpy_s function returns zero429) if there was no runtime-constraint violation.
24872     Otherwise, a nonzero value is returned.
24873
24874
24875
24876
24877     428) This allows an implementation to copy wide characters from s2 to s1 while simultaneously checking
24878          if any of those wide characters are null. Such an approach might write a wide character to every
24879          element of s1 before discovering that the first element should be set to the null wide character.
24880     429) A zero return value implies that all of the requested wide characters from the string pointed to by s2
24881          fit within the array pointed to by s1 and that the result in s1 is null terminated.
24882
24883 [page 635]
24884
24885      K.3.9.2.1.2 The wcsncpy_s function
24886      Synopsis
24887 7            #define __STDC_WANT_LIB_EXT1__ 1
24888              #include <wchar.h>
24889              errno_t wcsncpy_s(wchar_t * restrict s1,
24890                   rsize_t s1max,
24891                   const wchar_t * restrict s2,
24892                   rsize_t n);
24893      Runtime-constraints
24894 8    Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
24895      RSIZE_MAX. s1max shall not equal zero. If n is not less than s1max, then s1max
24896      shall be greater than wcsnlen_s(s2, s1max). Copying shall not take place between
24897      objects that overlap.
24898 9    If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
24899      greater than zero and not greater than RSIZE_MAX, then wcsncpy_s sets s1[0] to the
24900      null wide character.
24901      Description
24902 10   The wcsncpy_s function copies not more than n successive wide characters (wide
24903      characters that follow a null wide character are not copied) from the array pointed to by
24904      s2 to the array pointed to by s1. If no null wide character was copied from s2, then
24905      s1[n] is set to a null wide character.
24906 11   All elements following the terminating null wide character (if any) written by
24907      wcsncpy_s in the array of s1max wide characters pointed to by s1 take unspecified
24908      values when wcsncpy_s returns.430)
24909      Returns
24910 12   The wcsncpy_s function returns zero431) if there was no runtime-constraint violation.
24911      Otherwise, a nonzero value is returned.
24912 13   EXAMPLE 1 The wcsncpy_s function can be used to copy a wide string without the danger that the
24913      result will not be null terminated or that wide characters will be written past the end of the destination
24914      array.
24915
24916
24917
24918
24919      430) This allows an implementation to copy wide characters from s2 to s1 while simultaneously checking
24920           if any of those wide characters are null. Such an approach might write a wide character to every
24921           element of s1 before discovering that the first element should be set to the null wide character.
24922      431) A zero return value implies that all of the requested wide characters from the string pointed to by s2
24923           fit within the array pointed to by s1 and that the result in s1 is null terminated.
24924
24925 [page 636]
24926
24927              #define __STDC_WANT_LIB_EXT1__ 1
24928              #include <wchar.h>
24929              /* ... */
24930              wchar_t src1[100] = L"hello";
24931              wchar_t src2[7] = {L'g', L'o', L'o', L'd', L'b', L'y', L'e'};
24932              wchar_t dst1[6], dst2[5], dst3[5];
24933              int r1, r2, r3;
24934              r1 = wcsncpy_s(dst1, 6, src1, 100);
24935              r2 = wcsncpy_s(dst2, 5, src2, 7);
24936              r3 = wcsncpy_s(dst3, 5, src2, 4);
24937      The first call will assign to r1 the value zero and to dst1 the sequence of wide characters hello\0.
24938      The second call will assign to r2 a nonzero value and to dst2 the sequence of wide characters \0.
24939      The third call will assign to r3 the value zero and to dst3 the sequence of wide characters good\0.
24940
24941      K.3.9.2.1.3 The wmemcpy_s function
24942      Synopsis
24943 14           #define __STDC_WANT_LIB_EXT1__ 1
24944              #include <wchar.h>
24945              errno_t wmemcpy_s(wchar_t * restrict s1,
24946                   rsize_t s1max,
24947                   const wchar_t * restrict s2,
24948                   rsize_t n);
24949      Runtime-constraints
24950 15   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
24951      RSIZE_MAX. n shall not be greater than s1max. Copying shall not take place between
24952      objects that overlap.
24953 16   If there is a runtime-constraint violation, the wmemcpy_s function stores zeros in the
24954      first s1max wide characters of the object pointed to by s1 if s1 is not a null pointer and
24955      s1max is not greater than RSIZE_MAX.
24956      Description
24957 17   The wmemcpy_s function copies n successive wide characters from the object pointed
24958      to by s2 into the object pointed to by s1.
24959      Returns
24960 18   The wmemcpy_s function returns zero if there was no runtime-constraint violation.
24961      Otherwise, a nonzero value is returned.
24962
24963
24964
24965
24966 [page 637]
24967
24968      K.3.9.2.1.4 The wmemmove_s function
24969      Synopsis
24970 19          #define __STDC_WANT_LIB_EXT1__ 1
24971             #include <wchar.h>
24972             errno_t wmemmove_s(wchar_t *s1, rsize_t s1max,
24973                  const wchar_t *s2, rsize_t n);
24974      Runtime-constraints
24975 20   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
24976      RSIZE_MAX. n shall not be greater than s1max.
24977 21   If there is a runtime-constraint violation, the wmemmove_s function stores zeros in the
24978      first s1max wide characters of the object pointed to by s1 if s1 is not a null pointer and
24979      s1max is not greater than RSIZE_MAX.
24980      Description
24981 22   The wmemmove_s function copies n successive wide characters from the object pointed
24982      to by s2 into the object pointed to by s1. This copying takes place as if the n wide
24983      characters from the object pointed to by s2 are first copied into a temporary array of n
24984      wide characters that does not overlap the objects pointed to by s1 or s2, and then the n
24985      wide characters from the temporary array are copied into the object pointed to by s1.
24986      Returns
24987 23   The wmemmove_s function returns zero if there was no runtime-constraint violation.
24988      Otherwise, a nonzero value is returned.
24989      K.3.9.2.2 Wide string concatenation functions
24990      K.3.9.2.2.1 The wcscat_s function
24991      Synopsis
24992 1           #define __STDC_WANT_LIB_EXT1__ 1
24993             #include <wchar.h>
24994             errno_t wcscat_s(wchar_t * restrict s1,
24995                  rsize_t s1max,
24996                  const wchar_t * restrict s2);
24997      Runtime-constraints
24998 2    Let m denote the value s1max - wcsnlen_s(s1, s1max) upon entry to
24999      wcscat_s.
25000 3    Neither s1 nor s2 shall be a null pointer. s1max shall not be greater than RSIZE_MAX.
25001      s1max shall not equal zero. m shall not equal zero.432) m shall be greater than
25002      wcsnlen_s(s2, m). Copying shall not take place between objects that overlap.
25003
25004 [page 638]
25005
25006 4    If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
25007      greater than zero and not greater than RSIZE_MAX, then wcscat_s sets s1[0] to the
25008      null wide character.
25009      Description
25010 5    The wcscat_s function appends a copy of the wide string pointed to by s2 (including
25011      the terminating null wide character) to the end of the wide string pointed to by s1. The
25012      initial wide character from s2 overwrites the null wide character at the end of s1.
25013 6    All elements following the terminating null wide character (if any) written by
25014      wcscat_s in the array of s1max wide characters pointed to by s1 take unspecified
25015      values when wcscat_s returns.433)
25016      Returns
25017 7    The wcscat_s function returns zero434) if there was no runtime-constraint violation.
25018      Otherwise, a nonzero value is returned.
25019      K.3.9.2.2.2 The wcsncat_s function
25020      Synopsis
25021 8             #define __STDC_WANT_LIB_EXT1__ 1
25022               #include <wchar.h>
25023               errno_t wcsncat_s(wchar_t * restrict s1,
25024                    rsize_t s1max,
25025                    const wchar_t * restrict s2,
25026                    rsize_t n);
25027      Runtime-constraints
25028 9    Let m denote the value s1max - wcsnlen_s(s1, s1max) upon entry to
25029      wcsncat_s.
25030 10   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
25031      RSIZE_MAX. s1max shall not equal zero. m shall not equal zero.435) If n is not less
25032      than m, then m shall be greater than wcsnlen_s(s2, m). Copying shall not take
25033      place between objects that overlap.
25034
25035
25036      432) Zero means that s1 was not null terminated upon entry to wcscat_s.
25037      433) This allows an implementation to append wide characters from s2 to s1 while simultaneously
25038           checking if any of those wide characters are null. Such an approach might write a wide character to
25039           every element of s1 before discovering that the first element should be set to the null wide character.
25040      434) A zero return value implies that all of the requested wide characters from the wide string pointed to by
25041           s2 were appended to the wide string pointed to by s1 and that the result in s1 is null terminated.
25042      435) Zero means that s1 was not null terminated upon entry to wcsncat_s.
25043
25044 [page 639]
25045
25046 11   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
25047      greater than zero and not greater than RSIZE_MAX, then wcsncat_s sets s1[0] to the
25048      null wide character.
25049      Description
25050 12   The wcsncat_s function appends not more than n successive wide characters (wide
25051      characters that follow a null wide character are not copied) from the array pointed to by
25052      s2 to the end of the wide string pointed to by s1. The initial wide character from s2
25053      overwrites the null wide character at the end of s1. If no null wide character was copied
25054      from s2, then s1[s1max-m+n] is set to a null wide character.
25055 13   All elements following the terminating null wide character (if any) written by
25056      wcsncat_s in the array of s1max wide characters pointed to by s1 take unspecified
25057      values when wcsncat_s returns.436)
25058      Returns
25059 14   The wcsncat_s function returns zero437) if there was no runtime-constraint violation.
25060      Otherwise, a nonzero value is returned.
25061 15   EXAMPLE 1 The wcsncat_s function can be used to copy a wide string without the danger that the
25062      result will not be null terminated or that wide characters will be written past the end of the destination
25063      array.
25064               #define __STDC_WANT_LIB_EXT1__ 1
25065               #include <wchar.h>
25066               /* ... */
25067               wchar_t s1[100] = L"good";
25068               wchar_t s2[6] = L"hello";
25069               wchar_t s3[6] = L"hello";
25070               wchar_t s4[7] = L"abc";
25071               wchar_t s5[1000] = L"bye";
25072               int r1, r2, r3, r4;
25073               r1 = wcsncat_s(s1, 100, s5, 1000);
25074               r2 = wcsncat_s(s2, 6, L"", 1);
25075               r3 = wcsncat_s(s3, 6, L"X", 2);
25076               r4 = wcsncat_s(s4, 7, L"defghijklmn", 3);
25077      After the first call r1 will have the value zero and s1 will be the wide character sequence goodbye\0.
25078      After the second call r2 will have the value zero and s2 will be the wide character sequence hello\0.
25079      After the third call r3 will have a nonzero value and s3 will be the wide character sequence \0.
25080      After the fourth call r4 will have the value zero and s4 will be the wide character sequence abcdef\0.
25081
25082
25083
25084
25085      436) This allows an implementation to append wide characters from s2 to s1 while simultaneously
25086           checking if any of those wide characters are null. Such an approach might write a wide character to
25087           every element of s1 before discovering that the first element should be set to the null wide character.
25088      437) A zero return value implies that all of the requested wide characters from the wide string pointed to by
25089           s2 were appended to the wide string pointed to by s1 and that the result in s1 is null terminated.
25090
25091 [page 640]
25092
25093     K.3.9.2.3 Wide string search functions
25094     K.3.9.2.3.1 The wcstok_s function
25095     Synopsis
25096 1           #define __STDC_WANT_LIB_EXT1__ 1
25097             #include <wchar.h>
25098             wchar_t *wcstok_s(wchar_t * restrict s1,
25099                  rsize_t * restrict s1max,
25100                  const wchar_t * restrict s2,
25101                  wchar_t ** restrict ptr);
25102     Runtime-constraints
25103 2   None of s1max, s2, or ptr shall be a null pointer. If s1 is a null pointer, then *ptr
25104     shall not be a null pointer. The value of *s1max shall not be greater than RSIZE_MAX.
25105     The end of the token found shall occur within the first *s1max wide characters of s1 for
25106     the first call, and shall occur within the first *s1max wide characters of where searching
25107     resumes on subsequent calls.
25108 3   If there is a runtime-constraint violation, the wcstok_s function does not indirect
25109     through the s1 or s2 pointers, and does not store a value in the object pointed to by ptr.
25110     Description
25111 4   A sequence of calls to the wcstok_s function breaks the wide string pointed to by s1
25112     into a sequence of tokens, each of which is delimited by a wide character from the wide
25113     string pointed to by s2. The fourth argument points to a caller-provided wchar_t
25114     pointer into which the wcstok_s function stores information necessary for it to
25115     continue scanning the same wide string.
25116 5   The first call in a sequence has a non-null first argument and s1max points to an object
25117     whose value is the number of elements in the wide character array pointed to by the first
25118     argument. The first call stores an initial value in the object pointed to by ptr and
25119     updates the value pointed to by s1max to reflect the number of elements that remain in
25120     relation to ptr. Subsequent calls in the sequence have a null first argument and the
25121     objects pointed to by s1max and ptr are required to have the values stored by the
25122     previous call in the sequence, which are then updated. The separator wide string pointed
25123     to by s2 may be different from call to call.
25124 6   The first call in the sequence searches the wide string pointed to by s1 for the first wide
25125     character that is not contained in the current separator wide string pointed to by s2. If no
25126     such wide character is found, then there are no tokens in the wide string pointed to by s1
25127     and the wcstok_s function returns a null pointer. If such a wide character is found, it is
25128     the start of the first token.
25129
25130
25131 [page 641]
25132
25133 7    The wcstok_s function then searches from there for the first wide character in s1 that
25134      is contained in the current separator wide string. If no such wide character is found, the
25135      current token extends to the end of the wide string pointed to by s1, and subsequent
25136      searches in the same wide string for a token return a null pointer. If such a wide character
25137      is found, it is overwritten by a null wide character, which terminates the current token.
25138 8    In all cases, the wcstok_s function stores sufficient information in the pointer pointed
25139      to by ptr so that subsequent calls, with a null pointer for s1 and the unmodified pointer
25140      value for ptr, shall start searching just past the element overwritten by a null wide
25141      character (if any).
25142      Returns
25143 9    The wcstok_s function returns a pointer to the first wide character of a token, or a null
25144      pointer if there is no token or there is a runtime-constraint violation.
25145 10   EXAMPLE
25146             #define __STDC_WANT_LIB_EXT1__ 1
25147             #include <wchar.h>
25148             static wchar_t str1[] = L"?a???b,,,#c";
25149             static wchar_t str2[] = L"\t \t";
25150             wchar_t *t, *ptr1, *ptr2;
25151             rsize_t max1 = wcslen(str1)+1;
25152             rsize_t max2 = wcslen(str2)+1;
25153             t   =   wcstok_s(str1,   &max1,   "?", &ptr1);        //   t   points to the token "a"
25154             t   =   wcstok_s(NULL,   &max1,   ",", &ptr1);        //   t   points to the token "??b"
25155             t   =   wcstok_s(str2,   &max2,   " \t", &ptr2);      //   t   is a null pointer
25156             t   =   wcstok_s(NULL,   &max1,   "#,", &ptr1);       //   t   points to the token "c"
25157             t   =   wcstok_s(NULL,   &max1,   "?", &ptr1);        //   t   is a null pointer
25158
25159      K.3.9.2.4 Miscellaneous functions
25160      K.3.9.2.4.1 The wcsnlen_s function
25161      Synopsis
25162 1           #define __STDC_WANT_LIB_EXT1__ 1
25163             #include <wchar.h>
25164             size_t wcsnlen_s(const wchar_t *s, size_t maxsize);
25165      Description
25166 2    The wcsnlen_s function computes the length of the wide string pointed to by s.
25167      Returns
25168 3    If s is a null pointer,438) then the wcsnlen_s function returns zero.
25169 4    Otherwise, the wcsnlen_s function returns the number of wide characters that precede
25170      the terminating null wide character. If there is no null wide character in the first
25171      maxsize wide characters of s then wcsnlen_s returns maxsize. At most the first
25172
25173 [page 642]
25174
25175     maxsize wide characters of s shall be accessed by wcsnlen_s.
25176     K.3.9.3 Extended multibyte/wide character conversion utilities
25177     K.3.9.3.1 Restartable multibyte/wide character conversion functions
25178 1   Unlike wcrtomb, wcrtomb_s does not permit the ps parameter (the pointer to the
25179     conversion state) to be a null pointer.
25180     K.3.9.3.1.1 The wcrtomb_s function
25181     Synopsis
25182 2           #include <wchar.h>
25183             errno_t wcrtomb_s(size_t * restrict retval,
25184                  char * restrict s, rsize_t smax,
25185                  wchar_t wc, mbstate_t * restrict ps);
25186     Runtime-constraints
25187 3   Neither retval nor ps shall be a null pointer. If s is not a null pointer, then smax
25188     shall not equal zero and shall not be greater than RSIZE_MAX. If s is not a null pointer,
25189     then smax shall be not be less than the number of bytes to be stored in the array pointed
25190     to by s. If s is a null pointer, then smax shall equal zero.
25191 4   If there is a runtime-constraint violation, then wcrtomb_s does the following. If s is
25192     not a null pointer and smax is greater than zero and not greater than RSIZE_MAX, then
25193     wcrtomb_s sets s[0] to the null character. If retval is not a null pointer, then
25194     wcrtomb_s sets *retval to (size_t)(-1).
25195     Description
25196 5   If s is a null pointer, the wcrtomb_s function is equivalent to the call
25197                     wcrtomb_s(&retval, buf, sizeof buf, L'\0', ps)
25198     where retval and buf are internal variables of the appropriate types, and the size of
25199     buf is greater than MB_CUR_MAX.
25200 6   If s is not a null pointer, the wcrtomb_s function determines the number of bytes
25201     needed to represent the multibyte character that corresponds to the wide character given
25202     by wc (including any shift sequences), and stores the multibyte character representation
25203     in the array whose first element is pointed to by s. At most MB_CUR_MAX bytes are
25204     stored. If wc is a null wide character, a null byte is stored, preceded by any shift
25205     sequence needed to restore the initial shift state; the resulting state described is the initial
25206     conversion state.
25207
25208     438) Note that the wcsnlen_s function has no runtime-constraints. This lack of runtime-constraints
25209          along with the values returned for a null pointer or an unterminated wide string argument make
25210          wcsnlen_s useful in algorithms that gracefully handle such exceptional data.
25211
25212 [page 643]
25213
25214 7   If wc does not correspond to a valid multibyte character, an encoding error occurs: the
25215     wcrtomb_s function stores the value (size_t)(-1) into *retval and the
25216     conversion state is unspecified. Otherwise, the wcrtomb_s function stores into
25217     *retval the number of bytes (including any shift sequences) stored in the array pointed
25218     to by s.
25219     Returns
25220 8   The wcrtomb_s function returns zero if no runtime-constraint violation and no
25221     encoding error occurred. Otherwise, a nonzero value is returned.
25222     K.3.9.3.2 Restartable multibyte/wide string conversion functions
25223 1   Unlike mbsrtowcs and wcsrtombs, mbsrtowcs_s and wcsrtombs_s do not
25224     permit the ps parameter (the pointer to the conversion state) to be a null pointer.
25225     K.3.9.3.2.1 The mbsrtowcs_s function
25226     Synopsis
25227 2          #include <wchar.h>
25228            errno_t mbsrtowcs_s(size_t * restrict retval,
25229                 wchar_t * restrict dst, rsize_t dstmax,
25230                 const char ** restrict src, rsize_t len,
25231                 mbstate_t * restrict ps);
25232     Runtime-constraints
25233 3   None of retval, src, *src, or ps shall be null pointers. If dst is not a null pointer,
25234     then neither len nor dstmax shall be greater than RSIZE_MAX. If dst is a null
25235     pointer, then dstmax shall equal zero. If dst is not a null pointer, then dstmax shall
25236     not equal zero. If dst is not a null pointer and len is not less than dstmax, then a null
25237     character shall occur within the first dstmax multibyte characters of the array pointed to
25238     by *src.
25239 4   If there is a runtime-constraint violation, then mbsrtowcs_s does the following. If
25240     retval is not a null pointer, then mbsrtowcs_s sets *retval to (size_t)(-1).
25241     If dst is not a null pointer and dstmax is greater than zero and less than RSIZE_MAX,
25242     then mbsrtowcs_s sets dst[0] to the null wide character.
25243     Description
25244 5   The mbsrtowcs_s function converts a sequence of multibyte characters that begins in
25245     the conversion state described by the object pointed to by ps, from the array indirectly
25246     pointed to by src into a sequence of corresponding wide characters. If dst is not a null
25247     pointer, the converted characters are stored into the array pointed to by dst. Conversion
25248     continues up to and including a terminating null character, which is also stored.
25249     Conversion stops earlier in two cases: when a sequence of bytes is encountered that does
25250     not form a valid multibyte character, or (if dst is not a null pointer) when len wide
25251 [page 644]
25252
25253      characters have been stored into the array pointed to by dst.439) If dst is not a null
25254      pointer and no null wide character was stored into the array pointed to by dst, then
25255      dst[len] is set to the null wide character. Each conversion takes place as if by a call
25256      to the mbrtowc function.
25257 6    If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
25258      pointer (if conversion stopped due to reaching a terminating null character) or the address
25259      just past the last multibyte character converted (if any). If conversion stopped due to
25260      reaching a terminating null character and if dst is not a null pointer, the resulting state
25261      described is the initial conversion state.
25262 7    Regardless of whether dst is or is not a null pointer, if the input conversion encounters a
25263      sequence of bytes that do not form a valid multibyte character, an encoding error occurs:
25264      the mbsrtowcs_s function stores the value (size_t)(-1) into *retval and the
25265      conversion state is unspecified. Otherwise, the mbsrtowcs_s function stores into
25266      *retval the number of multibyte characters successfully converted, not including the
25267      terminating null character (if any).
25268 8    All elements following the terminating null wide character (if any) written by
25269      mbsrtowcs_s in the array of dstmax wide characters pointed to by dst take
25270      unspecified values when mbsrtowcs_s returns.440)
25271 9    If copying takes place between objects that overlap, the objects take on unspecified
25272      values.
25273      Returns
25274 10   The mbsrtowcs_s function returns zero if no runtime-constraint violation and no
25275      encoding error occurred. Otherwise, a nonzero value is returned.
25276      K.3.9.3.2.2 The wcsrtombs_s function
25277      Synopsis
25278 11            #include <wchar.h>
25279               errno_t wcsrtombs_s(size_t * restrict retval,
25280                    char * restrict dst, rsize_t dstmax,
25281                    const wchar_t ** restrict src, rsize_t len,
25282                    mbstate_t * restrict ps);
25283
25284
25285
25286
25287      439) Thus, the value of len is ignored if dst is a null pointer.
25288      440) This allows an implementation to attempt converting the multibyte string before discovering a
25289           terminating null character did not occur where required.
25290
25291 [page 645]
25292
25293      Runtime-constraints
25294 12   None of retval, src, *src, or ps shall be null pointers. If dst is not a null pointer,
25295      then neither len nor dstmax shall be greater than RSIZE_MAX. If dst is a null
25296      pointer, then dstmax shall equal zero. If dst is not a null pointer, then dstmax shall
25297      not equal zero. If dst is not a null pointer and len is not less than dstmax, then the
25298      conversion shall have been stopped (see below) because a terminating null wide character
25299      was reached or because an encoding error occurred.
25300 13   If there is a runtime-constraint violation, then wcsrtombs_s does the following. If
25301      retval is not a null pointer, then wcsrtombs_s sets *retval to (size_t)(-1).
25302      If dst is not a null pointer and dstmax is greater than zero and less than RSIZE_MAX,
25303      then wcsrtombs_s sets dst[0] to the null character.
25304      Description
25305 14   The wcsrtombs_s function converts a sequence of wide characters from the array
25306      indirectly pointed to by src into a sequence of corresponding multibyte characters that
25307      begins in the conversion state described by the object pointed to by ps. If dst is not a
25308      null pointer, the converted characters are then stored into the array pointed to by dst.
25309      Conversion continues up to and including a terminating null wide character, which is also
25310      stored. Conversion stops earlier in two cases:
25311      -- when a wide character is reached that does not correspond to a valid multibyte
25312        character;
25313      -- (if dst is not a null pointer) when the next multibyte character would exceed the
25314          limit of n total bytes to be stored into the array pointed to by dst. If the wide
25315          character being converted is the null wide character, then n is the lesser of len or
25316          dstmax. Otherwise, n is the lesser of len or dstmax-1.
25317      If the conversion stops without converting a null wide character and dst is not a null
25318      pointer, then a null character is stored into the array pointed to by dst immediately
25319      following any multibyte characters already stored. Each conversion takes place as if by a
25320      call to the wcrtomb function.441)
25321 15   If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
25322      pointer (if conversion stopped due to reaching a terminating null wide character) or the
25323      address just past the last wide character converted (if any). If conversion stopped due to
25324      reaching a terminating null wide character, the resulting state described is the initial
25325      conversion state.
25326
25327
25328      441) If conversion stops because a terminating null wide character has been reached, the bytes stored
25329           include those necessary to reach the initial shift state immediately before the null byte. However, if
25330           the conversion stops before a terminating null wide character has been reached, the result will be null
25331           terminated, but might not end in the initial shift state.
25332
25333 [page 646]
25334
25335 16   Regardless of whether dst is or is not a null pointer, if the input conversion encounters a
25336      wide character that does not correspond to a valid multibyte character, an encoding error
25337      occurs: the wcsrtombs_s function stores the value (size_t)(-1) into *retval
25338      and the conversion state is unspecified. Otherwise, the wcsrtombs_s function stores
25339      into *retval the number of bytes in the resulting multibyte character sequence, not
25340      including the terminating null character (if any).
25341 17   All elements following the terminating null character (if any) written by wcsrtombs_s
25342      in the array of dstmax elements pointed to by dst take unspecified values when
25343      wcsrtombs_s returns.442)
25344 18   If copying takes place between objects that overlap, the objects take on unspecified
25345      values.
25346      Returns
25347 19   The wcsrtombs_s function returns zero if no runtime-constraint violation and no
25348      encoding error occurred. Otherwise, a nonzero value is returned.
25349
25350
25351
25352
25353      442) When len is not less than dstmax, the implementation might fill the array before discovering a
25354           runtime-constraint violation.
25355
25356 [page 647]
25357
25358                                                 Annex L
25359                                                (normative)
25360                                             Analyzability
25361     L.1 Scope
25362 1   This annex specifies optional behavior that can aid in the analyzability of C programs.
25363 2   An implementation that defines __STDC_ANALYZABLE__ shall conform to the
25364     specifications in this annex.443)
25365     L.2 Definitions
25366     L.2.1
25367 1   out-of-bounds store
25368     an (attempted) access (3.1) that, at run time, for a given computational state, would
25369     modify (or, for an object declared volatile, fetch) one or more bytes that lie outside
25370     the bounds permitted by this Standard.
25371     L.2.2
25372 1   bounded undefined behavior
25373     undefined behavior (3.4.3) that does not perform an out-of-bounds store.
25374 2   NOTE 1    The behavior might perform a trap.
25375
25376 3   NOTE 2    Any values produced or stored might be indeterminate values.
25377
25378     L.2.3
25379 1   critical undefined behavior
25380     undefined behavior that is not bounded undefined behavior.
25381 2   NOTE     The behavior might perform an out-of-bounds store or perform a trap.
25382
25383
25384
25385
25386     443) Implementations that do not define __STDC_ANALYZABLE__ are not required to conform to these
25387          specifications.
25388
25389 [page 648]
25390
25391     L.3 Requirements
25392 1   If the program performs a trap (3.19.5), the implementation is permitted to invoke a
25393     runtime-constraint handler. Any such semantics are implementation-defined.
25394 2   All undefined behavior shall be limited to bounded undefined behavior, except for the
25395     following which are permitted to result in critical undefined behavior:
25396     -- An object is referred to outside of its lifetime (6.2.4).
25397     -- An lvalue does not designate an object when evaluated (6.3.2.1).
25398     -- A pointer is used to call a function whose type is not compatible with the referenced
25399       type (6.3.2.3).
25400     -- The operand of the unary * operator has an invalid value (6.5.3.2).
25401     -- Addition or subtraction of a pointer into, or just beyond, an array object and an
25402       integer type produces a result that points just beyond the array object and is used as
25403       the operand of a unary * operator that is evaluated (6.5.6).
25404     -- An argument to a library function has an invalid value or a type not expected by a
25405       function with variable number of arguments (7.1.4).
25406     -- The value of a pointer that refers to space deallocated by a call to the free or realloc
25407       function is used (7.22.3).
25408     -- A string or wide string utility function is instructed to access an array beyond the end
25409       of an object (7.23.1, 7.28.4).
25410
25411
25412
25413
25414 [page 649]
25415
25416
25417                                   Bibliography
25418   1.   ''The C Reference Manual'' by Dennis M. Ritchie, a version of which was
25419        published in The C Programming Language by Brian W. Kernighan and Dennis
25420        M. Ritchie, Prentice-Hall, Inc., (1978). Copyright owned by AT&T.
25421   2.   1984 /usr/group Standard by the /usr/group Standards Committee, Santa Clara,
25422        California, USA, November 1984.
25423   3.   ANSI X3/TR-1-82 (1982), American National Dictionary for Information
25424        Processing Systems, Information Processing Systems Technical Report.
25425   4.   ANSI/IEEE 754-1985, American National Standard for Binary Floating-Point
25426        Arithmetic.
25427   5.   ANSI/IEEE 854-1988, American National Standard for Radix-Independent
25428        Floating-Point Arithmetic.
25429   6.   IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems,
25430        second edition (previously designated IEC 559:1989).
25431   7.   ISO 31-11:1992, Quantities and units -- Part 11: Mathematical signs and
25432        symbols for use in the physical sciences and technology.
25433   8.   ISO/IEC 646:1991, Information technology -- ISO 7-bit coded character set for
25434        information interchange.
25435   9.   ISO/IEC 2382-1:1993, Information technology -- Vocabulary -- Part 1:
25436        Fundamental terms.
25437  10.   ISO 4217:1995, Codes for the representation of currencies and funds.
25438  11.   ISO 8601:1988, Data elements and interchange formats -- Information
25439        interchange -- Representation of dates and times.
25440  12.   ISO/IEC 9899:1990, Programming languages -- C.
25441  13.   ISO/IEC 9899/COR1:1994, Technical Corrigendum 1.
25442  14.   ISO/IEC 9899/COR2:1996, Technical Corrigendum 2.
25443  15.   ISO/IEC 9899/AMD1:1995, Amendment 1 to ISO/IEC 9899:1990 C Integrity.
25444  16.   ISO/IEC 9899:1999, Programming languages -- C.
25445  17.   ISO/IEC 9899:1999/Cor.1:2001, Technical Corrigendum 1.
25446  18.   ISO/IEC 9899:1999/Cor.2:2004, Technical Corrigendum 2.
25447  19.   ISO/IEC 9899:1999/Cor.3:2007, Technical Corrigendum 3.
25448
25449
25450
25451 [page 650]
25452
25453  20.    ISO/IEC 9945-2:1993, Information technology -- Portable Operating System
25454         Interface (POSIX) -- Part 2: Shell and Utilities.
25455  21.    ISO/IEC TR 10176:1998, Information technology -- Guidelines for the
25456         preparation of programming language standards.
25457  22.    ISO/IEC 10646-1:1993, Information technology -- Universal Multiple-Octet
25458         Coded Character Set (UCS) -- Part 1: Architecture and Basic Multilingual Plane.
25459  23.    ISO/IEC 10646-1/COR1:1996,         Technical       Corrigendum       1      to
25460         ISO/IEC 10646-1:1993.
25461  24.    ISO/IEC 10646-1/COR2:1998,         Technical       Corrigendum       2      to
25462         ISO/IEC 10646-1:1993.
25463  25.    ISO/IEC 10646-1/AMD1:1996, Amendment 1 to ISO/IEC 10646-1:1993
25464         Transformation Format for 16 planes of group 00 (UTF-16).
25465  26.    ISO/IEC 10646-1/AMD2:1996, Amendment 2 to ISO/IEC 10646-1:1993 UCS
25466         Transformation Format 8 (UTF-8).
25467  27.    ISO/IEC 10646-1/AMD3:1996, Amendment 3 to ISO/IEC 10646-1:1993.
25468  28.    ISO/IEC 10646-1/AMD4:1996, Amendment 4 to ISO/IEC 10646-1:1993.
25469  29.    ISO/IEC 10646-1/AMD5:1998, Amendment 5 to ISO/IEC 10646-1:1993 Hangul
25470         syllables.
25471  30.    ISO/IEC 10646-1/AMD6:1997,       Amendment     6   to   ISO/IEC 10646-1:1993
25472         Tibetan.
25473  31.    ISO/IEC 10646-1/AMD7:1997, Amendment 7 to ISO/IEC 10646-1:1993 33
25474         additional characters.
25475  32.    ISO/IEC 10646-1/AMD8:1997, Amendment 8 to ISO/IEC 10646-1:1993.
25476  33.    ISO/IEC 10646-1/AMD9:1997,       Amendment     9   to   ISO/IEC 10646-1:1993
25477         Identifiers for characters.
25478  34.    ISO/IEC 10646-1/AMD10:1998, Amendment 10 to ISO/IEC 10646-1:1993
25479         Ethiopic.
25480  35.    ISO/IEC 10646-1/AMD11:1998, Amendment 11 to ISO/IEC 10646-1:1993
25481         Unified Canadian Aboriginal Syllabics.
25482  36.    ISO/IEC 10646-1/AMD12:1998, Amendment 12 to ISO/IEC 10646-1:1993
25483         Cherokee.
25484  37.    ISO/IEC 10967-1:1994, Information technology -- Language independent
25485         arithmetic -- Part 1: Integer and floating point arithmetic.
25486
25487
25488 [page 651]
25489
25490  38.   ISO/IEC TR 19769:2004, Information technology -- Programming languages,
25491        their environments and system software interfaces -- Extensions for the
25492        programming language C to support new character data types.
25493  39.   ISO/IEC TR 24731-1:2007, Information technology -- Programming languages,
25494        their environments and system software interfaces -- Extensions to the C library
25495        -- Part 1: Bounds-checking interfaces.
25496
25497
25498
25499
25500 [page 652]
25501
25502
25503 Index
25504 [^ x ^], 3.20                                                    , (comma operator), 5.1.2.4, 6.5.17
25505                                                                , (comma punctuator), 6.5.2, 6.7, 6.7.2.1, 6.7.2.2,
25506 [_ x _], 3.21                                                         6.7.2.3, 6.7.9
25507 ! (logical negation operator), 6.5.3.3                         - (subtraction operator), 6.2.6.2, 6.5.6, F.3, G.5.2
25508 != (inequality operator), 6.5.9                                - (unary minus operator), 6.5.3.3, F.3
25509 # operator, 6.10.3.2                                           -- (postfix decrement operator), 6.3.2.1, 6.5.2.4
25510 # preprocessing directive, 6.10.7                              -- (prefix decrement operator), 6.3.2.1, 6.5.3.1
25511 # punctuator, 6.10                                             -= (subtraction assignment operator), 6.5.16.2
25512 ## operator, 6.10.3.3                                          -> (structure/union pointer operator), 6.5.2.3
25513 #define preprocessing directive, 6.10.3                        . (structure/union member operator), 6.3.2.1,
25514 #elif preprocessing directive, 6.10.1                               6.5.2.3
25515 #else preprocessing directive, 6.10.1                          . punctuator, 6.7.9
25516 #endif preprocessing directive, 6.10.1                         ... (ellipsis punctuator), 6.5.2.2, 6.7.6.3, 6.10.3
25517 #error preprocessing directive, 4, 6.10.5                      / (division operator), 6.2.6.2, 6.5.5, F.3, G.5.1
25518 #if preprocessing directive, 5.2.4.2.1, 5.2.4.2.2,             /* */ (comment delimiters), 6.4.9
25519      6.10.1, 7.1.4                                             // (comment delimiter), 6.4.9
25520 #ifdef preprocessing directive, 6.10.1                         /= (division assignment operator), 6.5.16.2
25521 #ifndef preprocessing directive, 6.10.1                        : (colon punctuator), 6.7.2.1
25522 #include preprocessing directive, 5.1.1.2,                     :> (alternative spelling of ]), 6.4.6
25523      6.10.2                                                    ; (semicolon punctuator), 6.7, 6.7.2.1, 6.8.3,
25524 #line preprocessing directive, 6.10.4                               6.8.5, 6.8.6
25525 #pragma preprocessing directive, 6.10.6                        < (less-than operator), 6.5.8
25526 #undef preprocessing directive, 6.10.3.5, 7.1.3,               <% (alternative spelling of {), 6.4.6
25527      7.1.4                                                     <: (alternative spelling of [), 6.4.6
25528 % (remainder operator), 6.2.6.2, 6.5.5                         << (left-shift operator), 6.2.6.2, 6.5.7
25529 %: (alternative spelling of #), 6.4.6                          <<= (left-shift assignment operator), 6.5.16.2
25530 %:%: (alternative spelling of ##), 6.4.6                       <= (less-than-or-equal-to operator), 6.5.8
25531 %= (remainder assignment operator), 6.5.16.2                   <assert.h> header, 7.2
25532 %> (alternative spelling of }), 6.4.6                          <complex.h> header, 5.2.4.2.2, 6.10.8.3, 7.1.2,
25533 & (address operator), 6.3.2.1, 6.5.3.2                              7.3, 7.24, 7.30.1, G.6, J.5.17
25534 & (bitwise AND operator), 6.2.6.2, 6.5.10                      <ctype.h> header, 7.4, 7.30.2
25535 && (logical AND operator), 5.1.2.4, 6.5.13                     <errno.h> header, 7.5, 7.30.3, K.3.2
25536 &= (bitwise AND assignment operator), 6.5.16.2                 <fenv.h> header, 5.1.2.3, 5.2.4.2.2, 7.6, 7.12, F,
25537 ' ' (space character), 5.1.1.2, 5.2.1, 6.4, 7.4.1.3,                H
25538      7.4.1.10, 7.29.2.1.3                                      <float.h> header, 4, 5.2.4.2.2, 7.7, 7.22.1.3,
25539 ( ) (cast operator), 6.5.4                                          7.28.4.1.1
25540 ( ) (function-call operator), 6.5.2.2                          <inttypes.h> header, 7.8, 7.30.4
25541 ( ) (parentheses punctuator), 6.7.6.3, 6.8.4, 6.8.5            <iso646.h> header, 4, 7.9
25542 ( ){ } (compound-literal operator), 6.5.2.5                    <limits.h> header, 4, 5.2.4.2.1, 6.2.5, 7.10
25543 * (asterisk punctuator), 6.7.6.1, 6.7.6.2                      <locale.h> header, 7.11, 7.30.5
25544 * (indirection operator), 6.5.2.1, 6.5.3.2                     <math.h> header, 5.2.4.2.2, 6.5, 7.12, 7.24, F,
25545 * (multiplication operator), 6.2.6.2, 6.5.5, F.3,                   F.10, J.5.17
25546      G.5.1                                                     <setjmp.h> header, 7.13
25547 *= (multiplication assignment operator), 6.5.16.2              <signal.h> header, 7.14, 7.30.6
25548 + (addition operator), 6.2.6.2, 6.5.2.1, 6.5.3.2,              <stdalign.h> header, 4, 7.15
25549      6.5.6, F.3, G.5.2                                         <stdarg.h> header, 4, 6.7.6.3, 7.16
25550 + (unary plus operator), 6.5.3.3                               <stdatomic.h> header, 6.10.8.3, 7.1.2, 7.17
25551 ++ (postfix increment operator), 6.3.2.1, 6.5.2.4               <stdbool.h> header, 4, 7.18, 7.30.7, H
25552 ++ (prefix increment operator), 6.3.2.1, 6.5.3.1                <stddef.h> header, 4, 6.3.2.1, 6.3.2.3, 6.4.4.4,
25553 += (addition assignment operator), 6.5.16.2
25554 [page 653]
25555
25556      6.4.5, 6.5.3.4, 6.5.6, 7.19, K.3.3                      \x hexadecimal digits (hexadecimal-character
25557 <stdint.h> header, 4, 5.2.4.2, 6.10.1, 7.8,                       escape sequence), 6.4.4.4
25558      7.20, 7.30.8, K.3.3, K.3.4                              ^ (bitwise exclusive OR operator), 6.2.6.2, 6.5.11
25559 <stdio.h> header, 5.2.4.2.2, 7.21, 7.30.9, F,                ^= (bitwise exclusive OR assignment operator),
25560      K.3.5                                                        6.5.16.2
25561 <stdlib.h> header, 5.2.4.2.2, 7.22, 7.30.10, F,              __alignas_is_defined macro, 7.15
25562      K.3.1.4, K.3.6                                          __bool_true_false_are_defined
25563 <string.h> header, 7.23, 7.30.11, K.3.7                           macro, 7.18
25564 <tgmath.h> header, 7.24, G.7                                 __cplusplus macro, 6.10.8
25565 <threads.h> header, 6.10.8.3, 7.1.2, 7.25                    __DATE__ macro, 6.10.8.1
25566 <time.h> header, 7.26, K.3.8                                 __FILE__ macro, 6.10.8.1, 7.2.1.1
25567 <uchar.h> header, 6.4.4.4, 6.4.5, 7.27                       __func__ identifier, 6.4.2.2, 7.2.1.1
25568 <wchar.h> header, 5.2.4.2.2, 7.21.1, 7.28,                   __LINE__ macro, 6.10.8.1, 7.2.1.1
25569      7.30.12, F, K.3.9                                       __STDC_, 6.11.9
25570 <wctype.h> header, 7.29, 7.30.13                             __STDC__ macro, 6.10.8.1
25571 = (equal-sign punctuator), 6.7, 6.7.2.2, 6.7.9               __STDC_ANALYZABLE__ macro, 6.10.8.3, L.1
25572 = (simple assignment operator), 6.5.16.1                     __STDC_HOSTED__ macro, 6.10.8.1
25573 == (equality operator), 6.5.9                                __STDC_IEC_559__ macro, 6.10.8.3, F.1
25574 > (greater-than operator), 6.5.8                             __STDC_IEC_559_COMPLEX__ macro,
25575 >= (greater-than-or-equal-to operator), 6.5.8                     6.10.8.3, G.1
25576 >> (right-shift operator), 6.2.6.2, 6.5.7                    __STDC_ISO_10646__ macro, 6.10.8.2
25577 >>= (right-shift assignment operator), 6.5.16.2              __STDC_LIB_EXT1__ macro, 6.10.8.3, K.2
25578 ? : (conditional operator), 5.1.2.4, 6.5.15                  __STDC_MB_MIGHT_NEQ_WC__ macro,
25579 ?? (trigraph sequences), 5.2.1.1                                  6.10.8.2, 7.19
25580 [ ] (array subscript operator), 6.5.2.1, 6.5.3.2             __STDC_NO_COMPLEX__ macro, 6.10.8.3,
25581 [ ] (brackets punctuator), 6.7.6.2, 6.7.9                         7.3.1
25582 \ (backslash character), 5.1.1.2, 5.2.1, 6.4.4.4             __STDC_NO_THREADS__ macro, 6.10.8.3,
25583 \ (escape character), 6.4.4.4                                     7.17.1, 7.25.1
25584 \" (double-quote escape sequence), 6.4.4.4,                  __STDC_NO_VLA__ macro, 6.10.8.3
25585      6.4.5, 6.10.9                                           __STDC_UTF_16__ macro, 6.10.8.2
25586 \\ (backslash escape sequence), 6.4.4.4, 6.10.9              __STDC_UTF_32__ macro, 6.10.8.2
25587 \' (single-quote escape sequence), 6.4.4.4, 6.4.5            __STDC_VERSION__ macro, 6.10.8.1
25588 \0 (null character), 5.2.1, 6.4.4.4, 6.4.5                   __STDC_WANT_LIB_EXT1__ macro, K.3.1.1
25589   padding of binary stream, 7.21.2                           __TIME__ macro, 6.10.8.1
25590 \? (question-mark escape sequence), 6.4.4.4                  __VA_ARGS__ identifier, 6.10.3, 6.10.3.1
25591 \a (alert escape sequence), 5.2.2, 6.4.4.4                   _Alignas, 6.7.5
25592 \b (backspace escape sequence), 5.2.2, 6.4.4.4               _Atomic type qualifier, 6.7.3
25593 \f (form-feed escape sequence), 5.2.2, 6.4.4.4,              _Bool type, 6.2.5, 6.3.1.1, 6.3.1.2, 6.7.2, 7.17.1,
25594      7.4.1.10                                                     F.4
25595 \n (new-line escape sequence), 5.2.2, 6.4.4.4,               _Bool type conversions, 6.3.1.2
25596      7.4.1.10                                                _Complex types, 6.2.5, 6.7.2, 7.3.1, G
25597 \octal digits (octal-character escape sequence),             _Complex_I macro, 7.3.1
25598      6.4.4.4                                                 _Exit function, 7.22.4.5, 7.22.4.7
25599 \r (carriage-return escape sequence), 5.2.2,                 _Imaginary keyword, G.2
25600      6.4.4.4, 7.4.1.10                                       _Imaginary types, 7.3.1, G
25601 \t (horizontal-tab escape sequence), 5.2.2,                  _Imaginary_I macro, 7.3.1, G.6
25602      6.4.4.4, 7.4.1.3, 7.4.1.10, 7.29.2.1.3                  _IOFBF macro, 7.21.1, 7.21.5.5, 7.21.5.6
25603 \U (universal character names), 6.4.3                        _IOLBF macro, 7.21.1, 7.21.5.6
25604 \u (universal character names), 6.4.3                        _IONBF macro, 7.21.1, 7.21.5.5, 7.21.5.6
25605 \v (vertical-tab escape sequence), 5.2.2, 6.4.4.4,           _Noreturn, 6.7.4
25606      7.4.1.10                                                _Pragma operator, 5.1.1.2, 6.10.9
25607
25608 [page 654]
25609
25610 _Static_assert, 6.7.10, 7.2                                  allocated storage, order and contiguity, 7.22.3
25611 _Thread_local storage-class specifier, 6.2.4,                 and macro, 7.9
25612      6.7.1                                                   AND operators
25613 { } (braces punctuator), 6.7.2.2, 6.7.2.3, 6.7.9,               bitwise (&), 6.2.6.2, 6.5.10
25614      6.8.2                                                      bitwise assignment (&=), 6.5.16.2
25615 { } (compound-literal operator), 6.5.2.5                        logical (&&), 5.1.2.4, 6.5.13
25616 | (bitwise inclusive OR operator), 6.2.6.2, 6.5.12           and_eq macro, 7.9
25617 |= (bitwise inclusive OR assignment operator),               anonymous structure, 6.7.2.1
25618      6.5.16.2                                                anonymous union, 6.7.2.1
25619 || (logical OR operator), 5.1.2.4, 6.5.14                    ANSI/IEEE 754, F.1
25620 ~ (bitwise complement operator), 6.2.6.2, 6.5.3.3            ANSI/IEEE 854, F.1
25621                                                              argc (main function parameter), 5.1.2.2.1
25622 abort function, 7.2.1.1, 7.14.1.1, 7.21.3,                   argument, 3.3
25623       7.22.4.1, 7.25.3.6, K.3.6.1.2                             array, 6.9.1
25624 abort_handler_s function, K.3.6.1.2                             default promotions, 6.5.2.2
25625 abs function, 7.22.6.1                                          function, 6.5.2.2, 6.9.1
25626 absolute-value functions                                        macro, substitution, 6.10.3.1
25627    complex, 7.3.8, G.6.4                                     argument, complex, 7.3.9.1
25628    integer, 7.8.2.1, 7.22.6.1                                argv (main function parameter), 5.1.2.2.1
25629    real, 7.12.7, F.10.4                                      arithmetic constant expression, 6.6
25630 abstract declarator, 6.7.7                                   arithmetic conversions, usual, see usual arithmetic
25631 abstract machine, 5.1.2.3                                          conversions
25632 access, 3.1, 6.7.3, L.2.1                                    arithmetic operators
25633 accuracy, see floating-point accuracy                            additive, 6.2.6.2, 6.5.6, G.5.2
25634 acos functions, 7.12.4.1, F.10.1.1                              bitwise, 6.2.6.2, 6.5.3.3, 6.5.10, 6.5.11, 6.5.12
25635 acos type-generic macro, 7.24                                   increment and decrement, 6.5.2.4, 6.5.3.1
25636 acosh functions, 7.12.5.1, F.10.2.1                             multiplicative, 6.2.6.2, 6.5.5, G.5.1
25637 acosh type-generic macro, 7.24                                  shift, 6.2.6.2, 6.5.7
25638 acquire fence, 7.17.4                                           unary, 6.5.3.3
25639 acquire operation, 5.1.2.4                                   arithmetic types, 6.2.5
25640 active position, 5.2.2                                       arithmetic, pointer, 6.5.6
25641 actual argument, 3.3                                         array
25642 actual parameter (deprecated), 3.3                              argument, 6.9.1
25643 addition assignment operator (+=), 6.5.16.2                     declarator, 6.7.6.2
25644 addition operator (+), 6.2.6.2, 6.5.2.1, 6.5.3.2,               initialization, 6.7.9
25645       6.5.6, F.3, G.5.2                                         multidimensional, 6.5.2.1
25646 additive expressions, 6.5.6, G.5.2                              parameter, 6.9.1
25647 address constant, 6.6                                           storage order, 6.5.2.1
25648 address operator (&), 6.3.2.1, 6.5.3.2                          subscript operator ([ ]), 6.5.2.1, 6.5.3.2
25649 address-free, 7.17.5                                            subscripting, 6.5.2.1
25650 aggregate initialization, 6.7.9                                 type, 6.2.5
25651 aggregate types, 6.2.5                                          type conversion, 6.3.2.1
25652 alert escape sequence (\a), 5.2.2, 6.4.4.4                      variable length, 6.7.6, 6.7.6.2, 6.10.8.3
25653 aliasing, 6.5                                                arrow operator (->), 6.5.2.3
25654 alignas macro, 7.15                                          as-if rule, 5.1.2.3
25655 aligned_alloc function, 7.22.3, 7.22.3.1                     ASCII code set, 5.2.1.1
25656 alignment, 3.2, 6.2.8, 7.22.3.1                              asctime function, 7.26.3.1
25657    pointer, 6.2.5, 6.3.2.3                                   asctime_s function, K.3.8.2, K.3.8.2.1
25658    structure/union member, 6.7.2.1                           asin functions, 7.12.4.2, F.10.1.2
25659 alignment specifier, 6.7.5                                    asin type-generic macro, 7.24, G.7
25660 alignof operator, 6.5.3, 6.5.3.4                             asinh functions, 7.12.5.2, F.10.2.2
25661
25662 [page 655]
25663
25664 asinh type-generic macro, 7.24, G.7                           atomic_is_lock_free generic function,
25665 asm keyword, J.5.10                                               7.17.5.1
25666 assert macro, 7.2.1.1                                         ATOMIC_LLONG_LOCK_FREE macro, 7.17.1
25667 assert.h header, 7.2                                          atomic_load generic functions, 7.17.7.2
25668 assignment                                                    ATOMIC_LONG_LOCK_FREE macro, 7.17.1
25669    compound, 6.5.16.2                                         ATOMIC_SHORT_LOCK_FREE macro, 7.17.1
25670    conversion, 6.5.16.1                                       atomic_signal_fence function, 7.17.4.2
25671    expression, 6.5.16                                         atomic_store generic functions, 7.17.7.1
25672    operators, 6.3.2.1, 6.5.16                                 atomic_thread_fence function, 7.17.4.1
25673    simple, 6.5.16.1                                           ATOMIC_VAR_INIT macro, 7.17.2.1
25674 associativity of operators, 6.5                               ATOMIC_WCHAR_T_LOCK_FREE macro, 7.17.1
25675 asterisk punctuator (*), 6.7.6.1, 6.7.6.2                     atomics header, 7.17
25676 at_quick_exit function, 7.22.4.2, 7.22.4.3,                   auto storage-class specifier, 6.7.1, 6.9
25677      7.22.4.4, 7.22.4.5, 7.22.4.7                             automatic storage duration, 5.2.3, 6.2.4
25678 atan functions, 7.12.4.3, F.10.1.3
25679 atan type-generic macro, 7.24, G.7                            backslash character (\), 5.1.1.2, 5.2.1, 6.4.4.4
25680 atan2 functions, 7.12.4.4, F.10.1.4                           backslash escape sequence (\\), 6.4.4.4, 6.10.9
25681 atan2 type-generic macro, 7.24                                backspace escape sequence (\b), 5.2.2, 6.4.4.4
25682 atanh functions, 7.12.5.3, F.10.2.3                           basic character set, 3.6, 3.7.2, 5.2.1
25683 atanh type-generic macro, 7.24, G.7                           basic types, 6.2.5
25684 atexit function, 7.22.4.2, 7.22.4.3, 7.22.4.4,                behavior, 3.4
25685      7.22.4.5, 7.22.4.7, J.5.13                               binary streams, 7.21.2, 7.21.7.10, 7.21.9.2,
25686 atof function, 7.22.1, 7.22.1.1                                     7.21.9.4
25687 atoi function, 7.22.1, 7.22.1.2                               bit, 3.5
25688 atol function, 7.22.1, 7.22.1.2                                  high order, 3.6
25689 atoll function, 7.22.1, 7.22.1.2                                 low order, 3.6
25690 atomic lock-free macros, 7.17.1, 7.17.5                       bit-field, 6.7.2.1
25691 atomic operations, 5.1.2.4                                    bitand macro, 7.9
25692 atomic types, 5.1.2.3, 6.2.5, 6.2.6.1, 6.3.2.1,               bitor macro, 7.9
25693      6.5.2.3, 6.5.2.4, 6.5.16.2, 6.7.2.4, 6.10.8.3,           bitwise operators, 6.5
25694      7.17.6                                                      AND, 6.2.6.2, 6.5.10
25695 atomic_address type, 7.17.1, 7.17.6                              AND assignment (&=), 6.5.16.2
25696 ATOMIC_ADDRESS_LOCK_FREE macro, 7.17.1                           complement (~), 6.2.6.2, 6.5.3.3
25697 atomic_bool type, 7.17.1, 7.17.6                                 exclusive OR, 6.2.6.2, 6.5.11
25698 ATOMIC_CHAR16_T_LOCK_FREE macro,                                 exclusive OR assignment (^=), 6.5.16.2
25699      7.17.1                                                      inclusive OR, 6.2.6.2, 6.5.12
25700 ATOMIC_CHAR32_T_LOCK_FREE macro,                                 inclusive OR assignment (|=), 6.5.16.2
25701      7.17.1                                                      shift, 6.2.6.2, 6.5.7
25702 ATOMIC_CHAR_LOCK_FREE macro, 7.17.1                           blank character, 7.4.1.3
25703 atomic_compare_exchange generic                               block, 6.8, 6.8.2, 6.8.4, 6.8.5
25704      functions, 7.17.7.4                                      block scope, 6.2.1
25705 atomic_exchange generic functions, 7.17.7.3                   block structure, 6.2.1
25706 atomic_fetch and modify generic functions,                    bold type convention, 6.1
25707      7.17.7.5                                                 bool macro, 7.18
25708 atomic_flag type, 7.17.1, 7.17.8                              boolean type, 6.3.1.2
25709 atomic_flag_clear functions, 7.17.8.2                         boolean type conversion, 6.3.1.1, 6.3.1.2
25710 ATOMIC_FLAG_INIT macro, 7.17.1, 7.17.8                        bounded undefined behavior, L.2.2
25711 atomic_flag_test_and_set functions,                           braces punctuator ({ }), 6.7.2.2, 6.7.2.3, 6.7.9,
25712      7.17.8.1                                                       6.8.2
25713 atomic_init generic function, 7.17.2.2                        brackets operator ([ ]), 6.5.2.1, 6.5.3.2
25714 ATOMIC_INT_LOCK_FREE macro, 7.17.1                            brackets punctuator ([ ]), 6.7.6.2, 6.7.9
25715
25716 [page 656]
25717
25718 branch cuts, 7.3.3                                                type-generic macro for, 7.24
25719 break statement, 6.8.6.3                                       ccosh functions, 7.3.6.4, G.6.2.4
25720 broken-down time, 7.26.1, 7.26.2.3, 7.26.3,                       type-generic macro for, 7.24
25721      7.26.3.1, 7.26.3.3, 7.26.3.4, 7.26.3.5,                   ceil functions, 7.12.9.1, F.10.6.1
25722      K.3.8.2.1, K.3.8.2.3, K.3.8.2.4                           ceil type-generic macro, 7.24
25723 bsearch function, 7.22.5, 7.22.5.1                             cerf function, 7.30.1
25724 bsearch_s function, K.3.6.3, K.3.6.3.1                         cerfc function, 7.30.1
25725 btowc function, 7.28.6.1.1                                     cexp functions, 7.3.7.1, G.6.3.1
25726 BUFSIZ macro, 7.21.1, 7.21.2, 7.21.5.5                            type-generic macro for, 7.24
25727 byte, 3.6, 6.5.3.4                                             cexp2 function, 7.30.1
25728 byte input/output functions, 7.21.1                            cexpm1 function, 7.30.1
25729 byte-oriented stream, 7.21.2                                   char type, 6.2.5, 6.3.1.1, 6.7.2, K.3.5.3.2,
25730                                                                      K.3.9.1.2
25731 C program, 5.1.1.1                                             char type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,
25732 c16rtomb function, 7.27.1.2                                          6.3.1.8
25733 c32rtomb function, 7.27.1.4                                    char16_t type, 6.4.4.4, 6.4.5, 6.10.8.2, 7.27
25734 cabs functions, 7.3.8.1, G.6                                   char32_t type, 6.4.4.4, 6.4.5, 6.10.8.2, 7.27
25735   type-generic macro for, 7.24                                 CHAR_BIT macro, 5.2.4.2.1, 6.7.2.1
25736 cacos functions, 7.3.5.1, G.6.1.1                              CHAR_MAX macro, 5.2.4.2.1, 7.11.2.1
25737   type-generic macro for, 7.24                                 CHAR_MIN macro, 5.2.4.2.1
25738 cacosh functions, 7.3.6.1, G.6.2.1                             character, 3.7, 3.7.1
25739   type-generic macro for, 7.24                                 character array initialization, 6.7.9
25740 calendar time, 7.26.1, 7.26.2.2, 7.26.2.3, 7.26.2.4,           character case mapping functions, 7.4.2
25741       7.26.3.2, 7.26.3.3, 7.26.3.4, K.3.8.2.2,                    wide character, 7.29.3.1
25742       K.3.8.2.3, K.3.8.2.4                                           extensible, 7.29.3.2
25743 call by value, 6.5.2.2                                         character classification functions, 7.4.1
25744 call_once function, 7.25.1, 7.25.2.1                              wide character, 7.29.2.1
25745 calloc function, 7.22.3, 7.22.3.2                                    extensible, 7.29.2.2
25746 carg functions, 7.3.9.1, G.6                                   character constant, 5.1.1.2, 5.2.1, 6.4.4.4
25747 carg type-generic macro, 7.24, G.7                             character display semantics, 5.2.2
25748 carriage-return escape sequence (\r), 5.2.2,                   character handling header, 7.4, 7.11.1.1
25749       6.4.4.4, 7.4.1.10                                        character input/output functions, 7.21.7, K.3.5.4
25750 carries a dependency, 5.1.2.4                                     wide character, 7.28.3
25751 case label, 6.8.1, 6.8.4.2                                     character sets, 5.2.1
25752 case mapping functions                                         character string literal, see string literal
25753   character, 7.4.2                                             character type conversion, 6.3.1.1
25754   wide character, 7.29.3.1                                     character types, 6.2.5, 6.7.9
25755       extensible, 7.29.3.2                                     cimag functions, 7.3.9.2, 7.3.9.5, G.6
25756 casin functions, 7.3.5.2, G.6                                  cimag type-generic macro, 7.24, G.7
25757   type-generic macro for, 7.24                                 cis function, G.6
25758 casinh functions, 7.3.6.2, G.6.2.2                             classification functions
25759   type-generic macro for, 7.24                                    character, 7.4.1
25760 cast expression, 6.5.4                                            floating-point, 7.12.3
25761 cast operator (( )), 6.5.4                                        wide character, 7.29.2.1
25762 catan functions, 7.3.5.3, G.6                                        extensible, 7.29.2.2
25763   type-generic macro for, 7.24                                 clearerr function, 7.21.10.1
25764 catanh functions, 7.3.6.3, G.6.2.3                             clgamma function, 7.30.1
25765   type-generic macro for, 7.24                                 clock function, 7.26.2.1
25766 cbrt functions, 7.12.7.1, F.10.4.1                             clock_t type, 7.26.1, 7.26.2.1
25767 cbrt type-generic macro, 7.24                                  CLOCKS_PER_SEC macro, 7.26.1, 7.26.2.1
25768 ccos functions, 7.3.5.4, G.6                                   clog functions, 7.3.7.2, G.6.3.2
25769
25770 [page 657]
25771
25772   type-generic macro for, 7.24                                  string, 7.23.3, K.3.7.2
25773 clog10 function, 7.30.1                                         wide string, 7.28.4.3, K.3.9.2.2
25774 clog1p function, 7.30.1                                       concatenation, preprocessing, see preprocessing
25775 clog2 function, 7.30.1                                             concatenation
25776 CMPLX macros, 7.3.9.3                                         conceptual models, 5.1
25777 cnd_broadcast function, 7.25.3.1, 7.25.3.5,                   conditional features, 4, 6.2.5, 6.7.6.2, 6.10.8.3,
25778      7.25.3.6                                                      7.1.2, F.1, G.1, K.2, L.1
25779 cnd_destroy function, 7.25.3.2                                conditional inclusion, 6.10.1
25780 cnd_init function, 7.25.3.3                                   conditional operator (? :), 5.1.2.4, 6.5.15
25781 cnd_signal function, 7.25.3.4, 7.25.3.5,                      conflict, 5.1.2.4
25782      7.25.3.6                                                 conformance, 4
25783 cnd_t type, 7.25.1                                            conj functions, 7.3.9.4, G.6
25784 cnd_timedwait function, 7.25.3.5                              conj type-generic macro, 7.24
25785 cnd_wait function, 7.25.3.3, 7.25.3.6                         const type qualifier, 6.7.3
25786 collating sequences, 5.2.1                                    const-qualified type, 6.2.5, 6.3.2.1, 6.7.3
25787 colon punctuator (:), 6.7.2.1                                 constant expression, 6.6, F.8.4
25788 comma operator (,), 5.1.2.4, 6.5.17                           constants, 6.4.4
25789 comma punctuator (,), 6.5.2, 6.7, 6.7.2.1, 6.7.2.2,             as primary expression, 6.5.1
25790      6.7.2.3, 6.7.9                                             character, 6.4.4.4
25791 command processor, 7.22.4.8                                     enumeration, 6.2.1, 6.4.4.3
25792 comment delimiters (/* */ and //), 6.4.9                        floating, 6.4.4.2
25793 comments, 5.1.1.2, 6.4, 6.4.9                                   hexadecimal, 6.4.4.1
25794 common extensions, J.5                                          integer, 6.4.4.1
25795 common initial sequence, 6.5.2.3                                octal, 6.4.4.1
25796 common real type, 6.3.1.8                                     constraint, 3.8, 4
25797 common warnings, I                                            constraint_handler_t type, K.3.6
25798 comparison functions, 7.22.5, 7.22.5.1, 7.22.5.2,             consume operation, 5.1.2.4
25799      K.3.6.3, K.3.6.3.1, K.3.6.3.2                            content of structure/union/enumeration, 6.7.2.3
25800   string, 7.23.4                                              contiguity of allocated storage, 7.22.3
25801   wide string, 7.28.4.4                                       continue statement, 6.8.6.2
25802 comparison macros, 7.12.14                                    contracted expression, 6.5, 7.12.2, F.7
25803 comparison, pointer, 6.5.8                                    control character, 5.2.1, 7.4
25804 compatible type, 6.2.7, 6.7.2, 6.7.3, 6.7.6                   control wide character, 7.29.2
25805 compl macro, 7.9                                              conversion, 6.3
25806 complement operator (~), 6.2.6.2, 6.5.3.3                       arithmetic operands, 6.3.1
25807 complete type, 6.2.5                                            array argument, 6.9.1
25808 complex macro, 7.3.1                                            array parameter, 6.9.1
25809 complex numbers, 6.2.5, G                                       arrays, 6.3.2.1
25810 complex type conversion, 6.3.1.6, 6.3.1.7                       boolean, 6.3.1.2
25811 complex type domain, 6.2.5                                      boolean, characters, and integers, 6.3.1.1
25812 complex types, 6.2.5, 6.7.2, 6.10.8.3, G                        by assignment, 6.5.16.1
25813 complex.h header, 5.2.4.2.2, 6.10.8.3, 7.1.2,                   by return statement, 6.8.6.4
25814      7.3, 7.24, 7.30.1, G.6, J.5.17                             complex types, 6.3.1.6
25815 compliance, see conformance                                     explicit, 6.3
25816 components of time, 7.26.1, K.3.8.1                             function, 6.3.2.1
25817 composite type, 6.2.7                                           function argument, 6.5.2.2, 6.9.1
25818 compound assignment, 6.5.16.2                                   function designators, 6.3.2.1
25819 compound literals, 6.5.2.5                                      function parameter, 6.9.1
25820 compound statement, 6.8.2                                       imaginary, G.4.1
25821 compound-literal operator (( ){ }), 6.5.2.5                     imaginary and complex, G.4.3
25822 concatenation functions                                         implicit, 6.3
25823
25824 [page 658]
25825
25826    lvalues, 6.3.2.1                                             csinh functions, 7.3.6.5, G.6.2.5
25827    pointer, 6.3.2.1, 6.3.2.3                                      type-generic macro for, 7.24
25828    real and complex, 6.3.1.7                                    csqrt functions, 7.3.8.3, G.6.4.2
25829    real and imaginary, G.4.2                                      type-generic macro for, 7.24
25830    real floating and integer, 6.3.1.4, F.3, F.4                  ctan functions, 7.3.5.6, G.6
25831    real floating types, 6.3.1.5, F.3                               type-generic macro for, 7.24
25832    signed and unsigned integers, 6.3.1.3                        ctanh functions, 7.3.6.6, G.6.2.6
25833    usual arithmetic, see usual arithmetic                         type-generic macro for, 7.24
25834          conversions                                            ctgamma function, 7.30.1
25835    void type, 6.3.2.2                                           ctime function, 7.26.3.2
25836 conversion functions                                            ctime_s function, K.3.8.2, K.3.8.2.2
25837    multibyte/wide character, 7.22.7, K.3.6.4                    ctype.h header, 7.4, 7.30.2
25838       extended, 7.28.6, K.3.9.3                                 current object, 6.7.9
25839       restartable, 7.27.1, 7.28.6.3, K.3.9.3.1                  CX_LIMITED_RANGE pragma, 6.10.6, 7.3.4
25840    multibyte/wide string, 7.22.8, K.3.6.5
25841       restartable, 7.28.6.4, K.3.9.3.2                          data race, 5.1.2.4, 7.1.4, 7.22.2.1, 7.22.4.6,
25842    numeric, 7.8.2.3, 7.22.1                                          7.23.5.8, 7.23.6.2, 7.26.3, 7.27.1, 7.28.6.3,
25843       wide string, 7.8.2.4, 7.28.4.1                                 7.28.6.4
25844    single byte/wide character, 7.28.6.1                         data stream, see streams
25845    time, 7.26.3, K.3.8.2                                        date and time header, 7.26, K.3.8
25846       wide character, 7.28.5                                    Daylight Saving Time, 7.26.1
25847 conversion specifier, 7.21.6.1, 7.21.6.2, 7.28.2.1,              DBL_DECIMAL_DIG macro, 5.2.4.2.2
25848       7.28.2.2                                                  DBL_DIG macro, 5.2.4.2.2
25849 conversion state, 7.22.7, 7.27.1, 7.27.1.1,                     DBL_EPSILON macro, 5.2.4.2.2
25850       7.27.1.2, 7.27.1.3, 7.27.1.4, 7.28.6,                     DBL_HAS_SUBNORM macro, 5.2.4.2.2
25851       7.28.6.2.1, 7.28.6.3, 7.28.6.3.2, 7.28.6.3.3,             DBL_MANT_DIG macro, 5.2.4.2.2
25852       7.28.6.4, 7.28.6.4.1, 7.28.6.4.2, K.3.6.4,                DBL_MAX macro, 5.2.4.2.2
25853       K.3.9.3.1, K.3.9.3.1.1, K.3.9.3.2, K.3.9.3.2.1,           DBL_MAX_10_EXP macro, 5.2.4.2.2
25854       K.3.9.3.2.2                                               DBL_MAX_EXP macro, 5.2.4.2.2
25855 conversion state functions, 7.28.6.2                            DBL_MIN macro, 5.2.4.2.2
25856 copying functions                                               DBL_MIN_10_EXP macro, 5.2.4.2.2
25857    string, 7.23.2, K.3.7.1                                      DBL_MIN_EXP macro, 5.2.4.2.2
25858    wide string, 7.28.4.2, K.3.9.2.1                             DBL_TRUE_MIN macro, 5.2.4.2.2
25859 copysign functions, 7.3.9.5, 7.12.11.1, F.3,                    decimal constant, 6.4.4.1
25860       F.10.8.1                                                  decimal digit, 5.2.1
25861 copysign type-generic macro, 7.24                               decimal-point character, 7.1.1, 7.11.2.1
25862 correctly rounded result, 3.9                                   DECIMAL_DIG macro, 5.2.4.2.2, 7.21.6.1,
25863 corresponding real type, 6.2.5                                       7.22.1.3, 7.28.2.1, 7.28.4.1.1, F.5
25864 cos functions, 7.12.4.5, F.10.1.5                               declaration specifiers, 6.7
25865 cos type-generic macro, 7.24, G.7                               declarations, 6.7
25866 cosh functions, 7.12.5.4, F.10.2.4                                function, 6.7.6.3
25867 cosh type-generic macro, 7.24, G.7                                pointer, 6.7.6.1
25868 cpow functions, 7.3.8.2, G.6.4.1                                  structure/union, 6.7.2.1
25869    type-generic macro for, 7.24                                   typedef, 6.7.8
25870 cproj functions, 7.3.9.5, G.6                                   declarator, 6.7.6
25871 cproj type-generic macro, 7.24                                    abstract, 6.7.7
25872 creal functions, 7.3.9.6, G.6                                   declarator type derivation, 6.2.5, 6.7.6
25873 creal type-generic macro, 7.24, G.7                             decrement operators, see arithmetic operators,
25874 critical undefined behavior, L.2.3                                    increment and decrement
25875 csin functions, 7.3.5.5, G.6                                    default argument promotions, 6.5.2.2
25876    type-generic macro for, 7.24                                 default initialization, 6.7.9
25877
25878 [page 659]
25879
25880 default label, 6.8.1, 6.8.4.2                                  elif preprocessing directive, 6.10.1
25881 define preprocessing directive, 6.10.3                         ellipsis punctuator (...), 6.5.2.2, 6.7.6.3, 6.10.3
25882 defined operator, 6.10.1, 6.10.8                               else preprocessing directive, 6.10.1
25883 definition, 6.7                                                 else statement, 6.8.4.1
25884    function, 6.9.1                                             empty statement, 6.8.3
25885 dependency-ordered before, 5.1.2.4                             encoding error, 7.21.3, 7.27.1.1, 7.27.1.2,
25886 derived declarator types, 6.2.5                                      7.27.1.3, 7.27.1.4, 7.28.3.1, 7.28.3.3,
25887 derived types, 6.2.5                                                 7.28.6.3.2, 7.28.6.3.3, 7.28.6.4.1, 7.28.6.4.2,
25888 designated initializer, 6.7.9                                        K.3.6.5.1, K.3.6.5.2, K.3.9.3.1.1, K.3.9.3.2.1,
25889 destringizing, 6.10.9                                                K.3.9.3.2.2
25890 device input/output, 5.1.2.3                                   end-of-file, 7.28.1
25891 diagnostic message, 3.10, 5.1.1.3                              end-of-file indicator, 7.21.1, 7.21.5.3, 7.21.7.1,
25892 diagnostics, 5.1.1.3                                                 7.21.7.5, 7.21.7.6, 7.21.7.10, 7.21.9.2,
25893 diagnostics header, 7.2                                              7.21.9.3, 7.21.10.1, 7.21.10.2, 7.28.3.1,
25894 difftime function, 7.26.2.2                                          7.28.3.10
25895 digit, 5.2.1, 7.4                                              end-of-file macro, see EOF macro
25896 digraphs, 6.4.6                                                end-of-line indicator, 5.2.1
25897 direct input/output functions, 7.21.8                          endif preprocessing directive, 6.10.1
25898 display device, 5.2.2                                          enum type, 6.2.5, 6.7.2, 6.7.2.2
25899 div function, 7.22.6.2                                         enumerated type, 6.2.5
25900 div_t type, 7.22                                               enumeration, 6.2.5, 6.7.2.2
25901 division assignment operator (/=), 6.5.16.2                    enumeration constant, 6.2.1, 6.4.4.3
25902 division operator (/), 6.2.6.2, 6.5.5, F.3, G.5.1              enumeration content, 6.7.2.3
25903 do statement, 6.8.5.2                                          enumeration members, 6.7.2.2
25904 documentation of implementation, 4                             enumeration specifiers, 6.7.2.2
25905 domain error, 7.12.1, 7.12.4.1, 7.12.4.2, 7.12.4.4,            enumeration tag, 6.2.3, 6.7.2.3
25906       7.12.5.1, 7.12.5.3, 7.12.6.5, 7.12.6.7,                  enumerator, 6.7.2.2
25907       7.12.6.8, 7.12.6.9, 7.12.6.10, 7.12.6.11,                environment, 5
25908       7.12.7.4, 7.12.7.5, 7.12.8.4, 7.12.9.5,                  environment functions, 7.22.4, K.3.6.2
25909       7.12.9.7, 7.12.10.1, 7.12.10.2, 7.12.10.3                environment list, 7.22.4.6, K.3.6.2.1
25910 dot operator (.), 6.5.2.3                                      environmental considerations, 5.2
25911 double _Complex type, 6.2.5                                    environmental limits, 5.2.4, 7.13.1.1, 7.21.2,
25912 double _Complex type conversion, 6.3.1.6,                            7.21.3, 7.21.4.4, 7.21.6.1, 7.22.2.1, 7.22.4.2,
25913       6.3.1.7, 6.3.1.8                                               7.22.4.3, 7.28.2.1, K.3.5.1.2
25914 double _Imaginary type, G.2                                    EOF macro, 7.4, 7.21.1, 7.21.5.1, 7.21.5.2,
25915 double type, 6.2.5, 6.4.4.2, 6.7.2, 7.21.6.2,                        7.21.6.2, 7.21.6.7, 7.21.6.9, 7.21.6.11,
25916       7.28.2.2, F.2                                                  7.21.6.14, 7.21.7.1, 7.21.7.3, 7.21.7.4,
25917 double type conversion, 6.3.1.4, 6.3.1.5, 6.3.1.7,                   7.21.7.5, 7.21.7.6, 7.21.7.8, 7.21.7.9,
25918       6.3.1.8                                                        7.21.7.10, 7.28.1, 7.28.2.2, 7.28.2.4,
25919 double-precision arithmetic, 5.1.2.3                                 7.28.2.6, 7.28.2.8, 7.28.2.10, 7.28.2.12,
25920 double-quote escape sequence (\"), 6.4.4.4,                          7.28.3.4, 7.28.6.1.1, 7.28.6.1.2, K.3.5.3.7,
25921       6.4.5, 6.10.9                                                  K.3.5.3.9, K.3.5.3.11, K.3.5.3.14, K.3.9.1.2,
25922 double_t type, 7.12, J.5.6                                           K.3.9.1.5, K.3.9.1.7, K.3.9.1.10, K.3.9.1.12,
25923                                                                      K.3.9.1.14
25924 EDOM macro, 7.5, 7.12.1, see also domain error                 equal-sign punctuator (=), 6.7, 6.7.2.2, 6.7.9
25925 effective type, 6.5                                            equal-to operator, see equality operator
25926 EILSEQ macro, 7.5, 7.21.3, 7.27.1.1, 7.27.1.2,                 equality expressions, 6.5.9
25927      7.27.1.3, 7.27.1.4, 7.28.3.1, 7.28.3.3,                   equality operator (==), 6.5.9
25928      7.28.6.3.2, 7.28.6.3.3, 7.28.6.4.1, 7.28.6.4.2,           ERANGE macro, 7.5, 7.8.2.3, 7.8.2.4, 7.12.1,
25929      see also encoding error                                         7.22.1.3, 7.22.1.4, 7.28.4.1.1, 7.28.4.1.2, see
25930 element type, 6.2.5                                                  also range error, pole error
25931
25932 [page 660]
25933
25934 erf functions, 7.12.8.1, F.10.5.1                               exp2 functions, 7.12.6.2, F.10.3.2
25935 erf type-generic macro, 7.24                                    exp2 type-generic macro, 7.24
25936 erfc functions, 7.12.8.2, F.10.5.2                              explicit conversion, 6.3
25937 erfc type-generic macro, 7.24                                   expm1 functions, 7.12.6.3, F.10.3.3
25938 errno macro, 7.1.3, 7.3.2, 7.5, 7.8.2.3, 7.8.2.4,               expm1 type-generic macro, 7.24
25939       7.12.1, 7.14.1.1, 7.21.3, 7.21.9.3, 7.21.10.4,            exponent part, 6.4.4.2
25940       7.22.1, 7.22.1.3, 7.22.1.4, 7.23.6.2, 7.27.1.1,           exponential functions
25941       7.27.1.2, 7.27.1.3, 7.27.1.4, 7.28.3.1,                     complex, 7.3.7, G.6.3
25942       7.28.3.3, 7.28.4.1.1, 7.28.4.1.2, 7.28.6.3.2,               real, 7.12.6, F.10.3
25943       7.28.6.3.3, 7.28.6.4.1, 7.28.6.4.2, J.5.17,               expression, 6.5
25944       K.3.1.3, K.3.7.4.2                                          assignment, 6.5.16
25945 errno.h header, 7.5, 7.30.3, K.3.2                                cast, 6.5.4
25946 errno_t type, K.3.2, K.3.5, K.3.6, K.3.6.1.1,                     constant, 6.6
25947       K.3.7, K.3.8, K.3.9                                         evaluation, 5.1.2.3
25948 error                                                             full, 6.8
25949    domain, see domain error                                       order of evaluation, see order of evaluation
25950    encoding, see encoding error                                   parenthesized, 6.5.1
25951    pole, see pole error                                           primary, 6.5.1
25952    range, see range error                                         unary, 6.5.3
25953 error conditions, 7.12.1                                        expression statement, 6.8.3
25954 error functions, 7.12.8, F.10.5                                 extended alignment, 6.2.8
25955 error indicator, 7.21.1, 7.21.5.3, 7.21.7.1,                    extended character set, 3.7.2, 5.2.1, 5.2.1.2
25956       7.21.7.3, 7.21.7.5, 7.21.7.6, 7.21.7.7,                   extended characters, 5.2.1
25957       7.21.7.8, 7.21.9.2, 7.21.10.1, 7.21.10.3,                 extended integer types, 6.2.5, 6.3.1.1, 6.4.4.1,
25958       7.28.3.1, 7.28.3.3                                             7.20
25959 error preprocessing directive, 4, 6.10.5                        extended multibyte/wide character conversion
25960 error-handling functions, 7.21.10, 7.23.6.2,                         utilities, 7.28.6, K.3.9.3
25961       K.3.7.4.2, K.3.7.4.3                                      extensible wide character case mapping functions,
25962 escape character (\), 6.4.4.4                                        7.29.3.2
25963 escape sequences, 5.2.1, 5.2.2, 6.4.4.4, 6.11.4                 extensible wide character classification functions,
25964 evaluation format, 5.2.4.2.2, 6.4.4.2, 7.12                          7.29.2.2
25965 evaluation method, 5.2.4.2.2, 6.5, F.8.5                        extern storage-class specifier, 6.2.2, 6.7.1
25966 evaluation of expression, 5.1.2.3                               external definition, 6.9
25967 evaluation order, see order of evaluation                       external identifiers, underscore, 7.1.3
25968 exceptional condition, 6.5                                      external linkage, 6.2.2
25969 excess precision, 5.2.4.2.2, 6.3.1.8, 6.8.6.4                   external name, 6.4.2.1
25970 excess range, 5.2.4.2.2, 6.3.1.8, 6.8.6.4                       external object definitions, 6.9.2
25971 exclusive OR operators
25972    bitwise (^), 6.2.6.2, 6.5.11                                 fabs functions, 7.12.7.2, F.3, F.10.4.2
25973    bitwise assignment (^=), 6.5.16.2                            fabs type-generic macro, 7.24, G.7
25974 executable program, 5.1.1.1                                     false macro, 7.18
25975 execution character set, 5.2.1                                  fclose function, 7.21.5.1
25976 execution environment, 5, 5.1.2, see also                       fdim functions, 7.12.12.1, F.10.9.1
25977       environmental limits                                      fdim type-generic macro, 7.24
25978 execution sequence, 5.1.2.3, 6.8                                FE_ALL_EXCEPT macro, 7.6
25979 exit function, 5.1.2.2.3, 7.21.3, 7.22, 7.22.4.4,               FE_DFL_ENV macro, 7.6
25980       7.22.4.5, 7.22.4.7                                        FE_DIVBYZERO macro, 7.6, 7.12, F.3
25981 EXIT_FAILURE macro, 7.22, 7.22.4.4                              FE_DOWNWARD macro, 7.6, F.3
25982 EXIT_SUCCESS macro, 7.22, 7.22.4.4                              FE_INEXACT macro, 7.6, F.3
25983 exp functions, 7.12.6.1, F.10.3.1                               FE_INVALID macro, 7.6, 7.12, F.3
25984 exp type-generic macro, 7.24                                    FE_OVERFLOW macro, 7.6, 7.12, F.3
25985
25986 [page 661]
25987
25988 FE_TONEAREST macro, 7.6, F.3                                 float _Complex type conversion, 6.3.1.6,
25989 FE_TOWARDZERO macro, 7.6, F.3                                     6.3.1.7, 6.3.1.8
25990 FE_UNDERFLOW macro, 7.6, F.3                                 float _Imaginary type, G.2
25991 FE_UPWARD macro, 7.6, F.3                                    float type, 6.2.5, 6.4.4.2, 6.7.2, F.2
25992 feclearexcept function, 7.6.2, 7.6.2.1, F.3                  float type conversion, 6.3.1.4, 6.3.1.5, 6.3.1.7,
25993 fegetenv function, 7.6.4.1, 7.6.4.3, 7.6.4.4, F.3                 6.3.1.8
25994 fegetexceptflag function, 7.6.2, 7.6.2.2, F.3                float.h header, 4, 5.2.4.2.2, 7.7, 7.22.1.3,
25995 fegetround function, 7.6, 7.6.3.1, F.3                            7.28.4.1.1
25996 feholdexcept function, 7.6.4.2, 7.6.4.3,                     float_t type, 7.12, J.5.6
25997      7.6.4.4, F.3                                            floating constant, 6.4.4.2
25998 fence, 5.1.2.4                                               floating suffix, f or F, 6.4.4.2
25999 fences, 7.17.4                                               floating type conversion, 6.3.1.4, 6.3.1.5, 6.3.1.7,
26000 fenv.h header, 5.1.2.3, 5.2.4.2.2, 7.6, 7.12, F, H                F.3, F.4
26001 FENV_ACCESS pragma, 6.10.6, 7.6.1, F.8, F.9,                 floating types, 6.2.5, 6.11.1
26002      F.10                                                    floating-point accuracy, 5.2.4.2.2, 6.4.4.2, 6.5,
26003 fenv_t type, 7.6                                                  7.22.1.3, F.5, see also contracted expression
26004 feof function, 7.21.10.2                                     floating-point arithmetic functions, 7.12, F.10
26005 feraiseexcept function, 7.6.2, 7.6.2.3, F.3                  floating-point classification functions, 7.12.3
26006 ferror function, 7.21.10.3                                   floating-point control mode, 7.6, F.8.6
26007 fesetenv function, 7.6.4.3, F.3                              floating-point environment, 7.6, F.8, F.8.6
26008 fesetexceptflag function, 7.6.2, 7.6.2.4, F.3                floating-point exception, 7.6, 7.6.2, F.10
26009 fesetround function, 7.6, 7.6.3.2, F.3                       floating-point number, 5.2.4.2.2, 6.2.5
26010 fetestexcept function, 7.6.2, 7.6.2.5, F.3                   floating-point rounding mode, 5.2.4.2.2
26011 feupdateenv function, 7.6.4.2, 7.6.4.4, F.3                  floating-point status flag, 7.6, F.8.6
26012 fexcept_t type, 7.6, F.3                                     floor functions, 7.12.9.2, F.10.6.2
26013 fflush function, 7.21.5.2, 7.21.5.3                          floor type-generic macro, 7.24
26014 fgetc function, 7.21.1, 7.21.3, 7.21.7.1,                    FLT_DECIMAL_DIG macro, 5.2.4.2.2
26015      7.21.7.5, 7.21.8.1                                      FLT_DIG macro, 5.2.4.2.2
26016 fgetpos function, 7.21.2, 7.21.9.1, 7.21.9.3                 FLT_EPSILON macro, 5.2.4.2.2
26017 fgets function, 7.21.1, 7.21.7.2, K.3.5.4.1                  FLT_EVAL_METHOD macro, 5.2.4.2.2, 6.6, 7.12,
26018 fgetwc function, 7.21.1, 7.21.3, 7.28.3.1,                        F.10.11
26019      7.28.3.6                                                FLT_HAS_SUBNORM macro, 5.2.4.2.2
26020 fgetws function, 7.21.1, 7.28.3.2                            FLT_MANT_DIG macro, 5.2.4.2.2
26021 field width, 7.21.6.1, 7.28.2.1                               FLT_MAX macro, 5.2.4.2.2
26022 file, 7.21.3                                                  FLT_MAX_10_EXP macro, 5.2.4.2.2
26023   access functions, 7.21.5, K.3.5.2                          FLT_MAX_EXP macro, 5.2.4.2.2
26024   name, 7.21.3                                               FLT_MIN macro, 5.2.4.2.2
26025   operations, 7.21.4, K.3.5.1                                FLT_MIN_10_EXP macro, 5.2.4.2.2
26026   position indicator, 7.21.1, 7.21.2, 7.21.3,                FLT_MIN_EXP macro, 5.2.4.2.2
26027         7.21.5.3, 7.21.7.1, 7.21.7.3, 7.21.7.10,             FLT_RADIX macro, 5.2.4.2.2, 7.21.6.1, 7.22.1.3,
26028         7.21.8.1, 7.21.8.2, 7.21.9.1, 7.21.9.2,                   7.28.2.1, 7.28.4.1.1
26029         7.21.9.3, 7.21.9.4, 7.21.9.5, 7.28.3.1,              FLT_ROUNDS macro, 5.2.4.2.2, 7.6, F.3
26030         7.28.3.3, 7.28.3.10                                  FLT_TRUE_MIN macro, 5.2.4.2.2
26031   positioning functions, 7.21.9                              fma functions, 7.12, 7.12.13.1, F.10.10.1
26032 file scope, 6.2.1, 6.9                                        fma type-generic macro, 7.24
26033 FILE type, 7.21.1, 7.21.3                                    fmax functions, 7.12.12.2, F.10.9.2
26034 FILENAME_MAX macro, 7.21.1                                   fmax type-generic macro, 7.24
26035 flags, 7.21.6.1, 7.28.2.1, see also floating-point             fmin functions, 7.12.12.3, F.10.9.3
26036      status flag                                              fmin type-generic macro, 7.24
26037 flexible array member, 6.7.2.1                                fmod functions, 7.12.10.1, F.10.7.1
26038 float _Complex type, 6.2.5                                   fmod type-generic macro, 7.24
26039
26040 [page 662]
26041
26042 fopen function, 7.21.5.3, 7.21.5.4, K.3.5.2.1                       K.3.5.3.7, K.3.5.3.9
26043 FOPEN_MAX macro, 7.21.1, 7.21.3, 7.21.4.3,                    fseek function, 7.21.1, 7.21.5.3, 7.21.7.10,
26044      K.3.5.1.1                                                      7.21.9.2, 7.21.9.4, 7.21.9.5, 7.28.3.10
26045 fopen_s function, K.3.5.1.1, K.3.5.2.1,                       fsetpos function, 7.21.2, 7.21.5.3, 7.21.7.10,
26046      K.3.5.2.2                                                      7.21.9.1, 7.21.9.3, 7.28.3.10
26047 for statement, 6.8.5, 6.8.5.3                                 ftell function, 7.21.9.2, 7.21.9.4
26048 form-feed character, 5.2.1, 6.4                               full declarator, 6.7.6
26049 form-feed escape sequence (\f), 5.2.2, 6.4.4.4,               full expression, 6.8
26050      7.4.1.10                                                 fully buffered stream, 7.21.3
26051 formal argument (deprecated), 3.16                            function
26052 formal parameter, 3.16                                           argument, 6.5.2.2, 6.9.1
26053 formatted input/output functions, 7.11.1.1, 7.21.6,              body, 6.9.1
26054      K.3.5.3                                                     call, 6.5.2.2
26055    wide character, 7.28.2, K.3.9.1                                  library, 7.1.4
26056 fortran keyword, J.5.9                                           declarator, 6.7.6.3, 6.11.6
26057 forward reference, 3.11                                          definition, 6.7.6.3, 6.9.1, 6.11.7
26058 FP_CONTRACT pragma, 6.5, 6.10.6, 7.12.2, see                     designator, 6.3.2.1
26059      also contracted expression                                  image, 5.2.3
26060 FP_FAST_FMA macro, 7.12                                          inline, 6.7.4
26061 FP_FAST_FMAF macro, 7.12                                         library, 5.1.1.1, 7.1.4
26062 FP_FAST_FMAL macro, 7.12                                         name length, 5.2.4.1, 6.4.2.1, 6.11.3
26063 FP_ILOGB0 macro, 7.12, 7.12.6.5                                  no-return, 6.7.4
26064 FP_ILOGBNAN macro, 7.12, 7.12.6.5                                parameter, 5.1.2.2.1, 6.5.2.2, 6.7, 6.9.1
26065 FP_INFINITE macro, 7.12, F.3                                     prototype, 5.1.2.2.1, 6.2.1, 6.2.7, 6.5.2.2, 6.7,
26066 FP_NAN macro, 7.12, F.3                                                6.7.6.3, 6.9.1, 6.11.6, 6.11.7, 7.1.2, 7.12
26067 FP_NORMAL macro, 7.12, F.3                                       prototype scope, 6.2.1, 6.7.6.2
26068 FP_SUBNORMAL macro, 7.12, F.3                                    recursive call, 6.5.2.2
26069 FP_ZERO macro, 7.12, F.3                                         return, 6.8.6.4, F.6
26070 fpclassify macro, 7.12.3.1, F.3                                  scope, 6.2.1
26071 fpos_t type, 7.21.1, 7.21.2                                      type, 6.2.5
26072 fprintf function, 7.8.1, 7.21.1, 7.21.6.1,                       type conversion, 6.3.2.1
26073      7.21.6.2, 7.21.6.3, 7.21.6.5, 7.21.6.6,                  function specifiers, 6.7.4
26074      7.21.6.8, 7.28.2.2, F.3, K.3.5.3.1                       function type, 6.2.5
26075 fprintf_s function, K.3.5.3.1                                 function-call operator (( )), 6.5.2.2
26076 fputc function, 5.2.2, 7.21.1, 7.21.3, 7.21.7.3,              function-like macro, 6.10.3
26077      7.21.7.7, 7.21.8.2                                       fundamental alignment, 6.2.8
26078 fputs function, 7.21.1, 7.21.7.4                              future directions
26079 fputwc function, 7.21.1, 7.21.3, 7.28.3.3,                       language, 6.11
26080      7.28.3.8                                                    library, 7.30
26081 fputws function, 7.21.1, 7.28.3.4                             fwide function, 7.21.2, 7.28.3.5
26082 fread function, 7.21.1, 7.21.8.1                              fwprintf function, 7.8.1, 7.21.1, 7.21.6.2,
26083 free function, 7.22.3.3, 7.22.3.5                                   7.28.2.1, 7.28.2.2, 7.28.2.3, 7.28.2.5,
26084 freestanding execution environment, 4, 5.1.2,                       7.28.2.11, K.3.9.1.1
26085      5.1.2.1                                                  fwprintf_s function, K.3.9.1.1
26086 freopen function, 7.21.2, 7.21.5.4                            fwrite function, 7.21.1, 7.21.8.2
26087 freopen_s function, K.3.5.2.2                                 fwscanf function, 7.8.1, 7.21.1, 7.28.2.2,
26088 frexp functions, 7.12.6.4, F.10.3.4                                 7.28.2.4, 7.28.2.6, 7.28.2.12, 7.28.3.10,
26089 frexp type-generic macro, 7.24                                      K.3.9.1.2
26090 fscanf function, 7.8.1, 7.21.1, 7.21.6.2,                     fwscanf_s function, K.3.9.1.2, K.3.9.1.5,
26091      7.21.6.4, 7.21.6.7, 7.21.6.9, F.3, K.3.5.3.2                   K.3.9.1.7, K.3.9.1.14
26092 fscanf_s function, K.3.5.3.2, K.3.5.3.4,
26093
26094 [page 663]
26095
26096 gamma functions, 7.12.8, F.10.5                               name spaces, 6.2.3
26097 general utilities, 7.22, K.3.6                                reserved, 6.4.1, 7.1.3, K.3.1.2
26098   wide string, 7.28.4, K.3.9.2                                 scope, 6.2.1
26099 general wide string utilities, 7.28.4, K.3.9.2                 type, 6.2.5
26100 generic parameters, 7.24                                    identifier list, 6.7.6
26101 generic selection, 6.5.1.1                                  identifier nondigit, 6.4.2.1
26102 getc function, 7.21.1, 7.21.7.5, 7.21.7.6                   IEC 559, F.1
26103 getchar function, 7.21.1, 7.21.7.6                          IEC 60559, 2, 5.1.2.3, 5.2.4.2.2, 6.10.8.3, 7.3.3,
26104 getenv function, 7.22.4.6                                         7.6, 7.6.4.2, 7.12.1, 7.12.10.2, 7.12.14, F, G,
26105 getenv_s function, K.3.6.2.1                                      H.1
26106 gets function, K.3.5.4.1                                    IEEE 754, F.1
26107 gets_s function, K.3.5.4.1                                  IEEE 854, F.1
26108 getwc function, 7.21.1, 7.28.3.6, 7.28.3.7                  IEEE floating-point arithmetic standard, see
26109 getwchar function, 7.21.1, 7.28.3.7                               IEC 60559, ANSI/IEEE 754,
26110 gmtime function, 7.26.3.3                                         ANSI/IEEE 854
26111 gmtime_s function, K.3.8.2.3                                if preprocessing directive, 5.2.4.2.1, 5.2.4.2.2,
26112 goto statement, 6.2.1, 6.8.1, 6.8.6.1                             6.10.1, 7.1.4
26113 graphic characters, 5.2.1                                   if statement, 6.8.4.1
26114 greater-than operator (>), 6.5.8                            ifdef preprocessing directive, 6.10.1
26115 greater-than-or-equal-to operator (>=), 6.5.8               ifndef preprocessing directive, 6.10.1
26116                                                             ignore_handler_s function, K.3.6.1.3
26117 happens before, 5.1.2.4                                     ilogb functions, 7.12, 7.12.6.5, F.10.3.5
26118 header, 5.1.1.1, 7.1.2, see also standard headers           ilogb type-generic macro, 7.24
26119 header names, 6.4, 6.4.7, 6.10.2                            imaginary macro, 7.3.1, G.6
26120 hexadecimal constant, 6.4.4.1                               imaginary numbers, G
26121 hexadecimal digit, 6.4.4.1, 6.4.4.2, 6.4.4.4                imaginary type domain, G.2
26122 hexadecimal prefix, 6.4.4.1                                  imaginary types, G
26123 hexadecimal-character escape sequence                       imaxabs function, 7.8.2.1
26124      (\x hexadecimal digits), 6.4.4.4                       imaxdiv function, 7.8, 7.8.2.2
26125 high-order bit, 3.6                                         imaxdiv_t type, 7.8
26126 horizontal-tab character, 5.2.1, 6.4                        implementation, 3.12
26127 horizontal-tab escape sequence (\r), 7.29.2.1.3             implementation limit, 3.13, 4, 5.2.4.2, 6.4.2.1,
26128 horizontal-tab escape sequence (\t), 5.2.2,                       6.7.6, 6.8.4.2, E, see also environmental
26129      6.4.4.4, 7.4.1.3, 7.4.1.10                                   limits
26130 hosted execution environment, 4, 5.1.2, 5.1.2.2             implementation-defined behavior, 3.4.1, 4, J.3
26131 HUGE_VAL macro, 7.12, 7.12.1, 7.22.1.3,                     implementation-defined value, 3.19.1
26132      7.28.4.1.1, F.10                                       implicit conversion, 6.3
26133 HUGE_VALF macro, 7.12, 7.12.1, 7.22.1.3,                    implicit initialization, 6.7.9
26134      7.28.4.1.1, F.10                                       include preprocessing directive, 5.1.1.2, 6.10.2
26135 HUGE_VALL macro, 7.12, 7.12.1, 7.22.1.3,                    inclusive OR operators
26136      7.28.4.1.1, F.10                                         bitwise (|), 6.2.6.2, 6.5.12
26137 hyperbolic functions                                           bitwise assignment (|=), 6.5.16.2
26138   complex, 7.3.6, G.6.2                                     incomplete type, 6.2.5
26139   real, 7.12.5, F.10.2                                      increment operators, see arithmetic operators,
26140 hypot functions, 7.12.7.3, F.10.4.3                               increment and decrement
26141 hypot type-generic macro, 7.24                              indeterminate value, 3.19.2
26142                                                             indeterminately sequenced, 5.1.2.3, 6.5.2.2,
26143 I macro, 7.3.1, 7.3.9.5, G.6                                      6.5.2.4, 6.5.16.2, see also sequenced before,
26144 identifier, 6.4.2.1, 6.5.1                                         unsequenced
26145    linkage, see linkage                                     indirection operator (*), 6.5.2.1, 6.5.3.2
26146    maximum length, 6.4.2.1                                  inequality operator (!=), 6.5.9
26147
26148 [page 664]
26149
26150 infinitary, 7.12.1                                                    extended, 6.2.5, 6.3.1.1, 6.4.4.1, 7.20
26151 INFINITY macro, 7.3.9.5, 7.12, F.2.1                              inter-thread happens before, 5.1.2.4
26152 initial position, 5.2.2                                           interactive device, 5.1.2.3, 7.21.3, 7.21.5.3
26153 initial shift state, 5.2.1.2                                      internal linkage, 6.2.2
26154 initialization, 5.1.2, 6.2.4, 6.3.2.1, 6.5.2.5, 6.7.9,            internal name, 6.4.2.1
26155       F.8.5                                                       interrupt, 5.2.3
26156    in blocks, 6.8                                                 INTMAX_C macro, 7.20.4.2
26157 initializer, 6.7.9                                                INTMAX_MAX macro, 7.8.2.3, 7.8.2.4, 7.20.2.5
26158    permitted form, 6.6                                            INTMAX_MIN macro, 7.8.2.3, 7.8.2.4, 7.20.2.5
26159    string literal, 6.3.2.1                                        intmax_t type, 7.20.1.5, 7.21.6.1, 7.21.6.2,
26160 inline, 6.7.4                                                           7.28.2.1, 7.28.2.2
26161 inner scope, 6.2.1                                                INTN_C macros, 7.20.4.1
26162 input failure, 7.28.2.6, 7.28.2.8, 7.28.2.10,                     INTN_MAX macros, 7.20.2.1
26163       K.3.5.3.2, K.3.5.3.4, K.3.5.3.7, K.3.5.3.9,                 INTN_MIN macros, 7.20.2.1
26164       K.3.5.3.11, K.3.5.3.14, K.3.9.1.2, K.3.9.1.5,               intN_t types, 7.20.1.1
26165       K.3.9.1.7, K.3.9.1.10, K.3.9.1.12, K.3.9.1.14               INTPTR_MAX macro, 7.20.2.4
26166 input/output functions                                            INTPTR_MIN macro, 7.20.2.4
26167    character, 7.21.7, K.3.5.4                                     intptr_t type, 7.20.1.4
26168    direct, 7.21.8                                                 inttypes.h header, 7.8, 7.30.4
26169    formatted, 7.21.6, K.3.5.3                                     isalnum function, 7.4.1.1, 7.4.1.9, 7.4.1.10
26170       wide character, 7.28.2, K.3.9.1                             isalpha function, 7.4.1.1, 7.4.1.2
26171    wide character, 7.28.3                                         isblank function, 7.4.1.3
26172       formatted, 7.28.2, K.3.9.1                                  iscntrl function, 7.4.1.2, 7.4.1.4, 7.4.1.7,
26173 input/output header, 7.21, K.3.5                                        7.4.1.11
26174 input/output, device, 5.1.2.3                                     isdigit function, 7.4.1.1, 7.4.1.2, 7.4.1.5,
26175 int type, 6.2.5, 6.3.1.1, 6.3.1.3, 6.4.4.1, 6.7.2                       7.4.1.7, 7.4.1.11, 7.11.1.1
26176 int type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,                   isfinite macro, 7.12.3.2, F.3
26177       6.3.1.8                                                     isgraph function, 7.4.1.6
26178 INT_FASTN_MAX macros, 7.20.2.3                                    isgreater macro, 7.12.14.1, F.3
26179 INT_FASTN_MIN macros, 7.20.2.3                                    isgreaterequal macro, 7.12.14.2, F.3
26180 int_fastN_t types, 7.20.1.3                                       isinf macro, 7.12.3.3
26181 INT_LEASTN_MAX macros, 7.20.2.2                                   isless macro, 7.12.14.3, F.3
26182 INT_LEASTN_MIN macros, 7.20.2.2                                   islessequal macro, 7.12.14.4, F.3
26183 int_leastN_t types, 7.20.1.2                                      islessgreater macro, 7.12.14.5, F.3
26184 INT_MAX macro, 5.2.4.2.1, 7.12, 7.12.6.5                          islower function, 7.4.1.2, 7.4.1.7, 7.4.2.1,
26185 INT_MIN macro, 5.2.4.2.1, 7.12                                          7.4.2.2
26186 integer arithmetic functions, 7.8.2.1, 7.8.2.2,                   isnan macro, 7.12.3.4, F.3
26187       7.22.6                                                      isnormal macro, 7.12.3.5
26188 integer character constant, 6.4.4.4                               ISO 31-11, 2, 3
26189 integer constant, 6.4.4.1                                         ISO 4217, 2, 7.11.2.1
26190 integer constant expression, 6.3.2.3, 6.6, 6.7.2.1,               ISO 8601, 2, 7.26.3.5
26191       6.7.2.2, 6.7.6.2, 6.7.9, 6.7.10, 6.8.4.2, 6.10.1,           ISO/IEC 10646, 2, 6.4.2.1, 6.4.3, 6.10.8.2
26192       7.1.4                                                       ISO/IEC 10976-1, H.1
26193 integer conversion rank, 6.3.1.1                                  ISO/IEC 2382-1, 2, 3
26194 integer promotions, 5.1.2.3, 5.2.4.2.1, 6.3.1.1,                  ISO/IEC 646, 2, 5.2.1.1
26195       6.5.2.2, 6.5.3.3, 6.5.7, 6.8.4.2, 7.20.2, 7.20.3,           ISO/IEC 9945-2, 7.11
26196       7.21.6.1, 7.28.2.1                                          iso646.h header, 4, 7.9                          *
26197 integer suffix, 6.4.4.1                                            isprint function, 5.2.2, 7.4.1.8
26198 integer type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,               ispunct function, 7.4.1.2, 7.4.1.7, 7.4.1.9,
26199       F.3, F.4                                                          7.4.1.11
26200 integer types, 6.2.5, 7.20                                        isspace function, 7.4.1.2, 7.4.1.7, 7.4.1.9,
26201
26202 [page 665]
26203
26204       7.4.1.10, 7.4.1.11, 7.21.6.2, 7.22.1.3,                   LC_ALL macro, 7.11, 7.11.1.1, 7.11.2.1
26205       7.22.1.4, 7.28.2.2                                        LC_COLLATE macro, 7.11, 7.11.1.1, 7.23.4.3,
26206 isunordered macro, 7.12.14.6, F.3                                     7.28.4.4.2
26207 isupper function, 7.4.1.2, 7.4.1.11, 7.4.2.1,                   LC_CTYPE macro, 7.11, 7.11.1.1, 7.22, 7.22.7,
26208       7.4.2.2                                                         7.22.8, 7.28.6, 7.29.1, 7.29.2.2.1, 7.29.2.2.2,
26209 iswalnum function, 7.29.2.1.1, 7.29.2.1.9,                            7.29.3.2.1, 7.29.3.2.2, K.3.6.4, K.3.6.5
26210       7.29.2.1.10, 7.29.2.2.1                                   LC_MONETARY macro, 7.11, 7.11.1.1, 7.11.2.1
26211 iswalpha function, 7.29.2.1.1, 7.29.2.1.2,                      LC_NUMERIC macro, 7.11, 7.11.1.1, 7.11.2.1
26212       7.29.2.2.1                                                LC_TIME macro, 7.11, 7.11.1.1, 7.26.3.5
26213 iswblank function, 7.29.2.1.3, 7.29.2.2.1                       lconv structure type, 7.11
26214 iswcntrl function, 7.29.2.1.2, 7.29.2.1.4,                      LDBL_DECIMAL_DIG macro, 5.2.4.2.2
26215       7.29.2.1.7, 7.29.2.1.11, 7.29.2.2.1                       LDBL_DIG macro, 5.2.4.2.2
26216 iswctype function, 7.29.2.2.1, 7.29.2.2.2                       LDBL_EPSILON macro, 5.2.4.2.2
26217 iswdigit function, 7.29.2.1.1, 7.29.2.1.2,                      LDBL_HAS_SUBNORM macro, 5.2.4.2.2
26218       7.29.2.1.5, 7.29.2.1.7, 7.29.2.1.11, 7.29.2.2.1           LDBL_MANT_DIG macro, 5.2.4.2.2
26219 iswgraph function, 7.29.2.1, 7.29.2.1.6,                        LDBL_MAX macro, 5.2.4.2.2
26220       7.29.2.1.10, 7.29.2.2.1                                   LDBL_MAX_10_EXP macro, 5.2.4.2.2
26221 iswlower function, 7.29.2.1.2, 7.29.2.1.7,                      LDBL_MAX_EXP macro, 5.2.4.2.2
26222       7.29.2.2.1, 7.29.3.1.1, 7.29.3.1.2                        LDBL_MIN macro, 5.2.4.2.2
26223 iswprint function, 7.29.2.1.6, 7.29.2.1.8,                      LDBL_MIN_10_EXP macro, 5.2.4.2.2
26224       7.29.2.2.1                                                LDBL_MIN_EXP macro, 5.2.4.2.2
26225 iswpunct function, 7.29.2.1, 7.29.2.1.2,                        LDBL_TRUE_MIN macro, 5.2.4.2.2
26226       7.29.2.1.7, 7.29.2.1.9, 7.29.2.1.10,                      ldexp functions, 7.12.6.6, F.10.3.6
26227       7.29.2.1.11, 7.29.2.2.1                                   ldexp type-generic macro, 7.24
26228 iswspace function, 7.21.6.2, 7.28.2.2,                          ldiv function, 7.22.6.2
26229       7.28.4.1.1, 7.28.4.1.2, 7.29.2.1.2, 7.29.2.1.6,           ldiv_t type, 7.22
26230       7.29.2.1.7, 7.29.2.1.9, 7.29.2.1.10,                      leading underscore in identifiers, 7.1.3
26231       7.29.2.1.11, 7.29.2.2.1                                   left-shift assignment operator (<<=), 6.5.16.2
26232 iswupper function, 7.29.2.1.2, 7.29.2.1.11,                     left-shift operator (<<), 6.2.6.2, 6.5.7
26233       7.29.2.2.1, 7.29.3.1.1, 7.29.3.1.2                        length
26234 iswxdigit function, 7.29.2.1.12, 7.29.2.2.1                        external name, 5.2.4.1, 6.4.2.1, 6.11.3
26235 isxdigit function, 7.4.1.12, 7.11.1.1                              function name, 5.2.4.1, 6.4.2.1, 6.11.3
26236 italic type convention, 3, 6.1                                     identifier, 6.4.2.1
26237 iteration statements, 6.8.5                                        internal name, 5.2.4.1, 6.4.2.1
26238                                                                 length function, 7.22.7.1, 7.23.6.3, 7.28.4.6.1,
26239 jmp_buf type, 7.13                                                    7.28.6.3.1, K.3.7.4.4, K.3.9.2.4.1
26240 jump statements, 6.8.6                                          length modifier, 7.21.6.1, 7.21.6.2, 7.28.2.1,
26241                                                                       7.28.2.2
26242 keywords, 6.4.1, G.2, J.5.9, J.5.10                             less-than operator (<), 6.5.8
26243 kill_dependency macro, 5.1.2.4, 7.17.3.1                        less-than-or-equal-to operator (<=), 6.5.8
26244 known constant size, 6.2.5                                      letter, 5.2.1, 7.4
26245                                                                 lexical elements, 5.1.1.2, 6.4
26246 L_tmpnam macro, 7.21.1, 7.21.4.4                                lgamma functions, 7.12.8.3, F.10.5.3
26247 L_tmpnam_s macro, K.3.5, K.3.5.1.2                              lgamma type-generic macro, 7.24
26248 label name, 6.2.1, 6.2.3                                        library, 5.1.1.1, 7, K.3
26249 labeled statement, 6.8.1                                           future directions, 7.30
26250 labs function, 7.22.6.1                                            summary, B
26251 language, 6                                                        terms, 7.1.1
26252    future directions, 6.11                                         use of functions, 7.1.4
26253    syntax summary, A                                            lifetime, 6.2.4
26254 Latin alphabet, 5.2.1, 6.4.2.1                                  limits
26255
26256 [page 666]
26257
26258    environmental, see environmental limits                      6.3.1.6, 6.3.1.7, 6.3.1.8
26259    implementation, see implementation limits               long double _Imaginary type, G.2
26260    numerical, see numerical limits                         long double suffix, l or L, 6.4.4.2
26261    translation, see translation limits                     long double type, 6.2.5, 6.4.4.2, 6.7.2,
26262 limits.h header, 4, 5.2.4.2.1, 6.2.5, 7.10                      7.21.6.1, 7.21.6.2, 7.28.2.1, 7.28.2.2, F.2
26263 line buffered stream, 7.21.3                               long double type conversion, 6.3.1.4, 6.3.1.5,
26264 line number, 6.10.4, 6.10.8.1                                   6.3.1.7, 6.3.1.8
26265 line preprocessing directive, 6.10.4                       long int type, 6.2.5, 6.3.1.1, 6.7.2, 7.21.6.1,
26266 lines, 5.1.1.2, 7.21.2                                          7.21.6.2, 7.28.2.1, 7.28.2.2
26267    preprocessing directive, 6.10                           long int type conversion, 6.3.1.1, 6.3.1.3,
26268 linkage, 6.2.2, 6.7, 6.7.4, 6.7.6.2, 6.9, 6.9.2,                6.3.1.4, 6.3.1.8
26269       6.11.2                                               long integer suffix, l or L, 6.4.4.1
26270 llabs function, 7.22.6.1                                   long long int type, 6.2.5, 6.3.1.1, 6.7.2,
26271 lldiv function, 7.22.6.2                                        7.21.6.1, 7.21.6.2, 7.28.2.1, 7.28.2.2
26272 lldiv_t type, 7.22                                         long long int type conversion, 6.3.1.1,
26273 LLONG_MAX macro, 5.2.4.2.1, 7.22.1.4,                           6.3.1.3, 6.3.1.4, 6.3.1.8
26274       7.28.4.1.2                                           long long integer suffix, ll or LL, 6.4.4.1
26275 LLONG_MIN macro, 5.2.4.2.1, 7.22.1.4,                      LONG_MAX macro, 5.2.4.2.1, 7.22.1.4, 7.28.4.1.2
26276       7.28.4.1.2                                           LONG_MIN macro, 5.2.4.2.1, 7.22.1.4, 7.28.4.1.2
26277 llrint functions, 7.12.9.5, F.3, F.10.6.5                  longjmp function, 7.13.1.1, 7.13.2.1, 7.22.4.4,
26278 llrint type-generic macro, 7.24                                 7.22.4.7
26279 llround functions, 7.12.9.7, F.10.6.7                      loop body, 6.8.5
26280 llround type-generic macro, 7.24                           low-order bit, 3.6
26281 local time, 7.26.1                                         lowercase letter, 5.2.1
26282 locale, 3.4.2                                              lrint functions, 7.12.9.5, F.3, F.10.6.5
26283 locale-specific behavior, 3.4.2, J.4                        lrint type-generic macro, 7.24
26284 locale.h header, 7.11, 7.30.5                              lround functions, 7.12.9.7, F.10.6.7
26285 localeconv function, 7.11.1.1, 7.11.2.1                    lround type-generic macro, 7.24
26286 localization, 7.11                                         lvalue, 6.3.2.1, 6.5.1, 6.5.2.4, 6.5.3.1, 6.5.16,
26287 localtime function, 7.26.3.4                                    6.7.2.4
26288 localtime_s function, K.3.8.2.4                            lvalue conversion, 6.3.2.1, 6.5.16, 6.5.16.1,
26289 log functions, 7.12.6.7, F.10.3.7                               6.5.16.2
26290 log type-generic macro, 7.24
26291 log10 functions, 7.12.6.8, F.10.3.8                        macro argument substitution, 6.10.3.1
26292 log10 type-generic macro, 7.24                             macro definition
26293 log1p functions, 7.12.6.9, F.10.3.9                          library function, 7.1.4
26294 log1p type-generic macro, 7.24                             macro invocation, 6.10.3
26295 log2 functions, 7.12.6.10, F.10.3.10                       macro name, 6.10.3
26296 log2 type-generic macro, 7.24                                length, 5.2.4.1
26297 logarithmic functions                                        predefined, 6.10.8, 6.11.9
26298    complex, 7.3.7, G.6.3                                     redefinition, 6.10.3
26299    real, 7.12.6, F.10.3                                      scope, 6.10.3.5
26300 logb functions, 7.12.6.11, F.3, F.10.3.11                  macro parameter, 6.10.3
26301 logb type-generic macro, 7.24                              macro preprocessor, 6.10
26302 logical operators                                          macro replacement, 6.10.3
26303    AND (&&), 5.1.2.4, 6.5.13                               magnitude, complex, 7.3.8.1
26304    negation (!), 6.5.3.3                                   main function, 5.1.2.2.1, 5.1.2.2.3, 6.7.3.1, 6.7.4,
26305    OR (||), 5.1.2.4, 6.5.14                                     7.21.3
26306 logical source lines, 5.1.1.2                              malloc function, 7.22.3, 7.22.3.4, 7.22.3.5
26307 long double _Complex type, 6.2.5                           manipulation functions
26308 long double _Complex type conversion,                        complex, 7.3.9
26309
26310 [page 667]
26311
26312   real, 7.12.11, F.10.8                                    modf functions, 7.12.6.12, F.10.3.12
26313 matching failure, 7.28.2.6, 7.28.2.8, 7.28.2.10,           modifiable lvalue, 6.3.2.1
26314      K.3.9.1.7, K.3.9.1.10, K.3.9.1.12                     modification order, 5.1.2.4
26315 math.h header, 5.2.4.2.2, 6.5, 7.12, 7.24, F,              modulus functions, 7.12.6.12
26316      F.10, J.5.17                                          modulus, complex, 7.3.8.1
26317 MATH_ERREXCEPT macro, 7.12, F.10                           mtx_destroy function, 7.25.4.1
26318 math_errhandling macro, 7.1.3, 7.12, F.10                  mtx_init function, 7.25.1, 7.25.4.2
26319 MATH_ERRNO macro, 7.12                                     mtx_lock function, 7.25.4.3
26320 max_align_t type, 7.19                                     mtx_t type, 7.25.1
26321 maximum functions, 7.12.12, F.10.9                         mtx_timedlock function, 7.25.4.4
26322 MB_CUR_MAX macro, 7.1.1, 7.22, 7.22.7.2,                   mtx_trylock function, 7.25.4.5
26323      7.22.7.3, 7.27.1.2, 7.27.1.4, 7.28.6.3.3,             mtx_unlock function, 7.25.4.3, 7.25.4.4,
26324      K.3.6.4.1, K.3.9.3.1.1                                     7.25.4.5, 7.25.4.6
26325 MB_LEN_MAX macro, 5.2.4.2.1, 7.1.1, 7.22                   multibyte character, 3.7.2, 5.2.1.2, 6.4.4.4
26326 mblen function, 7.22.7.1, 7.28.6.3                         multibyte conversion functions
26327 mbrlen function, 7.28.6.3.1                                  wide character, 7.22.7, K.3.6.4
26328 mbrtoc16 function, 6.4.4.4, 6.4.5, 7.27.1.1                     extended, 7.28.6, K.3.9.3
26329 mbrtoc32 function, 6.4.4.4, 6.4.5, 7.27.1.3                     restartable, 7.27.1, 7.28.6.3, K.3.9.3.1
26330 mbrtowc function, 7.21.3, 7.21.6.1, 7.21.6.2,                wide string, 7.22.8, K.3.6.5
26331      7.28.2.1, 7.28.2.2, 7.28.6.3.1, 7.28.6.3.2,                restartable, 7.28.6.4, K.3.9.3.2
26332      7.28.6.4.1, K.3.6.5.1, K.3.9.3.2.1                    multibyte string, 7.1.1
26333 mbsinit function, 7.28.6.2.1                               multibyte/wide character conversion functions,
26334 mbsrtowcs function, 7.28.6.4.1, K.3.9.3.2                       7.22.7, K.3.6.4
26335 mbsrtowcs_s function, K.3.9.3.2, K.3.9.3.2.1                 extended, 7.28.6, K.3.9.3
26336 mbstate_t type, 7.21.2, 7.21.3, 7.21.6.1,                    restartable, 7.27.1, 7.28.6.3, K.3.9.3.1
26337      7.21.6.2, 7.27, 7.27.1, 7.28.1, 7.28.2.1,             multibyte/wide string conversion functions,
26338      7.28.2.2, 7.28.6, 7.28.6.2.1, 7.28.6.3,                    7.22.8, K.3.6.5
26339      7.28.6.3.1, 7.28.6.4                                    restartable, 7.28.6.4, K.3.9.3.2
26340 mbstowcs function, 6.4.5, 7.22.8.1, 7.28.6.4               multidimensional array, 6.5.2.1
26341 mbstowcs_s function, K.3.6.5.1                             multiplication assignment operator (*=), 6.5.16.2
26342 mbtowc function, 6.4.4.4, 7.22.7.1, 7.22.7.2,              multiplication operator (*), 6.2.6.2, 6.5.5, F.3,
26343      7.22.8.1, 7.28.6.3                                         G.5.1
26344 member access operators (. and ->), 6.5.2.3                multiplicative expressions, 6.5.5, G.5.1
26345 member alignment, 6.7.2.1
26346 memchr function, 7.23.5.1                                  n-char sequence, 7.22.1.3
26347 memcmp function, 7.23.4, 7.23.4.1                          n-wchar sequence, 7.28.4.1.1
26348 memcpy function, 7.23.2.1                                  name
26349 memcpy_s function, K.3.7.1.1                                 external, 5.2.4.1, 6.4.2.1, 6.11.3
26350 memmove function, 7.23.2.2                                   file, 7.21.3
26351 memmove_s function, K.3.7.1.2                                internal, 5.2.4.1, 6.4.2.1
26352 memory location, 3.14                                        label, 6.2.3
26353 memory management functions, 7.22.3                          structure/union member, 6.2.3
26354 memory_order type, 7.17.1, 7.17.3                          name spaces, 6.2.3
26355 memset function, 7.23.6.1, K.3.7.4.1                       named label, 6.8.1
26356 memset_s function, K.3.7.4.1                               NaN, 5.2.4.2.2
26357 minimum functions, 7.12.12, F.10.9                         nan functions, 7.12.11.2, F.2.1, F.10.8.2
26358 minus operator, unary, 6.5.3.3                             NAN macro, 7.12, F.2.1
26359 miscellaneous functions                                    NDEBUG macro, 7.2
26360   string, 7.23.6, K.3.7.4                                  nearbyint functions, 7.12.9.3, 7.12.9.4, F.3,
26361   wide string, 7.28.4.6, K.3.9.2.4                              F.10.6.3
26362 mktime function, 7.26.2.3                                  nearbyint type-generic macro, 7.24
26363
26364 [page 668]
26365
26366 nearest integer functions, 7.12.9, F.10.6                       operating system, 5.1.2.1, 7.22.4.8
26367 negation operator (!), 6.5.3.3                                  operations on files, 7.21.4, K.3.5.1
26368 negative zero, 6.2.6.2, 7.12.11.1                               operator, 6.4.6
26369 new-line character, 5.1.1.2, 5.2.1, 6.4, 6.10, 6.10.4           operators, 6.5
26370 new-line escape sequence (\n), 5.2.2, 6.4.4.4,                     additive, 6.2.6.2, 6.5.6
26371      7.4.1.10                                                      alignof, 6.5.3.4
26372 nextafter functions, 7.12.11.3, 7.12.11.4, F.3,                    assignment, 6.5.16
26373      F.10.8.3                                                      associativity, 6.5
26374 nextafter type-generic macro, 7.24                                 equality, 6.5.9
26375 nexttoward functions, 7.12.11.4, F.3, F.10.8.4                     multiplicative, 6.2.6.2, 6.5.5, G.5.1
26376 nexttoward type-generic macro, 7.24                                postfix, 6.5.2
26377 no linkage, 6.2.2                                                  precedence, 6.5
26378 no-return function, 6.7.4                                          preprocessing, 6.10.1, 6.10.3.2, 6.10.3.3, 6.10.9
26379 non-stop floating-point control mode, 7.6.4.2                       relational, 6.5.8
26380 nongraphic characters, 5.2.2, 6.4.4.4                              shift, 6.5.7
26381 nonlocal jumps header, 7.13                                        sizeof, 6.5.3.4
26382 norm, complex, 7.3.8.1                                             unary, 6.5.3
26383 normalized broken-down time, K.3.8.1, K.3.8.2.1                    unary arithmetic, 6.5.3.3
26384 not macro, 7.9                                                  optional features, see conditional features
26385 not-equal-to operator, see inequality operator                  or macro, 7.9
26386 not_eq macro, 7.9                                               OR operators
26387 null character (\0), 5.2.1, 6.4.4.4, 6.4.5                         bitwise exclusive (^), 6.2.6.2, 6.5.11
26388   padding of binary stream, 7.21.2                                 bitwise exclusive assignment (^=), 6.5.16.2
26389 NULL macro, 7.11, 7.19, 7.21.1, 7.22, 7.23.1,                      bitwise inclusive (|), 6.2.6.2, 6.5.12
26390      7.26.1, 7.28.1                                                bitwise inclusive assignment (|=), 6.5.16.2
26391 null pointer, 6.3.2.3                                              logical (||), 5.1.2.4, 6.5.14
26392 null pointer constant, 6.3.2.3                                  or_eq macro, 7.9
26393 null preprocessing directive, 6.10.7                            order of allocated storage, 7.22.3
26394 null statement, 6.8.3                                           order of evaluation, 6.5, 6.5.16, 6.10.3.2, 6.10.3.3,
26395 null wide character, 7.1.1                                            see also sequence points
26396 number classification macros, 7.12, 7.12.3.1                     ordinary identifier name space, 6.2.3
26397 numeric conversion functions, 7.8.2.3, 7.22.1                   orientation of stream, 7.21.2, 7.28.3.5
26398   wide string, 7.8.2.4, 7.28.4.1                                out-of-bounds store, L.2.1
26399 numerical limits, 5.2.4.2                                       outer scope, 6.2.1
26400                                                                 over-aligned, 6.2.8
26401 object, 3.15
26402 object representation, 6.2.6.1                                  padding
26403 object type, 6.2.5                                                binary stream, 7.21.2
26404 object-like macro, 6.10.3                                         bits, 6.2.6.2, 7.20.1.1
26405 observable behavior, 5.1.2.3                                      structure/union, 6.2.6.1, 6.7.2.1
26406 obsolescence, 6.11, 7.30                                        parameter, 3.16
26407 octal constant, 6.4.4.1                                           array, 6.9.1
26408 octal digit, 6.4.4.1, 6.4.4.4                                     ellipsis, 6.7.6.3, 6.10.3
26409 octal-character escape sequence (\octal digits),                  function, 6.5.2.2, 6.7, 6.9.1
26410      6.4.4.4                                                      macro, 6.10.3
26411 offsetof macro, 7.19                                              main function, 5.1.2.2.1
26412 on-off switch, 6.10.6                                             program, 5.1.2.2.1
26413 once_flag type, 7.25.1                                          parameter type list, 6.7.6.3
26414 ONCE_FLAG_INIT macro, 7.25.1                                    parentheses punctuator (( )), 6.7.6.3, 6.8.4, 6.8.5
26415 ones' complement, 6.2.6.2                                       parenthesized expression, 6.5.1
26416 operand, 6.4.6, 6.5                                             parse state, 7.21.2
26417
26418 [page 669]
26419
26420 perform a trap, 3.19.5                                        preprocessor, 6.10
26421 permitted form of initializer, 6.6                            PRIcFASTN macros, 7.8.1
26422 perror function, 7.21.10.4                                    PRIcLEASTN macros, 7.8.1
26423 phase angle, complex, 7.3.9.1                                 PRIcMAX macros, 7.8.1
26424 physical source lines, 5.1.1.2                                PRIcN macros, 7.8.1
26425 placemarker, 6.10.3.3                                         PRIcPTR macros, 7.8.1
26426 plus operator, unary, 6.5.3.3                                 primary expression, 6.5.1
26427 pointer arithmetic, 6.5.6                                     printf function, 7.21.1, 7.21.6.3, 7.21.6.10,
26428 pointer comparison, 6.5.8                                           K.3.5.3.3
26429 pointer declarator, 6.7.6.1                                   printf_s function, K.3.5.3.3
26430 pointer operator (->), 6.5.2.3                                printing character, 5.2.2, 7.4, 7.4.1.8
26431 pointer to function, 6.5.2.2                                  printing wide character, 7.29.2
26432 pointer type, 6.2.5                                           program diagnostics, 7.2.1
26433 pointer type conversion, 6.3.2.1, 6.3.2.3                     program execution, 5.1.2.2.2, 5.1.2.3
26434 pointer, null, 6.3.2.3                                        program file, 5.1.1.1
26435 pole error, 7.12.1, 7.12.5.3, 7.12.6.7, 7.12.6.8,             program image, 5.1.1.2
26436      7.12.6.9, 7.12.6.10, 7.12.6.11, 7.12.7.4,                program name (argv[0]), 5.1.2.2.1
26437      7.12.8.3, 7.12.8.4                                       program parameters, 5.1.2.2.1
26438 portability, 4, J                                             program startup, 5.1.2, 5.1.2.1, 5.1.2.2.1
26439 position indicator, file, see file position indicator           program structure, 5.1.1.1
26440 positive difference, 7.12.12.1                                program termination, 5.1.2, 5.1.2.1, 5.1.2.2.3,
26441 positive difference functions, 7.12.12, F.10.9                      5.1.2.3
26442 postfix decrement operator (--), 6.3.2.1, 6.5.2.4              program, conforming, 4
26443 postfix expressions, 6.5.2                                     program, strictly conforming, 4
26444 postfix increment operator (++), 6.3.2.1, 6.5.2.4              promotions
26445 pow functions, 7.12.7.4, F.10.4.4                                default argument, 6.5.2.2
26446 pow type-generic macro, 7.24                                     integer, 5.1.2.3, 6.3.1.1
26447 power functions                                               prototype, see function prototype
26448   complex, 7.3.8, G.6.4                                       pseudo-random sequence functions, 7.22.2
26449   real, 7.12.7, F.10.4                                        PTRDIFF_MAX macro, 7.20.3
26450 pp-number, 6.4.8                                              PTRDIFF_MIN macro, 7.20.3
26451 pragma operator, 6.10.9                                       ptrdiff_t type, 7.17.1, 7.19, 7.20.3, 7.21.6.1,
26452 pragma preprocessing directive, 6.10.6, 6.11.8                      7.21.6.2, 7.28.2.1, 7.28.2.2
26453 precedence of operators, 6.5                                  punctuators, 6.4.6
26454 precedence of syntax rules, 5.1.1.2                           putc function, 7.21.1, 7.21.7.7, 7.21.7.8
26455 precision, 6.2.6.2, 6.3.1.1, 7.21.6.1, 7.28.2.1               putchar function, 7.21.1, 7.21.7.8
26456   excess, 5.2.4.2.2, 6.3.1.8, 6.8.6.4                         puts function, 7.21.1, 7.21.7.9
26457 predefined macro names, 6.10.8, 6.11.9                         putwc function, 7.21.1, 7.28.3.8, 7.28.3.9
26458 prefix decrement operator (--), 6.3.2.1, 6.5.3.1               putwchar function, 7.21.1, 7.28.3.9
26459 prefix increment operator (++), 6.3.2.1, 6.5.3.1
26460 preprocessing concatenation, 6.10.3.3                         qsort function, 7.22.5, 7.22.5.2
26461 preprocessing directives, 5.1.1.2, 6.10                       qsort_s function, K.3.6.3, K.3.6.3.2
26462 preprocessing file, 5.1.1.1, 6.10                              qualified types, 6.2.5
26463 preprocessing numbers, 6.4, 6.4.8                             qualified version of type, 6.2.5
26464 preprocessing operators                                       question-mark escape sequence (\?), 6.4.4.4
26465   #, 6.10.3.2                                                 quick_exit function, 7.22.4.3, 7.22.4.4,
26466   ##, 6.10.3.3                                                     7.22.4.7
26467   _Pragma, 5.1.1.2, 6.10.9                                    quiet NaN, 5.2.4.2.2
26468   defined, 6.10.1
26469 preprocessing tokens, 5.1.1.2, 6.4, 6.10                      raise function, 7.14, 7.14.1.1, 7.14.2.1, 7.22.4.1
26470 preprocessing translation unit, 5.1.1.1                       rand function, 7.22, 7.22.2.1, 7.22.2.2
26471
26472 [page 670]
26473
26474 RAND_MAX macro, 7.22, 7.22.2.1                               restrict-qualified type, 6.2.5, 6.7.3
26475 range                                                        return statement, 6.8.6.4, F.6
26476    excess, 5.2.4.2.2, 6.3.1.8, 6.8.6.4                       rewind function, 7.21.5.3, 7.21.7.10, 7.21.9.5,
26477 range error, 7.12.1, 7.12.5.4, 7.12.5.5, 7.12.6.1,                 7.28.3.10
26478       7.12.6.2, 7.12.6.3, 7.12.6.5, 7.12.6.6,                right-shift assignment operator (>>=), 6.5.16.2
26479       7.12.6.13, 7.12.7.3, 7.12.7.4, 7.12.8.2,               right-shift operator (>>), 6.2.6.2, 6.5.7
26480       7.12.8.3, 7.12.8.4, 7.12.9.5, 7.12.9.7,                rint functions, 7.12.9.4, F.3, F.10.6.4
26481       7.12.11.3, 7.12.12.1, 7.12.13.1                        rint type-generic macro, 7.24
26482 rank, see integer conversion rank                            round functions, 7.12.9.6, F.10.6.6
26483 read-modify-write operations, 5.1.2.4                        round type-generic macro, 7.24
26484 real floating type conversion, 6.3.1.4, 6.3.1.5,              rounding mode, floating point, 5.2.4.2.2
26485       6.3.1.7, F.3, F.4                                      RSIZE_MAX macro, K.3.3, K.3.4, K.3.5.1.2,
26486 real floating types, 6.2.5                                          K.3.5.3.5, K.3.5.3.6, K.3.5.3.12, K.3.5.3.13,
26487 real type domain, 6.2.5                                            K.3.5.4.1, K.3.6.2.1, K.3.6.3.1, K.3.6.3.2,
26488 real types, 6.2.5                                                  K.3.6.4.1, K.3.6.5.1, K.3.6.5.2, K.3.7.1.1,
26489 real-floating, 7.12.3                                               K.3.7.1.2, K.3.7.1.3, K.3.7.1.4, K.3.7.2.1,
26490 realloc function, 7.22.3, 7.22.3.5                                 K.3.7.2.2, K.3.7.3.1, K.3.7.4.1, K.3.7.4.2,
26491 recommended practice, 3.17                                         K.3.8.2.1, K.3.8.2.2, K.3.9.1.3, K.3.9.1.4,
26492 recursion, 6.5.2.2                                                 K.3.9.1.8, K.3.9.1.9, K.3.9.2.1.1, K.3.9.2.1.2,
26493 recursive function call, 6.5.2.2                                   K.3.9.2.1.3, K.3.9.2.1.4, K.3.9.2.2.1,
26494 redefinition of macro, 6.10.3                                       K.3.9.2.2.2, K.3.9.2.3.1, K.3.9.3.1.1,
26495 reentrancy, 5.1.2.3, 5.2.3                                         K.3.9.3.2.1, K.3.9.3.2.2
26496    library functions, 7.1.4                                  rsize_t type, K.3.3, K.3.4, K.3.5, K.3.5.3.2,
26497 referenced type, 6.2.5                                             K.3.6, K.3.7, K.3.8, K.3.9, K.3.9.1.2
26498 register storage-class specifier, 6.7.1, 6.9                  runtime-constraint, 3.18
26499 relational expressions, 6.5.8                                Runtime-constraint handling functions, K.3.6.1
26500 relaxed atomic operations, 5.1.2.4                           rvalue, 6.3.2.1
26501 release fence, 7.17.4
26502 release operation, 5.1.2.4                                   same scope, 6.2.1
26503 release sequence, 5.1.2.4                                    save calling environment function, 7.13.1
26504 reliability of data, interrupted, 5.1.2.3                    scalar types, 6.2.5
26505 remainder assignment operator (%=), 6.5.16.2                 scalbln function, 7.12.6.13, F.3, F.10.3.13
26506 remainder functions, 7.12.10, F.10.7                         scalbln type-generic macro, 7.24
26507 remainder functions, 7.12.10.2, 7.12.10.3, F.3,              scalbn function, 7.12.6.13, F.3, F.10.3.13
26508       F.10.7.2                                               scalbn type-generic macro, 7.24
26509 remainder operator (%), 6.2.6.2, 6.5.5                       scanf function, 7.21.1, 7.21.6.4, 7.21.6.11
26510 remainder type-generic macro, 7.24                           scanf_s function, K.3.5.3.4, K.3.5.3.11
26511 remove function, 7.21.4.1, 7.21.4.4, K.3.5.1.2               scanlist, 7.21.6.2, 7.28.2.2
26512 remquo functions, 7.12.10.3, F.3, F.10.7.3                   scanset, 7.21.6.2, 7.28.2.2
26513 remquo type-generic macro, 7.24                              SCHAR_MAX macro, 5.2.4.2.1
26514 rename function, 7.21.4.2                                    SCHAR_MIN macro, 5.2.4.2.1
26515 representations of types, 6.2.6                              SCNcFASTN macros, 7.8.1
26516    pointer, 6.2.5                                            SCNcLEASTN macros, 7.8.1
26517 rescanning and replacement, 6.10.3.4                         SCNcMAX macros, 7.8.1
26518 reserved identifiers, 6.4.1, 7.1.3, K.3.1.2                   SCNcN macros, 7.8.1
26519 restartable multibyte/wide character conversion              SCNcPTR macros, 7.8.1
26520       functions, 7.27.1, 7.28.6.3, K.3.9.3.1                 scope of identifier, 6.2.1, 6.9.2
26521 restartable multibyte/wide string conversion                 search functions
26522       functions, 7.28.6.4, K.3.9.3.2                           string, 7.23.5, K.3.7.3
26523 restore calling environment function, 7.13.2                   utility, 7.22.5, K.3.6.3
26524 restrict type qualifier, 6.7.3, 6.7.3.1                         wide string, 7.28.4.5, K.3.9.2.3
26525
26526 [page 671]
26527
26528 SEEK_CUR macro, 7.21.1, 7.21.9.2                                 sign and magnitude, 6.2.6.2
26529 SEEK_END macro, 7.21.1, 7.21.9.2                                 sign bit, 6.2.6.2
26530 SEEK_SET macro, 7.21.1, 7.21.9.2                                 signal function, 7.14.1.1, 7.22.4.5, 7.22.4.7
26531 selection statements, 6.8.4                                      signal handler, 5.1.2.3, 5.2.3, 7.14.1.1, 7.14.2.1
26532 self-referential structure, 6.7.2.3                              signal handling functions, 7.14.1
26533 semicolon punctuator (;), 6.7, 6.7.2.1, 6.8.3,                   signal.h header, 7.14, 7.30.6
26534       6.8.5, 6.8.6                                               signaling NaN, 5.2.4.2.2, F.2.1
26535 separate compilation, 5.1.1.1                                    signals, 5.1.2.3, 5.2.3, 7.14.1
26536 separate translation, 5.1.1.1                                    signbit macro, 7.12.3.6, F.3
26537 sequence points, 5.1.2.3, 6.5.2.2, 6.5.13, 6.5.14,               signed char type, 6.2.5, 7.21.6.1, 7.21.6.2,
26538       6.5.15, 6.5.17, 6.7.3, 6.7.3.1, 6.7.6, 6.8,                     7.28.2.1, 7.28.2.2, K.3.5.3.2, K.3.9.1.2
26539       7.1.4, 7.21.6, 7.22.5, 7.28.2, C, K.3.6.3                  signed character, 6.3.1.1
26540 sequenced after, see sequenced before                            signed integer types, 6.2.5, 6.3.1.3, 6.4.4.1
26541 sequenced before, 5.1.2.3, 6.5, 6.5.2.2, 6.5.2.4,                signed type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,
26542       6.5.16, see also indeterminately sequenced,                     6.3.1.8
26543       unsequenced                                                signed types, 6.2.5, 6.7.2
26544 sequencing of statements, 6.8                                    significand part, 6.4.4.2
26545 set_constraint_handler_s function,                               SIGSEGV macro, 7.14, 7.14.1.1
26546       K.3.1.4, K.3.6.1.1, K.3.6.1.2, K.3.6.1.3                   SIGTERM macro, 7.14
26547 setbuf function, 7.21.3, 7.21.5.1, 7.21.5.5                      simple assignment operator (=), 6.5.16.1
26548 setjmp macro, 7.1.3, 7.13.1.1, 7.13.2.1                          sin functions, 7.12.4.6, F.10.1.6
26549 setjmp.h header, 7.13                                            sin type-generic macro, 7.24, G.7
26550 setlocale function, 7.11.1.1, 7.11.2.1                           single-byte character, 3.7.1, 5.2.1.2
26551 setvbuf function, 7.21.1, 7.21.3, 7.21.5.1,                      single-byte/wide character conversion functions,
26552       7.21.5.5, 7.21.5.6                                              7.28.6.1
26553 shall, 4                                                         single-precision arithmetic, 5.1.2.3
26554 shift expressions, 6.5.7                                         single-quote escape sequence (\'), 6.4.4.4, 6.4.5
26555 shift sequence, 7.1.1                                            singularity, 7.12.1
26556 shift states, 5.2.1.2                                            sinh functions, 7.12.5.5, F.10.2.5
26557 short identifier, character, 5.2.4.1, 6.4.3                       sinh type-generic macro, 7.24, G.7
26558 short int type, 6.2.5, 6.3.1.1, 6.7.2, 7.21.6.1,                 SIZE_MAX macro, 7.20.3
26559       7.21.6.2, 7.28.2.1, 7.28.2.2                               size_t type, 6.2.8, 6.5.3.4, 7.19, 7.20.3, 7.21.1,
26560 short int type conversion, 6.3.1.1, 6.3.1.3,                          7.21.6.1, 7.21.6.2, 7.22, 7.23.1, 7.26.1, 7.27,
26561       6.3.1.4, 6.3.1.8                                                7.28.1, 7.28.2.1, 7.28.2.2, K.3.3, K.3.4,
26562 SHRT_MAX macro, 5.2.4.2.1                                             K.3.5, K.3.6, K.3.7, K.3.8, K.3.9, K.3.9.1.2
26563 SHRT_MIN macro, 5.2.4.2.1                                        sizeof operator, 6.3.2.1, 6.5.3, 6.5.3.4
26564 side effects, 5.1.2.3, 6.2.6.1, 6.3.2.2, 6.5, 6.5.2.4,           snprintf function, 7.21.6.5, 7.21.6.12,
26565       6.5.16, 6.7.9, 6.8.3, 7.6, 7.6.1, 7.21.7.5,                     K.3.5.3.5
26566       7.21.7.7, 7.28.3.6, 7.28.3.8, F.8.1, F.9.1,                snprintf_s function, K.3.5.3.5, K.3.5.3.6
26567       F.9.3                                                      snwprintf_s function, K.3.9.1.3, K.3.9.1.4
26568 SIG_ATOMIC_MAX macro, 7.20.3                                     sorting utility functions, 7.22.5, K.3.6.3
26569 SIG_ATOMIC_MIN macro, 7.20.3                                     source character set, 5.1.1.2, 5.2.1
26570 sig_atomic_t type, 5.1.2.3, 7.14, 7.14.1.1,                      source file, 5.1.1.1
26571       7.20.3                                                        name, 6.10.4, 6.10.8.1
26572 SIG_DFL macro, 7.14, 7.14.1.1                                    source file inclusion, 6.10.2
26573 SIG_ERR macro, 7.14, 7.14.1.1                                    source lines, 5.1.1.2
26574 SIG_IGN macro, 7.14, 7.14.1.1                                    source text, 5.1.1.2
26575 SIGABRT macro, 7.14, 7.22.4.1                                    space character (' '), 5.1.1.2, 5.2.1, 6.4, 7.4.1.3,
26576 SIGFPE macro, 7.12.1, 7.14, 7.14.1.1, J.5.17                          7.4.1.10, 7.29.2.1.3
26577 SIGILL macro, 7.14, 7.14.1.1                                     sprintf function, 7.21.6.6, 7.21.6.13, K.3.5.3.6
26578 SIGINT macro, 7.14                                               sprintf_s function, K.3.5.3.5, K.3.5.3.6
26579
26580 [page 672]
26581
26582 sqrt functions, 7.12.7.5, F.3, F.10.4.5                         do, 6.8.5.2
26583 sqrt type-generic macro, 7.24                                   else, 6.8.4.1
26584 srand function, 7.22.2.2                                        expression, 6.8.3
26585 sscanf function, 7.21.6.7, 7.21.6.14                            for, 6.8.5.3
26586 sscanf_s function, K.3.5.3.7, K.3.5.3.14                        goto, 6.8.6.1
26587 standard error stream, 7.21.1, 7.21.3, 7.21.10.4                if, 6.8.4.1
26588 standard headers, 4, 7.1.2                                      iteration, 6.8.5
26589    <assert.h>, 7.2                                              jump, 6.8.6
26590    <complex.h>, 5.2.4.2.2, 6.10.8.3, 7.1.2, 7.3,                labeled, 6.8.1
26591         7.24, 7.30.1, G.6, J.5.17                               null, 6.8.3
26592    <ctype.h>, 7.4, 7.30.2                                       return, 6.8.6.4, F.6
26593    <errno.h>, 7.5, 7.30.3, K.3.2                                selection, 6.8.4
26594    <fenv.h>, 5.1.2.3, 5.2.4.2.2, 7.6, 7.12, F, H                sequencing, 6.8
26595    <float.h>, 4, 5.2.4.2.2, 7.7, 7.22.1.3,                      switch, 6.8.4.2
26596         7.28.4.1.1                                              while, 6.8.5.1
26597    <inttypes.h>, 7.8, 7.30.4                                 static assertions, 6.7.10
26598    <iso646.h>, 4, 7.9                                        static storage duration, 6.2.4
26599    <limits.h>, 4, 5.2.4.2.1, 6.2.5, 7.10                     static storage-class specifier, 6.2.2, 6.2.4, 6.7.1
26600    <locale.h>, 7.11, 7.30.5                                  static, in array declarators, 6.7.6.2, 6.7.6.3
26601    <math.h>, 5.2.4.2.2, 6.5, 7.12, 7.24, F, F.10,            static_assert declaration, 6.7.10
26602         J.5.17                                               static_assert macro, 7.2
26603    <setjmp.h>, 7.13                                          stdalign.h header, 4, 7.15
26604    <signal.h>, 7.14, 7.30.6                                  stdarg.h header, 4, 6.7.6.3, 7.16
26605    <stdalign.h>, 4, 7.15                                     stdatomic.h header, 6.10.8.3, 7.1.2, 7.17
26606    <stdarg.h>, 4, 6.7.6.3, 7.16                              stdbool.h header, 4, 7.18, 7.30.7, H
26607    <stdatomic.h>, 6.10.8.3, 7.1.2, 7.17                      STDC, 6.10.6, 6.11.8
26608    <stdbool.h>, 4, 7.18, 7.30.7, H                           stddef.h header, 4, 6.3.2.1, 6.3.2.3, 6.4.4.4,
26609    <stddef.h>, 4, 6.3.2.1, 6.3.2.3, 6.4.4.4,                       6.4.5, 6.5.3.4, 6.5.6, 7.19, K.3.3
26610         6.4.5, 6.5.3.4, 6.5.6, 7.19, K.3.3                   stderr macro, 7.21.1, 7.21.2, 7.21.3
26611    <stdint.h>, 4, 5.2.4.2, 6.10.1, 7.8, 7.20,                stdin macro, 7.21.1, 7.21.2, 7.21.3, 7.21.6.4,
26612         7.30.8, K.3.3, K.3.4                                       7.21.7.6, 7.28.2.12, 7.28.3.7, K.3.5.3.4,
26613    <stdio.h>, 5.2.4.2.2, 7.21, 7.30.9, F, K.3.5                    K.3.5.4.1, K.3.9.1.14
26614    <stdlib.h>, 5.2.4.2.2, 7.22, 7.30.10, F,                  stdint.h header, 4, 5.2.4.2, 6.10.1, 7.8, 7.20,
26615         K.3.1.4, K.3.6                                             7.30.8, K.3.3, K.3.4
26616    <string.h>, 7.23, 7.30.11, K.3.7                          stdio.h header, 5.2.4.2.2, 7.21, 7.30.9, F, K.3.5
26617    <tgmath.h>, 7.24, G.7                                     stdlib.h header, 5.2.4.2.2, 7.22, 7.30.10, F,
26618    <threads.h>, 6.10.8.3, 7.1.2, 7.25                              K.3.1.4, K.3.6
26619    <time.h>, 7.26, K.3.8                                     stdout macro, 7.21.1, 7.21.2, 7.21.3, 7.21.6.3,
26620    <uchar.h>, 6.4.4.4, 6.4.5, 7.27                                 7.21.7.8, 7.21.7.9, 7.28.2.11, 7.28.3.9
26621    <wchar.h>, 5.2.4.2.2, 7.21.1, 7.28, 7.30.12,              storage duration, 6.2.4
26622         F, K.3.9                                             storage order of array, 6.5.2.1
26623    <wctype.h>, 7.29, 7.30.13                                 storage unit (bit-field), 6.2.6.1, 6.7.2.1
26624 standard input stream, 7.21.1, 7.21.3                        storage-class specifiers, 6.7.1, 6.11.5
26625 standard integer types, 6.2.5                                strcat function, 7.23.3.1
26626 standard output stream, 7.21.1, 7.21.3                       strcat_s function, K.3.7.2.1
26627 standard signed integer types, 6.2.5                         strchr function, 7.23.5.2
26628 state-dependent encoding, 5.2.1.2, 7.22.7, K.3.6.4           strcmp function, 7.23.4, 7.23.4.2
26629 statements, 6.8                                              strcoll function, 7.11.1.1, 7.23.4.3, 7.23.4.5
26630    break, 6.8.6.3                                            strcpy function, 7.23.2.3
26631    compound, 6.8.2                                           strcpy_s function, K.3.7.1.3
26632    continue, 6.8.6.2                                         strcspn function, 7.23.5.3
26633
26634 [page 673]
26635
26636 streams, 7.21.2, 7.22.4.4                                                7.22.1.4, 7.28.2.2
26637    fully buffered, 7.21.3                                          strtoull function, 7.8.2.3, 7.22.1.2, 7.22.1.4
26638    line buffered, 7.21.3                                           strtoumax function, 7.8.2.3
26639    orientation, 7.21.2                                             struct hack, see flexible array member
26640    standard error, 7.21.1, 7.21.3                                  struct lconv, 7.11
26641    standard input, 7.21.1, 7.21.3                                  struct tm, 7.26.1
26642    standard output, 7.21.1, 7.21.3                                 structure
26643    unbuffered, 7.21.3                                                 arrow operator (->), 6.5.2.3
26644 strerror function, 7.21.10.4, 7.23.6.2                                content, 6.7.2.3
26645 strerror_s function, K.3.7.4.2, K.3.7.4.3                             dot operator (.), 6.5.2.3
26646 strerrorlen_s function, K.3.7.4.3                                     initialization, 6.7.9
26647 strftime function, 7.11.1.1, 7.26.3, 7.26.3.5,                        member alignment, 6.7.2.1
26648       7.28.5.1, K.3.8.2, K.3.8.2.1, K.3.8.2.2                         member name space, 6.2.3
26649 stricter, 6.2.8                                                       member operator (.), 6.3.2.1, 6.5.2.3
26650 strictly conforming program, 4                                        pointer operator (->), 6.5.2.3
26651 string, 7.1.1                                                         specifier, 6.7.2.1
26652    comparison functions, 7.23.4                                       tag, 6.2.3, 6.7.2.3
26653    concatenation functions, 7.23.3, K.3.7.2                           type, 6.2.5, 6.7.2.1
26654    conversion functions, 7.11.1.1                                  strxfrm function, 7.11.1.1, 7.23.4.5
26655    copying functions, 7.23.2, K.3.7.1                              subnormal floating-point numbers, 5.2.4.2.2
26656    library function conventions, 7.23.1                            subscripting, 6.5.2.1
26657    literal, 5.1.1.2, 5.2.1, 6.3.2.1, 6.4.5, 6.5.1, 6.7.9           subtraction assignment operator (-=), 6.5.16.2
26658    miscellaneous functions, 7.23.6, K.3.7.4                        subtraction operator (-), 6.2.6.2, 6.5.6, F.3, G.5.2
26659    numeric conversion functions, 7.8.2.3, 7.22.1                   suffix
26660    search functions, 7.23.5, K.3.7.3                                  floating constant, 6.4.4.2
26661 string handling header, 7.23, K.3.7                                   integer constant, 6.4.4.1
26662 string.h header, 7.23, 7.30.11, K.3.7                              switch body, 6.8.4.2
26663 stringizing, 6.10.3.2, 6.10.9                                      switch case label, 6.8.1, 6.8.4.2
26664 strlen function, 7.23.6.3                                          switch default label, 6.8.1, 6.8.4.2
26665 strncat function, 7.23.3.2                                         switch statement, 6.8.1, 6.8.4.2
26666 strncat_s function, K.3.7.2.2                                      swprintf function, 7.28.2.3, 7.28.2.7,
26667 strncmp function, 7.23.4, 7.23.4.4                                       K.3.9.1.3, K.3.9.1.4
26668 strncpy function, 7.23.2.4                                         swprintf_s function, K.3.9.1.3, K.3.9.1.4
26669 strncpy_s function, K.3.7.1.4                                      swscanf function, 7.28.2.4, 7.28.2.8
26670 strnlen_s function, K.3.7.4.4                                      swscanf_s function, K.3.9.1.5, K.3.9.1.10
26671 stronger, 6.2.8                                                    symbols, 3
26672 strpbrk function, 7.23.5.4                                         synchronization operation, 5.1.2.4
26673 strrchr function, 7.23.5.5                                         synchronize with, 5.1.2.4
26674 strspn function, 7.23.5.6                                          syntactic categories, 6.1
26675 strstr function, 7.23.5.7                                          syntax notation, 6.1
26676 strtod function, 7.12.11.2, 7.21.6.2, 7.22.1.3,                    syntax rule precedence, 5.1.1.2
26677       7.28.2.2, F.3                                                syntax summary, language, A
26678 strtof function, 7.12.11.2, 7.22.1.3, F.3                          system function, 7.22.4.8
26679 strtoimax function, 7.8.2.3
26680 strtok function, 7.23.5.8                                          tab characters, 5.2.1, 6.4
26681 strtok_s function, K.3.7.3.1                                       tag compatibility, 6.2.7
26682 strtol function, 7.8.2.3, 7.21.6.2, 7.22.1.2,                      tag name space, 6.2.3
26683       7.22.1.4, 7.28.2.2                                           tags, 6.7.2.3
26684 strtold function, 7.12.11.2, 7.22.1.3, F.3                         tan functions, 7.12.4.7, F.10.1.7
26685 strtoll function, 7.8.2.3, 7.22.1.2, 7.22.1.4                      tan type-generic macro, 7.24, G.7
26686 strtoul function, 7.8.2.3, 7.21.6.2, 7.22.1.2,                     tanh functions, 7.12.5.6, F.10.2.6
26687
26688 [page 674]
26689
26690 tanh type-generic macro, 7.24, G.7                            toupper function, 7.4.2.2
26691 temporary lifetime, 6.2.4                                     towctrans function, 7.29.3.2.1, 7.29.3.2.2
26692 tentative definition, 6.9.2                                    towlower function, 7.29.3.1.1, 7.29.3.2.1
26693 terms, 3                                                      towupper function, 7.29.3.1.2, 7.29.3.2.1
26694 text streams, 7.21.2, 7.21.7.10, 7.21.9.2, 7.21.9.4           translation environment, 5, 5.1.1
26695 tgamma functions, 7.12.8.4, F.10.5.4                          translation limits, 5.2.4.1
26696 tgamma type-generic macro, 7.24                               translation phases, 5.1.1.2
26697 tgmath.h header, 7.24, G.7                                    translation unit, 5.1.1.1, 6.9
26698 thrd_create function, 7.25.1, 7.25.5.1                        trap, see perform a trap
26699 thrd_current function, 7.25.5.2                               trap representation, 3.19.4, 6.2.6.1, 6.2.6.2,
26700 thrd_detach function, 7.25.5.3                                      6.3.2.3, 6.5.2.3
26701 thrd_equal function, 7.25.5.4                                 trigonometric functions
26702 thrd_exit function, 7.25.5.5                                     complex, 7.3.5, G.6.1
26703 thrd_join function, 7.25.5.6                                     real, 7.12.4, F.10.1
26704 thrd_sleep function, 7.25.5.7                                 trigraph sequences, 5.1.1.2, 5.2.1.1
26705 thrd_start_t type, 7.25.1                                     true macro, 7.18
26706 thrd_t type, 7.25.1                                           trunc functions, 7.12.9.8, F.10.6.8
26707 thrd_yield function, 7.25.5.8                                 trunc type-generic macro, 7.24
26708 thread of execution, 5.1.2.4, 7.1.4, 7.6, 7.22.4.6            truncation, 6.3.1.4, 7.12.9.8, 7.21.3, 7.21.5.3
26709 thread storage duration, 6.2.4, 7.6                           truncation toward zero, 6.5.5
26710 threads header, 7.25                                          tss_create function, 7.25.6.1
26711 threads.h header, 6.10.8.3, 7.1.2, 7.25                       tss_delete function, 7.25.6.2
26712 time                                                          TSS_DTOR_ITERATIONS macro, 7.25.1
26713    broken down, 7.26.1, 7.26.2.3, 7.26.3, 7.26.3.1,           tss_dtor_t type, 7.25.1
26714          7.26.3.3, 7.26.3.4, 7.26.3.5, K.3.8.2.1,             tss_get function, 7.25.6.3
26715          K.3.8.2.3, K.3.8.2.4                                 tss_set function, 7.25.6.4
26716    calendar, 7.26.1, 7.26.2.2, 7.26.2.3, 7.26.2.4,            tss_t type, 7.25.1
26717          7.26.3.2, 7.26.3.3, 7.26.3.4, K.3.8.2.2,             two's complement, 6.2.6.2, 7.20.1.1
26718          K.3.8.2.3, K.3.8.2.4                                 type category, 6.2.5
26719    components, 7.26.1, K.3.8.1                                type conversion, 6.3
26720    conversion functions, 7.26.3, K.3.8.2                      type definitions, 6.7.8
26721       wide character, 7.28.5                                  type domain, 6.2.5, G.2
26722    local, 7.26.1                                              type names, 6.7.7
26723    manipulation functions, 7.26.2                             type punning, 6.5.2.3
26724    normalized broken down, K.3.8.1, K.3.8.2.1                 type qualifiers, 6.7.3
26725 time function, 7.26.2.4                                       type specifiers, 6.7.2
26726 time.h header, 7.26, K.3.8                                    type-generic macro, 7.24, G.7
26727 time_t type, 7.26.1                                           typedef declaration, 6.7.8
26728 TIME_UTC macro, 7.25.7.1                                      typedef storage-class specifier, 6.7.1, 6.7.8
26729 tm structure type, 7.26.1, 7.28.1, K.3.8.1                    types, 6.2.5
26730 TMP_MAX macro, 7.21.1, 7.21.4.3, 7.21.4.4                        atomic, 5.1.2.3, 6.2.5, 6.2.6.1, 6.3.2.1, 6.5.2.3,
26731 TMP_MAX_S macro, K.3.5, K.3.5.1.1, K.3.5.1.2                           6.5.2.4, 6.5.16.2, 6.7.2.4, 6.10.8.3, 7.17.6
26732 tmpfile function, 7.21.4.3, 7.22.4.4                             character, 6.7.9
26733 tmpfile_s function, K.3.5.1.1, K.3.5.1.2                         compatible, 6.2.7, 6.7.2, 6.7.3, 6.7.6
26734 tmpnam function, 7.21.1, 7.21.4.3, 7.21.4.4,                     complex, 6.2.5, G
26735       K.3.5.1.2                                                  composite, 6.2.7
26736 tmpnam_s function, K.3.5, K.3.5.1.1, K.3.5.1.2                   const qualified, 6.7.3
26737 token, 5.1.1.2, 6.4, see also preprocessing tokens               conversions, 6.3
26738 token concatenation, 6.10.3.3                                    imaginary, G
26739 token pasting, 6.10.3.3                                          restrict qualified, 6.7.3
26740 tolower function, 7.4.2.1                                        volatile qualified, 6.7.3
26741
26742 [page 675]
26743
26744 uchar.h header, 6.4.4.4, 6.4.5, 7.27                      universal character name, 6.4.3
26745 UCHAR_MAX macro, 5.2.4.2.1                                unnormalized floating-point numbers, 5.2.4.2.2
26746 UINT_FASTN_MAX macros, 7.20.2.3                           unqualified type, 6.2.5
26747 uint_fastN_t types, 7.20.1.3                              unqualified version of type, 6.2.5
26748 uint_least16_t type, 7.27                                 unsequenced, 5.1.2.3, 6.5, 6.5.16, see also
26749 uint_least32_t type, 7.27                                       indeterminately sequenced, sequenced
26750 UINT_LEASTN_MAX macros, 7.20.2.2                                before
26751 uint_leastN_t types, 7.20.1.2                             unsigned char type, K.3.5.3.2, K.3.9.1.2
26752 UINT_MAX macro, 5.2.4.2.1                                 unsigned integer suffix, u or U, 6.4.4.1
26753 UINTMAX_C macro, 7.20.4.2                                 unsigned integer types, 6.2.5, 6.3.1.3, 6.4.4.1
26754 UINTMAX_MAX macro, 7.8.2.3, 7.8.2.4, 7.20.2.5             unsigned type conversion, 6.3.1.1, 6.3.1.3,
26755 uintmax_t type, 7.20.1.5, 7.21.6.1, 7.21.6.2,                   6.3.1.4, 6.3.1.8
26756      7.28.2.1, 7.28.2.2                                   unsigned types, 6.2.5, 6.7.2, 7.21.6.1, 7.21.6.2,
26757 UINTN_C macros, 7.20.4.1                                        7.28.2.1, 7.28.2.2
26758 UINTN_MAX macros, 7.20.2.1                                unspecified behavior, 3.4.4, 4, J.1
26759 uintN_t types, 7.20.1.1                                   unspecified value, 3.19.3
26760 UINTPTR_MAX macro, 7.20.2.4                               uppercase letter, 5.2.1
26761 uintptr_t type, 7.20.1.4                                  use of library functions, 7.1.4
26762 ULLONG_MAX macro, 5.2.4.2.1, 7.22.1.4,                    USHRT_MAX macro, 5.2.4.2.1
26763      7.28.4.1.2                                           usual arithmetic conversions, 6.3.1.8, 6.5.5, 6.5.6,
26764 ULONG_MAX macro, 5.2.4.2.1, 7.22.1.4,                           6.5.8, 6.5.9, 6.5.10, 6.5.11, 6.5.12, 6.5.15
26765      7.28.4.1.2                                           UTF-16, 6.10.8.2
26766 unary arithmetic operators, 6.5.3.3                       UTF-32, 6.10.8.2
26767 unary expression, 6.5.3                                   UTF-8 string literal, see string literal
26768 unary minus operator (-), 6.5.3.3, F.3                    utilities, general, 7.22, K.3.6
26769 unary operators, 6.5.3                                       wide string, 7.28.4, K.3.9.2
26770 unary plus operator (+), 6.5.3.3
26771 unbuffered stream, 7.21.3                                 va_arg macro, 7.16, 7.16.1, 7.16.1.1, 7.16.1.2,
26772 undef preprocessing directive, 6.10.3.5, 7.1.3,                7.16.1.4, 7.21.6.8, 7.21.6.9, 7.21.6.10,
26773      7.1.4                                                     7.21.6.11, 7.21.6.12, 7.21.6.13, 7.21.6.14,
26774 undefined behavior, 3.4.3, 4, J.2                               7.28.2.5, 7.28.2.6, 7.28.2.7, 7.28.2.8,
26775 underscore character, 6.4.2.1                                  7.28.2.9, 7.28.2.10, K.3.5.3.9, K.3.5.3.11,
26776 underscore, leading, in identifier, 7.1.3                       K.3.5.3.14, K.3.9.1.7, K.3.9.1.10, K.3.9.1.12
26777 ungetc function, 7.21.1, 7.21.7.10, 7.21.9.2,             va_copy macro, 7.1.3, 7.16, 7.16.1, 7.16.1.1,
26778      7.21.9.3                                                  7.16.1.2, 7.16.1.3
26779 ungetwc function, 7.21.1, 7.28.3.10                       va_end macro, 7.1.3, 7.16, 7.16.1, 7.16.1.3,
26780 Unicode, 7.27, see also char16_t type,                         7.16.1.4, 7.21.6.8, 7.21.6.9, 7.21.6.10,
26781      char32_t type, wchar_t type                               7.21.6.11, 7.21.6.12, 7.21.6.13, 7.21.6.14,
26782 Unicode required set, 6.10.8.2                                 7.28.2.5, 7.28.2.6, 7.28.2.7, 7.28.2.8,
26783 union                                                          7.28.2.9, 7.28.2.10, K.3.5.3.9, K.3.5.3.11,
26784   arrow operator (->), 6.5.2.3                                 K.3.5.3.14, K.3.9.1.7, K.3.9.1.10, K.3.9.1.12
26785   content, 6.7.2.3                                        va_list type, 7.16, 7.16.1.3
26786   dot operator (.), 6.5.2.3                               va_start macro, 7.16, 7.16.1, 7.16.1.1,
26787   initialization, 6.7.9                                        7.16.1.2, 7.16.1.3, 7.16.1.4, 7.21.6.8,
26788   member alignment, 6.7.2.1                                    7.21.6.9, 7.21.6.10, 7.21.6.11, 7.21.6.12,
26789   member name space, 6.2.3                                     7.21.6.13, 7.21.6.14, 7.28.2.5, 7.28.2.6,
26790   member operator (.), 6.3.2.1, 6.5.2.3                        7.28.2.7, 7.28.2.8, 7.28.2.9, 7.28.2.10,
26791   pointer operator (->), 6.5.2.3                               K.3.5.3.9, K.3.5.3.11, K.3.5.3.14, K.3.9.1.7,
26792   specifier, 6.7.2.1                                            K.3.9.1.10, K.3.9.1.12
26793   tag, 6.2.3, 6.7.2.3                                     value, 3.19
26794   type, 6.2.5, 6.7.2.1                                    value bits, 6.2.6.2
26795
26796 [page 676]
26797
26798 variable arguments, 6.10.3, 7.16                             vswscanf function, 7.28.2.8
26799 variable arguments header, 7.16                              vswscanf_s function, K.3.9.1.10
26800 variable length array, 6.7.6, 6.7.6.2, 6.10.8.3              vwprintf function, 7.21.1, 7.28.2.9, K.3.9.1.11
26801 variably modified type, 6.7.6, 6.7.6.2, 6.10.8.3              vwprintf_s function, K.3.9.1.11
26802 vertical-tab character, 5.2.1, 6.4                           vwscanf function, 7.21.1, 7.28.2.10, 7.28.3.10
26803 vertical-tab escape sequence (\v), 5.2.2, 6.4.4.4,           vwscanf_s function, K.3.9.1.12
26804      7.4.1.10
26805 vfprintf function, 7.21.1, 7.21.6.8, K.3.5.3.8               warnings, I
26806 vfprintf_s function, K.3.5.3.8, K.3.5.3.9,                   wchar.h header, 5.2.4.2.2, 7.21.1, 7.28, 7.30.12,
26807      K.3.5.3.11, K.3.5.3.14                                      F, K.3.9
26808 vfscanf function, 7.21.1, 7.21.6.8, 7.21.6.9                 WCHAR_MAX macro, 7.20.3, 7.28.1
26809 vfscanf_s function, K.3.5.3.9, K.3.5.3.11,                   WCHAR_MIN macro, 7.20.3, 7.28.1
26810      K.3.5.3.14                                              wchar_t type, 3.7.3, 6.4.5, 6.7.9, 6.10.8.2, 7.19,
26811 vfwprintf function, 7.21.1, 7.28.2.5, K.3.9.1.6                  7.20.3, 7.21.6.1, 7.21.6.2, 7.22, 7.28.1,
26812 vfwprintf_s function, K.3.9.1.6                                  7.28.2.1, 7.28.2.2
26813 vfwscanf function, 7.21.1, 7.28.2.6, 7.28.3.10               wcrtomb function, 7.21.3, 7.21.6.2, 7.28.2.2,
26814 vfwscanf_s function, K.3.9.1.7                                   7.28.6.3.3, 7.28.6.4.2, K.3.6.5.2, K.3.9.3.1,
26815 visibility of identifier, 6.2.1                                   K.3.9.3.2.2
26816 visible sequence of side effects, 5.1.2.4                    wcrtomb_s function, K.3.9.3.1, K.3.9.3.1.1
26817 visible side effect, 5.1.2.4                                 wcscat function, 7.28.4.3.1
26818 VLA, see variable length array                               wcscat_s function, K.3.9.2.2.1
26819 void expression, 6.3.2.2                                     wcschr function, 7.28.4.5.1
26820 void function parameter, 6.7.6.3                             wcscmp function, 7.28.4.4.1, 7.28.4.4.4
26821 void type, 6.2.5, 6.3.2.2, 6.7.2, K.3.5.3.2,                 wcscoll function, 7.28.4.4.2, 7.28.4.4.4
26822      K.3.9.1.2                                               wcscpy function, 7.28.4.2.1
26823 void type conversion, 6.3.2.2                                wcscpy_s function, K.3.9.2.1.1
26824 volatile storage, 5.1.2.3                                    wcscspn function, 7.28.4.5.2
26825 volatile type qualifier, 6.7.3                                wcsftime function, 7.11.1.1, 7.28.5.1
26826 volatile-qualified type, 6.2.5, 6.7.3                         wcslen function, 7.28.4.6.1
26827 vprintf function, 7.21.1, 7.21.6.8, 7.21.6.10,               wcsncat function, 7.28.4.3.2
26828      K.3.5.3.10                                              wcsncat_s function, K.3.9.2.2.2
26829 vprintf_s function, K.3.5.3.9, K.3.5.3.10,                   wcsncmp function, 7.28.4.4.3
26830      K.3.5.3.11, K.3.5.3.14                                  wcsncpy function, 7.28.4.2.2
26831 vscanf function, 7.21.1, 7.21.6.8, 7.21.6.11                 wcsncpy_s function, K.3.9.2.1.2
26832 vscanf_s function, K.3.5.3.9, K.3.5.3.11,                    wcsnlen_s function, K.3.9.2.4.1
26833      K.3.5.3.14                                              wcspbrk function, 7.28.4.5.3
26834 vsnprintf function, 7.21.6.8, 7.21.6.12,                     wcsrchr function, 7.28.4.5.4
26835      K.3.5.3.12                                              wcsrtombs function, 7.28.6.4.2, K.3.9.3.2
26836 vsnprintf_s function, K.3.5.3.9, K.3.5.3.11,                 wcsrtombs_s function, K.3.9.3.2, K.3.9.3.2.2
26837      K.3.5.3.12, K.3.5.3.13, K.3.5.3.14                      wcsspn function, 7.28.4.5.5
26838 vsnwprintf_s function, K.3.9.1.8, K.3.9.1.9                  wcsstr function, 7.28.4.5.6
26839 vsprintf function, 7.21.6.8, 7.21.6.13,                      wcstod function, 7.21.6.2, 7.28.2.2
26840      K.3.5.3.13                                              wcstod function, 7.28.4.1.1
26841 vsprintf_s function, K.3.5.3.9, K.3.5.3.11,                  wcstof function, 7.28.4.1.1
26842      K.3.5.3.12, K.3.5.3.13, K.3.5.3.14                      wcstoimax function, 7.8.2.4
26843 vsscanf function, 7.21.6.8, 7.21.6.14                        wcstok function, 7.28.4.5.7
26844 vsscanf_s function, K.3.5.3.9, K.3.5.3.11,                   wcstok_s function, K.3.9.2.3.1
26845      K.3.5.3.14                                              wcstol function, 7.8.2.4, 7.21.6.2, 7.28.2.2,
26846 vswprintf function, 7.28.2.7, K.3.9.1.8,                         7.28.4.1.2
26847      K.3.9.1.9                                               wcstold function, 7.28.4.1.1
26848 vswprintf_s function, K.3.9.1.8, K.3.9.1.9                   wcstoll function, 7.8.2.4, 7.28.4.1.2
26849
26850 [page 677]
26851
26852 wcstombs function, 7.22.8.2, 7.28.6.4                           7.29.1
26853 wcstombs_s function, K.3.6.5.2                               wmemchr function, 7.28.4.5.8
26854 wcstoul function, 7.8.2.4, 7.21.6.2, 7.28.2.2,               wmemcmp function, 7.28.4.4.5
26855      7.28.4.1.2                                              wmemcpy function, 7.28.4.2.3
26856 wcstoull function, 7.8.2.4, 7.28.4.1.2                       wmemcpy_s function, K.3.9.2.1.3
26857 wcstoumax function, 7.8.2.4                                  wmemmove function, 7.28.4.2.4
26858 wcsxfrm function, 7.28.4.4.4                                 wmemmove_s function, K.3.9.2.1.4
26859 wctob function, 7.28.6.1.2, 7.29.2.1                         wmemset function, 7.28.4.6.2
26860 wctomb function, 7.22.7.3, 7.22.8.2, 7.28.6.3                wprintf function, 7.21.1, 7.28.2.9, 7.28.2.11,
26861 wctomb_s function, K.3.6.4.1                                    K.3.9.1.13
26862 wctrans function, 7.29.3.2.1, 7.29.3.2.2                     wprintf_s function, K.3.9.1.13
26863 wctrans_t type, 7.29.1, 7.29.3.2.2                           wscanf function, 7.21.1, 7.28.2.10, 7.28.2.12,
26864 wctype function, 7.29.2.2.1, 7.29.2.2.2                         7.28.3.10
26865 wctype.h header, 7.29, 7.30.13                               wscanf_s function, K.3.9.1.12, K.3.9.1.14
26866 wctype_t type, 7.29.1, 7.29.2.2.2
26867 weaker, 6.2.8                                                xor macro, 7.9
26868 WEOF macro, 7.28.1, 7.28.3.1, 7.28.3.3, 7.28.3.6,            xor_eq macro, 7.9
26869      7.28.3.7, 7.28.3.8, 7.28.3.9, 7.28.3.10,                xtime type, 7.25.1, 7.25.3.5, 7.25.4.4, 7.25.5.7,
26870      7.28.6.1.1, 7.29.1                                          7.25.7.1
26871 while statement, 6.8.5.1                                     xtime_get function, 7.25.7.1
26872 white space, 5.1.1.2, 6.4, 6.10, 7.4.1.10,
26873      7.29.2.1.10
26874 white-space characters, 6.4
26875 wide character, 3.7.3
26876   case mapping functions, 7.29.3.1
26877      extensible, 7.29.3.2
26878   classification functions, 7.29.2.1
26879      extensible, 7.29.2.2
26880   constant, 6.4.4.4
26881   formatted input/output functions, 7.28.2,
26882         K.3.9.1
26883   input functions, 7.21.1
26884   input/output functions, 7.21.1, 7.28.3
26885   output functions, 7.21.1
26886   single-byte conversion functions, 7.28.6.1
26887 wide string, 7.1.1
26888 wide string comparison functions, 7.28.4.4
26889 wide string concatenation functions, 7.28.4.3,
26890      K.3.9.2.2
26891 wide string copying functions, 7.28.4.2, K.3.9.2.1
26892 wide string literal, see string literal
26893 wide string miscellaneous functions, 7.28.4.6,
26894      K.3.9.2.4
26895 wide string numeric conversion functions, 7.8.2.4,
26896      7.28.4.1
26897 wide string search functions, 7.28.4.5, K.3.9.2.3
26898 wide-oriented stream, 7.21.2
26899 width, 6.2.6.2
26900 WINT_MAX macro, 7.20.3
26901 WINT_MIN macro, 7.20.3
26902 wint_t type, 7.20.3, 7.21.6.1, 7.28.1, 7.28.2.1,
26903
26904 [page 678]