fix page links
[c-standard] / n1516.txt
1 N1516                     Committee Draft -- October 4, 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 (N1494) 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 . . . . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   119
115           6.7.4   Function specifiers     . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   123
116           6.7.5   Alignment specifier . . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   125
117           6.7.6   Declarators     . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   126
118           6.7.7   Type names . . . . . . .         .   .   .   .   .   .   .   .   .   .   .   .   .   .   134
119           6.7.8   Type definitions      . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   135
120           6.7.9   Initialization    . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   137
121           6.7.10 Static assertions     . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   143
122      6.8 Statements and blocks      . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   144
123           6.8.1   Labeled statements     . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   144
124           6.8.2   Compound statement       . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   145
125           6.8.3   Expression and null statements       .   .   .   .   .   .   .   .   .   .   .   .   .   145
126           6.8.4   Selection statements     . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   146
127           6.8.5   Iteration statements . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   148
128           6.8.6   Jump statements      . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   149
129      6.9 External definitions      . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   153
130           6.9.1   Function definitions . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   154
131           6.9.2   External object definitions   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   156
132      6.10 Preprocessing directives     . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   158
133           6.10.1 Conditional inclusion     . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   160
134           6.10.2 Source file inclusion      . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   162
135           6.10.3 Macro replacement . . . .         .   .   .   .   .   .   .   .   .   .   .   .   .   .   164
136
137
138 [page iv]
139
140        6.10.4 Line control . . . . . .        .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   171
141        6.10.5 Error directive . . . . .       .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   172
142        6.10.6 Pragma directive . . . .        .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   172
143        6.10.7 Null directive      . . . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   173
144        6.10.8 Predefined macro names .         .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   173
145        6.10.9 Pragma operator       . . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   175
146   6.11 Future language directions     . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   177
147        6.11.1 Floating types      . . . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   177
148        6.11.2 Linkages of identifiers . .      .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   177
149        6.11.3 External names        . . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   177
150        6.11.4 Character escape sequences          .   .   .   .   .   .   .   .    .   .   .   .   .   .   177
151        6.11.5 Storage-class specifiers     .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   177
152        6.11.6 Function declarators      . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   177
153        6.11.7 Function definitions . . .       .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   177
154        6.11.8 Pragma directives       . . .   .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   177
155        6.11.9 Predefined macro names .         .   .   .   .   .   .   .   .   .    .   .   .   .   .   .   177
156 7. Library . . . . . . . . . . . . . . . . . .                .   .   .   .   .    .   .   .   .   .   .   178
157    7.1 Introduction     . . . . . . . . . . . . .             .   .   .   .   .    .   .   .   .   .   .   178
158          7.1.1 Definitions of terms . . . . . . .              .   .   .   .   .    .   .   .   .   .   .   178
159          7.1.2 Standard headers . . . . . . . .               .   .   .   .   .    .   .   .   .   .   .   179
160          7.1.3 Reserved identifiers . . . . . . .              .   .   .   .   .    .   .   .   .   .   .   180
161          7.1.4 Use of library functions    . . . . .          .   .   .   .   .    .   .   .   .   .   .   181
162    7.2 Diagnostics <assert.h>          . . . . . . .          .   .   .   .   .    .   .   .   .   .   .   184
163          7.2.1 Program diagnostics       . . . . . .          .   .   .   .   .    .   .   .   .   .   .   184
164    7.3 Complex arithmetic <complex.h>           . . .         .   .   .   .   .    .   .   .   .   .   .   186
165          7.3.1 Introduction . . . . . . . . . .               .   .   .   .   .    .   .   .   .   .   .   186
166          7.3.2 Conventions . . . . . . . . . .                .   .   .   .   .    .   .   .   .   .   .   187
167          7.3.3 Branch cuts . . . . . . . . . .                .   .   .   .   .    .   .   .   .   .   .   187
168          7.3.4 The CX_LIMITED_RANGE pragma                    .   .   .   .   .    .   .   .   .   .   .   187
169          7.3.5 Trigonometric functions . . . . .              .   .   .   .   .    .   .   .   .   .   .   188
170          7.3.6 Hyperbolic functions      . . . . . .          .   .   .   .   .    .   .   .   .   .   .   190
171          7.3.7 Exponential and logarithmic functions              .   .   .   .    .   .   .   .   .   .   192
172          7.3.8 Power and absolute-value functions             .   .   .   .   .    .   .   .   .   .   .   193
173          7.3.9 Manipulation functions      . . . . .          .   .   .   .   .    .   .   .   .   .   .   194
174    7.4 Character handling <ctype.h> . . . . .                 .   .   .   .   .    .   .   .   .   .   .   198
175          7.4.1 Character classification functions    .         .   .   .   .   .    .   .   .   .   .   .   198
176          7.4.2 Character case mapping functions     .         .   .   .   .   .    .   .   .   .   .   .   201
177    7.5 Errors <errno.h>         . . . . . . . . . .           .   .   .   .   .    .   .   .   .   .   .   203
178    7.6 Floating-point environment <fenv.h>        . .         .   .   .   .   .    .   .   .   .   .   .   204
179          7.6.1 The FENV_ACCESS pragma           . . .         .   .   .   .   .    .   .   .   .   .   .   206
180          7.6.2 Floating-point exceptions      . . . .         .   .   .   .   .    .   .   .   .   .   .   207
181          7.6.3 Rounding . . . . . . . . . . .                 .   .   .   .   .    .   .   .   .   .   .   210
182          7.6.4 Environment        . . . . . . . . .           .   .   .   .   .    .   .   .   .   .   .   211
183    7.7 Characteristics of floating types <float.h>             .   .   .   .   .    .   .   .   .   .   .   214
184
185 [page v]
186
187      7.8    Format conversion of integer types <inttypes.h> . . . .           .   .   .   .   215
188             7.8.1    Macros for format specifiers      . . . . . . . . . .     .   .   .   .   215
189             7.8.2    Functions for greatest-width integer types   . . . . .   .   .   .   .   216
190      7.9    Alternative spellings <iso646.h> . . . . . . . . . . .            .   .   .   .   219
191      7.10   Sizes of integer types <limits.h>         . . . . . . . . . .     .   .   .   .   220
192      7.11   Localization <locale.h> . . . . . . . . . . . . . .               .   .   .   .   221
193             7.11.1 Locale control . . . . . . . . . . . . . . . .             .   .   .   .   222
194             7.11.2 Numeric formatting convention inquiry . . . . . .          .   .   .   .   223
195      7.12   Mathematics <math.h> . . . . . . . . . . . . . . .                .   .   .   .   229
196             7.12.1 Treatment of error conditions . . . . . . . . . .          .   .   .   .   231
197             7.12.2 The FP_CONTRACT pragma             . . . . . . . . . .     .   .   .   .   233
198             7.12.3 Classification macros       . . . . . . . . . . . . .       .   .   .   .   233
199             7.12.4 Trigonometric functions . . . . . . . . . . . .            .   .   .   .   236
200             7.12.5 Hyperbolic functions       . . . . . . . . . . . . .       .   .   .   .   238
201             7.12.6 Exponential and logarithmic functions        . . . . . .   .   .   .   .   240
202             7.12.7 Power and absolute-value functions         . . . . . . .   .   .   .   .   245
203             7.12.8 Error and gamma functions . . . . . . . . . . .            .   .   .   .   247
204             7.12.9 Nearest integer functions . . . . . . . . . . . .          .   .   .   .   249
205             7.12.10 Remainder functions       . . . . . . . . . . . . .       .   .   .   .   252
206             7.12.11 Manipulation functions       . . . . . . . . . . . .      .   .   .   .   253
207             7.12.12 Maximum, minimum, and positive difference functions           .   .   .   255
208             7.12.13 Floating multiply-add . . . . . . . . . . . . .           .   .   .   .   256
209             7.12.14 Comparison macros . . . . . . . . . . . . . .             .   .   .   .   257
210      7.13   Nonlocal jumps <setjmp.h>            . . . . . . . . . . . .      .   .   .   .   260
211             7.13.1 Save calling environment         . . . . . . . . . . .     .   .   .   .   260
212             7.13.2 Restore calling environment        . . . . . . . . . .     .   .   .   .   261
213      7.14   Signal handling <signal.h> . . . . . . . . . . . . .              .   .   .   .   263
214             7.14.1 Specify signal handling       . . . . . . . . . . . .      .   .   .   .   264
215             7.14.2 Send signal      . . . . . . . . . . . . . . . . .         .   .   .   .   265
216      7.15   Alignment <stdalign.h>            . . . . . . . . . . . . .       .   .   .   .   266
217      7.16   Variable arguments <stdarg.h>           . . . . . . . . . . .     .   .   .   .   267
218             7.16.1 Variable argument list access macros . . . . . . .         .   .   .   .   267
219      7.17   Atomics <stdatomic.h> . . . . . . . . . . . . . .                 .   .   .   .   271
220             7.17.1 Introduction . . . . . . . . . . . . . . . . .             .   .   .   .   271
221             7.17.2 Initialization      . . . . . . . . . . . . . . . .        .   .   .   .   272
222             7.17.3 Order and consistency . . . . . . . . . . . . .            .   .   .   .   273
223             7.17.4 Fences . . . . . . . . . . . . . . . . . . .               .   .   .   .   276
224             7.17.5 Lock-free property       . . . . . . . . . . . . . .       .   .   .   .   277
225             7.17.6 Atomic integer and address types         . . . . . . . .   .   .   .   .   278
226             7.17.7 Operations on atomic types . . . . . . . . . . .           .   .   .   .   280
227             7.17.8 Atomic flag type and operations . . . . . . . . .           .   .   .   .   283
228      7.18   Boolean type and values <stdbool.h>             . . . . . . . .   .   .   .   .   285
229      7.19   Common definitions <stddef.h> . . . . . . . . . . .                .   .   .   .   286
230      7.20   Integer types <stdint.h> . . . . . . . . . . . . . .              .   .   .   .   288
231
232
233 [page vi]
234
235          7.20.1 Integer types      . . . . . . . . . . . .      .   .    .   .   .   .   .   .   288
236          7.20.2 Limits of specified-width integer types    . .   .   .    .   .   .   .   .   .   290
237          7.20.3 Limits of other integer types    . . . . . .    .   .    .   .   .   .   .   .   292
238          7.20.4 Macros for integer constants     . . . . . .    .   .    .   .   .   .   .   .   293
239   7.21   Input/output <stdio.h>         . . . . . . . . . .     .   .    .   .   .   .   .   .   295
240          7.21.1 Introduction . . . . . . . . . . . . .          .   .    .   .   .   .   .   .   295
241          7.21.2 Streams       . . . . . . . . . . . . . .       .   .    .   .   .   .   .   .   297
242          7.21.3 Files . . . . . . . . . . . . . . . .           .   .    .   .   .   .   .   .   299
243          7.21.4 Operations on files      . . . . . . . . . .     .   .    .   .   .   .   .   .   301
244          7.21.5 File access functions     . . . . . . . . .     .   .    .   .   .   .   .   .   303
245          7.21.6 Formatted input/output functions     . . . .    .   .    .   .   .   .   .   .   308
246          7.21.7 Character input/output functions . . . . .      .   .    .   .   .   .   .   .   329
247          7.21.8 Direct input/output functions    . . . . . .    .   .    .   .   .   .   .   .   333
248          7.21.9 File positioning functions     . . . . . . .    .   .    .   .   .   .   .   .   334
249          7.21.10 Error-handling functions . . . . . . . .       .   .    .   .   .   .   .   .   337
250   7.22   General utilities <stdlib.h>        . . . . . . . .    .   .    .   .   .   .   .   .   339
251          7.22.1 Numeric conversion functions . . . . . .        .   .    .   .   .   .   .   .   340
252          7.22.2 Pseudo-random sequence generation functions         .    .   .   .   .   .   .   345
253          7.22.3 Memory management functions . . . . .           .   .    .   .   .   .   .   .   346
254          7.22.4 Communication with the environment        . .   .   .    .   .   .   .   .   .   348
255          7.22.5 Searching and sorting utilities . . . . . .     .   .    .   .   .   .   .   .   352
256          7.22.6 Integer arithmetic functions     . . . . . .    .   .    .   .   .   .   .   .   354
257          7.22.7 Multibyte/wide character conversion functions       .    .   .   .   .   .   .   355
258          7.22.8 Multibyte/wide string conversion functions      .   .    .   .   .   .   .   .   357
259   7.23   String handling <string.h> . . . . . . . . .           .   .    .   .   .   .   .   .   359
260          7.23.1 String function conventions . . . . . . .       .   .    .   .   .   .   .   .   359
261          7.23.2 Copying functions       . . . . . . . . . .     .   .    .   .   .   .   .   .   359
262          7.23.3 Concatenation functions . . . . . . . .         .   .    .   .   .   .   .   .   361
263          7.23.4 Comparison functions . . . . . . . . .          .   .    .   .   .   .   .   .   362
264          7.23.5 Search functions      . . . . . . . . . . .     .   .    .   .   .   .   .   .   364
265          7.23.6 Miscellaneous functions . . . . . . . .         .   .    .   .   .   .   .   .   367
266   7.24   Type-generic math <tgmath.h>          . . . . . . .    .   .    .   .   .   .   .   .   369
267   7.25   Threads <threads.h>          . . . . . . . . . . .     .   .    .   .   .   .   .   .   372
268          7.25.1 Introduction . . . . . . . . . . . . .          .   .    .   .   .   .   .   .   372
269          7.25.2 Initialization functions . . . . . . . . .      .   .    .   .   .   .   .   .   374
270          7.25.3 Condition variable functions     . . . . . .    .   .    .   .   .   .   .   .   374
271          7.25.4 Mutex functions       . . . . . . . . . . .     .   .    .   .   .   .   .   .   376
272          7.25.5 Thread functions . . . . . . . . . . .          .   .    .   .   .   .   .   .   379
273          7.25.6 Thread-specific storage functions     . . . .    .   .    .   .   .   .   .   .   381
274          7.25.7 Time functions . . . . . . . . . . . .          .   .    .   .   .   .   .   .   383
275   7.26   Date and time <time.h>         . . . . . . . . . .     .   .    .   .   .   .   .   .   384
276          7.26.1 Components of time        . . . . . . . . .     .   .    .   .   .   .   .   .   384
277          7.26.2 Time manipulation functions      . . . . . .    .   .    .   .   .   .   .   .   385
278          7.26.3 Time conversion functions      . . . . . . .    .   .    .   .   .   .   .   .   387
279
280
281 [page vii]
282
283    7.27 Unicode utilities <uchar.h> . . . . . . . . . . . . . .               . .     .   394
284         7.27.1 Restartable multibyte/wide character conversion functions        .     .   394
285    7.28 Extended multibyte and wide character utilities <wchar.h> . .         . .     .   398
286         7.28.1 Introduction . . . . . . . . . . . . . . . . . .               . .     .   398
287         7.28.2 Formatted wide character input/output functions       . . .    . .     .   399
288         7.28.3 Wide character input/output functions        . . . . . . .     . .     .   417
289         7.28.4 General wide string utilities     . . . . . . . . . . .        . .     .   421
290                  7.28.4.1 Wide string numeric conversion functions     . .    . .     .   422
291                  7.28.4.2 Wide string copying functions . . . . . . .         . .     .   426
292                  7.28.4.3 Wide string concatenation functions      . . . .    . .     .   428
293                  7.28.4.4 Wide string comparison functions      . . . . .     . .     .   429
294                  7.28.4.5 Wide string search functions      . . . . . . .     . .     .   431
295                  7.28.4.6 Miscellaneous functions      . . . . . . . . .      . .     .   435
296         7.28.5 Wide character time conversion functions       . . . . . .     . .     .   435
297         7.28.6 Extended multibyte/wide character conversion utilities .       . .     .   436
298                  7.28.6.1 Single-byte/wide character conversion functions     . .     .   437
299                  7.28.6.2 Conversion state functions     . . . . . . . .      . .     .   437
300                  7.28.6.3 Restartable multibyte/wide character conversion
301                            functions   . . . . . . . . . . . . . . .          . . . 438
302                  7.28.6.4 Restartable multibyte/wide string conversion
303                            functions   . . . . . . . . . . . . . . .          .   .   .   440
304    7.29 Wide character classification and mapping utilities <wctype.h>         .   .   .   443
305         7.29.1 Introduction . . . . . . . . . . . . . . . . . .               .   .   .   443
306         7.29.2 Wide character classification utilities . . . . . . . .         .   .   .   444
307                  7.29.2.1 Wide character classification functions     . . .    .   .   .   444
308                  7.29.2.2 Extensible wide character classification
309                            functions   . . . . . . . . . . . . . . .          . . . 447
310         7.29.3 Wide character case mapping utilities . . . . . . . .          . . . 449
311                  7.29.3.1 Wide character case mapping functions      . . .    . . . 449
312                  7.29.3.2 Extensible wide character case mapping
313                            functions   . . . . . . . . . . . . . . .          .   .   .   449
314    7.30 Future library directions    . . . . . . . . . . . . . . . .          .   .   .   451
315         7.30.1 Complex arithmetic <complex.h> . . . . . . . .                 .   .   .   451
316         7.30.2 Character handling <ctype.h>            . . . . . . . . .      .   .   .   451
317         7.30.3 Errors <errno.h>           . . . . . . . . . . . . . .         .   .   .   451
318         7.30.4 Format conversion of integer types <inttypes.h>            .   .   .   .   451
319         7.30.5 Localization <locale.h>           . . . . . . . . . . .        .   .   .   451
320         7.30.6 Signal handling <signal.h>           . . . . . . . . . .       .   .   .   451
321         7.30.7 Boolean type and values <stdbool.h>            . . . . . .     .   .   .   451
322         7.30.8 Integer types <stdint.h>          . . . . . . . . . . .        .   .   .   451
323         7.30.9 Input/output <stdio.h>          . . . . . . . . . . . .        .   .   .   452
324         7.30.10 General utilities <stdlib.h>        . . . . . . . . . .       .   .   .   452
325         7.30.11 String handling <string.h>          . . . . . . . . . .       .   .   .   452
326
327
328
329 [page viii]
330
331         7.30.12 Extended multibyte and wide character utilities
332                 <wchar.h>        . . . . . . . . . . . . . . . . . . . . 452
333         7.30.13 Wide character classification and mapping utilities
334                 <wctype.h> . . . . . . . . . . . . . . . . . . . . 452
335 Annex A (informative) Language syntax summary   . .       .    .   .   .    .   .   .   .   .   .   453
336   A.1 Lexical grammar       . . . . . . . . . . . .       .    .   .   .    .   .   .   .   .   .   453
337   A.2 Phrase structure grammar . . . . . . . . .          .    .   .   .    .   .   .   .   .   .   460
338   A.3 Preprocessing directives    . . . . . . . . .       .    .   .   .    .   .   .   .   .   .   468
339 Annex B (informative) Library summary     . . . . . . . . . . . . .                     .   .   .   470
340   B.1 Diagnostics <assert.h>          . . . . . . . . . . . . . . .                     .   .   .   470
341   B.2 Complex <complex.h> . . . . . . . . . . . . . . . .                               .   .   .   470
342   B.3 Character handling <ctype.h> . . . . . . . . . . . . .                            .   .   .   472
343   B.4 Errors <errno.h>         . . . . . . . . . . . . . . . . . .                      .   .   .   472
344   B.5 Floating-point environment <fenv.h>          . . . . . . . . . .                  .   .   .   472
345   B.6 Characteristics of floating types <float.h> . . . . . . . .                        .   .   .   473
346   B.7 Format conversion of integer types <inttypes.h> . . . . .                         .   .   .   473
347   B.8 Alternative spellings <iso646.h> . . . . . . . . . . . .                          .   .   .   474
348   B.9 Sizes of integer types <limits.h>          . . . . . . . . . . .                  .   .   .   474
349   B.10 Localization <locale.h> . . . . . . . . . . . . . . .                            .   .   .   474
350   B.11 Mathematics <math.h> . . . . . . . . . . . . . . . .                             .   .   .   474
351   B.12 Nonlocal jumps <setjmp.h>          . . . . . . . . . . . . .                     .   .   .   479
352   B.13 Signal handling <signal.h> . . . . . . . . . . . . . .                           .   .   .   479
353   B.14 Alignment <stdalign.h>           . . . . . . . . . . . . . .                     .   .   .   480
354   B.15 Variable arguments <stdarg.h>         . . . . . . . . . . . .                    .   .   .   480
355   B.16 Atomics <stdatomic.h> . . . . . . . . . . . . . . .                              .   .   .   480
356   B.17 Boolean type and values <stdbool.h>           . . . . . . . . .                  .   .   .   482
357   B.18 Common definitions <stddef.h> . . . . . . . . . . . .                             .   .   .   482
358   B.19 Integer types <stdint.h> . . . . . . . . . . . . . . .                           .   .   .   482
359   B.20 Input/output <stdio.h>         . . . . . . . . . . . . . . .                     .   .   .   483
360   B.21 General utilities <stdlib.h>       . . . . . . . . . . . . .                     .   .   .   486
361   B.22 String handling <string.h> . . . . . . . . . . . . . .                           .   .   .   488
362   B.23 Type-generic math <tgmath.h>          . . . . . . . . . . . .                    .   .   .   490
363   B.24 Threads <threads.h>          . . . . . . . . . . . . . . . .                     .   .   .   490
364   B.25 Date and time <time.h>         . . . . . . . . . . . . . . .                     .   .   .   491
365   B.26 Unicode utilities <uchar.h> . . . . . . . . . . . . . .                          .   .   .   492
366   B.27 Extended multibyte/wide character utilities <wchar.h>     . . .                  .   .   .   492
367   B.28 Wide character classification and mapping utilities <wctype.h>                    .   .   .   497
368 Annex C (informative) Sequence points     . . . . . . . . . . . . . . . . . 498
369 Annex D (normative) Universal character names for identifiers           . . . . . . . 499
370 Annex E (informative) Implementation limits        . . . . . . . . . . . . . . 501
371 Annex F (normative) IEC 60559 floating-point arithmetic . . . . . . . . . . 503
372   F.1 Introduction     . . . . . . . . . . . . . . . . . . . . . . . . 503
373
374 [page ix]
375
376     F.2    Types . . . . . . . . . . . . . . . . . . . . . . .                . .     .   .   503
377     F.3    Operators and functions       . . . . . . . . . . . . . . .        . .     .   .   504
378     F.4    Floating to integer conversion    . . . . . . . . . . . . .        . .     .   .   506
379     F.5    Binary-decimal conversion       . . . . . . . . . . . . . .        . .     .   .   506
380     F.6    The return statement . . . . . . . . . . . . . . . .               . .     .   .   507
381     F.7    Contracted expressions . . . . . . . . . . . . . . . .             . .     .   .   507
382     F.8    Floating-point environment      . . . . . . . . . . . . . .        . .     .   .   507
383     F.9    Optimization . . . . . . . . . . . . . . . . . . . .               . .     .   .   510
384     F.10   Mathematics <math.h> . . . . . . . . . . . . . . .                 . .     .   .   513
385            F.10.1 Trigonometric functions . . . . . . . . . . . .             . .     .   .   514
386            F.10.2 Hyperbolic functions       . . . . . . . . . . . . .        . .     .   .   516
387            F.10.3 Exponential and logarithmic functions    . . . . . .        . .     .   .   516
388            F.10.4 Power and absolute value functions     . . . . . . .        . .     .   .   519
389            F.10.5 Error and gamma functions . . . . . . . . . . .             . .     .   .   521
390            F.10.6 Nearest integer functions . . . . . . . . . . . .           . .     .   .   521
391            F.10.7 Remainder functions        . . . . . . . . . . . . .        . .     .   .   524
392            F.10.8 Manipulation functions       . . . . . . . . . . . .        . .     .   .   525
393            F.10.9 Maximum, minimum, and positive difference functions           .     .   .   525
394            F.10.10 Floating multiply-add . . . . . . . . . . . . .            . .     .   .   526
395            F.10.11 Comparison macros . . . . . . . . . . . . . .              . .     .   .   526
396 Annex G (informative) IEC 60559-compatible complex arithmetic         .   .   .   .   .   .   527
397   G.1 Introduction      . . . . . . . . . . . . . . . . .         .   .   .   .   .   .   .   527
398   G.2 Types . . . . . . . . . . . . . . . . . . . .               .   .   .   .   .   .   .   527
399   G.3 Conventions       . . . . . . . . . . . . . . . . .         .   .   .   .   .   .   .   527
400   G.4 Conversions       . . . . . . . . . . . . . . . . .         .   .   .   .   .   .   .   528
401        G.4.1 Imaginary types      . . . . . . . . . . . .         .   .   .   .   .   .   .   528
402        G.4.2 Real and imaginary . . . . . . . . . . .             .   .   .   .   .   .   .   528
403        G.4.3 Imaginary and complex       . . . . . . . . .        .   .   .   .   .   .   .   528
404   G.5 Binary operators      . . . . . . . . . . . . . . .         .   .   .   .   .   .   .   528
405        G.5.1 Multiplicative operators    . . . . . . . . .        .   .   .   .   .   .   .   529
406        G.5.2 Additive operators     . . . . . . . . . . .         .   .   .   .   .   .   .   532
407   G.6 Complex arithmetic <complex.h>          . . . . . . .       .   .   .   .   .   .   .   532
408        G.6.1 Trigonometric functions . . . . . . . . .            .   .   .   .   .   .   .   534
409        G.6.2 Hyperbolic functions     . . . . . . . . . .         .   .   .   .   .   .   .   534
410        G.6.3 Exponential and logarithmic functions      . . .     .   .   .   .   .   .   .   538
411        G.6.4 Power and absolute-value functions      . . . .      .   .   .   .   .   .   .   539
412   G.7 Type-generic math <tgmath.h>          . . . . . . . .       .   .   .   .   .   .   .   540
413 Annex H (informative) Language independent arithmetic . .     .   .   .   .   .   .   .   .   541
414   H.1 Introduction     . . . . . . . . . . . . . . . .        .   .   .   .   .   .   .   .   541
415   H.2 Types . . . . . . . . . . . . . . . . . . .             .   .   .   .   .   .   .   .   541
416   H.3 Notification      . . . . . . . . . . . . . . . .        .   .   .   .   .   .   .   .   545
417 Annex I (informative) Common warnings       . . . . . . . . . . . . . . . . 547
418
419
420 [page x]
421
422 Annex J (informative) Portability issues    . . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   549
423   J.1 Unspecified behavior . . . .           . . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   549
424   J.2 Undefined behavior          . . . .    . . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   552
425   J.3 Implementation-defined behavior          . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   566
426   J.4 Locale-specific behavior         . .   . . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   573
427   J.5 Common extensions          . . . .    . . . .   .   .   .   .   .   .   .    .   .   .   .   .   .   574
428 Annex K (normative) Bounds-checking interfaces . . . . . . . . . .                             .   .   .   577
429   K.1 Background       . . . . . . . . . . . . . . . . . . . . .                               .   .   .   577
430   K.2 Scope . . . . . . . . . . . . . . . . . . . . . . . .                                    .   .   .   578
431   K.3 Library     . . . . . . . . . . . . . . . . . . . . . . .                                .   .   .   578
432        K.3.1 Introduction . . . . . . . . . . . . . . . . . .                                  .   .   .   578
433                 K.3.1.1 Standard headers     . . . . . . . . . . . .                           .   .   .   578
434                 K.3.1.2 Reserved identifiers     . . . . . . . . . . .                          .   .   .   579
435                 K.3.1.3 Use of errno . . . . . . . . . . . . . .                               .   .   .   579
436                 K.3.1.4 Runtime-constraint violations     . . . . . . .                        .   .   .   579
437        K.3.2 Errors <errno.h>           . . . . . . . . . . . . . .                            .   .   .   580
438        K.3.3 Common definitions <stddef.h>               . . . . . . . .                        .   .   .   580
439        K.3.4 Integer types <stdint.h>           . . . . . . . . . . .                          .   .   .   580
440        K.3.5 Input/output <stdio.h>          . . . . . . . . . . . .                           .   .   .   581
441                 K.3.5.1 Operations on files      . . . . . . . . . . .                          .   .   .   581
442                 K.3.5.2 File access functions . . . . . . . . . . .                            .   .   .   583
443                 K.3.5.3 Formatted input/output functions . . . . . .                           .   .   .   586
444                 K.3.5.4 Character input/output functions . . . . . .                           .   .   .   597
445        K.3.6 General utilities <stdlib.h>          . . . . . . . . . .                         .   .   .   599
446                 K.3.6.1 Runtime-constraint handling       . . . . . . .                        .   .   .   599
447                 K.3.6.2 Communication with the environment . . . .                             .   .   .   601
448                 K.3.6.3 Searching and sorting utilities . . . . . . .                          .   .   .   602
449                 K.3.6.4 Multibyte/wide character conversion functions                          .   .   .   605
450                 K.3.6.5 Multibyte/wide string conversion functions . .                         .   .   .   606
451        K.3.7 String handling <string.h>            . . . . . . . . . .                         .   .   .   609
452                 K.3.7.1 Copying functions       . . . . . . . . . . .                          .   .   .   609
453                 K.3.7.2 Concatenation functions       . . . . . . . . .                        .   .   .   612
454                 K.3.7.3 Search functions     . . . . . . . . . . . .                           .   .   .   615
455                 K.3.7.4 Miscellaneous functions       . . . . . . . . .                        .   .   .   616
456        K.3.8 Date and time <time.h>          . . . . . . . . . . . .                           .   .   .   619
457                 K.3.8.1 Components of time . . . . . . . . . . .                               .   .   .   619
458                 K.3.8.2 Time conversion functions       . . . . . . . .                        .   .   .   619
459        K.3.9 Extended multibyte and wide character utilities
460                 <wchar.h>        . . . . . . . . . . . . . . . . .                             . . . 622
461                 K.3.9.1 Formatted wide character input/output functions                        . . . 623
462                 K.3.9.2 General wide string utilities . . . . . . . .                          . . . 634
463                 K.3.9.3 Extended multibyte/wide character conversion
464                         utilities . . . . . . . . . . . . . . . .                              . . . 642
465
466
467 [page xi]
468
469 Annex L (normative) Analyzability . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   647
470   L.1 Scope . . . . . . . . . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   647
471   L.2 Definitions . . . . . . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   647
472   L.3 Requirements . . . . . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   648
473 Bibliography   . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
474 Index    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
475
476
477
478
479 [page xii]
480
481     Foreword
482 1   ISO (the International Organization for Standardization) and IEC (the International
483     Electrotechnical Commission) form the specialized system for worldwide
484     standardization. National bodies that are member of ISO or IEC participate in the
485     development of International Standards through technical committees established by the
486     respective organization to deal with particular fields of technical activity. ISO and IEC
487     technical committees collaborate in fields of mutual interest. Other international
488     organizations, governmental and non-governmental, in liaison with ISO and IEC, also
489     take part in the work.
490 2   International Standards are drafted in accordance with the rules given in the ISO/IEC
491     Directives, Part 2. This International Standard was drafted in accordance with the fifth
492     edition (2004).
493 3   In the field of information technology, ISO and IEC have established a joint technical
494     committee, ISO/IEC JTC 1. Draft International Standards adopted by the joint technical
495     committee are circulated to national bodies for voting. Publication as an International
496     Standard requires approval by at least 75% of the national bodies casting a vote.
497 4   Attention is drawn to the possibility that some of the elements of this document may be
498     the subject of patent rights. ISO and IEC shall not be held responsible for identifying any
499     or all such patent rights.
500 5   This International Standard was prepared by Joint Technical Committee ISO/IEC JTC 1,
501     Information technology, Subcommittee SC 22, Programming languages, their
502     environments and system software interfaces. The Working Group responsible for this
503     standard (WG 14) maintains a site on the World Wide Web at http://www.open-
504     std.org/JTC1/SC22/WG14/ containing additional information relevant to this
505     standard such as a Rationale for many of the decisions made during its preparation and a
506     log of Defect Reports and Responses.
507 6   This third edition cancels and replaces the second edition, ISO/IEC 9899:1999, as
508     corrected by ISO/IEC 9899:1999/Cor 1:2001, ISO/IEC 9899:1999/Cor 2:2004, and
509     ISO/IEC 9899:1999/Cor 3:2007. Major changes from the previous edition include:
510     -- conditional (optional) features (including some that were previously mandatory)
511     -- support for multiple threads of execution including an improved memory sequencing
512       model, atomic objects, and thread-local storage (<stdatomic.h> and
513       <threads.h>)
514     -- additional floating-point characteristic macros (<float.h>)
515     -- querying and specifying alignment of objects (<stdalign.h>, <stdlib.h>)
516     -- Unicode characters and           strings   (<uchar.h>)       (originally   specified    in
517       ISO/IEC TR 19769:2004)
518     -- type-generic expressions
519
520
521 [page xiii]
522
523     -- static assertions
524     -- anonymous structures and unions
525     -- no-return functions
526     -- macros to create complex numbers (<complex.h>)
527     -- support for opening files for exclusive access
528     -- removed the gets function (<stdio.h>)
529     -- added the aligned_alloc, at_quick_exit, and quick_exit functions
530       (<stdlib.h>)
531     -- (conditional) support for bounds-checking interfaces (originally specified in
532       ISO/IEC TR 24731-1:2007)
533     -- (conditional) support for analyzability
534 7   Major changes in the second edition included:
535     -- restricted character set support via digraphs and <iso646.h> (originally specified
536       in AMD1)
537     -- wide character library support in <wchar.h> and <wctype.h> (originally
538       specified in AMD1)
539     -- more precise aliasing rules via effective type
540     -- restricted pointers
541     -- variable length arrays
542     -- flexible array members
543     -- static and type qualifiers in parameter array declarators
544     -- complex (and imaginary) support in <complex.h>
545     -- type-generic math macros in <tgmath.h>
546     -- the long long int type and library functions
547     -- increased minimum translation limits
548     -- additional floating-point characteristics in <float.h>
549     -- remove implicit int
550     -- reliable integer division
551     -- universal character names (\u and \U)
552     -- extended identifiers
553     -- hexadecimal floating-point constants and %a and %A printf/scanf conversion
554       specifiers
555
556
557
558 [page xiv]
559
560 -- compound literals
561 -- designated initializers
562 -- // comments
563 -- extended integer types and library functions in <inttypes.h> and <stdint.h>
564 -- remove implicit function declaration
565 -- preprocessor arithmetic done in intmax_t/uintmax_t
566 -- mixed declarations and code
567 -- new block scopes for selection and iteration statements
568 -- integer constant type rules
569 -- integer promotion rules
570 -- macros with a variable number of arguments
571 -- the vscanf family of functions in <stdio.h> and <wchar.h>
572 -- additional math library functions in <math.h>
573 -- treatment of error conditions by math library functions (math_errhandling)
574 -- floating-point environment access in <fenv.h>
575 -- IEC 60559 (also known as IEC 559 or IEEE arithmetic) support
576 -- trailing comma allowed in enum declaration
577 -- %lf conversion specifier allowed in printf
578 -- inline functions
579 -- the snprintf family of functions in <stdio.h>
580 -- boolean type in <stdbool.h>
581 -- idempotent type qualifiers
582 -- empty macro arguments
583 -- new structure type compatibility rules (tag compatibility)
584 -- additional predefined macro names
585 -- _Pragma preprocessing operator
586 -- standard pragmas
587 -- __func__ predefined identifier
588 -- va_copy macro
589 -- additional strftime conversion specifiers
590 -- LIA compatibility annex
591
592
593 [page xv]
594
595     -- deprecate ungetc at the beginning of a binary file
596     -- remove deprecation of aliased array parameters
597     -- conversion of array to pointer not limited to lvalues
598     -- relaxed constraints on aggregate and union initialization
599     -- relaxed restrictions on portable header names
600     -- return without expression not permitted in function that returns a value (and vice
601       versa)
602 8   Annexes D, F, K, and L form a normative part of this standard; annexes A, B, C, E, G, H,
603     I, J, the bibliography, and the index are for information only. In accordance with Part 2 of
604     the ISO/IEC Directives, this foreword, the introduction, notes, footnotes, and examples
605     are also for information only.
606
607
608
609
610 [page xvi]
611
612     Introduction
613 1   With the introduction of new devices and extended character sets, new features may be
614     added to this International Standard. Subclauses in the language and library clauses warn
615     implementors and programmers of usages which, though valid in themselves, may
616     conflict with future additions.
617 2   Certain features are obsolescent, which means that they may be considered for
618     withdrawal in future revisions of this International Standard. They are retained because
619     of their widespread use, but their use in new implementations (for implementation
620     features) or new programs (for language [6.11] or library features [7.30]) is discouraged.
621 3   This International Standard is divided into four major subdivisions:
622     -- preliminary elements (clauses 1-4);
623     -- the characteristics of environments that translate and execute C programs (clause 5);
624     -- the language syntax, constraints, and semantics (clause 6);
625     -- the library facilities (clause 7).
626 4   Examples are provided to illustrate possible forms of the constructions described.
627     Footnotes are provided to emphasize consequences of the rules described in that
628     subclause or elsewhere in this International Standard. References are used to refer to
629     other related subclauses. Recommendations are provided to give advice or guidance to
630     implementors. Annexes provide additional information and summarize the information
631     contained in this International Standard. A bibliography lists documents that were
632     referred to during the preparation of the standard.
633 5   The language clause (clause 6) is derived from ''The C Reference Manual''.
634 6   The library clause (clause 7) is based on the 1984 /usr/group Standard.
635
636
637
638
639 [page xvii]
640
641
642
643 [page xviii]
644
645
646
647     Programming languages -- C
648
649
650
651     1. Scope
652 1   This International Standard specifies the form and establishes the interpretation of
653     programs written in the C programming language.1) It specifies
654     -- the representation of C programs;
655     -- the syntax and constraints of the C language;
656     -- the semantic rules for interpreting C programs;
657     -- the representation of input data to be processed by C programs;
658     -- the representation of output data produced by C programs;
659     -- the restrictions and limits imposed by a conforming implementation of C.
660 2   This International Standard does not specify
661     -- the mechanism by which C programs are transformed for use by a data-processing
662       system;
663     -- the mechanism by which C programs are invoked for use by a data-processing
664       system;
665     -- the mechanism by which input data are transformed for use by a C program;
666     -- the mechanism by which output data are transformed after being produced by a C
667       program;
668     -- the size or complexity of a program and its data that will exceed the capacity of any
669       specific data-processing system or the capacity of a particular processor;
670     -- all minimal requirements of a data-processing system that is capable of supporting a
671       conforming implementation.
672
673
674     1)   This International Standard is designed to promote the portability of C programs among a variety of
675          data-processing systems. It is intended for use by implementors and programmers.
676
677 [page 1]
678
679
680     2. Normative references
681 1   The following referenced documents are indispensable for the application of this
682     document. For dated references, only the edition cited applies. For undated references,
683     the latest edition of the referenced document (including any amendments) applies.
684 2   ISO 31-11:1992, Quantities and units -- Part 11: Mathematical signs and symbols for
685     use in the physical sciences and technology.
686 3   ISO/IEC 646, Information technology -- ISO 7-bit coded character set for information
687     interchange.
688 4   ISO/IEC 2382-1:1993, Information technology -- Vocabulary -- Part 1: Fundamental
689     terms.
690 5   ISO 4217, Codes for the representation of currencies and funds.
691 6   ISO 8601, Data elements and interchange formats -- Information interchange --
692     Representation of dates and times.
693 7   ISO/IEC 10646 (all parts), Information technology -- Universal Multiple-Octet Coded
694     Character Set (UCS).
695 8   IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems (previously
696     designated IEC 559:1989).
697
698
699
700
701 [page 2]
702
703
704     3. Terms, definitions, and symbols
705 1   For the purposes of this International Standard, the following definitions apply. Other
706     terms are defined where they appear in italic type or on the left side of a syntax rule.
707     Terms explicitly defined in this International Standard are not to be presumed to refer
708     implicitly to similar terms defined elsewhere. Terms not defined in this International
709     Standard are to be interpreted according to ISO/IEC 2382-1. Mathematical symbols not
710     defined in this International Standard are to be interpreted according to ISO 31-11.
711     3.1
712 1   access
713     <execution-time action> to read or modify the value of an object
714 2   NOTE 1   Where only one of these two actions is meant, ''read'' or ''modify'' is used.
715
716 3   NOTE 2   ''Modify'' includes the case where the new value being stored is the same as the previous value.
717
718 4   NOTE 3   Expressions that are not evaluated do not access objects.
719
720     3.2
721 1   alignment
722     requirement that objects of a particular type be located on storage boundaries with
723     addresses that are particular multiples of a byte address
724     3.3
725 1   argument
726     actual argument
727     actual parameter (deprecated)
728     expression in the comma-separated list bounded by the parentheses in a function call
729     expression, or a sequence of preprocessing tokens in the comma-separated list bounded
730     by the parentheses in a function-like macro invocation
731     3.4
732 1   behavior
733     external appearance or action
734     3.4.1
735 1   implementation-defined behavior
736     unspecified behavior where each implementation documents how the choice is made
737 2   EXAMPLE An example of implementation-defined behavior is the propagation of the high-order bit
738     when a signed integer is shifted right.
739
740     3.4.2
741 1   locale-specific behavior
742     behavior that depends on local conventions of nationality, culture, and language that each
743     implementation documents
744
745
746 [page 3]
747
748 2   EXAMPLE An example of locale-specific behavior is whether the islower function returns true for
749     characters other than the 26 lowercase Latin letters.
750
751     3.4.3
752 1   undefined behavior
753     behavior, upon use of a nonportable or erroneous program construct or of erroneous data,
754     for which this International Standard imposes no requirements
755 2   NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable
756     results, to behaving during translation or program execution in a documented manner characteristic of the
757     environment (with or without the issuance of a diagnostic message), to terminating a translation or
758     execution (with the issuance of a diagnostic message).
759
760 3   EXAMPLE        An example of undefined behavior is the behavior on integer overflow.
761
762     3.4.4
763 1   unspecified behavior
764     use of an unspecified value, or other behavior where this International Standard provides
765     two or more possibilities and imposes no further requirements on which is chosen in any
766     instance
767 2   EXAMPLE        An example of unspecified behavior is the order in which the arguments to a function are
768     evaluated.
769
770     3.5
771 1   bit
772     unit of data storage in the execution environment large enough to hold an object that may
773     have one of two values
774 2   NOTE     It need not be possible to express the address of each individual bit of an object.
775
776     3.6
777 1   byte
778     addressable unit of data storage large enough to hold any member of the basic character
779     set of the execution environment
780 2   NOTE 1     It is possible to express the address of each individual byte of an object uniquely.
781
782 3   NOTE 2 A byte is composed of a contiguous sequence of bits, the number of which is implementation-
783     defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order
784     bit.
785
786     3.7
787 1   character
788     <abstract> member of a set of elements used for the organization, control, or
789     representation of data
790     3.7.1
791 1   character
792     single-byte character
793     <C> bit representation that fits in a byte
794 [page 4]
795
796     3.7.2
797 1   multibyte character
798     sequence of one or more bytes representing a member of the extended character set of
799     either the source or the execution environment
800 2   NOTE    The extended character set is a superset of the basic character set.
801
802     3.7.3
803 1   wide character
804     bit representation that fits in an object of type wchar_t, capable of representing any
805     character in the current locale
806     3.8
807 1   constraint
808     restriction, either syntactic or semantic, by which the exposition of language elements is
809     to be interpreted
810     3.9
811 1   correctly rounded result
812     representation in the result format that is nearest in value, subject to the current rounding
813     mode, to what the result would be given unlimited range and precision
814     3.10
815 1   diagnostic message
816     message belonging to an implementation-defined subset of the implementation's message
817     output
818     3.11
819 1   forward reference
820     reference to a later subclause of this International Standard that contains additional
821     information relevant to this subclause
822     3.12
823 1   implementation
824     particular set of software, running in a particular translation environment under particular
825     control options, that performs translation of programs for, and supports execution of
826     functions in, a particular execution environment
827     3.13
828 1   implementation limit
829     restriction imposed upon programs by the implementation
830     3.14
831 1   memory location
832     either an object of scalar type, or a maximal sequence of adjacent bit-fields all having
833     nonzero width
834
835 [page 5]
836
837 2   NOTE 1 Two threads of execution can update and access separate memory locations without interfering
838     with each other.
839
840 3   NOTE 2 A bit-field and an adjacent non-bit-field member are in separate memory locations. The same
841     applies to two bit-fields, if one is declared inside a nested structure declaration and the other is not, or if the
842     two are separated by a zero-length bit-field declaration, or if they are separated by a non-bit-field member
843     declaration. It is not safe to concurrently update two non-atomic bit-fields in the same structure if all
844     members declared between them are also (non-zero-length) bit-fields, no matter what the sizes of those
845     intervening bit-fields happen to be.
846
847 4   EXAMPLE        A structure declared as
848              struct {
849                    char a;
850                    int b:5, c:11, :0, d:8;
851                    struct { int ee:8; } e;
852              }
853     contains four separate memory locations: The member a, and bit-fields d and e.ee are each separate
854     memory locations, and can be modified concurrently without interfering with each other. The bit-fields b
855     and c together constitute the fourth memory location. The bit-fields b and c cannot be concurrently
856     modified, but b and a, for example, can be.
857
858     3.15
859 1   object
860     region of data storage in the execution environment, the contents of which can represent
861     values
862 2   NOTE      When referenced, an object may be interpreted as having a particular type; see 6.3.2.1.
863
864     3.16
865 1   parameter
866     formal parameter
867     formal argument (deprecated)
868     object declared as part of a function declaration or definition that acquires a value on
869     entry to the function, or an identifier from the comma-separated list bounded by the
870     parentheses immediately following the macro name in a function-like macro definition
871     3.17
872 1   recommended practice
873     specification that is strongly recommended as being in keeping with the intent of the
874     standard, but that may be impractical for some implementations
875     3.18
876 1   runtime-constraint
877     requirement on a program when calling a library function
878 2   NOTE 1 Despite the similar terms, a runtime-constraint is not a kind of constraint as defined by 3.8, and
879     need not be diagnosed at translation time.
880
881 3   NOTE 2 Implementations that support the extensions in annex K are required to verify that the runtime-
882     constraints for a library function are not violated by the program; see K.3.1.4.
883
884 [page 6]
885
886     3.19
887 1   value
888     precise meaning of the contents of an object when interpreted as having a specific type
889     3.19.1
890 1   implementation-defined value
891     unspecified value where each implementation documents how the choice is made
892     3.19.2
893 1   indeterminate value
894     either an unspecified value or a trap representation
895     3.19.3
896 1   unspecified value
897     valid value of the relevant type where this International Standard imposes no
898     requirements on which value is chosen in any instance
899 2   NOTE     An unspecified value cannot be a trap representation.
900
901     3.19.4
902 1   trap representation
903     an object representation that need not represent a value of the object type
904     3.19.5
905 1   perform a trap
906     interrupt execution of the program such that no further operations are performed
907 2   NOTE In this International Standard, when the word ''trap'' is not immediately followed by
908     ''representation'', this is the intended usage.2)
909
910     3.20
911 1   [^ x^]
912     ceiling of x: the least integer greater than or equal to x
913 2   EXAMPLE       [^2.4^] is 3, [^-2.4^] is -2.
914
915     3.21
916 1   [_ x_]
917     floor of x: the greatest integer less than or equal to x
918 2   EXAMPLE       [_2.4_] is 2, [_-2.4_] is -3.
919
920
921
922
923     2)   For example, ''Trapping or stopping (if supported) is disabled...'' (F.8.2). Note that fetching a trap
924          representation might perform a trap but is not required to (see 6.2.6.1).
925
926 [page 7]
927
928
929     4. Conformance
930 1   In this International Standard, ''shall'' is to be interpreted as a requirement on an
931     implementation or on a program; conversely, ''shall not'' is to be interpreted as a
932     prohibition.
933 2   If a ''shall'' or ''shall not'' requirement that appears outside of a constraint or runtime-
934     constraint is violated, the behavior is undefined. Undefined behavior is otherwise
935     indicated in this International Standard by the words ''undefined behavior'' or by the
936     omission of any explicit definition of behavior. There is no difference in emphasis among
937     these three; they all describe ''behavior that is undefined''.
938 3   A program that is correct in all other aspects, operating on correct data, containing
939     unspecified behavior shall be a correct program and act in accordance with 5.1.2.3.
940 4   The implementation shall not successfully translate a preprocessing translation unit
941     containing a #error preprocessing directive unless it is part of a group skipped by
942     conditional inclusion.
943 5   A strictly conforming program shall use only those features of the language and library
944     specified in this International Standard.3) It shall not produce output dependent on any
945     unspecified, undefined, or implementation-defined behavior, and shall not exceed any
946     minimum implementation limit.
947 6   The two forms of conforming implementation are hosted and freestanding. A conforming
948     hosted implementation shall accept any strictly conforming program. A conforming
949     freestanding implementation shall accept any strictly conforming program that does not
950     use complex types and in which the use of the features specified in the library clause
951     (clause 7) is confined to the contents of the standard headers <float.h>,
952     <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>,
953     <stddef.h>, and <stdint.h>. A conforming implementation may have extensions
954     (including additional library functions), provided they do not alter the behavior of any
955     strictly conforming program.4)
956
957
958
959     3)   A strictly conforming program can use conditional features (see 6.10.8.3) provided the use is guarded
960          by an appropriate conditional inclusion preprocessing directive using the related macro. For example:
961                  #ifdef __STDC_IEC_559__ /* FE_UPWARD defined */
962                     /* ... */
963                     fesetround(FE_UPWARD);
964                     /* ... */
965                  #endif
966
967     4)   This implies that a conforming implementation reserves no identifiers other than those explicitly
968          reserved in this International Standard.
969
970 [page 8]
971
972 7   A conforming program is one that is acceptable to a conforming implementation.5)
973 8   An implementation shall be accompanied by a document that defines all implementation-
974     defined and locale-specific characteristics and all extensions.
975     Forward references: conditional inclusion (6.10.1), error directive (6.10.5),
976     characteristics of floating types <float.h> (7.7), alternative spellings <iso646.h>
977     (7.9), sizes of integer types <limits.h> (7.10), alignment <stdalign.h> (7.15),
978     variable arguments <stdarg.h> (7.16), boolean type and values <stdbool.h>
979     (7.18), common definitions <stddef.h> (7.19), integer types <stdint.h> (7.20).
980
981
982
983
984     5)   Strictly conforming programs are intended to be maximally portable among conforming
985          implementations. Conforming programs may depend upon nonportable features of a conforming
986          implementation.
987
988 [page 9]
989
990
991     5. Environment
992 1   An implementation translates C source files and executes C programs in two data-
993     processing-system environments, which will be called the translation environment and
994     the execution environment in this International Standard. Their characteristics define and
995     constrain the results of executing conforming C programs constructed according to the
996     syntactic and semantic rules for conforming implementations.
997     Forward references: In this clause, only a few of many possible forward references
998     have been noted.
999     5.1 Conceptual models
1000     5.1.1 Translation environment
1001     5.1.1.1 Program structure
1002 1   A C program need not all be translated at the same time. The text of the program is kept
1003     in units called source files, (or preprocessing files) in this International Standard. A
1004     source file together with all the headers and source files included via the preprocessing
1005     directive #include is known as a preprocessing translation unit. After preprocessing, a
1006     preprocessing translation unit is called a translation unit. Previously translated translation
1007     units may be preserved individually or in libraries. The separate translation units of a
1008     program communicate by (for example) calls to functions whose identifiers have external
1009     linkage, manipulation of objects whose identifiers have external linkage, or manipulation
1010     of data files. Translation units may be separately translated and then later linked to
1011     produce an executable program.
1012     Forward references: linkages of identifiers (6.2.2), external definitions (6.9),
1013     preprocessing directives (6.10).
1014     5.1.1.2 Translation phases
1015 1   The precedence among the syntax rules of translation is specified by the following
1016     phases.6)
1017          1.   Physical source file multibyte characters are mapped, in an implementation-
1018               defined manner, to the source character set (introducing new-line characters for
1019               end-of-line indicators) if necessary. Trigraph sequences are replaced by
1020               corresponding single-character internal representations.
1021
1022
1023
1024     6)    Implementations shall behave as if these separate phases occur, even though many are typically folded
1025           together in practice. Source files, translation units, and translated translation units need not
1026           necessarily be stored as files, nor need there be any one-to-one correspondence between these entities
1027           and any external representation. The description is conceptual only, and does not specify any
1028           particular implementation.
1029
1030 [page 10]
1031
1032      2.   Each instance of a backslash character (\) immediately followed by a new-line
1033           character is deleted, splicing physical source lines to form logical source lines.
1034           Only the last backslash on any physical source line shall be eligible for being part
1035           of such a splice. A source file that is not empty shall end in a new-line character,
1036           which shall not be immediately preceded by a backslash character before any such
1037           splicing takes place.
1038      3.   The source file is decomposed into preprocessing tokens7) and sequences of
1039           white-space characters (including comments). A source file shall not end in a
1040           partial preprocessing token or in a partial comment. Each comment is replaced by
1041           one space character. New-line characters are retained. Whether each nonempty
1042           sequence of white-space characters other than new-line is retained or replaced by
1043           one space character is implementation-defined.
1044      4. Preprocessing directives are executed, macro invocations are expanded, and
1045         _Pragma unary operator expressions are executed. If a character sequence that
1046         matches the syntax of a universal character name is produced by token
1047         concatenation (6.10.3.3), the behavior is undefined. A #include preprocessing
1048         directive causes the named header or source file to be processed from phase 1
1049         through phase 4, recursively. All preprocessing directives are then deleted.
1050      5. Each source character set member and escape sequence in character constants and
1051         string literals is converted to the corresponding member of the execution character
1052         set; if there is no corresponding member, it is converted to an implementation-
1053         defined member other than the null (wide) character.8)
1054      6.   Adjacent string literal tokens are concatenated.
1055      7. White-space characters separating tokens are no longer significant. Each
1056         preprocessing token is converted into a token. The resulting tokens are
1057         syntactically and semantically analyzed and translated as a translation unit.
1058      8.   All external object and function references are resolved. Library components are
1059           linked to satisfy external references to functions and objects not defined in the
1060           current translation. All such translator output is collected into a program image
1061           which contains information needed for execution in its execution environment.
1062 Forward references: universal character names (6.4.3), lexical elements (6.4),
1063 preprocessing directives (6.10), trigraph sequences (5.2.1.1), external definitions (6.9).
1064
1065
1066
1067 7)    As described in 6.4, the process of dividing a source file's characters into preprocessing tokens is
1068       context-dependent. For example, see the handling of < within a #include preprocessing directive.
1069 8)    An implementation need not convert all non-corresponding source characters to the same execution
1070       character.
1071
1072 [page 11]
1073
1074     5.1.1.3 Diagnostics
1075 1   A conforming implementation shall produce at least one diagnostic message (identified in
1076     an implementation-defined manner) if a preprocessing translation unit or translation unit
1077     contains a violation of any syntax rule or constraint, even if the behavior is also explicitly
1078     specified as undefined or implementation-defined. Diagnostic messages need not be
1079     produced in other circumstances.9)
1080 2   EXAMPLE        An implementation shall issue a diagnostic for the translation unit:
1081              char i;
1082              int i;
1083     because in those cases where wording in this International Standard describes the behavior for a construct
1084     as being both a constraint error and resulting in undefined behavior, the constraint error shall be diagnosed.
1085
1086     5.1.2 Execution environments
1087 1   Two execution environments are defined: freestanding and hosted. In both cases,
1088     program startup occurs when a designated C function is called by the execution
1089     environment. All objects with static storage duration shall be initialized (set to their
1090     initial values) before program startup. The manner and timing of such initialization are
1091     otherwise unspecified. Program termination returns control to the execution
1092     environment.
1093     Forward references: storage durations of objects (6.2.4), initialization (6.7.9).
1094     5.1.2.1 Freestanding environment
1095 1   In a freestanding environment (in which C program execution may take place without any
1096     benefit of an operating system), the name and type of the function called at program
1097     startup are implementation-defined. Any library facilities available to a freestanding
1098     program, other than the minimal set required by clause 4, are implementation-defined.
1099 2   The effect of program termination in a freestanding environment is implementation-
1100     defined.
1101     5.1.2.2 Hosted environment
1102 1   A hosted environment need not be provided, but shall conform to the following
1103     specifications if present.
1104
1105
1106
1107
1108     9)   The intent is that an implementation should identify the nature of, and where possible localize, each
1109          violation. Of course, an implementation is free to produce any number of diagnostics as long as a
1110          valid program is still correctly translated. It may also successfully translate an invalid program.
1111
1112 [page 12]
1113
1114     5.1.2.2.1 Program startup
1115 1   The function called at program startup is named main. The implementation declares no
1116     prototype for this function. It shall be defined with a return type of int and with no
1117     parameters:
1118             int main(void) { /* ... */ }
1119     or with two parameters (referred to here as argc and argv, though any names may be
1120     used, as they are local to the function in which they are declared):
1121             int main(int argc, char *argv[]) { /* ... */ }
1122     or equivalent;10) or in some other implementation-defined manner.
1123 2   If they are declared, the parameters to the main function shall obey the following
1124     constraints:
1125     -- The value of argc shall be nonnegative.
1126     -- argv[argc] shall be a null pointer.
1127     -- If the value of argc is greater than zero, the array members argv[0] through
1128       argv[argc-1] inclusive shall contain pointers to strings, which are given
1129       implementation-defined values by the host environment prior to program startup. The
1130       intent is to supply to the program information determined prior to program startup
1131       from elsewhere in the hosted environment. If the host environment is not capable of
1132       supplying strings with letters in both uppercase and lowercase, the implementation
1133       shall ensure that the strings are received in lowercase.
1134     -- If the value of argc is greater than zero, the string pointed to by argv[0]
1135       represents the program name; argv[0][0] shall be the null character if the
1136       program name is not available from the host environment. If the value of argc is
1137       greater than one, the strings pointed to by argv[1] through argv[argc-1]
1138       represent the program parameters.
1139     -- The parameters argc and argv and the strings pointed to by the argv array shall
1140       be modifiable by the program, and retain their last-stored values between program
1141       startup and program termination.
1142     5.1.2.2.2 Program execution
1143 1   In a hosted environment, a program may use all the functions, macros, type definitions,
1144     and objects described in the library clause (clause 7).
1145
1146
1147
1148
1149     10) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as
1150         char ** argv, and so on.
1151
1152 [page 13]
1153
1154     5.1.2.2.3 Program termination
1155 1   If the return type of the main function is a type compatible with int, a return from the
1156     initial call to the main function is equivalent to calling the exit function with the value
1157     returned by the main function as its argument;11) reaching the } that terminates the
1158     main function returns a value of 0. If the return type is not compatible with int, the
1159     termination status returned to the host environment is unspecified.
1160     Forward references: definition of terms (7.1.1), the exit function (7.22.4.4).
1161     5.1.2.3 Program execution
1162 1   The semantic descriptions in this International Standard describe the behavior of an
1163     abstract machine in which issues of optimization are irrelevant.
1164 2   Accessing a volatile object, modifying an object, modifying a file, or calling a function
1165     that does any of those operations are all side effects,12) which are changes in the state of
1166     the execution environment. Evaluation of an expression in general includes both value
1167     computations and initiation of side effects. Value computation for an lvalue expression
1168     includes determining the identity of the designated object.
1169 3   Sequenced before is an asymmetric, transitive, pair-wise relation between evaluations
1170     executed by a single thread, which induces a partial order among those evaluations.
1171     Given any two evaluations A and B, if A is sequenced before B, then the execution of A
1172     shall precede the execution of B. (Conversely, if A is sequenced before B, then B is
1173     sequenced after A.) If A is not sequenced before or after B, then A and B are
1174     unsequenced. Evaluations A and B are indeterminately sequenced when A is sequenced
1175     either before or after B, but it is unspecified which.13) The presence of a sequence point
1176     between the evaluation of expressions A and B implies that every value computation and
1177     side effect associated with A is sequenced before every value computation and side effect
1178     associated with B. (A summary of the sequence points is given in annex C.)
1179 4   In the abstract machine, all expressions are evaluated as specified by the semantics. An
1180     actual implementation need not evaluate part of an expression if it can deduce that its
1181     value is not used and that no needed side effects are produced (including any caused by
1182
1183     11) In accordance with 6.2.4, the lifetimes of objects with automatic storage duration declared in main
1184         will have ended in the former case, even where they would not have in the latter.
1185     12) The IEC 60559 standard for binary floating-point arithmetic requires certain user-accessible status
1186         flags and control modes. Floating-point operations implicitly set the status flags; modes affect result
1187         values of floating-point operations. Implementations that support such floating-point state are
1188         required to regard changes to it as side effects -- see annex F for details. The floating-point
1189         environment library <fenv.h> provides a programming facility for indicating when these side
1190         effects matter, freeing the implementations in other cases.
1191     13) The executions of unsequenced evaluations can interleave. Indeterminately sequenced evaluations
1192         cannot interleave, but can be executed in any order.
1193
1194 [page 14]
1195
1196      calling a function or accessing a volatile object).
1197 5    When the processing of the abstract machine is interrupted by receipt of a signal, the
1198      values of objects that are neither lock-free atomic objects nor of type volatile
1199      sig_atomic_t are unspecified, and the value of any object that is modified by the
1200      handler that is neither a lock-free atomic object nor of type volatile
1201      sig_atomic_t becomes undefined.
1202 6    The least requirements on a conforming implementation are:
1203      -- Accesses to volatile objects are evaluated strictly according to the rules of the abstract
1204        machine.
1205      -- At program termination, all data written into files shall be identical to the result that
1206        execution of the program according to the abstract semantics would have produced.
1207      -- The input and output dynamics of interactive devices shall take place as specified in
1208        7.21.3. The intent of these requirements is that unbuffered or line-buffered output
1209        appear as soon as possible, to ensure that prompting messages actually appear prior to
1210        a program waiting for input.
1211      This is the observable behavior of the program.
1212 7    What constitutes an interactive device is implementation-defined.
1213 8    More stringent correspondences between abstract and actual semantics may be defined by
1214      each implementation.
1215 9    EXAMPLE 1 An implementation might define a one-to-one correspondence between abstract and actual
1216      semantics: at every sequence point, the values of the actual objects would agree with those specified by the
1217      abstract semantics. The keyword volatile would then be redundant.
1218 10   Alternatively, an implementation might perform various optimizations within each translation unit, such
1219      that the actual semantics would agree with the abstract semantics only when making function calls across
1220      translation unit boundaries. In such an implementation, at the time of each function entry and function
1221      return where the calling function and the called function are in different translation units, the values of all
1222      externally linked objects and of all objects accessible via pointers therein would agree with the abstract
1223      semantics. Furthermore, at the time of each such function entry the values of the parameters of the called
1224      function and of all objects accessible via pointers therein would agree with the abstract semantics. In this
1225      type of implementation, objects referred to by interrupt service routines activated by the signal function
1226      would require explicit specification of volatile storage, as well as other implementation-defined
1227      restrictions.
1228
1229 11   EXAMPLE 2       In executing the fragment
1230               char c1, c2;
1231               /* ... */
1232               c1 = c1 + c2;
1233      the ''integer promotions'' require that the abstract machine promote the value of each variable to int size
1234      and then add the two ints and truncate the sum. Provided the addition of two chars can be done without
1235      overflow, or with overflow wrapping silently to produce the correct result, the actual execution need only
1236      produce the same result, possibly omitting the promotions.
1237
1238 [page 15]
1239
1240 12   EXAMPLE 3       Similarly, in the fragment
1241               float f1, f2;
1242               double d;
1243               /* ... */
1244               f1 = f2 * d;
1245      the multiplication may be executed using single-precision arithmetic if the implementation can ascertain
1246      that the result would be the same as if it were executed using double-precision arithmetic (for example, if d
1247      were replaced by the constant 2.0, which has type double).
1248
1249 13   EXAMPLE 4 Implementations employing wide registers have to take care to honor appropriate
1250      semantics. Values are independent of whether they are represented in a register or in memory. For
1251      example, an implicit spilling of a register is not permitted to alter the value. Also, an explicit store and load
1252      is required to round to the precision of the storage type. In particular, casts and assignments are required to
1253      perform their specified conversion. For the fragment
1254               double d1, d2;
1255               float f;
1256               d1 = f = expression;
1257               d2 = (float) expression;
1258      the values assigned to d1 and d2 are required to have been converted to float.
1259
1260 14   EXAMPLE 5 Rearrangement for floating-point expressions is often restricted because of limitations in
1261      precision as well as range. The implementation cannot generally apply the mathematical associative rules
1262      for addition or multiplication, nor the distributive rule, because of roundoff error, even in the absence of
1263      overflow and underflow. Likewise, implementations cannot generally replace decimal constants in order to
1264      rearrange expressions. In the following fragment, rearrangements suggested by mathematical rules for real
1265      numbers are often not valid (see F.9).
1266               double x, y, z;
1267               /* ... */
1268               x = (x * y) * z;            //   not equivalent to x   *= y * z;
1269               z = (x - y) + y ;           //   not equivalent to z   = x;
1270               z = x + x * y;              //   not equivalent to z   = x * (1.0 + y);
1271               y = x / 5.0;                //   not equivalent to y   = x * 0.2;
1272
1273 15   EXAMPLE 6       To illustrate the grouping behavior of expressions, in the following fragment
1274               int a, b;
1275               /* ... */
1276               a = a + 32760 + b + 5;
1277      the expression statement behaves exactly the same as
1278               a = (((a + 32760) + b) + 5);
1279      due to the associativity and precedence of these operators. Thus, the result of the sum (a + 32760) is
1280      next added to b, and that result is then added to 5 which results in the value assigned to a. On a machine in
1281      which overflows produce an explicit trap and in which the range of values representable by an int is
1282      [-32768, +32767], the implementation cannot rewrite this expression as
1283               a = ((a + b) + 32765);
1284      since if the values for a and b were, respectively, -32754 and -15, the sum a + b would produce a trap
1285      while the original expression would not; nor can the expression be rewritten either as
1286
1287
1288 [page 16]
1289
1290               a = ((a + 32765) + b);
1291      or
1292               a = (a + (b + 32765));
1293      since the values for a and b might have been, respectively, 4 and -8 or -17 and 12. However, on a machine
1294      in which overflow silently generates some value and where positive and negative overflows cancel, the
1295      above expression statement can be rewritten by the implementation in any of the above ways because the
1296      same result will occur.
1297
1298 16   EXAMPLE 7 The grouping of an expression does not completely determine its evaluation. In the
1299      following fragment
1300               #include <stdio.h>
1301               int sum;
1302               char *p;
1303               /* ... */
1304               sum = sum * 10 - '0' + (*p++ = getchar());
1305      the expression statement is grouped as if it were written as
1306               sum = (((sum * 10) - '0') + ((*(p++)) = (getchar())));
1307      but the actual increment of p can occur at any time between the previous sequence point and the next
1308      sequence point (the ;), and the call to getchar can occur at any point prior to the need of its returned
1309      value.
1310
1311      Forward references: expressions (6.5), type qualifiers (6.7.3), statements (6.8), the
1312      signal function (7.14), files (7.21.3).
1313      5.1.2.4 Multi-threaded executions and data races
1314 1    Under a hosted implementation, a program can have more than one thread of execution
1315      (or thread) running concurrently. The execution of each thread proceeds as defined by
1316      the remainder of this standard. The execution of the entire program consists of an
1317      execution of all of its threads.14) Under a freestanding implementation, it is
1318      implementation-defined whether a program can have more than one thread of execution.
1319 2    The value of an object visible to a thread T at a particular point is the initial value of the
1320      object, a value stored in the object by T , or a value stored in the object by another thread,
1321      according to the rules below.
1322 3    NOTE 1 In some cases, there may instead be undefined behavior. Much of this section is motivated by
1323      the desire to support atomic operations with explicit and detailed visibility constraints. However, it also
1324      implicitly supports a simpler view for more restricted programs.
1325
1326 4    Two expression evaluations conflict if one of them modifies a memory location and the
1327      other one accesses or modifies the same memory location.
1328
1329
1330
1331
1332      14) The execution can usually be viewed as an interleaving of all of the threads. However, some kinds of
1333          atomic operations, for example, allow executions inconsistent with a simple interleaving as described
1334          below.
1335
1336 [page 17]
1337
1338 5    The library defines a number of atomic operations (7.17) and operations on mutexes
1339      (7.25.4) that are specially identified as synchronization operations. These operations play
1340      a special role in making assignments in one thread visible to another. A synchronization
1341      operation on one or more memory locations is either an acquire operation, a release
1342      operation, both an acquire and release operation, or a consume operation. A
1343      synchronization operation without an associated memory location is a fence and can be
1344      either an acquire fence, a release fence, or both an acquire and release fence. In addition,
1345      there are relaxed atomic operations, which are not synchronization operations, and
1346      atomic read-modify-write operations, which have special characteristics.
1347 6    NOTE 2 For example, a call that acquires a mutex will perform an acquire operation on the locations
1348      composing the mutex. Correspondingly, a call that releases the same mutex will perform a release
1349      operation on those same locations. Informally, performing a release operation on A forces prior side effects
1350      on other memory locations to become visible to other threads that later perform an acquire or consume
1351      operation on A. We do not include relaxed atomic operations as synchronization operations although, like
1352      synchronization operations, they cannot contribute to data races.
1353
1354 7    All modifications to a particular atomic object M occur in some particular total order,
1355      called the modification order of M. If A and B are modifications of an atomic object M,
1356      and A happens before B, then A shall precede B in the modification order of M, which is
1357      defined below.
1358 8    NOTE 3     This states that the modification orders must respect the ''happens before'' relation.
1359
1360 9    NOTE 4 There is a separate order for each atomic object. There is no requirement that these can be
1361      combined into a single total order for all objects. In general this will be impossible since different threads
1362      may observe modifications to different variables in inconsistent orders.
1363
1364 10   A release sequence on an atomic object M is a maximal contiguous sub-sequence of side
1365      effects in the modification order of M, where the first operation is a release and every
1366      subsequent operation either is performed by the same thread that performed the release or
1367      is an atomic read-modify-write operation.
1368 11   Certain library calls synchronize with other library calls performed by another thread. In
1369      particular, an atomic operation A that performs a release operation on an object M
1370      synchronizes with an atomic operation B that performs an acquire operation on M and
1371      reads a value written by any side effect in the release sequence headed by A.
1372 12   NOTE 5 Except in the specified cases, reading a later value does not necessarily ensure visibility as
1373      described below. Such a requirement would sometimes interfere with efficient implementation.
1374
1375 13   NOTE 6 The specifications of the synchronization operations define when one reads the value written by
1376      another. For atomic variables, the definition is clear. All operations on a given mutex occur in a single total
1377      order. Each mutex acquisition ''reads the value written'' by the last mutex release.
1378
1379 14   An evaluation A carries a dependency 15) to an evaluation B if:
1380
1381
1382      15) The ''carries a dependency'' relation is a subset of the ''sequenced before'' relation, and is similarly
1383          strictly intra-thread.
1384
1385 [page 18]
1386
1387      -- the value of A is used as an operand of B, unless:
1388            o B is an invocation of the kill_dependency macro,
1389
1390            o A is the left operand of a && or || operator,
1391
1392            o A is the left operand of a ? : operator, or
1393
1394            o A is the left operand of a , operator;
1395          or
1396      -- A writes a scalar object or bit-field M, B reads from M the value written by A, and A
1397        is sequenced before B, or
1398      -- for some evaluation X, A carries a dependency to X and X carries a dependency to B.
1399 15   An evaluation A is dependency-ordered before16) an evaluation B if:
1400      -- A performs a release operation on an atomic object M, and B performs a consume
1401        operation on M and reads a value written by any side effect in the release sequence
1402        headed by A, or
1403      -- for some evaluation X, A is dependency-ordered before X and X carries a
1404        dependency to B.
1405 16   An evaluation A inter-thread happens before an evaluation B if A synchronizes with B, A
1406      is dependency-ordered before B, or, for some evaluation X:
1407      -- A synchronizes with X and X is sequenced before B,
1408      -- A is sequenced before X and X inter-thread happens before B, or
1409      -- A inter-thread happens before X and X inter-thread happens before B.
1410 17   NOTE 7 The ''inter-thread happens before'' relation describes arbitrary concatenations of ''sequenced
1411      before'', ''synchronizes with'', and ''dependency-ordered before'' relationships, with two exceptions. The
1412      first exception is that a concatenation is not permitted to end with ''dependency-ordered before'' followed
1413      by ''sequenced before''. The reason for this limitation is that a consume operation participating in a
1414      ''dependency-ordered before'' relationship provides ordering only with respect to operations to which this
1415      consume operation actually carries a dependency. The reason that this limitation applies only to the end of
1416      such a concatenation is that any subsequent release operation will provide the required ordering for a prior
1417      consume operation. The second exception is that a concatenation is not permitted to consist entirely of
1418      ''sequenced before''. The reasons for this limitation are (1) to permit ''inter-thread happens before'' to be
1419      transitively closed and (2) the ''happens before'' relation, defined below, provides for relationships
1420      consisting entirely of ''sequenced before''.
1421
1422 18   An evaluation A happens before an evaluation B if A is sequenced before B or A inter-
1423      thread happens before B.
1424
1425
1426
1427      16) The ''dependency-ordered before'' relation is analogous to the ''synchronizes with'' relation, but uses
1428          release/consume in place of release/acquire.
1429
1430 [page 19]
1431
1432 19   A visible side effect A on an object M with respect to a value computation B of M
1433      satisfies the conditions:
1434      -- A happens before B, and
1435      -- there is no other side effect X to M such that A happens before X and X happens
1436          before B.
1437      The value of a non-atomic scalar object M, as determined by evaluation B, shall be the
1438      value stored by the visible side effect A.
1439 20   NOTE 8 If there is ambiguity about which side effect to a non-atomic object is visible, then there is a data
1440      race and the behavior is undefined.
1441
1442 21   NOTE 9 This states that operations on ordinary variables are not visibly reordered. This is not actually
1443      detectable without data races, but it is necessary to ensure that data races, as defined here, and with suitable
1444      restrictions on the use of atomics, correspond to data races in a simple interleaved (sequentially consistent)
1445      execution.
1446
1447 22   The visible sequence of side effects on an atomic object M, with respect to a value
1448      computation B of M, is a maximal contiguous sub-sequence of side effects in the
1449      modification order of M, where the first side effect is visible with respect to B, and for
1450      every subsequent side effect, it is not the case that B happens before it. The value of an
1451      atomic object M, as determined by evaluation B, shall be the value stored by some
1452      operation in the visible sequence of M with respect to B. Furthermore, if a value
1453      computation A of an atomic object M happens before a value computation B of M, and
1454      the value computed by A corresponds to the value stored by side effect X, then the value
1455      computed by B shall either equal the value computed by A, or be the value stored by side
1456      effect Y , where Y follows X in the modification order of M.
1457 23   NOTE 10 This effectively disallows compiler reordering of atomic operations to a single object, even if
1458      both operations are ''relaxed'' loads. By doing so, we effectively make the ''cache coherence'' guarantee
1459      provided by most hardware available to C atomic operations.
1460
1461 24   NOTE 11 The visible sequence depends on the ''happens before'' relation, which in turn depends on the
1462      values observed by loads of atomics, which we are restricting here. The intended reading is that there must
1463      exist an association of atomic loads with modifications they observe that, together with suitably chosen
1464      modification orders and the ''happens before'' relation derived as described above, satisfy the resulting
1465      constraints as imposed here.
1466
1467 25   The execution of a program contains a data race if it contains two conflicting actions in
1468      different threads, at least one of which is not atomic, and neither happens before the
1469      other. Any such data race results in undefined behavior.
1470 26   NOTE 12 It can be shown that programs that correctly use simple mutexes and
1471      memory_order_seq_cst operations to prevent all data races, and use no other synchronization
1472      operations, behave as though the operations executed by their constituent threads were simply interleaved,
1473      with each value computation of an object being the last value stored in that interleaving. This is normally
1474      referred to as ''sequential consistency''. However, this applies only to data-race-free programs, and data-
1475      race-free programs cannot observe most program transformations that do not change single-threaded
1476      program semantics. In fact, most single-threaded program transformations continue to be allowed, since
1477      any program that behaves differently as a result must contain undefined behavior.
1478
1479 [page 20]
1480
1481 27   NOTE 13 Compiler transformations that introduce assignments to a potentially shared memory location
1482      that would not be modified by the abstract machine are generally precluded by this standard, since such an
1483      assignment might overwrite another assignment by a different thread in cases in which an abstract machine
1484      execution would not have encountered a data race. This includes implementations of data member
1485      assignment that overwrite adjacent members in separate memory locations. We also generally preclude
1486      reordering of atomic loads in cases in which the atomics in question may alias, since this may violate the
1487      "visible sequence" rules.
1488
1489 28   NOTE 14 Transformations that introduce a speculative read of a potentially shared memory location may
1490      not preserve the semantics of the program as defined in this standard, since they potentially introduce a data
1491      race. However, they are typically valid in the context of an optimizing compiler that targets a specific
1492      machine with well-defined semantics for data races. They would be invalid for a hypothetical machine that
1493      is not tolerant of races or provides hardware race detection.
1494
1495
1496
1497
1498 [page 21]
1499
1500     5.2 Environmental considerations
1501     5.2.1 Character sets
1502 1   Two sets of characters and their associated collating sequences shall be defined: the set in
1503     which source files are written (the source character set), and the set interpreted in the
1504     execution environment (the execution character set). Each set is further divided into a
1505     basic character set, whose contents are given by this subclause, and a set of zero or more
1506     locale-specific members (which are not members of the basic character set) called
1507     extended characters. The combined set is also called the extended character set. The
1508     values of the members of the execution character set are implementation-defined.
1509 2   In a character constant or string literal, members of the execution character set shall be
1510     represented by corresponding members of the source character set or by escape
1511     sequences consisting of the backslash \ followed by one or more characters. A byte with
1512     all bits set to 0, called the null character, shall exist in the basic execution character set; it
1513     is used to terminate a character string.
1514 3   Both the basic source and basic execution character sets shall have the following
1515     members: the 26 uppercase letters of the Latin alphabet
1516             A    B   C      D   E   F    G    H    I    J    K    L   M
1517             N    O   P      Q   R   S    T    U    V    W    X    Y   Z
1518     the 26 lowercase 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 10 decimal digits
1522             0    1   2      3   4   5    6    7    8    9
1523     the following 29 graphic characters
1524             !    "   #      %   &   '    (    )    *    +    ,    -   .    /    :
1525             ;    <   =      >   ?   [    \    ]    ^    _    {    |   }    ~
1526     the space character, and control characters representing horizontal tab, vertical tab, and
1527     form feed. The representation of each member of the source and execution basic
1528     character sets shall fit in a byte. In both the source and execution basic character sets, the
1529     value of each character after 0 in the above list of decimal digits shall be one greater than
1530     the value of the previous. In source files, there shall be some way of indicating the end of
1531     each line of text; this International Standard treats such an end-of-line indicator as if it
1532     were a single new-line character. In the basic execution character set, there shall be
1533     control characters representing alert, backspace, carriage return, and new line. If any
1534     other characters are encountered in a source file (except in an identifier, a character
1535     constant, a string literal, a header name, a comment, or a preprocessing token that is never
1536
1537 [page 22]
1538
1539     converted to a token), the behavior is undefined.
1540 4   A letter is an uppercase letter or a lowercase letter as defined above; in this International
1541     Standard the term does not include other characters that are letters in other alphabets.
1542 5   The universal character name construct provides a way to name other characters.
1543     Forward references: universal character names (6.4.3), character constants (6.4.4.4),
1544     preprocessing directives (6.10), string literals (6.4.5), comments (6.4.9), string (7.1.1).
1545     5.2.1.1 Trigraph sequences
1546 1   Before any other processing takes place, each occurrence of one of the following
1547     sequences of three characters (called trigraph sequences17)) is replaced with the
1548     corresponding single character.
1549            ??=      #                       ??)      ]                       ??!     |
1550            ??(      [                       ??'      ^                       ??>     }
1551            ??/      \                       ??<      {                       ??-     ~
1552     No other trigraph sequences exist. Each ? that does not begin one of the trigraphs listed
1553     above is not changed.
1554 2   EXAMPLE 1
1555               ??=define arraycheck(a, b) a??(b??) ??!??! b??(a??)
1556     becomes
1557               #define arraycheck(a, b) a[b] || b[a]
1558
1559 3   EXAMPLE 2      The following source line
1560               printf("Eh???/n");
1561     becomes (after replacement of the trigraph sequence ??/)
1562               printf("Eh?\n");
1563
1564     5.2.1.2 Multibyte characters
1565 1   The source character set may contain multibyte characters, used to represent members of
1566     the extended character set. The execution character set may also contain multibyte
1567     characters, which need not have the same encoding as for the source character set. For
1568     both character sets, the following shall hold:
1569     -- The basic character set shall be present and each character shall be encoded as a
1570       single byte.
1571     -- The presence, meaning, and representation of any additional members is locale-
1572       specific.
1573
1574     17) The trigraph sequences enable the input of characters that are not defined in the Invariant Code Set as
1575         described in ISO/IEC 646, which is a subset of the seven-bit US ASCII code set.
1576
1577 [page 23]
1578
1579     -- A multibyte character set may have a state-dependent encoding, wherein each
1580       sequence of multibyte characters begins in an initial shift state and enters other
1581       locale-specific shift states when specific multibyte characters are encountered in the
1582       sequence. While in the initial shift state, all single-byte characters retain their usual
1583       interpretation and do not alter the shift state. The interpretation for subsequent bytes
1584       in the sequence is a function of the current shift state.
1585     -- A byte with all bits zero shall be interpreted as a null character independent of shift
1586       state. Such a byte shall not occur as part of any other multibyte character.
1587 2   For source files, the following shall hold:
1588     -- An identifier, comment, string literal, character constant, or header name shall begin
1589       and end in the initial shift state.
1590     -- An identifier, comment, string literal, character constant, or header name shall consist
1591       of a sequence of valid multibyte characters.
1592     5.2.2 Character display semantics
1593 1   The active position is that location on a display device where the next character output by
1594     the fputc function would appear. The intent of writing a printing character (as defined
1595     by the isprint function) to a display device is to display a graphic representation of
1596     that character at the active position and then advance the active position to the next
1597     position on the current line. The direction of writing is locale-specific. If the active
1598     position is at the final position of a line (if there is one), the behavior of the display device
1599     is unspecified.
1600 2   Alphabetic escape sequences representing nongraphic characters in the execution
1601     character set are intended to produce actions on display devices as follows:
1602     \a (alert) Produces an audible or visible alert without changing the active position.
1603     \b (backspace) Moves the active position to the previous position on the current line. If
1604        the active position is at the initial position of a line, the behavior of the display
1605        device is unspecified.
1606     \f ( form feed) Moves the active position to the initial position at the start of the next
1607        logical page.
1608     \n (new line) Moves the active position to the initial position of the next line.
1609     \r (carriage return) Moves the active position to the initial position of the current line.
1610     \t (horizontal tab) Moves the active position to the next horizontal tabulation position
1611        on the current line. If the active position is at or past the last defined horizontal
1612        tabulation position, the behavior of the display device is unspecified.
1613     \v (vertical tab) Moves the active position to the initial position of the next vertical
1614        tabulation position. If the active position is at or past the last defined vertical
1615 [page 24]
1616
1617          tabulation position, the behavior of the display device is unspecified.
1618 3   Each of these escape sequences shall produce a unique implementation-defined value
1619     which can be stored in a single char object. The external representations in a text file
1620     need not be identical to the internal representations, and are outside the scope of this
1621     International Standard.
1622     Forward references: the isprint function (7.4.1.8), the fputc function (7.21.7.3).
1623     5.2.3 Signals and interrupts
1624 1   Functions shall be implemented such that they may be interrupted at any time by a signal,
1625     or may be called by a signal handler, or both, with no alteration to earlier, but still active,
1626     invocations' control flow (after the interruption), function return values, or objects with
1627     automatic storage duration. All such objects shall be maintained outside the function
1628     image (the instructions that compose the executable representation of a function) on a
1629     per-invocation basis.
1630     5.2.4 Environmental limits
1631 1   Both the translation and execution environments constrain the implementation of
1632     language translators and libraries. The following summarizes the language-related
1633     environmental limits on a conforming implementation; the library-related limits are
1634     discussed in clause 7.
1635     5.2.4.1 Translation limits
1636 1   The implementation shall be able to translate and execute at least one program that
1637     contains at least one instance of every one of the following limits:18)
1638     -- 127 nesting levels of blocks
1639     -- 63 nesting levels of conditional inclusion
1640     -- 12 pointer, array, and function declarators (in any combinations) modifying an
1641       arithmetic, structure, union, or void type in a declaration
1642     -- 63 nesting levels of parenthesized declarators within a full declarator
1643     -- 63 nesting levels of parenthesized expressions within a full expression
1644     -- 63 significant initial characters in an internal identifier or a macro name (each
1645       universal character name or extended source character is considered a single
1646       character)
1647     -- 31 significant initial characters in an external identifier (each universal character name
1648       specifying a short identifier of 0000FFFF or less is considered 6 characters, each
1649
1650
1651     18) Implementations should avoid imposing fixed translation limits whenever possible.
1652
1653 [page 25]
1654
1655          universal character name specifying a short identifier of 00010000 or more is
1656          considered 10 characters, and each extended source character is considered the same
1657          number of characters as the corresponding universal character name, if any)19)
1658     -- 4095 external identifiers in one translation unit
1659     -- 511 identifiers with block scope declared in one block
1660     -- 4095 macro identifiers simultaneously defined in one preprocessing translation unit
1661     -- 127 parameters in one function definition
1662     -- 127 arguments in one function call
1663     -- 127 parameters in one macro definition
1664     -- 127 arguments in one macro invocation
1665     -- 4095 characters in a logical source line
1666     -- 4095 characters in a string literal (after concatenation)
1667     -- 65535 bytes in an object (in a hosted environment only)
1668     -- 15 nesting levels for #included files
1669     -- 1023 case labels for a switch statement (excluding those for any nested switch
1670       statements)
1671     -- 1023 members in a single structure or union
1672     -- 1023 enumeration constants in a single enumeration
1673     -- 63 levels of nested structure or union definitions in a single struct-declaration-list
1674     5.2.4.2 Numerical limits
1675 1   An implementation is required to document all the limits specified in this subclause,
1676     which are specified in the headers <limits.h> and <float.h>. Additional limits are
1677     specified in <stdint.h>.
1678     Forward references: integer types <stdint.h> (7.20).
1679     5.2.4.2.1 Sizes of integer types <limits.h>
1680 1   The values given below shall be replaced by constant expressions suitable for use in #if
1681     preprocessing directives. Moreover, except for CHAR_BIT and MB_LEN_MAX, the
1682     following shall be replaced by expressions that have the same type as would an
1683     expression that is an object of the corresponding type converted according to the integer
1684     promotions. Their implementation-defined values shall be equal or greater in magnitude
1685
1686
1687     19) See ''future language directions'' (6.11.3).
1688
1689 [page 26]
1690
1691 (absolute value) to those shown, with the same sign.
1692 -- number of bits for smallest object that is not a bit-field (byte)
1693   CHAR_BIT                                            8
1694 -- minimum value for an object of type signed char
1695   SCHAR_MIN                                -127 // -(27 - 1)
1696 -- maximum value for an object of type signed char
1697   SCHAR_MAX                                +127 // 27 - 1
1698 -- maximum value for an object of type unsigned char
1699   UCHAR_MAX                                 255 // 28 - 1
1700 -- minimum value for an object of type char
1701   CHAR_MIN                               see below
1702 -- maximum value for an object of type char
1703   CHAR_MAX                              see below
1704 -- maximum number of bytes in a multibyte character, for any supported locale
1705   MB_LEN_MAX                                    1
1706 -- minimum value for an object of type short int
1707   SHRT_MIN                               -32767 // -(215 - 1)
1708 -- maximum value for an object of type short int
1709   SHRT_MAX                               +32767 // 215 - 1
1710 -- maximum value for an object of type unsigned short int
1711   USHRT_MAX                               65535 // 216 - 1
1712 -- minimum value for an object of type int
1713   INT_MIN                                 -32767 // -(215 - 1)
1714 -- maximum value for an object of type int
1715   INT_MAX                                +32767 // 215 - 1
1716 -- maximum value for an object of type unsigned int
1717   UINT_MAX                                65535 // 216 - 1
1718 -- minimum value for an object of type long int
1719   LONG_MIN                         -2147483647 // -(231 - 1)
1720 -- maximum value for an object of type long int
1721   LONG_MAX                         +2147483647 // 231 - 1
1722 -- maximum value for an object of type unsigned long int
1723   ULONG_MAX                         4294967295 // 232 - 1
1724
1725
1726 [page 27]
1727
1728     -- minimum value for an object of type long long int
1729       LLONG_MIN          -9223372036854775807 // -(263 - 1)
1730     -- maximum value for an object of type long long int
1731       LLONG_MAX          +9223372036854775807 // 263 - 1
1732     -- maximum value for an object of type unsigned long long int
1733       ULLONG_MAX         18446744073709551615 // 264 - 1
1734 2   If the value of an object of type char is treated as a signed integer when used in an
1735     expression, the value of CHAR_MIN shall be the same as that of SCHAR_MIN and the
1736     value of CHAR_MAX shall be the same as that of SCHAR_MAX. Otherwise, the value of
1737     CHAR_MIN shall be 0 and the value of CHAR_MAX shall be the same as that of
1738     UCHAR_MAX.20) The value UCHAR_MAX shall equal 2CHAR_BIT - 1.
1739     Forward references: representations of types (6.2.6), conditional inclusion (6.10.1).
1740     5.2.4.2.2 Characteristics of floating types <float.h>
1741 1   The characteristics of floating types are defined in terms of a model that describes a
1742     representation of floating-point numbers and values that provide information about an
1743     implementation's floating-point arithmetic.21) The following parameters are used to
1744     define the model for each floating-point type:
1745            s          sign ((+-)1)
1746            b          base or radix of exponent representation (an integer > 1)
1747            e          exponent (an integer between a minimum emin and a maximum emax )
1748            p          precision (the number of base-b digits in the significand)
1749             fk        nonnegative integers less than b (the significand digits)
1750 2   A floating-point number (x) is defined by the following model:
1751                        p
1752            x = sb e   (Sum) f k b-k ,
1753                       k=1
1754                                     emin <= e <= emax
1755
1756 3   In addition to normalized floating-point numbers ( f 1 > 0 if x != 0), floating types may be
1757     able to contain other kinds of floating-point numbers, such as subnormal floating-point
1758     numbers (x != 0, e = emin , f 1 = 0) and unnormalized floating-point numbers (x != 0,
1759     e > emin , f 1 = 0), and values that are not floating-point numbers, such as infinities and
1760     NaNs. A NaN is an encoding signifying Not-a-Number. A quiet NaN propagates
1761     through almost every arithmetic operation without raising a floating-point exception; a
1762     signaling NaN generally raises a floating-point exception when occurring as an
1763
1764
1765     20) See 6.2.5.
1766     21) The floating-point model is intended to clarify the description of each floating-point characteristic and
1767         does not require the floating-point arithmetic of the implementation to be identical.
1768
1769 [page 28]
1770
1771     arithmetic operand.22)
1772 4   An implementation may give zero and non-numeric values (such as infinities and NaNs) a
1773     sign or may leave them unsigned. Wherever such values are unsigned, any requirement
1774     in this International Standard to retrieve the sign shall produce an unspecified sign, and
1775     any requirement to set the sign shall be ignored.
1776 5   The minimum range of representable values for a floating type is the most negative finite
1777     floating-point number representable in that type through the most positive finite floating-
1778     point number representable in that type. In addition, if negative infinity is representable
1779     in a type, the range of that type is extended to all negative real numbers; likewise, if
1780     positive infinity is representable in a type, the range of that type is extended to all positive
1781     real numbers.
1782 6   The accuracy of the floating-point operations (+, -, *, /) and of the library functions in
1783     <math.h> and <complex.h> that return floating-point results is implementation-
1784     defined, as is the accuracy of the conversion between floating-point internal
1785     representations and string representations performed by the library functions in
1786     <stdio.h>, <stdlib.h>, and <wchar.h>. The implementation may state that the
1787     accuracy is unknown.
1788 7   All integer values in the <float.h> header, except FLT_ROUNDS, shall be constant
1789     expressions suitable for use in #if preprocessing directives; all floating values shall be
1790     constant expressions. All except DECIMAL_DIG, FLT_EVAL_METHOD, FLT_RADIX,
1791     and FLT_ROUNDS have separate names for all three floating-point types. The floating-
1792     point model representation is provided for all values except FLT_EVAL_METHOD and
1793     FLT_ROUNDS.
1794 8   The rounding mode for floating-point addition is characterized by the implementation-
1795     defined value of FLT_ROUNDS:23)
1796           -1      indeterminable
1797            0      toward zero
1798            1      to nearest
1799            2      toward positive infinity
1800            3      toward negative infinity
1801     All other values for FLT_ROUNDS characterize implementation-defined rounding
1802     behavior.
1803
1804
1805     22) IEC 60559:1989 specifies quiet and signaling NaNs. For implementations that do not support
1806         IEC 60559:1989, the terms quiet NaN and signaling NaN are intended to apply to encodings with
1807         similar behavior.
1808     23) Evaluation of FLT_ROUNDS correctly reflects any execution-time change of rounding mode through
1809         the function fesetround in <fenv.h>.
1810
1811 [page 29]
1812
1813 9    Except for assignment and cast (which remove all extra range and precision), the values
1814      yielded by operators with floating operands and values subject to the usual arithmetic
1815      conversions and of floating constants are evaluated to a format whose range and precision
1816      may be greater than required by the type. The use of evaluation formats is characterized
1817      by the implementation-defined value of FLT_EVAL_METHOD:24)
1818             -1         indeterminable;
1819               0        evaluate all operations and constants just to the range and precision of the
1820                        type;
1821               1        evaluate operations and constants of type float and double to the
1822                        range and precision of the double type, evaluate long double
1823                        operations and constants to the range and precision of the long double
1824                        type;
1825               2        evaluate all operations and constants to the range and precision of the
1826                        long double type.
1827      All other negative values for FLT_EVAL_METHOD characterize implementation-defined
1828      behavior.
1829 10   The presence or absence of subnormal numbers is characterized by the implementation-
1830      defined     values     of    FLT_HAS_SUBNORM,          DBL_HAS_SUBNORM,           and
1831      LDBL_HAS_SUBNORM:
1832             -1       indeterminable25)
1833              0       absent26) (type does not support subnormal numbers)
1834              1       present (type does support subnormal numbers)
1835 11   The values given in the following list shall be replaced by constant expressions with
1836      implementation-defined values that are greater or equal in magnitude (absolute value) to
1837      those shown, with the same sign:
1838      -- radix of exponent representation, b
1839        FLT_RADIX                                                    2
1840
1841
1842
1843
1844      24) The evaluation method determines evaluation formats of expressions involving all floating types, not
1845          just real types. For example, if FLT_EVAL_METHOD is 1, then the product of two float
1846          _Complex operands is represented in the double _Complex format, and its parts are evaluated to
1847          double.
1848      25) Characterization as indeterminable is intended if floating-point operations do not consistently interpret
1849          subnormal representations as zero, nor as nonzero.
1850      26) Characterization as absent is intended if no floating-point operations produce subnormal results from
1851          non-subnormal inputs, even if the type format includes representations of subnormal numbers.
1852
1853 [page 30]
1854
1855 -- number of base-FLT_RADIX digits in the floating-point significand, p
1856    FLT_MANT_DIG
1857    DBL_MANT_DIG
1858    LDBL_MANT_DIG
1859 -- number of decimal digits, n, such that any floating-point number with p radix b digits
1860   can be rounded to a floating-point number with n decimal digits and back again
1861   without change to the value,
1862        { p log10 b        if b is a power of 10
1863        {
1864        { [^1 + p log10 b^] otherwise
1865    FLT_DECIMAL_DIG                                   6
1866    DBL_DECIMAL_DIG                                  10
1867    LDBL_DECIMAL_DIG                                 10
1868 -- number of decimal digits, n, such that any floating-point number in the widest
1869   supported floating type with pmax radix b digits can be rounded to a floating-point
1870   number with n decimal digits and back again without change to the value,
1871        { pmax log10 b       if b is a power of 10
1872        {
1873        { [^1 + pmax log10 b^] otherwise
1874    DECIMAL_DIG                                     10
1875 -- number of decimal digits, q, such that any floating-point number with q decimal digits
1876   can be rounded into a floating-point number with p radix b digits and back again
1877   without change to the q decimal digits,
1878        { p log10 b          if b is a power of 10
1879        {
1880        { [_( p - 1) log10 b_] otherwise
1881    FLT_DIG                                          6
1882    DBL_DIG                                         10
1883    LDBL_DIG                                        10
1884 -- minimum negative integer such that FLT_RADIX raised to one less than that power is
1885   a normalized floating-point number, emin
1886    FLT_MIN_EXP
1887    DBL_MIN_EXP
1888    LDBL_MIN_EXP
1889
1890
1891
1892
1893 [page 31]
1894
1895      -- minimum negative integer such that 10 raised to that power is in the range of
1896        normalized floating-point numbers, [^log10 b emin -1 ^]
1897                                          [                  ]
1898        FLT_MIN_10_EXP                                 -37
1899        DBL_MIN_10_EXP                                 -37
1900        LDBL_MIN_10_EXP                                -37
1901      -- maximum integer such that FLT_RADIX raised to one less than that power is a
1902        representable finite floating-point number, emax
1903           FLT_MAX_EXP
1904           DBL_MAX_EXP
1905           LDBL_MAX_EXP
1906      -- maximum integer such that 10 raised to that power is in the range of representable
1907        finite floating-point numbers, [_log10 ((1 - b- p )b emax )_]
1908           FLT_MAX_10_EXP                               +37
1909           DBL_MAX_10_EXP                               +37
1910           LDBL_MAX_10_EXP                              +37
1911 12   The values given in the following list shall be replaced by constant expressions with
1912      implementation-defined values that are greater than or equal to those shown:
1913      -- maximum representable finite floating-point number, (1 - b- p )b emax
1914           FLT_MAX                                   1E+37
1915           DBL_MAX                                   1E+37
1916           LDBL_MAX                                  1E+37
1917 13   The values given in the following list shall be replaced by constant expressions with
1918      implementation-defined (positive) values that are less than or equal to those shown:
1919      -- the difference between 1 and the least value greater than 1 that is representable in the
1920        given floating point type, b1- p
1921           FLT_EPSILON                                1E-5
1922           DBL_EPSILON                                1E-9
1923           LDBL_EPSILON                               1E-9
1924      -- minimum normalized positive floating-point number, b emin -1
1925           FLT_MIN                                   1E-37
1926           DBL_MIN                                   1E-37
1927           LDBL_MIN                                  1E-37
1928
1929
1930
1931
1932 [page 32]
1933
1934      -- minimum positive floating-point number27)
1935          FLT_TRUE_MIN                                       1E-37
1936          DBL_TRUE_MIN                                       1E-37
1937          LDBL_TRUE_MIN                                      1E-37
1938      Recommended practice
1939 14   Conversion from (at least) double to decimal with DECIMAL_DIG digits and back
1940      should be the identity function.
1941 15   EXAMPLE 1 The following describes an artificial floating-point representation that meets the minimum
1942      requirements of this International Standard, and the appropriate values in a <float.h> header for type
1943      float:
1944                         6
1945            x = s16e    (Sum) f k 16-k ,
1946                        k=1
1947                                        -31 <= e <= +32
1948
1949              FLT_RADIX                                    16
1950              FLT_MANT_DIG                                  6
1951              FLT_EPSILON                     9.53674316E-07F
1952              FLT_DECIMAL_DIG                               9
1953              FLT_DIG                                       6
1954              FLT_MIN_EXP                                 -31
1955              FLT_MIN                         2.93873588E-39F
1956              FLT_MIN_10_EXP                              -38
1957              FLT_MAX_EXP                                 +32
1958              FLT_MAX                         3.40282347E+38F
1959              FLT_MAX_10_EXP                              +38
1960
1961 16   EXAMPLE 2 The following describes floating-point representations that also meet the requirements for
1962      single-precision and double-precision numbers in IEC 60559,28) and the appropriate values in a
1963      <float.h> header for types float and double:
1964                        24
1965            x f = s2e   (Sum) f k 2-k ,
1966                        k=1
1967                                       -125 <= e <= +128
1968
1969                        53
1970            x d = s2e   (Sum) f k 2-k ,
1971                        k=1
1972                                       -1021 <= e <= +1024
1973
1974              FLT_RADIX                                     2
1975              DECIMAL_DIG                                  17
1976              FLT_MANT_DIG                                 24
1977              FLT_EPSILON                     1.19209290E-07F // decimal constant
1978              FLT_EPSILON                            0X1P-23F // hex constant
1979              FLT_DECIMAL_DIG                               9
1980
1981
1982      27) If the presence or absence of subnormal numbers is indeterminable, then the value is intended to be a
1983          positive number no greater than the minimum normalized positive number for the type.
1984      28) The floating-point model in that standard sums powers of b from zero, so the values of the exponent
1985          limits are one less than shown here.
1986
1987 [page 33]
1988
1989         FLT_DIG                             6
1990         FLT_MIN_EXP                      -125
1991         FLT_MIN               1.17549435E-38F               //   decimal constant
1992         FLT_MIN                     0X1P-126F               //   hex constant
1993         FLT_TRUE_MIN          1.40129846E-45F               //   decimal constant
1994         FLT_TRUE_MIN                0X1P-149F               //   hex constant
1995         FLT_HAS_SUBNORM                     1
1996         FLT_MIN_10_EXP                    -37
1997         FLT_MAX_EXP                      +128
1998         FLT_MAX               3.40282347E+38F               // decimal constant
1999         FLT_MAX               0X1.fffffeP127F               // hex constant
2000         FLT_MAX_10_EXP                    +38
2001         DBL_MANT_DIG                       53
2002         DBL_EPSILON    2.2204460492503131E-16               // decimal constant
2003         DBL_EPSILON                   0X1P-52               // hex constant
2004         DBL_DECIMAL_DIG                    17
2005         DBL_DIG                            15
2006         DBL_MIN_EXP                     -1021
2007         DBL_MIN      2.2250738585072014E-308                //   decimal constant
2008         DBL_MIN                     0X1P-1022               //   hex constant
2009         DBL_TRUE_MIN 4.9406564584124654E-324                //   decimal constant
2010         DBL_TRUE_MIN                0X1P-1074               //   hex constant
2011         DBL_HAS_SUBNORM                     1
2012         DBL_MIN_10_EXP                   -307
2013         DBL_MAX_EXP                     +1024
2014         DBL_MAX      1.7976931348623157E+308                // decimal constant
2015         DBL_MAX        0X1.fffffffffffffP1023               // hex constant
2016         DBL_MAX_10_EXP                   +308
2017 If a type wider than double were supported, then DECIMAL_DIG would be greater than 17. For
2018 example, if the widest type were to use the minimal-width IEC 60559 double-extended format (64 bits of
2019 precision), then DECIMAL_DIG would be 21.
2020
2021 Forward references:        conditional inclusion (6.10.1), complex arithmetic
2022 <complex.h> (7.3), extended multibyte and wide character utilities <wchar.h>
2023 (7.28), floating-point environment <fenv.h> (7.6), general utilities <stdlib.h>
2024 (7.22), input/output <stdio.h> (7.21), mathematics <math.h> (7.12).
2025
2026
2027
2028
2029 [page 34]
2030
2031
2032     6. Language
2033     6.1 Notation
2034 1   In the syntax notation used in this clause, syntactic categories (nonterminals) are
2035     indicated by italic type, and literal words and character set members (terminals) by bold
2036     type. A colon (:) following a nonterminal introduces its definition. Alternative
2037     definitions are listed on separate lines, except when prefaced by the words ''one of''. An
2038     optional symbol is indicated by the subscript ''opt'', so that
2039              { expressionopt }
2040     indicates an optional expression enclosed in braces.
2041 2   When syntactic categories are referred to in the main text, they are not italicized and
2042     words are separated by spaces instead of hyphens.
2043 3   A summary of the language syntax is given in annex A.
2044     6.2 Concepts
2045     6.2.1 Scopes of identifiers
2046 1   An identifier can denote an object; a function; a tag or a member of a structure, union, or
2047     enumeration; a typedef name; a label name; a macro name; or a macro parameter. The
2048     same identifier can denote different entities at different points in the program. A member
2049     of an enumeration is called an enumeration constant. Macro names and macro
2050     parameters are not considered further here, because prior to the semantic phase of
2051     program translation any occurrences of macro names in the source file are replaced by the
2052     preprocessing token sequences that constitute their macro definitions.
2053 2   For each different entity that an identifier designates, the identifier is visible (i.e., can be
2054     used) only within a region of program text called its scope. Different entities designated
2055     by the same identifier either have different scopes, or are in different name spaces. There
2056     are four kinds of scopes: function, file, block, and function prototype. (A function
2057     prototype is a declaration of a function that declares the types of its parameters.)
2058 3   A label name is the only kind of identifier that has function scope. It can be used (in a
2059     goto statement) anywhere in the function in which it appears, and is declared implicitly
2060     by its syntactic appearance (followed by a : and a statement).
2061 4   Every other identifier has scope determined by the placement of its declaration (in a
2062     declarator or type specifier). If the declarator or type specifier that declares the identifier
2063     appears outside of any block or list of parameters, the identifier has file scope, which
2064     terminates at the end of the translation unit. If the declarator or type specifier that
2065     declares the identifier appears inside a block or within the list of parameter declarations in
2066     a function definition, the identifier has block scope, which terminates at the end of the
2067     associated block. If the declarator or type specifier that declares the identifier appears
2068
2069 [page 35]
2070
2071     within the list of parameter declarations in a function prototype (not part of a function
2072     definition), the identifier has function prototype scope, which terminates at the end of the
2073     function declarator. If an identifier designates two different entities in the same name
2074     space, the scopes might overlap. If so, the scope of one entity (the inner scope) will end
2075     strictly before the scope of the other entity (the outer scope). Within the inner scope, the
2076     identifier designates the entity declared in the inner scope; the entity declared in the outer
2077     scope is hidden (and not visible) within the inner scope.
2078 5   Unless explicitly stated otherwise, where this International Standard uses the term
2079     ''identifier'' to refer to some entity (as opposed to the syntactic construct), it refers to the
2080     entity in the relevant name space whose declaration is visible at the point the identifier
2081     occurs.
2082 6   Two identifiers have the same scope if and only if their scopes terminate at the same
2083     point.
2084 7   Structure, union, and enumeration tags have scope that begins just after the appearance of
2085     the tag in a type specifier that declares the tag. Each enumeration constant has scope that
2086     begins just after the appearance of its defining enumerator in an enumerator list. Any
2087     other identifier has scope that begins just after the completion of its declarator.
2088 8   As a special case, a type name (which is not a declaration of an identifier) is considered to
2089     have a scope that begins just after the place within the type name where the omitted
2090     identifier would appear were it not omitted.
2091     Forward references: declarations (6.7), function calls (6.5.2.2), function definitions
2092     (6.9.1), identifiers (6.4.2), macro replacement (6.10.3), name spaces of identifiers (6.2.3),
2093     source file inclusion (6.10.2), statements (6.8).
2094     6.2.2 Linkages of identifiers
2095 1   An identifier declared in different scopes or in the same scope more than once can be
2096     made to refer to the same object or function by a process called linkage.29) There are
2097     three kinds of linkage: external, internal, and none.
2098 2   In the set of translation units and libraries that constitutes an entire program, each
2099     declaration of a particular identifier with external linkage denotes the same object or
2100     function. Within one translation unit, each declaration of an identifier with internal
2101     linkage denotes the same object or function. Each declaration of an identifier with no
2102     linkage denotes a unique entity.
2103 3   If the declaration of a file scope identifier for an object or a function contains the storage-
2104     class specifier static, the identifier has internal linkage.30)
2105
2106
2107
2108     29) There is no linkage between different identifiers.
2109
2110 [page 36]
2111
2112 4   For an identifier declared with the storage-class specifier extern in a scope in which a
2113     prior declaration of that identifier is visible,31) if the prior declaration specifies internal or
2114     external linkage, the linkage of the identifier at the later declaration is the same as the
2115     linkage specified at the prior declaration. If no prior declaration is visible, or if the prior
2116     declaration specifies no linkage, then the identifier has external linkage.
2117 5   If the declaration of an identifier for a function has no storage-class specifier, its linkage
2118     is determined exactly as if it were declared with the storage-class specifier extern. If
2119     the declaration of an identifier for an object has file scope and no storage-class specifier,
2120     its linkage is external.
2121 6   The following identifiers have no linkage: an identifier declared to be anything other than
2122     an object or a function; an identifier declared to be a function parameter; a block scope
2123     identifier for an object declared without the storage-class specifier extern.
2124 7   If, within a translation unit, the same identifier appears with both internal and external
2125     linkage, the behavior is undefined.
2126     Forward references: declarations (6.7), expressions (6.5), external definitions (6.9),
2127     statements (6.8).
2128     6.2.3 Name spaces of identifiers
2129 1   If more than one declaration of a particular identifier is visible at any point in a
2130     translation unit, the syntactic context disambiguates uses that refer to different entities.
2131     Thus, there are separate name spaces for various categories of identifiers, as follows:
2132     -- label names (disambiguated by the syntax of the label declaration and use);
2133     -- the tags of structures, unions, and enumerations (disambiguated by following any32)
2134       of the keywords struct, union, or enum);
2135     -- the members of structures or unions; each structure or union has a separate name
2136       space for its members (disambiguated by the type of the expression used to access the
2137       member via the . or -> operator);
2138     -- all other identifiers, called ordinary identifiers (declared in ordinary declarators or as
2139       enumeration constants).
2140     Forward references: enumeration specifiers (6.7.2.2), labeled statements (6.8.1),
2141     structure and union specifiers (6.7.2.1), structure and union members (6.5.2.3), tags
2142     (6.7.2.3), the goto statement (6.8.6.1).
2143
2144     30) A function declaration can contain the storage-class specifier static only if it is at file scope; see
2145         6.7.1.
2146     31) As specified in 6.2.1, the later declaration might hide the prior declaration.
2147     32) There is only one name space for tags even though three are possible.
2148
2149 [page 37]
2150
2151     6.2.4 Storage durations of objects
2152 1   An object has a storage duration that determines its lifetime. There are four storage
2153     durations: static, thread, automatic, and allocated. Allocated storage is described in
2154     7.22.3.
2155 2   The lifetime of an object is the portion of program execution during which storage is
2156     guaranteed to be reserved for it. An object exists, has a constant address,33) and retains
2157     its last-stored value throughout its lifetime.34) If an object is referred to outside of its
2158     lifetime, the behavior is undefined. The value of a pointer becomes indeterminate when
2159     the object it points to (or just past) reaches the end of its lifetime.
2160 3   An object whose identifier is declared without the storage-class specifier
2161     _Thread_local, and either with external or internal linkage or with the storage-class
2162     specifier static, has static storage duration. Its lifetime is the entire execution of the
2163     program and its stored value is initialized only once, prior to program startup.
2164 4   An object whose identifier is declared with the storage-class specifier _Thread_local
2165     has thread storage duration. Its lifetime is the entire execution of the thread for which it
2166     is created, and its stored value is initialized when the thread is started. There is a distinct
2167     object per thread, and use of the declared name in an expression refers to the object
2168     associated with the thread evaluating the expression. The result of attempting to
2169     indirectly access an object with thread storage duration from a thread other than the one
2170     with which the object is associated is implementation-defined.
2171 5   An object whose identifier is declared with no linkage and without the storage-class
2172     specifier static has automatic storage duration, as do some compound literals. The
2173     result of attempting to indirectly access an object with automatic storage duration from a
2174     thread other than the one with which the object is associated is implementation-defined.
2175 6   For such an object that does not have a variable length array type, its lifetime extends
2176     from entry into the block with which it is associated until execution of that block ends in
2177     any way. (Entering an enclosed block or calling a function suspends, but does not end,
2178     execution of the current block.) If the block is entered recursively, a new instance of the
2179     object is created each time. The initial value of the object is indeterminate. If an
2180     initialization is specified for the object, it is performed each time the declaration or
2181     compound literal is reached in the execution of the block; otherwise, the value becomes
2182     indeterminate each time the declaration is reached.
2183
2184
2185
2186     33) The term ''constant address'' means that two pointers to the object constructed at possibly different
2187         times will compare equal. The address may be different during two different executions of the same
2188         program.
2189     34) In the case of a volatile object, the last store need not be explicit in the program.
2190
2191 [page 38]
2192
2193 7   For such an object that does have a variable length array type, its lifetime extends from
2194     the declaration of the object until execution of the program leaves the scope of the
2195     declaration.35) If the scope is entered recursively, a new instance of the object is created
2196     each time. The initial value of the object is indeterminate.
2197 8   A non-lvalue expression with structure or union type, where the structure or union
2198     contains a member with array type (including, recursively, members of all contained
2199     structures and unions) refers to an object with automatic storage duration and temporary
2200     lifetime.36) Its lifetime begins when the expression is evaluated and its initial value is the
2201     value of the expression. Its lifetime ends when the evaluation of the containing full
2202     expression or full declarator ends. Any attempt to modify an object with temporary
2203     lifetime results in undefined behavior.
2204     Forward references: array declarators (6.7.6.2), compound literals (6.5.2.5), declarators
2205     (6.7.6), function calls (6.5.2.2), initialization (6.7.9), statements (6.8).
2206     6.2.5 Types
2207 1   The meaning of a value stored in an object or returned by a function is determined by the
2208     type of the expression used to access it. (An identifier declared to be an object is the
2209     simplest such expression; the type is specified in the declaration of the identifier.) Types
2210     are partitioned into object types (types that describe objects) and function types (types
2211     that describe functions). At various points within a translation unit an object type may be
2212     incomplete (lacking sufficient information to determine the size of objects of that type) or
2213     complete (having sufficient information).37)
2214 2   An object declared as type _Bool is large enough to store the values 0 and 1.
2215 3   An object declared as type char is large enough to store any member of the basic
2216     execution character set. If a member of the basic execution character set is stored in a
2217     char object, its value is guaranteed to be nonnegative. If any other character is stored in
2218     a char object, the resulting value is implementation-defined but shall be within the range
2219     of values that can be represented in that type.
2220 4   There are five standard signed integer types, designated as signed char, short
2221     int, int, long int, and long long int. (These and other types may be
2222     designated in several additional ways, as described in 6.7.2.) There may also be
2223     implementation-defined extended signed integer types.38) The standard and extended
2224     signed integer types are collectively called signed integer types.39)
2225
2226     35) Leaving the innermost block containing the declaration, or jumping to a point in that block or an
2227         embedded block prior to the declaration, leaves the scope of the declaration.
2228     36) The address of such an object is taken implicitly when an array member is accessed.
2229     37) A type may be incomplete or complete throughout an entire translation unit, or it may change states at
2230         different points within a translation unit.
2231
2232 [page 39]
2233
2234 5    An object declared as type signed char occupies the same amount of storage as a
2235      ''plain'' char object. A ''plain'' int object has the natural size suggested by the
2236      architecture of the execution environment (large enough to contain any value in the range
2237      INT_MIN to INT_MAX as defined in the header <limits.h>).
2238 6    For each of the signed integer types, there is a corresponding (but different) unsigned
2239      integer type (designated with the keyword unsigned) that uses the same amount of
2240      storage (including sign information) and has the same alignment requirements. The type
2241      _Bool and the unsigned integer types that correspond to the standard signed integer
2242      types are the standard unsigned integer types. The unsigned integer types that
2243      correspond to the extended signed integer types are the extended unsigned integer types.
2244      The standard and extended unsigned integer types are collectively called unsigned integer
2245      types.40)
2246 7    The standard signed integer types and standard unsigned integer types are collectively
2247      called the standard integer types, the extended signed integer types and extended
2248      unsigned integer types are collectively called the extended integer types.
2249 8    For any two integer types with the same signedness and different integer conversion rank
2250      (see 6.3.1.1), the range of values of the type with smaller integer conversion rank is a
2251      subrange of the values of the other type.
2252 9    The range of nonnegative values of a signed integer type is a subrange of the
2253      corresponding unsigned integer type, and the representation of the same value in each
2254      type is the same.41) A computation involving unsigned operands can never overflow,
2255      because a result that cannot be represented by the resulting unsigned integer type is
2256      reduced modulo the number that is one greater than the largest value that can be
2257      represented by the resulting type.
2258 10   There are three real floating types, designated as float, double, and long
2259      double.42) The set of values of the type float is a subset of the set of values of the
2260      type double; the set of values of the type double is a subset of the set of values of the
2261      type long double.
2262
2263
2264      38) Implementation-defined keywords shall have the form of an identifier reserved for any use as
2265          described in 7.1.3.
2266      39) Therefore, any statement in this Standard about signed integer types also applies to the extended
2267          signed integer types.
2268      40) Therefore, any statement in this Standard about unsigned integer types also applies to the extended
2269          unsigned integer types.
2270      41) The same representation and alignment requirements are meant to imply interchangeability as
2271          arguments to functions, return values from functions, and members of unions.
2272      42) See ''future language directions'' (6.11.1).
2273
2274 [page 40]
2275
2276 11   There are three complex types, designated as float _Complex, double
2277      _Complex, and long double _Complex.43) (Complex types are a conditional
2278      feature that implementations need not support; see 6.10.8.3.) The real floating and
2279      complex types are collectively called the floating types.
2280 12   For each floating type there is a corresponding real type, which is always a real floating
2281      type. For real floating types, it is the same type. For complex types, it is the type given
2282      by deleting the keyword _Complex from the type name.
2283 13   Each complex type has the same representation and alignment requirements as an array
2284      type containing exactly two elements of the corresponding real type; the first element is
2285      equal to the real part, and the second element to the imaginary part, of the complex
2286      number.
2287 14   The type char, the signed and unsigned integer types, and the floating types are
2288      collectively called the basic types. The basic types are complete object types. Even if the
2289      implementation defines two or more basic types to have the same representation, they are
2290      nevertheless different types.44)
2291 15   The three types char, signed char, and unsigned char are collectively called
2292      the character types. The implementation shall define char to have the same range,
2293      representation, and behavior as either signed char or unsigned char.45)
2294 16   An enumeration comprises a set of named integer constant values. Each distinct
2295      enumeration constitutes a different enumerated type.
2296 17   The type char, the signed and unsigned integer types, and the enumerated types are
2297      collectively called integer types. The integer and real floating types are collectively called
2298      real types.
2299 18   Integer and floating types are collectively called arithmetic types. Each arithmetic type
2300      belongs to one type domain: the real type domain comprises the real types, the complex
2301      type domain comprises the complex types.
2302 19   The void type comprises an empty set of values; it is an incomplete object type that
2303      cannot be completed.
2304
2305
2306
2307      43) A specification for imaginary types is in informative annex G.
2308      44) An implementation may define new keywords that provide alternative ways to designate a basic (or
2309          any other) type; this does not violate the requirement that all basic types be different.
2310          Implementation-defined keywords shall have the form of an identifier reserved for any use as
2311          described in 7.1.3.
2312      45) CHAR_MIN, defined in <limits.h>, will have one of the values 0 or SCHAR_MIN, and this can be
2313          used to distinguish the two options. Irrespective of the choice made, char is a separate type from the
2314          other two and is not compatible with either.
2315
2316 [page 41]
2317
2318 20   Any number of derived types can be constructed from the object and function types, as
2319      follows:
2320      -- An array type describes a contiguously allocated nonempty set of objects with a
2321        particular member object type, called the element type. The element type shall be
2322        complete whenever the array type is specified. Array types are characterized by their
2323        element type and by the number of elements in the array. An array type is said to be
2324        derived from its element type, and if its element type is T , the array type is sometimes
2325        called ''array of T ''. The construction of an array type from an element type is called
2326        ''array type derivation''.
2327      -- A structure type describes a sequentially allocated nonempty set of member objects
2328        (and, in certain circumstances, an incomplete array), each of which has an optionally
2329        specified name and possibly distinct type.
2330      -- A union type describes an overlapping nonempty set of member objects, each of
2331        which has an optionally specified name and possibly distinct type.
2332      -- A function type describes a function with specified return type. A function type is
2333        characterized by its return type and the number and types of its parameters. A
2334        function type is said to be derived from its return type, and if its return type is T , the
2335        function type is sometimes called ''function returning T ''. The construction of a
2336        function type from a return type is called ''function type derivation''.
2337      -- A pointer type may be derived from a function type or an object type, called the
2338        referenced type. A pointer type describes an object whose value provides a reference
2339        to an entity of the referenced type. A pointer type derived from the referenced type T
2340        is sometimes called ''pointer to T ''. The construction of a pointer type from a
2341        referenced type is called ''pointer type derivation''. A pointer type is a complete
2342        object type.
2343      These methods of constructing derived types can be applied recursively.
2344 21   Arithmetic types and pointer types are collectively called scalar types. Array and
2345      structure types are collectively called aggregate types.46)
2346 22   An array type of unknown size is an incomplete type. It is completed, for an identifier of
2347      that type, by specifying the size in a later declaration (with internal or external linkage).
2348      A structure or union type of unknown content (as described in 6.7.2.3) is an incomplete
2349      type. It is completed, for all declarations of that type, by declaring the same structure or
2350      union tag with its defining content later in the same scope.
2351
2352
2353
2354
2355      46) Note that aggregate type does not include union type because an object with union type can only
2356          contain one member at a time.
2357
2358 [page 42]
2359
2360 23   A type has known constant size if the type is not incomplete and is not a variable length
2361      array type.
2362 24   Array, function, and pointer types are collectively called derived declarator types. A
2363      declarator type derivation from a type T is the construction of a derived declarator type
2364      from T by the application of an array-type, a function-type, or a pointer-type derivation to
2365      T.
2366 25   A type is characterized by its type category, which is either the outermost derivation of a
2367      derived type (as noted above in the construction of derived types), or the type itself if the
2368      type consists of no derived types.
2369 26   Any type so far mentioned is an unqualified type. Each unqualified type has several
2370      qualified versions of its type,47) corresponding to the combinations of one, two, or all
2371      three of the const, volatile, and restrict qualifiers. The qualified or unqualified
2372      versions of a type are distinct types that belong to the same type category and have the
2373      same representation and alignment requirements.48) A derived type is not qualified by the
2374      qualifiers (if any) of the type from which it is derived.
2375 27   Further, there is the _Atomic qualifier, which may combine with volatile and
2376      restrict. The size, representation, and alignment of an _Atomic-qualified type need
2377      not be the same as those of the corresponding unqualified type. (Atomic types are a
2378      conditional feature that implementations need not support; see 6.10.8.3.)
2379 28   A pointer to void shall have the same representation and alignment requirements as a
2380      pointer to a character type.48) Similarly, pointers to qualified or unqualified versions of
2381      compatible types shall have the same representation and alignment requirements. All
2382      pointers to structure types shall have the same representation and alignment requirements
2383      as each other. All pointers to union types shall have the same representation and
2384      alignment requirements as each other. Pointers to other types need not have the same
2385      representation or alignment requirements.
2386 29   EXAMPLE 1 The type designated as ''float *'' has type ''pointer to float''. Its type category is
2387      pointer, not a floating type. The const-qualified version of this type is designated as ''float * const''
2388      whereas the type designated as ''const float *'' is not a qualified type -- its type is ''pointer to const-
2389      qualified float'' and is a pointer to a qualified type.
2390
2391 30   EXAMPLE 2 The type designated as ''struct tag (*[5])(float)'' has type ''array of pointer to
2392      function returning struct tag''. The array has length five and the function has a single parameter of type
2393      float. Its type category is array.
2394
2395      Forward references: compatible type and composite type (6.2.7), declarations (6.7).
2396
2397
2398
2399      47) See 6.7.3 regarding qualified array and function types.
2400      48) The same representation and alignment requirements are meant to imply interchangeability as
2401          arguments to functions, return values from functions, and members of unions.
2402
2403 [page 43]
2404
2405     6.2.6 Representations of types
2406     6.2.6.1 General
2407 1   The representations of all types are unspecified except as stated in this subclause.
2408 2   Except for bit-fields, objects are composed of contiguous sequences of one or more bytes,
2409     the number, order, and encoding of which are either explicitly specified or
2410     implementation-defined.
2411 3   Values stored in unsigned bit-fields and objects of type unsigned char shall be
2412     represented using a pure binary notation.49)
2413 4   Values stored in non-bit-field objects of any other object type consist of n x CHAR_BIT
2414     bits, where n is the size of an object of that type, in bytes. The value may be copied into
2415     an object of type unsigned char [n] (e.g., by memcpy); the resulting set of bytes is
2416     called the object representation of the value. Values stored in bit-fields consist of m bits,
2417     where m is the size specified for the bit-field. The object representation is the set of m
2418     bits the bit-field comprises in the addressable storage unit holding it. Two values (other
2419     than NaNs) with the same object representation compare equal, but values that compare
2420     equal may have different object representations.
2421 5   Certain object representations need not represent a value of the object type. If the stored
2422     value of an object has such a representation and is read by an lvalue expression that does
2423     not have character type, the behavior is undefined. If such a representation is produced
2424     by a side effect that modifies all or any part of the object by an lvalue expression that
2425     does not have character type, the behavior is undefined.50) Such a representation is called
2426     a trap representation.
2427 6   When a value is stored in an object of structure or union type, including in a member
2428     object, the bytes of the object representation that correspond to any padding bytes take
2429     unspecified values.51) The value of a structure or union object is never a trap
2430     representation, even though the value of a member of the structure or union object may be
2431     a trap representation.
2432 7   When a value is stored in a member of an object of union type, the bytes of the object
2433     representation that do not correspond to that member but do correspond to other members
2434
2435     49) A positional representation for integers that uses the binary digits 0 and 1, in which the values
2436         represented by successive bits are additive, begin with 1, and are multiplied by successive integral
2437         powers of 2, except perhaps the bit with the highest position. (Adapted from the American National
2438         Dictionary for Information Processing Systems.) A byte contains CHAR_BIT bits, and the values of
2439         type unsigned char range from 0 to 2
2440                                                   CHAR_BIT
2441                                                             - 1.
2442     50) Thus, an automatic variable can be initialized to a trap representation without causing undefined
2443         behavior, but the value of the variable cannot be used until a proper value is stored in it.
2444     51) Thus, for example, structure assignment need not copy any padding bits.
2445
2446 [page 44]
2447
2448     take unspecified values.
2449 8   Where an operator is applied to a value that has more than one object representation,
2450     which object representation is used shall not affect the value of the result.52) Where a
2451     value is stored in an object using a type that has more than one object representation for
2452     that value, it is unspecified which representation is used, but a trap representation shall
2453     not be generated.
2454 9   Loads and stores of objects with _Atomic-qualified types are done with
2455     memory_order_seq_cst semantics.
2456     Forward references: declarations (6.7), expressions (6.5), lvalues, arrays, and function
2457     designators (6.3.2.1), order and consistency (7.17.3).
2458     6.2.6.2 Integer types
2459 1   For unsigned integer types other than unsigned char, the bits of the object
2460     representation shall be divided into two groups: value bits and padding bits (there need
2461     not be any of the latter). If there are N value bits, each bit shall represent a different
2462     power of 2 between 1 and 2 N -1 , so that objects of that type shall be capable of
2463     representing values from 0 to 2 N - 1 using a pure binary representation; this shall be
2464     known as the value representation. The values of any padding bits are unspecified.53)
2465 2   For signed integer types, the bits of the object representation shall be divided into three
2466     groups: value bits, padding bits, and the sign bit. There need not be any padding bits;
2467     signed char shall not have any padding bits. There shall be exactly one sign bit.
2468     Each bit that is a value bit shall have the same value as the same bit in the object
2469     representation of the corresponding unsigned type (if there are M value bits in the signed
2470     type and N in the unsigned type, then M <= N ). If the sign bit is zero, it shall not affect
2471     the resulting value. If the sign bit is one, the value shall be modified in one of the
2472     following ways:
2473     -- the corresponding value with sign bit 0 is negated (sign and magnitude);
2474     -- the sign bit has the value -(2 M ) (two's complement);
2475
2476
2477     52) It is possible for objects x and y with the same effective type T to have the same value when they are
2478         accessed as objects of type T, but to have different values in other contexts. In particular, if == is
2479         defined for type T, then x == y does not imply that memcmp(&x, &y, sizeof (T)) == 0.
2480         Furthermore, x == y does not necessarily imply that x and y have the same value; other operations
2481         on values of type T may distinguish between them.
2482     53) Some combinations of padding bits might generate trap representations, for example, if one padding
2483         bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap
2484         representation other than as part of an exceptional condition such as an overflow, and this cannot occur
2485         with unsigned types. All other combinations of padding bits are alternative object representations of
2486         the value specified by the value bits.
2487
2488 [page 45]
2489
2490     -- the sign bit has the value -(2 M - 1) (ones' complement).
2491     Which of these applies is implementation-defined, as is whether the value with sign bit 1
2492     and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones'
2493     complement), is a trap representation or a normal value. In the case of sign and
2494     magnitude and ones' complement, if this representation is a normal value it is called a
2495     negative zero.
2496 3   If the implementation supports negative zeros, they shall be generated only by:
2497     -- the &, |, ^, ~, <<, and >> operators with operands that produce such a value;
2498     -- the +, -, *, /, and % operators where one operand is a negative zero and the result is
2499       zero;
2500     -- compound assignment operators based on the above cases.
2501     It is unspecified whether these cases actually generate a negative zero or a normal zero,
2502     and whether a negative zero becomes a normal zero when stored in an object.
2503 4   If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<,
2504     and >> operators with operands that would produce such a value is undefined.
2505 5   The values of any padding bits are unspecified.54) A valid (non-trap) object representation
2506     of a signed integer type where the sign bit is zero is a valid object representation of the
2507     corresponding unsigned type, and shall represent the same value. For any integer type,
2508     the object representation where all the bits are zero shall be a representation of the value
2509     zero in that type.
2510 6   The precision of an integer type is the number of bits it uses to represent values,
2511     excluding any sign and padding bits. The width of an integer type is the same but
2512     including any sign bit; thus for unsigned integer types the two values are the same, while
2513     for signed integer types the width is one greater than the precision.
2514
2515
2516
2517
2518     54) Some combinations of padding bits might generate trap representations, for example, if one padding
2519         bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap
2520         representation other than as part of an exceptional condition such as an overflow. All other
2521         combinations of padding bits are alternative object representations of the value specified by the value
2522         bits.
2523
2524 [page 46]
2525
2526     6.2.7 Compatible type and composite type
2527 1   Two types have compatible type if their types are the same. Additional rules for
2528     determining whether two types are compatible are described in 6.7.2 for type specifiers,
2529     in 6.7.3 for type qualifiers, and in 6.7.6 for declarators.55) Moreover, two structure,
2530     union, or enumerated types declared in separate translation units are compatible if their
2531     tags and members satisfy the following requirements: If one is declared with a tag, the
2532     other shall be declared with the same tag. If both are completed anywhere within their
2533     respective translation units, then the following additional requirements apply: there shall
2534     be a one-to-one correspondence between their members such that each pair of
2535     corresponding members are declared with compatible types, and such that if one member
2536     of a corresponding pair is declared with a name, the other member is declared with the
2537     same name. For two structures, corresponding members shall be declared in the same
2538     order. For two structures or unions, corresponding bit-fields shall have the same widths.
2539     For two enumerations, corresponding members shall have the same values.
2540 2   All declarations that refer to the same object or function shall have compatible type;
2541     otherwise, the behavior is undefined.
2542 3   A composite type can be constructed from two types that are compatible; it is a type that
2543     is compatible with both of the two types and satisfies the following conditions:
2544     -- If both types are array types, the following rules are applied:
2545           o If one type is an array of known constant size, the composite type is an array of
2546              that size.
2547           o Otherwise, if one type is a variable length array whose size is specified by an
2548              expression that is not evaluated, the behavior is undefined.
2549           o Otherwise, if one type is a variable length array whose size is specified, the
2550              composite type is a variable length array of that size.
2551           o Otherwise, if one type is a variable length array of unspecified size, the composite
2552              type is a variable length array of unspecified size.
2553           o Otherwise, both types are arrays of unknown size and the composite type is an
2554              array of unknown size.
2555         The element type of the composite type is the composite type of the two element
2556         types.
2557     -- If only one type is a function type with a parameter type list (a function prototype),
2558       the composite type is a function prototype with the parameter type list.
2559
2560
2561
2562     55) Two types need not be identical to be compatible.
2563
2564 [page 47]
2565
2566     -- If both types are function types with parameter type lists, the type of each parameter
2567       in the composite parameter type list is the composite type of the corresponding
2568       parameters.
2569     These rules apply recursively to the types from which the two types are derived.
2570 4   For an identifier with internal or external linkage declared in a scope in which a prior
2571     declaration of that identifier is visible,56) if the prior declaration specifies internal or
2572     external linkage, the type of the identifier at the later declaration becomes the composite
2573     type.
2574     Forward references: array declarators (6.7.6.2).
2575 5   EXAMPLE        Given the following two file scope declarations:
2576              int f(int (*)(), double (*)[3]);
2577              int f(int (*)(char *), double (*)[]);
2578     The resulting composite type for the function is:
2579              int f(int (*)(char *), double (*)[3]);
2580
2581     6.2.8 Alignment of objects
2582 1   Complete object types have alignment requirements which place restrictions on the
2583     addresses at which objects of that type may be allocated. An alignment is an
2584     implementation-defined integer value representing the number of bytes between
2585     successive addresses at which a given object can be allocated. An object type imposes an
2586     alignment requirement on every object of that type: stricter alignment can be requested
2587     using the _Alignas keyword.
2588 2   A fundamental alignment is represented by an alignment less than or equal to the greatest
2589     alignment supported by the implementation in all contexts, which is equal to
2590     alignof(max_align_t).
2591 3   An extended alignment is represented by an alignment greater than
2592     alignof(max_align_t). It is implementation-defined whether any extended
2593     alignments are supported and the contexts in which they are supported. A type having an
2594     extended alignment requirement is an over-aligned type.57)
2595 4   Alignments are represented as values of the type size_t. Valid alignments include only
2596     those values returned by an alignof expression for fundamental types, plus an
2597     additional implementation-defined set of values, which may be empty. Every valid
2598     alignment value shall be an integral power of two.
2599
2600
2601     56) As specified in 6.2.1, the later declaration might hide the prior declaration.
2602     57) Every over-aligned type is, or contains, a structure or union type with a member to which an extended
2603         alignment has been applied.
2604
2605 [page 48]
2606
2607 5   Alignments have an order from weaker to stronger or stricter alignments. Stricter
2608     alignments have larger alignment values. An address that satisfies an alignment
2609     requirement also satisfies any weaker valid alignment requirement.
2610 6   The alignment requirement of a complete type can be queried using an alignof
2611     expression. The types char, signed char, and unsigned char shall have the
2612     weakest alignment requirement.
2613 7   Comparing alignments is meaningful and provides the obvious results:
2614     -- Two alignments are equal when their numeric values are equal.
2615     -- Two alignments are different when their numeric values are not equal.
2616     -- When an alignment is larger than another it represents a stricter alignment.
2617
2618
2619
2620
2621 [page 49]
2622
2623     6.3 Conversions
2624 1   Several operators convert operand values from one type to another automatically. This
2625     subclause specifies the result required from such an implicit conversion, as well as those
2626     that result from a cast operation (an explicit conversion). The list in 6.3.1.8 summarizes
2627     the conversions performed by most ordinary operators; it is supplemented as required by
2628     the discussion of each operator in 6.5.
2629 2   Conversion of an operand value to a compatible type causes no change to the value or the
2630     representation.
2631     Forward references: cast operators (6.5.4).
2632     6.3.1 Arithmetic operands
2633     6.3.1.1 Boolean, characters, and integers
2634 1   Every integer type has an integer conversion rank defined as follows:
2635     -- No two signed integer types shall have the same rank, even if they have the same
2636       representation.
2637     -- The rank of a signed integer type shall be greater than the rank of any signed integer
2638       type with less precision.
2639     -- The rank of long long int shall be greater than the rank of long int, which
2640       shall be greater than the rank of int, which shall be greater than the rank of short
2641       int, which shall be greater than the rank of signed char.
2642     -- The rank of any unsigned integer type shall equal the rank of the corresponding
2643       signed integer type, if any.
2644     -- The rank of any standard integer type shall be greater than the rank of any extended
2645       integer type with the same width.
2646     -- The rank of char shall equal the rank of signed char and unsigned char.
2647     -- The rank of _Bool shall be less than the rank of all other standard integer types.
2648     -- The rank of any enumerated type shall equal the rank of the compatible integer type
2649       (see 6.7.2.2).
2650     -- The rank of any extended signed integer type relative to another extended signed
2651       integer type with the same precision is implementation-defined, but still subject to the
2652       other rules for determining the integer conversion rank.
2653     -- For all integer types T1, T2, and T3, if T1 has greater rank than T2 and T2 has
2654       greater rank than T3, then T1 has greater rank than T3.
2655 2   The following may be used in an expression wherever an int or unsigned int may
2656     be used:
2657
2658 [page 50]
2659
2660     -- An object or expression with an integer type (other than int or unsigned int)
2661       whose integer conversion rank is less than or equal to the rank of int and
2662       unsigned int.
2663     -- A bit-field of type _Bool, int, signed int, or unsigned int.
2664     If an int can represent all values of the original type (as restricted by the width, for a
2665     bit-field), the value is converted to an int; otherwise, it is converted to an unsigned
2666     int. These are called the integer promotions.58) All other types are unchanged by the
2667     integer promotions.
2668 3   The integer promotions preserve value including sign. As discussed earlier, whether a
2669     ''plain'' char is treated as signed is implementation-defined.
2670     Forward references: enumeration specifiers (6.7.2.2), structure and union specifiers
2671     (6.7.2.1).
2672     6.3.1.2 Boolean type
2673 1   When any scalar value is converted to _Bool, the result is 0 if the value compares equal
2674     to 0; otherwise, the result is 1.59)
2675     6.3.1.3 Signed and unsigned integers
2676 1   When a value with integer type is converted to another integer type other than _Bool, if
2677     the value can be represented by the new type, it is unchanged.
2678 2   Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or
2679     subtracting one more than the maximum value that can be represented in the new type
2680     until the value is in the range of the new type.60)
2681 3   Otherwise, the new type is signed and the value cannot be represented in it; either the
2682     result is implementation-defined or an implementation-defined signal is raised.
2683     6.3.1.4 Real floating and integer
2684 1   When a finite value of real floating type is converted to an integer type other than _Bool,
2685     the fractional part is discarded (i.e., the value is truncated toward zero). If the value of
2686     the integral part cannot be represented by the integer type, the behavior is undefined.61)
2687
2688
2689     58) The integer promotions are applied only: as part of the usual arithmetic conversions, to certain
2690         argument expressions, to the operands of the unary +, -, and ~ operators, and to both operands of the
2691         shift operators, as specified by their respective subclauses.
2692     59) NaNs do not compare equal to 0 and thus convert to 1.
2693     60) The rules describe arithmetic on the mathematical value, not the value of a given type of expression.
2694     61) The remaindering operation performed when a value of integer type is converted to unsigned type
2695         need not be performed when a value of real floating type is converted to unsigned type. Thus, the
2696         range of portable real floating values is (-1, Utype_MAX+1).
2697
2698 [page 51]
2699
2700 2   When a value of integer type is converted to a real floating type, if the value being
2701     converted can be represented exactly in the new type, it is unchanged. If the value being
2702     converted is in the range of values that can be represented but cannot be represented
2703     exactly, the result is either the nearest higher or nearest lower representable value, chosen
2704     in an implementation-defined manner. If the value being converted is outside the range of
2705     values that can be represented, the behavior is undefined.
2706     6.3.1.5 Real floating types
2707 1   When a float is promoted to double or long double, or a double is promoted
2708     to long double, its value is unchanged (if the source value is represented in the
2709     precision and range of its type).
2710 2   When a double is demoted to float, a long double is demoted to double or
2711     float, or a value being represented in greater precision and range than required by its
2712     semantic type (see 6.3.1.8) is explicitly converted (including to its own type), if the value
2713     being converted can be represented exactly in the new type, it is unchanged. If the value
2714     being converted is in the range of values that can be represented but cannot be
2715     represented exactly, the result is either the nearest higher or nearest lower representable
2716     value, chosen in an implementation-defined manner. If the value being converted is
2717     outside the range of values that can be represented, the behavior is undefined.
2718     6.3.1.6 Complex types
2719 1   When a value of complex type is converted to another complex type, both the real and
2720     imaginary parts follow the conversion rules for the corresponding real types.
2721     6.3.1.7 Real and complex
2722 1   When a value of real type is converted to a complex type, the real part of the complex
2723     result value is determined by the rules of conversion to the corresponding real type and
2724     the imaginary part of the complex result value is a positive zero or an unsigned zero.
2725 2   When a value of complex type is converted to a real type, the imaginary part of the
2726     complex value is discarded and the value of the real part is converted according to the
2727     conversion rules for the corresponding real type.
2728     6.3.1.8 Usual arithmetic conversions
2729 1   Many operators that expect operands of arithmetic type cause conversions and yield result
2730     types in a similar way. The purpose is to determine a common real type for the operands
2731     and result. For the specified operands, each operand is converted, without change of type
2732     domain, to a type whose corresponding real type is the common real type. Unless
2733     explicitly stated otherwise, the common real type is also the corresponding real type of
2734     the result, whose type domain is the type domain of the operands if they are the same,
2735     and complex otherwise. This pattern is called the usual arithmetic conversions:
2736
2737
2738 [page 52]
2739
2740           First, if the corresponding real type of either operand is long double, the other
2741           operand is converted, without change of type domain, to a type whose
2742           corresponding real type is long double.
2743           Otherwise, if the corresponding real type of either operand is double, the other
2744           operand is converted, without change of type domain, to a type whose
2745           corresponding real type is double.
2746           Otherwise, if the corresponding real type of either operand is float, the other
2747           operand is converted, without change of type domain, to a type whose
2748           corresponding real type is float.62)
2749           Otherwise, the integer promotions are performed on both operands. Then the
2750           following rules are applied to the promoted operands:
2751                  If both operands have the same type, then no further conversion is needed.
2752                  Otherwise, if both operands have signed integer types or both have unsigned
2753                  integer types, the operand with the type of lesser integer conversion rank is
2754                  converted to the type of the operand with greater rank.
2755                  Otherwise, if the operand that has unsigned integer type has rank greater or
2756                  equal to the rank of the type of the other operand, then the operand with
2757                  signed integer type is converted to the type of the operand with unsigned
2758                  integer type.
2759                  Otherwise, if the type of the operand with signed integer type can represent
2760                  all of the values of the type of the operand with unsigned integer type, then
2761                  the operand with unsigned integer type is converted to the type of the
2762                  operand with signed integer type.
2763                  Otherwise, both operands are converted to the unsigned integer type
2764                  corresponding to the type of the operand with signed integer type.
2765 2   The values of floating operands and of the results of floating expressions may be
2766     represented in greater precision and range than that required by the type; the types are not
2767     changed thereby.63)
2768
2769
2770
2771
2772     62) For example, addition of a double _Complex and a float entails just the conversion of the
2773         float operand to double (and yields a double _Complex result).
2774     63) The cast and assignment operators are still required to perform their specified conversions as
2775         described in 6.3.1.4 and 6.3.1.5.
2776
2777 [page 53]
2778
2779     6.3.2 Other operands
2780     6.3.2.1 Lvalues, arrays, and function designators
2781 1   An lvalue is an expression (with an object type other than void) that potentially
2782     designates an object;64) if an lvalue does not designate an object when it is evaluated, the
2783     behavior is undefined. When an object is said to have a particular type, the type is
2784     specified by the lvalue used to designate the object. A modifiable lvalue is an lvalue that
2785     does not have array type, does not have an incomplete type, does not have a const-
2786     qualified type, and if it is a structure or union, does not have any member (including,
2787     recursively, any member or element of all contained aggregates or unions) with a const-
2788     qualified type.
2789 2   Except when it is the operand of the sizeof operator, the unary & operator, the ++
2790     operator, the -- operator, or the left operand of the . operator or an assignment operator,
2791     an lvalue that does not have array type is converted to the value stored in the designated
2792     object (and is no longer an lvalue). If the lvalue has qualified type, the value has the
2793     unqualified version of the type of the lvalue; otherwise, the value has the type of the
2794     lvalue. If the lvalue has an incomplete type and does not have array type, the behavior is
2795     undefined. If the lvalue designates an object of automatic storage duration that could
2796     have been declared with the register storage class (never had its address taken), and
2797     that object is uninitialized (not declared with an initializer and no assignment to it has
2798     been performed prior to use), the behavior is undefined.
2799 3   Except when it is the operand of the sizeof operator or the unary & operator, or is a
2800     string literal used to initialize an array, an expression that has type ''array of type'' is
2801     converted to an expression with type ''pointer to type'' that points to the initial element of
2802     the array object and is not an lvalue. If the array object has register storage class, the
2803     behavior is undefined.
2804 4   A function designator is an expression that has function type. Except when it is the
2805     operand of the sizeof operator65) or the unary & operator, a function designator with
2806     type ''function returning type'' is converted to an expression that has type ''pointer to
2807     function returning type''.
2808     Forward references: address and indirection operators (6.5.3.2), assignment operators
2809
2810     64) The name ''lvalue'' comes originally from the assignment expression E1 = E2, in which the left
2811         operand E1 is required to be a (modifiable) lvalue. It is perhaps better considered as representing an
2812         object ''locator value''. What is sometimes called ''rvalue'' is in this International Standard described
2813         as the ''value of an expression''.
2814          An obvious example of an lvalue is an identifier of an object. As a further example, if E is a unary
2815          expression that is a pointer to an object, *E is an lvalue that designates the object to which E points.
2816     65) Because this conversion does not occur, the operand of the sizeof operator remains a function
2817         designator and violates the constraint in 6.5.3.4.
2818
2819 [page 54]
2820
2821     (6.5.16), common definitions <stddef.h> (7.19), initialization (6.7.9), postfix
2822     increment and decrement operators (6.5.2.4), prefix increment and decrement operators
2823     (6.5.3.1), the sizeof operator (6.5.3.4), structure and union members (6.5.2.3).
2824     6.3.2.2 void
2825 1   The (nonexistent) value of a void expression (an expression that has type void) shall not
2826     be used in any way, and implicit or explicit conversions (except to void) shall not be
2827     applied to such an expression. If an expression of any other type is evaluated as a void
2828     expression, its value or designator is discarded. (A void expression is evaluated for its
2829     side effects.)
2830     6.3.2.3 Pointers
2831 1   A pointer to void may be converted to or from a pointer to any object type. A pointer to
2832     any object type may be converted to a pointer to void and back again; the result shall
2833     compare equal to the original pointer.
2834 2   For any qualifier q, a pointer to a non-q-qualified type may be converted to a pointer to
2835     the q-qualified version of the type; the values stored in the original and converted pointers
2836     shall compare equal.
2837 3   An integer constant expression with the value 0, or such an expression cast to type
2838     void *, is called a null pointer constant.66) If a null pointer constant is converted to a
2839     pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal
2840     to a pointer to any object or function.
2841 4   Conversion of a null pointer to another pointer type yields a null pointer of that type.
2842     Any two null pointers shall compare equal.
2843 5   An integer may be converted to any pointer type. Except as previously specified, the
2844     result is implementation-defined, might not be correctly aligned, might not point to an
2845     entity of the referenced type, and might be a trap representation.67)
2846 6   Any pointer type may be converted to an integer type. Except as previously specified, the
2847     result is implementation-defined. If the result cannot be represented in the integer type,
2848     the behavior is undefined. The result need not be in the range of values of any integer
2849     type.
2850 7   A pointer to an object type may be converted to a pointer to a different object type. If the
2851     resulting pointer is not correctly aligned68) for the referenced type, the behavior is
2852     undefined. Otherwise, when converted back again, the result shall compare equal to the
2853
2854
2855     66) The macro NULL is defined in <stddef.h> (and other headers) as a null pointer constant; see 7.19.
2856     67) The mapping functions for converting a pointer to an integer or an integer to a pointer are intended to
2857         be consistent with the addressing structure of the execution environment.
2858
2859 [page 55]
2860
2861     original pointer. When a pointer to an object is converted to a pointer to a character type,
2862     the result points to the lowest addressed byte of the object. Successive increments of the
2863     result, up to the size of the object, yield pointers to the remaining bytes of the object.
2864 8   A pointer to a function of one type may be converted to a pointer to a function of another
2865     type and back again; the result shall compare equal to the original pointer. If a converted
2866     pointer is used to call a function whose type is not compatible with the referenced type,
2867     the behavior is undefined.
2868     Forward references: cast operators (6.5.4), equality operators (6.5.9), integer types
2869     capable of holding object pointers (7.20.1.4), simple assignment (6.5.16.1).
2870
2871
2872
2873
2874     68) In general, the concept ''correctly aligned'' is transitive: if a pointer to type A is correctly aligned for a
2875         pointer to type B, which in turn is correctly aligned for a pointer to type C, then a pointer to type A is
2876         correctly aligned for a pointer to type C.
2877
2878 [page 56]
2879
2880     6.4 Lexical elements
2881     Syntax
2882 1            token:
2883                       keyword
2884                       identifier
2885                       constant
2886                       string-literal
2887                       punctuator
2888              preprocessing-token:
2889                     header-name
2890                     identifier
2891                     pp-number
2892                     character-constant
2893                     string-literal
2894                     punctuator
2895                     each non-white-space character that cannot be one of the above
2896     Constraints
2897 2   Each preprocessing token that is converted to a token shall have the lexical form of a
2898     keyword, an identifier, a constant, a string literal, or a punctuator.
2899     Semantics
2900 3   A token is the minimal lexical element of the language in translation phases 7 and 8. The
2901     categories of tokens are: keywords, identifiers, constants, string literals, and punctuators.
2902     A preprocessing token is the minimal lexical element of the language in translation
2903     phases 3 through 6. The categories of preprocessing tokens are: header names,
2904     identifiers, preprocessing numbers, character constants, string literals, punctuators, and
2905     single non-white-space characters that do not lexically match the other preprocessing
2906     token categories.69) If a ' or a " character matches the last category, the behavior is
2907     undefined. Preprocessing tokens can be separated by white space; this consists of
2908     comments (described later), or white-space characters (space, horizontal tab, new-line,
2909     vertical tab, and form-feed), or both. As described in 6.10, in certain circumstances
2910     during translation phase 4, white space (or the absence thereof) serves as more than
2911     preprocessing token separation. White space may appear within a preprocessing token
2912     only as part of a header name or between the quotation characters in a character constant
2913     or string literal.
2914
2915
2916
2917     69) An additional category, placemarkers, is used internally in translation phase 4 (see 6.10.3.3); it cannot
2918         occur in source files.
2919
2920 [page 57]
2921
2922 4   If the input stream has been parsed into preprocessing tokens up to a given character, the
2923     next preprocessing token is the longest sequence of characters that could constitute a
2924     preprocessing token. There is one exception to this rule: header name preprocessing
2925     tokens are recognized only within #include preprocessing directives and in
2926     implementation-defined locations within #pragma directives. In such contexts, a
2927     sequence of characters that could be either a header name or a string literal is recognized
2928     as the former.
2929 5   EXAMPLE 1 The program fragment 1Ex is parsed as a preprocessing number token (one that is not a
2930     valid floating or integer constant token), even though a parse as the pair of preprocessing tokens 1 and Ex
2931     might produce a valid expression (for example, if Ex were a macro defined as +1). Similarly, the program
2932     fragment 1E1 is parsed as a preprocessing number (one that is a valid floating constant token), whether or
2933     not E is a macro name.
2934
2935 6   EXAMPLE 2 The program fragment x+++++y is parsed as x ++ ++ + y, which violates a constraint on
2936     increment operators, even though the parse x ++ + ++ y might yield a correct expression.
2937
2938     Forward references: character constants (6.4.4.4), comments (6.4.9), expressions (6.5),
2939     floating constants (6.4.4.2), header names (6.4.7), macro replacement (6.10.3), postfix
2940     increment and decrement operators (6.5.2.4), prefix increment and decrement operators
2941     (6.5.3.1), preprocessing directives (6.10), preprocessing numbers (6.4.8), string literals
2942     (6.4.5).
2943     6.4.1 Keywords
2944     Syntax
2945 1            keyword: one of
2946                    alignof                         goto                         union
2947                    auto                            if                           unsigned
2948                    break                           inline                       void
2949                    case                            int                          volatile
2950                    char                            long                         while
2951                    const                           register                     _Alignas
2952                    continue                        restrict                     _Atomic
2953                    default                         return                       _Bool
2954                    do                              short                        _Complex
2955                    double                          signed                       _Generic
2956                    else                            sizeof                       _Imaginary
2957                    enum                            static                       _Noreturn
2958                    extern                          struct                       _Static_assert
2959                    float                           switch                       _Thread_local
2960                    for                             typedef
2961     Semantics
2962 2   The above tokens (case sensitive) are reserved (in translation phases 7 and 8) for use as
2963     keywords, and shall not be used otherwise. The keyword _Imaginary is reserved for
2964 [page 58]
2965
2966     specifying imaginary types.70)
2967     6.4.2 Identifiers
2968     6.4.2.1 General
2969     Syntax
2970 1            identifier:
2971                     identifier-nondigit
2972                     identifier identifier-nondigit
2973                     identifier digit
2974              identifier-nondigit:
2975                     nondigit
2976                     universal-character-name
2977                     other implementation-defined characters
2978              nondigit: one of
2979                     _ a b            c    d    e    f     g    h    i    j     k    l    m
2980                         n o          p    q    r    s     t    u    v    w     x    y    z
2981                         A B          C    D    E    F     G    H    I    J     K    L    M
2982                         N O          P    Q    R    S     T    U    V    W     X    Y    Z
2983              digit: one of
2984                     0 1        2     3    4    5    6     7    8    9
2985     Semantics
2986 2   An identifier is a sequence of nondigit characters (including the underscore _, the
2987     lowercase and uppercase Latin letters, and other characters) and digits, which designates
2988     one or more entities as described in 6.2.1. Lowercase and uppercase letters are distinct.
2989     There is no specific limit on the maximum length of an identifier.
2990 3   Each universal character name in an identifier shall designate a character whose encoding
2991     in ISO/IEC 10646 falls into one of the ranges specified in annex D.71) The initial
2992     character shall not be a universal character name designating a digit. An implementation
2993     may allow multibyte characters that are not part of the basic source character set to
2994     appear in identifiers; which characters and their correspondence to universal character
2995     names is implementation-defined.
2996
2997
2998
2999     70) One possible specification for imaginary types appears in annex G.
3000     71) On systems in which linkers cannot accept extended characters, an encoding of the universal character
3001         name may be used in forming valid external identifiers. For example, some otherwise unused
3002         character or sequence of characters may be used to encode the \u in a universal character name.
3003         Extended characters may produce a long external identifier.
3004
3005 [page 59]
3006
3007 4   When preprocessing tokens are converted to tokens during translation phase 7, if a
3008     preprocessing token could be converted to either a keyword or an identifier, it is converted
3009     to a keyword.
3010     Implementation limits
3011 5   As discussed in 5.2.4.1, an implementation may limit the number of significant initial
3012     characters in an identifier; the limit for an external name (an identifier that has external
3013     linkage) may be more restrictive than that for an internal name (a macro name or an
3014     identifier that does not have external linkage). The number of significant characters in an
3015     identifier is implementation-defined.
3016 6   Any identifiers that differ in a significant character are different identifiers. If two
3017     identifiers differ only in nonsignificant characters, the behavior is undefined.
3018     Forward references: universal character names (6.4.3), macro replacement (6.10.3).
3019     6.4.2.2 Predefined identifiers
3020     Semantics
3021 1   The identifier __func__ shall be implicitly declared by the translator as if,
3022     immediately following the opening brace of each function definition, the declaration
3023              static const char __func__[] = "function-name";
3024     appeared, where function-name is the name of the lexically-enclosing function.72)
3025 2   This name is encoded as if the implicit declaration had been written in the source
3026     character set and then translated into the execution character set as indicated in translation
3027     phase 5.
3028 3   EXAMPLE        Consider the code fragment:
3029              #include <stdio.h>
3030              void myfunc(void)
3031              {
3032                    printf("%s\n", __func__);
3033                    /* ... */
3034              }
3035     Each time the function is called, it will print to the standard output stream:
3036              myfunc
3037
3038     Forward references: function definitions (6.9.1).
3039
3040
3041
3042
3043     72) Since the name __func__ is reserved for any use by the implementation (7.1.3), if any other
3044         identifier is explicitly declared using the name __func__, the behavior is undefined.
3045
3046 [page 60]
3047
3048     6.4.3 Universal character names
3049     Syntax
3050 1            universal-character-name:
3051                     \u hex-quad
3052                     \U hex-quad hex-quad
3053              hex-quad:
3054                     hexadecimal-digit hexadecimal-digit
3055                                  hexadecimal-digit hexadecimal-digit
3056     Constraints
3057 2   A universal character name shall not specify a character whose short identifier is less than
3058     00A0 other than 0024 ($), 0040 (@), or 0060 ('), nor one in the range D800 through
3059     DFFF inclusive.73)
3060     Description
3061 3   Universal character names may be used in identifiers, character constants, and string
3062     literals to designate characters that are not in the basic character set.
3063     Semantics
3064 4   The universal character name \Unnnnnnnn designates the character whose eight-digit
3065     short identifier (as specified by ISO/IEC 10646) is nnnnnnnn.74) Similarly, the universal
3066     character name \unnnn designates the character whose four-digit short identifier is nnnn
3067     (and whose eight-digit short identifier is 0000nnnn).
3068
3069
3070
3071
3072     73) The disallowed characters are the characters in the basic character set and the code positions reserved
3073         by ISO/IEC 10646 for control characters, the character DELETE, and the S-zone (reserved for use by
3074         UTF-16).
3075
3076     74) Short identifiers for characters were first specified in ISO/IEC 10646-1/AMD9:1997.
3077
3078 [page 61]
3079
3080     6.4.4 Constants
3081     Syntax
3082 1            constant:
3083                     integer-constant
3084                     floating-constant
3085                     enumeration-constant
3086                     character-constant
3087     Constraints
3088 2   Each constant shall have a type and the value of a constant shall be in the range of
3089     representable values for its type.
3090     Semantics
3091 3   Each constant has a type, determined by its form and value, as detailed later.
3092     6.4.4.1 Integer constants
3093     Syntax
3094 1            integer-constant:
3095                      decimal-constant integer-suffixopt
3096                      octal-constant integer-suffixopt
3097                      hexadecimal-constant integer-suffixopt
3098              decimal-constant:
3099                    nonzero-digit
3100                    decimal-constant digit
3101              octal-constant:
3102                     0
3103                     octal-constant octal-digit
3104              hexadecimal-constant:
3105                    hexadecimal-prefix hexadecimal-digit
3106                    hexadecimal-constant hexadecimal-digit
3107              hexadecimal-prefix: one of
3108                    0x 0X
3109              nonzero-digit: one of
3110                     1 2 3 4          5     6     7   8    9
3111              octal-digit: one of
3112                      0 1 2 3         4     5     6   7
3113
3114
3115
3116
3117 [page 62]
3118
3119             hexadecimal-digit:    one of
3120                   0 1 2            3 4     5    6   7     8   9
3121                   a b c            d e     f
3122                   A B C            D E     F
3123             integer-suffix:
3124                     unsigned-suffix long-suffixopt
3125                     unsigned-suffix long-long-suffix
3126                     long-suffix unsigned-suffixopt
3127                     long-long-suffix unsigned-suffixopt
3128             unsigned-suffix: one of
3129                    u U
3130             long-suffix: one of
3131                    l L
3132             long-long-suffix: one of
3133                    ll LL
3134     Description
3135 2   An integer constant begins with a digit, but has no period or exponent part. It may have a
3136     prefix that specifies its base and a suffix that specifies its type.
3137 3   A decimal constant begins with a nonzero digit and consists of a sequence of decimal
3138     digits. An octal constant consists of the prefix 0 optionally followed by a sequence of the
3139     digits 0 through 7 only. A hexadecimal constant consists of the prefix 0x or 0X followed
3140     by a sequence of the decimal digits and the letters a (or A) through f (or F) with values
3141     10 through 15 respectively.
3142     Semantics
3143 4   The value of a decimal constant is computed base 10; that of an octal constant, base 8;
3144     that of a hexadecimal constant, base 16. The lexically first digit is the most significant.
3145 5   The type of an integer constant is the first of the corresponding list in which its value can
3146     be represented.
3147
3148
3149
3150
3151 [page 63]
3152
3153                                                                      Octal or Hexadecimal
3154     Suffix                       Decimal Constant                           Constant
3155
3156     none                int                                    int
3157                         long int                               unsigned int
3158                         long long int                          long int
3159                                                                unsigned long int
3160                                                                long long int
3161                                                                unsigned long long int
3162
3163     u or U              unsigned int                           unsigned int
3164                         unsigned long int                      unsigned long int
3165                         unsigned long long int                 unsigned long long int
3166
3167     l or L              long int                               long int
3168                         long long int                          unsigned long int
3169                                                                long long int
3170                                                                unsigned long long int
3171
3172     Both u or U         unsigned long int                      unsigned long int
3173     and l or L          unsigned long long int                 unsigned long long int
3174
3175     ll or LL            long long int                          long long int
3176                                                                unsigned long long int
3177
3178     Both u or U         unsigned long long int                 unsigned long long int
3179     and ll or LL
3180 6   If an integer constant cannot be represented by any type in its list, it may have an
3181     extended integer type, if the extended integer type can represent its value. If all of the
3182     types in the list for the constant are signed, the extended integer type shall be signed. If
3183     all of the types in the list for the constant are unsigned, the extended integer type shall be
3184     unsigned. If the list contains both signed and unsigned types, the extended integer type
3185     may be signed or unsigned. If an integer constant cannot be represented by any type in
3186     its list and has no extended integer type, then the integer constant has no type.
3187
3188
3189
3190
3191 [page 64]
3192
3193     6.4.4.2 Floating constants
3194     Syntax
3195 1            floating-constant:
3196                     decimal-floating-constant
3197                     hexadecimal-floating-constant
3198              decimal-floating-constant:
3199                    fractional-constant exponent-partopt floating-suffixopt
3200                    digit-sequence exponent-part floating-suffixopt
3201              hexadecimal-floating-constant:
3202                    hexadecimal-prefix hexadecimal-fractional-constant
3203                                   binary-exponent-part floating-suffixopt
3204                    hexadecimal-prefix hexadecimal-digit-sequence
3205                                   binary-exponent-part floating-suffixopt
3206              fractional-constant:
3207                      digit-sequenceopt . digit-sequence
3208                      digit-sequence .
3209              exponent-part:
3210                    e signopt digit-sequence
3211                    E signopt digit-sequence
3212              sign: one of
3213                     + -
3214              digit-sequence:
3215                      digit
3216                      digit-sequence digit
3217              hexadecimal-fractional-constant:
3218                    hexadecimal-digit-sequenceopt .
3219                                   hexadecimal-digit-sequence
3220                    hexadecimal-digit-sequence .
3221              binary-exponent-part:
3222                     p signopt digit-sequence
3223                     P signopt digit-sequence
3224              hexadecimal-digit-sequence:
3225                    hexadecimal-digit
3226                    hexadecimal-digit-sequence hexadecimal-digit
3227              floating-suffix: one of
3228                     f l F L
3229
3230 [page 65]
3231
3232     Description
3233 2   A floating constant has a significand part that may be followed by an exponent part and a
3234     suffix that specifies its type. The components of the significand part may include a digit
3235     sequence representing the whole-number part, followed by a period (.), followed by a
3236     digit sequence representing the fraction part. The components of the exponent part are an
3237     e, E, p, or P followed by an exponent consisting of an optionally signed digit sequence.
3238     Either the whole-number part or the fraction part has to be present; for decimal floating
3239     constants, either the period or the exponent part has to be present.
3240     Semantics
3241 3   The significand part is interpreted as a (decimal or hexadecimal) rational number; the
3242     digit sequence in the exponent part is interpreted as a decimal integer. For decimal
3243     floating constants, the exponent indicates the power of 10 by which the significand part is
3244     to be scaled. For hexadecimal floating constants, the exponent indicates the power of 2
3245     by which the significand part is to be scaled. For decimal floating constants, and also for
3246     hexadecimal floating constants when FLT_RADIX is not a power of 2, the result is either
3247     the nearest representable value, or the larger or smaller representable value immediately
3248     adjacent to the nearest representable value, chosen in an implementation-defined manner.
3249     For hexadecimal floating constants when FLT_RADIX is a power of 2, the result is
3250     correctly rounded.
3251 4   An unsuffixed floating constant has type double. If suffixed by the letter f or F, it has
3252     type float. If suffixed by the letter l or L, it has type long double.
3253 5   Floating constants are converted to internal format as if at translation-time. The
3254     conversion of a floating constant shall not raise an exceptional condition or a floating-
3255     point exception at execution time.
3256     Recommended practice
3257 6   The implementation should produce a diagnostic message if a hexadecimal constant
3258     cannot be represented exactly in its evaluation format; the implementation should then
3259     proceed with the translation of the program.
3260 7   The translation-time conversion of floating constants should match the execution-time
3261     conversion of character strings by library functions, such as strtod, given matching
3262     inputs suitable for both conversions, the same result format, and default execution-time
3263     rounding.75)
3264
3265
3266
3267
3268     75) The specification for the library functions recommends more accurate conversion than required for
3269         floating constants (see 7.22.1.3).
3270
3271 [page 66]
3272
3273     6.4.4.3 Enumeration constants
3274     Syntax
3275 1            enumeration-constant:
3276                    identifier
3277     Semantics
3278 2   An identifier declared as an enumeration constant has type int.
3279     Forward references: enumeration specifiers (6.7.2.2).
3280     6.4.4.4 Character constants
3281     Syntax
3282 1            character-constant:
3283                     ' c-char-sequence '
3284                     L' c-char-sequence '
3285                     u' c-char-sequence '
3286                     U' c-char-sequence '
3287              c-char-sequence:
3288                     c-char
3289                     c-char-sequence c-char
3290              c-char:
3291                        any member of the source character set except
3292                                     the single-quote ', backslash \, or new-line character
3293                        escape-sequence
3294              escape-sequence:
3295                     simple-escape-sequence
3296                     octal-escape-sequence
3297                     hexadecimal-escape-sequence
3298                     universal-character-name
3299              simple-escape-sequence: one of
3300                     \' \" \? \\
3301                     \a \b \f \n \r                  \t    \v
3302              octal-escape-sequence:
3303                      \ octal-digit
3304                      \ octal-digit octal-digit
3305                      \ octal-digit octal-digit octal-digit
3306
3307
3308
3309
3310 [page 67]
3311
3312            hexadecimal-escape-sequence:
3313                  \x hexadecimal-digit
3314                  hexadecimal-escape-sequence hexadecimal-digit
3315     Description
3316 2   An integer character constant is a sequence of one or more multibyte characters enclosed
3317     in single-quotes, as in 'x'. A wide character constant is the same, except prefixed by the
3318     letter L, u, or U. With a few exceptions detailed later, the elements of the sequence are
3319     any members of the source character set; they are mapped in an implementation-defined
3320     manner to members of the execution character set.
3321 3   The single-quote ', the double-quote ", the question-mark ?, the backslash \, and
3322     arbitrary integer values are representable according to the following table of escape
3323     sequences:
3324           single quote '            \'
3325           double quote "            \"
3326           question mark ?           \?
3327           backslash \               \\
3328           octal character           \octal digits
3329           hexadecimal character     \x hexadecimal digits
3330 4   The double-quote " and question-mark ? are representable either by themselves or by the
3331     escape sequences \" and \?, respectively, but the single-quote ' and the backslash \
3332     shall be represented, respectively, by the escape sequences \' and \\.
3333 5   The octal digits that follow the backslash in an octal escape sequence are taken to be part
3334     of the construction of a single character for an integer character constant or of a single
3335     wide character for a wide character constant. The numerical value of the octal integer so
3336     formed specifies the value of the desired character or wide character.
3337 6   The hexadecimal digits that follow the backslash and the letter x in a hexadecimal escape
3338     sequence are taken to be part of the construction of a single character for an integer
3339     character constant or of a single wide character for a wide character constant. The
3340     numerical value of the hexadecimal integer so formed specifies the value of the desired
3341     character or wide character.
3342 7   Each octal or hexadecimal escape sequence is the longest sequence of characters that can
3343     constitute the escape sequence.
3344 8   In addition, characters not in the basic character set are representable by universal
3345     character names and certain nongraphic characters are representable by escape sequences
3346     consisting of the backslash \ followed by a lowercase letter: \a, \b, \f, \n, \r, \t,
3347     and \v.76)
3348
3349
3350
3351 [page 68]
3352
3353      Constraints
3354 9    The value of an octal or hexadecimal escape sequence shall be in the range of
3355      representable values for the corresponding type:
3356             Prefix      Corresponding Type
3357             none       unsigned char
3358             L          the unsigned type corresponding to wchar_t
3359             u          char16_t
3360             U          char32_t
3361      Semantics
3362 10   An integer character constant has type int. The value of an integer character constant
3363      containing a single character that maps to a single-byte execution character is the
3364      numerical value of the representation of the mapped character interpreted as an integer.
3365      The value of an integer character constant containing more than one character (e.g.,
3366      'ab'), or containing a character or escape sequence that does not map to a single-byte
3367      execution character, is implementation-defined. If an integer character constant contains
3368      a single character or escape sequence, its value is the one that results when an object with
3369      type char whose value is that of the single character or escape sequence is converted to
3370      type int.
3371 11   A wide character constant prefixed by the letter L has type wchar_t, an integer type
3372      defined in the <stddef.h> header; a wide character constant prefixed by the letter u or
3373      U has type char16_t or char32_t, respectively, unsigned integer types defined in the
3374      <uchar.h> header. The value of a wide character constant containing a single
3375      multibyte character that maps to a single member of the extended execution character set
3376      is the wide character corresponding to that multibyte character, as defined by the
3377      mbtowc, mbrtoc16, or mbrtoc32 function as appropriate for its type, with an
3378      implementation-defined current locale. The value of a wide character constant containing
3379      more than one multibyte character or a single multibyte character that maps to multiple
3380      members of the extended execution character set, or containing a multibyte character or
3381      escape sequence not represented in the extended execution character set, is
3382      implementation-defined.
3383 12   EXAMPLE 1      The construction '\0' is commonly used to represent the null character.
3384
3385 13   EXAMPLE 2 Consider implementations that use two's-complement representation for integers and eight
3386      bits for objects that have type char. In an implementation in which type char has the same range of
3387      values as signed char, the integer character constant '\xFF' has the value -1; if type char has the
3388      same range of values as unsigned char, the character constant '\xFF' has the value +255.
3389
3390
3391
3392
3393      76) The semantics of these characters were discussed in 5.2.2. If any other character follows a backslash,
3394          the result is not a token and a diagnostic is required. See ''future language directions'' (6.11.4).
3395
3396 [page 69]
3397
3398 14   EXAMPLE 3 Even if eight bits are used for objects that have type char, the construction '\x123'
3399      specifies an integer character constant containing only one character, since a hexadecimal escape sequence
3400      is terminated only by a non-hexadecimal character. To specify an integer character constant containing the
3401      two characters whose values are '\x12' and '3', the construction '\0223' may be used, since an octal
3402      escape sequence is terminated after three octal digits. (The value of this two-character integer character
3403      constant is implementation-defined.)
3404
3405 15   EXAMPLE 4 Even if 12 or more bits are used for objects that have type wchar_t, the construction
3406      L'\1234' specifies the implementation-defined value that results from the combination of the values
3407      0123 and '4'.
3408
3409      Forward references: common definitions <stddef.h> (7.19), the mbtowc function
3410      (7.22.7.2), Unicode utilities <uchar.h> (7.27).
3411      6.4.5 String literals
3412      Syntax
3413 1             string-literal:
3414                       encoding-prefixopt " s-char-sequenceopt "
3415               encoding-prefix:
3416                      u8
3417                      u
3418                      U
3419                      L
3420               s-char-sequence:
3421                      s-char
3422                      s-char-sequence s-char
3423               s-char:
3424                         any member of the source character set except
3425                                      the double-quote ", backslash \, or new-line character
3426                         escape-sequence
3427      Constraints
3428 2    A sequence of adjacent string literal tokens shall not include both a wide string literal and
3429      a UTF-8 string literal.
3430      Description
3431 3    A character string literal is a sequence of zero or more multibyte characters enclosed in
3432      double-quotes, as in "xyz". A UTF-8 string literal is the same, except prefixed by u8.
3433      A wide string literal is the same, except prefixed by the letter L, u, or U.
3434 4    The same considerations apply to each element of the sequence in a string literal as if it
3435      were in an integer character constant (for a character or UTF-8 string literal) or a wide
3436      character constant (for a wide string literal), except that the single-quote ' is
3437      representable either by itself or by the escape sequence \', but the double-quote " shall
3438 [page 70]
3439
3440     be represented by the escape sequence \".
3441     Semantics
3442 5   In translation phase 6, the multibyte character sequences specified by any sequence of
3443     adjacent character and identically-prefixed string literal tokens are concatenated into a
3444     single multibyte character sequence. If any of the tokens has an encoding prefix, the
3445     resulting multibyte character sequence is treated as having the same prefix; otherwise, it
3446     is treated as a character string literal. Whether differently-prefixed wide string literal
3447     tokens can be concatenated and, if so, the treatment of the resulting multibyte character
3448     sequence are implementation-defined.
3449 6   In translation phase 7, a byte or code of value zero is appended to each multibyte
3450     character sequence that results from a string literal or literals.77) The multibyte character
3451     sequence is then used to initialize an array of static storage duration and length just
3452     sufficient to contain the sequence. For character string literals, the array elements have
3453     type char, and are initialized with the individual bytes of the multibyte character
3454     sequence. For UTF-8 string literals, the array elements have type char, and are
3455     initialized with the characters of the multibyte character sequence, as encoded in UTF-8.
3456     For wide string literals prefixed by the letter L, the array elements have type wchar_t
3457     and are initialized with the sequence of wide characters corresponding to the multibyte
3458     character sequence, as defined by the mbstowcs function with an implementation-
3459     defined current locale. For wide string literals prefixed by the letter u or U, the array
3460     elements have type char16_t or char32_t, respectively, and are initialized with the
3461     sequence of wide characters corresponding to the multibyte character sequence, as
3462     defined by successive calls to the mbrtoc16, or mbrtoc32 function as appropriate for
3463     its type, with an implementation-defined current locale. The value of a string literal
3464     containing a multibyte character or escape sequence not represented in the execution
3465     character set is implementation-defined.
3466 7   It is unspecified whether these arrays are distinct provided their elements have the
3467     appropriate values. If the program attempts to modify such an array, the behavior is
3468     undefined.
3469 8   EXAMPLE 1      This pair of adjacent character string literals
3470              "\x12" "3"
3471     produces a single character string literal containing the two characters whose values are '\x12' and '3',
3472     because escape sequences are converted into single members of the execution character set just prior to
3473     adjacent string literal concatenation.
3474
3475 9   EXAMPLE 2      Each of the sequences of adjacent string literal tokens
3476
3477
3478
3479     77) A string literal need not be a string (see 7.1.1), because a null character may be embedded in it by a
3480         \0 escape sequence.
3481
3482 [page 71]
3483
3484              "a" "b" L"c"
3485              "a" L"b" "c"
3486              L"a" "b" L"c"
3487              L"a" L"b" L"c"
3488     is equivalent to the string literal
3489              L"abc"
3490     Likewise, each of the sequences
3491              "a" "b" u"c"
3492              "a" u"b" "c"
3493              u"a" "b" u"c"
3494              u"a" u"b" u"c"
3495     is equivalent to
3496              u"abc"
3497
3498     Forward references: common definitions <stddef.h> (7.19), the mbstowcs
3499     function (7.22.8.1), Unicode utilities <uchar.h> (7.27).
3500     6.4.6 Punctuators
3501     Syntax
3502 1            punctuator: one of
3503                     [ ] ( ) { } . ->
3504                     ++ -- & * + - ~ !
3505                     / % << >> < > <= >=                              ==    !=      ^    |   &&   ||
3506                     ? : ; ...
3507                     = *= /= %= += -= <<=                             >>=      &=       ^=   |=
3508                     , # ##
3509                     <: :> <% %> %: %:%:
3510     Semantics
3511 2   A punctuator is a symbol that has independent syntactic and semantic significance.
3512     Depending on context, it may specify an operation to be performed (which in turn may
3513     yield a value or a function designator, produce a side effect, or some combination thereof)
3514     in which case it is known as an operator (other forms of operator also exist in some
3515     contexts). An operand is an entity on which an operator acts.
3516
3517
3518
3519
3520 [page 72]
3521
3522 3   In all aspects of the language, the six tokens78)
3523              <:    :>      <%    %>     %:     %:%:
3524     behave, respectively, the same as the six tokens
3525              [     ]       {     }      #      ##
3526     except for their spelling.79)
3527     Forward references: expressions (6.5), declarations (6.7), preprocessing directives
3528     (6.10), statements (6.8).
3529     6.4.7 Header names
3530     Syntax
3531 1            header-name:
3532                     < h-char-sequence >
3533                     " q-char-sequence "
3534              h-char-sequence:
3535                     h-char
3536                     h-char-sequence h-char
3537              h-char:
3538                        any member of the source character set except
3539                                     the new-line character and >
3540              q-char-sequence:
3541                     q-char
3542                     q-char-sequence q-char
3543              q-char:
3544                        any member of the source character set except
3545                                     the new-line character and "
3546     Semantics
3547 2   The sequences in both forms of header names are mapped in an implementation-defined
3548     manner to headers or external source file names as specified in 6.10.2.
3549 3   If the characters ', \, ", //, or /* occur in the sequence between the < and > delimiters,
3550     the behavior is undefined. Similarly, if the characters ', \, //, or /* occur in the
3551
3552
3553
3554
3555     78) These tokens are sometimes called ''digraphs''.
3556     79) Thus [ and <: behave differently when ''stringized'' (see 6.10.3.2), but can otherwise be freely
3557         interchanged.
3558
3559 [page 73]
3560
3561     sequence between the " delimiters, the behavior is undefined.80) Header name
3562     preprocessing tokens are recognized only within #include preprocessing directives and
3563     in implementation-defined locations within #pragma directives.81)
3564 4   EXAMPLE       The following sequence of characters:
3565              0x3<1/a.h>1e2
3566              #include <1/a.h>
3567              #define const.member@$
3568     forms the following sequence of preprocessing tokens (with each individual preprocessing token delimited
3569     by a { on the left and a } on the right).
3570              {0x3}{<}{1}{/}{a}{.}{h}{>}{1e2}
3571              {#}{include} {<1/a.h>}
3572              {#}{define} {const}{.}{member}{@}{$}
3573
3574     Forward references: source file inclusion (6.10.2).
3575     6.4.8 Preprocessing numbers
3576     Syntax
3577 1            pp-number:
3578                    digit
3579                    . digit
3580                    pp-number       digit
3581                    pp-number       identifier-nondigit
3582                    pp-number       e sign
3583                    pp-number       E sign
3584                    pp-number       p sign
3585                    pp-number       P sign
3586                    pp-number       .
3587     Description
3588 2   A preprocessing number begins with a digit optionally preceded by a period (.) and may
3589     be followed by valid identifier characters and the character sequences e+, e-, E+, E-,
3590     p+, p-, P+, or P-.
3591 3   Preprocessing number tokens lexically include all floating and integer constant tokens.
3592     Semantics
3593 4   A preprocessing number does not have type or a value; it acquires both after a successful
3594     conversion (as part of translation phase 7) to a floating constant token or an integer
3595     constant token.
3596
3597
3598     80) Thus, sequences of characters that resemble escape sequences cause undefined behavior.
3599     81) For an example of a header name preprocessing token used in a #pragma directive, see 6.10.9.
3600
3601 [page 74]
3602
3603     6.4.9 Comments
3604 1   Except within a character constant, a string literal, or a comment, the characters /*
3605     introduce a comment. The contents of such a comment are examined only to identify
3606     multibyte characters and to find the characters */ that terminate it.82)
3607 2   Except within a character constant, a string literal, or a comment, the characters //
3608     introduce a comment that includes all multibyte characters up to, but not including, the
3609     next new-line character. The contents of such a comment are examined only to identify
3610     multibyte characters and to find the terminating new-line character.
3611 3   EXAMPLE
3612              "a//b"                             //   four-character string literal
3613              #include "//e"                     //   undefined behavior
3614              // */                              //   comment, not syntax error
3615              f = g/**//h;                       //   equivalent to f = g / h;
3616              //\
3617              i();                               // part of a two-line comment
3618              /\
3619              / j();                             // part of a two-line comment
3620              #define glue(x,y) x##y
3621              glue(/,/) k();                     // syntax error, not comment
3622              /*//*/ l();                        // equivalent to l();
3623              m = n//**/o
3624                 + p;                            // equivalent to m = n + p;
3625
3626
3627
3628
3629     82) Thus, /* ... */ comments do not nest.
3630
3631 [page 75]
3632
3633     6.5 Expressions
3634 1   An expression is a sequence of operators and operands that specifies computation of a
3635     value, or that designates an object or a function, or that generates side effects, or that
3636     performs a combination thereof. The value computations of the operands of an operator
3637     are sequenced before the value computation of the result of the operator.
3638 2   If a side effect on a scalar object is unsequenced relative to either a different side effect
3639     on the same scalar object or a value computation using the value of the same scalar
3640     object, the behavior is undefined. If there are multiple allowable orderings of the
3641     subexpressions of an expression, the behavior is undefined if such an unsequenced side
3642     effect occurs in any of the orderings.83)
3643 3   The grouping of operators and operands is indicated by the syntax.84) Except as specified
3644     later, side effects and value computations of subexpressions are unsequenced.85)
3645 4   Some operators (the unary operator ~, and the binary operators <<, >>, &, ^, and |,
3646     collectively described as bitwise operators) are required to have operands that have
3647     integer type. These operators yield values that depend on the internal representations of
3648     integers, and have implementation-defined and undefined aspects for signed types.
3649 5   If an exceptional condition occurs during the evaluation of an expression (that is, if the
3650     result is not mathematically defined or not in the range of representable values for its
3651     type), the behavior is undefined.
3652
3653
3654
3655     83) This paragraph renders undefined statement expressions such as
3656                   i = ++i + 1;
3657                   a[i++] = i;
3658          while allowing
3659                   i = i + 1;
3660                   a[i] = i;
3661
3662     84) The syntax specifies the precedence of operators in the evaluation of an expression, which is the same
3663         as the order of the major subclauses of this subclause, highest precedence first. Thus, for example, the
3664         expressions allowed as the operands of the binary + operator (6.5.6) are those expressions defined in
3665         6.5.1 through 6.5.6. The exceptions are cast expressions (6.5.4) as operands of unary operators
3666         (6.5.3), and an operand contained between any of the following pairs of operators: grouping
3667         parentheses () (6.5.1), subscripting brackets [] (6.5.2.1), function-call parentheses () (6.5.2.2), and
3668         the conditional operator ? : (6.5.15).
3669          Within each major subclause, the operators have the same precedence. Left- or right-associativity is
3670          indicated in each subclause by the syntax for the expressions discussed therein.
3671     85) In an expression that is evaluated more than once during the execution of a program, unsequenced and
3672         indeterminately sequenced evaluations of its subexpressions need not be performed consistently in
3673         different evaluations.
3674
3675 [page 76]
3676
3677 6   The effective type of an object for an access to its stored value is the declared type of the
3678     object, if any.86) If a value is stored into an object having no declared type through an
3679     lvalue having a type that is not a character type, then the type of the lvalue becomes the
3680     effective type of the object for that access and for subsequent accesses that do not modify
3681     the stored value. If a value is copied into an object having no declared type using
3682     memcpy or memmove, or is copied as an array of character type, then the effective type
3683     of the modified object for that access and for subsequent accesses that do not modify the
3684     value is the effective type of the object from which the value is copied, if it has one. For
3685     all other accesses to an object having no declared type, the effective type of the object is
3686     simply the type of the lvalue used for the access.
3687 7   An object shall have its stored value accessed only by an lvalue expression that has one of
3688     the following types:87)
3689     -- a type compatible with the effective type of the object,
3690     -- a qualified version of a type compatible with the effective type of the object,
3691     -- a type that is the signed or unsigned type corresponding to the effective type of the
3692       object,
3693     -- a type that is the signed or unsigned type corresponding to a qualified version of the
3694       effective type of the object,
3695     -- an aggregate or union type that includes one of the aforementioned types among its
3696       members (including, recursively, a member of a subaggregate or contained union), or
3697     -- a character type.
3698 8   A floating expression may be contracted, that is, evaluated as though it were a single
3699     operation, thereby omitting rounding errors implied by the source code and the
3700     expression evaluation method.88) The FP_CONTRACT pragma in <math.h> provides a
3701     way to disallow contracted expressions. Otherwise, whether and how expressions are
3702     contracted is implementation-defined.89)
3703     Forward references: the FP_CONTRACT pragma (7.12.2), copying functions (7.23.2).
3704
3705
3706     86) Allocated objects have no declared type.
3707     87) The intent of this list is to specify those circumstances in which an object may or may not be aliased.
3708     88) The intermediate operations in the contracted expression are evaluated as if to infinite precision and
3709         range, while the final operation is rounded to the format determined by the expression evaluation
3710         method. A contracted expression might also omit the raising of floating-point exceptions.
3711     89) This license is specifically intended to allow implementations to exploit fast machine instructions that
3712         combine multiple C operators. As contractions potentially undermine predictability, and can even
3713         decrease accuracy for containing expressions, their use needs to be well-defined and clearly
3714         documented.
3715
3716 [page 77]
3717
3718     6.5.1 Primary expressions
3719     Syntax
3720 1            primary-expression:
3721                     identifier
3722                     constant
3723                     string-literal
3724                     ( expression )
3725                     generic-selection
3726     Semantics
3727 2   An identifier is a primary expression, provided it has been declared as designating an
3728     object (in which case it is an lvalue) or a function (in which case it is a function
3729     designator).90)
3730 3   A constant is a primary expression. Its type depends on its form and value, as detailed in
3731     6.4.4.
3732 4   A string literal is a primary expression. It is an lvalue with type as detailed in 6.4.5.
3733 5   A parenthesized expression is a primary expression. Its type and value are identical to
3734     those of the unparenthesized expression. It is an lvalue, a function designator, or a void
3735     expression if the unparenthesized expression is, respectively, an lvalue, a function
3736     designator, or a void expression.
3737     Forward references: declarations (6.7).
3738     6.5.1.1 Generic selection
3739     Syntax
3740 1            generic-selection:
3741                     _Generic ( assignment-expression , generic-assoc-list )
3742              generic-assoc-list:
3743                     generic-association
3744                     generic-assoc-list , generic-association
3745              generic-association:
3746                     type-name : assignment-expression
3747                     default : assignment-expression
3748     Constraints
3749 2   A generic selection shall have no more than one default generic association. The type
3750     name in a generic association shall specify a complete object type other than a variably
3751
3752     90) Thus, an undeclared identifier is a violation of the syntax.
3753
3754 [page 78]
3755
3756     modified type. No two generic associations in the same generic selection shall specify
3757     compatible types. The controlling expression of a generic selection shall have type
3758     compatible with at most one of the types named in its generic association list. If a
3759     generic selection has no default generic association, its controlling expression shall
3760     have type compatible with exactly one of the types named in its generic association list.
3761     Semantics
3762 3   The controlling expression of a generic selection is not evaluated. If a generic selection
3763     has a generic association with a type name that is compatible with the type of the
3764     controlling expression, then the result expression of the generic selection is the
3765     expression in that generic association. Otherwise, the result expression of the generic
3766     selection is the expression in the default generic association. None of the expressions
3767     from any other generic association of the generic selection is evaluated.
3768 4   The type and value of a generic selection are identical to those of its result expression. It
3769     is an lvalue, a function designator, or a void expression if its result expression is,
3770     respectively, an lvalue, a function designator, or a void expression.
3771 5   EXAMPLE      The cbrt type-generic macro could be implemented as follows:
3772              #define cbrt(X) _Generic((X),                                      \
3773                                      long double: cbrtl,                        \
3774                                      default: cbrt,                             \
3775                                      float: cbrtf                               \
3776                                      )(X)
3777
3778     6.5.2 Postfix operators
3779     Syntax
3780 1            postfix-expression:
3781                     primary-expression
3782                     postfix-expression [ expression ]
3783                     postfix-expression ( argument-expression-listopt )
3784                     postfix-expression . identifier
3785                     postfix-expression -> identifier
3786                     postfix-expression ++
3787                     postfix-expression --
3788                     ( type-name ) { initializer-list }
3789                     ( type-name ) { initializer-list , }
3790              argument-expression-list:
3791                    assignment-expression
3792                    argument-expression-list , assignment-expression
3793
3794
3795
3796
3797 [page 79]
3798
3799     6.5.2.1 Array subscripting
3800     Constraints
3801 1   One of the expressions shall have type ''pointer to complete object type'', the other
3802     expression shall have integer type, and the result has type ''type''.
3803     Semantics
3804 2   A postfix expression followed by an expression in square brackets [] is a subscripted
3805     designation of an element of an array object. The definition of the subscript operator []
3806     is that E1[E2] is identical to (*((E1)+(E2))). Because of the conversion rules that
3807     apply to the binary + operator, if E1 is an array object (equivalently, a pointer to the
3808     initial element of an array object) and E2 is an integer, E1[E2] designates the E2-th
3809     element of E1 (counting from zero).
3810 3   Successive subscript operators designate an element of a multidimensional array object.
3811     If E is an n-dimensional array (n >= 2) with dimensions i x j x . . . x k, then E (used as
3812     other than an lvalue) is converted to a pointer to an (n - 1)-dimensional array with
3813     dimensions j x . . . x k. If the unary * operator is applied to this pointer explicitly, or
3814     implicitly as a result of subscripting, the result is the referenced (n - 1)-dimensional
3815     array, which itself is converted into a pointer if used as other than an lvalue. It follows
3816     from this that arrays are stored in row-major order (last subscript varies fastest).
3817 4   EXAMPLE        Consider the array object defined by the declaration
3818              int x[3][5];
3819     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
3820     array of five ints. In the expression x[i], which is equivalent to (*((x)+(i))), x is first converted to
3821     a pointer to the initial array of five ints. Then i is adjusted according to the type of x, which conceptually
3822     entails multiplying i by the size of the object to which the pointer points, namely an array of five int
3823     objects. The results are added and indirection is applied to yield an array of five ints. When used in the
3824     expression x[i][j], that array is in turn converted to a pointer to the first of the ints, so x[i][j]
3825     yields an int.
3826
3827     Forward references: additive operators (6.5.6), address and indirection operators
3828     (6.5.3.2), array declarators (6.7.6.2).
3829     6.5.2.2 Function calls
3830     Constraints
3831 1   The expression that denotes the called function91) shall have type pointer to function
3832     returning void or returning a complete object type other than an array type.
3833 2   If the expression that denotes the called function has a type that includes a prototype, the
3834     number of arguments shall agree with the number of parameters. Each argument shall
3835
3836
3837     91) Most often, this is the result of converting an identifier that is a function designator.
3838
3839 [page 80]
3840
3841     have a type such that its value may be assigned to an object with the unqualified version
3842     of the type of its corresponding parameter.
3843     Semantics
3844 3   A postfix expression followed by parentheses () containing a possibly empty, comma-
3845     separated list of expressions is a function call. The postfix expression denotes the called
3846     function. The list of expressions specifies the arguments to the function.
3847 4   An argument may be an expression of any complete object type. In preparing for the call
3848     to a function, the arguments are evaluated, and each parameter is assigned the value of the
3849     corresponding argument.92)
3850 5   If the expression that denotes the called function has type pointer to function returning an
3851     object type, the function call expression has the same type as that object type, and has the
3852     value determined as specified in 6.8.6.4. Otherwise, the function call has type void.
3853 6   If the expression that denotes the called function has a type that does not include a
3854     prototype, the integer promotions are performed on each argument, and arguments that
3855     have type float are promoted to double. These are called the default argument
3856     promotions. If the number of arguments does not equal the number of parameters, the
3857     behavior is undefined. If the function is defined with a type that includes a prototype, and
3858     either the prototype ends with an ellipsis (, ...) or the types of the arguments after
3859     promotion are not compatible with the types of the parameters, the behavior is undefined.
3860     If the function is defined with a type that does not include a prototype, and the types of
3861     the arguments after promotion are not compatible with those of the parameters after
3862     promotion, the behavior is undefined, except for the following cases:
3863     -- one promoted type is a signed integer type, the other promoted type is the
3864       corresponding unsigned integer type, and the value is representable in both types;
3865     -- both types are pointers to qualified or unqualified versions of a character type or
3866       void.
3867 7   If the expression that denotes the called function has a type that does include a prototype,
3868     the arguments are implicitly converted, as if by assignment, to the types of the
3869     corresponding parameters, taking the type of each parameter to be the unqualified version
3870     of its declared type. The ellipsis notation in a function prototype declarator causes
3871     argument type conversion to stop after the last declared parameter. The default argument
3872     promotions are performed on trailing arguments.
3873
3874
3875
3876     92) A function may change the values of its parameters, but these changes cannot affect the values of the
3877         arguments. On the other hand, it is possible to pass a pointer to an object, and the function may
3878         change the value of the object pointed to. A parameter declared to have array or function type is
3879         adjusted to have a pointer type as described in 6.9.1.
3880
3881 [page 81]
3882
3883 8    No other conversions are performed implicitly; in particular, the number and types of
3884      arguments are not compared with those of the parameters in a function definition that
3885      does not include a function prototype declarator.
3886 9    If the function is defined with a type that is not compatible with the type (of the
3887      expression) pointed to by the expression that denotes the called function, the behavior is
3888      undefined.
3889 10   There is a sequence point after the evaluations of the function designator and the actual
3890      arguments but before the actual call. Every evaluation in the calling function (including
3891      other function calls) that is not otherwise specifically sequenced before or after the
3892      execution of the body of the called function is indeterminately sequenced with respect to
3893      the execution of the called function.93)
3894 11   Recursive function calls shall be permitted, both directly and indirectly through any chain
3895      of other functions.
3896 12   EXAMPLE        In the function call
3897               (*pf[f1()]) (f2(), f3() + f4())
3898      the functions f1, f2, f3, and f4 may be called in any order. All side effects have to be completed before
3899      the function pointed to by pf[f1()] is called.
3900
3901      Forward references: function declarators (including prototypes) (6.7.6.3), function
3902      definitions (6.9.1), the return statement (6.8.6.4), simple assignment (6.5.16.1).
3903      6.5.2.3 Structure and union members
3904      Constraints
3905 1    The first operand of the . operator shall have a qualified or unqualified structure or union
3906      type, and the second operand shall name a member of that type.
3907 2    The first operand of the -> operator shall have type ''pointer to qualified or unqualified
3908      structure'' or ''pointer to qualified or unqualified union'', and the second operand shall
3909      name a member of the type pointed to.
3910      Semantics
3911 3    A postfix expression followed by the . operator and an identifier designates a member of
3912      a structure or union object. The value is that of the named member,94) and is an lvalue if
3913      the first expression is an lvalue. If the first expression has qualified type, the result has
3914      the so-qualified version of the type of the designated member.
3915
3916      93) In other words, function executions do not ''interleave'' with each other.
3917      94) If the member used to access the contents of a union object is not the same as the member last used to
3918          store a value in the object, the appropriate part of the object representation of the value is reinterpreted
3919          as an object representation in the new type as described in 6.2.6 (a process sometimes called ''type
3920          punning''). This might be a trap representation.
3921
3922 [page 82]
3923
3924 4   A postfix expression followed by the -> operator and an identifier designates a member
3925     of a structure or union object. The value is that of the named member of the object to
3926     which the first expression points, and is an lvalue.95) If the first expression is a pointer to
3927     a qualified type, the result has the so-qualified version of the type of the designated
3928     member.
3929 5   Accessing a member of an _Atomic-qualified structure or union object results in
3930     undefined behavior.96)
3931 6   One special guarantee is made in order to simplify the use of unions: if a union contains
3932     several structures that share a common initial sequence (see below), and if the union
3933     object currently contains one of these structures, it is permitted to inspect the common
3934     initial part of any of them anywhere that a declaration of the completed type of the union
3935     is visible. Two structures share a common initial sequence if corresponding members
3936     have compatible types (and, for bit-fields, the same widths) for a sequence of one or more
3937     initial members.
3938 7   EXAMPLE 1 If f is a function returning a structure or union, and x is a member of that structure or
3939     union, f().x is a valid postfix expression but is not an lvalue.
3940
3941 8   EXAMPLE 2       In:
3942              struct s { int i; const int ci; };
3943              struct s s;
3944              const struct s cs;
3945              volatile struct s vs;
3946     the various members have the types:
3947              s.i          int
3948              s.ci         const int
3949              cs.i         const int
3950              cs.ci        const int
3951              vs.i         volatile int
3952              vs.ci        volatile const int
3953
3954
3955
3956
3957     95) If &E is a valid pointer expression (where & is the ''address-of '' operator, which generates a pointer to
3958         its operand), the expression (&E)->MOS is the same as E.MOS.
3959     96) A data race would occur if access to the entire structure or union in one thread conflicts with access to
3960         a member from another thread, where at least one access is a modification. Such a data race results in
3961         undefined behavior.
3962
3963 [page 83]
3964
3965 9   EXAMPLE 3       The following is a valid fragment:
3966              union {
3967                      struct {
3968                            int      alltypes;
3969                      } n;
3970                      struct {
3971                            int      type;
3972                            int      intnode;
3973                      } ni;
3974                      struct {
3975                            int      type;
3976                            double doublenode;
3977                      } nf;
3978              } u;
3979              u.nf.type = 1;
3980              u.nf.doublenode = 3.14;
3981              /* ... */
3982              if (u.n.alltypes == 1)
3983                      if (sin(u.nf.doublenode) == 0.0)
3984                            /* ... */
3985     The following is not a valid fragment (because the union type is not visible within function f):
3986              struct t1 { int m; };
3987              struct t2 { int m; };
3988              int f(struct t1 *p1, struct t2 *p2)
3989              {
3990                    if (p1->m < 0)
3991                            p2->m = -p2->m;
3992                    return p1->m;
3993              }
3994              int g()
3995              {
3996                    union {
3997                            struct t1 s1;
3998                            struct t2 s2;
3999                    } u;
4000                    /* ... */
4001                    return f(&u.s1, &u.s2);
4002              }
4003
4004     Forward references: address and indirection operators (6.5.3.2), structure and union
4005     specifiers (6.7.2.1).
4006
4007
4008
4009
4010 [page 84]
4011
4012     6.5.2.4 Postfix increment and decrement operators
4013     Constraints
4014 1   The operand of the postfix increment or decrement operator shall have qualified or
4015     unqualified real or pointer type and shall be a modifiable lvalue.
4016     Semantics
4017 2   The result of the postfix ++ operator is the value of the operand. As a side effect, the
4018     value of the operand object is incremented (that is, the value 1 of the appropriate type is
4019     added to it). See the discussions of additive operators and compound assignment for
4020     information on constraints, types, and conversions and the effects of operations on
4021     pointers. The value computation of the result is sequenced before the side effect of
4022     updating the stored value of the operand. With respect to an indeterminately-sequenced
4023     function call, the operation of postfix ++ is a single evaluation. Postfix ++ on an object
4024     with     _Atomic-qualified       type   is    a    read-modify-write      operation    with
4025                                                              97)
4026     memory_order_seq_cst memory order semantics.
4027 3   The postfix -- operator is analogous to the postfix ++ operator, except that the value of
4028     the operand is decremented (that is, the value 1 of the appropriate type is subtracted from
4029     it).
4030     Forward references: additive operators (6.5.6), compound assignment (6.5.16.2).
4031     6.5.2.5 Compound literals
4032     Constraints
4033 1   The type name shall specify a complete object type or an array of unknown size, but not a
4034     variable length array type.
4035 2   All the constraints for initializer lists in 6.7.9 also apply to compound literals.
4036     Semantics
4037 3   A postfix expression that consists of a parenthesized type name followed by a brace-
4038     enclosed list of initializers is a compound literal. It provides an unnamed object whose
4039     value is given by the initializer list.98)
4040
4041
4042     97) Where a pointer to an atomic object can be formed, this is equivalent to the following code sequence
4043         where T is the type of E:
4044                  T tmp;
4045                  T result = E;
4046                  do {
4047                         tmp = result + 1;
4048                  } while (!atomic_compare_exchange_strong(&E, &result, tmp));
4049          with result being the result of the operation.
4050
4051 [page 85]
4052
4053 4    If the type name specifies an array of unknown size, the size is determined by the
4054      initializer list as specified in 6.7.9, and the type of the compound literal is that of the
4055      completed array type. Otherwise (when the type name specifies an object type), the type
4056      of the compound literal is that specified by the type name. In either case, the result is an
4057      lvalue.
4058 5    The value of the compound literal is that of an unnamed object initialized by the
4059      initializer list. If the compound literal occurs outside the body of a function, the object
4060      has static storage duration; otherwise, it has automatic storage duration associated with
4061      the enclosing block.
4062 6    All the semantic rules for initializer lists in 6.7.9 also apply to compound literals.99)
4063 7    String literals, and compound literals with const-qualified types, need not designate
4064      distinct objects.100)
4065 8    EXAMPLE 1       The file scope definition
4066               int *p = (int []){2, 4};
4067      initializes p to point to the first element of an array of two ints, the first having the value two and the
4068      second, four. The expressions in this compound literal are required to be constant. The unnamed object
4069      has static storage duration.
4070
4071 9    EXAMPLE 2       In contrast, in
4072               void f(void)
4073               {
4074                     int *p;
4075                     /*...*/
4076                     p = (int [2]){*p};
4077                     /*...*/
4078               }
4079      p is assigned the address of the first element of an array of two ints, the first having the value previously
4080      pointed to by p and the second, zero. The expressions in this compound literal need not be constant. The
4081      unnamed object has automatic storage duration.
4082
4083 10   EXAMPLE 3 Initializers with designations can be combined with compound literals. Structure objects
4084      created using compound literals can be passed to functions without depending on member order:
4085               drawline((struct point){.x=1, .y=1},
4086                     (struct point){.x=3, .y=4});
4087      Or, if drawline instead expected pointers to struct point:
4088
4089
4090
4091      98) Note that this differs from a cast expression. For example, a cast specifies a conversion to scalar types
4092          or void only, and the result of a cast expression is not an lvalue.
4093      99) For example, subobjects without explicit initializers are initialized to zero.
4094      100) This allows implementations to share storage for string literals and constant compound literals with
4095           the same or overlapping representations.
4096
4097 [page 86]
4098
4099               drawline(&(struct point){.x=1, .y=1},
4100                     &(struct point){.x=3, .y=4});
4101
4102 11   EXAMPLE 4        A read-only compound literal can be specified through constructions like:
4103               (const float []){1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6}
4104
4105 12   EXAMPLE 5        The following three expressions have different meanings:
4106               "/tmp/fileXXXXXX"
4107               (char []){"/tmp/fileXXXXXX"}
4108               (const char []){"/tmp/fileXXXXXX"}
4109      The first always has static storage duration and has type array of char, but need not be modifiable; the last
4110      two have automatic storage duration when they occur within the body of a function, and the first of these
4111      two is modifiable.
4112
4113 13   EXAMPLE 6 Like string literals, const-qualified compound literals can be placed into read-only memory
4114      and can even be shared. For example,
4115               (const char []){"abc"} == "abc"
4116      might yield 1 if the literals' storage is shared.
4117
4118 14   EXAMPLE 7 Since compound literals are unnamed, a single compound literal cannot specify a circularly
4119      linked object. For example, there is no way to write a self-referential compound literal that could be used
4120      as the function argument in place of the named object endless_zeros below:
4121               struct int_list { int car; struct int_list *cdr; };
4122               struct int_list endless_zeros = {0, &endless_zeros};
4123               eval(endless_zeros);
4124
4125 15   EXAMPLE 8        Each compound literal creates only a single object in a given scope:
4126               struct s { int i; };
4127               int f (void)
4128               {
4129                     struct s *p = 0, *q;
4130                     int j = 0;
4131               again:
4132                         q = p, p = &((struct s){ j++ });
4133                         if (j < 2) goto again;
4134                         return p == q && q->i == 1;
4135               }
4136      The function f() always returns the value 1.
4137 16   Note that if an iteration statement were used instead of an explicit goto and a labeled statement, the
4138      lifetime of the unnamed object would be the body of the loop only, and on entry next time around p would
4139      have an indeterminate value, which would result in undefined behavior.
4140
4141      Forward references: type names (6.7.7), initialization (6.7.9).
4142
4143
4144
4145
4146 [page 87]
4147
4148     6.5.3 Unary operators
4149     Syntax
4150 1            unary-expression:
4151                     postfix-expression
4152                     ++ unary-expression
4153                     -- unary-expression
4154                     unary-operator cast-expression
4155                     sizeof unary-expression
4156                     sizeof ( type-name )
4157                     alignof ( type-name )
4158              unary-operator: one of
4159                     & * + - ~             !
4160     6.5.3.1 Prefix increment and decrement operators
4161     Constraints
4162 1   The operand of the prefix increment or decrement operator shall have qualified or
4163     unqualified real or pointer type and shall be a modifiable lvalue.
4164     Semantics
4165 2   The value of the operand of the prefix ++ operator is incremented. The result is the new
4166     value of the operand after incrementation. The expression ++E is equivalent to (E+=1).
4167     See the discussions of additive operators and compound assignment for information on
4168     constraints, types, side effects, and conversions and the effects of operations on pointers.
4169 3   The prefix -- operator is analogous to the prefix ++ operator, except that the value of the
4170     operand is decremented.
4171     Forward references: additive operators (6.5.6), compound assignment (6.5.16.2).
4172     6.5.3.2 Address and indirection operators
4173     Constraints
4174 1   The operand of the unary & operator shall be either a function designator, the result of a
4175     [] or unary * operator, or an lvalue that designates an object that is not a bit-field and is
4176     not declared with the register storage-class specifier.
4177 2   The operand of the unary * operator shall have pointer type.
4178     Semantics
4179 3   The unary & operator yields the address of its operand. If the operand has type ''type'',
4180     the result has type ''pointer to type''. If the operand is the result of a unary * operator,
4181     neither that operator nor the & operator is evaluated and the result is as if both were
4182     omitted, except that the constraints on the operators still apply and the result is not an
4183
4184 [page 88]
4185
4186     lvalue. Similarly, if the operand is the result of a [] operator, neither the & operator nor
4187     the unary * that is implied by the [] is evaluated and the result is as if the & operator
4188     were removed and the [] operator were changed to a + operator. Otherwise, the result is
4189     a pointer to the object or function designated by its operand.
4190 4   The unary * operator denotes indirection. If the operand points to a function, the result is
4191     a function designator; if it points to an object, the result is an lvalue designating the
4192     object. If the operand has type ''pointer to type'', the result has type ''type''. If an
4193     invalid value has been assigned to the pointer, the behavior of the unary * operator is
4194     undefined.101)
4195     Forward references: storage-class specifiers (6.7.1), structure and union specifiers
4196     (6.7.2.1).
4197     6.5.3.3 Unary arithmetic operators
4198     Constraints
4199 1   The operand of the unary + or - operator shall have arithmetic type; of the ~ operator,
4200     integer type; of the ! operator, scalar type.
4201     Semantics
4202 2   The result of the unary + operator is the value of its (promoted) operand. The integer
4203     promotions are performed on the operand, and the result has the promoted type.
4204 3   The result of the unary - operator is the negative of its (promoted) operand. The integer
4205     promotions are performed on the operand, and the result has the promoted type.
4206 4   The result of the ~ operator is the bitwise complement of its (promoted) operand (that is,
4207     each bit in the result is set if and only if the corresponding bit in the converted operand is
4208     not set). The integer promotions are performed on the operand, and the result has the
4209     promoted type. If the promoted type is an unsigned type, the expression ~E is equivalent
4210     to the maximum value representable in that type minus E.
4211 5   The result of the logical negation operator ! is 0 if the value of its operand compares
4212     unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int.
4213     The expression !E is equivalent to (0==E).
4214
4215
4216
4217     101) Thus, &*E is equivalent to E (even if E is a null pointer), and &(E1[E2]) to ((E1)+(E2)). It is
4218          always true that if E is a function designator or an lvalue that is a valid operand of the unary &
4219          operator, *&E is a function designator or an lvalue equal to E. If *P is an lvalue and T is the name of
4220          an object pointer type, *(T)P is an lvalue that has a type compatible with that to which T points.
4221          Among the invalid values for dereferencing a pointer by the unary * operator are a null pointer, an
4222          address inappropriately aligned for the type of object pointed to, and the address of an object after the
4223          end of its lifetime.
4224
4225 [page 89]
4226
4227     6.5.3.4 The sizeof and alignof operators
4228     Constraints
4229 1   The sizeof operator shall not be applied to an expression that has function type or an
4230     incomplete type, to the parenthesized name of such a type, or to an expression that
4231     designates a bit-field member. The alignof operator shall not be applied to a function
4232     type or an incomplete type.
4233     Semantics
4234 2   The sizeof operator yields the size (in bytes) of its operand, which may be an
4235     expression or the parenthesized name of a type. The size is determined from the type of
4236     the operand. The result is an integer. If the type of the operand is a variable length array
4237     type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an
4238     integer constant.
4239 3   The alignof operator yields the alignment requirement of its operand type. The result
4240     is an integer constant. When applied to an array type, the result is the alignment
4241     requirement of the element type.
4242 4   When sizeof is applied to an operand that has type char, unsigned char, or
4243     signed char, (or a qualified version thereof) the result is 1. When applied to an
4244     operand that has array type, the result is the total number of bytes in the array.102) When
4245     applied to an operand that has structure or union type, the result is the total number of
4246     bytes in such an object, including internal and trailing padding.
4247 5   The value of the result of both operators is implementation-defined, and its type (an
4248     unsigned integer type) is size_t, defined in <stddef.h> (and other headers).
4249 6   EXAMPLE 1 A principal use of the sizeof operator is in communication with routines such as storage
4250     allocators and I/O systems. A storage-allocation function might accept a size (in bytes) of an object to
4251     allocate and return a pointer to void. For example:
4252             extern void *alloc(size_t);
4253             double *dp = alloc(sizeof *dp);
4254     The implementation of the alloc function should ensure that its return value is aligned suitably for
4255     conversion to a pointer to double.
4256
4257 7   EXAMPLE 2      Another use of the sizeof operator is to compute the number of elements in an array:
4258             sizeof array / sizeof array[0]
4259
4260 8   EXAMPLE 3      In this example, the size of a variable length array is computed and returned from a
4261     function:
4262             #include <stddef.h>
4263
4264
4265
4266     102) When applied to a parameter declared to have array or function type, the sizeof operator yields the
4267          size of the adjusted (pointer) type (see 6.9.1).
4268
4269 [page 90]
4270
4271              size_t fsize3(int n)
4272              {
4273                    char b[n+3];                  // variable length array
4274                    return sizeof b;              // execution time sizeof
4275              }
4276              int main()
4277              {
4278                    size_t size;
4279                    size = fsize3(10); // fsize3 returns 13
4280                    return 0;
4281              }
4282
4283     Forward references: common definitions <stddef.h> (7.19), declarations (6.7),
4284     structure and union specifiers (6.7.2.1), type names (6.7.7), array declarators (6.7.6.2).
4285     6.5.4 Cast operators
4286     Syntax
4287 1            cast-expression:
4288                     unary-expression
4289                     ( type-name ) cast-expression
4290     Constraints
4291 2   Unless the type name specifies a void type, the type name shall specify qualified or
4292     unqualified scalar type and the operand shall have scalar type.
4293 3   Conversions that involve pointers, other than where permitted by the constraints of
4294     6.5.16.1, shall be specified by means of an explicit cast.
4295 4   A pointer type shall not be converted to any floating type. A floating type shall not be
4296     converted to any pointer type.
4297     Semantics
4298 5   Preceding an expression by a parenthesized type name converts the value of the
4299     expression to the named type. This construction is called a cast.103) A cast that specifies
4300     no conversion has no effect on the type or value of an expression.
4301 6   If the value of the expression is represented with greater precision or range than required
4302     by the type named by the cast (6.3.1.8), then the cast specifies a conversion even if the
4303     type of the expression is the same as the named type.
4304     Forward references: equality operators (6.5.9), function declarators (including
4305     prototypes) (6.7.6.3), simple assignment (6.5.16.1), type names (6.7.7).
4306
4307
4308
4309     103) A cast does not yield an lvalue. Thus, a cast to a qualified type has the same effect as a cast to the
4310          unqualified version of the type.
4311
4312 [page 91]
4313
4314     6.5.5 Multiplicative operators
4315     Syntax
4316 1            multiplicative-expression:
4317                      cast-expression
4318                      multiplicative-expression * cast-expression
4319                      multiplicative-expression / cast-expression
4320                      multiplicative-expression % cast-expression
4321     Constraints
4322 2   Each of the operands shall have arithmetic type. The operands of the % operator shall
4323     have integer type.
4324     Semantics
4325 3   The usual arithmetic conversions are performed on the operands.
4326 4   The result of the binary * operator is the product of the operands.
4327 5   The result of the / operator is the quotient from the division of the first operand by the
4328     second; the result of the % operator is the remainder. In both operations, if the value of
4329     the second operand is zero, the behavior is undefined.
4330 6   When integers are divided, the result of the / operator is the algebraic quotient with any
4331     fractional part discarded.104) If the quotient a/b is representable, the expression
4332     (a/b)*b + a%b shall equal a; otherwise, the behavior of both a/b and a%b is
4333     undefined.
4334     6.5.6 Additive operators
4335     Syntax
4336 1            additive-expression:
4337                     multiplicative-expression
4338                     additive-expression + multiplicative-expression
4339                     additive-expression - multiplicative-expression
4340     Constraints
4341 2   For addition, either both operands shall have arithmetic type, or one operand shall be a
4342     pointer to a complete object type and the other shall have integer type. (Incrementing is
4343     equivalent to adding 1.)
4344 3   For subtraction, one of the following shall hold:
4345
4346
4347
4348
4349     104) This is often called ''truncation toward zero''.
4350
4351 [page 92]
4352
4353     -- both operands have arithmetic type;
4354     -- both operands are pointers to qualified or unqualified versions of compatible complete
4355       object types; or
4356     -- the left operand is a pointer to a complete object type and the right operand has
4357       integer type.
4358     (Decrementing is equivalent to subtracting 1.)
4359     Semantics
4360 4   If both operands have arithmetic type, the usual arithmetic conversions are performed on
4361     them.
4362 5   The result of the binary + operator is the sum of the operands.
4363 6   The result of the binary - operator is the difference resulting from the subtraction of the
4364     second operand from the first.
4365 7   For the purposes of these operators, a pointer to an object that is not an element of an
4366     array behaves the same as a pointer to the first element of an array of length one with the
4367     type of the object as its element type.
4368 8   When an expression that has integer type is added to or subtracted from a pointer, the
4369     result has the type of the pointer operand. If the pointer operand points to an element of
4370     an array object, and the array is large enough, the result points to an element offset from
4371     the original element such that the difference of the subscripts of the resulting and original
4372     array elements equals the integer expression. In other words, if the expression P points to
4373     the i-th element of an array object, the expressions (P)+N (equivalently, N+(P)) and
4374     (P)-N (where N has the value n) point to, respectively, the i+n-th and i-n-th elements of
4375     the array object, provided they exist. Moreover, if the expression P points to the last
4376     element of an array object, the expression (P)+1 points one past the last element of the
4377     array object, and if the expression Q points one past the last element of an array object,
4378     the expression (Q)-1 points to the last element of the array object. If both the pointer
4379     operand and the result point to elements of the same array object, or one past the last
4380     element of the array object, the evaluation shall not produce an overflow; otherwise, the
4381     behavior is undefined. If the result points one past the last element of the array object, it
4382     shall not be used as the operand of a unary * operator that is evaluated.
4383 9   When two pointers are subtracted, both shall point to elements of the same array object,
4384     or one past the last element of the array object; the result is the difference of the
4385     subscripts of the two array elements. The size of the result is implementation-defined,
4386     and its type (a signed integer type) is ptrdiff_t defined in the <stddef.h> header.
4387     If the result is not representable in an object of that type, the behavior is undefined. In
4388     other words, if the expressions P and Q point to, respectively, the i-th and j-th elements of
4389     an array object, the expression (P)-(Q) has the value i-j provided the value fits in an
4390
4391 [page 93]
4392
4393      object of type ptrdiff_t. Moreover, if the expression P points either to an element of
4394      an array object or one past the last element of an array object, and the expression Q points
4395      to the last element of the same array object, the expression ((Q)+1)-(P) has the same
4396      value as ((Q)-(P))+1 and as -((P)-((Q)+1)), and has the value zero if the
4397      expression P points one past the last element of the array object, even though the
4398      expression (Q)+1 does not point to an element of the array object.105)
4399 10   EXAMPLE        Pointer arithmetic is well defined with pointers to variable length array types.
4400               {
4401                        int n = 4, m = 3;
4402                        int a[n][m];
4403                        int (*p)[m] = a;            //   p == &a[0]
4404                        p += 1;                     //   p == &a[1]
4405                        (*p)[2] = 99;               //   a[1][2] == 99
4406                        n = p - a;                  //   n == 1
4407               }
4408 11   If array a in the above example were declared to be an array of known constant size, and pointer p were
4409      declared to be a pointer to an array of the same known constant size (pointing to a), the results would be
4410      the same.
4411
4412      Forward references: array declarators (6.7.6.2), common definitions <stddef.h>
4413      (7.19).
4414      6.5.7 Bitwise shift operators
4415      Syntax
4416 1             shift-expression:
4417                       additive-expression
4418                       shift-expression << additive-expression
4419                       shift-expression >> additive-expression
4420      Constraints
4421 2    Each of the operands shall have integer type.
4422      Semantics
4423 3    The integer promotions are performed on each of the operands. The type of the result is
4424      that of the promoted left operand. If the value of the right operand is negative or is
4425
4426      105) Another way to approach pointer arithmetic is first to convert the pointer(s) to character pointer(s): In
4427           this scheme the integer expression added to or subtracted from the converted pointer is first multiplied
4428           by the size of the object originally pointed to, and the resulting pointer is converted back to the
4429           original type. For pointer subtraction, the result of the difference between the character pointers is
4430           similarly divided by the size of the object originally pointed to.
4431           When viewed in this way, an implementation need only provide one extra byte (which may overlap
4432           another object in the program) just after the end of the object in order to satisfy the ''one past the last
4433           element'' requirements.
4434
4435 [page 94]
4436
4437     greater than or equal to the width of the promoted left operand, the behavior is undefined.
4438 4   The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with
4439     zeros. If E1 has an unsigned type, the value of the result is E1 x 2E2 , reduced modulo
4440     one more than the maximum value representable in the result type. If E1 has a signed
4441     type and nonnegative value, and E1 x 2E2 is representable in the result type, then that is
4442     the resulting value; otherwise, the behavior is undefined.
4443 5   The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type
4444     or if E1 has a signed type and a nonnegative value, the value of the result is the integral
4445     part of the quotient of E1 / 2E2 . If E1 has a signed type and a negative value, the
4446     resulting value is implementation-defined.
4447     6.5.8 Relational operators
4448     Syntax
4449 1            relational-expression:
4450                      shift-expression
4451                      relational-expression   <    shift-expression
4452                      relational-expression   >    shift-expression
4453                      relational-expression   <=   shift-expression
4454                      relational-expression   >=   shift-expression
4455     Constraints
4456 2   One of the following shall hold:
4457     -- both operands have real type; or
4458     -- both operands are pointers to qualified or unqualified versions of compatible object
4459       types.
4460     Semantics
4461 3   If both of the operands have arithmetic type, the usual arithmetic conversions are
4462     performed.
4463 4   For the purposes of these operators, a pointer to an object that is not an element of an
4464     array behaves the same as a pointer to the first element of an array of length one with the
4465     type of the object as its element type.
4466 5   When two pointers are compared, the result depends on the relative locations in the
4467     address space of the objects pointed to. If two pointers to object types both point to the
4468     same object, or both point one past the last element of the same array object, they
4469     compare equal. If the objects pointed to are members of the same aggregate object,
4470     pointers to structure members declared later compare greater than pointers to members
4471     declared earlier in the structure, and pointers to array elements with larger subscript
4472     values compare greater than pointers to elements of the same array with lower subscript
4473
4474 [page 95]
4475
4476     values. All pointers to members of the same union object compare equal. If the
4477     expression P points to an element of an array object and the expression Q points to the
4478     last element of the same array object, the pointer expression Q+1 compares greater than
4479     P. In all other cases, the behavior is undefined.
4480 6   Each of the operators < (less than), > (greater than), <= (less than or equal to), and >=
4481     (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is
4482     false.106) The result has type int.
4483     6.5.9 Equality operators
4484     Syntax
4485 1            equality-expression:
4486                     relational-expression
4487                     equality-expression == relational-expression
4488                     equality-expression != relational-expression
4489     Constraints
4490 2   One of the following shall hold:
4491     -- both operands have arithmetic type;
4492     -- both operands are pointers to qualified or unqualified versions of compatible types;
4493     -- one operand is a pointer to an object type and the other is a pointer to a qualified or
4494       unqualified version of void; or
4495     -- one operand is a pointer and the other is a null pointer constant.
4496     Semantics
4497 3   The == (equal to) and != (not equal to) operators are analogous to the relational
4498     operators except for their lower precedence.107) Each of the operators yields 1 if the
4499     specified relation is true and 0 if it is false. The result has type int. For any pair of
4500     operands, exactly one of the relations is true.
4501 4   If both of the operands have arithmetic type, the usual arithmetic conversions are
4502     performed. Values of complex types are equal if and only if both their real parts are equal
4503     and also their imaginary parts are equal. Any two values of arithmetic types from
4504     different type domains are equal if and only if the results of their conversions to the
4505     (complex) result type determined by the usual arithmetic conversions are equal.
4506
4507
4508
4509     106) The expression a<b<c is not interpreted as in ordinary mathematics. As the syntax indicates, it
4510          means (a<b)<c; in other words, ''if a is less than b, compare 1 to c; otherwise, compare 0 to c''.
4511     107) Because of the precedences, a<b == c<d is 1 whenever a<b and c<d have the same truth-value.
4512
4513 [page 96]
4514
4515 5   Otherwise, at least one operand is a pointer. If one operand is a pointer and the other is a
4516     null pointer constant, the null pointer constant is converted to the type of the pointer. If
4517     one operand is a pointer to an object type and the other is a pointer to a qualified or
4518     unqualified version of void, the former is converted to the type of the latter.
4519 6   Two pointers compare equal if and only if both are null pointers, both are pointers to the
4520     same object (including a pointer to an object and a subobject at its beginning) or function,
4521     both are pointers to one past the last element of the same array object, or one is a pointer
4522     to one past the end of one array object and the other is a pointer to the start of a different
4523     array object that happens to immediately follow the first array object in the address
4524     space.108)
4525 7   For the purposes of these operators, a pointer to an object that is not an element of an
4526     array behaves the same as a pointer to the first element of an array of length one with the
4527     type of the object as its element type.
4528     6.5.10 Bitwise AND operator
4529     Syntax
4530 1            AND-expression:
4531                    equality-expression
4532                    AND-expression & equality-expression
4533     Constraints
4534 2   Each of the operands shall have integer type.
4535     Semantics
4536 3   The usual arithmetic conversions are performed on the operands.
4537 4   The result of the binary & operator is the bitwise AND of the operands (that is, each bit in
4538     the result is set if and only if each of the corresponding bits in the converted operands is
4539     set).
4540
4541
4542
4543
4544     108) Two objects may be adjacent in memory because they are adjacent elements of a larger array or
4545          adjacent members of a structure with no padding between them, or because the implementation chose
4546          to place them so, even though they are unrelated. If prior invalid pointer operations (such as accesses
4547          outside array bounds) produced undefined behavior, subsequent comparisons also produce undefined
4548          behavior.
4549
4550 [page 97]
4551
4552     6.5.11 Bitwise exclusive OR operator
4553     Syntax
4554 1            exclusive-OR-expression:
4555                      AND-expression
4556                      exclusive-OR-expression ^ AND-expression
4557     Constraints
4558 2   Each of the operands shall have integer type.
4559     Semantics
4560 3   The usual arithmetic conversions are performed on the operands.
4561 4   The result of the ^ operator is the bitwise exclusive OR of the operands (that is, each bit
4562     in the result is set if and only if exactly one of the corresponding bits in the converted
4563     operands is set).
4564     6.5.12 Bitwise inclusive OR operator
4565     Syntax
4566 1            inclusive-OR-expression:
4567                      exclusive-OR-expression
4568                      inclusive-OR-expression | exclusive-OR-expression
4569     Constraints
4570 2   Each of the operands shall have integer type.
4571     Semantics
4572 3   The usual arithmetic conversions are performed on the operands.
4573 4   The result of the | operator is the bitwise inclusive OR of the operands (that is, each bit in
4574     the result is set if and only if at least one of the corresponding bits in the converted
4575     operands is set).
4576
4577
4578
4579
4580 [page 98]
4581
4582     6.5.13 Logical AND operator
4583     Syntax
4584 1             logical-AND-expression:
4585                       inclusive-OR-expression
4586                       logical-AND-expression && inclusive-OR-expression
4587     Constraints
4588 2   Each of the operands shall have scalar type.
4589     Semantics
4590 3   The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it
4591     yields 0. The result has type int.
4592 4   Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation;
4593     if the second operand is evaluated, there is a sequence point between the evaluations of
4594     the first and second operands. If the first operand compares equal to 0, the second
4595     operand is not evaluated.
4596     6.5.14 Logical OR operator
4597     Syntax
4598 1             logical-OR-expression:
4599                       logical-AND-expression
4600                       logical-OR-expression || logical-AND-expression
4601     Constraints
4602 2   Each of the operands shall have scalar type.
4603     Semantics
4604 3   The || operator shall yield 1 if either of its operands compare unequal to 0; otherwise, it
4605     yields 0. The result has type int.
4606 4   Unlike the bitwise | operator, the || operator guarantees left-to-right evaluation; if the
4607     second operand is evaluated, there is a sequence point between the evaluations of the first
4608     and second operands. If the first operand compares unequal to 0, the second operand is
4609     not evaluated.
4610
4611
4612
4613
4614 [page 99]
4615
4616     6.5.15 Conditional operator
4617     Syntax
4618 1            conditional-expression:
4619                     logical-OR-expression
4620                     logical-OR-expression ? expression : conditional-expression
4621     Constraints
4622 2   The first operand shall have scalar type.
4623 3   One of the following shall hold for the second and third operands:
4624     -- both operands have arithmetic type;
4625     -- both operands have the same structure or union type;
4626     -- both operands have void type;
4627     -- both operands are pointers to qualified or unqualified versions of compatible types;
4628     -- one operand is a pointer and the other is a null pointer constant; or
4629     -- one operand is a pointer to an object type and the other is a pointer to a qualified or
4630       unqualified version of void.
4631     Semantics
4632 4   The first operand is evaluated; there is a sequence point between its evaluation and the
4633     evaluation of the second or third operand (whichever is evaluated). The second operand
4634     is evaluated only if the first compares unequal to 0; the third operand is evaluated only if
4635     the first compares equal to 0; the result is the value of the second or third operand
4636     (whichever is evaluated), converted to the type described below.109)
4637 5   If both the second and third operands have arithmetic type, the result type that would be
4638     determined by the usual arithmetic conversions, were they applied to those two operands,
4639     is the type of the result. If both the operands have structure or union type, the result has
4640     that type. If both operands have void type, the result has void type.
4641 6   If both the second and third operands are pointers or one is a null pointer constant and the
4642     other is a pointer, the result type is a pointer to a type qualified with all the type qualifiers
4643     of the types referenced by both operands. Furthermore, if both operands are pointers to
4644     compatible types or to differently qualified versions of compatible types, the result type is
4645     a pointer to an appropriately qualified version of the composite type; if one operand is a
4646     null pointer constant, the result has the type of the other operand; otherwise, one operand
4647     is a pointer to void or a qualified version of void, in which case the result type is a
4648     pointer to an appropriately qualified version of void.
4649
4650     109) A conditional expression does not yield an lvalue.
4651
4652 [page 100]
4653
4654 7   EXAMPLE The common type that results when the second and third operands are pointers is determined
4655     in two independent stages. The appropriate qualifiers, for example, do not depend on whether the two
4656     pointers have compatible types.
4657 8   Given the declarations
4658               const void *c_vp;
4659               void *vp;
4660               const int *c_ip;
4661               volatile int *v_ip;
4662               int *ip;
4663               const char *c_cp;
4664     the third column in the following table is the common type that is the result of a conditional expression in
4665     which the first two columns are the second and third operands (in either order):
4666               c_vp    c_ip      const void *
4667               v_ip    0         volatile int *
4668               c_ip    v_ip      const volatile int *
4669               vp      c_cp      const void *
4670               ip      c_ip      const int *
4671               vp      ip        void *
4672
4673     6.5.16 Assignment operators
4674     Syntax
4675 1            assignment-expression:
4676                     conditional-expression
4677                     unary-expression assignment-operator assignment-expression
4678              assignment-operator: one of
4679                     = *= /= %= +=                       -=     <<=      >>=      &=     ^=     |=
4680     Constraints
4681 2   An assignment operator shall have a modifiable lvalue as its left operand.
4682     Semantics
4683 3   An assignment operator stores a value in the object designated by the left operand. An
4684     assignment expression has the value of the left operand after the assignment,110) but is not
4685     an lvalue. The type of an assignment expression is the type of the left operand unless the
4686     left operand has qualified type, in which case it is the unqualified version of the type of
4687     the left operand. The side effect of updating the stored value of the left operand is
4688     sequenced after the value computations of the left and right operands. The evaluations of
4689     the operands are unsequenced.
4690
4691
4692
4693
4694     110) The implementation is permitted to read the object to determine the value but is not required to, even
4695          when the object has volatile-qualified type.
4696
4697 [page 101]
4698
4699     6.5.16.1 Simple assignment
4700     Constraints
4701 1   One of the following shall hold:111)
4702     -- the left operand has qualified or unqualified arithmetic type and the right has
4703       arithmetic type;
4704     -- the left operand has a qualified or unqualified version of a structure or union type
4705       compatible with the type of the right;
4706     -- both operands are pointers to qualified or unqualified versions of compatible types,
4707       and the type pointed to by the left has all the qualifiers of the type pointed to by the
4708       right;
4709     -- one operand is a pointer to an object type and the other is a pointer to a qualified or
4710       unqualified version of void, and the type pointed to by the left has all the qualifiers
4711       of the type pointed to by the right;
4712     -- the left operand is a pointer and the right is a null pointer constant; or
4713     -- the left operand has type _Bool and the right is a pointer.
4714     Semantics
4715 2   In simple assignment (=), the value of the right operand is converted to the type of the
4716     assignment expression and replaces the value stored in the object designated by the left
4717     operand.
4718 3   If the value being stored in an object is read from another object that overlaps in any way
4719     the storage of the first object, then the overlap shall be exact and the two objects shall
4720     have qualified or unqualified versions of a compatible type; otherwise, the behavior is
4721     undefined.
4722 4   EXAMPLE 1       In the program fragment
4723             int f(void);
4724             char c;
4725             /* ... */
4726             if ((c = f()) == -1)
4727                     /* ... */
4728     the int value returned by the function may be truncated when stored in the char, and then converted back
4729     to int width prior to the comparison. In an implementation in which ''plain'' char has the same range of
4730     values as unsigned char (and char is narrower than int), the result of the conversion cannot be
4731
4732
4733
4734     111) The asymmetric appearance of these constraints with respect to type qualifiers is due to the conversion
4735          (specified in 6.3.2.1) that changes lvalues to ''the value of the expression'' and thus removes any type
4736          qualifiers that were applied to the type category of the expression (for example, it removes const but
4737          not volatile from the type int volatile * const).
4738
4739 [page 102]
4740
4741     negative, so the operands of the comparison can never compare equal. Therefore, for full portability, the
4742     variable c should be declared as int.
4743
4744 5   EXAMPLE 2       In the fragment:
4745             char c;
4746             int i;
4747             long l;
4748             l = (c = i);
4749     the value of i is converted to the type of the assignment expression c = i, that is, char type. The value
4750     of the expression enclosed in parentheses is then converted to the type of the outer assignment expression,
4751     that is, long int type.
4752
4753 6   EXAMPLE 3       Consider the fragment:
4754             const char **cpp;
4755             char *p;
4756             const char c = 'A';
4757             cpp = &p;                  // constraint violation
4758             *cpp = &c;                 // valid
4759             *p = 0;                    // valid
4760     The first assignment is unsafe because it would allow the following valid code to attempt to change the
4761     value of the const object c.
4762
4763     6.5.16.2 Compound assignment
4764     Constraints
4765 1   For the operators += and -= only, either the left operand shall be a pointer to a complete
4766     object type and the right shall have integer type, or the left operand shall have qualified or
4767     unqualified arithmetic type and the right shall have arithmetic type.
4768 2   For the other operators, each operand shall have arithmetic type consistent with those
4769     allowed by the corresponding binary operator.
4770     Semantics
4771 3   A compound assignment of the form E1 op = E2 is equivalent to the simple assignment
4772     expression E1 = E1 op (E2), except that the lvalue E1 is evaluated only once, and with
4773     respect to an indeterminately-sequenced function call, the operation of a compound
4774     assignment is a single evaluation. If E1 has an _Atomic-qualified type, compound
4775     assignment is a read-modify-write operation with memory_order_seq_cst memory
4776     order semantics.112)
4777
4778
4779
4780
4781 [page 103]
4782
4783     6.5.17 Comma operator
4784     Syntax
4785 1            expression:
4786                     assignment-expression
4787                     expression , assignment-expression
4788     Semantics
4789 2   The left operand of a comma operator is evaluated as a void expression; there is a
4790     sequence point between its evaluation and that of the right operand. Then the right
4791     operand is evaluated; the result has its type and value.113)
4792 3   EXAMPLE As indicated by the syntax, the comma operator (as described in this subclause) cannot
4793     appear in contexts where a comma is used to separate items in a list (such as arguments to functions or lists
4794     of initializers). On the other hand, it can be used within a parenthesized expression or within the second
4795     expression of a conditional operator in such contexts. In the function call
4796              f(a, (t=3, t+2), c)
4797     the function has three arguments, the second of which has the value 5.
4798
4799     Forward references: initialization (6.7.9).
4800
4801
4802
4803
4804     112) Where a pointer to an atomic object can be formed, this is equivalent to the following code sequence
4805          where T is the type of E1:
4806                   T tmp = E1;
4807                   T result;
4808                   do {
4809                         result = tmp op (E2);
4810                   } while (!atomic_compare_exchange_strong(&E1, &tmp, result));
4811           with result being the result of the operation.
4812     113) A comma operator does not yield an lvalue.
4813
4814 [page 104]
4815
4816     6.6 Constant expressions
4817     Syntax
4818 1            constant-expression:
4819                     conditional-expression
4820     Description
4821 2   A constant expression can be evaluated during translation rather than runtime, and
4822     accordingly may be used in any place that a constant may be.
4823     Constraints
4824 3   Constant expressions shall not contain assignment, increment, decrement, function-call,
4825     or comma operators, except when they are contained within a subexpression that is not
4826     evaluated.114)
4827 4   Each constant expression shall evaluate to a constant that is in the range of representable
4828     values for its type.
4829     Semantics
4830 5   An expression that evaluates to a constant is required in several contexts. If a floating
4831     expression is evaluated in the translation environment, the arithmetic precision and range
4832     shall be at least as great as if the expression were being evaluated in the execution
4833     environment.115)
4834 6   An integer constant expression116) shall have integer type and shall only have operands
4835     that are integer constants, enumeration constants, character constants, sizeof
4836     expressions whose results are integer constants, and floating constants that are the
4837     immediate operands of casts. Cast operators in an integer constant expression shall only
4838     convert arithmetic types to integer types, except as part of an operand to the sizeof
4839     operator.
4840 7   More latitude is permitted for constant expressions in initializers. Such a constant
4841     expression shall be, or evaluate to, one of the following:
4842     -- an arithmetic constant expression,
4843
4844
4845
4846     114) The operand of a sizeof operator is usually not evaluated (6.5.3.4).
4847     115) The use of evaluation formats as characterized by FLT_EVAL_METHOD also applies to evaluation in
4848          the translation environment.
4849     116) An integer constant expression is required in a number of contexts such as the size of a bit-field
4850          member of a structure, the value of an enumeration constant, and the size of a non-variable length
4851          array. Further constraints that apply to the integer constant expressions used in conditional-inclusion
4852          preprocessing directives are discussed in 6.10.1.
4853
4854 [page 105]
4855
4856      -- a null pointer constant,
4857      -- an address constant, or
4858      -- an address constant for a complete object type plus or minus an integer constant
4859        expression.
4860 8    An arithmetic constant expression shall have arithmetic type and shall only have
4861      operands that are integer constants, floating constants, enumeration constants, character
4862      constants, and sizeof expressions. Cast operators in an arithmetic constant expression
4863      shall only convert arithmetic types to arithmetic types, except as part of an operand to a
4864      sizeof operator whose result is an integer constant.
4865 9    An address constant is a null pointer, a pointer to an lvalue designating an object of static
4866      storage duration, or a pointer to a function designator; it shall be created explicitly using
4867      the unary & operator or an integer constant cast to pointer type, or implicitly by the use of
4868      an expression of array or function type. The array-subscript [] and member-access .
4869      and -> operators, the address & and indirection * unary operators, and pointer casts may
4870      be used in the creation of an address constant, but the value of an object shall not be
4871      accessed by use of these operators.
4872 10   An implementation may accept other forms of constant expressions.
4873 11   The semantic rules for the evaluation of a constant expression are the same as for
4874      nonconstant expressions.117)
4875      Forward references: array declarators (6.7.6.2), initialization (6.7.9).
4876
4877
4878
4879
4880      117) Thus, in the following initialization,
4881                     static int i = 2 || 1 / 0;
4882            the expression is a valid integer constant expression with value one.
4883
4884 [page 106]
4885
4886     6.7 Declarations
4887     Syntax
4888 1            declaration:
4889                     declaration-specifiers init-declarator-listopt ;
4890                     static_assert-declaration                                                      *
4891              declaration-specifiers:
4892                     storage-class-specifier declaration-specifiersopt
4893                     type-specifier declaration-specifiersopt
4894                     type-qualifier declaration-specifiersopt
4895                     function-specifier declaration-specifiersopt
4896                     alignment-specifier declaration-specifiersopt
4897              init-declarator-list:
4898                      init-declarator
4899                      init-declarator-list , init-declarator
4900              init-declarator:
4901                      declarator
4902                      declarator = initializer
4903     Constraints
4904 2   A declaration other than a static_assert declaration shall declare at least a declarator
4905     (other than the parameters of a function or the members of a structure or union), a tag, or
4906     the members of an enumeration.
4907 3   If an identifier has no linkage, there shall be no more than one declaration of the identifier
4908     (in a declarator or type specifier) with the same scope and in the same name space, except
4909     that a typedef name can be redefined to denote the same type as it currently does and tags
4910     may be redeclared as specified in 6.7.2.3.
4911 4   All declarations in the same scope that refer to the same object or function shall specify
4912     compatible types.
4913     Semantics
4914 5   A declaration specifies the interpretation and attributes of a set of identifiers. A definition
4915     of an identifier is a declaration for that identifier that:
4916     -- for an object, causes storage to be reserved for that object;
4917     -- for a function, includes the function body;118)
4918
4919
4920
4921     118) Function definitions have a different syntax, described in 6.9.1.
4922
4923 [page 107]
4924
4925     -- for an enumeration constant or typedef name, is the (only) declaration of the
4926       identifier.
4927 6   The declaration specifiers consist of a sequence of specifiers that indicate the linkage,
4928     storage duration, and part of the type of the entities that the declarators denote. The init-
4929     declarator-list is a comma-separated sequence of declarators, each of which may have
4930     additional type information, or an initializer, or both. The declarators contain the
4931     identifiers (if any) being declared.
4932 7   If an identifier for an object is declared with no linkage, the type for the object shall be *
4933     complete by the end of its declarator, or by the end of its init-declarator if it has an
4934     initializer; in the case of function parameters (including in prototypes), it is the adjusted
4935     type (see 6.7.6.3) that is required to be complete.
4936     Forward references: declarators (6.7.6), enumeration specifiers (6.7.2.2), initialization
4937     (6.7.9), type names (6.7.7), type qualifiers (6.7.3).
4938     6.7.1 Storage-class specifiers
4939     Syntax
4940 1            storage-class-specifier:
4941                     typedef
4942                     extern
4943                     static
4944                     _Thread_local
4945                     auto
4946                     register
4947     Constraints
4948 2   At most, one storage-class specifier may be given in the declaration specifiers in a
4949     declaration, except that _Thread_local may appear with static or extern.119)
4950 3   In the declaration of an object with block scope, if the declaration specifiers include
4951     _Thread_local, they shall also include either static or extern. If
4952     _Thread_local appears in any declaration of an object, it shall be present in every
4953     declaration of that object.
4954     Semantics
4955 4   The typedef specifier is called a ''storage-class specifier'' for syntactic convenience
4956     only; it is discussed in 6.7.8. The meanings of the various linkages and storage durations
4957     were discussed in 6.2.2 and 6.2.4.
4958
4959
4960
4961     119) See ''future language directions'' (6.11.5).
4962
4963 [page 108]
4964
4965 5   A declaration of an identifier for an object with storage-class specifier register
4966     suggests that access to the object be as fast as possible. The extent to which such
4967     suggestions are effective is implementation-defined.120)
4968 6   The declaration of an identifier for a function that has block scope shall have no explicit
4969     storage-class specifier other than extern.
4970 7   If an aggregate or union object is declared with a storage-class specifier other than
4971     typedef, the properties resulting from the storage-class specifier, except with respect to
4972     linkage, also apply to the members of the object, and so on recursively for any aggregate
4973     or union member objects.
4974     Forward references: type definitions (6.7.8).
4975     6.7.2 Type specifiers
4976     Syntax
4977 1            type-specifier:
4978                     void
4979                     char
4980                     short
4981                     int
4982                     long
4983                     float
4984                     double
4985                     signed
4986                     unsigned
4987                     _Bool
4988                     _Complex
4989                     _Atomic ( type-name )
4990                     struct-or-union-specifier
4991                     enum-specifier
4992                     typedef-name
4993     Constraints
4994 2   At least one type specifier shall be given in the declaration specifiers in each declaration,
4995     and in the specifier-qualifier list in each struct declaration and type name. Each list of
4996
4997
4998     120) The implementation may treat any register declaration simply as an auto declaration. However,
4999          whether or not addressable storage is actually used, the address of any part of an object declared with
5000          storage-class specifier register cannot be computed, either explicitly (by use of the unary &
5001          operator as discussed in 6.5.3.2) or implicitly (by converting an array name to a pointer as discussed in
5002          6.3.2.1). Thus, the only operator that can be applied to an array declared with storage-class specifier
5003          register is sizeof.
5004
5005 [page 109]
5006
5007     type specifiers shall be one of the following multisets (delimited by commas, when there
5008     is more than one multiset per item); the type specifiers may occur in any order, possibly
5009     intermixed with the other declaration specifiers.
5010     -- void
5011     -- char
5012     -- signed char
5013     -- unsigned char
5014     -- short, signed short, short int, or signed short int
5015     -- unsigned short, or unsigned short int
5016     -- int, signed, or signed int
5017     -- unsigned, or unsigned int
5018     -- long, signed long, long int, or signed long int
5019     -- unsigned long, or unsigned long int
5020     -- long long, signed long long, long long int, or
5021       signed long long int
5022     -- unsigned long long, or unsigned long long int
5023     -- float
5024     -- double
5025     -- long double
5026     -- _Bool
5027     -- float _Complex
5028     -- double _Complex
5029     -- long double _Complex
5030     -- _Atomic ( type-name )
5031     -- struct or union specifier
5032     -- enum specifier
5033     -- typedef name
5034 3   The type specifier _Complex shall not be used if the implementation does not support
5035     complex types; likewise, _Atomic shall not be used if the implementation does not
5036     support atomic types (see 6.10.8.3).
5037
5038
5039
5040 [page 110]
5041
5042     Semantics
5043 4   The _Atomic form of type specifier designates the _Atomic-qualified version of the
5044     named type.
5045 5   Specifiers for structures, unions, and enumerations are discussed in 6.7.2.1 through
5046     6.7.2.3. Declarations of typedef names are discussed in 6.7.8. The characteristics of the
5047     other types are discussed in 6.2.5.
5048 6   Each of the comma-separated multisets designates the same type, except that for bit-
5049     fields, it is implementation-defined whether the specifier int designates the same type as
5050     signed int or the same type as unsigned int.
5051     Forward references: enumeration specifiers (6.7.2.2), structure and union specifiers
5052     (6.7.2.1), tags (6.7.2.3), type definitions (6.7.8).
5053     6.7.2.1 Structure and union specifiers
5054     Syntax
5055 1            struct-or-union-specifier:
5056                      struct-or-union identifieropt { struct-declaration-list }
5057                      struct-or-union identifier
5058              struct-or-union:
5059                      struct
5060                      union
5061              struct-declaration-list:
5062                      struct-declaration
5063                      struct-declaration-list struct-declaration
5064              struct-declaration:
5065                      specifier-qualifier-list struct-declarator-listopt ;
5066                      static_assert-declaration
5067              specifier-qualifier-list:
5068                     type-specifier specifier-qualifier-listopt
5069                     type-qualifier specifier-qualifier-listopt
5070              struct-declarator-list:
5071                      struct-declarator
5072                      struct-declarator-list , struct-declarator
5073              struct-declarator:
5074                      declarator
5075                      declaratoropt : constant-expression
5076
5077
5078
5079 [page 111]
5080
5081     Constraints
5082 2   A struct-declaration that does not declare an anonymous structure or anonymous union
5083     shall contain a struct-declarator-list.
5084 3   A structure or union shall not contain a member with incomplete or function type (hence,
5085     a structure shall not contain an instance of itself, but may contain a pointer to an instance
5086     of itself), except that the last member of a structure with more than one named member
5087     may have incomplete array type; such a structure (and any union containing, possibly
5088     recursively, a member that is such a structure) shall not be a member of a structure or an
5089     element of an array.
5090 4   The expression that specifies the width of a bit-field shall be an integer constant
5091     expression with a nonnegative value that does not exceed the width of an object of the
5092     type that would be specified were the colon and expression omitted.121) If the value is
5093     zero, the declaration shall have no declarator.
5094 5   A bit-field shall have a type that is a qualified or unqualified version of _Bool, signed
5095     int, unsigned int, or some other implementation-defined type.
5096     Semantics
5097 6   As discussed in 6.2.5, a structure is a type consisting of a sequence of members, whose
5098     storage is allocated in an ordered sequence, and a union is a type consisting of a sequence
5099     of members whose storage overlap.
5100 7   Structure and union specifiers have the same form. The keywords struct and union
5101     indicate that the type being specified is, respectively, a structure type or a union type.
5102 8   The presence of a struct-declaration-list in a struct-or-union-specifier declares a new type,
5103     within a translation unit. The struct-declaration-list is a sequence of declarations for the
5104     members of the structure or union. If the struct-declaration-list contains no named
5105     members, no anonymous structures, and no anonymous unions, the behavior is undefined.
5106     The type is incomplete until immediately after the } that terminates the list, and complete
5107     thereafter.
5108 9   A member of a structure or union may have any complete object type other than a
5109     variably modified type.122) In addition, a member may be declared to consist of a
5110     specified number of bits (including a sign bit, if any). Such a member is called a
5111     bit-field;123) its width is preceded by a colon.
5112
5113
5114
5115     121) While the number of bits in a _Bool object is at least CHAR_BIT, the width (number of sign and
5116          value bits) of a _Bool may be just 1 bit.
5117     122) A structure or union cannot contain a member with a variably modified type because member names
5118          are not ordinary identifiers as defined in 6.2.3.
5119
5120 [page 112]
5121
5122 10   A bit-field is interpreted as a signed or unsigned integer type consisting of the specified
5123      number of bits.124) If the value 0 or 1 is stored into a nonzero-width bit-field of type
5124      _Bool, the value of the bit-field shall compare equal to the value stored; a _Bool bit-
5125      field has the semantics of a _Bool.
5126 11   An implementation may allocate any addressable storage unit large enough to hold a bit-
5127      field. If enough space remains, a bit-field that immediately follows another bit-field in a
5128      structure shall be packed into adjacent bits of the same unit. If insufficient space remains,
5129      whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is
5130      implementation-defined. The order of allocation of bit-fields within a unit (high-order to
5131      low-order or low-order to high-order) is implementation-defined. The alignment of the
5132      addressable storage unit is unspecified.
5133 12   A bit-field declaration with no declarator, but only a colon and a width, indicates an
5134      unnamed bit-field.125) As a special case, a bit-field structure member with a width of 0
5135      indicates that no further bit-field is to be packed into the unit in which the previous bit-
5136      field, if any, was placed.
5137 13   An unnamed member of structure type with no tag is called an anonymous structure; an
5138      unnamed member of union type with no tag is called an anonymous union. The members
5139      of an anonymous structure or union are considered to be members of the containing
5140      structure or union. This applies recursively if the containing structure or union is also
5141      anonymous.
5142 14   Each non-bit-field member of a structure or union object is aligned in an implementation-
5143      defined manner appropriate to its type.
5144 15   Within a structure object, the non-bit-field members and the units in which bit-fields
5145      reside have addresses that increase in the order in which they are declared. A pointer to a
5146      structure object, suitably converted, points to its initial member (or if that member is a
5147      bit-field, then to the unit in which it resides), and vice versa. There may be unnamed
5148      padding within a structure object, but not at its beginning.
5149 16   The size of a union is sufficient to contain the largest of its members. The value of at
5150      most one of the members can be stored in a union object at any time. A pointer to a
5151      union object, suitably converted, points to each of its members (or if a member is a bit-
5152      field, then to the unit in which it resides), and vice versa.
5153
5154
5155      123) The unary & (address-of) operator cannot be applied to a bit-field object; thus, there are no pointers to
5156           or arrays of bit-field objects.
5157      124) As specified in 6.7.2 above, if the actual type specifier used is int or a typedef-name defined as int,
5158           then it is implementation-defined whether the bit-field is signed or unsigned.
5159      125) An unnamed bit-field structure member is useful for padding to conform to externally imposed
5160           layouts.
5161
5162 [page 113]
5163
5164 17   There may be unnamed padding at the end of a structure or union.
5165 18   As a special case, the last element of a structure with more than one named member may
5166      have an incomplete array type; this is called a flexible array member. In most situations,
5167      the flexible array member is ignored. In particular, the size of the structure is as if the
5168      flexible array member were omitted except that it may have more trailing padding than
5169      the omission would imply. However, when a . (or ->) operator has a left operand that is
5170      (a pointer to) a structure with a flexible array member and the right operand names that
5171      member, it behaves as if that member were replaced with the longest array (with the same
5172      element type) that would not make the structure larger than the object being accessed; the
5173      offset of the array shall remain that of the flexible array member, even if this would differ
5174      from that of the replacement array. If this array would have no elements, it behaves as if
5175      it had one element but the behavior is undefined if any attempt is made to access that
5176      element or to generate a pointer one past it.
5177 19   EXAMPLE 1       The following illustrates anonymous structures and unions:
5178               struct v {
5179                     union {      // anonymous union
5180                            struct { int i, j; };    // anonymous structure
5181                            struct { long k, l; } w;
5182                     };
5183                     int m;
5184               } v1;
5185               v1.i = 2;   // valid
5186               v1.k = 3;   // invalid: inner structure is not anonymous
5187               v1.w.k = 5; // valid
5188
5189 20   EXAMPLE 2       After the declaration:
5190               struct s { int n; double d[]; };
5191      the structure struct s has a flexible array member d. A typical way to use this is:
5192               int m = /* some value */;
5193               struct s *p = malloc(sizeof (struct s) + sizeof (double [m]));
5194      and assuming that the call to malloc succeeds, the object pointed to by p behaves, for most purposes, as if
5195      p had been declared as:
5196               struct { int n; double d[m]; } *p;
5197      (there are circumstances in which this equivalence is broken; in particular, the offsets of member d might
5198      not be the same).
5199 21   Following the above declaration:
5200               struct s t1 = { 0 };                         //   valid
5201               struct s t2 = { 1, { 4.2 }};                 //   invalid
5202               t1.n = 4;                                    //   valid
5203               t1.d[0] = 4.2;                               //   might be undefined behavior
5204      The initialization of t2 is invalid (and violates a constraint) because struct s is treated as if it did not
5205      contain member d. The assignment to t1.d[0] is probably undefined behavior, but it is possible that
5206
5207 [page 114]
5208
5209               sizeof (struct s) >= offsetof(struct s, d) + sizeof (double)
5210      in which case the assignment would be legitimate. Nevertheless, it cannot appear in strictly conforming
5211      code.
5212 22   After the further declaration:
5213               struct ss { int n; };
5214      the expressions:
5215               sizeof (struct s) >= sizeof (struct ss)
5216               sizeof (struct s) >= offsetof(struct s, d)
5217      are always equal to 1.
5218 23   If sizeof (double) is 8, then after the following code is executed:
5219               struct s *s1;
5220               struct s *s2;
5221               s1 = malloc(sizeof (struct s) + 64);
5222               s2 = malloc(sizeof (struct s) + 46);
5223      and assuming that the calls to malloc succeed, the objects pointed to by s1 and s2 behave, for most
5224      purposes, as if the identifiers had been declared as:
5225               struct { int n; double d[8]; } *s1;
5226               struct { int n; double d[5]; } *s2;
5227 24   Following the further successful assignments:
5228               s1 = malloc(sizeof (struct s) + 10);
5229               s2 = malloc(sizeof (struct s) + 6);
5230      they then behave as if the declarations were:
5231               struct { int n; double d[1]; } *s1, *s2;
5232      and:
5233               double *dp;
5234               dp = &(s1->d[0]);          //   valid
5235               *dp = 42;                  //   valid
5236               dp = &(s2->d[0]);          //   valid
5237               *dp = 42;                  //   undefined behavior
5238 25   The assignment:
5239               *s1 = *s2;
5240      only copies the member n; if any of the array elements are within the first sizeof (struct s) bytes
5241      of the structure, they might be copied or simply overwritten with indeterminate values.
5242
5243      Forward references: declarators (6.7.6), tags (6.7.2.3).
5244
5245
5246
5247
5248 [page 115]
5249
5250     6.7.2.2 Enumeration specifiers
5251     Syntax
5252 1            enum-specifier:
5253                    enum identifieropt { enumerator-list }
5254                    enum identifieropt { enumerator-list , }
5255                    enum identifier
5256              enumerator-list:
5257                    enumerator
5258                    enumerator-list , enumerator
5259              enumerator:
5260                    enumeration-constant
5261                    enumeration-constant = constant-expression
5262     Constraints
5263 2   The expression that defines the value of an enumeration constant shall be an integer
5264     constant expression that has a value representable as an int.
5265     Semantics
5266 3   The identifiers in an enumerator list are declared as constants that have type int and
5267     may appear wherever such are permitted.126) An enumerator with = defines its
5268     enumeration constant as the value of the constant expression. If the first enumerator has
5269     no =, the value of its enumeration constant is 0. Each subsequent enumerator with no =
5270     defines its enumeration constant as the value of the constant expression obtained by
5271     adding 1 to the value of the previous enumeration constant. (The use of enumerators with
5272     = may produce enumeration constants with values that duplicate other values in the same
5273     enumeration.) The enumerators of an enumeration are also known as its members.
5274 4   Each enumerated type shall be compatible with char, a signed integer type, or an
5275     unsigned integer type. The choice of type is implementation-defined,127) but shall be
5276     capable of representing the values of all the members of the enumeration. The
5277     enumerated type is incomplete until immediately after the } that terminates the list of
5278     enumerator declarations, and complete thereafter.
5279
5280
5281
5282
5283     126) Thus, the identifiers of enumeration constants declared in the same scope shall all be distinct from
5284          each other and from other identifiers declared in ordinary declarators.
5285     127) An implementation may delay the choice of which integer type until all enumeration constants have
5286          been seen.
5287
5288 [page 116]
5289
5290 5   EXAMPLE       The following fragment:
5291              enum hue { chartreuse, burgundy, claret=20, winedark };
5292              enum hue col, *cp;
5293              col = claret;
5294              cp = &col;
5295              if (*cp != burgundy)
5296                    /* ... */
5297     makes hue the tag of an enumeration, and then declares col as an object that has that type and cp as a
5298     pointer to an object that has that type. The enumerated values are in the set { 0, 1, 20, 21 }.
5299
5300     Forward references: tags (6.7.2.3).
5301     6.7.2.3 Tags
5302     Constraints
5303 1   A specific type shall have its content defined at most once.
5304 2   Where two declarations that use the same tag declare the same type, they shall both use
5305     the same choice of struct, union, or enum.
5306 3   A type specifier of the form
5307             enum identifier
5308     without an enumerator list shall only appear after the type it specifies is complete.
5309     Semantics
5310 4   All declarations of structure, union, or enumerated types that have the same scope and
5311     use the same tag declare the same type. Irrespective of whether there is a tag or what
5312     other declarations of the type are in the same translation unit, the type is incomplete128)
5313     until immediately after the closing brace of the list defining the content, and complete
5314     thereafter.
5315 5   Two declarations of structure, union, or enumerated types which are in different scopes or
5316     use different tags declare distinct types. Each declaration of a structure, union, or
5317     enumerated type which does not include a tag declares a distinct type.
5318 6   A type specifier of the form
5319
5320
5321
5322
5323     128) An incomplete type may only by used when the size of an object of that type is not needed. It is not
5324          needed, for example, when a typedef name is declared to be a specifier for a structure or union, or
5325          when a pointer to or a function returning a structure or union is being declared. (See incomplete types
5326          in 6.2.5.) The specification has to be complete before such a function is called or defined.
5327
5328 [page 117]
5329
5330               struct-or-union identifieropt { struct-declaration-list }
5331      or
5332               enum identifieropt { enumerator-list }
5333      or
5334               enum identifieropt { enumerator-list , }
5335      declares a structure, union, or enumerated type. The list defines the structure content,
5336      union content, or enumeration content. If an identifier is provided,129) the type specifier
5337      also declares the identifier to be the tag of that type.
5338 7    A declaration of the form
5339               struct-or-union identifier ;
5340      specifies a structure or union type and declares the identifier as a tag of that type.130)
5341 8    If a type specifier of the form
5342               struct-or-union identifier
5343      occurs other than as part of one of the above forms, and no other declaration of the
5344      identifier as a tag is visible, then it declares an incomplete structure or union type, and
5345      declares the identifier as the tag of that type.130)
5346 9    If a type specifier of the form
5347               struct-or-union identifier
5348      or
5349               enum identifier
5350      occurs other than as part of one of the above forms, and a declaration of the identifier as a
5351      tag is visible, then it specifies the same type as that other declaration, and does not
5352      redeclare the tag.
5353 10   EXAMPLE 1       This mechanism allows declaration of a self-referential structure.
5354               struct tnode {
5355                     int count;
5356                     struct tnode *left, *right;
5357               };
5358      specifies a structure that contains an integer and two pointers to objects of the same type. Once this
5359      declaration has been given, the declaration
5360
5361
5362
5363
5364      129) If there is no identifier, the type can, within the translation unit, only be referred to by the declaration
5365           of which it is a part. Of course, when the declaration is of a typedef name, subsequent declarations
5366           can make use of that typedef name to declare objects having the specified structure, union, or
5367           enumerated type.
5368      130) A similar construction with enum does not exist.
5369
5370 [page 118]
5371
5372               struct tnode s, *sp;
5373      declares s to be an object of the given type and sp to be a pointer to an object of the given type. With
5374      these declarations, the expression sp->left refers to the left struct tnode pointer of the object to
5375      which sp points; the expression s.right->count designates the count member of the right struct
5376      tnode pointed to from s.
5377 11   The following alternative formulation uses the typedef mechanism:
5378               typedef struct tnode TNODE;
5379               struct tnode {
5380                     int count;
5381                     TNODE *left, *right;
5382               };
5383               TNODE s, *sp;
5384
5385 12   EXAMPLE 2 To illustrate the use of prior declaration of a tag to specify a pair of mutually referential
5386      structures, the declarations
5387               struct s1 { struct s2 *s2p; /* ... */ }; // D1
5388               struct s2 { struct s1 *s1p; /* ... */ }; // D2
5389      specify a pair of structures that contain pointers to each other. Note, however, that if s2 were already
5390      declared as a tag in an enclosing scope, the declaration D1 would refer to it, not to the tag s2 declared in
5391      D2. To eliminate this context sensitivity, the declaration
5392               struct s2;
5393      may be inserted ahead of D1. This declares a new tag s2 in the inner scope; the declaration D2 then
5394      completes the specification of the new type.
5395
5396      Forward references: declarators (6.7.6), type definitions (6.7.8).
5397      6.7.3 Type qualifiers
5398      Syntax
5399 1             type-qualifier:
5400                      const
5401                      restrict
5402                      volatile
5403                      _Atomic
5404      Constraints
5405 2    Types other than pointer types whose referenced type is an object type shall not be
5406      restrict-qualified.
5407      Semantics
5408 3    The properties associated with qualified types are meaningful only for expressions that
5409      are lvalues.131)
5410 4    If the same qualifier appears more than once in the same specifier-qualifier-list, either
5411      directly or via one or more typedefs, the behavior is the same as if it appeared only
5412      once.
5413 [page 119]
5414
5415 5   If an attempt is made to modify an object defined with a const-qualified type through use
5416     of an lvalue with non-const-qualified type, the behavior is undefined. If an attempt is
5417     made to refer to an object defined with a volatile-qualified type through use of an lvalue
5418     with non-volatile-qualified type, the behavior is undefined.132) If an attempt is made to
5419     refer to an object defined with an _Atomic-qualified type through use of an lvalue with
5420     non-_Atomic-qualified type, the behavior is undefined.
5421 6   An object that has volatile-qualified type may be modified in ways unknown to the
5422     implementation or have other unknown side effects. Therefore any expression referring
5423     to such an object shall be evaluated strictly according to the rules of the abstract machine,
5424     as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the
5425     object shall agree with that prescribed by the abstract machine, except as modified by the
5426     unknown factors mentioned previously.133) What constitutes an access to an object that
5427     has volatile-qualified type is implementation-defined.
5428 7   An object that is accessed through a restrict-qualified pointer has a special association
5429     with that pointer. This association, defined in 6.7.3.1 below, requires that all accesses to
5430     that object use, directly or indirectly, the value of that particular pointer.134) The intended
5431     use of the restrict qualifier (like the register storage class) is to promote
5432     optimization, and deleting all instances of the qualifier from all preprocessing translation
5433     units composing a conforming program does not change its meaning (i.e., observable
5434     behavior).
5435 8   If the specification of an array type includes any type qualifiers, the element type is so-
5436     qualified, not the array type. If the specification of a function type includes any type
5437     qualifiers, the behavior is undefined.135)
5438 9   For two qualified types to be compatible, both shall have the identically qualified version
5439     of a compatible type; the order of type qualifiers within a list of specifiers or qualifiers
5440     does not affect the specified type.
5441
5442     131) The implementation may place a const object that is not volatile in a read-only region of
5443          storage. Moreover, the implementation need not allocate storage for such an object if its address is
5444          never used.
5445     132) This applies to those objects that behave as if they were defined with qualified types, even if they are
5446          never actually defined as objects in the program (such as an object at a memory-mapped input/output
5447          address).
5448     133) A volatile declaration may be used to describe an object corresponding to a memory-mapped
5449          input/output port or an object accessed by an asynchronously interrupting function. Actions on
5450          objects so declared shall not be ''optimized out'' by an implementation or reordered except as
5451          permitted by the rules for evaluating expressions.
5452     134) For example, a statement that assigns a value returned by malloc to a single pointer establishes this
5453          association between the allocated object and the pointer.
5454     135) Both of these can occur through the use of typedefs.
5455
5456 [page 120]
5457
5458 10   EXAMPLE 1      An object declared
5459              extern const volatile int real_time_clock;
5460      may be modifiable by hardware, but cannot be assigned to, incremented, or decremented.
5461
5462 11   EXAMPLE 2 The following declarations and expressions illustrate the behavior when type qualifiers
5463      modify an aggregate type:
5464              const struct s { int mem; } cs = { 1 };
5465              struct s ncs; // the object ncs is modifiable
5466              typedef int A[2][3];
5467              const A a = {{4, 5, 6}, {7, 8, 9}}; // array of array of const int
5468              int *pi;
5469              const int *pci;
5470              ncs = cs;             //    valid
5471              cs = ncs;             //    violates modifiable lvalue constraint for =
5472              pi = &ncs.mem;        //    valid
5473              pi = &cs.mem;         //    violates type constraints for =
5474              pci = &cs.mem;        //    valid
5475              pi = a[0];            //    invalid: a[0] has type ''const int *''
5476
5477      6.7.3.1 Formal definition of restrict
5478 1    Let D be a declaration of an ordinary identifier that provides a means of designating an
5479      object P as a restrict-qualified pointer to type T.
5480 2    If D appears inside a block and does not have storage class extern, let B denote the
5481      block. If D appears in the list of parameter declarations of a function definition, let B
5482      denote the associated block. Otherwise, let B denote the block of main (or the block of
5483      whatever function is called at program startup in a freestanding environment).
5484 3    In what follows, a pointer expression E is said to be based on object P if (at some
5485      sequence point in the execution of B prior to the evaluation of E) modifying P to point to
5486      a copy of the array object into which it formerly pointed would change the value of E.136)
5487      Note that ''based'' is defined only for expressions with pointer types.
5488 4    During each execution of B, let L be any lvalue that has &L based on P. If L is used to
5489      access the value of the object X that it designates, and X is also modified (by any means),
5490      then the following requirements apply: T shall not be const-qualified. Every other lvalue
5491      used to access the value of X shall also have its address based on P. Every access that
5492      modifies X shall be considered also to modify P, for the purposes of this subclause. If P
5493      is assigned the value of a pointer expression E that is based on another restricted pointer
5494      object P2, associated with block B2, then either the execution of B2 shall begin before
5495
5496
5497      136) In other words, E depends on the value of P itself rather than on the value of an object referenced
5498           indirectly through P. For example, if identifier p has type (int **restrict), then the pointer
5499           expressions p and p+1 are based on the restricted pointer object designated by p, but the pointer
5500           expressions *p and p[1] are not.
5501
5502 [page 121]
5503
5504      the execution of B, or the execution of B2 shall end prior to the assignment. If these
5505      requirements are not met, then the behavior is undefined.
5506 5    Here an execution of B means that portion of the execution of the program that would
5507      correspond to the lifetime of an object with scalar type and automatic storage duration
5508      associated with B.
5509 6    A translator is free to ignore any or all aliasing implications of uses of restrict.
5510 7    EXAMPLE 1       The file scope declarations
5511              int * restrict a;
5512              int * restrict b;
5513              extern int c[];
5514      assert that if an object is accessed using one of a, b, or c, and that object is modified anywhere in the
5515      program, then it is never accessed using either of the other two.
5516
5517 8    EXAMPLE 2       The function parameter declarations in the following example
5518              void f(int n, int * restrict p, int * restrict q)
5519              {
5520                    while (n-- > 0)
5521                          *p++ = *q++;
5522              }
5523      assert that, during each execution of the function, if an object is accessed through one of the pointer
5524      parameters, then it is not also accessed through the other.
5525 9    The benefit of the restrict qualifiers is that they enable a translator to make an effective dependence
5526      analysis of function f without examining any of the calls of f in the program. The cost is that the
5527      programmer has to examine all of those calls to ensure that none give undefined behavior. For example, the
5528      second call of f in g has undefined behavior because each of d[1] through d[49] is accessed through
5529      both p and q.
5530               void g(void)
5531               {
5532                     extern int d[100];
5533                     f(50, d + 50, d); // valid
5534                     f(50, d + 1, d); // undefined behavior
5535               }
5536
5537 10   EXAMPLE 3       The function parameter declarations
5538              void h(int n, int * restrict p, int * restrict q, int * restrict r)
5539              {
5540                    int i;
5541                    for (i = 0; i < n; i++)
5542                           p[i] = q[i] + r[i];
5543              }
5544      illustrate how an unmodified object can be aliased through two restricted pointers. In particular, if a and b
5545      are disjoint arrays, a call of the form h(100, a, b, b) has defined behavior, because array b is not
5546      modified within function h.
5547
5548 11   EXAMPLE 4 The rule limiting assignments between restricted pointers does not distinguish between a
5549      function call and an equivalent nested block. With one exception, only ''outer-to-inner'' assignments
5550
5551 [page 122]
5552
5553      between restricted pointers declared in nested blocks have defined behavior.
5554               {
5555                        int * restrict p1;
5556                        int * restrict q1;
5557                        p1 = q1; // undefined behavior
5558                        {
5559                              int * restrict p2 = p1; // valid
5560                              int * restrict q2 = q1; // valid
5561                              p1 = q2;                // undefined behavior
5562                              p2 = q2;                // undefined behavior
5563                        }
5564               }
5565 12   The one exception allows the value of a restricted pointer to be carried out of the block in which it (or, more
5566      precisely, the ordinary identifier used to designate it) is declared when that block finishes execution. For
5567      example, this permits new_vector to return a vector.
5568               typedef struct { int n; float * restrict v; } vector;
5569               vector new_vector(int n)
5570               {
5571                     vector t;
5572                     t.n = n;
5573                     t.v = malloc(n * sizeof (float));
5574                     return t;
5575               }
5576
5577      6.7.4 Function specifiers
5578      Syntax
5579 1             function-specifier:
5580                      inline
5581                      _Noreturn
5582      Constraints
5583 2    Function specifiers shall be used only in the declaration of an identifier for a function.
5584 3    An inline definition of a function with external linkage shall not contain a definition of a
5585      modifiable object with static or thread storage duration, and shall not contain a reference
5586      to an identifier with internal linkage.
5587 4    In a hosted environment, no function specifier(s) shall appear in a declaration of main.
5588      Semantics
5589 5    A function specifier may appear more than once; the behavior is the same as if it
5590      appeared only once.
5591 6    A function declared with an inline function specifier is an inline function. Making a
5592      function an inline function suggests that calls to the function be as fast as possible.137)
5593      The extent to which such suggestions are effective is implementation-defined.138)
5594
5595 [page 123]
5596
5597 7    Any function with internal linkage can be an inline function. For a function with external
5598      linkage, the following restrictions apply: If a function is declared with an inline
5599      function specifier, then it shall also be defined in the same translation unit. If all of the
5600      file scope declarations for a function in a translation unit include the inline function
5601      specifier without extern, then the definition in that translation unit is an inline
5602      definition. An inline definition does not provide an external definition for the function,
5603      and does not forbid an external definition in another translation unit. An inline definition
5604      provides an alternative to an external definition, which a translator may use to implement
5605      any call to the function in the same translation unit. It is unspecified whether a call to the
5606      function uses the inline definition or the external definition.139)
5607 8    A function declared with a _Noreturn function specifier shall not return to its caller.
5608      Recommended practice
5609 9    The implementation should produce a diagnostic message for a function declared with a
5610      _Noreturn function specifier that appears to be capable of returning to its caller.
5611 10   EXAMPLE 1 The declaration of an inline function with external linkage can result in either an external
5612      definition, or a definition available for use only within the translation unit. A file scope declaration with
5613      extern creates an external definition. The following example shows an entire translation unit.
5614               inline double fahr(double t)
5615               {
5616                     return (9.0 * t) / 5.0 + 32.0;
5617               }
5618               inline double cels(double t)
5619               {
5620                     return (5.0 * (t - 32.0)) / 9.0;
5621               }
5622               extern double fahr(double);                  // creates an external definition
5623
5624
5625
5626
5627      137) By using, for example, an alternative to the usual function call mechanism, such as ''inline
5628           substitution''. Inline substitution is not textual substitution, nor does it create a new function.
5629           Therefore, for example, the expansion of a macro used within the body of the function uses the
5630           definition it had at the point the function body appears, and not where the function is called; and
5631           identifiers refer to the declarations in scope where the body occurs. Likewise, the function has a
5632           single address, regardless of the number of inline definitions that occur in addition to the external
5633           definition.
5634      138) For example, an implementation might never perform inline substitution, or might only perform inline
5635           substitutions to calls in the scope of an inline declaration.
5636      139) Since an inline definition is distinct from the corresponding external definition and from any other
5637           corresponding inline definitions in other translation units, all corresponding objects with static storage
5638           duration are also distinct in each of the definitions.
5639
5640 [page 124]
5641
5642               double convert(int is_fahr, double temp)
5643               {
5644                     /* A translator may perform inline substitutions */
5645                     return is_fahr ? cels(temp) : fahr(temp);
5646               }
5647 11   Note that the definition of fahr is an external definition because fahr is also declared with extern, but
5648      the definition of cels is an inline definition. Because cels has external linkage and is referenced, an
5649      external definition has to appear in another translation unit (see 6.9); the inline definition and the external
5650      definition are distinct and either may be used for the call.
5651
5652 12   EXAMPLE 2
5653               _Noreturn void f () {
5654                     abort(); // ok
5655               }
5656               _Noreturn void g (int i) { // causes undefined behavior if i <= 0
5657                     if (i > 0) abort();
5658               }
5659
5660      Forward references: function definitions (6.9.1).
5661      6.7.5 Alignment specifier
5662      Syntax
5663 1             alignment-specifier:
5664                     _Alignas ( type-name )
5665                     _Alignas ( constant-expression )
5666      Constraints
5667 2    An alignment attribute shall not be specified in a declaration of a typedef, or a bit-field, or
5668      a function, or a parameter, or an object declared with the register storage-class
5669      specifier.
5670 3    The constant expression shall be an integer constant expression. It shall evaluate to a
5671      valid fundamental alignment, or to a valid extended alignment supported by the
5672      implementation in the context in which it appears, or to zero.
5673 4    The combined effect of all alignment attributes in a declaration shall not specify an
5674      alignment that is less strict than the alignment that would otherwise be required for the
5675      type of the object or field being declared.
5676      Semantics
5677 5    The first form is equivalent to _Alignas(alignof(type-name)).
5678 6    The alignment requirement of the declared object or field is taken to be the specified
5679      alignment. An alignment specification of zero has no effect.140) When multiple
5680      alignment specifiers occur in a declaration, the effective alignment requirement is the
5681      strictest specified alignment.
5682
5683 [page 125]
5684
5685 7   If the definition of an object has an alignment specifier, any other declaration of that
5686     object shall either specify equivalent alignment or have no alignment specifier. If the
5687     definition of an object does not have an alignment specifier, any other declaration of that
5688     object shall also have no alignment specifier. If declarations of an object in different
5689     translation units have different alignment specifiers, the behavior is undefined.
5690     6.7.6 Declarators
5691     Syntax
5692 1            declarator:
5693                     pointeropt direct-declarator
5694              direct-declarator:
5695                      identifier
5696                      ( declarator )
5697                      direct-declarator [ type-qualifier-listopt assignment-expressionopt ]
5698                      direct-declarator [ static type-qualifier-listopt assignment-expression ]
5699                      direct-declarator [ type-qualifier-list static assignment-expression ]
5700                      direct-declarator [ type-qualifier-listopt * ]
5701                      direct-declarator ( parameter-type-list )
5702                      direct-declarator ( identifier-listopt )
5703              pointer:
5704                     * type-qualifier-listopt
5705                     * type-qualifier-listopt pointer
5706              type-qualifier-list:
5707                     type-qualifier
5708                     type-qualifier-list type-qualifier
5709              parameter-type-list:
5710                    parameter-list
5711                    parameter-list , ...
5712              parameter-list:
5713                    parameter-declaration
5714                    parameter-list , parameter-declaration
5715              parameter-declaration:
5716                    declaration-specifiers declarator
5717                    declaration-specifiers abstract-declaratoropt
5718
5719
5720
5721     140) An alignment specification of zero also does not affect other alignment specifications in the same
5722          declaration.
5723
5724 [page 126]
5725
5726              identifier-list:
5727                     identifier
5728                     identifier-list , identifier
5729     Semantics
5730 2   Each declarator declares one identifier, and asserts that when an operand of the same
5731     form as the declarator appears in an expression, it designates a function or object with the
5732     scope, storage duration, and type indicated by the declaration specifiers.
5733 3   A full declarator is a declarator that is not part of another declarator. The end of a full
5734     declarator is a sequence point. If, in the nested sequence of declarators in a full
5735     declarator, there is a declarator specifying a variable length array type, the type specified
5736     by the full declarator is said to be variably modified. Furthermore, any type derived by
5737     declarator type derivation from a variably modified type is itself variably modified.
5738 4   In the following subclauses, consider a declaration
5739              T D1
5740     where T contains the declaration specifiers that specify a type T (such as int) and D1 is
5741     a declarator that contains an identifier ident. The type specified for the identifier ident in
5742     the various forms of declarator is described inductively using this notation.
5743 5   If, in the declaration ''T D1'', D1 has the form
5744              identifier
5745     then the type specified for ident is T .
5746 6   If, in the declaration ''T D1'', D1 has the form
5747              ( D )
5748     then ident has the type specified by the declaration ''T D''. Thus, a declarator in
5749     parentheses is identical to the unparenthesized declarator, but the binding of complicated
5750     declarators may be altered by parentheses.
5751     Implementation limits
5752 7   As discussed in 5.2.4.1, an implementation may limit the number of pointer, array, and
5753     function declarators that modify an arithmetic, structure, union, or void type, either
5754     directly or via one or more typedefs.
5755     Forward references: array declarators (6.7.6.2), type definitions (6.7.8).
5756
5757
5758
5759
5760 [page 127]
5761
5762     6.7.6.1 Pointer declarators
5763     Semantics
5764 1   If, in the declaration ''T D1'', D1 has the form
5765             * type-qualifier-listopt D
5766     and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
5767     T '', then the type specified for ident is ''derived-declarator-type-list type-qualifier-list
5768     pointer to T ''. For each type qualifier in the list, ident is a so-qualified pointer.
5769 2   For two pointer types to be compatible, both shall be identically qualified and both shall
5770     be pointers to compatible types.
5771 3   EXAMPLE The following pair of declarations demonstrates the difference between a ''variable pointer
5772     to a constant value'' and a ''constant pointer to a variable value''.
5773             const int *ptr_to_constant;
5774             int *const constant_ptr;
5775     The contents of any object pointed to by ptr_to_constant shall not be modified through that pointer,
5776     but ptr_to_constant itself may be changed to point to another object. Similarly, the contents of the
5777     int pointed to by constant_ptr may be modified, but constant_ptr itself shall always point to the
5778     same location.
5779 4   The declaration of the constant pointer constant_ptr may be clarified by including a definition for the
5780     type ''pointer to int''.
5781             typedef int *int_ptr;
5782             const int_ptr constant_ptr;
5783     declares constant_ptr as an object that has type ''const-qualified pointer to int''.
5784
5785     6.7.6.2 Array declarators
5786     Constraints
5787 1   In addition to optional type qualifiers and the keyword static, the [ and ] may delimit
5788     an expression or *. If they delimit an expression (which specifies the size of an array), the
5789     expression shall have an integer type. If the expression is a constant expression, it shall
5790     have a value greater than zero. The element type shall not be an incomplete or function
5791     type. The optional type qualifiers and the keyword static shall appear only in a
5792     declaration of a function parameter with an array type, and then only in the outermost
5793     array type derivation.
5794 2   An ordinary identifier (as defined in 6.2.3) that has a variably modified type shall have
5795     either block scope and no linkage or function prototype scope. If an identifier is declared
5796     to be an object with static or thread storage duration, it shall not have a variable length
5797     array type.
5798
5799
5800
5801
5802 [page 128]
5803
5804     Semantics
5805 3   If, in the declaration ''T D1'', D1 has one of the forms:
5806              D[ type-qualifier-listopt assignment-expressionopt ]
5807              D[ static type-qualifier-listopt assignment-expression ]
5808              D[ type-qualifier-list static assignment-expression ]
5809              D[ type-qualifier-listopt * ]
5810     and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
5811     T '', then the type specified for ident is ''derived-declarator-type-list array of T ''.141)
5812     (See 6.7.6.3 for the meaning of the optional type qualifiers and the keyword static.)
5813 4   If the size is not present, the array type is an incomplete type. If the size is * instead of
5814     being an expression, the array type is a variable length array type of unspecified size,
5815     which can only be used in declarations or type names with function prototype scope;142)
5816     such arrays are nonetheless complete types. If the size is an integer constant expression
5817     and the element type has a known constant size, the array type is not a variable length
5818     array type; otherwise, the array type is a variable length array type. (Variable length
5819     arrays are a conditional feature that implementations need not support; see 6.10.8.3.)
5820 5   If the size is an expression that is not an integer constant expression: if it occurs in a
5821     declaration at function prototype scope, it is treated as if it were replaced by *; otherwise,
5822     each time it is evaluated it shall have a value greater than zero. The size of each instance
5823     of a variable length array type does not change during its lifetime. Where a size
5824     expression is part of the operand of a sizeof operator and changing the value of the
5825     size expression would not affect the result of the operator, it is unspecified whether or not
5826     the size expression is evaluated.
5827 6   For two array types to be compatible, both shall have compatible element types, and if
5828     both size specifiers are present, and are integer constant expressions, then both size
5829     specifiers shall have the same constant value. If the two array types are used in a context
5830     which requires them to be compatible, it is undefined behavior if the two size specifiers
5831     evaluate to unequal values.
5832 7   EXAMPLE 1
5833              float fa[11], *afp[17];
5834     declares an array of float numbers and an array of pointers to float numbers.
5835
5836 8   EXAMPLE 2       Note the distinction between the declarations
5837
5838
5839
5840
5841     141) When several ''array of'' specifications are adjacent, a multidimensional array is declared.
5842     142) Thus, * can be used only in function declarations that are not definitions (see 6.7.6.3).
5843
5844 [page 129]
5845
5846              extern int *x;
5847              extern int y[];
5848      The first declares x to be a pointer to int; the second declares y to be an array of int of unspecified size
5849      (an incomplete type), the storage for which is defined elsewhere.
5850
5851 9    EXAMPLE 3      The following declarations demonstrate the compatibility rules for variably modified types.
5852              extern int n;
5853              extern int m;
5854              void fcompat(void)
5855              {
5856                    int a[n][6][m];
5857                    int (*p)[4][n+1];
5858                    int c[n][n][6][m];
5859                    int (*r)[n][n][n+1];
5860                    p = a;       // invalid: not compatible because 4 != 6
5861                    r = c;       // compatible, but defined behavior only if
5862                                 // n == 6 and m == n+1
5863              }
5864
5865 10   EXAMPLE 4 All declarations of variably modified (VM) types have to be at either block scope or
5866      function prototype scope. Array objects declared with the _Thread_local, static, or extern
5867      storage-class specifier cannot have a variable length array (VLA) type. However, an object declared with
5868      the static storage-class specifier can have a VM type (that is, a pointer to a VLA type). Finally, all
5869      identifiers declared with a VM type have to be ordinary identifiers and cannot, therefore, be members of
5870      structures or unions.
5871              extern int n;
5872              int A[n];                                            // invalid: file scope VLA
5873              extern int (*p2)[n];                                 // invalid: file scope VM
5874              int B[100];                                          // valid: file scope but not VM
5875              void fvla(int m, int C[m][m]);                       // valid: VLA with prototype scope
5876              void fvla(int m, int C[m][m])                        // valid: adjusted to auto pointer to VLA
5877              {
5878                    typedef int VLA[m][m];                         // valid: block scope typedef VLA
5879                       struct tag {
5880                             int (*y)[n];                          // invalid: y not ordinary identifier
5881                             int z[n];                             // invalid: z not ordinary identifier
5882                       };
5883                       int D[m];                                   //   valid: auto VLA
5884                       static int E[m];                            //   invalid: static block scope VLA
5885                       extern int F[m];                            //   invalid: F has linkage and is VLA
5886                       int (*s)[m];                                //   valid: auto pointer to VLA
5887                       extern int (*r)[m];                         //   invalid: r has linkage and points to VLA
5888                       static int (*q)[m] = &B;                    //   valid: q is a static block pointer to VLA
5889              }
5890
5891      Forward references:           function declarators (6.7.6.3), function definitions (6.9.1),
5892      initialization (6.7.9).
5893
5894
5895
5896 [page 130]
5897
5898      6.7.6.3 Function declarators (including prototypes)
5899      Constraints
5900 1    A function declarator shall not specify a return type that is a function type or an array
5901      type.
5902 2    The only storage-class specifier that shall occur in a parameter declaration is register.
5903 3    An identifier list in a function declarator that is not part of a definition of that function
5904      shall be empty.
5905 4    After adjustment, the parameters in a parameter type list in a function declarator that is
5906      part of a definition of that function shall not have incomplete type.
5907      Semantics
5908 5    If, in the declaration ''T D1'', D1 has the form
5909              D( parameter-type-list )
5910      or
5911              D( identifier-listopt )
5912      and the type specified for ident in the declaration ''T D'' is ''derived-declarator-type-list
5913      T '', then the type specified for ident is ''derived-declarator-type-list function returning
5914      T ''.
5915 6    A parameter type list specifies the types of, and may declare identifiers for, the
5916      parameters of the function.
5917 7    A declaration of a parameter as ''array of type'' shall be adjusted to ''qualified pointer to
5918      type'', where the type qualifiers (if any) are those specified within the [ and ] of the
5919      array type derivation. If the keyword static also appears within the [ and ] of the
5920      array type derivation, then for each call to the function, the value of the corresponding
5921      actual argument shall provide access to the first element of an array with at least as many
5922      elements as specified by the size expression.
5923 8    A declaration of a parameter as ''function returning type'' shall be adjusted to ''pointer to
5924      function returning type'', as in 6.3.2.1.
5925 9    If the list terminates with an ellipsis (, ...), no information about the number or types
5926      of the parameters after the comma is supplied.143)
5927 10   The special case of an unnamed parameter of type void as the only item in the list
5928      specifies that the function has no parameters.
5929
5930
5931
5932      143) The macros defined in the <stdarg.h> header (7.16) may be used to access arguments that
5933           correspond to the ellipsis.
5934
5935 [page 131]
5936
5937 11   If, in a parameter declaration, an identifier can be treated either as a typedef name or as a
5938      parameter name, it shall be taken as a typedef name.
5939 12   If the function declarator is not part of a definition of that function, parameters may have
5940      incomplete type and may use the [*] notation in their sequences of declarator specifiers
5941      to specify variable length array types.
5942 13   The storage-class specifier in the declaration specifiers for a parameter declaration, if
5943      present, is ignored unless the declared parameter is one of the members of the parameter
5944      type list for a function definition.
5945 14   An identifier list declares only the identifiers of the parameters of the function. An empty
5946      list in a function declarator that is part of a definition of that function specifies that the
5947      function has no parameters. The empty list in a function declarator that is not part of a
5948      definition of that function specifies that no information about the number or types of the
5949      parameters is supplied.144)
5950 15   For two function types to be compatible, both shall specify compatible return types.145)
5951      Moreover, the parameter type lists, if both are present, shall agree in the number of
5952      parameters and in use of the ellipsis terminator; corresponding parameters shall have
5953      compatible types. If one type has a parameter type list and the other type is specified by a
5954      function declarator that is not part of a function definition and that contains an empty
5955      identifier list, the parameter list shall not have an ellipsis terminator and the type of each
5956      parameter shall be compatible with the type that results from the application of the
5957      default argument promotions. If one type has a parameter type list and the other type is
5958      specified by a function definition that contains a (possibly empty) identifier list, both shall
5959      agree in the number of parameters, and the type of each prototype parameter shall be
5960      compatible with the type that results from the application of the default argument
5961      promotions to the type of the corresponding identifier. (In the determination of type
5962      compatibility and of a composite type, each parameter declared with function or array
5963      type is taken as having the adjusted type and each parameter declared with qualified type
5964      is taken as having the unqualified version of its declared type.)
5965 16   EXAMPLE 1       The declaration
5966               int f(void), *fip(), (*pfi)();
5967      declares a function f with no parameters returning an int, a function fip with no parameter specification
5968      returning a pointer to an int, and a pointer pfi to a function with no parameter specification returning an
5969      int. It is especially useful to compare the last two. The binding of *fip() is *(fip()), so that the
5970      declaration suggests, and the same construction in an expression requires, the calling of a function fip,
5971      and then using indirection through the pointer result to yield an int. In the declarator (*pfi)(), the
5972      extra parentheses are necessary to indicate that indirection through a pointer to a function yields a function
5973
5974
5975      144) See ''future language directions'' (6.11.6).
5976      145) If both function types are ''old style'', parameter types are not compared.
5977
5978 [page 132]
5979
5980      designator, which is then used to call the function; it returns an int.
5981 17   If the declaration occurs outside of any function, the identifiers have file scope and external linkage. If the
5982      declaration occurs inside a function, the identifiers of the functions f and fip have block scope and either
5983      internal or external linkage (depending on what file scope declarations for these identifiers are visible), and
5984      the identifier of the pointer pfi has block scope and no linkage.
5985
5986 18   EXAMPLE 2        The declaration
5987                int (*apfi[3])(int *x, int *y);
5988      declares an array apfi of three pointers to functions returning int. Each of these functions has two
5989      parameters that are pointers to int. The identifiers x and y are declared for descriptive purposes only and
5990      go out of scope at the end of the declaration of apfi.
5991
5992 19   EXAMPLE 3        The declaration
5993                int (*fpfi(int (*)(long), int))(int, ...);
5994      declares a function fpfi that returns a pointer to a function returning an int. The function fpfi has two
5995      parameters: a pointer to a function returning an int (with one parameter of type long int), and an int.
5996      The pointer returned by fpfi points to a function that has one int parameter and accepts zero or more
5997      additional arguments of any type.
5998
5999 20   EXAMPLE 4        The following prototype has a variably modified parameter.
6000                void addscalar(int n, int m,
6001                      double a[n][n*m+300], double x);
6002                int main()
6003                {
6004                      double b[4][308];
6005                      addscalar(4, 2, b, 2.17);
6006                      return 0;
6007                }
6008                void addscalar(int n, int m,
6009                      double a[n][n*m+300], double x)
6010                {
6011                      for (int i = 0; i < n; i++)
6012                            for (int j = 0, k = n*m+300; j < k; j++)
6013                                  // a is a pointer to a VLA with n*m+300 elements
6014                                  a[i][j] += x;
6015                }
6016
6017 21   EXAMPLE 5        The following are all compatible function prototype declarators.
6018                double    maximum(int        n,   int   m,   double    a[n][m]);
6019                double    maximum(int        n,   int   m,   double    a[*][*]);
6020                double    maximum(int        n,   int   m,   double    a[ ][*]);
6021                double    maximum(int        n,   int   m,   double    a[ ][m]);
6022      as are:
6023                void   f(double      (* restrict a)[5]);
6024                void   f(double      a[restrict][5]);
6025                void   f(double      a[restrict 3][5]);
6026                void   f(double      a[restrict static 3][5]);
6027
6028
6029 [page 133]
6030
6031     (Note that the last declaration also specifies that the argument corresponding to a in any call to f must be a
6032     non-null pointer to the first of at least three arrays of 5 doubles, which the others do not.)
6033
6034     Forward references: function definitions (6.9.1), type names (6.7.7).
6035     6.7.7 Type names
6036     Syntax
6037 1            type-name:
6038                     specifier-qualifier-list abstract-declaratoropt
6039              abstract-declarator:
6040                     pointer
6041                     pointeropt direct-abstract-declarator
6042              direct-abstract-declarator:
6043                      ( abstract-declarator )
6044                      direct-abstract-declaratoropt [ type-qualifier-listopt
6045                                     assignment-expressionopt ]
6046                      direct-abstract-declaratoropt [ static type-qualifier-listopt
6047                                     assignment-expression ]
6048                      direct-abstract-declaratoropt [ type-qualifier-list static
6049                                     assignment-expression ]
6050                      direct-abstract-declaratoropt [ * ]
6051                      direct-abstract-declaratoropt ( parameter-type-listopt )
6052     Semantics
6053 2   In several contexts, it is necessary to specify a type. This is accomplished using a type
6054     name, which is syntactically a declaration for a function or an object of that type that
6055     omits the identifier.146)
6056 3   EXAMPLE        The constructions
6057              (a)      int
6058              (b)      int   *
6059              (c)      int   *[3]
6060              (d)      int   (*)[3]
6061              (e)      int   (*)[*]
6062              (f)      int   *()
6063              (g)      int   (*)(void)
6064              (h)      int   (*const [])(unsigned int, ...)
6065     name respectively the types (a) int, (b) pointer to int, (c) array of three pointers to int, (d) pointer to an
6066     array of three ints, (e) pointer to a variable length array of an unspecified number of ints, (f) function
6067     with no parameter specification returning a pointer to int, (g) pointer to function with no parameters
6068
6069
6070     146) As indicated by the syntax, empty parentheses in a type name are interpreted as ''function with no
6071          parameter specification'', rather than redundant parentheses around the omitted identifier.
6072
6073 [page 134]
6074
6075     returning an int, and (h) array of an unspecified number of constant pointers to functions, each with one
6076     parameter that has type unsigned int and an unspecified number of other parameters, returning an
6077     int.
6078
6079     6.7.8 Type definitions
6080     Syntax
6081 1            typedef-name:
6082                     identifier
6083     Constraints
6084 2   If a typedef name specifies a variably modified type then it shall have block scope.
6085     Semantics
6086 3   In a declaration whose storage-class specifier is typedef, each declarator defines an
6087     identifier to be a typedef name that denotes the type specified for the identifier in the way
6088     described in 6.7.6. Any array size expressions associated with variable length array
6089     declarators are evaluated each time the declaration of the typedef name is reached in the
6090     order of execution. A typedef declaration does not introduce a new type, only a
6091     synonym for the type so specified. That is, in the following declarations:
6092              typedef T type_ident;
6093              type_ident D;
6094     type_ident is defined as a typedef name with the type specified by the declaration
6095     specifiers in T (known as T ), and the identifier in D has the type ''derived-declarator-
6096     type-list T '' where the derived-declarator-type-list is specified by the declarators of D. A
6097     typedef name shares the same name space as other identifiers declared in ordinary
6098     declarators.
6099 4   EXAMPLE 1       After
6100              typedef int MILES, KLICKSP();
6101              typedef struct { double hi, lo; } range;
6102     the constructions
6103              MILES distance;
6104              extern KLICKSP *metricp;
6105              range x;
6106              range z, *zp;
6107     are all valid declarations. The type of distance is int, that of metricp is ''pointer to function with no
6108     parameter specification returning int'', and that of x and z is the specified structure; zp is a pointer to
6109     such a structure. The object distance has a type compatible with any other int object.
6110
6111 5   EXAMPLE 2       After the declarations
6112              typedef struct s1 { int x; } t1, *tp1;
6113              typedef struct s2 { int x; } t2, *tp2;
6114     type t1 and the type pointed to by tp1 are compatible. Type t1 is also compatible with type struct
6115
6116 [page 135]
6117
6118     s1, but not compatible with the types struct s2, t2, the type pointed to by tp2, or int.
6119
6120 6   EXAMPLE 3       The following obscure constructions
6121              typedef signed int t;
6122              typedef int plain;
6123              struct tag {
6124                    unsigned t:4;
6125                    const t:5;
6126                    plain r:5;
6127              };
6128     declare a typedef name t with type signed int, a typedef name plain with type int, and a structure
6129     with three bit-field members, one named t that contains values in the range [0, 15], an unnamed const-
6130     qualified bit-field which (if it could be accessed) would contain values in either the range [-15, +15] or
6131     [-16, +15], and one named r that contains values in one of the ranges [0, 31], [-15, +15], or [-16, +15].
6132     (The choice of range is implementation-defined.) The first two bit-field declarations differ in that
6133     unsigned is a type specifier (which forces t to be the name of a structure member), while const is a
6134     type qualifier (which modifies t which is still visible as a typedef name). If these declarations are followed
6135     in an inner scope by
6136              t f(t (t));
6137              long t;
6138     then a function f is declared with type ''function returning signed int with one unnamed parameter
6139     with type pointer to function returning signed int with one unnamed parameter with type signed
6140     int'', and an identifier t with type long int.
6141
6142 7   EXAMPLE 4 On the other hand, typedef names can be used to improve code readability. All three of the
6143     following declarations of the signal function specify exactly the same type, the first without making use
6144     of any typedef names.
6145              typedef void fv(int), (*pfv)(int);
6146              void (*signal(int, void (*)(int)))(int);
6147              fv *signal(int, fv *);
6148              pfv signal(int, pfv);
6149
6150 8   EXAMPLE 5 If a typedef name denotes a variable length array type, the length of the array is fixed at the
6151     time the typedef name is defined, not each time it is used:
6152              void copyt(int n)
6153              {
6154                    typedef int B[n];   //               B is n ints, n evaluated now
6155                    n += 1;
6156                    B a;                //               a is n ints, n without += 1
6157                    int b[n];           //               a and b are different sizes
6158                    for (int i = 1; i < n;               i++)
6159                          a[i-1] = b[i];
6160              }
6161
6162
6163
6164
6165 [page 136]
6166
6167     6.7.9 Initialization
6168     Syntax
6169 1            initializer:
6170                       assignment-expression
6171                       { initializer-list }
6172                       { initializer-list , }
6173              initializer-list:
6174                       designationopt initializer
6175                       initializer-list , designationopt initializer
6176              designation:
6177                     designator-list =
6178              designator-list:
6179                     designator
6180                     designator-list designator
6181              designator:
6182                     [ constant-expression ]
6183                     . identifier
6184     Constraints
6185 2   No initializer shall attempt to provide a value for an object not contained within the entity
6186     being initialized.
6187 3   The type of the entity to be initialized shall be an array of unknown size or a complete
6188     object type that is not a variable length array type.
6189 4   All the expressions in an initializer for an object that has static or thread storage duration
6190     shall be constant expressions or string literals.
6191 5   If the declaration of an identifier has block scope, and the identifier has external or
6192     internal linkage, the declaration shall have no initializer for the identifier.
6193 6   If a designator has the form
6194              [ constant-expression ]
6195     then the current object (defined below) shall have array type and the expression shall be
6196     an integer constant expression. If the array is of unknown size, any nonnegative value is
6197     valid.
6198 7   If a designator has the form
6199              . identifier
6200     then the current object (defined below) shall have structure or union type and the
6201     identifier shall be the name of a member of that type.
6202 [page 137]
6203
6204      Semantics
6205 8    An initializer specifies the initial value stored in an object.
6206 9    Except where explicitly stated otherwise, for the purposes of this subclause unnamed
6207      members of objects of structure and union type do not participate in initialization.
6208      Unnamed members of structure objects have indeterminate value even after initialization.
6209 10   If an object that has automatic storage duration is not initialized explicitly, its value is
6210      indeterminate. If an object that has static or thread storage duration is not initialized
6211      explicitly, then:
6212      -- if it has pointer type, it is initialized to a null pointer;
6213      -- if it has arithmetic type, it is initialized to (positive or unsigned) zero;
6214      -- if it is an aggregate, every member is initialized (recursively) according to these rules,
6215        and any padding is initialized to zero bits;
6216      -- if it is a union, the first named member is initialized (recursively) according to these
6217        rules, and any padding is initialized to zero bits;
6218 11   The initializer for a scalar shall be a single expression, optionally enclosed in braces. The
6219      initial value of the object is that of the expression (after conversion); the same type
6220      constraints and conversions as for simple assignment apply, taking the type of the scalar
6221      to be the unqualified version of its declared type.
6222 12   The rest of this subclause deals with initializers for objects that have aggregate or union
6223      type.
6224 13   The initializer for a structure or union object that has automatic storage duration shall be
6225      either an initializer list as described below, or a single expression that has compatible
6226      structure or union type. In the latter case, the initial value of the object, including
6227      unnamed members, is that of the expression.
6228 14   An array of character type may be initialized by a character string literal or UTF-8 string
6229      literal, optionally enclosed in braces. Successive bytes of the string literal (including the
6230      terminating null character if there is room or if the array is of unknown size) initialize the
6231      elements of the array.
6232 15   An array with element type compatible with a qualified or unqualified version of
6233      wchar_t may be initialized by a wide string literal, optionally enclosed in braces.
6234      Successive wide characters of the wide string literal (including the terminating null wide
6235      character if there is room or if the array is of unknown size) initialize the elements of the
6236      array.
6237 16   Otherwise, the initializer for an object that has aggregate or union type shall be a brace-
6238      enclosed list of initializers for the elements or named members.
6239
6240
6241 [page 138]
6242
6243 17   Each brace-enclosed initializer list has an associated current object. When no
6244      designations are present, subobjects of the current object are initialized in order according
6245      to the type of the current object: array elements in increasing subscript order, structure
6246      members in declaration order, and the first named member of a union.147) In contrast, a
6247      designation causes the following initializer to begin initialization of the subobject
6248      described by the designator. Initialization then continues forward in order, beginning
6249      with the next subobject after that described by the designator.148)
6250 18   Each designator list begins its description with the current object associated with the
6251      closest surrounding brace pair. Each item in the designator list (in order) specifies a
6252      particular member of its current object and changes the current object for the next
6253      designator (if any) to be that member.149) The current object that results at the end of the
6254      designator list is the subobject to be initialized by the following initializer.
6255 19   The initialization shall occur in initializer list order, each initializer provided for a
6256      particular subobject overriding any previously listed initializer for the same subobject;150)
6257      all subobjects that are not initialized explicitly shall be initialized implicitly the same as
6258      objects that have static storage duration.
6259 20   If the aggregate or union contains elements or members that are aggregates or unions,
6260      these rules apply recursively to the subaggregates or contained unions. If the initializer of
6261      a subaggregate or contained union begins with a left brace, the initializers enclosed by
6262      that brace and its matching right brace initialize the elements or members of the
6263      subaggregate or the contained union. Otherwise, only enough initializers from the list are
6264      taken to account for the elements or members of the subaggregate or the first member of
6265      the contained union; any remaining initializers are left to initialize the next element or
6266      member of the aggregate of which the current subaggregate or contained union is a part.
6267 21   If there are fewer initializers in a brace-enclosed list than there are elements or members
6268      of an aggregate, or fewer characters in a string literal used to initialize an array of known
6269      size than there are elements in the array, the remainder of the aggregate shall be
6270      initialized implicitly the same as objects that have static storage duration.
6271
6272
6273
6274      147) If the initializer list for a subaggregate or contained union does not begin with a left brace, its
6275           subobjects are initialized as usual, but the subaggregate or contained union does not become the
6276           current object: current objects are associated only with brace-enclosed initializer lists.
6277      148) After a union member is initialized, the next object is not the next member of the union; instead, it is
6278           the next subobject of an object containing the union.
6279      149) Thus, a designator can only specify a strict subobject of the aggregate or union that is associated with
6280           the surrounding brace pair. Note, too, that each separate designator list is independent.
6281      150) Any initializer for the subobject which is overridden and so not used to initialize that subobject might
6282           not be evaluated at all.
6283
6284 [page 139]
6285
6286 22   If an array of unknown size is initialized, its size is determined by the largest indexed
6287      element with an explicit initializer. The array type is completed at the end of its
6288      initializer list.
6289 23   The order in which any side effects occur among the initialization list expressions is
6290      unspecified.151)
6291 24   EXAMPLE 1       Provided that <complex.h> has been #included, the declarations
6292               int i = 3.5;
6293               double complex c = 5 + 3 * I;
6294      define and initialize i with the value 3 and c with the value 5.0 + i3.0.
6295
6296 25   EXAMPLE 2       The declaration
6297               int x[] = { 1, 3, 5 };
6298      defines and initializes x as a one-dimensional array object that has three elements, as no size was specified
6299      and there are three initializers.
6300
6301 26   EXAMPLE 3       The declaration
6302               int y[4][3] =         {
6303                     { 1, 3,         5 },
6304                     { 2, 4,         6 },
6305                     { 3, 5,         7 },
6306               };
6307      is a definition with a fully bracketed initialization: 1, 3, and 5 initialize the first row of y (the array object
6308      y[0]), namely y[0][0], y[0][1], and y[0][2]. Likewise the next two lines initialize y[1] and
6309      y[2]. The initializer ends early, so y[3] is initialized with zeros. Precisely the same effect could have
6310      been achieved by
6311               int y[4][3] = {
6312                     1, 3, 5, 2, 4, 6, 3, 5, 7
6313               };
6314      The initializer for y[0] does not begin with a left brace, so three items from the list are used. Likewise the
6315      next three are taken successively for y[1] and y[2].
6316
6317 27   EXAMPLE 4       The declaration
6318               int z[4][3] = {
6319                     { 1 }, { 2 }, { 3 }, { 4 }
6320               };
6321      initializes the first column of z as specified and initializes the rest with zeros.
6322
6323 28   EXAMPLE 5       The declaration
6324               struct { int a[3], b; } w[] = { { 1 }, 2 };
6325      is a definition with an inconsistently bracketed initialization. It defines an array with two element
6326      structures: w[0].a[0] is 1 and w[1].a[0] is 2; all the other elements are zero.
6327
6328
6329
6330      151) In particular, the evaluation order need not be the same as the order of subobject initialization.
6331
6332 [page 140]
6333
6334 29   EXAMPLE 6         The declaration
6335                short q[4][3][2] = {
6336                      { 1 },
6337                      { 2, 3 },
6338                      { 4, 5, 6 }
6339                };
6340      contains an incompletely but consistently bracketed initialization. It defines a three-dimensional array
6341      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
6342      q[2][0][0], q[2][0][1], and q[2][1][0], respectively; all the rest are zero. The initializer for
6343      q[0][0] does not begin with a left brace, so up to six items from the current list may be used. There is
6344      only one, so the values for the remaining five elements are initialized with zero. Likewise, the initializers
6345      for q[1][0] and q[2][0] do not begin with a left brace, so each uses up to six items, initializing their
6346      respective two-dimensional subaggregates. If there had been more than six items in any of the lists, a
6347      diagnostic message would have been issued. The same initialization result could have been achieved by:
6348                short q[4][3][2] = {
6349                      1, 0, 0, 0, 0, 0,
6350                      2, 3, 0, 0, 0, 0,
6351                      4, 5, 6
6352                };
6353      or by:
6354                short q[4][3][2] = {
6355                      {
6356                            { 1 },
6357                      },
6358                      {
6359                            { 2, 3 },
6360                      },
6361                      {
6362                            { 4, 5 },
6363                            { 6 },
6364                      }
6365                };
6366      in a fully bracketed form.
6367 30   Note that the fully bracketed and minimally bracketed forms of initialization are, in general, less likely to
6368      cause confusion.
6369
6370 31   EXAMPLE 7         One form of initialization that completes array types involves typedef names. Given the
6371      declaration
6372                typedef int A[];             // OK - declared with block scope
6373      the declaration
6374                A a = { 1, 2 }, b = { 3, 4, 5 };
6375      is identical to
6376                int a[] = { 1, 2 }, b[] = { 3, 4, 5 };
6377      due to the rules for incomplete types.
6378
6379
6380
6381 [page 141]
6382
6383 32   EXAMPLE 8       The declaration
6384               char s[] = "abc", t[3] = "abc";
6385      defines ''plain'' char array objects s and t whose elements are initialized with character string literals.
6386      This declaration is identical to
6387               char s[] = { 'a', 'b', 'c', '\0' },
6388                    t[] = { 'a', 'b', 'c' };
6389      The contents of the arrays are modifiable. On the other hand, the declaration
6390               char *p = "abc";
6391      defines p with type ''pointer to char'' and initializes it to point to an object with type ''array of char''
6392      with length 4 whose elements are initialized with a character string literal. If an attempt is made to use p to
6393      modify the contents of the array, the behavior is undefined.
6394
6395 33   EXAMPLE 9       Arrays can be initialized to correspond to the elements of an enumeration by using
6396      designators:
6397               enum { member_one,           member_two };
6398               const char *nm[] =           {
6399                     [member_two]           = "member two",
6400                     [member_one]           = "member one",
6401               };
6402
6403 34   EXAMPLE 10       Structure members can be initialized to nonzero values without depending on their order:
6404               div_t answer = { .quot = 2, .rem = -1 };
6405
6406 35   EXAMPLE 11 Designators can be used to provide explicit initialization when unadorned initializer lists
6407      might be misunderstood:
6408               struct { int a[3], b; } w[] =
6409                     { [0].a = {1}, [1].a[0] = 2 };
6410
6411 36   EXAMPLE 12       Space can be ''allocated'' from both ends of an array by using a single designator:
6412               int a[MAX] = {
6413                     1, 3, 5, 7, 9, [MAX-5] = 8, 6, 4, 2, 0
6414               };
6415 37   In the above, if MAX is greater than ten, there will be some zero-valued elements in the middle; if it is less
6416      than ten, some of the values provided by the first five initializers will be overridden by the second five.
6417
6418 38   EXAMPLE 13       Any member of a union can be initialized:
6419               union { /* ... */ } u = { .any_member = 42 };
6420
6421      Forward references: common definitions <stddef.h> (7.19).
6422
6423
6424
6425
6426 [page 142]
6427
6428     6.7.10 Static assertions
6429     Syntax
6430 1            static_assert-declaration:
6431                      _Static_assert ( constant-expression , string-literal ) ;
6432     Constraints
6433 2   The constant expression shall compare unequal to 0.
6434     Semantics
6435 3   The constant expression shall be an integer constant expression. If the value of the
6436     constant expression compares unequal to 0, the declaration has no effect. Otherwise, the
6437     constraint is violated and the implementation shall produce a diagnostic message that
6438     includes the text of the string literal, except that characters not in the basic source
6439     character set are not required to appear in the message.
6440     Forward references: diagnostics (7.2).
6441
6442
6443
6444
6445 [page 143]
6446
6447     6.8 Statements and blocks
6448     Syntax
6449 1            statement:
6450                     labeled-statement
6451                     compound-statement
6452                     expression-statement
6453                     selection-statement
6454                     iteration-statement
6455                     jump-statement
6456     Semantics
6457 2   A statement specifies an action to be performed. Except as indicated, statements are
6458     executed in sequence.
6459 3   A block allows a set of declarations and statements to be grouped into one syntactic unit.
6460     The initializers of objects that have automatic storage duration, and the variable length
6461     array declarators of ordinary identifiers with block scope, are evaluated and the values are
6462     stored in the objects (including storing an indeterminate value in objects without an
6463     initializer) each time the declaration is reached in the order of execution, as if it were a
6464     statement, and within each declaration in the order that declarators appear.
6465 4   A full expression is an expression that is not part of another expression or of a declarator.
6466     Each of the following is a full expression: an initializer that is not part of a compound
6467     literal; the expression in an expression statement; the controlling expression of a selection
6468     statement (if or switch); the controlling expression of a while or do statement; each
6469     of the (optional) expressions of a for statement; the (optional) expression in a return
6470     statement. There is a sequence point between the evaluation of a full expression and the
6471     evaluation of the next full expression to be evaluated.
6472     Forward references: expression and null statements (6.8.3), selection statements
6473     (6.8.4), iteration statements (6.8.5), the return statement (6.8.6.4).
6474     6.8.1 Labeled statements
6475     Syntax
6476 1            labeled-statement:
6477                     identifier : statement
6478                     case constant-expression : statement
6479                     default : statement
6480     Constraints
6481 2   A case or default label shall appear only in a switch statement. Further
6482     constraints on such labels are discussed under the switch statement.
6483
6484 [page 144]
6485
6486 3   Label names shall be unique within a function.
6487     Semantics
6488 4   Any statement may be preceded by a prefix that declares an identifier as a label name.
6489     Labels in themselves do not alter the flow of control, which continues unimpeded across
6490     them.
6491     Forward references: the goto statement (6.8.6.1), the switch statement (6.8.4.2).
6492     6.8.2 Compound statement
6493     Syntax
6494 1            compound-statement:
6495                    { block-item-listopt }
6496              block-item-list:
6497                      block-item
6498                      block-item-list block-item
6499              block-item:
6500                      declaration
6501                      statement
6502     Semantics
6503 2   A compound statement is a block.
6504     6.8.3 Expression and null statements
6505     Syntax
6506 1            expression-statement:
6507                     expressionopt ;
6508     Semantics
6509 2   The expression in an expression statement is evaluated as a void expression for its side
6510     effects.152)
6511 3   A null statement (consisting of just a semicolon) performs no operations.
6512 4   EXAMPLE 1 If a function call is evaluated as an expression statement for its side effects only, the
6513     discarding of its value may be made explicit by converting the expression to a void expression by means of
6514     a cast:
6515              int p(int);
6516              /* ... */
6517              (void)p(0);
6518
6519
6520
6521     152) Such as assignments, and function calls which have side effects.
6522
6523 [page 145]
6524
6525 5   EXAMPLE 2       In the program fragment
6526              char *s;
6527              /* ... */
6528              while (*s++ != '\0')
6529                      ;
6530     a null statement is used to supply an empty loop body to the iteration statement.
6531
6532 6   EXAMPLE 3       A null statement may also be used to carry a label just before the closing } of a compound
6533     statement.
6534              while (loop1) {
6535                    /* ... */
6536                    while (loop2) {
6537                            /* ... */
6538                            if (want_out)
6539                                    goto end_loop1;
6540                            /* ... */
6541                    }
6542                    /* ... */
6543              end_loop1: ;
6544              }
6545
6546     Forward references: iteration statements (6.8.5).
6547     6.8.4 Selection statements
6548     Syntax
6549 1            selection-statement:
6550                      if ( expression ) statement
6551                      if ( expression ) statement else statement
6552                      switch ( expression ) statement
6553     Semantics
6554 2   A selection statement selects among a set of statements depending on the value of a
6555     controlling expression.
6556 3   A selection statement is a block whose scope is a strict subset of the scope of its
6557     enclosing block. Each associated substatement is also a block whose scope is a strict
6558     subset of the scope of the selection statement.
6559     6.8.4.1 The if statement
6560     Constraints
6561 1   The controlling expression of an if statement shall have scalar type.
6562     Semantics
6563 2   In both forms, the first substatement is executed if the expression compares unequal to 0.
6564     In the else form, the second substatement is executed if the expression compares equal
6565
6566
6567 [page 146]
6568
6569     to 0. If the first substatement is reached via a label, the second substatement is not
6570     executed.
6571 3   An else is associated with the lexically nearest preceding if that is allowed by the
6572     syntax.
6573     6.8.4.2 The switch statement
6574     Constraints
6575 1   The controlling expression of a switch statement shall have integer type.
6576 2   If a switch statement has an associated case or default label within the scope of an
6577     identifier with a variably modified type, the entire switch statement shall be within the
6578     scope of that identifier.153)
6579 3   The expression of each case label shall be an integer constant expression and no two of
6580     the case constant expressions in the same switch statement shall have the same value
6581     after conversion. There may be at most one default label in a switch statement.
6582     (Any enclosed switch statement may have a default label or case constant
6583     expressions with values that duplicate case constant expressions in the enclosing
6584     switch statement.)
6585     Semantics
6586 4   A switch statement causes control to jump to, into, or past the statement that is the
6587     switch body, depending on the value of a controlling expression, and on the presence of a
6588     default label and the values of any case labels on or in the switch body. A case or
6589     default label is accessible only within the closest enclosing switch statement.
6590 5   The integer promotions are performed on the controlling expression. The constant
6591     expression in each case label is converted to the promoted type of the controlling
6592     expression. If a converted value matches that of the promoted controlling expression,
6593     control jumps to the statement following the matched case label. Otherwise, if there is
6594     a default label, control jumps to the labeled statement. If no converted case constant
6595     expression matches and there is no default label, no part of the switch body is
6596     executed.
6597     Implementation limits
6598 6   As discussed in 5.2.4.1, the implementation may limit the number of case values in a
6599     switch statement.
6600
6601
6602
6603
6604     153) That is, the declaration either precedes the switch statement, or it follows the last case or
6605          default label associated with the switch that is in the block containing the declaration.
6606
6607 [page 147]
6608
6609 7   EXAMPLE        In the artificial program fragment
6610              switch (expr)
6611              {
6612                    int i = 4;
6613                    f(i);
6614              case 0:
6615                    i = 17;
6616                    /* falls through into default code */
6617              default:
6618                    printf("%d\n", i);
6619              }
6620     the object whose identifier is i exists with automatic storage duration (within the block) but is never
6621     initialized, and thus if the controlling expression has a nonzero value, the call to the printf function will
6622     access an indeterminate value. Similarly, the call to the function f cannot be reached.
6623
6624     6.8.5 Iteration statements
6625     Syntax
6626 1            iteration-statement:
6627                      while ( expression ) statement
6628                      do statement while ( expression ) ;
6629                      for ( expressionopt ; expressionopt ; expressionopt ) statement
6630                      for ( declaration expressionopt ; expressionopt ) statement
6631     Constraints
6632 2   The controlling expression of an iteration statement shall have scalar type.
6633 3   The declaration part of a for statement shall only declare identifiers for objects having
6634     storage class auto or register.
6635     Semantics
6636 4   An iteration statement causes a statement called the loop body to be executed repeatedly
6637     until the controlling expression compares equal to 0. The repetition occurs regardless of
6638     whether the loop body is entered from the iteration statement or by a jump.154)
6639 5   An iteration statement is a block whose scope is a strict subset of the scope of its
6640     enclosing block. The loop body is also a block whose scope is a strict subset of the scope
6641     of the iteration statement.
6642 6   An iteration statement that performs no input/output operations, does not access volatile
6643     objects, and performs no synchronization or atomic operations in its body, controlling
6644     expression, or (in the case of a for statement) its expression-3, may be assumed by the
6645     implementation to terminate.155)
6646
6647     154) Code jumped over is not executed. In particular, the controlling expression of a for or while
6648          statement is not evaluated before entering the loop body, nor is clause-1 of a for statement.
6649
6650 [page 148]
6651
6652     6.8.5.1 The while statement
6653 1   The evaluation of the controlling expression takes place before each execution of the loop
6654     body.
6655     6.8.5.2 The do statement
6656 1   The evaluation of the controlling expression takes place after each execution of the loop
6657     body.
6658     6.8.5.3 The for statement
6659 1   The statement
6660              for ( clause-1 ; expression-2 ; expression-3 ) statement
6661     behaves as follows: The expression expression-2 is the controlling expression that is
6662     evaluated before each execution of the loop body. The expression expression-3 is
6663     evaluated as a void expression after each execution of the loop body. If clause-1 is a
6664     declaration, the scope of any identifiers it declares is the remainder of the declaration and
6665     the entire loop, including the other two expressions; it is reached in the order of execution
6666     before the first evaluation of the controlling expression. If clause-1 is an expression, it is
6667     evaluated as a void expression before the first evaluation of the controlling expression.156)
6668 2   Both clause-1 and expression-3 can be omitted. An omitted expression-2 is replaced by a
6669     nonzero constant.
6670     6.8.6 Jump statements
6671     Syntax
6672 1            jump-statement:
6673                     goto identifier ;
6674                     continue ;
6675                     break ;
6676                     return expressionopt ;
6677     Semantics
6678 2   A jump statement causes an unconditional jump to another place.
6679
6680
6681
6682
6683     155) This is intended to allow compiler transformations such as removal of empty loops even when
6684          termination cannot be proven.
6685     156) Thus, clause-1 specifies initialization for the loop, possibly declaring one or more variables for use in
6686          the loop; the controlling expression, expression-2, specifies an evaluation made before each iteration,
6687          such that execution of the loop continues until the expression compares equal to 0; and expression-3
6688          specifies an operation (such as incrementing) that is performed after each iteration.
6689
6690 [page 149]
6691
6692     6.8.6.1 The goto statement
6693     Constraints
6694 1   The identifier in a goto statement shall name a label located somewhere in the enclosing
6695     function. A goto statement shall not jump from outside the scope of an identifier having
6696     a variably modified type to inside the scope of that identifier.
6697     Semantics
6698 2   A goto statement causes an unconditional jump to the statement prefixed by the named
6699     label in the enclosing function.
6700 3   EXAMPLE 1 It is sometimes convenient to jump into the middle of a complicated set of statements. The
6701     following outline presents one possible approach to a problem based on these three assumptions:
6702       1.   The general initialization code accesses objects only visible to the current function.
6703       2.   The general initialization code is too large to warrant duplication.
6704       3. The code to determine the next operation is at the head of the loop. (To allow it to be reached by
6705          continue statements, for example.)
6706             /* ... */
6707             goto first_time;
6708             for (;;) {
6709                     // determine next operation
6710                     /* ... */
6711                     if (need to reinitialize) {
6712                             // reinitialize-only code
6713                             /* ... */
6714                     first_time:
6715                             // general initialization code
6716                             /* ... */
6717                             continue;
6718                     }
6719                     // handle other operations
6720                     /* ... */
6721             }
6722
6723
6724
6725
6726 [page 150]
6727
6728 4   EXAMPLE 2 A goto statement is not allowed to jump past any declarations of objects with variably
6729     modified types. A jump within the scope, however, is permitted.
6730             goto lab3;                         // invalid: going INTO scope of VLA.
6731             {
6732                   double a[n];
6733                   a[j] = 4.4;
6734             lab3:
6735                   a[j] = 3.3;
6736                   goto lab4;                   // valid: going WITHIN scope of VLA.
6737                   a[j] = 5.5;
6738             lab4:
6739                   a[j] = 6.6;
6740             }
6741             goto lab4;                         // invalid: going INTO scope of VLA.
6742
6743     6.8.6.2 The continue statement
6744     Constraints
6745 1   A continue statement shall appear only in or as a loop body.
6746     Semantics
6747 2   A continue statement causes a jump to the loop-continuation portion of the smallest
6748     enclosing iteration statement; that is, to the end of the loop body. More precisely, in each
6749     of the statements
6750     while (/* ... */) {                  do {                                 for (/* ... */) {
6751        /* ... */                            /* ... */                            /* ... */
6752        continue;                            continue;                            continue;
6753        /* ... */                            /* ... */                            /* ... */
6754     contin: ;                            contin: ;                            contin: ;
6755     }                                    } while (/* ... */);                 }
6756     unless the continue statement shown is in an enclosed iteration statement (in which
6757     case it is interpreted within that statement), it is equivalent to goto contin;.157)
6758     6.8.6.3 The break statement
6759     Constraints
6760 1   A break statement shall appear only in or as a switch body or loop body.
6761     Semantics
6762 2   A break statement terminates execution of the smallest enclosing switch or iteration
6763     statement.
6764
6765
6766
6767     157) Following the contin: label is a null statement.
6768
6769 [page 151]
6770
6771     6.8.6.4 The return statement
6772     Constraints
6773 1   A return statement with an expression shall not appear in a function whose return type
6774     is void. A return statement without an expression shall only appear in a function
6775     whose return type is void.
6776     Semantics
6777 2   A return statement terminates execution of the current function and returns control to
6778     its caller. A function may have any number of return statements.
6779 3   If a return statement with an expression is executed, the value of the expression is
6780     returned to the caller as the value of the function call expression. If the expression has a
6781     type different from the return type of the function in which it appears, the value is
6782     converted as if by assignment to an object having the return type of the function.158)
6783 4   EXAMPLE       In:
6784             struct s { double i; } f(void);
6785             union {
6786                   struct {
6787                         int f1;
6788                         struct s f2;
6789                   } u1;
6790                   struct {
6791                         struct s f3;
6792                         int f4;
6793                   } u2;
6794             } g;
6795             struct s f(void)
6796             {
6797                   return g.u1.f2;
6798             }
6799             /* ... */
6800             g.u2.f3 = f();
6801     there is no undefined behavior, although there would be if the assignment were done directly (without using
6802     a function call to fetch the value).
6803
6804
6805
6806
6807     158) The return statement is not an assignment. The overlap restriction of subclause 6.5.16.1 does not
6808          apply to the case of function return. The representation of floating-point values may have wider range
6809          or precision than implied by the type; a cast may be used to remove this extra range and precision.
6810
6811 [page 152]
6812
6813     6.9 External definitions
6814     Syntax
6815 1            translation-unit:
6816                      external-declaration
6817                      translation-unit external-declaration
6818              external-declaration:
6819                     function-definition
6820                     declaration
6821     Constraints
6822 2   The storage-class specifiers auto and register shall not appear in the declaration
6823     specifiers in an external declaration.
6824 3   There shall be no more than one external definition for each identifier declared with
6825     internal linkage in a translation unit. Moreover, if an identifier declared with internal
6826     linkage is used in an expression (other than as a part of the operand of a sizeof
6827     operator whose result is an integer constant), there shall be exactly one external definition
6828     for the identifier in the translation unit.
6829     Semantics
6830 4   As discussed in 5.1.1.1, the unit of program text after preprocessing is a translation unit,
6831     which consists of a sequence of external declarations. These are described as ''external''
6832     because they appear outside any function (and hence have file scope). As discussed in
6833     6.7, a declaration that also causes storage to be reserved for an object or a function named
6834     by the identifier is a definition.
6835 5   An external definition is an external declaration that is also a definition of a function
6836     (other than an inline definition) or an object. If an identifier declared with external
6837     linkage is used in an expression (other than as part of the operand of a sizeof operator
6838     whose result is an integer constant), somewhere in the entire program there shall be
6839     exactly one external definition for the identifier; otherwise, there shall be no more than
6840     one.159)
6841
6842
6843
6844
6845     159) Thus, if an identifier declared with external linkage is not used in an expression, there need be no
6846          external definition for it.
6847
6848 [page 153]
6849
6850     6.9.1 Function definitions
6851     Syntax
6852 1            function-definition:
6853                     declaration-specifiers declarator declaration-listopt compound-statement
6854              declaration-list:
6855                     declaration
6856                     declaration-list declaration
6857     Constraints
6858 2   The identifier declared in a function definition (which is the name of the function) shall
6859     have a function type, as specified by the declarator portion of the function definition.160)
6860 3   The return type of a function shall be void or a complete object type other than array
6861     type.
6862 4   The storage-class specifier, if any, in the declaration specifiers shall be either extern or
6863     static.
6864 5   If the declarator includes a parameter type list, the declaration of each parameter shall
6865     include an identifier, except for the special case of a parameter list consisting of a single
6866     parameter of type void, in which case there shall not be an identifier. No declaration list
6867     shall follow.
6868 6   If the declarator includes an identifier list, each declaration in the declaration list shall
6869     have at least one declarator, those declarators shall declare only identifiers from the
6870     identifier list, and every identifier in the identifier list shall be declared. An identifier
6871     declared as a typedef name shall not be redeclared as a parameter. The declarations in the
6872     declaration list shall contain no storage-class specifier other than register and no
6873     initializations.
6874
6875
6876
6877     160) The intent is that the type category in a function definition cannot be inherited from a typedef:
6878                   typedef int F(void);                          //   type F is ''function with no parameters
6879                                                                 //                  returning int''
6880                   F f, g;                                       //   f and g both have type compatible with F
6881                   F f { /* ... */ }                             //   WRONG: syntax/constraint error
6882                   F g() { /* ... */ }                           //   WRONG: declares that g returns a function
6883                   int f(void) { /* ... */ }                     //   RIGHT: f has type compatible with F
6884                   int g() { /* ... */ }                         //   RIGHT: g has type compatible with F
6885                   F *e(void) { /* ... */ }                      //   e returns a pointer to a function
6886                   F *((e))(void) { /* ... */ }                  //   same: parentheses irrelevant
6887                   int (*fp)(void);                              //   fp points to a function that has type F
6888                   F *Fp;                                        //   Fp points to a function that has type F
6889
6890
6891 [page 154]
6892
6893      Semantics
6894 7    The declarator in a function definition specifies the name of the function being defined
6895      and the identifiers of its parameters. If the declarator includes a parameter type list, the
6896      list also specifies the types of all the parameters; such a declarator also serves as a
6897      function prototype for later calls to the same function in the same translation unit. If the
6898      declarator includes an identifier list,161) the types of the parameters shall be declared in a
6899      following declaration list. In either case, the type of each parameter is adjusted as
6900      described in 6.7.6.3 for a parameter type list; the resulting type shall be a complete object
6901      type.
6902 8    If a function that accepts a variable number of arguments is defined without a parameter
6903      type list that ends with the ellipsis notation, the behavior is undefined.
6904 9    Each parameter has automatic storage duration; its identifier is an lvalue.162) The layout
6905      of the storage for parameters is unspecified.
6906 10   On entry to the function, the size expressions of each variably modified parameter are
6907      evaluated and the value of each argument expression is converted to the type of the
6908      corresponding parameter as if by assignment. (Array expressions and function
6909      designators as arguments were converted to pointers before the call.)
6910 11   After all parameters have been assigned, the compound statement that constitutes the
6911      body of the function definition is executed.
6912 12   If the } that terminates a function is reached, and the value of the function call is used by
6913      the caller, the behavior is undefined.
6914 13   EXAMPLE 1       In the following:
6915               extern int max(int a, int b)
6916               {
6917                     return a > b ? a : b;
6918               }
6919      extern is the storage-class specifier and int is the type specifier; max(int a, int b) is the
6920      function declarator; and
6921               { return a > b ? a : b; }
6922      is the function body. The following similar definition uses the identifier-list form for the parameter
6923      declarations:
6924
6925
6926
6927
6928      161) See ''future language directions'' (6.11.7).
6929      162) A parameter identifier cannot be redeclared in the function body except in an enclosed block.
6930
6931 [page 155]
6932
6933               extern int max(a, b)
6934               int a, b;
6935               {
6936                     return a > b ? a : b;
6937               }
6938      Here int a, b; is the declaration list for the parameters. The difference between these two definitions is
6939      that the first form acts as a prototype declaration that forces conversion of the arguments of subsequent calls
6940      to the function, whereas the second form does not.
6941
6942 14   EXAMPLE 2           To pass one function to another, one might say
6943                           int f(void);
6944                           /* ... */
6945                           g(f);
6946      Then the definition of g might read
6947               void g(int (*funcp)(void))
6948               {
6949                     /* ... */
6950                     (*funcp)(); /* or funcp(); ...                    */
6951               }
6952      or, equivalently,
6953               void g(int func(void))
6954               {
6955                     /* ... */
6956                     func(); /* or (*func)(); ...                   */
6957               }
6958
6959      6.9.2 External object definitions
6960      Semantics
6961 1    If the declaration of an identifier for an object has file scope and an initializer, the
6962      declaration is an external definition for the identifier.
6963 2    A declaration of an identifier for an object that has file scope without an initializer, and
6964      without a storage-class specifier or with the storage-class specifier static, constitutes a
6965      tentative definition. If a translation unit contains one or more tentative definitions for an
6966      identifier, and the translation unit contains no external definition for that identifier, then
6967      the behavior is exactly as if the translation unit contains a file scope declaration of that
6968      identifier, with the composite type as of the end of the translation unit, with an initializer
6969      equal to 0.
6970 3    If the declaration of an identifier for an object is a tentative definition and has internal
6971      linkage, the declared type shall not be an incomplete type.
6972
6973
6974
6975
6976 [page 156]
6977
6978 4   EXAMPLE 1
6979              int i1 = 1;                    // definition, external linkage
6980              static int i2 = 2;             // definition, internal linkage
6981              extern int i3 = 3;             // definition, external linkage
6982              int i4;                        // tentative definition, external linkage
6983              static int i5;                 // tentative definition, internal linkage
6984              int   i1;                      // valid tentative definition, refers to previous
6985              int   i2;                      // 6.2.2 renders undefined, linkage disagreement
6986              int   i3;                      // valid tentative definition, refers to previous
6987              int   i4;                      // valid tentative definition, refers to previous
6988              int   i5;                      // 6.2.2 renders undefined, linkage disagreement
6989              extern    int   i1;            // refers to previous, whose linkage is external
6990              extern    int   i2;            // refers to previous, whose linkage is internal
6991              extern    int   i3;            // refers to previous, whose linkage is external
6992              extern    int   i4;            // refers to previous, whose linkage is external
6993              extern    int   i5;            // refers to previous, whose linkage is internal
6994
6995 5   EXAMPLE 2       If at the end of the translation unit containing
6996              int i[];
6997     the array i still has incomplete type, the implicit initializer causes it to have one element, which is set to
6998     zero on program startup.
6999
7000
7001
7002
7003 [page 157]
7004
7005     6.10 Preprocessing directives
7006     Syntax
7007 1            preprocessing-file:
7008                     groupopt
7009              group:
7010                       group-part
7011                       group group-part
7012              group-part:
7013                     if-section
7014                     control-line
7015                     text-line
7016                     # non-directive
7017              if-section:
7018                       if-group elif-groupsopt else-groupopt endif-line
7019              if-group:
7020                      # if     constant-expression new-line groupopt
7021                      # ifdef identifier new-line groupopt
7022                      # ifndef identifier new-line groupopt
7023              elif-groups:
7024                      elif-group
7025                      elif-groups elif-group
7026              elif-group:
7027                      # elif        constant-expression new-line groupopt
7028              else-group:
7029                      # else        new-line groupopt
7030              endif-line:
7031                      # endif       new-line
7032
7033
7034
7035
7036 [page 158]
7037
7038              control-line:
7039                     # include pp-tokens new-line
7040                     # define identifier replacement-list new-line
7041                     # define identifier lparen identifier-listopt )
7042                                                     replacement-list new-line
7043                     # define identifier lparen ... ) replacement-list new-line
7044                     # define identifier lparen identifier-list , ... )
7045                                                     replacement-list new-line
7046                     # undef   identifier new-line
7047                     # line    pp-tokens new-line
7048                     # error   pp-tokensopt new-line
7049                     # pragma pp-tokensopt new-line
7050                     #         new-line
7051              text-line:
7052                      pp-tokensopt new-line
7053              non-directive:
7054                     pp-tokens new-line
7055              lparen:
7056                        a ( character not immediately preceded by white-space
7057              replacement-list:
7058                     pp-tokensopt
7059              pp-tokens:
7060                     preprocessing-token
7061                     pp-tokens preprocessing-token
7062              new-line:
7063                     the new-line character
7064     Description
7065 2   A preprocessing directive consists of a sequence of preprocessing tokens that satisfies the
7066     following constraints: The first token in the sequence is a # preprocessing token that (at
7067     the start of translation phase 4) is either the first character in the source file (optionally
7068     after white space containing no new-line characters) or that follows white space
7069     containing at least one new-line character. The last token in the sequence is the first new-
7070     line character that follows the first token in the sequence.163) A new-line character ends
7071     the preprocessing directive even if it occurs within what would otherwise be an
7072
7073     163) Thus, preprocessing directives are commonly called ''lines''. These ''lines'' have no other syntactic
7074          significance, as all white space is equivalent except in certain situations during preprocessing (see the
7075          # character string literal creation operator in 6.10.3.2, for example).
7076
7077 [page 159]
7078
7079     invocation of a function-like macro.
7080 3   A text line shall not begin with a # preprocessing token. A non-directive shall not begin
7081     with any of the directive names appearing in the syntax.
7082 4   When in a group that is skipped (6.10.1), the directive syntax is relaxed to allow any
7083     sequence of preprocessing tokens to occur between the directive name and the following
7084     new-line character.
7085     Constraints
7086 5   The only white-space characters that shall appear between preprocessing tokens within a
7087     preprocessing directive (from just after the introducing # preprocessing token through
7088     just before the terminating new-line character) are space and horizontal-tab (including
7089     spaces that have replaced comments or possibly other white-space characters in
7090     translation phase 3).
7091     Semantics
7092 6   The implementation can process and skip sections of source files conditionally, include
7093     other source files, and replace macros. These capabilities are called preprocessing,
7094     because conceptually they occur before translation of the resulting translation unit.
7095 7   The preprocessing tokens within a preprocessing directive are not subject to macro
7096     expansion unless otherwise stated.
7097 8   EXAMPLE        In:
7098              #define EMPTY
7099              EMPTY # include <file.h>
7100     the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not
7101     begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been
7102     replaced.
7103
7104     6.10.1 Conditional inclusion
7105     Constraints
7106 1   The expression that controls conditional inclusion shall be an integer constant expression
7107     except that: identifiers (including those lexically identical to keywords) are interpreted as
7108     described below;164) and it may contain unary operator expressions of the form
7109          defined identifier
7110     or
7111          defined ( identifier )
7112     which evaluate to 1 if the identifier is currently defined as a macro name (that is, if it is
7113
7114
7115     164) Because the controlling constant expression is evaluated during translation phase 4, all identifiers
7116          either are or are not macro names -- there simply are no keywords, enumeration constants, etc.
7117
7118 [page 160]
7119
7120     predefined or if it has been the subject of a #define preprocessing directive without an
7121     intervening #undef directive with the same subject identifier), 0 if it is not.
7122 2   Each preprocessing token that remains (in the list of preprocessing tokens that will
7123     become the controlling expression) after all macro replacements have occurred shall be in
7124     the lexical form of a token (6.4).
7125     Semantics
7126 3   Preprocessing directives of the forms
7127        # if   constant-expression new-line groupopt
7128        # elif constant-expression new-line groupopt
7129     check whether the controlling constant expression evaluates to nonzero.
7130 4   Prior to evaluation, macro invocations in the list of preprocessing tokens that will become
7131     the controlling constant expression are replaced (except for those macro names modified
7132     by the defined unary operator), just as in normal text. If the token defined is
7133     generated as a result of this replacement process or use of the defined unary operator
7134     does not match one of the two specified forms prior to macro replacement, the behavior is
7135     undefined. After all replacements due to macro expansion and the defined unary
7136     operator have been performed, all remaining identifiers (including those lexically
7137     identical to keywords) are replaced with the pp-number 0, and then each preprocessing
7138     token is converted into a token. The resulting tokens compose the controlling constant
7139     expression which is evaluated according to the rules of 6.6. For the purposes of this
7140     token conversion and evaluation, all signed integer types and all unsigned integer types
7141     act as if they have the same representation as, respectively, the types intmax_t and
7142     uintmax_t defined in the header <stdint.h>.165) This includes interpreting
7143     character constants, which may involve converting escape sequences into execution
7144     character set members. Whether the numeric value for these character constants matches
7145     the value obtained when an identical character constant occurs in an expression (other
7146     than within a #if or #elif directive) is implementation-defined.166) Also, whether a
7147     single-character character constant may have a negative value is implementation-defined.
7148
7149
7150
7151
7152     165) Thus, on an implementation where INT_MAX is 0x7FFF and UINT_MAX is 0xFFFF, the constant
7153          0x8000 is signed and positive within a #if expression even though it would be unsigned in
7154          translation phase 7.
7155     166) Thus, the constant expression in the following #if directive and if statement is not guaranteed to
7156          evaluate to the same value in these two contexts.
7157             #if 'z' - 'a' == 25
7158             if ('z' - 'a' == 25)
7159
7160
7161 [page 161]
7162
7163 5   Preprocessing directives of the forms
7164        # ifdef identifier new-line groupopt
7165        # ifndef identifier new-line groupopt
7166     check whether the identifier is or is not currently defined as a macro name. Their
7167     conditions are equivalent to #if defined identifier and #if !defined identifier
7168     respectively.
7169 6   Each directive's condition is checked in order. If it evaluates to false (zero), the group
7170     that it controls is skipped: directives are processed only through the name that determines
7171     the directive in order to keep track of the level of nested conditionals; the rest of the
7172     directives' preprocessing tokens are ignored, as are the other preprocessing tokens in the
7173     group. Only the first group whose control condition evaluates to true (nonzero) is
7174     processed. If none of the conditions evaluates to true, and there is a #else directive, the
7175     group controlled by the #else is processed; lacking a #else directive, all the groups
7176     until the #endif are skipped.167)
7177     Forward references: macro replacement (6.10.3), source file inclusion (6.10.2), largest
7178     integer types (7.20.1.5).
7179     6.10.2 Source file inclusion
7180     Constraints
7181 1   A #include directive shall identify a header or source file that can be processed by the
7182     implementation.
7183     Semantics
7184 2   A preprocessing directive of the form
7185        # include <h-char-sequence> new-line
7186     searches a sequence of implementation-defined places for a header identified uniquely by
7187     the specified sequence between the < and > delimiters, and causes the replacement of that
7188     directive by the entire contents of the header. How the places are specified or the header
7189     identified is implementation-defined.
7190 3   A preprocessing directive of the form
7191        # include "q-char-sequence" new-line
7192     causes the replacement of that directive by the entire contents of the source file identified
7193     by the specified sequence between the " delimiters. The named source file is searched
7194
7195
7196     167) As indicated by the syntax, a preprocessing token shall not follow a #else or #endif directive
7197          before the terminating new-line character. However, comments may appear anywhere in a source file,
7198          including within a preprocessing directive.
7199
7200 [page 162]
7201
7202     for in an implementation-defined manner. If this search is not supported, or if the search
7203     fails, the directive is reprocessed as if it read
7204        # include <h-char-sequence> new-line
7205     with the identical contained sequence (including > characters, if any) from the original
7206     directive.
7207 4   A preprocessing directive of the form
7208        # include pp-tokens new-line
7209     (that does not match one of the two previous forms) is permitted. The preprocessing
7210     tokens after include in the directive are processed just as in normal text. (Each
7211     identifier currently defined as a macro name is replaced by its replacement list of
7212     preprocessing tokens.) The directive resulting after all replacements shall match one of
7213     the two previous forms.168) The method by which a sequence of preprocessing tokens
7214     between a < and a > preprocessing token pair or a pair of " characters is combined into a
7215     single header name preprocessing token is implementation-defined.
7216 5   The implementation shall provide unique mappings for sequences consisting of one or
7217     more nondigits or digits (6.4.2.1) followed by a period (.) and a single nondigit. The
7218     first character shall not be a digit. The implementation may ignore distinctions of
7219     alphabetical case and restrict the mapping to eight significant characters before the
7220     period.
7221 6   A #include preprocessing directive may appear in a source file that has been read
7222     because of a #include directive in another file, up to an implementation-defined
7223     nesting limit (see 5.2.4.1).
7224 7   EXAMPLE 1       The most common uses of #include preprocessing directives are as in the following:
7225               #include <stdio.h>
7226               #include "myprog.h"
7227
7228
7229
7230
7231     168) Note that adjacent string literals are not concatenated into a single string literal (see the translation
7232          phases in 5.1.1.2); thus, an expansion that results in two string literals is an invalid directive.
7233
7234 [page 163]
7235
7236 8   EXAMPLE 2     This illustrates macro-replaced #include directives:
7237            #if VERSION == 1
7238                  #define INCFILE            "vers1.h"
7239            #elif VERSION == 2
7240                  #define INCFILE            "vers2.h"        // and so on
7241            #else
7242                   #define INCFILE           "versN.h"
7243            #endif
7244            #include INCFILE
7245
7246     Forward references: macro replacement (6.10.3).
7247     6.10.3 Macro replacement
7248     Constraints
7249 1   Two replacement lists are identical if and only if the preprocessing tokens in both have
7250     the same number, ordering, spelling, and white-space separation, where all white-space
7251     separations are considered identical.
7252 2   An identifier currently defined as an object-like macro shall not be redefined by another
7253     #define preprocessing directive unless the second definition is an object-like macro
7254     definition and the two replacement lists are identical. Likewise, an identifier currently
7255     defined as a function-like macro shall not be redefined by another #define
7256     preprocessing directive unless the second definition is a function-like macro definition
7257     that has the same number and spelling of parameters, and the two replacement lists are
7258     identical.
7259 3   There shall be white-space between the identifier and the replacement list in the definition
7260     of an object-like macro.
7261 4   If the identifier-list in the macro definition does not end with an ellipsis, the number of
7262     arguments (including those arguments consisting of no preprocessing tokens) in an
7263     invocation of a function-like macro shall equal the number of parameters in the macro
7264     definition. Otherwise, there shall be more arguments in the invocation than there are
7265     parameters in the macro definition (excluding the ...). There shall exist a )
7266     preprocessing token that terminates the invocation.
7267 5   The identifier __VA_ARGS__ shall occur only in the replacement-list of a function-like
7268     macro that uses the ellipsis notation in the parameters.
7269 6   A parameter identifier in a function-like macro shall be uniquely declared within its
7270     scope.
7271     Semantics
7272 7   The identifier immediately following the define is called the macro name. There is one
7273     name space for macro names. Any white-space characters preceding or following the
7274     replacement list of preprocessing tokens are not considered part of the replacement list
7275
7276 [page 164]
7277
7278      for either form of macro.
7279 8    If a # preprocessing token, followed by an identifier, occurs lexically at the point at which
7280      a preprocessing directive could begin, the identifier is not subject to macro replacement.
7281 9    A preprocessing directive of the form
7282         # define identifier replacement-list new-line
7283      defines an object-like macro that causes each subsequent instance of the macro name169)
7284      to be replaced by the replacement list of preprocessing tokens that constitute the
7285      remainder of the directive. The replacement list is then rescanned for more macro names
7286      as specified below.
7287 10   A preprocessing directive of the form
7288         # define identifier lparen identifier-listopt ) replacement-list new-line
7289         # define identifier lparen ... ) replacement-list new-line
7290         # define identifier lparen identifier-list , ... ) replacement-list new-line
7291      defines a function-like macro with parameters, whose use is similar syntactically to a
7292      function call. The parameters are specified by the optional list of identifiers, whose scope
7293      extends from their declaration in the identifier list until the new-line character that
7294      terminates the #define preprocessing directive. Each subsequent instance of the
7295      function-like macro name followed by a ( as the next preprocessing token introduces the
7296      sequence of preprocessing tokens that is replaced by the replacement list in the definition
7297      (an invocation of the macro). The replaced sequence of preprocessing tokens is
7298      terminated by the matching ) preprocessing token, skipping intervening matched pairs of
7299      left and right parenthesis preprocessing tokens. Within the sequence of preprocessing
7300      tokens making up an invocation of a function-like macro, new-line is considered a normal
7301      white-space character.
7302 11   The sequence of preprocessing tokens bounded by the outside-most matching parentheses
7303      forms the list of arguments for the function-like macro. The individual arguments within
7304      the list are separated by comma preprocessing tokens, but comma preprocessing tokens
7305      between matching inner parentheses do not separate arguments. If there are sequences of
7306      preprocessing tokens within the list of arguments that would otherwise act as
7307      preprocessing directives,170) the behavior is undefined.
7308 12   If there is a ... in the identifier-list in the macro definition, then the trailing arguments,
7309      including any separating comma preprocessing tokens, are merged to form a single item:
7310
7311
7312      169) Since, by macro-replacement time, all character constants and string literals are preprocessing tokens,
7313           not sequences possibly containing identifier-like subsequences (see 5.1.1.2, translation phases), they
7314           are never scanned for macro names or parameters.
7315      170) Despite the name, a non-directive is a preprocessing directive.
7316
7317 [page 165]
7318
7319     the variable arguments. The number of arguments so combined is such that, following
7320     merger, the number of arguments is one more than the number of parameters in the macro
7321     definition (excluding the ...).
7322     6.10.3.1 Argument substitution
7323 1   After the arguments for the invocation of a function-like macro have been identified,
7324     argument substitution takes place. A parameter in the replacement list, unless preceded
7325     by a # or ## preprocessing token or followed by a ## preprocessing token (see below), is
7326     replaced by the corresponding argument after all macros contained therein have been
7327     expanded. Before being substituted, each argument's preprocessing tokens are
7328     completely macro replaced as if they formed the rest of the preprocessing file; no other
7329     preprocessing tokens are available.
7330 2   An identifier __VA_ARGS__ that occurs in the replacement list shall be treated as if it
7331     were a parameter, and the variable arguments shall form the preprocessing tokens used to
7332     replace it.
7333     6.10.3.2 The # operator
7334     Constraints
7335 1   Each # preprocessing token in the replacement list for a function-like macro shall be
7336     followed by a parameter as the next preprocessing token in the replacement list.
7337     Semantics
7338 2   If, in the replacement list, a parameter is immediately preceded by a # preprocessing
7339     token, both are replaced by a single character string literal preprocessing token that
7340     contains the spelling of the preprocessing token sequence for the corresponding
7341     argument. Each occurrence of white space between the argument's preprocessing tokens
7342     becomes a single space character in the character string literal. White space before the
7343     first preprocessing token and after the last preprocessing token composing the argument
7344     is deleted. Otherwise, the original spelling of each preprocessing token in the argument
7345     is retained in the character string literal, except for special handling for producing the
7346     spelling of string literals and character constants: a \ character is inserted before each "
7347     and \ character of a character constant or string literal (including the delimiting "
7348     characters), except that it is implementation-defined whether a \ character is inserted
7349     before the \ character beginning a universal character name. If the replacement that
7350     results is not a valid character string literal, the behavior is undefined. The character
7351     string literal corresponding to an empty argument is "". The order of evaluation of # and
7352     ## operators is unspecified.
7353
7354
7355
7356
7357 [page 166]
7358
7359     6.10.3.3 The ## operator
7360     Constraints
7361 1   A ## preprocessing token shall not occur at the beginning or at the end of a replacement
7362     list for either form of macro definition.
7363     Semantics
7364 2   If, in the replacement list of a function-like macro, a parameter is immediately preceded
7365     or followed by a ## preprocessing token, the parameter is replaced by the corresponding
7366     argument's preprocessing token sequence; however, if an argument consists of no
7367     preprocessing tokens, the parameter is replaced by a placemarker preprocessing token
7368     instead.171)
7369 3   For both object-like and function-like macro invocations, before the replacement list is
7370     reexamined for more macro names to replace, each instance of a ## preprocessing token
7371     in the replacement list (not from an argument) is deleted and the preceding preprocessing
7372     token is concatenated with the following preprocessing token. Placemarker
7373     preprocessing tokens are handled specially: concatenation of two placemarkers results in
7374     a single placemarker preprocessing token, and concatenation of a placemarker with a
7375     non-placemarker preprocessing token results in the non-placemarker preprocessing token.
7376     If the result is not a valid preprocessing token, the behavior is undefined. The resulting
7377     token is available for further macro replacement. The order of evaluation of ## operators
7378     is unspecified.
7379 4   EXAMPLE       In the following fragment:
7380             #define     hash_hash # ## #
7381             #define     mkstr(a) # a
7382             #define     in_between(a) mkstr(a)
7383             #define     join(c, d) in_between(c hash_hash d)
7384             char p[] = join(x, y); // equivalent to
7385                                    // char p[] = "x ## y";
7386     The expansion produces, at various stages:
7387             join(x, y)
7388             in_between(x hash_hash y)
7389             in_between(x ## y)
7390             mkstr(x ## y)
7391             "x ## y"
7392     In other words, expanding hash_hash produces a new token, consisting of two adjacent sharp signs, but
7393     this new token is not the ## operator.
7394
7395
7396     171) Placemarker preprocessing tokens do not appear in the syntax because they are temporary entities that
7397          exist only within translation phase 4.
7398
7399 [page 167]
7400
7401     6.10.3.4 Rescanning and further replacement
7402 1   After all parameters in the replacement list have been substituted and # and ##
7403     processing has taken place, all placemarker preprocessing tokens are removed. The
7404     resulting preprocessing token sequence is then rescanned, along with all subsequent
7405     preprocessing tokens of the source file, for more macro names to replace.
7406 2   If the name of the macro being replaced is found during this scan of the replacement list
7407     (not including the rest of the source file's preprocessing tokens), it is not replaced.
7408     Furthermore, if any nested replacements encounter the name of the macro being replaced,
7409     it is not replaced. These nonreplaced macro name preprocessing tokens are no longer
7410     available for further replacement even if they are later (re)examined in contexts in which
7411     that macro name preprocessing token would otherwise have been replaced.
7412 3   The resulting completely macro-replaced preprocessing token sequence is not processed
7413     as a preprocessing directive even if it resembles one, but all pragma unary operator
7414     expressions within it are then processed as specified in 6.10.9 below.
7415     6.10.3.5 Scope of macro definitions
7416 1   A macro definition lasts (independent of block structure) until a corresponding #undef
7417     directive is encountered or (if none is encountered) until the end of the preprocessing
7418     translation unit. Macro definitions have no significance after translation phase 4.
7419 2   A preprocessing directive of the form
7420        # undef identifier new-line
7421     causes the specified identifier no longer to be defined as a macro name. It is ignored if
7422     the specified identifier is not currently defined as a macro name.
7423 3   EXAMPLE 1      The simplest use of this facility is to define a ''manifest constant'', as in
7424             #define TABSIZE 100
7425             int table[TABSIZE];
7426
7427 4   EXAMPLE 2 The following defines a function-like macro whose value is the maximum of its arguments.
7428     It has the advantages of working for any compatible types of the arguments and of generating in-line code
7429     without the overhead of function calling. It has the disadvantages of evaluating one or the other of its
7430     arguments a second time (including side effects) and generating more code than a function if invoked
7431     several times. It also cannot have its address taken, as it has none.
7432             #define max(a, b) ((a) > (b) ? (a) : (b))
7433     The parentheses ensure that the arguments and the resulting expression are bound properly.
7434
7435
7436
7437
7438 [page 168]
7439
7440 5   EXAMPLE 3     To illustrate the rules for redefinition and reexamination, the sequence
7441              #define   x         3
7442              #define   f(a)      f(x * (a))
7443              #undef    x
7444              #define   x         2
7445              #define   g         f
7446              #define   z         z[0]
7447              #define   h         g(~
7448              #define   m(a)      a(w)
7449              #define   w         0,1
7450              #define   t(a)      a
7451              #define   p()       int
7452              #define   q(x)      x
7453              #define   r(x,y)    x ## y
7454              #define   str(x)    # x
7455              f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
7456              g(x+(3,4)-w) | h 5) & m
7457                    (f)^m(m);
7458              p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
7459              char c[2][6] = { str(hello), str() };
7460     results in
7461              f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
7462              f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
7463              int i[] = { 1, 23, 4, 5, };
7464              char c[2][6] = { "hello", "" };
7465
7466 6   EXAMPLE 4     To illustrate the rules for creating character string literals and concatenating tokens, the
7467     sequence
7468              #define str(s)      # s
7469              #define xstr(s)     str(s)
7470              #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \
7471                                      x ## s, x ## t)
7472              #define INCFILE(n) vers ## n
7473              #define glue(a, b) a ## b
7474              #define xglue(a, b) glue(a, b)
7475              #define HIGHLOW     "hello"
7476              #define LOW         LOW ", world"
7477              debug(1, 2);
7478              fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away
7479                    == 0) str(: @\n), s);
7480              #include xstr(INCFILE(2).h)
7481              glue(HIGH, LOW);
7482              xglue(HIGH, LOW)
7483     results in
7484
7485
7486
7487
7488 [page 169]
7489
7490              printf("x" "1" "= %d, x" "2" "= %s", x1, x2);
7491              fputs(
7492                "strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n",
7493                s);
7494              #include "vers2.h"    (after macro replacement, before file access)
7495              "hello";
7496              "hello" ", world"
7497     or, after concatenation of the character string literals,
7498              printf("x1= %d, x2= %s", x1, x2);
7499              fputs(
7500                "strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: @\n",
7501                s);
7502              #include "vers2.h"    (after macro replacement, before file access)
7503              "hello";
7504              "hello, world"
7505     Space around the # and ## tokens in the macro definition is optional.
7506
7507 7   EXAMPLE 5        To illustrate the rules for placemarker preprocessing tokens, the sequence
7508              #define t(x,y,z) x ## y ## z
7509              int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
7510                         t(10,,), t(,11,), t(,,12), t(,,) };
7511     results in
7512              int j[] = { 123, 45, 67, 89,
7513                          10, 11, 12, };
7514
7515 8   EXAMPLE 6        To demonstrate the redefinition rules, the following sequence is valid.
7516              #define      OBJ_LIKE      (1-1)
7517              #define      OBJ_LIKE      /* white space */ (1-1) /* other */
7518              #define      FUNC_LIKE(a)   ( a )
7519              #define      FUNC_LIKE( a )( /* note the white space */ \
7520                                           a /* other stuff on this line
7521                                               */ )
7522     But the following redefinitions are invalid:
7523              #define      OBJ_LIKE    (0)     // different token sequence
7524              #define      OBJ_LIKE    (1 - 1) // different white space
7525              #define      FUNC_LIKE(b) ( a ) // different parameter usage
7526              #define      FUNC_LIKE(b) ( b ) // different parameter spelling
7527
7528 9   EXAMPLE 7        Finally, to show the variable argument list macro facilities:
7529              #define debug(...)       fprintf(stderr, __VA_ARGS__)
7530              #define showlist(...)    puts(#__VA_ARGS__)
7531              #define report(test, ...) ((test)?puts(#test):\
7532                          printf(__VA_ARGS__))
7533              debug("Flag");
7534              debug("X = %d\n", x);
7535              showlist(The first, second, and third items.);
7536              report(x>y, "x is %d but y is %d", x, y);
7537
7538
7539 [page 170]
7540
7541     results in
7542               fprintf(stderr, "Flag" );
7543               fprintf(stderr, "X = %d\n", x );
7544               puts( "The first, second, and third items." );
7545               ((x>y)?puts("x>y"):
7546                           printf("x is %d but y is %d", x, y));
7547
7548     6.10.4 Line control
7549     Constraints
7550 1   The string literal of a #line directive, if present, shall be a character string literal.
7551     Semantics
7552 2   The line number of the current source line is one greater than the number of new-line
7553     characters read or introduced in translation phase 1 (5.1.1.2) while processing the source
7554     file to the current token.
7555 3   A preprocessing directive of the form
7556        # line digit-sequence new-line
7557     causes the implementation to behave as if the following sequence of source lines begins
7558     with a source line that has a line number as specified by the digit sequence (interpreted as
7559     a decimal integer). The digit sequence shall not specify zero, nor a number greater than
7560     2147483647.
7561 4   A preprocessing directive of the form
7562        # line digit-sequence "s-char-sequenceopt" new-line
7563     sets the presumed line number similarly and changes the presumed name of the source
7564     file to be the contents of the character string literal.
7565 5   A preprocessing directive of the form
7566        # line pp-tokens new-line
7567     (that does not match one of the two previous forms) is permitted. The preprocessing
7568     tokens after line on the directive are processed just as in normal text (each identifier
7569     currently defined as a macro name is replaced by its replacement list of preprocessing
7570     tokens). The directive resulting after all replacements shall match one of the two
7571     previous forms and is then processed as appropriate.
7572
7573
7574
7575
7576 [page 171]
7577
7578     6.10.5 Error directive
7579     Semantics
7580 1   A preprocessing directive of the form
7581        # error pp-tokensopt new-line
7582     causes the implementation to produce a diagnostic message that includes the specified
7583     sequence of preprocessing tokens.
7584     6.10.6 Pragma directive
7585     Semantics
7586 1   A preprocessing directive of the form
7587        # pragma pp-tokensopt new-line
7588     where the preprocessing token STDC does not immediately follow pragma in the
7589     directive (prior to any macro replacement)172) causes the implementation to behave in an
7590     implementation-defined manner. The behavior might cause translation to fail or cause the
7591     translator or the resulting program to behave in a non-conforming manner. Any such
7592     pragma that is not recognized by the implementation is ignored.
7593 2   If the preprocessing token STDC does immediately follow pragma in the directive (prior
7594     to any macro replacement), then no macro replacement is performed on the directive, and
7595     the directive shall have one of the following forms173) whose meanings are described
7596     elsewhere:
7597        #pragma STDC FP_CONTRACT on-off-switch
7598        #pragma STDC FENV_ACCESS on-off-switch
7599        #pragma STDC CX_LIMITED_RANGE on-off-switch
7600        on-off-switch: one of
7601                    ON     OFF           DEFAULT
7602     Forward references: the FP_CONTRACT pragma (7.12.2), the FENV_ACCESS pragma
7603     (7.6.1), the CX_LIMITED_RANGE pragma (7.3.4).
7604
7605
7606
7607
7608     172) An implementation is not required to perform macro replacement in pragmas, but it is permitted
7609          except for in standard pragmas (where STDC immediately follows pragma). If the result of macro
7610          replacement in a non-standard pragma has the same form as a standard pragma, the behavior is still
7611          implementation-defined; an implementation is permitted to behave as if it were the standard pragma,
7612          but is not required to.
7613     173) See ''future language directions'' (6.11.8).
7614
7615 [page 172]
7616
7617     6.10.7 Null directive
7618     Semantics
7619 1   A preprocessing directive of the form
7620        # new-line
7621     has no effect.
7622     6.10.8 Predefined macro names
7623 1   The values of the predefined macros listed in the following subclauses174) (except for
7624     __FILE__ and __LINE__) remain constant throughout the translation unit.
7625 2   None of these macro names, nor the identifier defined, shall be the subject of a
7626     #define or a #undef preprocessing directive. Any other predefined macro names
7627     shall begin with a leading underscore followed by an uppercase letter or a second
7628     underscore.
7629 3   The implementation shall not predefine the macro __cplusplus, nor shall it define it
7630     in any standard header.
7631     Forward references: standard headers (7.1.2).
7632     6.10.8.1 Mandatory macros
7633 1   The following macro names shall be defined by the implementation:
7634     __DATE__ The date of translation of the preprocessing translation unit: a character
7635                string literal of the form "Mmm dd yyyy", where the names of the
7636                months are the same as those generated by the asctime function, and the
7637                first character of dd is a space character if the value is less than 10. If the
7638                date of translation is not available, an implementation-defined valid date
7639                shall be supplied.
7640     __FILE__ The presumed name of the current source file (a character string literal).175)
7641     __LINE__ The presumed line number (within the current source file) of the current
7642                source line (an integer constant).175)
7643     __STDC__ The integer constant 1, intended to indicate a conforming implementation.
7644     __STDC_HOSTED__ The integer constant 1 if the implementation is a hosted
7645               implementation or the integer constant 0 if it is not.
7646
7647
7648
7649
7650     174) See ''future language directions'' (6.11.9).
7651     175) The presumed source file name and line number can be changed by the #line directive.
7652
7653 [page 173]
7654
7655     __STDC_VERSION__ The integer constant 201ymmL.176)
7656     __TIME__ The time of translation of the preprocessing translation unit: a character
7657                string literal of the form "hh:mm:ss" as in the time generated by the
7658                asctime function. If the time of translation is not available, an
7659                implementation-defined valid time shall be supplied.
7660     Forward references: the asctime function (7.26.3.1).
7661     6.10.8.2 Environment macros
7662 1   The following macro names are conditionally defined by the implementation:
7663     __STDC_ISO_10646__ An integer constant of the form yyyymmL (for example,
7664               199712L). If this symbol is defined, then every character in the Unicode
7665               required set, when stored in an object of type wchar_t, has the same
7666               value as the short identifier of that character. The Unicode required set
7667               consists of all the characters that are defined by ISO/IEC 10646, along with
7668               all amendments and technical corrigenda, as of the specified year and
7669               month. If some other encoding is used, the macro shall not be defined and
7670               the actual encoding used is implementation-defined.
7671     __STDC_MB_MIGHT_NEQ_WC__ The integer constant 1, intended to indicate that, in
7672               the encoding for wchar_t, a member of the basic character set need not
7673               have a code value equal to its value when used as the lone character in an
7674               integer character constant.
7675     __STDC_UTF_16__ The integer constant 1, intended to indicate that values of type
7676               char16_t are UTF-16 encoded. If some other encoding is used, the
7677               macro shall not be defined and the actual encoding used is implementation-
7678               defined.
7679     __STDC_UTF_32__ The integer constant 1, intended to indicate that values of type
7680               char32_t are UTF-32 encoded. If some other encoding is used, the
7681               macro shall not be defined and the actual encoding used is implementation-
7682               defined.
7683     Forward references: common definitions (7.19), unicode utilities (7.27).
7684
7685
7686
7687
7688     176) This macro was not specified in ISO/IEC 9899:1990 and was specified as 199409L in
7689          ISO/IEC 9899/AMD1:1995 and as 199901L in ISO/IEC 9899:1999. The intention is that this will
7690          remain an integer constant of type long int that is increased with each revision of this International
7691          Standard.
7692
7693 [page 174]
7694
7695     6.10.8.3 Conditional feature macros
7696 1   The following macro names are conditionally defined by the implementation:
7697     __STDC_ANALYZABLE__ The integer constant 1, intended to indicate conformance to
7698               the specifications in annex L (Analyzability).
7699     __STDC_IEC_559__ The integer constant 1, intended to indicate conformance to the
7700               specifications in annex F (IEC 60559 floating-point arithmetic).
7701     __STDC_IEC_559_COMPLEX__ The integer constant 1, intended to indicate
7702               adherence to the specifications in informative annex G (IEC 60559
7703               compatible complex arithmetic).
7704     __STDC_LIB_EXT1__ The integer constant 201ymmL, intended to indicate support
7705               for the extensions defined in annex K (Bounds-checking interfaces).177)
7706     __STDC_NO_COMPLEX__ The integer constant 1, intended to indicate that the
7707               implementation does not support complex types or the <complex.h>
7708               header.
7709     __STDC_NO_THREADS__ The integer constant 1, intended to indicate that the
7710               implementation does not support atomic types (including the _Atomic
7711               type qualifier and the <stdatomic.h> header) or the <threads.h>
7712               header.
7713     __STDC_NO_VLA__ The integer constant 1, intended to indicate that the
7714               implementation does not support variable length arrays or variably
7715               modified types.
7716     6.10.9 Pragma operator
7717     Semantics
7718 1   A unary operator expression of the form:
7719        _Pragma ( string-literal )
7720     is processed as follows: The string literal is destringized by deleting the L prefix, if
7721     present, deleting the leading and trailing double-quotes, replacing each escape sequence
7722     \" by a double-quote, and replacing each escape sequence \\ by a single backslash. The
7723     resulting sequence of characters is processed through translation phase 3 to produce
7724     preprocessing tokens that are executed as if they were the pp-tokens in a pragma
7725     directive. The original four preprocessing tokens in the unary operator expression are
7726     removed.
7727
7728
7729     177) The intention is that this will remain an integer constant of type long int that is increased with
7730          each revision of this International Standard.
7731
7732 [page 175]
7733
7734 2   EXAMPLE       A directive of the form:
7735              #pragma listing on "..\listing.dir"
7736     can also be expressed as:
7737              _Pragma ( "listing on \"..\\listing.dir\"" )
7738     The latter form is processed in the same way whether it appears literally as shown, or results from macro
7739     replacement, as in:
7740              #define LISTING(x) PRAGMA(listing on #x)
7741              #define PRAGMA(x) _Pragma(#x)
7742              LISTING ( ..\listing.dir )
7743
7744
7745
7746
7747 [page 176]
7748
7749     6.11 Future language directions
7750     6.11.1 Floating types
7751 1   Future standardization may include additional floating-point types, including those with
7752     greater range, precision, or both than long double.
7753     6.11.2 Linkages of identifiers
7754 1   Declaring an identifier with internal linkage at file scope without the static storage-
7755     class specifier is an obsolescent feature.
7756     6.11.3 External names
7757 1   Restriction of the significance of an external name to fewer than 255 characters
7758     (considering each universal character name or extended source character as a single
7759     character) is an obsolescent feature that is a concession to existing implementations.
7760     6.11.4 Character escape sequences
7761 1   Lowercase letters as escape sequences are reserved for future standardization. Other
7762     characters may be used in extensions.
7763     6.11.5 Storage-class specifiers
7764 1   The placement of a storage-class specifier other than at the beginning of the declaration
7765     specifiers in a declaration is an obsolescent feature.
7766     6.11.6 Function declarators
7767 1   The use of function declarators with empty parentheses (not prototype-format parameter
7768     type declarators) is an obsolescent feature.
7769     6.11.7 Function definitions
7770 1   The use of function definitions with separate parameter identifier and declaration lists
7771     (not prototype-format parameter type and identifier declarators) is an obsolescent feature.
7772     6.11.8 Pragma directives
7773 1   Pragmas whose first preprocessing token is STDC are reserved for future standardization.
7774     6.11.9 Predefined macro names
7775 1   Macro names beginning with __STDC_ are reserved for future standardization.
7776
7777
7778
7779
7780 [page 177]
7781
7782
7783     7. Library
7784     7.1 Introduction
7785     7.1.1 Definitions of terms
7786 1   A string is a contiguous sequence of characters terminated by and including the first null
7787     character. The term multibyte string is sometimes used instead to emphasize special
7788     processing given to multibyte characters contained in the string or to avoid confusion
7789     with a wide string. A pointer to a string is a pointer to its initial (lowest addressed)
7790     character. The length of a string is the number of bytes preceding the null character and
7791     the value of a string is the sequence of the values of the contained characters, in order.
7792 2   The decimal-point character is the character used by functions that convert floating-point
7793     numbers to or from character sequences to denote the beginning of the fractional part of
7794     such character sequences.178) It is represented in the text and examples by a period, but
7795     may be changed by the setlocale function.
7796 3   A null wide character is a wide character with code value zero.
7797 4   A wide string is a contiguous sequence of wide characters terminated by and including
7798     the first null wide character. A pointer to a wide string is a pointer to its initial (lowest
7799     addressed) wide character. The length of a wide string is the number of wide characters
7800     preceding the null wide character and the value of a wide string is the sequence of code
7801     values of the contained wide characters, in order.
7802 5   A shift sequence is a contiguous sequence of bytes within a multibyte string that
7803     (potentially) causes a change in shift state (see 5.2.1.2). A shift sequence shall not have a
7804     corresponding wide character; it is instead taken to be an adjunct to an adjacent multibyte
7805     character.179)
7806     Forward references: character handling (7.4), the setlocale function (7.11.1.1).
7807
7808
7809
7810
7811     178) The functions that make use of the decimal-point character are the numeric conversion functions
7812          (7.22.1, 7.28.4.1) and the formatted input/output functions (7.21.6, 7.28.2).
7813     179) For state-dependent encodings, the values for MB_CUR_MAX and MB_LEN_MAX shall thus be large
7814          enough to count all the bytes in any complete multibyte character plus at least one adjacent shift
7815          sequence of maximum length. Whether these counts provide for more than one shift sequence is the
7816          implementation's choice.
7817
7818 [page 178]
7819
7820     7.1.2 Standard headers
7821 1   Each library function is declared, with a type that includes a prototype, in a header,180)
7822     whose contents are made available by the #include preprocessing directive. The
7823     header declares a set of related functions, plus any necessary types and additional macros
7824     needed to facilitate their use. Declarations of types described in this clause shall not
7825     include type qualifiers, unless explicitly stated otherwise.
7826 2   The standard headers are181)
7827            <assert.h>             <iso646.h>              <stdarg.h>              <string.h>
7828            <complex.h>            <limits.h>              <stdatomic.h>           <tgmath.h>
7829            <ctype.h>              <locale.h>              <stdbool.h>             <threads.h>
7830            <errno.h>              <math.h>                <stddef.h>              <time.h>
7831            <fenv.h>               <setjmp.h>              <stdint.h>              <uchar.h>
7832            <float.h>              <signal.h>              <stdio.h>               <wchar.h>
7833            <inttypes.h>           <stdalign.h>            <stdlib.h>              <wctype.h>
7834 3   If a file with the same name as one of the above < and > delimited sequences, not
7835     provided as part of the implementation, is placed in any of the standard places that are
7836     searched for included source files, the behavior is undefined.
7837 4   Standard headers may be included in any order; each may be included more than once in
7838     a given scope, with no effect different from being included only once, except that the
7839     effect of including <assert.h> depends on the definition of NDEBUG (see 7.2). If
7840     used, a header shall be included outside of any external declaration or definition, and it
7841     shall first be included before the first reference to any of the functions or objects it
7842     declares, or to any of the types or macros it defines. However, if an identifier is declared
7843     or defined in more than one header, the second and subsequent associated headers may be
7844     included after the initial reference to the identifier. The program shall not have any
7845     macros with names lexically identical to keywords currently defined prior to the
7846     inclusion.
7847 5   Any definition of an object-like macro described in this clause shall expand to code that is
7848     fully protected by parentheses where necessary, so that it groups in an arbitrary
7849     expression as if it were a single identifier.
7850 6   Any declaration of a library function shall have external linkage.
7851
7852
7853
7854
7855     180) A header is not necessarily a source file, nor are the < and > delimited sequences in header names
7856          necessarily valid source file names.
7857     181) The headers <complex.h>, <stdatomic.h>, and <threads.h> are conditional features that
7858          implementations need not support; see 6.10.8.3.
7859
7860 [page 179]
7861
7862 7   A summary of the contents of the standard headers is given in annex B.
7863     Forward references: diagnostics (7.2).
7864     7.1.3 Reserved identifiers
7865 1   Each header declares or defines all identifiers listed in its associated subclause, and
7866     optionally declares or defines identifiers listed in its associated future library directions
7867     subclause and identifiers which are always reserved either for any use or for use as file
7868     scope identifiers.
7869     -- All identifiers that begin with an underscore and either an uppercase letter or another
7870       underscore are always reserved for any use.
7871     -- All identifiers that begin with an underscore are always reserved for use as identifiers
7872       with file scope in both the ordinary and tag name spaces.
7873     -- Each macro name in any of the following subclauses (including the future library
7874       directions) is reserved for use as specified if any of its associated headers is included;
7875       unless explicitly stated otherwise (see 7.1.4).
7876     -- All identifiers with external linkage in any of the following subclauses (including the
7877       future library directions) and errno are always reserved for use as identifiers with
7878       external linkage.182)
7879     -- Each identifier with file scope listed in any of the following subclauses (including the
7880       future library directions) is reserved for use as a macro name and as an identifier with
7881       file scope in the same name space if any of its associated headers is included.
7882 2   No other identifiers are reserved. If the program declares or defines an identifier in a
7883     context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved
7884     identifier as a macro name, the behavior is undefined.
7885 3   If the program removes (with #undef) any macro definition of an identifier in the first
7886     group listed above, the behavior is undefined.
7887
7888
7889
7890
7891     182) The list of reserved identifiers with external linkage includes math_errhandling, setjmp,
7892          va_copy, and va_end.
7893
7894 [page 180]
7895
7896     7.1.4 Use of library functions
7897 1   Each of the following statements applies unless explicitly stated otherwise in the detailed
7898     descriptions that follow: If an argument to a function has an invalid value (such as a value
7899     outside the domain of the function, or a pointer outside the address space of the program,
7900     or a null pointer, or a pointer to non-modifiable storage when the corresponding
7901     parameter is not const-qualified) or a type (after promotion) not expected by a function
7902     with variable number of arguments, the behavior is undefined. If a function argument is
7903     described as being an array, the pointer actually passed to the function shall have a value
7904     such that all address computations and accesses to objects (that would be valid if the
7905     pointer did point to the first element of such an array) are in fact valid. Any function
7906     declared in a header may be additionally implemented as a function-like macro defined in
7907     the header, so if a library function is declared explicitly when its header is included, one
7908     of the techniques shown below can be used to ensure the declaration is not affected by
7909     such a macro. Any macro definition of a function can be suppressed locally by enclosing
7910     the name of the function in parentheses, because the name is then not followed by the left
7911     parenthesis that indicates expansion of a macro function name. For the same syntactic
7912     reason, it is permitted to take the address of a library function even if it is also defined as
7913     a macro.183) The use of #undef to remove any macro definition will also ensure that an
7914     actual function is referred to. Any invocation of a library function that is implemented as
7915     a macro shall expand to code that evaluates each of its arguments exactly once, fully
7916     protected by parentheses where necessary, so it is generally safe to use arbitrary
7917     expressions as arguments.184) Likewise, those function-like macros described in the
7918     following subclauses may be invoked in an expression anywhere a function with a
7919     compatible return type could be called.185) All object-like macros listed as expanding to
7920
7921
7922     183) This means that an implementation shall provide an actual function for each library function, even if it
7923          also provides a macro for that function.
7924     184) Such macros might not contain the sequence points that the corresponding function calls do.
7925     185) Because external identifiers and some macro names beginning with an underscore are reserved,
7926          implementations may provide special semantics for such names. For example, the identifier
7927          _BUILTIN_abs could be used to indicate generation of in-line code for the abs function. Thus, the
7928          appropriate header could specify
7929                   #define abs(x) _BUILTIN_abs(x)
7930          for a compiler whose code generator will accept it.
7931          In this manner, a user desiring to guarantee that a given library function such as abs will be a genuine
7932          function may write
7933                   #undef abs
7934          whether the implementation's header provides a macro implementation of abs or a built-in
7935          implementation. The prototype for the function, which precedes and is hidden by any macro
7936          definition, is thereby revealed also.
7937
7938 [page 181]
7939
7940     integer constant expressions shall additionally be suitable for use in #if preprocessing
7941     directives.
7942 2   Provided that a library function can be declared without reference to any type defined in a
7943     header, it is also permissible to declare the function and use it without including its
7944     associated header.
7945 3   There is a sequence point immediately before a library function returns.
7946 4   The functions in the standard library are not guaranteed to be reentrant and may modify
7947     objects with static or thread storage duration.186)
7948 5   Unless explicitly stated otherwise in the detailed descriptions that follow, library
7949     functions shall prevent data races as follows: A library function shall not directly or
7950     indirectly access objects accessible by threads other than the current thread unless the
7951     objects are accessed directly or indirectly via the function's arguments. A library
7952     function shall not directly or indirectly modify objects accessible by threads other than
7953     the current thread unless the objects are accessed directly or indirectly via the function's
7954     non-const arguments.187) Implementations may share their own internal objects between
7955     threads if the objects are not visible to users and are protected against data races.
7956 6   Unless otherwise specified, library functions shall perform all operations solely within the
7957     current thread if those operations have effects that are visible to users.188)
7958 7   EXAMPLE        The function atoi may be used in any of several ways:
7959     -- by use of its associated header (possibly generating a macro expansion)
7960                  #include <stdlib.h>
7961                  const char *str;
7962                  /* ... */
7963                  i = atoi(str);
7964     -- by use of its associated header (assuredly generating a true function reference)
7965
7966
7967
7968
7969     186) Thus, a signal handler cannot, in general, call standard library functions.
7970     187) This means, for example, that an implementation is not permitted to use a static object for internal
7971          purposes without synchronization because it could cause a data race even in programs that do not
7972          explicitly share objects between threads.
7973     188) This allows implementations to parallelize operations if there are no visible side effects.
7974
7975 [page 182]
7976
7977             #include <stdlib.h>
7978             #undef atoi
7979             const char *str;
7980             /* ... */
7981             i = atoi(str);
7982    or
7983             #include <stdlib.h>
7984             const char *str;
7985             /* ... */
7986             i = (atoi)(str);
7987 -- by explicit declaration
7988             extern int atoi(const char *);
7989             const char *str;
7990             /* ... */
7991             i = atoi(str);
7992
7993
7994
7995
7996 [page 183]
7997
7998     7.2 Diagnostics <assert.h>
7999 1   The header <assert.h> defines the assert and static_assert macros and
8000     refers to another macro,
8001             NDEBUG
8002     which is not defined by <assert.h>. If NDEBUG is defined as a macro name at the
8003     point in the source file where <assert.h> is included, the assert macro is defined
8004     simply as
8005             #define assert(ignore) ((void)0)
8006     The assert macro is redefined according to the current state of NDEBUG each time that
8007     <assert.h> is included.
8008 2   The assert macro shall be implemented as a macro, not as an actual function. If the
8009     macro definition is suppressed in order to access an actual function, the behavior is
8010     undefined.
8011 3   The macro
8012             static_assert
8013     expands to _Static_assert.
8014     7.2.1 Program diagnostics
8015     7.2.1.1 The assert macro
8016     Synopsis
8017 1           #include <assert.h>
8018             void assert(scalar expression);
8019     Description
8020 2   The assert macro puts diagnostic tests into programs; it expands to a void expression.
8021     When it is executed, if expression (which shall have a scalar type) is false (that is,
8022     compares equal to 0), the assert macro writes information about the particular call that
8023     failed (including the text of the argument, the name of the source file, the source line
8024     number, and the name of the enclosing function -- the latter are respectively the values of
8025     the preprocessing macros __FILE__ and __LINE__ and of the identifier
8026     __func__) on the standard error stream in an implementation-defined format.189) It
8027     then calls the abort function.
8028
8029
8030
8031     189) The message written might be of the form:
8032           Assertion failed: expression, function abc, file xyz, line nnn.
8033
8034
8035 [page 184]
8036
8037     Returns
8038 3   The assert macro returns no value.
8039     Forward references: the abort function (7.22.4.1).
8040
8041
8042
8043
8044 [page 185]
8045
8046     7.3 Complex arithmetic <complex.h>
8047     7.3.1 Introduction
8048 1   The header <complex.h> defines macros and declares functions that support complex
8049     arithmetic.190)
8050 2   Implementations that define the macro __STDC_NO_COMPLEX__ need not provide
8051     this header nor support any of its facilities.
8052 3   Each synopsis specifies a family of functions consisting of a principal function with one
8053     or more double complex parameters and a double complex or double return
8054     value; and other functions with the same name but with f and l suffixes which are
8055     corresponding functions with float and long double parameters and return values.
8056 4   The macro
8057              complex
8058     expands to _Complex; the macro
8059              _Complex_I
8060     expands to a constant expression of type const float _Complex, with the value of
8061     the imaginary unit.191)
8062 5   The macros
8063              imaginary
8064     and
8065              _Imaginary_I
8066     are defined if and only if the implementation supports imaginary types;192) if defined,
8067     they expand to _Imaginary and a constant expression of type const float
8068     _Imaginary with the value of the imaginary unit.
8069 6   The macro
8070              I
8071     expands to either _Imaginary_I or _Complex_I. If _Imaginary_I is not
8072     defined, I shall expand to _Complex_I.
8073 7   Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then
8074     redefine the macros complex, imaginary, and I.
8075
8076     190) See ''future library directions'' (7.30.1).
8077     191) The imaginary unit is a number i such that i 2 = -1.
8078     192) A specification for imaginary types is in informative annex G.
8079
8080 [page 186]
8081
8082     Forward references: IEC 60559-compatible complex arithmetic (annex G).
8083     7.3.2 Conventions
8084 1   Values are interpreted as radians, not degrees. An implementation may set errno but is
8085     not required to.
8086     7.3.3 Branch cuts
8087 1   Some of the functions below have branch cuts, across which the function is
8088     discontinuous. For implementations with a signed zero (including all IEC 60559
8089     implementations) that follow the specifications of annex G, the sign of zero distinguishes
8090     one side of a cut from another so the function is continuous (except for format
8091     limitations) as the cut is approached from either side. For example, for the square root
8092     function, which has a branch cut along the negative real axis, the top of the cut, with
8093     imaginary part +0, maps to the positive imaginary axis, and the bottom of the cut, with
8094     imaginary part -0, maps to the negative imaginary axis.
8095 2   Implementations that do not support a signed zero (see annex F) cannot distinguish the
8096     sides of branch cuts. These implementations shall map a cut so the function is continuous
8097     as the cut is approached coming around the finite endpoint of the cut in a counter
8098     clockwise direction. (Branch cuts for the functions specified here have just one finite
8099     endpoint.) For example, for the square root function, coming counter clockwise around
8100     the finite endpoint of the cut along the negative real axis approaches the cut from above,
8101     so the cut maps to the positive imaginary axis.
8102     7.3.4 The CX_LIMITED_RANGE pragma
8103     Synopsis
8104 1            #include <complex.h>
8105              #pragma STDC CX_LIMITED_RANGE on-off-switch
8106     Description
8107 2   The usual mathematical formulas for complex multiply, divide, and absolute value are
8108     problematic because of their treatment of infinities and because of undue overflow and
8109     underflow. The CX_LIMITED_RANGE pragma can be used to inform the
8110     implementation that (where the state is ''on'') the usual mathematical formulas are
8111     acceptable.193) The pragma can occur either outside external declarations or preceding all
8112     explicit declarations and statements inside a compound statement. When outside external
8113     declarations, the pragma takes effect from its occurrence until another
8114     CX_LIMITED_RANGE pragma is encountered, or until the end of the translation unit.
8115     When inside a compound statement, the pragma takes effect from its occurrence until
8116     another CX_LIMITED_RANGE pragma is encountered (including within a nested
8117     compound statement), or until the end of the compound statement; at the end of a
8118     compound statement the state for the pragma is restored to its condition just before the
8119
8120 [page 187]
8121
8122     compound statement. If this pragma is used in any other context, the behavior is
8123     undefined. The default state for the pragma is ''off''.
8124     7.3.5 Trigonometric functions
8125     7.3.5.1 The cacos functions
8126     Synopsis
8127 1            #include <complex.h>
8128              double complex cacos(double complex z);
8129              float complex cacosf(float complex z);
8130              long double complex cacosl(long double complex z);
8131     Description
8132 2   The cacos functions compute the complex arc cosine of z, with branch cuts outside the
8133     interval [-1, +1] along the real axis.
8134     Returns
8135 3   The cacos functions return the complex arc cosine value, in the range of a strip
8136     mathematically unbounded along the imaginary axis and in the interval [0, pi ] along the
8137     real axis.
8138     7.3.5.2 The casin functions
8139     Synopsis
8140 1            #include <complex.h>
8141              double complex casin(double complex z);
8142              float complex casinf(float complex z);
8143              long double complex casinl(long double complex z);
8144     Description
8145 2   The casin functions compute the complex arc sine of z, with branch cuts outside the
8146     interval [-1, +1] along the real axis.
8147     Returns
8148 3   The casin functions return the complex arc sine value, in the range of a strip
8149     mathematically unbounded along the imaginary axis and in the interval [-pi /2, +pi /2]
8150
8151     193) The purpose of the pragma is to allow the implementation to use the formulas:
8152              (x + iy) x (u + iv) = (xu - yv) + i(yu + xv)
8153              (x + iy) / (u + iv) = [(xu + yv) + i(yu - xv)]/(u2 + v 2 )
8154              | x + iy | = sqrt: x 2 + y 2
8155                           -----
8156           where the programmer can determine they are safe.
8157
8158 [page 188]
8159
8160     along the real axis.
8161     7.3.5.3 The catan functions
8162     Synopsis
8163 1           #include <complex.h>
8164             double complex catan(double complex z);
8165             float complex catanf(float complex z);
8166             long double complex catanl(long double complex z);
8167     Description
8168 2   The catan functions compute the complex arc tangent of z, with branch cuts outside the
8169     interval [-i, +i] along the imaginary axis.
8170     Returns
8171 3   The catan functions return the complex arc tangent value, in the range of a strip
8172     mathematically unbounded along the imaginary axis and in the interval [-pi /2, +pi /2]
8173     along the real axis.
8174     7.3.5.4 The ccos functions
8175     Synopsis
8176 1           #include <complex.h>
8177             double complex ccos(double complex z);
8178             float complex ccosf(float complex z);
8179             long double complex ccosl(long double complex z);
8180     Description
8181 2   The ccos functions compute the complex cosine of z.
8182     Returns
8183 3   The ccos functions return the complex cosine value.
8184     7.3.5.5 The csin functions
8185     Synopsis
8186 1           #include <complex.h>
8187             double complex csin(double complex z);
8188             float complex csinf(float complex z);
8189             long double complex csinl(long double complex z);
8190     Description
8191 2   The csin functions compute the complex sine of z.
8192
8193
8194
8195 [page 189]
8196
8197     Returns
8198 3   The csin functions return the complex sine value.
8199     7.3.5.6 The ctan functions
8200     Synopsis
8201 1          #include <complex.h>
8202            double complex ctan(double complex z);
8203            float complex ctanf(float complex z);
8204            long double complex ctanl(long double complex z);
8205     Description
8206 2   The ctan functions compute the complex tangent of z.
8207     Returns
8208 3   The ctan functions return the complex tangent value.
8209     7.3.6 Hyperbolic functions
8210     7.3.6.1 The cacosh functions
8211     Synopsis
8212 1          #include <complex.h>
8213            double complex cacosh(double complex z);
8214            float complex cacoshf(float complex z);
8215            long double complex cacoshl(long double complex z);
8216     Description
8217 2   The cacosh functions compute the complex arc hyperbolic cosine of z, with a branch
8218     cut at values less than 1 along the real axis.
8219     Returns
8220 3   The cacosh functions return the complex arc hyperbolic cosine value, in the range of a
8221     half-strip of non-negative values along the real axis and in the interval [-ipi , +ipi ] along
8222     the imaginary axis.
8223     7.3.6.2 The casinh functions
8224     Synopsis
8225 1          #include <complex.h>
8226            double complex casinh(double complex z);
8227            float complex casinhf(float complex z);
8228            long double complex casinhl(long double complex z);
8229
8230
8231
8232 [page 190]
8233
8234     Description
8235 2   The casinh functions compute the complex arc hyperbolic sine of z, with branch cuts
8236     outside the interval [-i, +i] along the imaginary axis.
8237     Returns
8238 3   The casinh functions return the complex arc hyperbolic sine value, in the range of a
8239     strip mathematically unbounded along the real axis and in the interval [-ipi /2, +ipi /2]
8240     along the imaginary axis.
8241     7.3.6.3 The catanh functions
8242     Synopsis
8243 1           #include <complex.h>
8244             double complex catanh(double complex z);
8245             float complex catanhf(float complex z);
8246             long double complex catanhl(long double complex z);
8247     Description
8248 2   The catanh functions compute the complex arc hyperbolic tangent of z, with branch
8249     cuts outside the interval [-1, +1] along the real axis.
8250     Returns
8251 3   The catanh functions return the complex arc hyperbolic tangent value, in the range of a
8252     strip mathematically unbounded along the real axis and in the interval [-ipi /2, +ipi /2]
8253     along the imaginary axis.
8254     7.3.6.4 The ccosh functions
8255     Synopsis
8256 1           #include <complex.h>
8257             double complex ccosh(double complex z);
8258             float complex ccoshf(float complex z);
8259             long double complex ccoshl(long double complex z);
8260     Description
8261 2   The ccosh functions compute the complex hyperbolic cosine of z.
8262     Returns
8263 3   The ccosh functions return the complex hyperbolic cosine value.
8264
8265
8266
8267
8268 [page 191]
8269
8270     7.3.6.5 The csinh functions
8271     Synopsis
8272 1          #include <complex.h>
8273            double complex csinh(double complex z);
8274            float complex csinhf(float complex z);
8275            long double complex csinhl(long double complex z);
8276     Description
8277 2   The csinh functions compute the complex hyperbolic sine of z.
8278     Returns
8279 3   The csinh functions return the complex hyperbolic sine value.
8280     7.3.6.6 The ctanh functions
8281     Synopsis
8282 1          #include <complex.h>
8283            double complex ctanh(double complex z);
8284            float complex ctanhf(float complex z);
8285            long double complex ctanhl(long double complex z);
8286     Description
8287 2   The ctanh functions compute the complex hyperbolic tangent of z.
8288     Returns
8289 3   The ctanh functions return the complex hyperbolic tangent value.
8290     7.3.7 Exponential and logarithmic functions
8291     7.3.7.1 The cexp functions
8292     Synopsis
8293 1          #include <complex.h>
8294            double complex cexp(double complex z);
8295            float complex cexpf(float complex z);
8296            long double complex cexpl(long double complex z);
8297     Description
8298 2   The cexp functions compute the complex base-e exponential of z.
8299     Returns
8300 3   The cexp functions return the complex base-e exponential value.
8301
8302
8303
8304 [page 192]
8305
8306     7.3.7.2 The clog functions
8307     Synopsis
8308 1           #include <complex.h>
8309             double complex clog(double complex z);
8310             float complex clogf(float complex z);
8311             long double complex clogl(long double complex z);
8312     Description
8313 2   The clog functions compute the complex natural (base-e) logarithm of z, with a branch
8314     cut along the negative real axis.
8315     Returns
8316 3   The clog functions return the complex natural logarithm value, in the range of a strip
8317     mathematically unbounded along the real axis and in the interval [-ipi , +ipi ] along the
8318     imaginary axis.
8319     7.3.8 Power and absolute-value functions
8320     7.3.8.1 The cabs functions
8321     Synopsis
8322 1           #include <complex.h>
8323             double cabs(double complex z);
8324             float cabsf(float complex z);
8325             long double cabsl(long double complex z);
8326     Description
8327 2   The cabs functions compute the complex absolute value (also called norm, modulus, or
8328     magnitude) of z.
8329     Returns
8330 3   The cabs functions return the complex absolute value.
8331     7.3.8.2 The cpow functions
8332     Synopsis
8333 1           #include <complex.h>
8334             double complex cpow(double complex x, double complex y);
8335             float complex cpowf(float complex x, float complex y);
8336             long double complex cpowl(long double complex x,
8337                  long double complex y);
8338
8339
8340
8341
8342 [page 193]
8343
8344     Description
8345 2   The cpow functions compute the complex power function xy , with a branch cut for the
8346     first parameter along the negative real axis.
8347     Returns
8348 3   The cpow functions return the complex power function value.
8349     7.3.8.3 The csqrt functions
8350     Synopsis
8351 1          #include <complex.h>
8352            double complex csqrt(double complex z);
8353            float complex csqrtf(float complex z);
8354            long double complex csqrtl(long double complex z);
8355     Description
8356 2   The csqrt functions compute the complex square root of z, with a branch cut along the
8357     negative real axis.
8358     Returns
8359 3   The csqrt functions return the complex square root value, in the range of the right half-
8360     plane (including the imaginary axis).
8361     7.3.9 Manipulation functions
8362     7.3.9.1 The carg functions
8363     Synopsis
8364 1          #include <complex.h>
8365            double carg(double complex z);
8366            float cargf(float complex z);
8367            long double cargl(long double complex z);
8368     Description
8369 2   The carg functions compute the argument (also called phase angle) of z, with a branch
8370     cut along the negative real axis.
8371     Returns
8372 3   The carg functions return the value of the argument in the interval [-pi , +pi ].
8373
8374
8375
8376
8377 [page 194]
8378
8379     7.3.9.2 The cimag functions
8380     Synopsis
8381 1           #include <complex.h>
8382             double cimag(double complex z);
8383             float cimagf(float complex z);
8384             long double cimagl(long double complex z);
8385     Description
8386 2   The cimag functions compute the imaginary part of z.194)
8387     Returns
8388 3   The cimag functions return the imaginary part value (as a real).
8389     7.3.9.3 The CMPLX macros
8390     Synopsis
8391 1           #include <complex.h>
8392             double complex CMPLX(double x, double y);
8393             float complex CMPLXF(float x, float y);
8394             long double complex CMPLXL(long double x, long double y);
8395     Description
8396 2   The CMPLX macros expand to an expression of the specified complex type, with the real
8397     part having the (converted) value of x and the imaginary part having the (converted)
8398     value of y.
8399     Recommended practice
8400 3   The resulting expression should be suitable for use as an initializer for an object with
8401     static or thread storage duration, provided both arguments are likewise suitable.
8402     Returns
8403 4   The CMPLX macros return the complex value x + i y.
8404 5   NOTE    These macros act as if the implementation supported imaginary types and the definitions were:
8405          #define CMPLX(x, y)  ((double complex)((double)(x) + \
8406                                        _Imaginary_I * (double)(y)))
8407          #define CMPLXF(x, y) ((float complex)((float)(x) + \
8408                                        _Imaginary_I * (float)(y)))
8409          #define CMPLXL(x, y) ((long double complex)((long double)(x) + \
8410                                        _Imaginary_I * (long double)(y)))
8411
8412
8413
8414
8415     194) For a variable z of complex type, z == creal(z) + cimag(z)*I.
8416
8417 [page 195]
8418
8419     7.3.9.4 The conj functions
8420     Synopsis
8421 1          #include <complex.h>
8422            double complex conj(double complex z);
8423            float complex conjf(float complex z);
8424            long double complex conjl(long double complex z);
8425     Description
8426 2   The conj functions compute the complex conjugate of z, by reversing the sign of its
8427     imaginary part.
8428     Returns
8429 3   The conj functions return the complex conjugate value.
8430     7.3.9.5 The cproj functions
8431     Synopsis
8432 1          #include <complex.h>
8433            double complex cproj(double complex z);
8434            float complex cprojf(float complex z);
8435            long double complex cprojl(long double complex z);
8436     Description
8437 2   The cproj functions compute a projection of z onto the Riemann sphere: z projects to
8438     z except that all complex infinities (even those with one infinite part and one NaN part)
8439     project to positive infinity on the real axis. If z has an infinite part, then cproj(z) is
8440     equivalent to
8441            INFINITY + I * copysign(0.0, cimag(z))
8442     Returns
8443 3   The cproj functions return the value of the projection onto the Riemann sphere.
8444     7.3.9.6 The creal functions
8445     Synopsis
8446 1          #include <complex.h>
8447            double creal(double complex z);
8448            float crealf(float complex z);
8449            long double creall(long double complex z);
8450     Description
8451 2   The creal functions compute the real part of z.195)
8452
8453
8454 [page 196]
8455
8456     Returns
8457 3   The creal functions return the real part value.
8458
8459
8460
8461
8462     195) For a variable z of complex type, z == creal(z) + cimag(z)*I.
8463
8464 [page 197]
8465
8466     7.4 Character handling <ctype.h>
8467 1   The header <ctype.h> declares several functions useful for classifying and mapping
8468     characters.196) In all cases the argument is an int, the value of which shall be
8469     representable as an unsigned char or shall equal the value of the macro EOF. If the
8470     argument has any other value, the behavior is undefined.
8471 2   The behavior of these functions is affected by the current locale. Those functions that
8472     have locale-specific aspects only when not in the "C" locale are noted below.
8473 3   The term printing character refers to a member of a locale-specific set of characters, each
8474     of which occupies one printing position on a display device; the term control character
8475     refers to a member of a locale-specific set of characters that are not printing
8476     characters.197) All letters and digits are printing characters.
8477     Forward references: EOF (7.21.1), localization (7.11).
8478     7.4.1 Character classification functions
8479 1   The functions in this subclause return nonzero (true) if and only if the value of the
8480     argument c conforms to that in the description of the function.
8481     7.4.1.1 The isalnum function
8482     Synopsis
8483 1            #include <ctype.h>
8484              int isalnum(int c);
8485     Description
8486 2   The isalnum function tests for any character for which isalpha or isdigit is true.
8487     7.4.1.2 The isalpha function
8488     Synopsis
8489 1            #include <ctype.h>
8490              int isalpha(int c);
8491     Description
8492 2   The isalpha function tests for any character for which isupper or islower is true,
8493     or any character that is one of a locale-specific set of alphabetic characters for which
8494
8495
8496
8497     196) See ''future library directions'' (7.30.2).
8498     197) In an implementation that uses the seven-bit US ASCII character set, the printing characters are those
8499          whose values lie from 0x20 (space) through 0x7E (tilde); the control characters are those whose
8500          values lie from 0 (NUL) through 0x1F (US), and the character 0x7F (DEL).
8501
8502 [page 198]
8503
8504     none of iscntrl, isdigit, ispunct, or isspace is true.198) In the "C" locale,
8505     isalpha returns true only for the characters for which isupper or islower is true.
8506     7.4.1.3 The isblank function
8507     Synopsis
8508 1           #include <ctype.h>
8509             int isblank(int c);
8510     Description
8511 2   The isblank function tests for any character that is a standard blank character or is one
8512     of a locale-specific set of characters for which isspace is true and that is used to
8513     separate words within a line of text. The standard blank characters are the following:
8514     space (' '), and horizontal tab ('\t'). In the "C" locale, isblank returns true only
8515     for the standard blank characters.
8516     7.4.1.4 The iscntrl function
8517     Synopsis
8518 1           #include <ctype.h>
8519             int iscntrl(int c);
8520     Description
8521 2   The iscntrl function tests for any control character.
8522     7.4.1.5 The isdigit function
8523     Synopsis
8524 1           #include <ctype.h>
8525             int isdigit(int c);
8526     Description
8527 2   The isdigit function tests for any decimal-digit character (as defined in 5.2.1).
8528     7.4.1.6 The isgraph function
8529     Synopsis
8530 1           #include <ctype.h>
8531             int isgraph(int c);
8532
8533
8534
8535
8536     198) The functions islower and isupper test true or false separately for each of these additional
8537          characters; all four combinations are possible.
8538
8539 [page 199]
8540
8541     Description
8542 2   The isgraph function tests for any printing character except space (' ').
8543     7.4.1.7 The islower function
8544     Synopsis
8545 1          #include <ctype.h>
8546            int islower(int c);
8547     Description
8548 2   The islower function tests for any character that is a lowercase letter or is one of a
8549     locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or
8550     isspace is true. In the "C" locale, islower returns true only for the lowercase
8551     letters (as defined in 5.2.1).
8552     7.4.1.8 The isprint function
8553     Synopsis
8554 1          #include <ctype.h>
8555            int isprint(int c);
8556     Description
8557 2   The isprint function tests for any printing character including space (' ').
8558     7.4.1.9 The ispunct function
8559     Synopsis
8560 1          #include <ctype.h>
8561            int ispunct(int c);
8562     Description
8563 2   The ispunct function tests for any printing character that is one of a locale-specific set
8564     of punctuation characters for which neither isspace nor isalnum is true. In the "C"
8565     locale, ispunct returns true for every printing character for which neither isspace
8566     nor isalnum is true.
8567     7.4.1.10 The isspace function
8568     Synopsis
8569 1          #include <ctype.h>
8570            int isspace(int c);
8571     Description
8572 2   The isspace function tests for any character that is a standard white-space character or
8573     is one of a locale-specific set of characters for which isalnum is false. The standard
8574
8575 [page 200]
8576
8577     white-space characters are the following: space (' '), form feed ('\f'), new-line
8578     ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). In the
8579     "C" locale, isspace returns true only for the standard white-space characters.
8580     7.4.1.11 The isupper function
8581     Synopsis
8582 1           #include <ctype.h>
8583             int isupper(int c);
8584     Description
8585 2   The isupper function tests for any character that is an uppercase letter or is one of a
8586     locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or
8587     isspace is true. In the "C" locale, isupper returns true only for the uppercase
8588     letters (as defined in 5.2.1).
8589     7.4.1.12 The isxdigit function
8590     Synopsis
8591 1           #include <ctype.h>
8592             int isxdigit(int c);
8593     Description
8594 2   The isxdigit function tests for any hexadecimal-digit character (as defined in 6.4.4.1).
8595     7.4.2 Character case mapping functions
8596     7.4.2.1 The tolower function
8597     Synopsis
8598 1           #include <ctype.h>
8599             int tolower(int c);
8600     Description
8601 2   The tolower function converts an uppercase letter to a corresponding lowercase letter.
8602     Returns
8603 3   If the argument is a character for which isupper is true and there are one or more
8604     corresponding characters, as specified by the current locale, for which islower is true,
8605     the tolower function returns one of the corresponding characters (always the same one
8606     for any given locale); otherwise, the argument is returned unchanged.
8607
8608
8609
8610
8611 [page 201]
8612
8613     7.4.2.2 The toupper function
8614     Synopsis
8615 1          #include <ctype.h>
8616            int toupper(int c);
8617     Description
8618 2   The toupper function converts a lowercase letter to a corresponding uppercase letter.
8619     Returns
8620 3   If the argument is a character for which islower is true and there are one or more
8621     corresponding characters, as specified by the current locale, for which isupper is true,
8622     the toupper function returns one of the corresponding characters (always the same one
8623     for any given locale); otherwise, the argument is returned unchanged.
8624
8625
8626
8627
8628 [page 202]
8629
8630     7.5 Errors <errno.h>
8631 1   The header <errno.h> defines several macros, all relating to the reporting of error
8632     conditions.
8633 2   The macros are
8634              EDOM
8635              EILSEQ
8636              ERANGE
8637     which expand to integer constant expressions with type int, distinct positive values, and
8638     which are suitable for use in #if preprocessing directives; and
8639              errno
8640     which expands to a modifiable lvalue199) that has type int and thread local storage
8641     duration, the value of which is set to a positive error number by several library functions.
8642     If a macro definition is suppressed in order to access an actual object, or a program
8643     defines an identifier with the name errno, the behavior is undefined.
8644 3   The value of errno in the initial thread is zero at program startup (the initial value of
8645     errno in other threads is an indeterminate value), but is never set to zero by any library
8646     function.200) The value of errno may be set to nonzero by a library function call
8647     whether or not there is an error, provided the use of errno is not documented in the
8648     description of the function in this International Standard.
8649 4   Additional macro definitions, beginning with E and a digit or E and an uppercase
8650     letter,201) may also be specified by the implementation.
8651
8652
8653
8654
8655     199) The macro errno need not be the identifier of an object. It might expand to a modifiable lvalue
8656          resulting from a function call (for example, *errno()).
8657     200) Thus, a program that uses errno for error checking should set it to zero before a library function call,
8658          then inspect it before a subsequent library function call. Of course, a library function can save the
8659          value of errno on entry and then set it to zero, as long as the original value is restored if errno's
8660          value is still zero just before the return.
8661     201) See ''future library directions'' (7.30.3).
8662
8663 [page 203]
8664
8665     7.6 Floating-point environment <fenv.h>
8666 1   The header <fenv.h> defines several macros, and declares types and functions that
8667     provide access to the floating-point environment. The floating-point environment refers
8668     collectively to any floating-point status flags and control modes supported by the
8669     implementation.202) A floating-point status flag is a system variable whose value is set
8670     (but never cleared) when a floating-point exception is raised, which occurs as a side effect
8671     of exceptional floating-point arithmetic to provide auxiliary information.203) A floating-
8672     point control mode is a system variable whose value may be set by the user to affect the
8673     subsequent behavior of floating-point arithmetic.
8674 2   The floating-point environment has thread storage duration. The initial state for a
8675     thread's floating-point environment is the current state of the floating-point environment
8676     of the thread that creates it at the time of creation.
8677 3   Certain programming conventions support the intended model of use for the floating-
8678     point environment:204)
8679     -- a function call does not alter its caller's floating-point control modes, clear its caller's
8680       floating-point status flags, nor depend on the state of its caller's floating-point status
8681       flags unless the function is so documented;
8682     -- a function call is assumed to require default floating-point control modes, unless its
8683       documentation promises otherwise;
8684     -- a function call is assumed to have the potential for raising floating-point exceptions,
8685       unless its documentation promises otherwise.
8686 4   The type
8687             fenv_t
8688     represents the entire floating-point environment.
8689 5   The type
8690             fexcept_t
8691     represents the floating-point status flags collectively, including any status the
8692     implementation associates with the flags.
8693
8694
8695     202) This header is designed to support the floating-point exception status flags and directed-rounding
8696          control modes required by IEC 60559, and other similar floating-point state information. Also it is
8697          designed to facilitate code portability among all systems.
8698     203) A floating-point status flag is not an object and can be set more than once within an expression.
8699     204) With these conventions, a programmer can safely assume default floating-point control modes (or be
8700          unaware of them). The responsibilities associated with accessing the floating-point environment fall
8701          on the programmer or program that does so explicitly.
8702
8703 [page 204]
8704
8705 6   Each of the macros
8706              FE_DIVBYZERO
8707              FE_INEXACT
8708              FE_INVALID
8709              FE_OVERFLOW
8710              FE_UNDERFLOW
8711     is defined if and only if the implementation supports the floating-point exception by
8712     means of the functions in 7.6.2.205) Additional implementation-defined floating-point
8713     exceptions, with macro definitions beginning with FE_ and an uppercase letter, may also
8714     be specified by the implementation. The defined macros expand to integer constant
8715     expressions with values such that bitwise ORs of all combinations of the macros result in
8716     distinct values, and furthermore, bitwise ANDs of all combinations of the macros result in
8717     zero.206)
8718 7   The macro
8719              FE_ALL_EXCEPT
8720     is simply the bitwise OR of all floating-point exception macros defined by the
8721     implementation. If no such macros are defined, FE_ALL_EXCEPT shall be defined as 0.
8722 8   Each of the macros
8723             FE_DOWNWARD
8724             FE_TONEAREST
8725             FE_TOWARDZERO
8726             FE_UPWARD
8727     is defined if and only if the implementation supports getting and setting the represented
8728     rounding direction by means of the fegetround and fesetround functions.
8729     Additional implementation-defined rounding directions, with macro definitions beginning
8730     with FE_ and an uppercase letter, may also be specified by the implementation. The
8731     defined macros expand to integer constant expressions whose values are distinct
8732     nonnegative values.207)
8733 9   The macro
8734
8735
8736
8737     205) The implementation supports an exception if there are circumstances where a call to at least one of the
8738          functions in 7.6.2, using the macro as the appropriate argument, will succeed. It is not necessary for
8739          all the functions to succeed all the time.
8740     206) The macros should be distinct powers of two.
8741     207) Even though the rounding direction macros may expand to constants corresponding to the values of
8742          FLT_ROUNDS, they are not required to do so.
8743
8744 [page 205]
8745
8746              FE_DFL_ENV
8747      represents the default floating-point environment -- the one installed at program startup
8748      -- and has type ''pointer to const-qualified fenv_t''. It can be used as an argument to
8749      <fenv.h> functions that manage the floating-point environment.
8750 10   Additional implementation-defined environments, with macro definitions beginning with
8751      FE_ and an uppercase letter, and having type ''pointer to const-qualified fenv_t'', may
8752      also be specified by the implementation.
8753      7.6.1 The FENV_ACCESS pragma
8754      Synopsis
8755 1            #include <fenv.h>
8756              #pragma STDC FENV_ACCESS on-off-switch
8757      Description
8758 2    The FENV_ACCESS pragma provides a means to inform the implementation when a
8759      program might access the floating-point environment to test floating-point status flags or
8760      run under non-default floating-point control modes.208) The pragma shall occur either
8761      outside external declarations or preceding all explicit declarations and statements inside a
8762      compound statement. When outside external declarations, the pragma takes effect from
8763      its occurrence until another FENV_ACCESS pragma is encountered, or until the end of
8764      the translation unit. When inside a compound statement, the pragma takes effect from its
8765      occurrence until another FENV_ACCESS pragma is encountered (including within a
8766      nested compound statement), or until the end of the compound statement; at the end of a
8767      compound statement the state for the pragma is restored to its condition just before the
8768      compound statement. If this pragma is used in any other context, the behavior is
8769      undefined. If part of a program tests floating-point status flags, sets floating-point control
8770      modes, or runs under non-default mode settings, but was translated with the state for the
8771      FENV_ACCESS pragma ''off'', the behavior is undefined. The default state (''on'' or
8772      ''off'') for the pragma is implementation-defined. (When execution passes from a part of
8773      the program translated with FENV_ACCESS ''off'' to a part translated with
8774      FENV_ACCESS ''on'', the state of the floating-point status flags is unspecified and the
8775      floating-point control modes have their default settings.)
8776
8777
8778
8779
8780      208) The purpose of the FENV_ACCESS pragma is to allow certain optimizations that could subvert flag
8781           tests and mode changes (e.g., global common subexpression elimination, code motion, and constant
8782           folding). In general, if the state of FENV_ACCESS is ''off'', the translator can assume that default
8783           modes are in effect and the flags are not tested.
8784
8785 [page 206]
8786
8787 3   EXAMPLE
8788             #include <fenv.h>
8789             void f(double x)
8790             {
8791                   #pragma STDC FENV_ACCESS ON
8792                   void g(double);
8793                   void h(double);
8794                   /* ... */
8795                   g(x + 1);
8796                   h(x + 1);
8797                   /* ... */
8798             }
8799 4   If the function g might depend on status flags set as a side effect of the first x + 1, or if the second
8800     x + 1 might depend on control modes set as a side effect of the call to function g, then the program shall
8801     contain an appropriately placed invocation of #pragma STDC FENV_ACCESS ON.209)
8802
8803     7.6.2 Floating-point exceptions
8804 1   The following functions provide access to the floating-point status flags.210) The int
8805     input argument for the functions represents a subset of floating-point exceptions, and can
8806     be zero or the bitwise OR of one or more floating-point exception macros, for example
8807     FE_OVERFLOW | FE_INEXACT. For other argument values the behavior of these
8808     functions is undefined.
8809     7.6.2.1 The feclearexcept function
8810     Synopsis
8811 1           #include <fenv.h>
8812             int feclearexcept(int excepts);
8813     Description
8814 2   The feclearexcept function attempts to clear the supported floating-point exceptions
8815     represented by its argument.
8816     Returns
8817 3   The feclearexcept function returns zero if the excepts argument is zero or if all
8818     the specified exceptions were successfully cleared. Otherwise, it returns a nonzero value.
8819
8820
8821     209) The side effects impose a temporal ordering that requires two evaluations of x + 1. On the other
8822          hand, without the #pragma STDC FENV_ACCESS ON pragma, and assuming the default state is
8823          ''off'', just one evaluation of x + 1 would suffice.
8824     210) The functions fetestexcept, feraiseexcept, and feclearexcept support the basic
8825          abstraction of flags that are either set or clear. An implementation may endow floating-point status
8826          flags with more information -- for example, the address of the code which first raised the floating-
8827          point exception; the functions fegetexceptflag and fesetexceptflag deal with the full
8828          content of flags.
8829
8830 [page 207]
8831
8832     7.6.2.2 The fegetexceptflag function
8833     Synopsis
8834 1            #include <fenv.h>
8835              int fegetexceptflag(fexcept_t *flagp,
8836                   int excepts);
8837     Description
8838 2   The fegetexceptflag function attempts to store an implementation-defined
8839     representation of the states of the floating-point status flags indicated by the argument
8840     excepts in the object pointed to by the argument flagp.
8841     Returns
8842 3   The fegetexceptflag function returns zero if the representation was successfully
8843     stored. Otherwise, it returns a nonzero value.
8844     7.6.2.3 The feraiseexcept function
8845     Synopsis
8846 1            #include <fenv.h>
8847              int feraiseexcept(int excepts);
8848     Description
8849 2   The feraiseexcept function attempts to raise the supported floating-point exceptions
8850     represented by its argument.211) The order in which these floating-point exceptions are
8851     raised is unspecified, except as stated in F.8.6. Whether the feraiseexcept function
8852     additionally raises the ''inexact'' floating-point exception whenever it raises the
8853     ''overflow'' or ''underflow'' floating-point exception is implementation-defined.
8854     Returns
8855 3   The feraiseexcept function returns zero if the excepts argument is zero or if all
8856     the specified exceptions were successfully raised. Otherwise, it returns a nonzero value.
8857
8858
8859
8860
8861     211) The effect is intended to be similar to that of floating-point exceptions raised by arithmetic operations.
8862          Hence, enabled traps for floating-point exceptions raised by this function are taken. The specification
8863          in F.8.6 is in the same spirit.
8864
8865 [page 208]
8866
8867     7.6.2.4 The fesetexceptflag function
8868     Synopsis
8869 1           #include <fenv.h>
8870             int fesetexceptflag(const fexcept_t *flagp,
8871                  int excepts);
8872     Description
8873 2   The fesetexceptflag function attempts to set the floating-point status flags
8874     indicated by the argument excepts to the states stored in the object pointed to by
8875     flagp. The value of *flagp shall have been set by a previous call to
8876     fegetexceptflag whose second argument represented at least those floating-point
8877     exceptions represented by the argument excepts. This function does not raise floating-
8878     point exceptions, but only sets the state of the flags.
8879     Returns
8880 3   The fesetexceptflag function returns zero if the excepts argument is zero or if
8881     all the specified flags were successfully set to the appropriate state. Otherwise, it returns
8882     a nonzero value.
8883     7.6.2.5 The fetestexcept function
8884     Synopsis
8885 1           #include <fenv.h>
8886             int fetestexcept(int excepts);
8887     Description
8888 2   The fetestexcept function determines which of a specified subset of the floating-
8889     point exception flags are currently set. The excepts argument specifies the floating-
8890     point status flags to be queried.212)
8891     Returns
8892 3   The fetestexcept function returns the value of the bitwise OR of the floating-point
8893     exception macros corresponding to the currently set floating-point exceptions included in
8894     excepts.
8895 4   EXAMPLE       Call f if ''invalid'' is set, then g if ''overflow'' is set:
8896
8897
8898
8899
8900     212) This mechanism allows testing several floating-point exceptions with just one function call.
8901
8902 [page 209]
8903
8904            #include <fenv.h>
8905            /* ... */
8906            {
8907                    #pragma STDC FENV_ACCESS ON
8908                    int set_excepts;
8909                    feclearexcept(FE_INVALID | FE_OVERFLOW);
8910                    // maybe raise exceptions
8911                    set_excepts = fetestexcept(FE_INVALID | FE_OVERFLOW);
8912                    if (set_excepts & FE_INVALID) f();
8913                    if (set_excepts & FE_OVERFLOW) g();
8914                    /* ... */
8915            }
8916
8917     7.6.3 Rounding
8918 1   The fegetround and fesetround functions provide control of rounding direction
8919     modes.
8920     7.6.3.1 The fegetround function
8921     Synopsis
8922 1          #include <fenv.h>
8923            int fegetround(void);
8924     Description
8925 2   The fegetround function gets the current rounding direction.
8926     Returns
8927 3   The fegetround function returns the value of the rounding direction macro
8928     representing the current rounding direction or a negative value if there is no such
8929     rounding direction macro or the current rounding direction is not determinable.
8930     7.6.3.2 The fesetround function
8931     Synopsis
8932 1          #include <fenv.h>
8933            int fesetround(int round);
8934     Description
8935 2   The fesetround function establishes the rounding direction represented by its
8936     argument round. If the argument is not equal to the value of a rounding direction macro,
8937     the rounding direction is not changed.
8938     Returns
8939 3   The fesetround function returns zero if and only if the requested rounding direction
8940     was established.
8941
8942
8943 [page 210]
8944
8945 4   EXAMPLE Save, set, and restore the rounding direction. Report an error and abort if setting the
8946     rounding direction fails.
8947             #include <fenv.h>
8948             #include <assert.h>
8949             void f(int round_dir)
8950             {
8951                   #pragma STDC FENV_ACCESS ON
8952                   int save_round;
8953                   int setround_ok;
8954                   save_round = fegetround();
8955                   setround_ok = fesetround(round_dir);
8956                   assert(setround_ok == 0);
8957                   /* ... */
8958                   fesetround(save_round);
8959                   /* ... */
8960             }
8961
8962     7.6.4 Environment
8963 1   The functions in this section manage the floating-point environment -- status flags and
8964     control modes -- as one entity.
8965     7.6.4.1 The fegetenv function
8966     Synopsis
8967 1           #include <fenv.h>
8968             int fegetenv(fenv_t *envp);
8969     Description
8970 2   The fegetenv function attempts to store the current floating-point environment in the
8971     object pointed to by envp.
8972     Returns
8973 3   The fegetenv function returns zero if the environment was successfully stored.
8974     Otherwise, it returns a nonzero value.
8975     7.6.4.2 The feholdexcept function
8976     Synopsis
8977 1           #include <fenv.h>
8978             int feholdexcept(fenv_t *envp);
8979     Description
8980 2   The feholdexcept function saves the current floating-point environment in the object
8981     pointed to by envp, clears the floating-point status flags, and then installs a non-stop
8982     (continue on floating-point exceptions) mode, if available, for all floating-point
8983     exceptions.213)
8984
8985 [page 211]
8986
8987     Returns
8988 3   The feholdexcept function returns zero if and only if non-stop floating-point
8989     exception handling was successfully installed.
8990     7.6.4.3 The fesetenv function
8991     Synopsis
8992 1           #include <fenv.h>
8993             int fesetenv(const fenv_t *envp);
8994     Description
8995 2   The fesetenv function attempts to establish the floating-point environment represented
8996     by the object pointed to by envp. The argument envp shall point to an object set by a
8997     call to fegetenv or feholdexcept, or equal a floating-point environment macro.
8998     Note that fesetenv merely installs the state of the floating-point status flags
8999     represented through its argument, and does not raise these floating-point exceptions.
9000     Returns
9001 3   The fesetenv function returns zero if the environment was successfully established.
9002     Otherwise, it returns a nonzero value.
9003     7.6.4.4 The feupdateenv function
9004     Synopsis
9005 1           #include <fenv.h>
9006             int feupdateenv(const fenv_t *envp);
9007     Description
9008 2   The feupdateenv function attempts to save the currently raised floating-point
9009     exceptions in its automatic storage, install the floating-point environment represented by
9010     the object pointed to by envp, and then raise the saved floating-point exceptions. The
9011     argument envp shall point to an object set by a call to feholdexcept or fegetenv,
9012     or equal a floating-point environment macro.
9013     Returns
9014 3   The feupdateenv function returns zero if all the actions were successfully carried out.
9015     Otherwise, it returns a nonzero value.
9016
9017
9018
9019
9020     213) IEC 60559 systems have a default non-stop mode, and typically at least one other mode for trap
9021          handling or aborting; if the system provides only the non-stop mode then installing it is trivial. For
9022          such systems, the feholdexcept function can be used in conjunction with the feupdateenv
9023          function to write routines that hide spurious floating-point exceptions from their callers.
9024
9025 [page 212]
9026
9027 4   EXAMPLE     Hide spurious underflow floating-point exceptions:
9028             #include <fenv.h>
9029             double f(double x)
9030             {
9031                   #pragma STDC FENV_ACCESS ON
9032                   double result;
9033                   fenv_t save_env;
9034                   if (feholdexcept(&save_env))
9035                         return /* indication of an environmental problem */;
9036                   // compute result
9037                   if (/* test spurious underflow */)
9038                         if (feclearexcept(FE_UNDERFLOW))
9039                                  return /* indication of an environmental problem */;
9040                   if (feupdateenv(&save_env))
9041                         return /* indication of an environmental problem */;
9042                   return result;
9043             }
9044
9045
9046
9047
9048 [page 213]
9049
9050     7.7 Characteristics of floating types <float.h>
9051 1   The header <float.h> defines several macros that expand to various limits and
9052     parameters of the standard floating-point types.
9053 2   The macros, their meanings, and the constraints (or restrictions) on their values are listed
9054     in 5.2.4.2.2.
9055
9056
9057
9058
9059 [page 214]
9060
9061     7.8 Format conversion of integer types <inttypes.h>
9062 1   The header <inttypes.h> includes the header <stdint.h> and extends it with
9063     additional facilities provided by hosted implementations.
9064 2   It declares functions for manipulating greatest-width integers and converting numeric
9065     character strings to greatest-width integers, and it declares the type
9066              imaxdiv_t
9067     which is a structure type that is the type of the value returned by the imaxdiv function.
9068     For each type declared in <stdint.h>, it defines corresponding macros for conversion
9069     specifiers for use with the formatted input/output functions.214)
9070     Forward references: integer types <stdint.h> (7.20), formatted input/output
9071     functions (7.21.6), formatted wide character input/output functions (7.28.2).
9072     7.8.1 Macros for format specifiers
9073 1   Each of the following object-like macros expands to a character string literal containing a
9074     conversion specifier, possibly modified by a length modifier, suitable for use within the
9075     format argument of a formatted input/output function when converting the corresponding
9076     integer type. These macro names have the general form of PRI (character string literals
9077     for the fprintf and fwprintf family) or SCN (character string literals for the
9078     fscanf and fwscanf family),215) followed by the conversion specifier, followed by a
9079     name corresponding to a similar type name in 7.20.1. In these names, N represents the
9080     width of the type as described in 7.20.1. For example, PRIdFAST32 can be used in a
9081     format string to print the value of an integer of type int_fast32_t.
9082 2   The fprintf macros for signed integers are:
9083            PRIdN             PRIdLEASTN                PRIdFASTN          PRIdMAX             PRIdPTR
9084            PRIiN             PRIiLEASTN                PRIiFASTN          PRIiMAX             PRIiPTR
9085 3   The fprintf macros for unsigned integers are:
9086            PRIoN             PRIoLEASTN                PRIoFASTN          PRIoMAX             PRIoPTR
9087            PRIuN             PRIuLEASTN                PRIuFASTN          PRIuMAX             PRIuPTR
9088            PRIxN             PRIxLEASTN                PRIxFASTN          PRIxMAX             PRIxPTR
9089            PRIXN             PRIXLEASTN                PRIXFASTN          PRIXMAX             PRIXPTR
9090 4   The fscanf macros for signed integers are:
9091
9092
9093
9094     214) See ''future library directions'' (7.30.4).
9095     215) Separate macros are given for use with fprintf and fscanf functions because, in the general case,
9096          different format specifiers may be required for fprintf and fscanf, even when the type is the
9097          same.
9098
9099 [page 215]
9100
9101            SCNdN           SCNdLEASTN               SCNdFASTN              SCNdMAX             SCNdPTR
9102            SCNiN           SCNiLEASTN               SCNiFASTN              SCNiMAX             SCNiPTR
9103 5   The fscanf macros for unsigned integers are:
9104            SCNoN           SCNoLEASTN               SCNoFASTN              SCNoMAX             SCNoPTR
9105            SCNuN           SCNuLEASTN               SCNuFASTN              SCNuMAX             SCNuPTR
9106            SCNxN           SCNxLEASTN               SCNxFASTN              SCNxMAX             SCNxPTR
9107 6   For each type that the implementation provides in <stdint.h>, the corresponding
9108     fprintf macros shall be defined and the corresponding fscanf macros shall be
9109     defined unless the implementation does not have a suitable fscanf length modifier for
9110     the type.
9111 7   EXAMPLE
9112             #include <inttypes.h>
9113             #include <wchar.h>
9114             int main(void)
9115             {
9116                   uintmax_t i = UINTMAX_MAX;    // this type always exists
9117                   wprintf(L"The largest integer value is %020"
9118                         PRIxMAX "\n", i);
9119                   return 0;
9120             }
9121
9122     7.8.2 Functions for greatest-width integer types
9123     7.8.2.1 The imaxabs function
9124     Synopsis
9125 1           #include <inttypes.h>
9126             intmax_t imaxabs(intmax_t j);
9127     Description
9128 2   The imaxabs function computes the absolute value of an integer j. If the result cannot
9129     be represented, the behavior is undefined.216)
9130     Returns
9131 3   The imaxabs function returns the absolute value.
9132
9133
9134
9135
9136     216) The absolute value of the most negative number cannot be represented in two's complement.
9137
9138 [page 216]
9139
9140     7.8.2.2 The imaxdiv function
9141     Synopsis
9142 1           #include <inttypes.h>
9143             imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
9144     Description
9145 2   The imaxdiv function computes numer / denom and numer % denom in a single
9146     operation.
9147     Returns
9148 3   The imaxdiv function returns a structure of type imaxdiv_t comprising both the
9149     quotient and the remainder. The structure shall contain (in either order) the members
9150     quot (the quotient) and rem (the remainder), each of which has type intmax_t. If
9151     either part of the result cannot be represented, the behavior is undefined.
9152     7.8.2.3 The strtoimax and strtoumax functions
9153     Synopsis
9154 1           #include <inttypes.h>
9155             intmax_t strtoimax(const char * restrict nptr,
9156                  char ** restrict endptr, int base);
9157             uintmax_t strtoumax(const char * restrict nptr,
9158                  char ** restrict endptr, int base);
9159     Description
9160 2   The strtoimax and strtoumax functions are equivalent to the strtol, strtoll,
9161     strtoul, and strtoull functions, except that the initial portion of the string is
9162     converted to intmax_t and uintmax_t representation, respectively.
9163     Returns
9164 3   The strtoimax and strtoumax functions return the converted value, if any. If no
9165     conversion could be performed, zero is returned. If the correct value is outside the range
9166     of representable values, INTMAX_MAX, INTMAX_MIN, or UINTMAX_MAX is returned
9167     (according to the return type and sign of the value, if any), and the value of the macro
9168     ERANGE is stored in errno.
9169     Forward references: the strtol, strtoll, strtoul, and strtoull functions
9170     (7.22.1.4).
9171
9172
9173
9174
9175 [page 217]
9176
9177     7.8.2.4 The wcstoimax and wcstoumax functions
9178     Synopsis
9179 1          #include <stddef.h>           // for wchar_t
9180            #include <inttypes.h>
9181            intmax_t wcstoimax(const wchar_t * restrict nptr,
9182                 wchar_t ** restrict endptr, int base);
9183            uintmax_t wcstoumax(const wchar_t * restrict nptr,
9184                 wchar_t ** restrict endptr, int base);
9185     Description
9186 2   The wcstoimax and wcstoumax functions are equivalent to the wcstol, wcstoll,
9187     wcstoul, and wcstoull functions except that the initial portion of the wide string is
9188     converted to intmax_t and uintmax_t representation, respectively.
9189     Returns
9190 3   The wcstoimax function returns the converted value, if any. If no conversion could be
9191     performed, zero is returned. If the correct value is outside the range of representable
9192     values, INTMAX_MAX, INTMAX_MIN, or UINTMAX_MAX is returned (according to the
9193     return type and sign of the value, if any), and the value of the macro ERANGE is stored in
9194     errno.
9195     Forward references: the wcstol, wcstoll, wcstoul, and wcstoull functions
9196     (7.28.4.1.2).
9197
9198
9199
9200
9201 [page 218]
9202
9203     7.9 Alternative spellings <iso646.h>
9204 1   The header <iso646.h> defines the following eleven macros (on the left) that expand
9205     to the corresponding tokens (on the right):
9206             and        &&
9207             and_eq     &=
9208             bitand     &
9209             bitor      |
9210             compl      ~
9211             not        !
9212             not_eq     !=
9213             or         ||
9214             or_eq      |=
9215             xor        ^
9216             xor_eq     ^=
9217
9218
9219
9220
9221 [page 219]
9222
9223     7.10 Sizes of integer types <limits.h>
9224 1   The header <limits.h> defines several macros that expand to various limits and
9225     parameters of the standard integer types.
9226 2   The macros, their meanings, and the constraints (or restrictions) on their values are listed
9227     in 5.2.4.2.1.
9228
9229
9230
9231
9232 [page 220]
9233
9234     7.11 Localization <locale.h>
9235 1   The header <locale.h> declares two functions, one type, and defines several macros.
9236 2   The type is
9237             struct lconv
9238     which contains members related to the formatting of numeric values. The structure shall
9239     contain at least the following members, in any order. The semantics of the members and
9240     their normal ranges are explained in 7.11.2.1. In the "C" locale, the members shall have
9241     the values specified in the comments.
9242             char   *decimal_point;                //   "."
9243             char   *thousands_sep;                //   ""
9244             char   *grouping;                     //   ""
9245             char   *mon_decimal_point;            //   ""
9246             char   *mon_thousands_sep;            //   ""
9247             char   *mon_grouping;                 //   ""
9248             char   *positive_sign;                //   ""
9249             char   *negative_sign;                //   ""
9250             char   *currency_symbol;              //   ""
9251             char   frac_digits;                   //   CHAR_MAX
9252             char   p_cs_precedes;                 //   CHAR_MAX
9253             char   n_cs_precedes;                 //   CHAR_MAX
9254             char   p_sep_by_space;                //   CHAR_MAX
9255             char   n_sep_by_space;                //   CHAR_MAX
9256             char   p_sign_posn;                   //   CHAR_MAX
9257             char   n_sign_posn;                   //   CHAR_MAX
9258             char   *int_curr_symbol;              //   ""
9259             char   int_frac_digits;               //   CHAR_MAX
9260             char   int_p_cs_precedes;             //   CHAR_MAX
9261             char   int_n_cs_precedes;             //   CHAR_MAX
9262             char   int_p_sep_by_space;            //   CHAR_MAX
9263             char   int_n_sep_by_space;            //   CHAR_MAX
9264             char   int_p_sign_posn;               //   CHAR_MAX
9265             char   int_n_sign_posn;               //   CHAR_MAX
9266
9267
9268
9269
9270 [page 221]
9271
9272 3   The macros defined are NULL (described in 7.19); and
9273              LC_ALL
9274              LC_COLLATE
9275              LC_CTYPE
9276              LC_MONETARY
9277              LC_NUMERIC
9278              LC_TIME
9279     which expand to integer constant expressions with distinct values, suitable for use as the
9280     first argument to the setlocale function.217) Additional macro definitions, beginning
9281     with the characters LC_ and an uppercase letter,218) may also be specified by the
9282     implementation.
9283     7.11.1 Locale control
9284     7.11.1.1 The setlocale function
9285     Synopsis
9286 1            #include <locale.h>
9287              char *setlocale(int category, const char *locale);
9288     Description
9289 2   The setlocale function selects the appropriate portion of the program's locale as
9290     specified by the category and locale arguments. The setlocale function may be
9291     used to change or query the program's entire current locale or portions thereof. The value
9292     LC_ALL for category names the program's entire locale; the other values for
9293     category name only a portion of the program's locale. LC_COLLATE affects the
9294     behavior of the strcoll and strxfrm functions. LC_CTYPE affects the behavior of
9295     the character handling functions219) and the multibyte and wide character functions.
9296     LC_MONETARY affects the monetary formatting information returned by the
9297     localeconv function. LC_NUMERIC affects the decimal-point character for the
9298     formatted input/output functions and the string conversion functions, as well as the
9299     nonmonetary formatting information returned by the localeconv function. LC_TIME
9300     affects the behavior of the strftime and wcsftime functions.
9301 3   A value of "C" for locale specifies the minimal environment for C translation; a value
9302     of "" for locale specifies the locale-specific native environment. Other
9303     implementation-defined strings may be passed as the second argument to setlocale.
9304
9305     217) ISO/IEC 9945-2 specifies locale and charmap formats that may be used to specify locales for C.
9306     218) See ''future library directions'' (7.30.5).
9307     219) The only functions in 7.4 whose behavior is not affected by the current locale are isdigit and
9308          isxdigit.
9309
9310 [page 222]
9311
9312 4   At program startup, the equivalent of
9313             setlocale(LC_ALL, "C");
9314     is executed.
9315 5   A call to the setlocale function may introduce a data race with other calls to the
9316     setlocale function or with calls to functions that are affected by the current locale.
9317     The implementation shall behave as if no library function calls the setlocale function.
9318     Returns
9319 6   If a pointer to a string is given for locale and the selection can be honored, the
9320     setlocale function returns a pointer to the string associated with the specified
9321     category for the new locale. If the selection cannot be honored, the setlocale
9322     function returns a null pointer and the program's locale is not changed.
9323 7   A null pointer for locale causes the setlocale function to return a pointer to the
9324     string associated with the category for the program's current locale; the program's
9325     locale is not changed.220)
9326 8   The pointer to string returned by the setlocale function is such that a subsequent call
9327     with that string value and its associated category will restore that part of the program's
9328     locale. The string pointed to shall not be modified by the program, but may be
9329     overwritten by a subsequent call to the setlocale function.
9330     Forward references: formatted input/output functions (7.21.6), multibyte/wide
9331     character conversion functions (7.22.7), multibyte/wide string conversion functions
9332     (7.22.8), numeric conversion functions (7.22.1), the strcoll function (7.23.4.3), the
9333     strftime function (7.26.3.5), the strxfrm function (7.23.4.5).
9334     7.11.2 Numeric formatting convention inquiry
9335     7.11.2.1 The localeconv function
9336     Synopsis
9337 1           #include <locale.h>
9338             struct lconv *localeconv(void);
9339     Description
9340 2   The localeconv function sets the components of an object with type struct lconv
9341     with values appropriate for the formatting of numeric quantities (monetary and otherwise)
9342     according to the rules of the current locale.
9343
9344
9345
9346     220) The implementation shall arrange to encode in a string the various categories due to a heterogeneous
9347          locale when category has the value LC_ALL.
9348
9349 [page 223]
9350
9351 3   The members of the structure with type char * are pointers to strings, any of which
9352     (except decimal_point) can point to "", to indicate that the value is not available in
9353     the current locale or is of zero length. Apart from grouping and mon_grouping, the
9354     strings shall start and end in the initial shift state. The members with type char are
9355     nonnegative numbers, any of which can be CHAR_MAX to indicate that the value is not
9356     available in the current locale. The members include the following:
9357     char *decimal_point
9358               The decimal-point character used to format nonmonetary quantities.
9359     char *thousands_sep
9360               The character used to separate groups of digits before the decimal-point
9361               character in formatted nonmonetary quantities.
9362     char *grouping
9363               A string whose elements indicate the size of each group of digits in
9364               formatted nonmonetary quantities.
9365     char *mon_decimal_point
9366               The decimal-point used to format monetary quantities.
9367     char *mon_thousands_sep
9368               The separator for groups of digits before the decimal-point in formatted
9369               monetary quantities.
9370     char *mon_grouping
9371               A string whose elements indicate the size of each group of digits in
9372               formatted monetary quantities.
9373     char *positive_sign
9374               The string used to indicate a nonnegative-valued formatted monetary
9375               quantity.
9376     char *negative_sign
9377               The string used to indicate a negative-valued formatted monetary quantity.
9378     char *currency_symbol
9379               The local currency symbol applicable to the current locale.
9380     char frac_digits
9381               The number of fractional digits (those after the decimal-point) to be
9382               displayed in a locally formatted monetary quantity.
9383     char p_cs_precedes
9384               Set to 1 or 0 if the currency_symbol respectively precedes or
9385               succeeds the value for a nonnegative locally formatted monetary quantity.
9386
9387
9388
9389 [page 224]
9390
9391 char n_cs_precedes
9392           Set to 1 or 0 if the currency_symbol respectively precedes or
9393           succeeds the value for a negative locally formatted monetary quantity.
9394 char p_sep_by_space
9395           Set to a value indicating the separation of the currency_symbol, the
9396           sign string, and the value for a nonnegative locally formatted monetary
9397           quantity.
9398 char n_sep_by_space
9399           Set to a value indicating the separation of the currency_symbol, the
9400           sign string, and the value for a negative locally formatted monetary
9401           quantity.
9402 char p_sign_posn
9403           Set to a value indicating the positioning of the positive_sign for a
9404           nonnegative locally formatted monetary quantity.
9405 char n_sign_posn
9406           Set to a value indicating the positioning of the negative_sign for a
9407           negative locally formatted monetary quantity.
9408 char *int_curr_symbol
9409           The international currency symbol applicable to the current locale. The
9410           first three characters contain the alphabetic international currency symbol
9411           in accordance with those specified in ISO 4217. The fourth character
9412           (immediately preceding the null character) is the character used to separate
9413           the international currency symbol from the monetary quantity.
9414 char int_frac_digits
9415           The number of fractional digits (those after the decimal-point) to be
9416           displayed in an internationally formatted monetary quantity.
9417 char int_p_cs_precedes
9418           Set to 1 or 0 if the int_curr_symbol respectively precedes or
9419           succeeds the value for a nonnegative internationally formatted monetary
9420           quantity.
9421 char int_n_cs_precedes
9422           Set to 1 or 0 if the int_curr_symbol respectively precedes or
9423           succeeds the value for a negative internationally formatted monetary
9424           quantity.
9425 char int_p_sep_by_space
9426           Set to a value indicating the separation of the int_curr_symbol, the
9427           sign string, and the value for a nonnegative internationally formatted
9428           monetary quantity.
9429 [page 225]
9430
9431     char int_n_sep_by_space
9432               Set to a value indicating the separation of the int_curr_symbol, the
9433               sign string, and the value for a negative internationally formatted monetary
9434               quantity.
9435     char int_p_sign_posn
9436               Set to a value indicating the positioning of the positive_sign for a
9437               nonnegative internationally formatted monetary quantity.
9438     char int_n_sign_posn
9439               Set to a value indicating the positioning of the negative_sign for a
9440               negative internationally formatted monetary quantity.
9441 4   The elements of grouping and mon_grouping are interpreted according to the
9442     following:
9443     CHAR_MAX        No further grouping is to be performed.
9444     0               The previous element is to be repeatedly used for the remainder of the
9445                     digits.
9446     other           The integer value is the number of digits that compose the current group.
9447                     The next element is examined to determine the size of the next group of
9448                     digits before the current group.
9449 5   The values of p_sep_by_space, n_sep_by_space, int_p_sep_by_space,
9450     and int_n_sep_by_space are interpreted according to the following:
9451     0     No space separates the currency symbol and value.
9452     1     If the currency symbol and sign string are adjacent, a space separates them from the
9453           value; otherwise, a space separates the currency symbol from the value.
9454     2   If the currency symbol and sign string are adjacent, a space separates them;
9455         otherwise, a space separates the sign string from the value.
9456     For int_p_sep_by_space and int_n_sep_by_space, the fourth character of
9457     int_curr_symbol is used instead of a space.
9458 6   The values of p_sign_posn, n_sign_posn, int_p_sign_posn,                              and
9459     int_n_sign_posn are interpreted according to the following:
9460     0     Parentheses surround the quantity and currency symbol.
9461     1     The sign string precedes the quantity and currency symbol.
9462     2     The sign string succeeds the quantity and currency symbol.
9463     3     The sign string immediately precedes the currency symbol.
9464     4     The sign string immediately succeeds the currency symbol.
9465
9466
9467 [page 226]
9468
9469 7    The implementation shall behave as if no library function calls the localeconv
9470      function.
9471      Returns
9472 8    The localeconv function returns a pointer to the filled-in object. The structure
9473      pointed to by the return value shall not be modified by the program, but may be
9474      overwritten by a subsequent call to the localeconv function. In addition, calls to the
9475      setlocale function with categories LC_ALL, LC_MONETARY, or LC_NUMERIC may
9476      overwrite the contents of the structure.
9477 9    EXAMPLE 1 The following table illustrates rules which may well be used by four countries to format
9478      monetary quantities.
9479                                    Local format                                     International format
9480
9481      Country            Positive                  Negative                    Positive               Negative
9482
9483      Country1     1.234,56 mk             -1.234,56 mk                  FIM   1.234,56         FIM -1.234,56
9484      Country2     L.1.234                 -L.1.234                      ITL   1.234            -ITL 1.234
9485      Country3     fl. 1.234,56              fl. -1.234,56                   NLG   1.234,56         NLG -1.234,56
9486      Country4     SFrs.1,234.56           SFrs.1,234.56C                CHF   1,234.56         CHF 1,234.56C
9487 10   For these four countries, the respective values for the monetary members of the structure returned by
9488      localeconv could be:
9489                                        Country1              Country2              Country3            Country4
9490
9491      mon_decimal_point                 ","                   ""                   ","                 "."
9492      mon_thousands_sep                 "."                   "."                  "."                 ","
9493      mon_grouping                      "\3"                  "\3"                 "\3"                "\3"
9494      positive_sign                     ""                    ""                   ""                  ""
9495      negative_sign                     "-"                   "-"                  "-"                 "C"
9496      currency_symbol                   "mk"                  "L."                 "\u0192"            "SFrs."
9497      frac_digits                       2                     0                    2                   2
9498      p_cs_precedes                     0                     1                    1                   1
9499      n_cs_precedes                     0                     1                    1                   1
9500      p_sep_by_space                    1                     0                    1                   0
9501      n_sep_by_space                    1                     0                    2                   0
9502      p_sign_posn                       1                     1                    1                   1
9503      n_sign_posn                       1                     1                    4                   2
9504      int_curr_symbol                   "FIM "                "ITL "               "NLG "              "CHF "
9505      int_frac_digits                   2                     0                    2                   2
9506      int_p_cs_precedes                 1                     1                    1                   1
9507      int_n_cs_precedes                 1                     1                    1                   1
9508      int_p_sep_by_space                1                     1                    1                   1
9509      int_n_sep_by_space                2                     1                    2                   1
9510      int_p_sign_posn                   1                     1                    1                   1
9511      int_n_sign_posn                   4                     1                    4                   2
9512
9513
9514
9515
9516 [page 227]
9517
9518 11   EXAMPLE 2 The following table illustrates how the cs_precedes, sep_by_space, and sign_posn members
9519      affect the formatted value.
9520                                                                    p_sep_by_space
9521
9522      p_cs_precedes           p_sign_posn                0                   1                  2
9523
9524                      0                    0         (1.25$)            (1.25 $)            (1.25$)
9525                                           1         +1.25$             +1.25 $             + 1.25$
9526                                           2         1.25$+             1.25 $+             1.25$ +
9527                                           3         1.25+$             1.25 +$             1.25+ $
9528                                           4         1.25$+             1.25 $+             1.25$ +
9529
9530                      1                    0         ($1.25)            ($ 1.25)            ($1.25)
9531                                           1         +$1.25             +$ 1.25             + $1.25
9532                                           2         $1.25+             $ 1.25+             $1.25 +
9533                                           3         +$1.25             +$ 1.25             + $1.25
9534                                           4         $+1.25             $+ 1.25             $ +1.25
9535
9536
9537
9538
9539 [page 228]
9540
9541     7.12 Mathematics <math.h>
9542 1   The header <math.h> declares two types and many mathematical functions and defines
9543     several macros. Most synopses specify a family of functions consisting of a principal
9544     function with one or more double parameters, a double return value, or both; and
9545     other functions with the same name but with f and l suffixes, which are corresponding
9546     functions with float and long double parameters, return values, or both.221)
9547     Integer arithmetic functions and conversion functions are discussed later.
9548 2   The types
9549             float_t
9550             double_t
9551     are floating types at least as wide as float and double, respectively, and such that
9552     double_t is at least as wide as float_t. If FLT_EVAL_METHOD equals 0,
9553     float_t and double_t are float and double, respectively; if
9554     FLT_EVAL_METHOD equals 1, they are both double; if FLT_EVAL_METHOD equals
9555     2, they are both long double; and for other values of FLT_EVAL_METHOD, they are
9556     otherwise implementation-defined.222)
9557 3   The macro
9558             HUGE_VAL
9559     expands to a positive double constant expression, not necessarily representable as a
9560     float. The macros
9561             HUGE_VALF
9562             HUGE_VALL
9563     are respectively float and long double analogs of HUGE_VAL.223)
9564 4   The macro
9565             INFINITY
9566     expands to a constant expression of type float representing positive or unsigned
9567     infinity, if available; else to a positive constant of type float that overflows at
9568
9569
9570
9571     221) Particularly on systems with wide expression evaluation, a <math.h> function might pass arguments
9572          and return values in wider format than the synopsis prototype indicates.
9573     222) The types float_t and double_t are intended to be the implementation's most efficient types at
9574          least as wide as float and double, respectively. For FLT_EVAL_METHOD equal 0, 1, or 2, the
9575          type float_t is the narrowest type used by the implementation to evaluate floating expressions.
9576     223) HUGE_VAL, HUGE_VALF, and HUGE_VALL can be positive infinities in an implementation that
9577          supports infinities.
9578
9579 [page 229]
9580
9581     translation time.224)
9582 5   The macro
9583              NAN
9584     is defined if and only if the implementation supports quiet NaNs for the float type. It
9585     expands to a constant expression of type float representing a quiet NaN.
9586 6   The number classification macros
9587              FP_INFINITE
9588              FP_NAN
9589              FP_NORMAL
9590              FP_SUBNORMAL
9591              FP_ZERO
9592     represent the mutually exclusive kinds of floating-point values. They expand to integer
9593     constant expressions with distinct values. Additional implementation-defined floating-
9594     point classifications, with macro definitions beginning with FP_ and an uppercase letter,
9595     may also be specified by the implementation.
9596 7   The macro
9597              FP_FAST_FMA
9598     is optionally defined. If defined, it indicates that the fma function generally executes
9599     about as fast as, or faster than, a multiply and an add of double operands.225) The
9600     macros
9601              FP_FAST_FMAF
9602              FP_FAST_FMAL
9603     are, respectively, float and long double analogs of FP_FAST_FMA. If defined,
9604     these macros expand to the integer constant 1.
9605 8   The macros
9606              FP_ILOGB0
9607              FP_ILOGBNAN
9608     expand to integer constant expressions whose values are returned by ilogb(x) if x is
9609     zero or NaN, respectively. The value of FP_ILOGB0 shall be either INT_MIN or
9610     -INT_MAX. The value of FP_ILOGBNAN shall be either INT_MAX or INT_MIN.
9611
9612
9613     224) In this case, using INFINITY will violate the constraint in 6.4.4 and thus require a diagnostic.
9614     225) Typically, the FP_FAST_FMA macro is defined if and only if the fma function is implemented
9615          directly with a hardware multiply-add instruction. Software implementations are expected to be
9616          substantially slower.
9617
9618 [page 230]
9619
9620 9   The macros
9621               MATH_ERRNO
9622               MATH_ERREXCEPT
9623     expand to the integer constants 1 and 2, respectively; the macro
9624             math_errhandling
9625     expands to an expression that has type int and the value MATH_ERRNO,
9626     MATH_ERREXCEPT, or the bitwise OR of both. The value of math_errhandling is
9627     constant for the duration of the program. It is unspecified whether
9628     math_errhandling is a macro or an identifier with external linkage. If a macro
9629     definition is suppressed or a program defines an identifier with the name
9630     math_errhandling, the behavior is undefined.               If the expression
9631     math_errhandling & MATH_ERREXCEPT can be nonzero, the implementation
9632     shall define the macros FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in
9633     <fenv.h>.
9634     7.12.1 Treatment of error conditions
9635 1   The behavior of each of the functions in <math.h> is specified for all representable
9636     values of its input arguments, except where stated otherwise. Each function shall execute
9637     as if it were a single operation without raising SIGFPE and without generating any of the
9638     exceptions ''invalid'', ''divide-by-zero'', or ''overflow'' except to reflect the result of the
9639     function.
9640 2   For all functions, a domain error occurs if an input argument is outside the domain over
9641     which the mathematical function is defined. The description of each function lists any
9642     required domain errors; an implementation may define additional domain errors, provided
9643     that such errors are consistent with the mathematical definition of the function.226) On a
9644     domain error, the function returns an implementation-defined value; if the integer
9645     expression math_errhandling & MATH_ERRNO is nonzero, the integer expression
9646     errno acquires the value EDOM; if the integer expression math_errhandling &
9647     MATH_ERREXCEPT is nonzero, the ''invalid'' floating-point exception is raised.
9648 3   Similarly, a pole error (also known as a singularity or infinitary) occurs if the
9649     mathematical function has an exact infinite result as the finite input argument(s) are
9650     approached in the limit (for example, log(0.0)). The description of each function lists
9651     any required pole errors; an implementation may define additional pole errors, provided
9652     that such errors are consistent with the mathematical definition of the function. On a pole
9653     error, the function returns an implementation-defined value; if the integer expression
9654
9655
9656     226) In an implementation that supports infinities, this allows an infinity as an argument to be a domain
9657          error if the mathematical domain of the function does not include the infinity.
9658
9659 [page 231]
9660
9661     math_errhandling & MATH_ERRNO is nonzero, the integer expression errno
9662     acquires the value ERANGE; if the integer expression math_errhandling &
9663     MATH_ERREXCEPT is nonzero, the ''divide-by-zero'' floating-point exception is raised.
9664 4   Likewise, a range error occurs if the mathematical result of the function cannot be
9665     represented in an object of the specified type, due to extreme magnitude.
9666 5   A floating result overflows if the magnitude of the mathematical result is finite but so
9667     large that the mathematical result cannot be represented without extraordinary roundoff
9668     error in an object of the specified type. If a floating result overflows and default rounding
9669     is in effect, then the function returns the value of the macro HUGE_VAL, HUGE_VALF, or
9670     HUGE_VALL according to the return type, with the same sign as the correct value of the
9671     function; if the integer expression math_errhandling & MATH_ERRNO is nonzero,
9672     the integer expression errno acquires the value ERANGE; if the integer expression
9673     math_errhandling & MATH_ERREXCEPT is nonzero, the ''overflow'' floating-
9674     point exception is raised.
9675 6   The result underflows if the magnitude of the mathematical result is so small that the
9676     mathematical result cannot be represented, without extraordinary roundoff error, in an
9677     object of the specified type.227) If the result underflows, the function returns an
9678     implementation-defined value whose magnitude is no greater than the smallest
9679     normalized positive number in the specified type; if the integer expression
9680     math_errhandling & MATH_ERRNO is nonzero, whether errno acquires the
9681     value    ERANGE       is    implementation-defined;     if   the  integer   expression
9682     math_errhandling & MATH_ERREXCEPT is nonzero, whether the ''underflow''
9683     floating-point exception is raised is implementation-defined.
9684 7   If a domain, pole, or range error occurs and the integer expression
9685     math_errhandling & MATH_ERRNO is zero,228) then errno shall either be set to
9686     the value corresponding to the error or left unmodified. If no such error occurs, errno
9687     shall be left unmodified regardless of the setting of math_errhandling.
9688
9689
9690
9691
9692     227) The term underflow here is intended to encompass both ''gradual underflow'' as in IEC 60559 and
9693          also ''flush-to-zero'' underflow.
9694     228) Math errors are being indicated by the floating-point exception flags rather than by errno.
9695
9696 [page 232]
9697
9698     7.12.2 The FP_CONTRACT pragma
9699     Synopsis
9700 1            #include <math.h>
9701              #pragma STDC FP_CONTRACT on-off-switch
9702     Description
9703 2   The FP_CONTRACT pragma can be used to allow (if the state is ''on'') or disallow (if the
9704     state is ''off'') the implementation to contract expressions (6.5). Each pragma can occur
9705     either outside external declarations or preceding all explicit declarations and statements
9706     inside a compound statement. When outside external declarations, the pragma takes
9707     effect from its occurrence until another FP_CONTRACT pragma is encountered, or until
9708     the end of the translation unit. When inside a compound statement, the pragma takes
9709     effect from its occurrence until another FP_CONTRACT pragma is encountered
9710     (including within a nested compound statement), or until the end of the compound
9711     statement; at the end of a compound statement the state for the pragma is restored to its
9712     condition just before the compound statement. If this pragma is used in any other
9713     context, the behavior is undefined. The default state (''on'' or ''off'') for the pragma is
9714     implementation-defined.
9715     7.12.3 Classification macros
9716 1   In the synopses in this subclause, real-floating indicates that the argument shall be an
9717     expression of real floating type.
9718     7.12.3.1 The fpclassify macro
9719     Synopsis
9720 1            #include <math.h>
9721              int fpclassify(real-floating x);
9722     Description
9723 2   The fpclassify macro classifies its argument value as NaN, infinite, normal,
9724     subnormal, zero, or into another implementation-defined category. First, an argument
9725     represented in a format wider than its semantic type is converted to its semantic type.
9726     Then classification is based on the type of the argument.229)
9727     Returns
9728 3   The fpclassify macro returns the value of the number classification macro
9729     appropriate to the value of its argument.
9730
9731
9732     229) Since an expression can be evaluated with more range and precision than its type has, it is important to
9733          know the type that classification is based on. For example, a normal long double value might
9734          become subnormal when converted to double, and zero when converted to float.
9735
9736 [page 233]
9737
9738     7.12.3.2 The isfinite macro
9739     Synopsis
9740 1           #include <math.h>
9741             int isfinite(real-floating x);
9742     Description
9743 2   The isfinite macro determines whether its argument has a finite value (zero,
9744     subnormal, or normal, and not infinite or NaN). First, an argument represented in a
9745     format wider than its semantic type is converted to its semantic type. Then determination
9746     is based on the type of the argument.
9747     Returns
9748 3   The isfinite macro returns a nonzero value if and only if its argument has a finite
9749     value.
9750     7.12.3.3 The isinf macro
9751     Synopsis
9752 1           #include <math.h>
9753             int isinf(real-floating x);
9754     Description
9755 2   The isinf macro determines whether its argument value is an infinity (positive or
9756     negative). First, an argument represented in a format wider than its semantic type is
9757     converted to its semantic type. Then determination is based on the type of the argument.
9758     Returns
9759 3   The isinf macro returns a nonzero value if and only if its argument has an infinite
9760     value.
9761     7.12.3.4 The isnan macro
9762     Synopsis
9763 1           #include <math.h>
9764             int isnan(real-floating x);
9765     Description
9766 2   The isnan macro determines whether its argument value is a NaN. First, an argument
9767     represented in a format wider than its semantic type is converted to its semantic type.
9768     Then determination is based on the type of the argument.230)
9769
9770
9771     230) For the isnan macro, the type for determination does not matter unless the implementation supports
9772          NaNs in the evaluation type but not in the semantic type.
9773
9774 [page 234]
9775
9776     Returns
9777 3   The isnan macro returns a nonzero value if and only if its argument has a NaN value.
9778     7.12.3.5 The isnormal macro
9779     Synopsis
9780 1           #include <math.h>
9781             int isnormal(real-floating x);
9782     Description
9783 2   The isnormal macro determines whether its argument value is normal (neither zero,
9784     subnormal, infinite, nor NaN). First, an argument represented in a format wider than its
9785     semantic type is converted to its semantic type. Then determination is based on the type
9786     of the argument.
9787     Returns
9788 3   The isnormal macro returns a nonzero value if and only if its argument has a normal
9789     value.
9790     7.12.3.6 The signbit macro
9791     Synopsis
9792 1           #include <math.h>
9793             int signbit(real-floating x);
9794     Description
9795 2   The signbit macro determines whether the sign of its argument value is negative.231)
9796     Returns
9797 3   The signbit macro returns a nonzero value if and only if the sign of its argument value
9798     is negative.
9799
9800
9801
9802
9803     231) The signbit macro reports the sign of all values, including infinities, zeros, and NaNs. If zero is
9804          unsigned, it is treated as positive.
9805
9806 [page 235]
9807
9808     7.12.4 Trigonometric functions
9809     7.12.4.1 The acos functions
9810     Synopsis
9811 1          #include <math.h>
9812            double acos(double x);
9813            float acosf(float x);
9814            long double acosl(long double x);
9815     Description
9816 2   The acos functions compute the principal value of the arc cosine of x. A domain error
9817     occurs for arguments not in the interval [-1, +1].
9818     Returns
9819 3   The acos functions return arccos x in the interval [0, pi ] radians.
9820     7.12.4.2 The asin functions
9821     Synopsis
9822 1          #include <math.h>
9823            double asin(double x);
9824            float asinf(float x);
9825            long double asinl(long double x);
9826     Description
9827 2   The asin functions compute the principal value of the arc sine of x. A domain error
9828     occurs for arguments not in the interval [-1, +1].
9829     Returns
9830 3   The asin functions return arcsin x in the interval [-pi /2, +pi /2] radians.
9831     7.12.4.3 The atan functions
9832     Synopsis
9833 1          #include <math.h>
9834            double atan(double x);
9835            float atanf(float x);
9836            long double atanl(long double x);
9837     Description
9838 2   The atan functions compute the principal value of the arc tangent of x.
9839
9840
9841
9842
9843 [page 236]
9844
9845     Returns
9846 3   The atan functions return arctan x in the interval [-pi /2, +pi /2] radians.
9847     7.12.4.4 The atan2 functions
9848     Synopsis
9849 1           #include <math.h>
9850             double atan2(double y, double x);
9851             float atan2f(float y, float x);
9852             long double atan2l(long double y, long double x);
9853     Description
9854 2   The atan2 functions compute the value of the arc tangent of y/x, using the signs of both
9855     arguments to determine the quadrant of the return value. A domain error may occur if
9856     both arguments are zero.
9857     Returns
9858 3   The atan2 functions return arctan y/x in the interval [-pi , +pi ] radians.
9859     7.12.4.5 The cos functions
9860     Synopsis
9861 1           #include <math.h>
9862             double cos(double x);
9863             float cosf(float x);
9864             long double cosl(long double x);
9865     Description
9866 2   The cos functions compute the cosine of x (measured in radians).
9867     Returns
9868 3   The cos functions return cos x.
9869     7.12.4.6 The sin functions
9870     Synopsis
9871 1           #include <math.h>
9872             double sin(double x);
9873             float sinf(float x);
9874             long double sinl(long double x);
9875     Description
9876 2   The sin functions compute the sine of x (measured in radians).
9877
9878
9879
9880 [page 237]
9881
9882     Returns
9883 3   The sin functions return sin x.
9884     7.12.4.7 The tan functions
9885     Synopsis
9886 1          #include <math.h>
9887            double tan(double x);
9888            float tanf(float x);
9889            long double tanl(long double x);
9890     Description
9891 2   The tan functions return the tangent of x (measured in radians).
9892     Returns
9893 3   The tan functions return tan x.
9894     7.12.5 Hyperbolic functions
9895     7.12.5.1 The acosh functions
9896     Synopsis
9897 1          #include <math.h>
9898            double acosh(double x);
9899            float acoshf(float x);
9900            long double acoshl(long double x);
9901     Description
9902 2   The acosh functions compute the (nonnegative) arc hyperbolic cosine of x. A domain
9903     error occurs for arguments less than 1.
9904     Returns
9905 3   The acosh functions return arcosh x in the interval [0, +(inf)].
9906     7.12.5.2 The asinh functions
9907     Synopsis
9908 1          #include <math.h>
9909            double asinh(double x);
9910            float asinhf(float x);
9911            long double asinhl(long double x);
9912     Description
9913 2   The asinh functions compute the arc hyperbolic sine of x.
9914
9915
9916 [page 238]
9917
9918     Returns
9919 3   The asinh functions return arsinh x.
9920     7.12.5.3 The atanh functions
9921     Synopsis
9922 1           #include <math.h>
9923             double atanh(double x);
9924             float atanhf(float x);
9925             long double atanhl(long double x);
9926     Description
9927 2   The atanh functions compute the arc hyperbolic tangent of x. A domain error occurs
9928     for arguments not in the interval [-1, +1]. A pole error may occur if the argument equals
9929     -1 or +1.
9930     Returns
9931 3   The atanh functions return artanh x.
9932     7.12.5.4 The cosh functions
9933     Synopsis
9934 1           #include <math.h>
9935             double cosh(double x);
9936             float coshf(float x);
9937             long double coshl(long double x);
9938     Description
9939 2   The cosh functions compute the hyperbolic cosine of x. A range error occurs if the
9940     magnitude of x is too large.
9941     Returns
9942 3   The cosh functions return cosh x.
9943     7.12.5.5 The sinh functions
9944     Synopsis
9945 1           #include <math.h>
9946             double sinh(double x);
9947             float sinhf(float x);
9948             long double sinhl(long double x);
9949     Description
9950 2   The sinh functions compute the hyperbolic sine of x. A range error occurs if the
9951     magnitude of x is too large.
9952 [page 239]
9953
9954     Returns
9955 3   The sinh functions return sinh x.
9956     7.12.5.6 The tanh functions
9957     Synopsis
9958 1          #include <math.h>
9959            double tanh(double x);
9960            float tanhf(float x);
9961            long double tanhl(long double x);
9962     Description
9963 2   The tanh functions compute the hyperbolic tangent of x.
9964     Returns
9965 3   The tanh functions return tanh x.
9966     7.12.6 Exponential and logarithmic functions
9967     7.12.6.1 The exp functions
9968     Synopsis
9969 1          #include <math.h>
9970            double exp(double x);
9971            float expf(float x);
9972            long double expl(long double x);
9973     Description
9974 2   The exp functions compute the base-e exponential of x. A range error occurs if the
9975     magnitude of x is too large.
9976     Returns
9977 3   The exp functions return ex .
9978     7.12.6.2 The exp2 functions
9979     Synopsis
9980 1          #include <math.h>
9981            double exp2(double x);
9982            float exp2f(float x);
9983            long double exp2l(long double x);
9984     Description
9985 2   The exp2 functions compute the base-2 exponential of x. A range error occurs if the
9986     magnitude of x is too large.
9987
9988 [page 240]
9989
9990     Returns
9991 3   The exp2 functions return 2x .
9992     7.12.6.3 The expm1 functions
9993     Synopsis
9994 1           #include <math.h>
9995             double expm1(double x);
9996             float expm1f(float x);
9997             long double expm1l(long double x);
9998     Description
9999 2   The expm1 functions compute the base-e exponential of the argument, minus 1. A range
10000     error occurs if x is too large.232)
10001     Returns
10002 3   The expm1 functions return ex - 1.
10003     7.12.6.4 The frexp functions
10004     Synopsis
10005 1           #include <math.h>
10006             double frexp(double value, int *exp);
10007             float frexpf(float value, int *exp);
10008             long double frexpl(long double value, int *exp);
10009     Description
10010 2   The frexp functions break a floating-point number into a normalized fraction and an
10011     integral power of 2. They store the integer in the int object pointed to by exp.
10012     Returns
10013 3   If value is not a floating-point number or if the integral power of 2 is outside the range
10014     of int, the results are unspecified. Otherwise, the frexp functions return the value x,
10015     such that x has a magnitude in the interval [1/2, 1) or zero, and value equals x x 2*exp .
10016     If value is zero, both parts of the result are zero.
10017
10018
10019
10020
10021     232) For small magnitude x, expm1(x) is expected to be more accurate than exp(x) - 1.
10022
10023 [page 241]
10024
10025     7.12.6.5 The ilogb functions
10026     Synopsis
10027 1          #include <math.h>
10028            int ilogb(double x);
10029            int ilogbf(float x);
10030            int ilogbl(long double x);
10031     Description
10032 2   The ilogb functions extract the exponent of x as a signed int value. If x is zero they
10033     compute the value FP_ILOGB0; if x is infinite they compute the value INT_MAX; if x is
10034     a NaN they compute the value FP_ILOGBNAN; otherwise, they are equivalent to calling
10035     the corresponding logb function and casting the returned value to type int. A domain
10036     error or range error may occur if x is zero, infinite, or NaN. If the correct value is outside
10037     the range of the return type, the numeric result is unspecified.
10038     Returns
10039 3   The ilogb functions return the exponent of x as a signed int value.
10040     Forward references: the logb functions (7.12.6.11).
10041     7.12.6.6 The ldexp functions
10042     Synopsis
10043 1          #include <math.h>
10044            double ldexp(double x, int exp);
10045            float ldexpf(float x, int exp);
10046            long double ldexpl(long double x, int exp);
10047     Description
10048 2   The ldexp functions multiply a floating-point number by an integral power of 2. A
10049     range error may occur.
10050     Returns
10051 3   The ldexp functions return x x 2exp .
10052     7.12.6.7 The log functions
10053     Synopsis
10054 1          #include <math.h>
10055            double log(double x);
10056            float logf(float x);
10057            long double logl(long double x);
10058
10059
10060
10061 [page 242]
10062
10063     Description
10064 2   The log functions compute the base-e (natural) logarithm of x. A domain error occurs if
10065     the argument is negative. A pole error may occur if the argument is zero.
10066     Returns
10067 3   The log functions return loge x.
10068     7.12.6.8 The log10 functions
10069     Synopsis
10070 1           #include <math.h>
10071             double log10(double x);
10072             float log10f(float x);
10073             long double log10l(long double x);
10074     Description
10075 2   The log10 functions compute the base-10 (common) logarithm of x. A domain error
10076     occurs if the argument is negative. A pole error may occur if the argument is zero.
10077     Returns
10078 3   The log10 functions return log10 x.
10079     7.12.6.9 The log1p functions
10080     Synopsis
10081 1           #include <math.h>
10082             double log1p(double x);
10083             float log1pf(float x);
10084             long double log1pl(long double x);
10085     Description
10086 2   The log1p functions compute the base-e (natural) logarithm of 1 plus the argument.233)
10087     A domain error occurs if the argument is less than -1. A pole error may occur if the
10088     argument equals -1.
10089     Returns
10090 3   The log1p functions return loge (1 + x).
10091
10092
10093
10094
10095     233) For small magnitude x, log1p(x) is expected to be more accurate than log(1 + x).
10096
10097 [page 243]
10098
10099     7.12.6.10 The log2 functions
10100     Synopsis
10101 1          #include <math.h>
10102            double log2(double x);
10103            float log2f(float x);
10104            long double log2l(long double x);
10105     Description
10106 2   The log2 functions compute the base-2 logarithm of x. A domain error occurs if the
10107     argument is less than zero. A pole error may occur if the argument is zero.
10108     Returns
10109 3   The log2 functions return log2 x.
10110     7.12.6.11 The logb functions
10111     Synopsis
10112 1          #include <math.h>
10113            double logb(double x);
10114            float logbf(float x);
10115            long double logbl(long double x);
10116     Description
10117 2   The logb functions extract the exponent of x, as a signed integer value in floating-point
10118     format. If x is subnormal it is treated as though it were normalized; thus, for positive
10119     finite x,
10120           1 <= x x FLT_RADIX-logb(x) < FLT_RADIX
10121     A domain error or pole error may occur if the argument is zero.
10122     Returns
10123 3   The logb functions return the signed exponent of x.
10124     7.12.6.12 The modf functions
10125     Synopsis
10126 1          #include <math.h>
10127            double modf(double value, double *iptr);
10128            float modff(float value, float *iptr);
10129            long double modfl(long double value, long double *iptr);
10130     Description
10131 2   The modf functions break the argument value into integral and fractional parts, each of
10132     which has the same type and sign as the argument. They store the integral part (in
10133 [page 244]
10134
10135     floating-point format) in the object pointed to by iptr.
10136     Returns
10137 3   The modf functions return the signed fractional part of value.
10138     7.12.6.13 The scalbn and scalbln functions
10139     Synopsis
10140 1           #include <math.h>
10141             double scalbn(double x, int n);
10142             float scalbnf(float x, int n);
10143             long double scalbnl(long double x, int n);
10144             double scalbln(double x, long int n);
10145             float scalblnf(float x, long int n);
10146             long double scalblnl(long double x, long int n);
10147     Description
10148 2   The scalbn and scalbln functions compute x x FLT_RADIXn efficiently, not
10149     normally by computing FLT_RADIXn explicitly. A range error may occur.
10150     Returns
10151 3   The scalbn and scalbln functions return x x FLT_RADIXn .
10152     7.12.7 Power and absolute-value functions
10153     7.12.7.1 The cbrt functions
10154     Synopsis
10155 1           #include <math.h>
10156             double cbrt(double x);
10157             float cbrtf(float x);
10158             long double cbrtl(long double x);
10159     Description
10160 2   The cbrt functions compute the real cube root of x.
10161     Returns
10162 3   The cbrt functions return x1/3 .
10163
10164
10165
10166
10167 [page 245]
10168
10169     7.12.7.2 The fabs functions
10170     Synopsis
10171 1          #include <math.h>
10172            double fabs(double x);
10173            float fabsf(float x);
10174            long double fabsl(long double x);
10175     Description
10176 2   The fabs functions compute the absolute value of a floating-point number x.
10177     Returns
10178 3   The fabs functions return | x |.
10179     7.12.7.3 The hypot functions
10180     Synopsis
10181 1          #include <math.h>
10182            double hypot(double x, double y);
10183            float hypotf(float x, float y);
10184            long double hypotl(long double x, long double y);
10185     Description
10186 2   The hypot functions compute the square root of the sum of the squares of x and y,
10187     without undue overflow or underflow. A range error may occur.
10188 3   Returns
10189 4   The hypot functions return sqrt:x2 + y2 .
10190                                -
10191                                -----
10192     7.12.7.4 The pow functions
10193     Synopsis
10194 1          #include <math.h>
10195            double pow(double x, double y);
10196            float powf(float x, float y);
10197            long double powl(long double x, long double y);
10198     Description
10199 2   The pow functions compute x raised to the power y. A domain error occurs if x is finite
10200     and negative and y is finite and not an integer value. A range error may occur. A domain
10201     error may occur if x is zero and y is zero. A domain error or pole error may occur if x is
10202     zero and y is less than zero.
10203
10204
10205
10206
10207 [page 246]
10208
10209     Returns
10210 3   The pow functions return xy .
10211     7.12.7.5 The sqrt functions
10212     Synopsis
10213 1           #include <math.h>
10214             double sqrt(double x);
10215             float sqrtf(float x);
10216             long double sqrtl(long double x);
10217     Description
10218 2   The sqrt functions compute the nonnegative square root of x. A domain error occurs if
10219     the argument is less than zero.
10220     Returns
10221 3   The sqrt functions return sqrt:x.
10222                               -
10223                               -
10224     7.12.8 Error and gamma functions
10225     7.12.8.1 The erf functions
10226     Synopsis
10227 1           #include <math.h>
10228             double erf(double x);
10229             float erff(float x);
10230             long double erfl(long double x);
10231     Description
10232 2   The erf functions compute the error function of x.
10233     Returns
10234 3                                      2        x
10235                                             (integral)       e-t dt.
10236                                                       2
10237     The erf functions return erf x =
10238                                        sqrt:pi
10239                                        -
10240                                        -    0
10241
10242     7.12.8.2 The erfc functions
10243     Synopsis
10244 1           #include <math.h>
10245             double erfc(double x);
10246             float erfcf(float x);
10247             long double erfcl(long double x);
10248     Description
10249 2   The erfc functions compute the complementary error function of x. A range error
10250     occurs if x is too large.
10251 [page 247]
10252
10253     Returns
10254 3                                                       2       (inf)
10255                                                             (integral)       e-t dt.
10256                                                                       2
10257     The erfc functions return erfc x = 1 - erf x =
10258                                                      sqrt:pi
10259                                                      -
10260                                                      -      x
10261
10262     7.12.8.3 The lgamma functions
10263     Synopsis
10264 1          #include <math.h>
10265            double lgamma(double x);
10266            float lgammaf(float x);
10267            long double lgammal(long double x);
10268     Description
10269 2   The lgamma functions compute the natural logarithm of the absolute value of gamma of
10270     x. A range error occurs if x is too large. A pole error may occur if x is a negative integer
10271     or zero.
10272     Returns
10273 3   The lgamma functions return loge | (Gamma)(x) |.
10274     7.12.8.4 The tgamma functions
10275     Synopsis
10276 1          #include <math.h>
10277            double tgamma(double x);
10278            float tgammaf(float x);
10279            long double tgammal(long double x);
10280     Description
10281 2   The tgamma functions compute the gamma function of x. A domain error or pole error
10282     may occur if x is a negative integer or zero. A range error occurs if the magnitude of x is
10283     too large and may occur if the magnitude of x is too small.
10284     Returns
10285 3   The tgamma functions return (Gamma)(x).
10286
10287
10288
10289
10290 [page 248]
10291
10292     7.12.9 Nearest integer functions
10293     7.12.9.1 The ceil functions
10294     Synopsis
10295 1           #include <math.h>
10296             double ceil(double x);
10297             float ceilf(float x);
10298             long double ceill(long double x);
10299     Description
10300 2   The ceil functions compute the smallest integer value not less than x.
10301     Returns
10302 3   The ceil functions return [^x^], expressed as a floating-point number.
10303     7.12.9.2 The floor functions
10304     Synopsis
10305 1           #include <math.h>
10306             double floor(double x);
10307             float floorf(float x);
10308             long double floorl(long double x);
10309     Description
10310 2   The floor functions compute the largest integer value not greater than x.
10311     Returns
10312 3   The floor functions return [_x_], expressed as a floating-point number.
10313     7.12.9.3 The nearbyint functions
10314     Synopsis
10315 1           #include <math.h>
10316             double nearbyint(double x);
10317             float nearbyintf(float x);
10318             long double nearbyintl(long double x);
10319     Description
10320 2   The nearbyint functions round their argument to an integer value in floating-point
10321     format, using the current rounding direction and without raising the ''inexact'' floating-
10322     point exception.
10323
10324
10325
10326
10327 [page 249]
10328
10329     Returns
10330 3   The nearbyint functions return the rounded integer value.
10331     7.12.9.4 The rint functions
10332     Synopsis
10333 1          #include <math.h>
10334            double rint(double x);
10335            float rintf(float x);
10336            long double rintl(long double x);
10337     Description
10338 2   The rint functions differ from the nearbyint functions (7.12.9.3) only in that the
10339     rint functions may raise the ''inexact'' floating-point exception if the result differs in
10340     value from the argument.
10341     Returns
10342 3   The rint functions return the rounded integer value.
10343     7.12.9.5 The lrint and llrint functions
10344     Synopsis
10345 1          #include <math.h>
10346            long int lrint(double x);
10347            long int lrintf(float x);
10348            long int lrintl(long double x);
10349            long long int llrint(double x);
10350            long long int llrintf(float x);
10351            long long int llrintl(long double x);
10352     Description
10353 2   The lrint and llrint functions round their argument to the nearest integer value,
10354     rounding according to the current rounding direction. If the rounded value is outside the
10355     range of the return type, the numeric result is unspecified and a domain error or range
10356     error may occur.
10357     Returns
10358 3   The lrint and llrint functions return the rounded integer value.
10359
10360
10361
10362
10363 [page 250]
10364
10365     7.12.9.6 The round functions
10366     Synopsis
10367 1           #include <math.h>
10368             double round(double x);
10369             float roundf(float x);
10370             long double roundl(long double x);
10371     Description
10372 2   The round functions round their argument to the nearest integer value in floating-point
10373     format, rounding halfway cases away from zero, regardless of the current rounding
10374     direction.
10375     Returns
10376 3   The round functions return the rounded integer value.
10377     7.12.9.7 The lround and llround functions
10378     Synopsis
10379 1           #include <math.h>
10380             long int lround(double x);
10381             long int lroundf(float x);
10382             long int lroundl(long double x);
10383             long long int llround(double x);
10384             long long int llroundf(float x);
10385             long long int llroundl(long double x);
10386     Description
10387 2   The lround and llround functions round their argument to the nearest integer value,
10388     rounding halfway cases away from zero, regardless of the current rounding direction. If
10389     the rounded value is outside the range of the return type, the numeric result is unspecified
10390     and a domain error or range error may occur.
10391     Returns
10392 3   The lround and llround functions return the rounded integer value.
10393     7.12.9.8 The trunc functions
10394     Synopsis
10395 1           #include <math.h>
10396             double trunc(double x);
10397             float truncf(float x);
10398             long double truncl(long double x);
10399
10400
10401 [page 251]
10402
10403     Description
10404 2   The trunc functions round their argument to the integer value, in floating format,
10405     nearest to but no larger in magnitude than the argument.
10406     Returns
10407 3   The trunc functions return the truncated integer value.
10408     7.12.10 Remainder functions
10409     7.12.10.1 The fmod functions
10410     Synopsis
10411 1            #include <math.h>
10412              double fmod(double x, double y);
10413              float fmodf(float x, float y);
10414              long double fmodl(long double x, long double y);
10415     Description
10416 2   The fmod functions compute the floating-point remainder of x/y.
10417     Returns
10418 3   The fmod functions return the value x - ny, for some integer n such that, if y is nonzero,
10419     the result has the same sign as x and magnitude less than the magnitude of y. If y is zero,
10420     whether a domain error occurs or the fmod functions return zero is implementation-
10421     defined.
10422     7.12.10.2 The remainder functions
10423     Synopsis
10424 1            #include <math.h>
10425              double remainder(double x, double y);
10426              float remainderf(float x, float y);
10427              long double remainderl(long double x, long double y);
10428     Description
10429 2   The remainder functions compute the remainder x REM y required by IEC 60559.234)
10430
10431
10432
10433
10434     234) ''When y != 0, the remainder r = x REM y is defined regardless of the rounding mode by the
10435          mathematical relation r = x - ny, where n is the integer nearest the exact value of x/y; whenever
10436          | n - x/y | = 1/2, then n is even. If r = 0, its sign shall be that of x.'' This definition is applicable for
10437          all implementations.
10438
10439 [page 252]
10440
10441     Returns
10442 3   The remainder functions return x REM y. If y is zero, whether a domain error occurs
10443     or the functions return zero is implementation defined.
10444     7.12.10.3 The remquo functions
10445     Synopsis
10446 1           #include <math.h>
10447             double remquo(double x, double y, int *quo);
10448             float remquof(float x, float y, int *quo);
10449             long double remquol(long double x, long double y,
10450                  int *quo);
10451     Description
10452 2   The remquo functions compute the same remainder as the remainder functions. In
10453     the object pointed to by quo they store a value whose sign is the sign of x/y and whose
10454     magnitude is congruent modulo 2n to the magnitude of the integral quotient of x/y, where
10455     n is an implementation-defined integer greater than or equal to 3.
10456     Returns
10457 3   The remquo functions return x REM y. If y is zero, the value stored in the object
10458     pointed to by quo is unspecified and whether a domain error occurs or the functions
10459     return zero is implementation defined.
10460     7.12.11 Manipulation functions
10461     7.12.11.1 The copysign functions
10462     Synopsis
10463 1           #include <math.h>
10464             double copysign(double x, double y);
10465             float copysignf(float x, float y);
10466             long double copysignl(long double x, long double y);
10467     Description
10468 2   The copysign functions produce a value with the magnitude of x and the sign of y.
10469     They produce a NaN (with the sign of y) if x is a NaN. On implementations that
10470     represent a signed zero but do not treat negative zero consistently in arithmetic
10471     operations, the copysign functions regard the sign of zero as positive.
10472     Returns
10473 3   The copysign functions return a value with the magnitude of x and the sign of y.
10474
10475
10476
10477 [page 253]
10478
10479     7.12.11.2 The nan functions
10480     Synopsis
10481 1           #include <math.h>
10482             double nan(const char *tagp);
10483             float nanf(const char *tagp);
10484             long double nanl(const char *tagp);
10485     Description
10486 2   The call nan("n-char-sequence") is equivalent to strtod("NAN(n-char-
10487     sequence)",     (char**)       NULL); the call nan("") is equivalent to
10488     strtod("NAN()", (char**) NULL). If tagp does not point to an n-char
10489     sequence or an empty string, the call is equivalent to strtod("NAN", (char**)
10490     NULL). Calls to nanf and nanl are equivalent to the corresponding calls to strtof
10491     and strtold.
10492     Returns
10493 3   The nan functions return a quiet NaN, if available, with content indicated through tagp.
10494     If the implementation does not support quiet NaNs, the functions return zero.
10495     Forward references: the strtod, strtof, and strtold functions (7.22.1.3).
10496     7.12.11.3 The nextafter functions
10497     Synopsis
10498 1           #include <math.h>
10499             double nextafter(double x, double y);
10500             float nextafterf(float x, float y);
10501             long double nextafterl(long double x, long double y);
10502     Description
10503 2   The nextafter functions determine the next representable value, in the type of the
10504     function, after x in the direction of y, where x and y are first converted to the type of the
10505     function.235) The nextafter functions return y if x equals y. A range error may occur
10506     if the magnitude of x is the largest finite value representable in the type and the result is
10507     infinite or not representable in the type.
10508     Returns
10509 3   The nextafter functions return the next representable value in the specified format
10510     after x in the direction of y.
10511
10512
10513     235) The argument values are converted to the type of the function, even by a macro implementation of the
10514          function.
10515
10516 [page 254]
10517
10518     7.12.11.4 The nexttoward functions
10519     Synopsis
10520 1           #include <math.h>
10521             double nexttoward(double x, long double y);
10522             float nexttowardf(float x, long double y);
10523             long double nexttowardl(long double x, long double y);
10524     Description
10525 2   The nexttoward functions are equivalent to the nextafter functions except that the
10526     second parameter has type long double and the functions return y converted to the
10527     type of the function if x equals y.236)
10528     7.12.12 Maximum, minimum, and positive difference functions
10529     7.12.12.1 The fdim functions
10530     Synopsis
10531 1           #include <math.h>
10532             double fdim(double x, double y);
10533             float fdimf(float x, float y);
10534             long double fdiml(long double x, long double y);
10535     Description
10536 2   The fdim functions determine the positive difference between their arguments:
10537           {x - y if x > y
10538           {
10539           {+0     if x <= y
10540     A range error may occur.
10541     Returns
10542 3   The fdim functions return the positive difference value.
10543     7.12.12.2 The fmax functions
10544     Synopsis
10545 1           #include <math.h>
10546             double fmax(double x, double y);
10547             float fmaxf(float x, float y);
10548             long double fmaxl(long double x, long double y);
10549
10550
10551
10552     236) The result of the nexttoward functions is determined in the type of the function, without loss of
10553          range or precision in a floating second argument.
10554
10555 [page 255]
10556
10557     Description
10558 2   The fmax functions determine the maximum numeric value of their arguments.237)
10559     Returns
10560 3   The fmax functions return the maximum numeric value of their arguments.
10561     7.12.12.3 The fmin functions
10562     Synopsis
10563 1           #include <math.h>
10564             double fmin(double x, double y);
10565             float fminf(float x, float y);
10566             long double fminl(long double x, long double y);
10567     Description
10568 2   The fmin functions determine the minimum numeric value of their arguments.238)
10569     Returns
10570 3   The fmin functions return the minimum numeric value of their arguments.
10571     7.12.13 Floating multiply-add
10572     7.12.13.1 The fma functions
10573     Synopsis
10574 1           #include <math.h>
10575             double fma(double x, double y, double z);
10576             float fmaf(float x, float y, float z);
10577             long double fmal(long double x, long double y,
10578                  long double z);
10579     Description
10580 2   The fma functions compute (x x y) + z, rounded as one ternary operation: they compute
10581     the value (as if) to infinite precision and round once to the result format, according to the
10582     current rounding mode. A range error may occur.
10583     Returns
10584 3   The fma functions return (x x y) + z, rounded as one ternary operation.
10585
10586
10587
10588
10589     237) NaN arguments are treated as missing data: if one argument is a NaN and the other numeric, then the
10590          fmax functions choose the numeric value. See F.10.9.2.
10591     238) The fmin functions are analogous to the fmax functions in their treatment of NaNs.
10592
10593 [page 256]
10594
10595     7.12.14 Comparison macros
10596 1   The relational and equality operators support the usual mathematical relationships
10597     between numeric values. For any ordered pair of numeric values exactly one of the
10598     relationships -- less, greater, and equal -- is true. Relational operators may raise the
10599     ''invalid'' floating-point exception when argument values are NaNs. For a NaN and a
10600     numeric value, or for two NaNs, just the unordered relationship is true.239) The following
10601     subclauses provide macros that are quiet (non floating-point exception raising) versions
10602     of the relational operators, and other comparison macros that facilitate writing efficient
10603     code that accounts for NaNs without suffering the ''invalid'' floating-point exception. In
10604     the synopses in this subclause, real-floating indicates that the argument shall be an
10605     expression of real floating type (both arguments need not have the same type).240)
10606     7.12.14.1 The isgreater macro
10607     Synopsis
10608 1            #include <math.h>
10609              int isgreater(real-floating x, real-floating y);
10610     Description
10611 2   The isgreater macro determines whether its first argument is greater than its second
10612     argument. The value of isgreater(x, y) is always equal to (x) > (y); however,
10613     unlike (x) > (y), isgreater(x, y) does not raise the ''invalid'' floating-point
10614     exception when x and y are unordered.
10615     Returns
10616 3   The isgreater macro returns the value of (x) > (y).
10617     7.12.14.2 The isgreaterequal macro
10618     Synopsis
10619 1            #include <math.h>
10620              int isgreaterequal(real-floating x, real-floating y);
10621     Description
10622 2   The isgreaterequal macro determines whether its first argument is greater than or
10623     equal to its second argument. The value of isgreaterequal(x, y) is always equal
10624     to (x) >= (y); however, unlike (x) >= (y), isgreaterequal(x, y) does
10625
10626
10627     239) IEC 60559 requires that the built-in relational operators raise the ''invalid'' floating-point exception if
10628          the operands compare unordered, as an error indicator for programs written without consideration of
10629          NaNs; the result in these cases is false.
10630     240) Whether an argument represented in a format wider than its semantic type is converted to the semantic
10631          type is unspecified.
10632
10633 [page 257]
10634
10635     not raise the ''invalid'' floating-point exception when x and y are unordered.
10636     Returns
10637 3   The isgreaterequal macro returns the value of (x) >= (y).
10638     7.12.14.3 The isless macro
10639     Synopsis
10640 1          #include <math.h>
10641            int isless(real-floating x, real-floating y);
10642     Description
10643 2   The isless macro determines whether its first argument is less than its second
10644     argument. The value of isless(x, y) is always equal to (x) < (y); however,
10645     unlike (x) < (y), isless(x, y) does not raise the ''invalid'' floating-point
10646     exception when x and y are unordered.
10647     Returns
10648 3   The isless macro returns the value of (x) < (y).
10649     7.12.14.4 The islessequal macro
10650     Synopsis
10651 1          #include <math.h>
10652            int islessequal(real-floating x, real-floating y);
10653     Description
10654 2   The islessequal macro determines whether its first argument is less than or equal to
10655     its second argument. The value of islessequal(x, y) is always equal to
10656     (x) <= (y); however, unlike (x) <= (y), islessequal(x, y) does not raise
10657     the ''invalid'' floating-point exception when x and y are unordered.
10658     Returns
10659 3   The islessequal macro returns the value of (x) <= (y).
10660     7.12.14.5 The islessgreater macro
10661     Synopsis
10662 1          #include <math.h>
10663            int islessgreater(real-floating x, real-floating y);
10664     Description
10665 2   The islessgreater macro determines whether its first argument is less than or
10666     greater than its second argument. The islessgreater(x, y) macro is similar to
10667     (x) < (y) || (x) > (y); however, islessgreater(x, y) does not raise
10668
10669 [page 258]
10670
10671     the ''invalid'' floating-point exception when x and y are unordered (nor does it evaluate x
10672     and y twice).
10673     Returns
10674 3   The islessgreater macro returns the value of (x) < (y) || (x) > (y).
10675     7.12.14.6 The isunordered macro
10676     Synopsis
10677 1           #include <math.h>
10678             int isunordered(real-floating x, real-floating y);
10679     Description
10680 2   The isunordered macro determines whether its arguments are unordered.
10681     Returns
10682 3   The isunordered macro returns 1 if its arguments are unordered and 0 otherwise.
10683
10684
10685
10686
10687 [page 259]
10688
10689     7.13 Nonlocal jumps <setjmp.h>
10690 1   The header <setjmp.h> defines the macro setjmp, and declares one function and
10691     one type, for bypassing the normal function call and return discipline.241)
10692 2   The type declared is
10693             jmp_buf
10694     which is an array type suitable for holding the information needed to restore a calling
10695     environment. The environment of a call to the setjmp macro consists of information
10696     sufficient for a call to the longjmp function to return execution to the correct block and
10697     invocation of that block, were it called recursively. It does not include the state of the
10698     floating-point status flags, of open files, or of any other component of the abstract
10699     machine.
10700 3   It is unspecified whether setjmp is a macro or an identifier declared with external
10701     linkage. If a macro definition is suppressed in order to access an actual function, or a
10702     program defines an external identifier with the name setjmp, the behavior is undefined.
10703     7.13.1 Save calling environment
10704     7.13.1.1 The setjmp macro
10705     Synopsis
10706 1           #include <setjmp.h>
10707             int setjmp(jmp_buf env);
10708     Description
10709 2   The setjmp macro saves its calling environment in its jmp_buf argument for later use
10710     by the longjmp function.
10711     Returns
10712 3   If the return is from a direct invocation, the setjmp macro returns the value zero. If the
10713     return is from a call to the longjmp function, the setjmp macro returns a nonzero
10714     value.
10715     Environmental limits
10716 4   An invocation of the setjmp macro shall appear only in one of the following contexts:
10717     -- the entire controlling expression of a selection or iteration statement;
10718     -- one operand of a relational or equality operator with the other operand an integer
10719       constant expression, with the resulting expression being the entire controlling
10720
10721
10722     241) These functions are useful for dealing with unusual conditions encountered in a low-level function of
10723          a program.
10724
10725 [page 260]
10726
10727         expression of a selection or iteration statement;
10728     -- the operand of a unary ! operator with the resulting expression being the entire
10729       controlling expression of a selection or iteration statement; or
10730     -- the entire expression of an expression statement (possibly cast to void).
10731 5   If the invocation appears in any other context, the behavior is undefined.
10732     7.13.2 Restore calling environment
10733     7.13.2.1 The longjmp function
10734     Synopsis
10735 1            #include <setjmp.h>
10736              _Noreturn void longjmp(jmp_buf env, int val);
10737     Description
10738 2   The longjmp function restores the environment saved by the most recent invocation of
10739     the setjmp macro in the same invocation of the program with the corresponding
10740     jmp_buf argument. If there has been no such invocation, or if the function containing
10741     the invocation of the setjmp macro has terminated execution242) in the interim, or if the
10742     invocation of the setjmp macro was within the scope of an identifier with variably
10743     modified type and execution has left that scope in the interim, the behavior is undefined.
10744 3   All accessible objects have values, and all other components of the abstract machine243)
10745     have state, as of the time the longjmp function was called, except that the values of
10746     objects of automatic storage duration that are local to the function containing the
10747     invocation of the corresponding setjmp macro that do not have volatile-qualified type
10748     and have been changed between the setjmp invocation and longjmp call are
10749     indeterminate.
10750     Returns
10751 4   After longjmp is completed, program execution continues as if the corresponding
10752     invocation of the setjmp macro had just returned the value specified by val. The
10753     longjmp function cannot cause the setjmp macro to return the value 0; if val is 0,
10754     the setjmp macro returns the value 1.
10755 5   EXAMPLE The longjmp function that returns control back to the point of the setjmp invocation
10756     might cause memory associated with a variable length array object to be squandered.
10757
10758
10759
10760
10761     242) For example, by executing a return statement or because another longjmp call has caused a
10762          transfer to a setjmp invocation in a function earlier in the set of nested calls.
10763     243) This includes, but is not limited to, the floating-point status flags and the state of open files.
10764
10765 [page 261]
10766
10767       #include <setjmp.h>
10768       jmp_buf buf;
10769       void g(int n);
10770       void h(int n);
10771       int n = 6;
10772       void f(void)
10773       {
10774             int x[n];             // valid: f is not terminated
10775             setjmp(buf);
10776             g(n);
10777       }
10778       void g(int n)
10779       {
10780             int a[n];             // a may remain allocated
10781             h(n);
10782       }
10783       void h(int n)
10784       {
10785             int b[n];             // b may remain allocated
10786             longjmp(buf, 2);      // might cause memory loss
10787       }
10788
10789
10790
10791
10792 [page 262]
10793
10794     7.14 Signal handling <signal.h>
10795 1   The header <signal.h> declares a type and two functions and defines several macros,
10796     for handling various signals (conditions that may be reported during program execution).
10797 2   The type defined is
10798              sig_atomic_t
10799     which is the (possibly volatile-qualified) integer type of an object that can be accessed as
10800     an atomic entity, even in the presence of asynchronous interrupts.
10801 3   The macros defined are
10802              SIG_DFL
10803              SIG_ERR
10804              SIG_IGN
10805     which expand to constant expressions with distinct values that have type compatible with
10806     the second argument to, and the return value of, the signal function, and whose values
10807     compare unequal to the address of any declarable function; and the following, which
10808     expand to positive integer constant expressions with type int and distinct values that are
10809     the signal numbers, each corresponding to the specified condition:
10810              SIGABRT abnormal termination, such as is initiated by the abort function
10811              SIGFPE        an erroneous arithmetic operation, such as zero divide or an operation
10812                            resulting in overflow
10813              SIGILL        detection of an invalid function image, such as an invalid instruction
10814              SIGINT        receipt of an interactive attention signal
10815              SIGSEGV an invalid access to storage
10816              SIGTERM a termination request sent to the program
10817 4   An implementation need not generate any of these signals, except as a result of explicit
10818     calls to the raise function. Additional signals and pointers to undeclarable functions,
10819     with macro definitions beginning, respectively, with the letters SIG and an uppercase
10820     letter or with SIG_ and an uppercase letter,244) may also be specified by the
10821     implementation. The complete set of signals, their semantics, and their default handling
10822     is implementation-defined; all signal numbers shall be positive.
10823
10824
10825
10826
10827     244) See ''future library directions'' (7.30.6). The names of the signal numbers reflect the following terms
10828          (respectively): abort, floating-point exception, illegal instruction, interrupt, segmentation violation,
10829          and termination.
10830
10831 [page 263]
10832
10833     7.14.1 Specify signal handling
10834     7.14.1.1 The signal function
10835     Synopsis
10836 1           #include <signal.h>
10837             void (*signal(int sig, void (*func)(int)))(int);
10838     Description
10839 2   The signal function chooses one of three ways in which receipt of the signal number
10840     sig is to be subsequently handled. If the value of func is SIG_DFL, default handling
10841     for that signal will occur. If the value of func is SIG_IGN, the signal will be ignored.
10842     Otherwise, func shall point to a function to be called when that signal occurs. An
10843     invocation of such a function because of a signal, or (recursively) of any further functions
10844     called by that invocation (other than functions in the standard library), is called a signal
10845     handler.
10846 3   When a signal occurs and func points to a function, it is implementation-defined
10847     whether the equivalent of signal(sig, SIG_DFL); is executed or the
10848     implementation prevents some implementation-defined set of signals (at least including
10849     sig) from occurring until the current signal handling has completed; in the case of
10850     SIGILL, the implementation may alternatively define that no action is taken. Then the
10851     equivalent of (*func)(sig); is executed. If and when the function returns, if the
10852     value of sig is SIGFPE, SIGILL, SIGSEGV, or any other implementation-defined
10853     value corresponding to a computational exception, the behavior is undefined; otherwise
10854     the program will resume execution at the point it was interrupted.
10855 4   If the signal occurs as the result of calling the abort or raise function, the signal
10856     handler shall not call the raise function.
10857 5   If the signal occurs other than as the result of calling the abort or raise function, the
10858     behavior is undefined if the signal handler refers to any object with static or thread
10859     storage duration other than by assigning a value to an object declared as volatile
10860     sig_atomic_t, or the signal handler calls any function in the standard library other
10861     than the abort function, the _Exit function, the quick_exit function, or the
10862     signal function with the first argument equal to the signal number corresponding to the
10863     signal that caused the invocation of the handler. Furthermore, if such a call to the
10864     signal function results in a SIG_ERR return, the value of errno is indeterminate.245)
10865 6   At program startup, the equivalent of
10866             signal(sig, SIG_IGN);
10867
10868
10869     245) If any signal is generated by an asynchronous signal handler, the behavior is undefined.
10870
10871 [page 264]
10872
10873     may be executed for some signals selected in an implementation-defined manner; the
10874     equivalent of
10875             signal(sig, SIG_DFL);
10876     is executed for all other signals defined by the implementation.
10877 7   The implementation shall behave as if no library function calls the signal function.
10878     Returns
10879 8   If the request can be honored, the signal function returns the value of func for the
10880     most recent successful call to signal for the specified signal sig. Otherwise, a value of
10881     SIG_ERR is returned and a positive value is stored in errno.
10882     Forward references: the abort function (7.22.4.1), the exit function (7.22.4.4), the
10883     _Exit function (7.22.4.5), the quick_exit function (7.22.4.7).
10884     7.14.2 Send signal
10885     7.14.2.1 The raise function
10886     Synopsis
10887 1           #include <signal.h>
10888             int raise(int sig);
10889     Description
10890 2   The raise function carries out the actions described in 7.14.1.1 for the signal sig. If a
10891     signal handler is called, the raise function shall not return until after the signal handler
10892     does.
10893     Returns
10894 3   The raise function returns zero if successful, nonzero if unsuccessful.
10895
10896
10897
10898
10899 [page 265]
10900
10901     7.15 Alignment <stdalign.h>
10902 1   The header <stdalign.h> defines two macros.
10903 2   The macro
10904            alignas
10905     expands to _Alignas.
10906 3   The remaining macro is suitable for use in #if preprocessing directives. It is
10907            __alignas_is_defined
10908     which expands to the integer constant 1.
10909
10910
10911
10912
10913 [page 266]
10914
10915     7.16 Variable arguments <stdarg.h>
10916 1   The header <stdarg.h> declares a type and defines four macros, for advancing
10917     through a list of arguments whose number and types are not known to the called function
10918     when it is translated.
10919 2   A function may be called with a variable number of arguments of varying types. As
10920     described in 6.9.1, its parameter list contains one or more parameters. The rightmost
10921     parameter plays a special role in the access mechanism, and will be designated parmN in
10922     this description.
10923 3   The type declared is
10924             va_list
10925     which is a complete object type suitable for holding information needed by the macros
10926     va_start, va_arg, va_end, and va_copy. If access to the varying arguments is
10927     desired, the called function shall declare an object (generally referred to as ap in this
10928     subclause) having type va_list. The object ap may be passed as an argument to
10929     another function; if that function invokes the va_arg macro with parameter ap, the
10930     value of ap in the calling function is indeterminate and shall be passed to the va_end
10931     macro prior to any further reference to ap.246)
10932     7.16.1 Variable argument list access macros
10933 1   The va_start and va_arg macros described in this subclause shall be implemented
10934     as macros, not functions. It is unspecified whether va_copy and va_end are macros or
10935     identifiers declared with external linkage. If a macro definition is suppressed in order to
10936     access an actual function, or a program defines an external identifier with the same name,
10937     the behavior is undefined. Each invocation of the va_start and va_copy macros
10938     shall be matched by a corresponding invocation of the va_end macro in the same
10939     function.
10940     7.16.1.1 The va_arg macro
10941     Synopsis
10942 1           #include <stdarg.h>
10943             type va_arg(va_list ap, type);
10944     Description
10945 2   The va_arg macro expands to an expression that has the specified type and the value of
10946     the next argument in the call. The parameter ap shall have been initialized by the
10947     va_start or va_copy macro (without an intervening invocation of the va_end
10948
10949     246) It is permitted to create a pointer to a va_list and pass that pointer to another function, in which
10950          case the original function may make further use of the original list after the other function returns.
10951
10952 [page 267]
10953
10954     macro for the same ap). Each invocation of the va_arg macro modifies ap so that the
10955     values of successive arguments are returned in turn. The parameter type shall be a type
10956     name specified such that the type of a pointer to an object that has the specified type can
10957     be obtained simply by postfixing a * to type. If there is no actual next argument, or if
10958     type is not compatible with the type of the actual next argument (as promoted according
10959     to the default argument promotions), the behavior is undefined, except for the following
10960     cases:
10961     -- one type is a signed integer type, the other type is the corresponding unsigned integer
10962       type, and the value is representable in both types;
10963     -- one type is pointer to void and the other is a pointer to a character type.
10964     Returns
10965 3   The first invocation of the va_arg macro after that of the va_start macro returns the
10966     value of the argument after that specified by parmN . Successive invocations return the
10967     values of the remaining arguments in succession.
10968     7.16.1.2 The va_copy macro
10969     Synopsis
10970 1          #include <stdarg.h>
10971            void va_copy(va_list dest, va_list src);
10972     Description
10973 2   The va_copy macro initializes dest as a copy of src, as if the va_start macro had
10974     been applied to dest followed by the same sequence of uses of the va_arg macro as
10975     had previously been used to reach the present state of src. Neither the va_copy nor
10976     va_start macro shall be invoked to reinitialize dest without an intervening
10977     invocation of the va_end macro for the same dest.
10978     Returns
10979 3   The va_copy macro returns no value.
10980     7.16.1.3 The va_end macro
10981     Synopsis
10982 1          #include <stdarg.h>
10983            void va_end(va_list ap);
10984     Description
10985 2   The va_end macro facilitates a normal return from the function whose variable
10986     argument list was referred to by the expansion of the va_start macro, or the function
10987     containing the expansion of the va_copy macro, that initialized the va_list ap. The
10988     va_end macro may modify ap so that it is no longer usable (without being reinitialized
10989
10990 [page 268]
10991
10992     by the va_start or va_copy macro). If there is no corresponding invocation of the
10993     va_start or va_copy macro, or if the va_end macro is not invoked before the
10994     return, the behavior is undefined.
10995     Returns
10996 3   The va_end macro returns no value.
10997     7.16.1.4 The va_start macro
10998     Synopsis
10999 1           #include <stdarg.h>
11000             void va_start(va_list ap, parmN);
11001     Description
11002 2   The va_start macro shall be invoked before any access to the unnamed arguments.
11003 3   The va_start macro initializes ap for subsequent use by the va_arg and va_end
11004     macros. Neither the va_start nor va_copy macro shall be invoked to reinitialize ap
11005     without an intervening invocation of the va_end macro for the same ap.
11006 4   The parameter parmN is the identifier of the rightmost parameter in the variable
11007     parameter list in the function definition (the one just before the , ...). If the parameter
11008     parmN is declared with the register storage class, with a function or array type, or
11009     with a type that is not compatible with the type that results after application of the default
11010     argument promotions, the behavior is undefined.
11011     Returns
11012 5   The va_start macro returns no value.
11013 6   EXAMPLE 1 The function f1 gathers into an array a list of arguments that are pointers to strings (but not
11014     more than MAXARGS arguments), then passes the array as a single argument to function f2. The number of
11015     pointers is specified by the first argument to f1.
11016             #include <stdarg.h>
11017             #define MAXARGS   31
11018             void f1(int n_ptrs, ...)
11019             {
11020                   va_list ap;
11021                   char *array[MAXARGS];
11022                   int ptr_no = 0;
11023
11024
11025
11026
11027 [page 269]
11028
11029                       if (n_ptrs > MAXARGS)
11030                             n_ptrs = MAXARGS;
11031                       va_start(ap, n_ptrs);
11032                       while (ptr_no < n_ptrs)
11033                             array[ptr_no++] = va_arg(ap, char *);
11034                       va_end(ap);
11035                       f2(n_ptrs, array);
11036              }
11037     Each call to f1 is required to have visible the definition of the function or a declaration such as
11038              void f1(int, ...);
11039
11040 7   EXAMPLE 2 The function f3 is similar, but saves the status of the variable argument list after the
11041     indicated number of arguments; after f2 has been called once with the whole list, the trailing part of the list
11042     is gathered again and passed to function f4.
11043              #include <stdarg.h>
11044              #define MAXARGS 31
11045              void f3(int n_ptrs, int f4_after, ...)
11046              {
11047                    va_list ap, ap_save;
11048                    char *array[MAXARGS];
11049                    int ptr_no = 0;
11050                    if (n_ptrs > MAXARGS)
11051                          n_ptrs = MAXARGS;
11052                    va_start(ap, f4_after);
11053                    while (ptr_no < n_ptrs) {
11054                          array[ptr_no++] = va_arg(ap, char *);
11055                          if (ptr_no == f4_after)
11056                                va_copy(ap_save, ap);
11057                    }
11058                    va_end(ap);
11059                    f2(n_ptrs, array);
11060                       // Now process the saved copy.
11061                       n_ptrs -= f4_after;
11062                       ptr_no = 0;
11063                       while (ptr_no < n_ptrs)
11064                             array[ptr_no++] = va_arg(ap_save, char *);
11065                       va_end(ap_save);
11066                       f4(n_ptrs, array);
11067              }
11068
11069
11070
11071
11072 [page 270]
11073
11074     7.17 Atomics <stdatomic.h>
11075     7.17.1 Introduction
11076 1   The header <stdatomic.h> defines several macros and declares several types and
11077     functions for performing atomic operations on data shared between threads.
11078 2   Implementations that define the macro __STDC_NO_THREADS__ need not provide
11079     this header nor support any of its facilities.
11080 3   The macros defined are the atomic lock-free macros
11081             ATOMIC_CHAR_LOCK_FREE
11082             ATOMIC_CHAR16_T_LOCK_FREE
11083             ATOMIC_CHAR32_T_LOCK_FREE
11084             ATOMIC_WCHAR_T_LOCK_FREE
11085             ATOMIC_SHORT_LOCK_FREE
11086             ATOMIC_INT_LOCK_FREE
11087             ATOMIC_LONG_LOCK_FREE
11088             ATOMIC_LLONG_LOCK_FREE
11089             ATOMIC_ADDRESS_LOCK_FREE
11090     which indicate the lock-free property of the corresponding atomic types (both signed and
11091     unsigned); and
11092             ATOMIC_FLAG_INIT
11093     which expands to an initializer for an object of type atomic_flag.
11094 4   The types include
11095               memory_order
11096     which is an enumerated type whose enumerators identify memory ordering constraints;
11097               atomic_flag
11098     which is a structure type representing a lock-free, primitive atomic flag;
11099               atomic_bool
11100     which is a structure type representing the atomic analog of the type _Bool;
11101               atomic_address
11102     which is a structure type representing the atomic analog of a pointer type; and several
11103     atomic analogs of integer types.
11104 5   In the following operation definitions:
11105     -- An A refers to one of the atomic types.
11106
11107
11108 [page 271]
11109
11110         -- A C refers to its corresponding non-atomic type. The atomic_address atomic
11111           type corresponds to the void * non-atomic type.
11112         -- An M refers to the type of the other argument for arithmetic operations. For atomic
11113           integer types, M is C. For atomic address types, M is ptrdiff_t.
11114         -- The functions not ending in _explicit have the same semantics as the
11115           corresponding _explicit function with memory_order_seq_cst for the
11116           memory_order argument.
11117     6         NOTE Many operations are volatile-qualified. The ''volatile as device register'' semantics have not
11118               changed in the standard. This qualification means that volatility is preserved when applying these
11119               operations to volatile objects.
11120
11121         7.17.2 Initialization
11122         7.17.2.1 The ATOMIC_VAR_INIT macro
11123         Synopsis
11124 1                 #include <stdatomic.h>
11125                   #define ATOMIC_VAR_INIT(C value)
11126         Description
11127 2       The ATOMIC_VAR_INIT macro expands to a token sequence suitable for initializing an
11128         atomic object of a type that is initialization-compatible with value. An atomic object
11129         with automatic storage duration that is not explicitly initialized using
11130         ATOMIC_VAR_INIT is initially in an indeterminate state; however, the default (zero)
11131         initialization for objects with static or thread-local storage duration is guaranteed to
11132         produce a valid state.
11133 3       Concurrent access to the variable being initialized, even via an atomic operation,
11134         constitutes a data race.
11135 4       EXAMPLE
11136                   atomic_int guide = ATOMIC_VAR_INIT(42);
11137
11138         7.17.2.2 The atomic_init generic function
11139         Synopsis
11140 1                 #include <stdatomic.h>
11141                   void atomic_init(volatile A *obj, C value);
11142         Description
11143 2       The atomic_init generic function initializes the atomic object pointed to by obj to
11144         the value value, while also initializing any additional state that the implementation
11145         might need to carry for the atomic object.
11146
11147
11148
11149 [page 272]
11150
11151 3   Although this function initializes an atomic object, it does not avoid data races;
11152     concurrent access to the variable being initialized, even via an atomic operation,
11153     constitutes a data race.
11154     Returns
11155 4   The atomic_init generic function returns no value.
11156 5   EXAMPLE
11157               atomic_int guide;
11158               atomic_init(&guide, 42);
11159
11160     7.17.3 Order and consistency
11161 1   The enumerated type memory_order specifies the detailed regular (non-atomic)
11162     memory synchronization operations as defined in 5.1.2.4 and may provide for operation
11163     ordering. Its enumeration constants are as follows:
11164               memory_order_relaxed
11165               memory_order_consume
11166               memory_order_acquire
11167               memory_order_release
11168               memory_order_acq_rel
11169               memory_order_seq_cst
11170 2   For memory_order_relaxed, no operation orders memory.
11171 3   For       memory_order_release,       memory_order_acq_rel,             and
11172     memory_order_seq_cst, a store operation performs a release operation on the
11173     affected memory location.
11174 4   For       memory_order_acquire,       memory_order_acq_rel,             and
11175     memory_order_seq_cst, a load operation performs an acquire operation on the
11176     affected memory location.
11177 5   For memory_order_consume, a load operation performs a consume operation on the
11178     affected memory location.
11179 6   For memory_order_seq_cst, there shall be a single total order S on all operations,
11180     consistent with the ''happens before'' order and modification orders for all affected
11181     locations, such that each memory_order_seq_cst operation that loads a value
11182     observes either the last preceding modification according to this order S, or the result of
11183     an operation that is not memory_order_seq_cst.
11184 7   NOTE 1 Although it is not explicitly required that S include lock operations, it can always be extended to
11185     an order that does include lock and unlock operations, since the ordering between those is already included
11186     in the ''happens before'' ordering.
11187
11188 8   NOTE 2 Atomic operations specifying memory_order_relaxed are relaxed only with respect to
11189     memory ordering. Implementations must still guarantee that any given atomic access to a particular atomic
11190
11191 [page 273]
11192
11193      object be indivisible with respect to all other atomic accesses to that object.
11194
11195 9    For an atomic operation B that reads the value of an atomic object M, if there is a
11196      memory_order_seq_cst fence X sequenced before B, then B observes either the
11197      last memory_order_seq_cst modification of M preceding X in the total order S or
11198      a later modification of M in its modification order.
11199 10   For atomic operations A and B on an atomic object M, where A modifies M and B takes
11200      its value, if there is a memory_order_seq_cst fence X such that A is sequenced
11201      before X and B follows X in S, then B observes either the effects of A or a later
11202      modification of M in its modification order.
11203 11   For atomic operations A and B on an atomic object M, where A modifies M and B takes
11204      its value, if there are memory_order_seq_cst fences X and Y such that A is
11205      sequenced before X, Y is sequenced before B, and X precedes Y in S, then B observes
11206      either the effects of A or a later modification of M in its modification order.
11207 12   Atomic read-modify-write operations shall always read the last value (in the modification
11208      order) stored before the write associated with the read-modify-write operation.
11209 13   An atomic store shall only store a value that has been computed from constants and
11210      program input values by a finite sequence of program evaluations, such that each
11211      evaluation observes the values of variables as computed by the last prior assignment in
11212      the sequence.247) The ordering of evaluations in this sequence shall be such that
11213      -- If an evaluation B observes a value computed by A in a different thread, then B does
11214        not happen before A.
11215      -- If an evaluation A is included in the sequence, then all evaluations that assign to the
11216        same variable and happen before A are also included.
11217 14   NOTE 3 The second requirement disallows ''out-of-thin-air'', or ''speculative'' stores of atomics when
11218      relaxed atomics are used. Since unordered operations are involved, evaluations may appear in this
11219      sequence out of thread order. For example, with x and y initially zero,
11220               // Thread 1:
11221               r1 = atomic_load_explicit(&y, memory_order_relaxed);
11222               atomic_store_explicit(&x, r1, memory_order_relaxed);
11223
11224               // Thread 2:
11225               r2 = atomic_load_explicit(&x, memory_order_relaxed);
11226               atomic_store_explicit(&y, 42, memory_order_relaxed);
11227      is allowed to produce r1 == 42 && r2 == 42. The sequence of evaluations justifying this consists of:
11228
11229
11230
11231
11232      247) Among other implications, atomic variables shall not decay.
11233
11234 [page 274]
11235
11236              atomic_store_explicit(&y, 42,               memory_order_relaxed);
11237              r1 = atomic_load_explicit(&y,               memory_order_relaxed);
11238              atomic_store_explicit(&x, r1,               memory_order_relaxed);
11239              r2 = atomic_load_explicit(&x,               memory_order_relaxed);
11240      On the other hand,
11241              // Thread 1:
11242              r1 = atomic_load_explicit(&y, memory_order_relaxed);
11243              atomic_store_explicit(&x, r1, memory_order_relaxed);
11244
11245              // Thread 2:
11246              r2 = atomic_load_explicit(&x, memory_order_relaxed);
11247              atomic_store_explicit(&y, r2, memory_order_relaxed);
11248      is not allowed to produce r1 == 42 && r2 = 42, since there is no sequence of evaluations that results
11249      in the computation of 42. In the absence of ''relaxed'' operations and read-modify-write operations with
11250      weaker than memory_order_acq_rel ordering, the second requirement has no impact.
11251
11252      Recommended practice
11253 15   The requirements do not forbid r1 == 42 && r2 == 42 in the following example,
11254      with x and y initially zero:
11255              // Thread 1:
11256              r1 = atomic_load_explicit(&x, memory_order_relaxed);
11257              if (r1 == 42)
11258                   atomic_store_explicit(&y, r1, memory_order_relaxed);
11259
11260              // Thread 2:
11261              r2 = atomic_load_explicit(&y, memory_order_relaxed);
11262              if (r2 == 42)
11263                   atomic_store_explicit(&x, 42, memory_order_relaxed);
11264      However, this is not useful behavior, and implementations should not allow it.
11265 16   Implementations should make atomic stores visible to atomic loads within a reasonable
11266      amount of time.
11267      7.17.3.1 The kill_dependency macro
11268      Synopsis
11269 1            #include <stdatomic.h>
11270              type kill_dependency(type y);
11271      Description
11272 2    The kill_dependency macro terminates a dependency chain; the argument does not
11273      carry a dependency to the return value.
11274
11275
11276
11277 [page 275]
11278
11279     Returns
11280 3   The kill_dependency macro returns the value of y.
11281     7.17.4 Fences
11282 1   This subclause introduces synchronization primitives called fences. Fences can have
11283     acquire semantics, release semantics, or both. A fence with acquire semantics is called
11284     an acquire fence; a fence with release semantics is called a release fence.
11285 2   A release fence A synchronizes with an acquire fence B if there exist atomic operations
11286     X and Y , both operating on some atomic object M, such that A is sequenced before X, X
11287     modifies M, Y is sequenced before B, and Y reads the value written by X or a value
11288     written by any side effect in the hypothetical release sequence X would head if it were a
11289     release operation.
11290 3   A release fence A synchronizes with an atomic operation B that performs an acquire
11291     operation on an atomic object M if there exists an atomic operation X such that A is
11292     sequenced before X, X modifies M, and B reads the value written by X or a value written
11293     by any side effect in the hypothetical release sequence X would head if it were a release
11294     operation.
11295 4   An atomic operation A that is a release operation on an atomic object M synchronizes
11296     with an acquire fence B if there exists some atomic operation X on M such that X is
11297     sequenced before B and reads the value written by A or a value written by any side effect
11298     in the release sequence headed by A.
11299     7.17.4.1 The atomic_thread_fence function
11300     Synopsis
11301 1          #include <stdatomic.h>
11302            void atomic_thread_fence(memory_order order);
11303     Description
11304 2   Depending on the value of order, this operation:
11305     -- has no effects, if order == memory_order_relaxed;
11306     -- is an acquire fence, if order == memory_order_acquire or order ==
11307       memory_order_consume;
11308     -- is a release fence, if order == memory_order_release;
11309     -- is both an acquire fence              and   a    release   fence,   if   order      ==
11310       memory_order_acq_rel;
11311     -- is a sequentially consistent acquire and release fence, if order                    ==
11312       memory_order_seq_cst.
11313
11314
11315 [page 276]
11316
11317     Returns
11318 3   The atomic_thread_fence function returns no value.
11319     7.17.4.2 The atomic_signal_fence function
11320     Synopsis
11321 1           #include <stdatomic.h>
11322             void atomic_signal_fence(memory_order order);
11323     Description
11324 2   Equivalent to atomic_thread_fence(order), except that ''synchronizes with''
11325     relationships are established only between a thread and a signal handler executed in the
11326     same thread.
11327 3   NOTE 1 The atomic_signal_fence function can be used to specify the order in which actions
11328     performed by the thread become visible to the signal handler.
11329
11330 4   NOTE 2 Compiler optimizations and reorderings of loads and stores are inhibited in the same way as with
11331     atomic_thread_fence, but the hardware fence instructions that atomic_thread_fence would
11332     have inserted are not emitted.
11333
11334     Returns
11335 5   The atomic_signal_fence function returns no value.
11336     7.17.5 Lock-free property
11337 1   The atomic lock-free macros indicate the lock-free property of integer and address atomic
11338     types. A value of 0 indicates that the type is never lock-free; a value of 1 indicates that
11339     the type is sometimes lock-free; a value of 2 indicates that the type is always lock-free.
11340 2   NOTE Operations that are lock-free should also be address-free. That is, atomic operations on the same
11341     memory location via two different addresses will communicate atomically. The implementation should not
11342     depend on any per-process state. This restriction enables communication via memory mapped into a
11343     process more than once and memory shared between two processes.
11344
11345     7.17.5.1 The atomic_is_lock_free generic function
11346     Synopsis
11347 1           #include <stdatomic.h>
11348             _Bool atomic_is_lock_free(atomic_type const volatile *obj);
11349     Description
11350 2   The atomic_is_lock_free generic function indicates whether or not the object
11351     pointed to by obj is lock-free. atomic_type can be any atomic type.
11352     Returns
11353 3   The atomic_is_lock_free generic function returns nonzero (true) if and only if the
11354     object's operations are lock-free. The result of a lock-free query on one object cannot be
11355
11356 [page 277]
11357
11358     inferred from the result of a lock-free query on another object.
11359     7.17.6 Atomic integer and address types
11360 1   For each line in the following table, the atomic type name is declared as the
11361     corresponding direct type.
11362
11363
11364
11365
11366 [page 278]
11367
11368
11369
11370                 Atomic type name                             Direct type
11371             atomic_char                          _Atomic    char
11372             atomic_schar                         _Atomic    signed char
11373             atomic_uchar                         _Atomic    unsigned char
11374             atomic_short                         _Atomic    short
11375             atomic_ushort                        _Atomic    unsigned short
11376             atomic_int                           _Atomic    int
11377             atomic_uint                          _Atomic    unsigned int
11378             atomic_long                          _Atomic    long
11379             atomic_ulong                         _Atomic    unsigned long
11380             atomic_llong                         _Atomic    long long
11381             atomic_ullong                        _Atomic    unsigned long long
11382             atomic_char16_t                      _Atomic    char16_t
11383             atomic_char32_t                      _Atomic    char32_t
11384             atomic_wchar_t                       _Atomic    wchar_t
11385             atomic_int_least8_t                  _Atomic    int_least8_t
11386             atomic_uint_least8_t                 _Atomic    uint_least8_t
11387             atomic_int_least16_t                 _Atomic    int_least16_t
11388             atomic_uint_least16_t                _Atomic    uint_least16_t
11389             atomic_int_least32_t                 _Atomic    int_least32_t
11390             atomic_uint_least32_t                _Atomic    uint_least32_t
11391             atomic_int_least64_t                 _Atomic    int_least64_t
11392             atomic_uint_least64_t                _Atomic    uint_least64_t
11393             atomic_int_fast8_t                   _Atomic    int_fast8_t
11394             atomic_uint_fast8_t                  _Atomic    uint_fast8_t
11395             atomic_int_fast16_t                  _Atomic    int_fast16_t
11396             atomic_uint_fast16_t                 _Atomic    uint_fast16_t
11397             atomic_int_fast32_t                  _Atomic    int_fast32_t
11398             atomic_uint_fast32_t                 _Atomic    uint_fast32_t
11399             atomic_int_fast64_t                  _Atomic    int_fast64_t
11400             atomic_uint_fast64_t                 _Atomic    uint_fast64_t
11401             atomic_intptr_t                      _Atomic    intptr_t
11402             atomic_uintptr_t                     _Atomic    uintptr_t
11403             atomic_size_t                        _Atomic    size_t
11404             atomic_ptrdiff_t                     _Atomic    ptrdiff_t
11405             atomic_intmax_t                      _Atomic    intmax_t
11406             atomic_uintmax_t                     _Atomic    uintmax_t
11407 2   The semantics of the operations on these types are defined in 7.17.7.
11408
11409
11410
11411 [page 279]
11412
11413 3   The atomic_bool type provides an atomic boolean.
11414 4   The atomic_address type provides atomic void * operations. The unit of
11415     addition/subtraction shall be one byte.
11416 5   NOTE The representation of atomic integer and address types need not have the same size as their
11417     corresponding regular types. They should have the same size whenever possible, as it eases effort required
11418     to port existing code.
11419
11420     7.17.7 Operations on atomic types
11421 1   There are only a few kinds of operations on atomic types, though there are many
11422     instances of those kinds. This subclause specifies each general kind.
11423     7.17.7.1 The atomic_store generic functions
11424     Synopsis
11425 1           #include <stdatomic.h>
11426             void atomic_store(volatile A *object, C desired);
11427             void atomic_store_explicit(volatile A *object,
11428                  C desired, memory_order order);
11429     Description
11430 2   The      order      argument    shall    not    be    memory_order_acquire,
11431     memory_order_consume, nor memory_order_acq_rel. Atomically replace the
11432     value pointed to by object with the value of desired. Memory is affected according
11433     to the value of order.
11434     Returns
11435 3   The atomic_store generic functions return no value.
11436     7.17.7.2 The atomic_load generic functions
11437     Synopsis
11438 1           #include <stdatomic.h>
11439             C atomic_load(volatile A *object);
11440             C atomic_load_explicit(volatile A *object,
11441                  memory_order order);
11442     Description
11443 2   The order argument shall not be memory_order_release nor
11444     memory_order_acq_rel. Memory is affected according to the value of order.
11445     Returns
11446     Atomically returns the value pointed to by object.
11447
11448
11449
11450 [page 280]
11451
11452     7.17.7.3 The atomic_exchange generic functions
11453     Synopsis
11454 1            #include <stdatomic.h>
11455              C atomic_exchange(volatile A *object, C desired);
11456              C atomic_exchange_explicit(volatile A *object,
11457                   C desired, memory_order order);
11458     Description
11459 2   Atomically replace the value pointed to by object with desired. Memory is affected
11460     according to the value of order. These operations are read-modify-write operations
11461     (5.1.2.4).
11462     Returns
11463 3   Atomically returns the value pointed to by object immediately before the effects.
11464     7.17.7.4 The atomic_compare_exchange generic functions
11465     Synopsis
11466 1            #include <stdatomic.h>
11467              _Bool atomic_compare_exchange_strong(volatile A *object,
11468                   C *expected, C desired);
11469              _Bool atomic_compare_exchange_strong_explicit(
11470                   volatile A *object, C *expected, C desired,
11471                   memory_order success, memory_order failure);
11472              _Bool atomic_compare_exchange_weak(volatile A *object,
11473                   C *expected, C desired);
11474              _Bool atomic_compare_exchange_weak_explicit(
11475                   volatile A *object, C *expected, C desired,
11476                   memory_order success, memory_order failure);
11477     Description
11478 2   The failure argument shall not be memory_order_release nor
11479     memory_order_acq_rel. The failure argument shall be no stronger than the
11480     success argument. Atomically, compares the value pointed to by object for equality
11481     with that in expected, and if true, replaces the value pointed to by object with
11482     desired, and if false, updates the value in expected with the value pointed to by
11483     object. Further, if the comparison is true, memory is affected according to the value of
11484     success, and if the comparison is false, memory is affected according to the value of
11485     failure. These operations are atomic read-modify-write operations (5.1.2.4).
11486 3   NOTE 1    The effect of the compare-and-exchange operations is
11487
11488
11489
11490
11491 [page 281]
11492
11493              if (*object == *expected)
11494                    *object = desired;
11495              else
11496                    *expected = *object;
11497
11498 4   The weak compare-and-exchange operations may fail spuriously, that is, return zero
11499     while leaving the value pointed to by expected unchanged.
11500 5   NOTE 2 This spurious failure enables implementation of compare-and-exchange on a broader class of
11501     machines, e.g. load-locked store-conditional machines.
11502
11503 6   EXAMPLE         A consequence of spurious failure is that nearly all uses of weak compare-and-exchange will
11504     be in a loop.
11505              exp = atomic_load(&cur);
11506              do {
11507                    des = function(exp);
11508              } while (!atomic_compare_exchange_weak(&cur, &exp, des));
11509     When a compare-and-exchange is in a loop, the weak version will yield better performance on some
11510     platforms. When a weak compare-and-exchange would require a loop and a strong one would not, the
11511     strong one is preferable.
11512
11513     Returns
11514 7   The result of the comparison.
11515     7.17.7.5 The atomic_fetch and modify generic functions
11516 1   The following operations perform arithmetic and bitwise computations. All of these
11517     operations are applicable to an object of any atomic integer type. Only addition and
11518     subtraction are applicable to atomic_address. None of these operations is applicable
11519     to atomic_bool. The key, operator, and computation correspondence is:
11520
11521
11522      key            op          computation
11523      add            +       addition
11524      sub            -       subtraction
11525      or             |       bitwise inclusive or
11526      xor            ^       bitwise exclusive or
11527      and            &       bitwise and
11528     Synopsis
11529 2            #include <stdatomic.h>
11530              C atomic_fetch_key(volatile A *object, M operand);
11531              C atomic_fetch_key_explicit(volatile A *object,
11532                   M operand, memory_order order);
11533     Description
11534 3   Atomically replaces the value pointed to by object with the result of the computation
11535     applied to the value pointed to by object and the given operand. Memory is affected
11536 [page 282]
11537
11538     according to the value of order. These operations are atomic read-modify-write
11539     operations (5.1.2.4). For signed integer types, arithmetic is defined to use two's-
11540     complement representation. There are no undefined results. For address types, the result
11541     may be an undefined address, but the operations otherwise have no undefined behavior.
11542     Returns
11543 4   Atomically, the value pointed to by object immediately before the effects.
11544 5   NOTE The operation of the atomic_fetch and modify generic functions are nearly equivalent to the
11545     operation of the corresponding op= compound assignment operators. The only differences are that the
11546     compound assignment operators are not guaranteed to operate atomically, and the value yielded by a
11547     compound assignment operator is the updated value of the object, whereas the value returned by the
11548     atomic_fetch and modify generic functions is the previous value of the atomic object.
11549
11550     7.17.8 Atomic flag type and operations
11551 1   The atomic_flag type provides the classic test-and-set functionality. It has two
11552     states, set and clear.
11553 2   Operations on an object of type atomic_flag shall be lock free.
11554 3   NOTE Hence the operations should also be address-free. No other type requires lock-free operations, so
11555     the atomic_flag type is the minimum hardware-implemented type needed to conform to this
11556     International standard. The remaining types can be emulated with atomic_flag, though with less than
11557     ideal properties.
11558
11559 4   The macro ATOMIC_FLAG_INIT may be used to initialize an atomic_flag to the
11560     clear state. An atomic_flag that is not explicitly initialized with
11561     ATOMIC_FLAG_INIT is initially in an indeterminate state.
11562 5   EXAMPLE
11563             atomic_flag guard = ATOMIC_FLAG_INIT;
11564
11565     7.17.8.1 The atomic_flag_test_and_set functions
11566     Synopsis
11567 1           #include <stdatomic.h>
11568             bool atomic_flag_test_and_set(
11569                  volatile atomic_flag *object);
11570             bool atomic_flag_test_and_set_explicit(
11571                  volatile atomic_flag *object, memory_order order);
11572     Description
11573 2   Atomically sets the value pointed to by object to true. Memory is affected according
11574     to the value of order. These operations are atomic read-modify-write operations
11575     (5.1.2.4).
11576
11577
11578
11579
11580 [page 283]
11581
11582     Returns
11583 3   Atomically, the value of the object immediately before the effects.
11584     7.17.8.2 The atomic_flag_clear functions
11585     Synopsis
11586 1          #include <stdatomic.h>
11587            void atomic_flag_clear(volatile atomic_flag *object);
11588            void atomic_flag_clear_explicit(
11589                 volatile atomic_flag *object, memory_order order);
11590     Description
11591 2   The order argument shall not be memory_order_acquire nor
11592     memory_order_acq_rel. Atomically sets the value pointed to by object to false.
11593     Memory is affected according to the value of order.
11594     Returns
11595 3   The atomic_flag_clear functions return no value.
11596
11597
11598
11599
11600 [page 284]
11601
11602     7.18 Boolean type and values <stdbool.h>
11603 1   The header <stdbool.h> defines four macros.
11604 2   The macro
11605              bool
11606     expands to _Bool.
11607 3   The remaining three macros are suitable for use in #if preprocessing directives. They
11608     are
11609              true
11610     which expands to the integer constant 1,
11611              false
11612     which expands to the integer constant 0, and
11613              __bool_true_false_are_defined
11614     which expands to the integer constant 1.
11615 4   Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then
11616     redefine the macros bool, true, and false.248)
11617
11618
11619
11620
11621     248) See ''future library directions'' (7.30.7).
11622
11623 [page 285]
11624
11625     7.19 Common definitions <stddef.h>
11626 1   The header <stddef.h> defines the following macros and declares the following types.
11627     Some are also defined in other headers, as noted in their respective subclauses.
11628 2   The types are
11629            ptrdiff_t
11630     which is the signed integer type of the result of subtracting two pointers;
11631            size_t
11632     which is the unsigned integer type of the result of the sizeof operator;
11633            max_align_t
11634     which is an object type whose alignment is as great as is supported by the implementation
11635     in all contexts; and
11636            wchar_t
11637     which is an integer type whose range of values can represent distinct codes for all
11638     members of the largest extended character set specified among the supported locales; the
11639     null character shall have the code value zero. Each member of the basic character set
11640     shall have a code value equal to its value when used as the lone character in an integer
11641     character      constant     if     an      implementation      does      not      define
11642     __STDC_MB_MIGHT_NEQ_WC__.
11643 3   The macros are
11644            NULL
11645     which expands to an implementation-defined null pointer constant; and
11646            offsetof(type, member-designator)
11647     which expands to an integer constant expression that has type size_t, the value of
11648     which is the offset in bytes, to the structure member (designated by member-designator),
11649     from the beginning of its structure (designated by type). The type and member designator
11650     shall be such that given
11651            static type t;
11652     then the expression &(t.member-designator) evaluates to an address constant. (If the
11653     specified member is a bit-field, the behavior is undefined.)
11654     Recommended practice
11655 4   The types used for size_t and ptrdiff_t should not have an integer conversion rank
11656     greater than that of signed long int unless the implementation supports objects
11657     large enough to make this necessary.
11658
11659 [page 286]
11660
11661 Forward references: localization (7.11).
11662
11663
11664
11665
11666 [page 287]
11667
11668     7.20 Integer types <stdint.h>
11669 1   The header <stdint.h> declares sets of integer types having specified widths, and
11670     defines corresponding sets of macros.249) It also defines macros that specify limits of
11671     integer types corresponding to types defined in other standard headers.
11672 2   Types are defined in the following categories:
11673     -- integer types having certain exact widths;
11674     -- integer types having at least certain specified widths;
11675     -- fastest integer types having at least certain specified widths;
11676     -- integer types wide enough to hold pointers to objects;
11677     -- integer types having greatest width.
11678     (Some of these types may denote the same type.)
11679 3   Corresponding macros specify limits of the declared types and construct suitable
11680     constants.
11681 4   For each type described herein that the implementation provides,250) <stdint.h> shall
11682     declare that typedef name and define the associated macros. Conversely, for each type
11683     described herein that the implementation does not provide, <stdint.h> shall not
11684     declare that typedef name nor shall it define the associated macros. An implementation
11685     shall provide those types described as ''required'', but need not provide any of the others
11686     (described as ''optional'').
11687     7.20.1 Integer types
11688 1   When typedef names differing only in the absence or presence of the initial u are defined,
11689     they shall denote corresponding signed and unsigned types as described in 6.2.5; an
11690     implementation providing one of these corresponding types shall also provide the other.
11691 2   In the following descriptions, the symbol N represents an unsigned decimal integer with
11692     no leading zeros (e.g., 8 or 24, but not 04 or 048).
11693
11694
11695
11696
11697     249) See ''future library directions'' (7.30.8).
11698     250) Some of these types may denote implementation-defined extended integer types.
11699
11700 [page 288]
11701
11702     7.20.1.1 Exact-width integer types
11703 1   The typedef name intN_t designates a signed integer type with width N , no padding
11704     bits, and a two's complement representation. Thus, int8_t denotes such a signed
11705     integer type with a width of exactly 8 bits.
11706 2   The typedef name uintN_t designates an unsigned integer type with width N and no
11707     padding bits. Thus, uint24_t denotes such an unsigned integer type with a width of
11708     exactly 24 bits.
11709 3   These types are optional. However, if an implementation provides integer types with
11710     widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a
11711     two's complement representation, it shall define the corresponding typedef names.
11712     7.20.1.2 Minimum-width integer types
11713 1   The typedef name int_leastN_t designates a signed integer type with a width of at
11714     least N , such that no signed integer type with lesser size has at least the specified width.
11715     Thus, int_least32_t denotes a signed integer type with a width of at least 32 bits.
11716 2   The typedef name uint_leastN_t designates an unsigned integer type with a width
11717     of at least N , such that no unsigned integer type with lesser size has at least the specified
11718     width. Thus, uint_least16_t denotes an unsigned integer type with a width of at
11719     least 16 bits.
11720 3   The following types are required:
11721              int_least8_t                                      uint_least8_t
11722              int_least16_t                                     uint_least16_t
11723              int_least32_t                                     uint_least32_t
11724              int_least64_t                                     uint_least64_t
11725     All other types of this form are optional.
11726     7.20.1.3 Fastest minimum-width integer types
11727 1   Each of the following types designates an integer type that is usually fastest251) to operate
11728     with among all integer types that have at least the specified width.
11729 2   The typedef name int_fastN_t designates the fastest signed integer type with a width
11730     of at least N . The typedef name uint_fastN_t designates the fastest unsigned integer
11731     type with a width of at least N .
11732
11733
11734
11735
11736     251) The designated type is not guaranteed to be fastest for all purposes; if the implementation has no clear
11737          grounds for choosing one type over another, it will simply pick some integer type satisfying the
11738          signedness and width requirements.
11739
11740 [page 289]
11741
11742 3   The following types are required:
11743            int_fast8_t                                     uint_fast8_t
11744            int_fast16_t                                    uint_fast16_t
11745            int_fast32_t                                    uint_fast32_t
11746            int_fast64_t                                    uint_fast64_t
11747     All other types of this form are optional.
11748     7.20.1.4 Integer types capable of holding object pointers
11749 1   The following type designates a signed integer type with the property that any valid
11750     pointer to void can be converted to this type, then converted back to pointer to void,
11751     and the result will compare equal to the original pointer:
11752            intptr_t
11753     The following type designates an unsigned integer type with the property that any valid
11754     pointer to void can be converted to this type, then converted back to pointer to void,
11755     and the result will compare equal to the original pointer:
11756            uintptr_t
11757     These types are optional.
11758     7.20.1.5 Greatest-width integer types
11759 1   The following type designates a signed integer type capable of representing any value of
11760     any signed integer type:
11761            intmax_t
11762     The following type designates an unsigned integer type capable of representing any value
11763     of any unsigned integer type:
11764            uintmax_t
11765     These types are required.
11766     7.20.2 Limits of specified-width integer types
11767 1   The following object-like macros specify the minimum and maximum limits of the types
11768     declared in <stdint.h>. Each macro name corresponds to a similar type name in
11769     7.20.1.
11770 2   Each instance of any defined macro shall be replaced by a constant expression suitable
11771     for use in #if preprocessing directives, and this expression shall have the same type as
11772     would an expression that is an object of the corresponding type converted according to
11773     the integer promotions. Its implementation-defined value shall be equal to or greater in
11774     magnitude (absolute value) than the corresponding value given below, with the same sign,
11775     except where stated to be exactly the given value.
11776
11777 [page 290]
11778
11779     7.20.2.1 Limits of exact-width integer types
11780 1   -- minimum values of exact-width signed integer types
11781        INTN_MIN                                     exactly -(2 N -1 )
11782     -- maximum values of exact-width signed integer types
11783        INTN_MAX                                     exactly 2 N -1 - 1
11784     -- maximum values of exact-width unsigned integer types
11785        UINTN_MAX                                    exactly 2 N - 1
11786     7.20.2.2 Limits of minimum-width integer types
11787 1   -- minimum values of minimum-width signed integer types
11788        INT_LEASTN_MIN                                       -(2 N -1 - 1)
11789     -- maximum values of minimum-width signed integer types
11790        INT_LEASTN_MAX                                       2 N -1 - 1
11791     -- maximum values of minimum-width unsigned integer types
11792        UINT_LEASTN_MAX                                      2N - 1
11793     7.20.2.3 Limits of fastest minimum-width integer types
11794 1   -- minimum values of fastest minimum-width signed integer types
11795        INT_FASTN_MIN                                        -(2 N -1 - 1)
11796     -- maximum values of fastest minimum-width signed integer types
11797        INT_FASTN_MAX                                        2 N -1 - 1
11798     -- maximum values of fastest minimum-width unsigned integer types
11799        UINT_FASTN_MAX                                       2N - 1
11800     7.20.2.4 Limits of integer types capable of holding object pointers
11801 1   -- minimum value of pointer-holding signed integer type
11802        INTPTR_MIN                                           -(215 - 1)
11803     -- maximum value of pointer-holding signed integer type
11804        INTPTR_MAX                                           215 - 1
11805     -- maximum value of pointer-holding unsigned integer type
11806        UINTPTR_MAX                                          216 - 1
11807
11808
11809
11810 [page 291]
11811
11812     7.20.2.5 Limits of greatest-width integer types
11813 1   -- minimum value of greatest-width signed integer type
11814           INTMAX_MIN                                                  -(263 - 1)
11815     -- maximum value of greatest-width signed integer type
11816         INTMAX_MAX                                                    263 - 1
11817     -- maximum value of greatest-width unsigned integer type
11818         UINTMAX_MAX                                                   264 - 1
11819     7.20.3 Limits of other integer types
11820 1   The following object-like macros specify the minimum and maximum limits of integer
11821     types corresponding to types defined in other standard headers.
11822 2   Each instance of these macros shall be replaced by a constant expression suitable for use
11823     in #if preprocessing directives, and this expression shall have the same type as would an
11824     expression that is an object of the corresponding type converted according to the integer
11825     promotions. Its implementation-defined value shall be equal to or greater in magnitude
11826     (absolute value) than the corresponding value given below, with the same sign. An
11827     implementation shall define only the macros corresponding to those typedef names it
11828     actually provides.252)
11829     -- limits of ptrdiff_t
11830         PTRDIFF_MIN                                                 -65535
11831         PTRDIFF_MAX                                                 +65535
11832     -- limits of sig_atomic_t
11833         SIG_ATOMIC_MIN                                              see below
11834         SIG_ATOMIC_MAX                                              see below
11835     -- limit of size_t
11836         SIZE_MAX                                                      65535
11837     -- limits of wchar_t
11838         WCHAR_MIN                                                   see below
11839         WCHAR_MAX                                                   see below
11840     -- limits of wint_t
11841
11842
11843
11844
11845     252) A freestanding implementation need not provide all of these types.
11846
11847 [page 292]
11848
11849         WINT_MIN                                              see below
11850         WINT_MAX                                              see below
11851 3   If sig_atomic_t (see 7.14) is defined as a signed integer type, the value of
11852     SIG_ATOMIC_MIN shall be no greater than -127 and the value of SIG_ATOMIC_MAX
11853     shall be no less than 127; otherwise, sig_atomic_t is defined as an unsigned integer
11854     type, and the value of SIG_ATOMIC_MIN shall be 0 and the value of
11855     SIG_ATOMIC_MAX shall be no less than 255.
11856 4   If wchar_t (see 7.19) is defined as a signed integer type, the value of WCHAR_MIN
11857     shall be no greater than -127 and the value of WCHAR_MAX shall be no less than 127;
11858     otherwise, wchar_t is defined as an unsigned integer type, and the value of
11859     WCHAR_MIN shall be 0 and the value of WCHAR_MAX shall be no less than 255.253)
11860 5   If wint_t (see 7.28) is defined as a signed integer type, the value of WINT_MIN shall
11861     be no greater than -32767 and the value of WINT_MAX shall be no less than 32767;
11862     otherwise, wint_t is defined as an unsigned integer type, and the value of WINT_MIN
11863     shall be 0 and the value of WINT_MAX shall be no less than 65535.
11864     7.20.4 Macros for integer constants
11865 1   The following function-like macros expand to integer constants suitable for initializing
11866     objects that have integer types corresponding to types defined in <stdint.h>. Each
11867     macro name corresponds to a similar type name in 7.20.1.2 or 7.20.1.5.
11868 2   The argument in any instance of these macros shall be an unsuffixed integer constant (as
11869     defined in 6.4.4.1) with a value that does not exceed the limits for the corresponding type.
11870 3   Each invocation of one of these macros shall expand to an integer constant expression
11871     suitable for use in #if preprocessing directives. The type of the expression shall have
11872     the same type as would an expression of the corresponding type converted according to
11873     the integer promotions. The value of the expression shall be that of the argument.
11874     7.20.4.1 Macros for minimum-width integer constants
11875 1   The macro INTN_C(value) shall expand to an integer constant expression
11876     corresponding to the type int_leastN_t. The macro UINTN_C(value) shall expand
11877     to an integer constant expression corresponding to the type uint_leastN_t. For
11878     example, if uint_least64_t is a name for the type unsigned long long int,
11879     then UINT64_C(0x123) might expand to the integer constant 0x123ULL.
11880
11881
11882
11883
11884     253) The values WCHAR_MIN and WCHAR_MAX do not necessarily correspond to members of the extended
11885          character set.
11886
11887 [page 293]
11888
11889     7.20.4.2 Macros for greatest-width integer constants
11890 1   The following macro expands to an integer constant expression having the value specified
11891     by its argument and the type intmax_t:
11892            INTMAX_C(value)
11893     The following macro expands to an integer constant expression having the value specified
11894     by its argument and the type uintmax_t:
11895            UINTMAX_C(value)
11896
11897
11898
11899
11900 [page 294]
11901
11902     7.21 Input/output <stdio.h>
11903     7.21.1 Introduction
11904 1   The header <stdio.h> defines several macros, and declares three types and many
11905     functions for performing input and output.
11906 2   The types declared are size_t (described in 7.19);
11907             FILE
11908     which is an object type capable of recording all the information needed to control a
11909     stream, including its file position indicator, a pointer to its associated buffer (if any), an
11910     error indicator that records whether a read/write error has occurred, and an end-of-file
11911     indicator that records whether the end of the file has been reached; and
11912             fpos_t
11913     which is a complete object type other than an array type capable of recording all the
11914     information needed to specify uniquely every position within a file.
11915 3   The macros are NULL (described in 7.19);
11916             _IOFBF
11917             _IOLBF
11918             _IONBF
11919     which expand to integer constant expressions with distinct values, suitable for use as the
11920     third argument to the setvbuf function;
11921             BUFSIZ
11922     which expands to an integer constant expression that is the size of the buffer used by the
11923     setbuf function;
11924             EOF
11925     which expands to an integer constant expression, with type int and a negative value, that
11926     is returned by several functions to indicate end-of-file, that is, no more input from a
11927     stream;
11928               FOPEN_MAX
11929     which expands to an integer constant expression that is the minimum number of files that
11930     the implementation guarantees can be open simultaneously;
11931               FILENAME_MAX
11932     which expands to an integer constant expression that is the size needed for an array of
11933     char large enough to hold the longest file name string that the implementation
11934
11935
11936
11937 [page 295]
11938
11939     guarantees can be opened;254)
11940             L_tmpnam
11941     which expands to an integer constant expression that is the size needed for an array of
11942     char large enough to hold a temporary file name string generated by the tmpnam
11943     function;
11944             SEEK_CUR
11945             SEEK_END
11946             SEEK_SET
11947     which expand to integer constant expressions with distinct values, suitable for use as the
11948     third argument to the fseek function;
11949             TMP_MAX
11950     which expands to an integer constant expression that is the minimum number of unique
11951     file names that can be generated by the tmpnam function;
11952             stderr
11953             stdin
11954             stdout
11955     which are expressions of type ''pointer to FILE'' that point to the FILE objects
11956     associated, respectively, with the standard error, input, and output streams.
11957 4   The header <wchar.h> declares a number of functions useful for wide character input
11958     and output. The wide character input/output functions described in that subclause
11959     provide operations analogous to most of those described here, except that the
11960     fundamental units internal to the program are wide characters. The external
11961     representation (in the file) is a sequence of ''generalized'' multibyte characters, as
11962     described further in 7.21.3.
11963 5   The input/output functions are given the following collective terms:
11964     -- The wide character input functions -- those functions described in 7.28 that perform
11965       input into wide characters and wide strings: fgetwc, fgetws, getwc, getwchar,
11966       fwscanf, wscanf, vfwscanf, and vwscanf.
11967     -- The wide character output functions -- those functions described in 7.28 that perform
11968       output from wide characters and wide strings: fputwc, fputws, putwc,
11969       putwchar, fwprintf, wprintf, vfwprintf, and vwprintf.
11970
11971
11972     254) If the implementation imposes no practical limit on the length of file name strings, the value of
11973          FILENAME_MAX should instead be the recommended size of an array intended to hold a file name
11974          string. Of course, file name string contents are subject to other system-specific constraints; therefore
11975          all possible strings of length FILENAME_MAX cannot be expected to be opened successfully.
11976
11977 [page 296]
11978
11979     -- The wide character input/output functions -- the union of the ungetwc function, the
11980       wide character input functions, and the wide character output functions.
11981     -- The byte input/output functions -- those functions described in this subclause that
11982       perform input/output: fgetc, fgets, fprintf, fputc, fputs, fread,
11983       fscanf, fwrite, getc, getchar, printf, putc, putchar, puts, scanf,
11984       ungetc, vfprintf, vfscanf, vprintf, and vscanf.
11985     Forward references: files (7.21.3), the fseek function (7.21.9.2), streams (7.21.2), the
11986     tmpnam function (7.21.4.4), <wchar.h> (7.28).
11987     7.21.2 Streams
11988 1   Input and output, whether to or from physical devices such as terminals and tape drives,
11989     or whether to or from files supported on structured storage devices, are mapped into
11990     logical data streams, whose properties are more uniform than their various inputs and
11991     outputs. Two forms of mapping are supported, for text streams and for binary
11992     streams.255)
11993 2   A text stream is an ordered sequence of characters composed into lines, each line
11994     consisting of zero or more characters plus a terminating new-line character. Whether the
11995     last line requires a terminating new-line character is implementation-defined. Characters
11996     may have to be added, altered, or deleted on input and output to conform to differing
11997     conventions for representing text in the host environment. Thus, there need not be a one-
11998     to-one correspondence between the characters in a stream and those in the external
11999     representation. Data read in from a text stream will necessarily compare equal to the data
12000     that were earlier written out to that stream only if: the data consist only of printing
12001     characters and the control characters horizontal tab and new-line; no new-line character is
12002     immediately preceded by space characters; and the last character is a new-line character.
12003     Whether space characters that are written out immediately before a new-line character
12004     appear when read in is implementation-defined.
12005 3   A binary stream is an ordered sequence of characters that can transparently record
12006     internal data. Data read in from a binary stream shall compare equal to the data that were
12007     earlier written out to that stream, under the same implementation. Such a stream may,
12008     however, have an implementation-defined number of null characters appended to the end
12009     of the stream.
12010 4   Each stream has an orientation. After a stream is associated with an external file, but
12011     before any operations are performed on it, the stream is without orientation. Once a wide
12012     character input/output function has been applied to a stream without orientation, the
12013
12014
12015     255) An implementation need not distinguish between text streams and binary streams. In such an
12016          implementation, there need be no new-line characters in a text stream nor any limit to the length of a
12017          line.
12018
12019 [page 297]
12020
12021     stream becomes a wide-oriented stream. Similarly, once a byte input/output function has
12022     been applied to a stream without orientation, the stream becomes a byte-oriented stream.
12023     Only a call to the freopen function or the fwide function can otherwise alter the
12024     orientation of a stream. (A successful call to freopen removes any orientation.)256)
12025 5   Byte input/output functions shall not be applied to a wide-oriented stream and wide
12026     character input/output functions shall not be applied to a byte-oriented stream. The
12027     remaining stream operations do not affect, and are not affected by, a stream's orientation,
12028     except for the following additional restrictions:
12029     -- Binary wide-oriented streams have the file-positioning restrictions ascribed to both
12030       text and binary streams.
12031     -- For wide-oriented streams, after a successful call to a file-positioning function that
12032       leaves the file position indicator prior to the end-of-file, a wide character output
12033       function can overwrite a partial multibyte character; any file contents beyond the
12034       byte(s) written are henceforth indeterminate.
12035 6   Each wide-oriented stream has an associated mbstate_t object that stores the current
12036     parse state of the stream. A successful call to fgetpos stores a representation of the
12037     value of this mbstate_t object as part of the value of the fpos_t object. A later
12038     successful call to fsetpos using the same stored fpos_t value restores the value of
12039     the associated mbstate_t object as well as the position within the controlled stream.
12040     Environmental limits
12041 7   An implementation shall support text files with lines containing at least 254 characters,
12042     including the terminating new-line character. The value of the macro BUFSIZ shall be at
12043     least 256.
12044     Forward references: the freopen function (7.21.5.4), the fwide function (7.28.3.5),
12045     mbstate_t (7.29.1), the fgetpos function (7.21.9.1), the fsetpos function
12046     (7.21.9.3).
12047
12048
12049
12050
12051     256) The three predefined streams stdin, stdout, and stderr are unoriented at program startup.
12052
12053 [page 298]
12054
12055     7.21.3 Files
12056 1   A stream is associated with an external file (which may be a physical device) by opening
12057     a file, which may involve creating a new file. Creating an existing file causes its former
12058     contents to be discarded, if necessary. If a file can support positioning requests (such as a
12059     disk file, as opposed to a terminal), then a file position indicator associated with the
12060     stream is positioned at the start (character number zero) of the file, unless the file is
12061     opened with append mode in which case it is implementation-defined whether the file
12062     position indicator is initially positioned at the beginning or the end of the file. The file
12063     position indicator is maintained by subsequent reads, writes, and positioning requests, to
12064     facilitate an orderly progression through the file.
12065 2   Binary files are not truncated, except as defined in 7.21.5.3. Whether a write on a text
12066     stream causes the associated file to be truncated beyond that point is implementation-
12067     defined.
12068 3   When a stream is unbuffered, characters are intended to appear from the source or at the
12069     destination as soon as possible. Otherwise characters may be accumulated and
12070     transmitted to or from the host environment as a block. When a stream is fully buffered,
12071     characters are intended to be transmitted to or from the host environment as a block when
12072     a buffer is filled. When a stream is line buffered, characters are intended to be
12073     transmitted to or from the host environment as a block when a new-line character is
12074     encountered. Furthermore, characters are intended to be transmitted as a block to the host
12075     environment when a buffer is filled, when input is requested on an unbuffered stream, or
12076     when input is requested on a line buffered stream that requires the transmission of
12077     characters from the host environment. Support for these characteristics is
12078     implementation-defined, and may be affected via the setbuf and setvbuf functions.
12079 4   A file may be disassociated from a controlling stream by closing the file. Output streams
12080     are flushed (any unwritten buffer contents are transmitted to the host environment) before
12081     the stream is disassociated from the file. The value of a pointer to a FILE object is
12082     indeterminate after the associated file is closed (including the standard text streams).
12083     Whether a file of zero length (on which no characters have been written by an output
12084     stream) actually exists is implementation-defined.
12085 5   The file may be subsequently reopened, by the same or another program execution, and
12086     its contents reclaimed or modified (if it can be repositioned at its start). If the main
12087     function returns to its original caller, or if the exit function is called, all open files are
12088     closed (hence all output streams are flushed) before program termination. Other paths to
12089     program termination, such as calling the abort function, need not close all files
12090     properly.
12091 6   The address of the FILE object used to control a stream may be significant; a copy of a
12092     FILE object need not serve in place of the original.
12093
12094 [page 299]
12095
12096 7    At program startup, three text streams are predefined and need not be opened explicitly
12097      -- standard input (for reading conventional input), standard output (for writing
12098      conventional output), and standard error (for writing diagnostic output). As initially
12099      opened, the standard error stream is not fully buffered; the standard input and standard
12100      output streams are fully buffered if and only if the stream can be determined not to refer
12101      to an interactive device.
12102 8    Functions that open additional (nontemporary) files require a file name, which is a string.
12103      The rules for composing valid file names are implementation-defined. Whether the same
12104      file can be simultaneously open multiple times is also implementation-defined.
12105 9    Although both text and binary wide-oriented streams are conceptually sequences of wide
12106      characters, the external file associated with a wide-oriented stream is a sequence of
12107      multibyte characters, generalized as follows:
12108      -- Multibyte encodings within files may contain embedded null bytes (unlike multibyte
12109        encodings valid for use internal to the program).
12110      -- A file need not begin nor end in the initial shift state.257)
12111 10   Moreover, the encodings used for multibyte characters may differ among files. Both the
12112      nature and choice of such encodings are implementation-defined.
12113 11   The wide character input functions read multibyte characters from the stream and convert
12114      them to wide characters as if they were read by successive calls to the fgetwc function.
12115      Each conversion occurs as if by a call to the mbrtowc function, with the conversion state
12116      described by the stream's own mbstate_t object. The byte input functions read
12117      characters from the stream as if by successive calls to the fgetc function.
12118 12   The wide character output functions convert wide characters to multibyte characters and
12119      write them to the stream as if they were written by successive calls to the fputwc
12120      function. Each conversion occurs as if by a call to the wcrtomb function, with the
12121      conversion state described by the stream's own mbstate_t object. The byte output
12122      functions write characters to the stream as if by successive calls to the fputc function.
12123 13   In some cases, some of the byte input/output functions also perform conversions between
12124      multibyte characters and wide characters. These conversions also occur as if by calls to
12125      the mbrtowc and wcrtomb functions.
12126 14   An encoding error occurs if the character sequence presented to the underlying
12127      mbrtowc function does not form a valid (generalized) multibyte character, or if the code
12128      value passed to the underlying wcrtomb does not correspond to a valid (generalized)
12129
12130
12131      257) Setting the file position indicator to end-of-file, as with fseek(file, 0, SEEK_END), has
12132           undefined behavior for a binary stream (because of possible trailing null characters) or for any stream
12133           with state-dependent encoding that does not assuredly end in the initial shift state.
12134
12135 [page 300]
12136
12137      multibyte character. The wide character input/output functions and the byte input/output
12138      functions store the value of the macro EILSEQ in errno if and only if an encoding error
12139      occurs.
12140      Environmental limits
12141 15   The value of FOPEN_MAX shall be at least eight, including the three standard text
12142      streams.
12143      Forward references: the exit function (7.22.4.4), the fgetc function (7.21.7.1), the
12144      fopen function (7.21.5.3), the fputc function (7.21.7.3), the setbuf function
12145      (7.21.5.5), the setvbuf function (7.21.5.6), the fgetwc function (7.28.3.1), the
12146      fputwc function (7.28.3.3), conversion state (7.28.6), the mbrtowc function
12147      (7.28.6.3.2), the wcrtomb function (7.28.6.3.3).
12148      7.21.4 Operations on files
12149      7.21.4.1 The remove function
12150      Synopsis
12151 1            #include <stdio.h>
12152              int remove(const char *filename);
12153      Description
12154 2    The remove function causes the file whose name is the string pointed to by filename
12155      to be no longer accessible by that name. A subsequent attempt to open that file using that
12156      name will fail, unless it is created anew. If the file is open, the behavior of the remove
12157      function is implementation-defined.
12158      Returns
12159 3    The remove function returns zero if the operation succeeds, nonzero if it fails.
12160      7.21.4.2 The rename function
12161      Synopsis
12162 1            #include <stdio.h>
12163              int rename(const char *old, const char *new);
12164      Description
12165 2    The rename function causes the file whose name is the string pointed to by old to be
12166      henceforth known by the name given by the string pointed to by new. The file named
12167      old is no longer accessible by that name. If a file named by the string pointed to by new
12168      exists prior to the call to the rename function, the behavior is implementation-defined.
12169
12170
12171
12172
12173 [page 301]
12174
12175     Returns
12176 3   The rename function returns zero if the operation succeeds, nonzero if it fails,258) in
12177     which case if the file existed previously it is still known by its original name.
12178     7.21.4.3 The tmpfile function
12179     Synopsis
12180 1           #include <stdio.h>
12181             FILE *tmpfile(void);
12182     Description
12183 2   The tmpfile function creates a temporary binary file that is different from any other
12184     existing file and that will automatically be removed when it is closed or at program
12185     termination. If the program terminates abnormally, whether an open temporary file is
12186     removed is implementation-defined. The file is opened for update with "wb+" mode.
12187     Recommended practice
12188 3   It should be possible to open at least TMP_MAX temporary files during the lifetime of the
12189     program (this limit may be shared with tmpnam) and there should be no limit on the
12190     number simultaneously open other than this limit and any limit on the number of open
12191     files (FOPEN_MAX).
12192     Returns
12193 4   The tmpfile function returns a pointer to the stream of the file that it created. If the file
12194     cannot be created, the tmpfile function returns a null pointer.
12195     Forward references: the fopen function (7.21.5.3).
12196     7.21.4.4 The tmpnam function
12197     Synopsis
12198 1           #include <stdio.h>
12199             char *tmpnam(char *s);
12200     Description
12201 2   The tmpnam function generates a string that is a valid file name and that is not the same
12202     as the name of an existing file.259) The function is potentially capable of generating at
12203
12204
12205     258) Among the reasons the implementation may cause the rename function to fail are that the file is open
12206          or that it is necessary to copy its contents to effectuate its renaming.
12207     259) Files created using strings generated by the tmpnam function are temporary only in the sense that
12208          their names should not collide with those generated by conventional naming rules for the
12209          implementation. It is still necessary to use the remove function to remove such files when their use
12210          is ended, and before program termination.
12211
12212 [page 302]
12213
12214     least TMP_MAX different strings, but any or all of them may already be in use by existing
12215     files and thus not be suitable return values.
12216 3   The tmpnam function generates a different string each time it is called.
12217 4   Calls to the tmpnam function with a null pointer argument may introduce data races with
12218     each other. The implementation shall behave as if no library function calls the tmpnam
12219     function.
12220     Returns
12221 5   If no suitable string can be generated, the tmpnam function returns a null pointer.
12222     Otherwise, if the argument is a null pointer, the tmpnam function leaves its result in an
12223     internal static object and returns a pointer to that object (subsequent calls to the tmpnam
12224     function may modify the same object). If the argument is not a null pointer, it is assumed
12225     to point to an array of at least L_tmpnam chars; the tmpnam function writes its result
12226     in that array and returns the argument as its value.
12227     Environmental limits
12228 6   The value of the macro TMP_MAX shall be at least 25.
12229     7.21.5 File access functions
12230     7.21.5.1 The fclose function
12231     Synopsis
12232 1           #include <stdio.h>
12233             int fclose(FILE *stream);
12234     Description
12235 2   A successful call to the fclose function causes the stream pointed to by stream to be
12236     flushed and the associated file to be closed. Any unwritten buffered data for the stream
12237     are delivered to the host environment to be written to the file; any unread buffered data
12238     are discarded. Whether or not the call succeeds, the stream is disassociated from the file
12239     and any buffer set by the setbuf or setvbuf function is disassociated from the stream
12240     (and deallocated if it was automatically allocated).
12241     Returns
12242 3   The fclose function returns zero if the stream was successfully closed, or EOF if any
12243     errors were detected.
12244
12245
12246
12247
12248 [page 303]
12249
12250     7.21.5.2 The fflush function
12251     Synopsis
12252 1           #include <stdio.h>
12253             int fflush(FILE *stream);
12254     Description
12255 2   If stream points to an output stream or an update stream in which the most recent
12256     operation was not input, the fflush function causes any unwritten data for that stream
12257     to be delivered to the host environment to be written to the file; otherwise, the behavior is
12258     undefined.
12259 3   If stream is a null pointer, the fflush function performs this flushing action on all
12260     streams for which the behavior is defined above.
12261     Returns
12262 4   The fflush function sets the error indicator for the stream and returns EOF if a write
12263     error occurs, otherwise it returns zero.
12264     Forward references: the fopen function (7.21.5.3).
12265     7.21.5.3 The fopen function
12266     Synopsis
12267 1           #include <stdio.h>
12268             FILE *fopen(const char * restrict filename,
12269                  const char * restrict mode);
12270     Description
12271 2   The fopen function opens the file whose name is the string pointed to by filename,
12272     and associates a stream with it.
12273 3   The argument mode points to a string. If the string is one of the following, the file is
12274     open in the indicated mode. Otherwise, the behavior is undefined.260)
12275     r                     open text file for reading
12276     w                     truncate to zero length or create text file for writing
12277     wx                    create text file for writing
12278     a                     append; open or create text file for writing at end-of-file
12279     rb                    open binary file for reading
12280     wb                    truncate to zero length or create binary file for writing
12281
12282
12283     260) If the string begins with one of the above sequences, the implementation might choose to ignore the
12284          remaining characters, or it might use them to select different kinds of a file (some of which might not
12285          conform to the properties in 7.21.2).
12286
12287 [page 304]
12288
12289     wbx               create binary file for writing
12290     ab                append; open or create binary file for writing at end-of-file
12291     r+                open text file for update (reading and writing)
12292     w+                truncate to zero length or create text file for update
12293     w+x               create text file for update
12294     a+                append; open or create text file for update, writing at end-of-file
12295     r+b or rb+        open binary file for update (reading and writing)
12296     w+b or wb+        truncate to zero length or create binary file for update
12297     w+bx or wb+x      create binary file for update
12298     a+b or ab+        append; open or create binary file for update, writing at end-of-file
12299 4   Opening a file with read mode ('r' as the first character in the mode argument) fails if
12300     the file does not exist or cannot be read.
12301 5   Opening a file with exclusive mode ('x' as the last character in the mode argument)
12302     fails if the file already exists or cannot be created. Otherwise, the file is created with
12303     exclusive (also known as non-shared) access to the extent that the underlying system
12304     supports exclusive access.
12305 6   Opening a file with append mode ('a' as the first character in the mode argument)
12306     causes all subsequent writes to the file to be forced to the then current end-of-file,
12307     regardless of intervening calls to the fseek function. In some implementations, opening
12308     a binary file with append mode ('b' as the second or third character in the above list of
12309     mode argument values) may initially position the file position indicator for the stream
12310     beyond the last data written, because of null character padding.
12311 7   When a file is opened with update mode ('+' as the second or third character in the
12312     above list of mode argument values), both input and output may be performed on the
12313     associated stream. However, output shall not be directly followed by input without an
12314     intervening call to the fflush function or to a file positioning function (fseek,
12315     fsetpos, or rewind), and input shall not be directly followed by output without an
12316     intervening call to a file positioning function, unless the input operation encounters end-
12317     of-file. Opening (or creating) a text file with update mode may instead open (or create) a
12318     binary stream in some implementations.
12319 8   When opened, a stream is fully buffered if and only if it can be determined not to refer to
12320     an interactive device. The error and end-of-file indicators for the stream are cleared.
12321     Returns
12322 9   The fopen function returns a pointer to the object controlling the stream. If the open
12323     operation fails, fopen returns a null pointer.
12324     Forward references: file positioning functions (7.21.9).
12325
12326
12327
12328 [page 305]
12329
12330     7.21.5.4 The freopen function
12331     Synopsis
12332 1           #include <stdio.h>
12333             FILE *freopen(const char * restrict filename,
12334                  const char * restrict mode,
12335                  FILE * restrict stream);
12336     Description
12337 2   The freopen function opens the file whose name is the string pointed to by filename
12338     and associates the stream pointed to by stream with it. The mode argument is used just
12339     as in the fopen function.261)
12340 3   If filename is a null pointer, the freopen function attempts to change the mode of
12341     the stream to that specified by mode, as if the name of the file currently associated with
12342     the stream had been used. It is implementation-defined which changes of mode are
12343     permitted (if any), and under what circumstances.
12344 4   The freopen function first attempts to close any file that is associated with the specified
12345     stream. Failure to close the file is ignored. The error and end-of-file indicators for the
12346     stream are cleared.
12347     Returns
12348 5   The freopen function returns a null pointer if the open operation fails. Otherwise,
12349     freopen returns the value of stream.
12350     7.21.5.5 The setbuf function
12351     Synopsis
12352 1           #include <stdio.h>
12353             void setbuf(FILE * restrict stream,
12354                  char * restrict buf);
12355     Description
12356 2   Except that it returns no value, the setbuf function is equivalent to the setvbuf
12357     function invoked with the values _IOFBF for mode and BUFSIZ for size, or (if buf
12358     is a null pointer), with the value _IONBF for mode.
12359
12360
12361
12362
12363     261) The primary use of the freopen function is to change the file associated with a standard text stream
12364          (stderr, stdin, or stdout), as those identifiers need not be modifiable lvalues to which the value
12365          returned by the fopen function may be assigned.
12366
12367 [page 306]
12368
12369     Returns
12370 3   The setbuf function returns no value.
12371     Forward references: the setvbuf function (7.21.5.6).
12372     7.21.5.6 The setvbuf function
12373     Synopsis
12374 1           #include <stdio.h>
12375             int setvbuf(FILE * restrict stream,
12376                  char * restrict buf,
12377                  int mode, size_t size);
12378     Description
12379 2   The setvbuf function may be used only after the stream pointed to by stream has
12380     been associated with an open file and before any other operation (other than an
12381     unsuccessful call to setvbuf) is performed on the stream. The argument mode
12382     determines how stream will be buffered, as follows: _IOFBF causes input/output to be
12383     fully buffered; _IOLBF causes input/output to be line buffered; _IONBF causes
12384     input/output to be unbuffered. If buf is not a null pointer, the array it points to may be
12385     used instead of a buffer allocated by the setvbuf function262) and the argument size
12386     specifies the size of the array; otherwise, size may determine the size of a buffer
12387     allocated by the setvbuf function. The contents of the array at any time are
12388     indeterminate.
12389     Returns
12390 3   The setvbuf function returns zero on success, or nonzero if an invalid value is given
12391     for mode or if the request cannot be honored.
12392
12393
12394
12395
12396     262) The buffer has to have a lifetime at least as great as the open stream, so the stream should be closed
12397          before a buffer that has automatic storage duration is deallocated upon block exit.
12398
12399 [page 307]
12400
12401     7.21.6 Formatted input/output functions
12402 1   The formatted input/output functions shall behave as if there is a sequence point after the
12403     actions associated with each specifier.263)
12404     7.21.6.1 The fprintf function
12405     Synopsis
12406 1            #include <stdio.h>
12407              int fprintf(FILE * restrict stream,
12408                   const char * restrict format, ...);
12409     Description
12410 2   The fprintf function writes output to the stream pointed to by stream, under control
12411     of the string pointed to by format that specifies how subsequent arguments are
12412     converted for output. If there are insufficient arguments for the format, the behavior is
12413     undefined. If the format is exhausted while arguments remain, the excess arguments are
12414     evaluated (as always) but are otherwise ignored. The fprintf function returns when
12415     the end of the format string is encountered.
12416 3   The format shall be a multibyte character sequence, beginning and ending in its initial
12417     shift state. The format is composed of zero or more directives: ordinary multibyte
12418     characters (not %), which are copied unchanged to the output stream; and conversion
12419     specifications, each of which results in fetching zero or more subsequent arguments,
12420     converting them, if applicable, according to the corresponding conversion specifier, and
12421     then writing the result to the output stream.
12422 4   Each conversion specification is introduced by the character %. After the %, the following
12423     appear in sequence:
12424     -- Zero or more flags (in any order) that modify the meaning of the conversion
12425       specification.
12426     -- An optional minimum field width. If the converted value has fewer characters than the
12427       field width, it is padded with spaces (by default) on the left (or right, if the left
12428       adjustment flag, described later, has been given) to the field width. The field width
12429       takes the form of an asterisk * (described later) or a nonnegative decimal integer.264)
12430     -- An optional precision that gives the minimum number of digits to appear for the d, i,
12431       o, u, x, and X conversions, the number of digits to appear after the decimal-point
12432       character for a, A, e, E, f, and F conversions, the maximum number of significant
12433       digits for the g and G conversions, or the maximum number of bytes to be written for
12434
12435
12436     263) The fprintf functions perform writes to memory for the %n specifier.
12437     264) Note that 0 is taken as a flag, not as the beginning of a field width.
12438
12439 [page 308]
12440
12441         s conversions. The precision takes the form of a period (.) followed either by an
12442         asterisk * (described later) or by an optional decimal integer; if only the period is
12443         specified, the precision is taken as zero. If a precision appears with any other
12444         conversion specifier, the behavior is undefined.
12445     -- An optional length modifier that specifies the size of the argument.
12446     -- A conversion specifier character that specifies the type of conversion to be applied.
12447 5   As noted above, a field width, or precision, or both, may be indicated by an asterisk. In
12448     this case, an int argument supplies the field width or precision. The arguments
12449     specifying field width, or precision, or both, shall appear (in that order) before the
12450     argument (if any) to be converted. A negative field width argument is taken as a - flag
12451     followed by a positive field width. A negative precision argument is taken as if the
12452     precision were omitted.
12453 6   The flag characters and their meanings are:
12454     -       The result of the conversion is left-justified within the field. (It is right-justified if
12455             this flag is not specified.)
12456     +       The result of a signed conversion always begins with a plus or minus sign. (It
12457             begins with a sign only when a negative value is converted if this flag is not
12458             specified.)265)
12459     space If the first character of a signed conversion is not a sign, or if a signed conversion
12460           results in no characters, a space is prefixed to the result. If the space and + flags
12461           both appear, the space flag is ignored.
12462     #       The result is converted to an ''alternative form''. For o conversion, it increases
12463             the precision, if and only if necessary, to force the first digit of the result to be a
12464             zero (if the value and precision are both 0, a single 0 is printed). For x (or X)
12465             conversion, a nonzero result has 0x (or 0X) prefixed to it. For a, A, e, E, f, F, g,
12466             and G conversions, the result of converting a floating-point number always
12467             contains a decimal-point character, even if no digits follow it. (Normally, a
12468             decimal-point character appears in the result of these conversions only if a digit
12469             follows it.) For g and G conversions, trailing zeros are not removed from the
12470             result. For other conversions, the behavior is undefined.
12471     0       For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros
12472             (following any indication of sign or base) are used to pad to the field width rather
12473             than performing space padding, except when converting an infinity or NaN. If the
12474             0 and - flags both appear, the 0 flag is ignored. For d, i, o, u, x, and X
12475
12476
12477     265) The results of all floating conversions of a negative zero, and of negative values that round to zero,
12478          include a minus sign.
12479
12480 [page 309]
12481
12482               conversions, if a precision is specified, the 0 flag is ignored. For other
12483               conversions, the behavior is undefined.
12484 7   The length modifiers and their meanings are:
12485     hh            Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12486                   signed char or unsigned char argument (the argument will have
12487                   been promoted according to the integer promotions, but its value shall be
12488                   converted to signed char or unsigned char before printing); or that
12489                   a following n conversion specifier applies to a pointer to a signed char
12490                   argument.
12491     h             Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12492                   short int or unsigned short int argument (the argument will
12493                   have been promoted according to the integer promotions, but its value shall
12494                   be converted to short int or unsigned short int before printing);
12495                   or that a following n conversion specifier applies to a pointer to a short
12496                   int argument.
12497     l (ell)       Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12498                   long int or unsigned long int argument; that a following n
12499                   conversion specifier applies to a pointer to a long int argument; that a
12500                   following c conversion specifier applies to a wint_t argument; that a
12501                   following s conversion specifier applies to a pointer to a wchar_t
12502                   argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion
12503                   specifier.
12504     ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12505                  long long int or unsigned long long int argument; or that a
12506                  following n conversion specifier applies to a pointer to a long long int
12507                  argument.
12508     j             Specifies that a following d, i, o, u, x, or X conversion specifier applies to
12509                   an intmax_t or uintmax_t argument; or that a following n conversion
12510                   specifier applies to a pointer to an intmax_t argument.
12511     z             Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12512                   size_t or the corresponding signed integer type argument; or that a
12513                   following n conversion specifier applies to a pointer to a signed integer type
12514                   corresponding to size_t argument.
12515     t             Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
12516                   ptrdiff_t or the corresponding unsigned integer type argument; or that a
12517                   following n conversion specifier applies to a pointer to a ptrdiff_t
12518                   argument.
12519
12520
12521 [page 310]
12522
12523     L              Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
12524                    applies to a long double argument.
12525     If a length modifier appears with any conversion specifier other than as specified above,
12526     the behavior is undefined.
12527 8   The conversion specifiers and their meanings are:
12528     d,i          The int argument is converted to signed decimal in the style [-]dddd. The
12529                  precision specifies the minimum number of digits to appear; if the value
12530                  being converted can be represented in fewer digits, it is expanded with
12531                  leading zeros. The default precision is 1. The result of converting a zero
12532                  value with a precision of zero is no characters.
12533     o,u,x,X The unsigned int argument is converted to unsigned octal (o), unsigned
12534             decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; the
12535             letters abcdef are used for x conversion and the letters ABCDEF for X
12536             conversion. The precision specifies the minimum number of digits to appear;
12537             if the value being converted can be represented in fewer digits, it is expanded
12538             with leading zeros. The default precision is 1. The result of converting a
12539             zero value with a precision of zero is no characters.
12540     f,F          A double argument representing a floating-point number is converted to
12541                  decimal notation in the style [-]ddd.ddd, where the number of digits after
12542                  the decimal-point character is equal to the precision specification. If the
12543                  precision is missing, it is taken as 6; if the precision is zero and the # flag is
12544                  not specified, no decimal-point character appears. If a decimal-point
12545                  character appears, at least one digit appears before it. The value is rounded to
12546                  the appropriate number of digits.
12547                  A double argument representing an infinity is converted in one of the styles
12548                  [-]inf or [-]infinity -- which style is implementation-defined. A
12549                  double argument representing a NaN is converted in one of the styles
12550                  [-]nan or [-]nan(n-char-sequence) -- which style, and the meaning of
12551                  any n-char-sequence, is implementation-defined. The F conversion specifier
12552                  produces INF, INFINITY, or NAN instead of inf, infinity, or nan,
12553                  respectively.266)
12554     e,E          A double argument representing a floating-point number is converted in the
12555                  style [-]d.ddd e(+-)dd, where there is one digit (which is nonzero if the
12556                  argument is nonzero) before the decimal-point character and the number of
12557                  digits after it is equal to the precision; if the precision is missing, it is taken as
12558
12559
12560     266) When applied to infinite and NaN values, the -, +, and space flag characters have their usual meaning;
12561          the # and 0 flag characters have no effect.
12562
12563 [page 311]
12564
12565               6; if the precision is zero and the # flag is not specified, no decimal-point
12566               character appears. The value is rounded to the appropriate number of digits.
12567               The E conversion specifier produces a number with E instead of e
12568               introducing the exponent. The exponent always contains at least two digits,
12569               and only as many more digits as necessary to represent the exponent. If the
12570               value is zero, the exponent is zero.
12571               A double argument representing an infinity or NaN is converted in the style
12572               of an f or F conversion specifier.
12573 g,G           A double argument representing a floating-point number is converted in
12574               style f or e (or in style F or E in the case of a G conversion specifier),
12575               depending on the value converted and the precision. Let P equal the
12576               precision if nonzero, 6 if the precision is omitted, or 1 if the precision is zero.
12577               Then, if a conversion with style E would have an exponent of X:
12578               -- if P > X >= -4, the conversion is with style f (or F) and precision
12579                 P - (X + 1).
12580               -- otherwise, the conversion is with style e (or E) and precision P - 1.
12581               Finally, unless the # flag is used, any trailing zeros are removed from the
12582               fractional portion of the result and the decimal-point character is removed if
12583               there is no fractional portion remaining.
12584               A double argument representing an infinity or NaN is converted in the style
12585               of an f or F conversion specifier.
12586 a,A           A double argument representing a floating-point number is converted in the
12587               style [-]0xh.hhhh p(+-)d, where there is one hexadecimal digit (which is
12588               nonzero if the argument is a normalized floating-point number and is
12589               otherwise unspecified) before the decimal-point character267) and the number
12590               of hexadecimal digits after it is equal to the precision; if the precision is
12591               missing and FLT_RADIX is a power of 2, then the precision is sufficient for
12592               an exact representation of the value; if the precision is missing and
12593               FLT_RADIX is not a power of 2, then the precision is sufficient to
12594
12595
12596
12597
12598 267) Binary implementations can choose the hexadecimal digit to the left of the decimal-point character so
12599      that subsequent digits align to nibble (4-bit) boundaries.
12600
12601 [page 312]
12602
12603               distinguish268) values of type double, except that trailing zeros may be
12604               omitted; if the precision is zero and the # flag is not specified, no decimal-
12605               point character appears. The letters abcdef are used for a conversion and
12606               the letters ABCDEF for A conversion. The A conversion specifier produces a
12607               number with X and P instead of x and p. The exponent always contains at
12608               least one digit, and only as many more digits as necessary to represent the
12609               decimal exponent of 2. If the value is zero, the exponent is zero.
12610               A double argument representing an infinity or NaN is converted in the style
12611               of an f or F conversion specifier.
12612 c             If no l length modifier is present, the int argument is converted to an
12613               unsigned char, and the resulting character is written.
12614               If an l length modifier is present, the wint_t argument is converted as if by
12615               an ls conversion specification with no precision and an argument that points
12616               to the initial element of a two-element array of wchar_t, the first element
12617               containing the wint_t argument to the lc conversion specification and the
12618               second a null wide character.
12619 s             If no l length modifier is present, the argument shall be a pointer to the initial
12620               element of an array of character type.269) Characters from the array are
12621               written up to (but not including) the terminating null character. If the
12622               precision is specified, no more than that many bytes are written. If the
12623               precision is not specified or is greater than the size of the array, the array shall
12624               contain a null character.
12625               If an l length modifier is present, the argument shall be a pointer to the initial
12626               element of an array of wchar_t type. Wide characters from the array are
12627               converted to multibyte characters (each as if by a call to the wcrtomb
12628               function, with the conversion state described by an mbstate_t object
12629               initialized to zero before the first wide character is converted) up to and
12630               including a terminating null wide character. The resulting multibyte
12631               characters are written up to (but not including) the terminating null character
12632               (byte). If no precision is specified, the array shall contain a null wide
12633               character. If a precision is specified, no more than that many bytes are
12634               written (including shift sequences, if any), and the array shall contain a null
12635               wide character if, to equal the multibyte character sequence length given by
12636
12637 268) The precision p is sufficient to distinguish values of the source type if 16 p-1 > b n where b is
12638      FLT_RADIX and n is the number of base-b digits in the significand of the source type. A smaller p
12639      might suffice depending on the implementation's scheme for determining the digit to the left of the
12640      decimal-point character.
12641 269) No special provisions are made for multibyte characters.
12642
12643 [page 313]
12644
12645                     the precision, the function would need to access a wide character one past the
12646                     end of the array. In no case is a partial multibyte character written.270)
12647      p              The argument shall be a pointer to void. The value of the pointer is
12648                     converted to a sequence of printing characters, in an implementation-defined
12649                     manner.
12650      n              The argument shall be a pointer to signed integer into which is written the
12651                     number of characters written to the output stream so far by this call to
12652                     fprintf. No argument is converted, but one is consumed. If the conversion
12653                     specification includes any flags, a field width, or a precision, the behavior is
12654                     undefined.
12655      %              A % character is written. No argument is converted. The complete
12656                     conversion specification shall be %%.
12657 9    If a conversion specification is invalid, the behavior is undefined.271) If any argument is
12658      not the correct type for the corresponding conversion specification, the behavior is
12659      undefined.
12660 10   In no case does a nonexistent or small field width cause truncation of a field; if the result
12661      of a conversion is wider than the field width, the field is expanded to contain the
12662      conversion result.
12663 11   For a and A conversions, if FLT_RADIX is a power of 2, the value is correctly rounded
12664      to a hexadecimal floating number with the given precision.
12665      Recommended practice
12666 12   For a and A conversions, if FLT_RADIX is not a power of 2 and the result is not exactly
12667      representable in the given precision, the result should be one of the two adjacent numbers
12668      in hexadecimal floating style with the given precision, with the extra stipulation that the
12669      error should have a correct sign for the current rounding direction.
12670 13   For e, E, f, F, g, and G conversions, if the number of significant decimal digits is at most
12671      DECIMAL_DIG, then the result should be correctly rounded.272) If the number of
12672      significant decimal digits is more than DECIMAL_DIG but the source value is exactly
12673      representable with DECIMAL_DIG digits, then the result should be an exact
12674      representation with trailing zeros. Otherwise, the source value is bounded by two
12675      adjacent decimal strings L < U, both having DECIMAL_DIG significant digits; the value
12676
12677
12678      270) Redundant shift sequences may result if multibyte characters have a state-dependent encoding.
12679      271) See ''future library directions'' (7.30.9).
12680      272) For binary-to-decimal conversion, the result format's values are the numbers representable with the
12681           given format specifier. The number of significant digits is determined by the format specifier, and in
12682           the case of fixed-point conversion by the source value as well.
12683
12684 [page 314]
12685
12686      of the resultant decimal string D should satisfy L <= D <= U, with the extra stipulation that
12687      the error should have a correct sign for the current rounding direction.
12688      Returns
12689 14   The fprintf function returns the number of characters transmitted, or a negative value
12690      if an output or encoding error occurred.
12691      Environmental limits
12692 15   The number of characters that can be produced by any single conversion shall be at least
12693      4095.
12694 16   EXAMPLE 1         To print a date and time in the form ''Sunday, July 3, 10:02'' followed by pi to five decimal
12695      places:
12696               #include <math.h>
12697               #include <stdio.h>
12698               /* ... */
12699               char *weekday, *month;      // pointers to strings
12700               int day, hour, min;
12701               fprintf(stdout, "%s, %s %d, %.2d:%.2d\n",
12702                       weekday, month, day, hour, min);
12703               fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0));
12704
12705 17   EXAMPLE 2 In this example, multibyte characters do not have a state-dependent encoding, and the
12706      members of the extended character set that consist of more than one byte each consist of exactly two bytes,
12707      the first of which is denoted here by a and the second by an uppercase letter.
12708 18   Given the following wide string with length seven,
12709               static wchar_t wstr[] = L" X Yabc Z W";
12710      the seven calls
12711               fprintf(stdout,          "|1234567890123|\n");
12712               fprintf(stdout,          "|%13ls|\n", wstr);
12713               fprintf(stdout,          "|%-13.9ls|\n", wstr);
12714               fprintf(stdout,          "|%13.10ls|\n", wstr);
12715               fprintf(stdout,          "|%13.11ls|\n", wstr);
12716               fprintf(stdout,          "|%13.15ls|\n", &wstr[2]);
12717               fprintf(stdout,          "|%13lc|\n", (wint_t) wstr[5]);
12718      will print the following seven lines:
12719               |1234567890123|
12720               |   X Yabc Z W|
12721               | X Yabc Z    |
12722               |     X Yabc Z|
12723               |   X Yabc Z W|
12724               |      abc Z W|
12725               |            Z|
12726
12727      Forward references: conversion state (7.28.6), the wcrtomb function (7.28.6.3.3).
12728
12729
12730
12731 [page 315]
12732
12733     7.21.6.2 The fscanf function
12734     Synopsis
12735 1          #include <stdio.h>
12736            int fscanf(FILE * restrict stream,
12737                 const char * restrict format, ...);
12738     Description
12739 2   The fscanf function reads input from the stream pointed to by stream, under control
12740     of the string pointed to by format that specifies the admissible input sequences and how
12741     they are to be converted for assignment, using subsequent arguments as pointers to the
12742     objects to receive the converted input. If there are insufficient arguments for the format,
12743     the behavior is undefined. If the format is exhausted while arguments remain, the excess
12744     arguments are evaluated (as always) but are otherwise ignored.
12745 3   The format shall be a multibyte character sequence, beginning and ending in its initial
12746     shift state. The format is composed of zero or more directives: one or more white-space
12747     characters, an ordinary multibyte character (neither % nor a white-space character), or a
12748     conversion specification. Each conversion specification is introduced by the character %.
12749     After the %, the following appear in sequence:
12750     -- An optional assignment-suppressing character *.
12751     -- An optional decimal integer greater than zero that specifies the maximum field width
12752       (in characters).
12753     -- An optional length modifier that specifies the size of the receiving object.
12754     -- A conversion specifier character that specifies the type of conversion to be applied.
12755 4   The fscanf function executes each directive of the format in turn. When all directives
12756     have been executed, or if a directive fails (as detailed below), the function returns.
12757     Failures are described as input failures (due to the occurrence of an encoding error or the
12758     unavailability of input characters), or matching failures (due to inappropriate input).
12759 5   A directive composed of white-space character(s) is executed by reading input up to the
12760     first non-white-space character (which remains unread), or until no more characters can
12761     be read.
12762 6   A directive that is an ordinary multibyte character is executed by reading the next
12763     characters of the stream. If any of those characters differ from the ones composing the
12764     directive, the directive fails and the differing and subsequent characters remain unread.
12765     Similarly, if end-of-file, an encoding error, or a read error prevents a character from being
12766     read, the directive fails.
12767 7   A directive that is a conversion specification defines a set of matching input sequences, as
12768     described below for each specifier. A conversion specification is executed in the
12769
12770 [page 316]
12771
12772      following steps:
12773 8    Input white-space characters (as specified by the isspace function) are skipped, unless
12774      the specification includes a [, c, or n specifier.273)
12775 9    An input item is read from the stream, unless the specification includes an n specifier. An
12776      input item is defined as the longest sequence of input characters which does not exceed
12777      any specified field width and which is, or is a prefix of, a matching input sequence.274)
12778      The first character, if any, after the input item remains unread. If the length of the input
12779      item is zero, the execution of the directive fails; this condition is a matching failure unless
12780      end-of-file, an encoding error, or a read error prevented input from the stream, in which
12781      case it is an input failure.
12782 10   Except in the case of a % specifier, the input item (or, in the case of a %n directive, the
12783      count of input characters) is converted to a type appropriate to the conversion specifier. If
12784      the input item is not a matching sequence, the execution of the directive fails: this
12785      condition is a matching failure. Unless assignment suppression was indicated by a *, the
12786      result of the conversion is placed in the object pointed to by the first argument following
12787      the format argument that has not already received a conversion result. If this object
12788      does not have an appropriate type, or if the result of the conversion cannot be represented
12789      in the object, the behavior is undefined.
12790 11   The length modifiers and their meanings are:
12791      hh             Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12792                     to an argument with type pointer to signed char or unsigned char.
12793      h              Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12794                     to an argument with type pointer to short int or unsigned short
12795                     int.
12796      l (ell)        Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12797                     to an argument with type pointer to long int or unsigned long
12798                     int; that a following a, A, e, E, f, F, g, or G conversion specifier applies to
12799                     an argument with type pointer to double; or that a following c, s, or [
12800                     conversion specifier applies to an argument with type pointer to wchar_t.
12801      ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12802                   to an argument with type pointer to long long int or unsigned
12803                   long long int.
12804
12805
12806
12807      273) These white-space characters are not counted against a specified field width.
12808      274) fscanf pushes back at most one input character onto the input stream. Therefore, some sequences
12809           that are acceptable to strtod, strtol, etc., are unacceptable to fscanf.
12810
12811 [page 317]
12812
12813      j           Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12814                  to an argument with type pointer to intmax_t or uintmax_t.
12815      z           Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12816                  to an argument with type pointer to size_t or the corresponding signed
12817                  integer type.
12818      t           Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
12819                  to an argument with type pointer to ptrdiff_t or the corresponding
12820                  unsigned integer type.
12821      L           Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
12822                  applies to an argument with type pointer to long double.
12823      If a length modifier appears with any conversion specifier other than as specified above,
12824      the behavior is undefined.
12825 12   The conversion specifiers and their meanings are:
12826      d          Matches an optionally signed decimal integer, whose format is the same as
12827                 expected for the subject sequence of the strtol function with the value 10
12828                 for the base argument. The corresponding argument shall be a pointer to
12829                 signed integer.
12830      i          Matches an optionally signed integer, whose format is the same as expected
12831                 for the subject sequence of the strtol function with the value 0 for the
12832                 base argument. The corresponding argument shall be a pointer to signed
12833                 integer.
12834      o          Matches an optionally signed octal integer, whose format is the same as
12835                 expected for the subject sequence of the strtoul function with the value 8
12836                 for the base argument. The corresponding argument shall be a pointer to
12837                 unsigned integer.
12838      u          Matches an optionally signed decimal integer, whose format is the same as
12839                 expected for the subject sequence of the strtoul function with the value 10
12840                 for the base argument. The corresponding argument shall be a pointer to
12841                 unsigned integer.
12842      x          Matches an optionally signed hexadecimal integer, whose format is the same
12843                 as expected for the subject sequence of the strtoul function with the value
12844                 16 for the base argument. The corresponding argument shall be a pointer to
12845                 unsigned integer.
12846      a,e,f,g Matches an optionally signed floating-point number, infinity, or NaN, whose
12847              format is the same as expected for the subject sequence of the strtod
12848              function. The corresponding argument shall be a pointer to floating.
12849
12850
12851 [page 318]
12852
12853 c             Matches a sequence of characters of exactly the number specified by the field
12854               width (1 if no field width is present in the directive).275)
12855               If no l length modifier is present, the corresponding argument shall be a
12856               pointer to the initial element of a character array large enough to accept the
12857               sequence. No null character is added.
12858               If an l length modifier is present, the input shall be a sequence of multibyte
12859               characters that begins in the initial shift state. Each multibyte character in the
12860               sequence is converted to a wide character as if by a call to the mbrtowc
12861               function, with the conversion state described by an mbstate_t object
12862               initialized to zero before the first multibyte character is converted. The
12863               corresponding argument shall be a pointer to the initial element of an array of
12864               wchar_t large enough to accept the resulting sequence of wide characters.
12865               No null wide character is added.
12866 s             Matches a sequence of non-white-space characters.275)
12867               If no l length modifier is present, the corresponding argument shall be a
12868               pointer to the initial element of a character array large enough to accept the
12869               sequence and a terminating null character, which will be added automatically.
12870               If an l length modifier is present, the input shall be a sequence of multibyte
12871               characters that begins in the initial shift state. Each multibyte character is
12872               converted to a wide character as if by a call to the mbrtowc function, with
12873               the conversion state described by an mbstate_t object initialized to zero
12874               before the first multibyte character is converted. The corresponding argument
12875               shall be a pointer to the initial element of an array of wchar_t large enough
12876               to accept the sequence and the terminating null wide character, which will be
12877               added automatically.
12878 [             Matches a nonempty sequence of characters from a set of expected characters
12879               (the scanset).275)
12880               If no l length modifier is present, the corresponding argument shall be a
12881               pointer to the initial element of a character array large enough to accept the
12882               sequence and a terminating null character, which will be added automatically.
12883               If an l length modifier is present, the input shall be a sequence of multibyte
12884               characters that begins in the initial shift state. Each multibyte character is
12885               converted to a wide character as if by a call to the mbrtowc function, with
12886               the conversion state described by an mbstate_t object initialized to zero
12887
12888 275) No special provisions are made for multibyte characters in the matching rules used by the c, s, and [
12889      conversion specifiers -- the extent of the input field is determined on a byte-by-byte basis. The
12890      resulting field is nevertheless a sequence of multibyte characters that begins in the initial shift state.
12891
12892 [page 319]
12893
12894                     before the first multibyte character is converted. The corresponding argument
12895                     shall be a pointer to the initial element of an array of wchar_t large enough
12896                     to accept the sequence and the terminating null wide character, which will be
12897                     added automatically.
12898                     The conversion specifier includes all subsequent characters in the format
12899                     string, up to and including the matching right bracket (]). The characters
12900                     between the brackets (the scanlist) compose the scanset, unless the character
12901                     after the left bracket is a circumflex (^), in which case the scanset contains all
12902                     characters that do not appear in the scanlist between the circumflex and the
12903                     right bracket. If the conversion specifier begins with [] or [^], the right
12904                     bracket character is in the scanlist and the next following right bracket
12905                     character is the matching right bracket that ends the specification; otherwise
12906                     the first following right bracket character is the one that ends the
12907                     specification. If a - character is in the scanlist and is not the first, nor the
12908                     second where the first character is a ^, nor the last character, the behavior is
12909                     implementation-defined.
12910      p              Matches an implementation-defined set of sequences, which should be the
12911                     same as the set of sequences that may be produced by the %p conversion of
12912                     the fprintf function. The corresponding argument shall be a pointer to a
12913                     pointer to void. The input item is converted to a pointer value in an
12914                     implementation-defined manner. If the input item is a value converted earlier
12915                     during the same program execution, the pointer that results shall compare
12916                     equal to that value; otherwise the behavior of the %p conversion is undefined.
12917      n              No input is consumed. The corresponding argument shall be a pointer to
12918                     signed integer into which is to be written the number of characters read from
12919                     the input stream so far by this call to the fscanf function. Execution of a
12920                     %n directive does not increment the assignment count returned at the
12921                     completion of execution of the fscanf function. No argument is converted,
12922                     but one is consumed. If the conversion specification includes an assignment-
12923                     suppressing character or a field width, the behavior is undefined.
12924      %              Matches a single % character; no conversion or assignment occurs. The
12925                     complete conversion specification shall be %%.
12926 13   If a conversion specification is invalid, the behavior is undefined.276)
12927 14   The conversion specifiers A, E, F, G, and X are also valid and behave the same as,
12928      respectively, a, e, f, g, and x.
12929
12930
12931
12932      276) See ''future library directions'' (7.30.9).
12933
12934 [page 320]
12935
12936 15   Trailing white space (including new-line characters) is left unread unless matched by a
12937      directive. The success of literal matches and suppressed assignments is not directly
12938      determinable other than via the %n directive.
12939      Returns
12940 16   The fscanf function returns the value of the macro EOF if an input failure occurs
12941      before the first conversion (if any) has completed. Otherwise, the function returns the
12942      number of input items assigned, which can be fewer than provided for, or even zero, in
12943      the event of an early matching failure.
12944 17   EXAMPLE 1        The call:
12945               #include <stdio.h>
12946               /* ... */
12947               int n, i; float x; char name[50];
12948               n = fscanf(stdin, "%d%f%s", &i, &x, name);
12949      with the input line:
12950               25 54.32E-1 thompson
12951      will assign to n the value 3, to i the value 25, to x the value 5.432, and to name the sequence
12952      thompson\0.
12953
12954 18   EXAMPLE 2        The call:
12955               #include <stdio.h>
12956               /* ... */
12957               int i; float x; char name[50];
12958               fscanf(stdin, "%2d%f%*d %[0123456789]", &i, &x, name);
12959      with input:
12960               56789 0123 56a72
12961      will assign to i the value 56 and to x the value 789.0, will skip 0123, and will assign to name the
12962      sequence 56\0. The next character read from the input stream will be a.
12963
12964 19   EXAMPLE 3        To accept repeatedly from stdin a quantity, a unit of measure, and an item name:
12965               #include <stdio.h>
12966               /* ... */
12967               int count; float quant; char units[21], item[21];
12968               do {
12969                       count = fscanf(stdin, "%f%20s of %20s", &quant, units, item);
12970                       fscanf(stdin,"%*[^\n]");
12971               } while (!feof(stdin) && !ferror(stdin));
12972 20   If the stdin stream contains the following lines:
12973               2 quarts of oil
12974               -12.8degrees Celsius
12975               lots of luck
12976               10.0LBS     of
12977               dirt
12978               100ergs of energy
12979
12980 [page 321]
12981
12982      the execution of the above example will be analogous to the following assignments:
12983                quant     =   2; strcpy(units, "quarts"); strcpy(item, "oil");
12984                count     =   3;
12985                quant     =   -12.8; strcpy(units, "degrees");
12986                count     =   2; // "C" fails to match "o"
12987                count     =   0; // "l" fails to match "%f"
12988                quant     =   10.0; strcpy(units, "LBS"); strcpy(item, "dirt");
12989                count     =   3;
12990                count     =   0; // "100e" fails to match "%f"
12991                count     =   EOF;
12992
12993 21   EXAMPLE 4         In:
12994                #include <stdio.h>
12995                /* ... */
12996                int d1, d2, n1, n2, i;
12997                i = sscanf("123", "%d%n%n%d", &d1, &n1, &n2, &d2);
12998      the value 123 is assigned to d1 and the value 3 to n1. Because %n can never get an input failure the value
12999      of 3 is also assigned to n2. The value of d2 is not affected. The value 1 is assigned to i.
13000
13001 22   EXAMPLE 5 In these examples, multibyte characters do have a state-dependent encoding, and the
13002      members of the extended character set that consist of more than one byte each consist of exactly two bytes,
13003      the first of which is denoted here by a and the second by an uppercase letter, but are only recognized as
13004      such when in the alternate shift state. The shift sequences are denoted by (uparrow) and (downarrow), in which the first causes
13005      entry into the alternate shift state.
13006 23   After the call:
13007                #include <stdio.h>
13008                /* ... */
13009                char str[50];
13010                fscanf(stdin, "a%s", str);
13011      with the input line:
13012                a(uparrow) X Y(downarrow) bc
13013      str will contain (uparrow) X Y(downarrow)\0 assuming that none of the bytes of the shift sequences (or of the multibyte
13014      characters, in the more general case) appears to be a single-byte white-space character.
13015 24   In contrast, after the call:
13016                #include <stdio.h>
13017                #include <stddef.h>
13018                /* ... */
13019                wchar_t wstr[50];
13020                fscanf(stdin, "a%ls", wstr);
13021      with the same input line, wstr will contain the two wide characters that correspond to X and Y and a
13022      terminating null wide character.
13023 25   However, the call:
13024
13025
13026
13027
13028 [page 322]
13029
13030              #include <stdio.h>
13031              #include <stddef.h>
13032              /* ... */
13033              wchar_t wstr[50];
13034              fscanf(stdin, "a(uparrow) X(downarrow)%ls", wstr);
13035      with the same input line will return zero due to a matching failure against the (downarrow) sequence in the format
13036      string.
13037 26   Assuming that the first byte of the multibyte character X is the same as the first byte of the multibyte
13038      character Y, after the call:
13039              #include <stdio.h>
13040              #include <stddef.h>
13041              /* ... */
13042              wchar_t wstr[50];
13043              fscanf(stdin, "a(uparrow) Y(downarrow)%ls", wstr);
13044      with the same input line, zero will again be returned, but stdin will be left with a partially consumed
13045      multibyte character.
13046
13047      Forward references: the strtod, strtof, and strtold functions (7.22.1.3), the
13048      strtol, strtoll, strtoul, and strtoull functions (7.22.1.4), conversion state
13049      (7.28.6), the wcrtomb function (7.28.6.3.3).
13050      7.21.6.3 The printf function
13051      Synopsis
13052 1            #include <stdio.h>
13053              int printf(const char * restrict format, ...);
13054      Description
13055 2    The printf function is equivalent to fprintf with the argument stdout interposed
13056      before the arguments to printf.
13057      Returns
13058 3    The printf function returns the number of characters transmitted, or a negative value if
13059      an output or encoding error occurred.
13060      7.21.6.4 The scanf function
13061      Synopsis
13062 1            #include <stdio.h>
13063              int scanf(const char * restrict format, ...);
13064      Description
13065 2    The scanf function is equivalent to fscanf with the argument stdin interposed
13066      before the arguments to scanf.
13067
13068
13069
13070 [page 323]
13071
13072     Returns
13073 3   The scanf function returns the value of the macro EOF if an input failure occurs before
13074     the first conversion (if any) has completed. Otherwise, the scanf function returns the
13075     number of input items assigned, which can be fewer than provided for, or even zero, in
13076     the event of an early matching failure.
13077     7.21.6.5 The snprintf function
13078     Synopsis
13079 1          #include <stdio.h>
13080            int snprintf(char * restrict s, size_t n,
13081                 const char * restrict format, ...);
13082     Description
13083 2   The snprintf function is equivalent to fprintf, except that the output is written into
13084     an array (specified by argument s) rather than to a stream. If n is zero, nothing is written,
13085     and s may be a null pointer. Otherwise, output characters beyond the n-1st are
13086     discarded rather than being written to the array, and a null character is written at the end
13087     of the characters actually written into the array. If copying takes place between objects
13088     that overlap, the behavior is undefined.
13089     Returns
13090 3   The snprintf function returns the number of characters that would have been written
13091     had n been sufficiently large, not counting the terminating null character, or a negative
13092     value if an encoding error occurred. Thus, the null-terminated output has been
13093     completely written if and only if the returned value is nonnegative and less than n.
13094     7.21.6.6 The sprintf function
13095     Synopsis
13096 1          #include <stdio.h>
13097            int sprintf(char * restrict s,
13098                 const char * restrict format, ...);
13099     Description
13100 2   The sprintf function is equivalent to fprintf, except that the output is written into
13101     an array (specified by the argument s) rather than to a stream. A null character is written
13102     at the end of the characters written; it is not counted as part of the returned value. If
13103     copying takes place between objects that overlap, the behavior is undefined.
13104     Returns
13105 3   The sprintf function returns the number of characters written in the array, not
13106     counting the terminating null character, or a negative value if an encoding error occurred.
13107
13108 [page 324]
13109
13110     7.21.6.7 The sscanf function
13111     Synopsis
13112 1           #include <stdio.h>
13113             int sscanf(const char * restrict s,
13114                  const char * restrict format, ...);
13115     Description
13116 2   The sscanf function is equivalent to fscanf, except that input is obtained from a
13117     string (specified by the argument s) rather than from a stream. Reaching the end of the
13118     string is equivalent to encountering end-of-file for the fscanf function. If copying
13119     takes place between objects that overlap, the behavior is undefined.
13120     Returns
13121 3   The sscanf function returns the value of the macro EOF if an input failure occurs
13122     before the first conversion (if any) has completed. Otherwise, the sscanf function
13123     returns the number of input items assigned, which can be fewer than provided for, or even
13124     zero, in the event of an early matching failure.
13125     7.21.6.8 The vfprintf function
13126     Synopsis
13127 1           #include <stdarg.h>
13128             #include <stdio.h>
13129             int vfprintf(FILE * restrict stream,
13130                  const char * restrict format,
13131                  va_list arg);
13132     Description
13133 2   The vfprintf function is equivalent to fprintf, with the variable argument list
13134     replaced by arg, which shall have been initialized by the va_start macro (and
13135     possibly subsequent va_arg calls). The vfprintf function does not invoke the
13136     va_end macro.277)
13137     Returns
13138 3   The vfprintf function returns the number of characters transmitted, or a negative
13139     value if an output or encoding error occurred.
13140 4   EXAMPLE       The following shows the use of the vfprintf function in a general error-reporting routine.
13141
13142
13143
13144
13145     277) As the functions vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf, and
13146          vsscanf invoke the va_arg macro, the value of arg after the return is indeterminate.
13147
13148 [page 325]
13149
13150            #include <stdarg.h>
13151            #include <stdio.h>
13152            void error(char *function_name, char *format, ...)
13153            {
13154                  va_list args;
13155                   va_start(args, format);
13156                   // print out name of function causing error
13157                   fprintf(stderr, "ERROR in %s: ", function_name);
13158                   // print out remainder of message
13159                   vfprintf(stderr, format, args);
13160                   va_end(args);
13161            }
13162
13163     7.21.6.9 The vfscanf function
13164     Synopsis
13165 1          #include <stdarg.h>
13166            #include <stdio.h>
13167            int vfscanf(FILE * restrict stream,
13168                 const char * restrict format,
13169                 va_list arg);
13170     Description
13171 2   The vfscanf function is equivalent to fscanf, with the variable argument list
13172     replaced by arg, which shall have been initialized by the va_start macro (and
13173     possibly subsequent va_arg calls). The vfscanf function does not invoke the
13174     va_end macro.277)
13175     Returns
13176 3   The vfscanf function returns the value of the macro EOF if an input failure occurs
13177     before the first conversion (if any) has completed. Otherwise, the vfscanf 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.10 The vprintf function
13181     Synopsis
13182 1          #include <stdarg.h>
13183            #include <stdio.h>
13184            int vprintf(const char * restrict format,
13185                 va_list arg);
13186     Description
13187 2   The vprintf function is equivalent to printf, with the variable argument list
13188     replaced by arg, which shall have been initialized by the va_start macro (and
13189
13190 [page 326]
13191
13192     possibly subsequent va_arg calls). The vprintf function does not invoke the
13193     va_end macro.277)
13194     Returns
13195 3   The vprintf function returns the number of characters transmitted, or a negative value
13196     if an output or encoding error occurred.
13197     7.21.6.11 The vscanf function
13198     Synopsis
13199 1           #include <stdarg.h>
13200             #include <stdio.h>
13201             int vscanf(const char * restrict format,
13202                  va_list arg);
13203     Description
13204 2   The vscanf function is equivalent to scanf, with the variable argument list replaced
13205     by arg, which shall have been initialized by the va_start macro (and possibly
13206     subsequent va_arg calls). The vscanf function does not invoke the va_end
13207     macro.277)
13208     Returns
13209 3   The vscanf function returns the value of the macro EOF if an input failure occurs
13210     before the first conversion (if any) has completed. Otherwise, the vscanf function
13211     returns the number of input items assigned, which can be fewer than provided for, or even
13212     zero, in the event of an early matching failure.
13213     7.21.6.12 The vsnprintf function
13214     Synopsis
13215 1           #include <stdarg.h>
13216             #include <stdio.h>
13217             int vsnprintf(char * restrict s, size_t n,
13218                  const char * restrict format,
13219                  va_list arg);
13220     Description
13221 2   The vsnprintf function is equivalent to snprintf, with the variable argument list
13222     replaced by arg, which shall have been initialized by the va_start macro (and
13223     possibly subsequent va_arg calls). The vsnprintf function does not invoke the
13224     va_end macro.277) If copying takes place between objects that overlap, the behavior is
13225     undefined.
13226
13227
13228
13229 [page 327]
13230
13231     Returns
13232 3   The vsnprintf function returns the number of characters that would have been written
13233     had n been sufficiently large, not counting the terminating null character, or a negative
13234     value if an encoding error occurred. Thus, the null-terminated output has been
13235     completely written if and only if the returned value is nonnegative and less than n.
13236     7.21.6.13 The vsprintf function
13237     Synopsis
13238 1          #include <stdarg.h>
13239            #include <stdio.h>
13240            int vsprintf(char * restrict s,
13241                 const char * restrict format,
13242                 va_list arg);
13243     Description
13244 2   The vsprintf function is equivalent to sprintf, with the variable argument list
13245     replaced by arg, which shall have been initialized by the va_start macro (and
13246     possibly subsequent va_arg calls). The vsprintf function does not invoke the
13247     va_end macro.277) If copying takes place between objects that overlap, the behavior is
13248     undefined.
13249     Returns
13250 3   The vsprintf function returns the number of characters written in the array, not
13251     counting the terminating null character, or a negative value if an encoding error occurred.
13252     7.21.6.14 The vsscanf function
13253     Synopsis
13254 1          #include <stdarg.h>
13255            #include <stdio.h>
13256            int vsscanf(const char * restrict s,
13257                 const char * restrict format,
13258                 va_list arg);
13259     Description
13260 2   The vsscanf function is equivalent to sscanf, with the variable argument list
13261     replaced by arg, which shall have been initialized by the va_start macro (and
13262     possibly subsequent va_arg calls). The vsscanf function does not invoke the
13263     va_end macro.277)
13264     Returns
13265 3   The vsscanf function returns the value of the macro EOF if an input failure occurs
13266     before the first conversion (if any) has completed. Otherwise, the vsscanf function
13267 [page 328]
13268
13269     returns the number of input items assigned, which can be fewer than provided for, or even
13270     zero, in the event of an early matching failure.
13271     7.21.7 Character input/output functions
13272     7.21.7.1 The fgetc function
13273     Synopsis
13274 1           #include <stdio.h>
13275             int fgetc(FILE *stream);
13276     Description
13277 2   If the end-of-file indicator for the input stream pointed to by stream is not set and a
13278     next character is present, the fgetc function obtains that character as an unsigned
13279     char converted to an int and advances the associated file position indicator for the
13280     stream (if defined).
13281     Returns
13282 3   If the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-
13283     of-file indicator for the stream is set and the fgetc function returns EOF. Otherwise, the
13284     fgetc function returns the next character from the input stream pointed to by stream.
13285     If a read error occurs, the error indicator for the stream is set and the fgetc function
13286     returns EOF.278)
13287     7.21.7.2 The fgets function
13288     Synopsis
13289 1           #include <stdio.h>
13290             char *fgets(char * restrict s, int n,
13291                  FILE * restrict stream);
13292     Description
13293 2   The fgets function reads at most one less than the number of characters specified by n
13294     from the stream pointed to by stream into the array pointed to by s. No additional
13295     characters are read after a new-line character (which is retained) or after end-of-file. A
13296     null character is written immediately after the last character read into the array.
13297     Returns
13298 3   The fgets function returns s if successful. If end-of-file is encountered and no
13299     characters have been read into the array, the contents of the array remain unchanged and a
13300     null pointer is returned. If a read error occurs during the operation, the array contents are
13301     indeterminate and a null pointer is returned.
13302
13303     278) An end-of-file and a read error can be distinguished by use of the feof and ferror functions.
13304
13305 [page 329]
13306
13307     7.21.7.3 The fputc function
13308     Synopsis
13309 1          #include <stdio.h>
13310            int fputc(int c, FILE *stream);
13311     Description
13312 2   The fputc function writes the character specified by c (converted to an unsigned
13313     char) to the output stream pointed to by stream, at the position indicated by the
13314     associated file position indicator for the stream (if defined), and advances the indicator
13315     appropriately. If the file cannot support positioning requests, or if the stream was opened
13316     with append mode, the character is appended to the output stream.
13317     Returns
13318 3   The fputc function returns the character written. If a write error occurs, the error
13319     indicator for the stream is set and fputc returns EOF.
13320     7.21.7.4 The fputs function
13321     Synopsis
13322 1          #include <stdio.h>
13323            int fputs(const char * restrict s,
13324                 FILE * restrict stream);
13325     Description
13326 2   The fputs function writes the string pointed to by s to the stream pointed to by
13327     stream. The terminating null character is not written.
13328     Returns
13329 3   The fputs function returns EOF if a write error occurs; otherwise it returns a
13330     nonnegative value.
13331     7.21.7.5 The getc function
13332     Synopsis
13333 1          #include <stdio.h>
13334            int getc(FILE *stream);
13335     Description
13336 2   The getc function is equivalent to fgetc, except that if it is implemented as a macro, it
13337     may evaluate stream more than once, so the argument should never be an expression
13338     with side effects.
13339
13340
13341
13342
13343 [page 330]
13344
13345     Returns
13346 3   The getc function returns the next character from the input stream pointed to by
13347     stream. If the stream is at end-of-file, the end-of-file indicator for the stream is set and
13348     getc returns EOF. If a read error occurs, the error indicator for the stream is set and
13349     getc returns EOF.
13350     7.21.7.6 The getchar function
13351     Synopsis
13352 1           #include <stdio.h>
13353             int getchar(void);
13354     Description
13355 2   The getchar function is equivalent to getc with the argument stdin.
13356     Returns
13357 3   The getchar function returns the next character from the input stream pointed to by
13358     stdin. If the stream is at end-of-file, the end-of-file indicator for the stream is set and
13359     getchar returns EOF. If a read error occurs, the error indicator for the stream is set and
13360     getchar returns EOF.
13361     7.21.7.7 The putc function
13362     Synopsis
13363 1           #include <stdio.h>
13364             int putc(int c, FILE *stream);
13365     Description
13366 2   The putc function is equivalent to fputc, except that if it is implemented as a macro, it
13367     may evaluate stream more than once, so that argument should never be an expression
13368     with side effects.
13369     Returns
13370 3   The putc function returns the character written. If a write error occurs, the error
13371     indicator for the stream is set and putc returns EOF.
13372     7.21.7.8 The putchar function
13373     Synopsis
13374 1           #include <stdio.h>
13375             int putchar(int c);
13376     Description
13377 2   The putchar function is equivalent to putc with the second argument stdout.
13378
13379
13380 [page 331]
13381
13382     Returns
13383 3   The putchar function returns the character written. If a write error occurs, the error
13384     indicator for the stream is set and putchar returns EOF.
13385     7.21.7.9 The puts function
13386     Synopsis
13387 1          #include <stdio.h>
13388            int puts(const char *s);
13389     Description
13390 2   The puts function writes the string pointed to by s to the stream pointed to by stdout,
13391     and appends a new-line character to the output. The terminating null character is not
13392     written.
13393     Returns
13394 3   The puts function returns EOF if a write error occurs; otherwise it returns a nonnegative
13395     value.
13396     7.21.7.10 The ungetc function
13397     Synopsis
13398 1          #include <stdio.h>
13399            int ungetc(int c, FILE *stream);
13400     Description
13401 2   The ungetc function pushes the character specified by c (converted to an unsigned
13402     char) back onto the input stream pointed to by stream. Pushed-back characters will be
13403     returned by subsequent reads on that stream in the reverse order of their pushing. A
13404     successful intervening call (with the stream pointed to by stream) to a file positioning
13405     function (fseek, fsetpos, or rewind) discards any pushed-back characters for the
13406     stream. The external storage corresponding to the stream is unchanged.
13407 3   One character of pushback is guaranteed. If the ungetc function is called too many
13408     times on the same stream without an intervening read or file positioning operation on that
13409     stream, the operation may fail.
13410 4   If the value of c equals that of the macro EOF, the operation fails and the input stream is
13411     unchanged.
13412 5   A successful call to the ungetc function clears the end-of-file indicator for the stream.
13413     The value of the file position indicator for the stream after reading or discarding all
13414     pushed-back characters shall be the same as it was before the characters were pushed
13415     back. For a text stream, the value of its file position indicator after a successful call to the
13416     ungetc function is unspecified until all pushed-back characters are read or discarded.
13417
13418 [page 332]
13419
13420     For a binary stream, its file position indicator is decremented by each successful call to
13421     the ungetc function; if its value was zero before a call, it is indeterminate after the
13422     call.279)
13423     Returns
13424 6   The ungetc function returns the character pushed back after conversion, or EOF if the
13425     operation fails.
13426     Forward references: file positioning functions (7.21.9).
13427     7.21.8 Direct input/output functions
13428     7.21.8.1 The fread function
13429     Synopsis
13430 1            #include <stdio.h>
13431              size_t fread(void * restrict ptr,
13432                   size_t size, size_t nmemb,
13433                   FILE * restrict stream);
13434     Description
13435 2   The fread function reads, into the array pointed to by ptr, up to nmemb elements
13436     whose size is specified by size, from the stream pointed to by stream. For each
13437     object, size calls are made to the fgetc function and the results stored, in the order
13438     read, in an array of unsigned char exactly overlaying the object. The file position
13439     indicator for the stream (if defined) is advanced by the number of characters successfully
13440     read. If an error occurs, the resulting value of the file position indicator for the stream is
13441     indeterminate. If a partial element is read, its value is indeterminate.
13442     Returns
13443 3   The fread function returns the number of elements successfully read, which may be
13444     less than nmemb if a read error or end-of-file is encountered. If size or nmemb is zero,
13445     fread returns zero and the contents of the array and the state of the stream remain
13446     unchanged.
13447
13448
13449
13450
13451     279) See ''future library directions'' (7.30.9).
13452
13453 [page 333]
13454
13455     7.21.8.2 The fwrite function
13456     Synopsis
13457 1          #include <stdio.h>
13458            size_t fwrite(const void * restrict ptr,
13459                 size_t size, size_t nmemb,
13460                 FILE * restrict stream);
13461     Description
13462 2   The fwrite function writes, from the array pointed to by ptr, up to nmemb elements
13463     whose size is specified by size, to the stream pointed to by stream. For each object,
13464     size calls are made to the fputc function, taking the values (in order) from an array of
13465     unsigned char exactly overlaying the object. The file position indicator for the
13466     stream (if defined) is advanced by the number of characters successfully written. If an
13467     error occurs, the resulting value of the file position indicator for the stream is
13468     indeterminate.
13469     Returns
13470 3   The fwrite function returns the number of elements successfully written, which will be
13471     less than nmemb only if a write error is encountered. If size or nmemb is zero,
13472     fwrite returns zero and the state of the stream remains unchanged.
13473     7.21.9 File positioning functions
13474     7.21.9.1 The fgetpos function
13475     Synopsis
13476 1          #include <stdio.h>
13477            int fgetpos(FILE * restrict stream,
13478                 fpos_t * restrict pos);
13479     Description
13480 2   The fgetpos function stores the current values of the parse state (if any) and file
13481     position indicator for the stream pointed to by stream in the object pointed to by pos.
13482     The values stored contain unspecified information usable by the fsetpos function for
13483     repositioning the stream to its position at the time of the call to the fgetpos function.
13484     Returns
13485 3   If successful, the fgetpos function returns zero; on failure, the fgetpos function
13486     returns nonzero and stores an implementation-defined positive value in errno.
13487     Forward references: the fsetpos function (7.21.9.3).
13488
13489
13490
13491
13492 [page 334]
13493
13494     7.21.9.2 The fseek function
13495     Synopsis
13496 1           #include <stdio.h>
13497             int fseek(FILE *stream, long int offset, int whence);
13498     Description
13499 2   The fseek function sets the file position indicator for the stream pointed to by stream.
13500     If a read or write error occurs, the error indicator for the stream is set and fseek fails.
13501 3   For a binary stream, the new position, measured in characters from the beginning of the
13502     file, is obtained by adding offset to the position specified by whence. The specified
13503     position is the beginning of the file if whence is SEEK_SET, the current value of the file
13504     position indicator if SEEK_CUR, or end-of-file if SEEK_END. A binary stream need not
13505     meaningfully support fseek calls with a whence value of SEEK_END.
13506 4   For a text stream, either offset shall be zero, or offset shall be a value returned by
13507     an earlier successful call to the ftell function on a stream associated with the same file
13508     and whence shall be SEEK_SET.
13509 5   After determining the new position, a successful call to the fseek function undoes any
13510     effects of the ungetc function on the stream, clears the end-of-file indicator for the
13511     stream, and then establishes the new position. After a successful fseek call, the next
13512     operation on an update stream may be either input or output.
13513     Returns
13514 6   The fseek function returns nonzero only for a request that cannot be satisfied.
13515     Forward references: the ftell function (7.21.9.4).
13516     7.21.9.3 The fsetpos function
13517     Synopsis
13518 1           #include <stdio.h>
13519             int fsetpos(FILE *stream, const fpos_t *pos);
13520     Description
13521 2   The fsetpos function sets the mbstate_t object (if any) and file position indicator
13522     for the stream pointed to by stream according to the value of the object pointed to by
13523     pos, which shall be a value obtained from an earlier successful call to the fgetpos
13524     function on a stream associated with the same file. If a read or write error occurs, the
13525     error indicator for the stream is set and fsetpos fails.
13526 3   A successful call to the fsetpos function undoes any effects of the ungetc function
13527     on the stream, clears the end-of-file indicator for the stream, and then establishes the new
13528     parse state and position. After a successful fsetpos call, the next operation on an
13529
13530 [page 335]
13531
13532     update stream may be either input or output.
13533     Returns
13534 4   If successful, the fsetpos function returns zero; on failure, the fsetpos function
13535     returns nonzero and stores an implementation-defined positive value in errno.
13536     7.21.9.4 The ftell function
13537     Synopsis
13538 1          #include <stdio.h>
13539            long int ftell(FILE *stream);
13540     Description
13541 2   The ftell function obtains the current value of the file position indicator for the stream
13542     pointed to by stream. For a binary stream, the value is the number of characters from
13543     the beginning of the file. For a text stream, its file position indicator contains unspecified
13544     information, usable by the fseek function for returning the file position indicator for the
13545     stream to its position at the time of the ftell call; the difference between two such
13546     return values is not necessarily a meaningful measure of the number of characters written
13547     or read.
13548     Returns
13549 3   If successful, the ftell function returns the current value of the file position indicator
13550     for the stream. On failure, the ftell function returns -1L and stores an
13551     implementation-defined positive value in errno.
13552     7.21.9.5 The rewind function
13553     Synopsis
13554 1          #include <stdio.h>
13555            void rewind(FILE *stream);
13556     Description
13557 2   The rewind function sets the file position indicator for the stream pointed to by
13558     stream to the beginning of the file. It is equivalent to
13559            (void)fseek(stream, 0L, SEEK_SET)
13560     except that the error indicator for the stream is also cleared.
13561     Returns
13562 3   The rewind function returns no value.
13563
13564
13565
13566
13567 [page 336]
13568
13569     7.21.10 Error-handling functions
13570     7.21.10.1 The clearerr function
13571     Synopsis
13572 1           #include <stdio.h>
13573             void clearerr(FILE *stream);
13574     Description
13575 2   The clearerr function clears the end-of-file and error indicators for the stream pointed
13576     to by stream.
13577     Returns
13578 3   The clearerr function returns no value.
13579     7.21.10.2 The feof function
13580     Synopsis
13581 1           #include <stdio.h>
13582             int feof(FILE *stream);
13583     Description
13584 2   The feof function tests the end-of-file indicator for the stream pointed to by stream.
13585     Returns
13586 3   The feof function returns nonzero if and only if the end-of-file indicator is set for
13587     stream.
13588     7.21.10.3 The ferror function
13589     Synopsis
13590 1           #include <stdio.h>
13591             int ferror(FILE *stream);
13592     Description
13593 2   The ferror function tests the error indicator for the stream pointed to by stream.
13594     Returns
13595 3   The ferror function returns nonzero if and only if the error indicator is set for
13596     stream.
13597
13598
13599
13600
13601 [page 337]
13602
13603     7.21.10.4 The perror function
13604     Synopsis
13605 1          #include <stdio.h>
13606            void perror(const char *s);
13607     Description
13608 2   The perror function maps the error number in the integer expression errno to an
13609     error message. It writes a sequence of characters to the standard error stream thus: first
13610     (if s is not a null pointer and the character pointed to by s is not the null character), the
13611     string pointed to by s followed by a colon (:) and a space; then an appropriate error
13612     message string followed by a new-line character. The contents of the error message
13613     strings are the same as those returned by the strerror function with argument errno.
13614     Returns
13615 3   The perror function returns no value.
13616     Forward references: the strerror function (7.23.6.2).
13617
13618
13619
13620
13621 [page 338]
13622
13623     7.22 General utilities <stdlib.h>
13624 1   The header <stdlib.h> declares five types and several functions of general utility, and
13625     defines several macros.280)
13626 2   The types declared are size_t and wchar_t (both described in 7.19),
13627              div_t
13628     which is a structure type that is the type of the value returned by the div function,
13629              ldiv_t
13630     which is a structure type that is the type of the value returned by the ldiv function, and
13631              lldiv_t
13632     which is a structure type that is the type of the value returned by the lldiv function.
13633 3   The macros defined are NULL (described in 7.19);
13634              EXIT_FAILURE
13635     and
13636              EXIT_SUCCESS
13637     which expand to integer constant expressions that can be used as the argument to the
13638     exit function to return unsuccessful or successful termination status, respectively, to the
13639     host environment;
13640              RAND_MAX
13641     which expands to an integer constant expression that is the maximum value returned by
13642     the rand function; and
13643              MB_CUR_MAX
13644     which expands to a positive integer expression with type size_t that is the maximum
13645     number of bytes in a multibyte character for the extended character set specified by the
13646     current locale (category LC_CTYPE), which is never greater than MB_LEN_MAX.
13647
13648
13649
13650
13651     280) See ''future library directions'' (7.30.10).
13652
13653 [page 339]
13654
13655     7.22.1 Numeric conversion functions
13656 1   The functions atof, atoi, atol, and atoll need not affect the value of the integer
13657     expression errno on an error. If the value of the result cannot be represented, the
13658     behavior is undefined.
13659     7.22.1.1 The atof function
13660     Synopsis
13661 1          #include <stdlib.h>
13662            double atof(const char *nptr);
13663     Description
13664 2   The atof function converts the initial portion of the string pointed to by nptr to
13665     double representation. Except for the behavior on error, it is equivalent to
13666            strtod(nptr, (char **)NULL)
13667     Returns
13668 3   The atof function returns the converted value.
13669     Forward references: the strtod, strtof, and strtold functions (7.22.1.3).
13670     7.22.1.2 The atoi, atol, and atoll functions
13671     Synopsis
13672 1          #include <stdlib.h>
13673            int atoi(const char *nptr);
13674            long int atol(const char *nptr);
13675            long long int atoll(const char *nptr);
13676     Description
13677 2   The atoi, atol, and atoll functions convert the initial portion of the string pointed
13678     to by nptr to int, long int, and long long int representation, respectively.
13679     Except for the behavior on error, they are equivalent to
13680            atoi: (int)strtol(nptr, (char **)NULL, 10)
13681            atol: strtol(nptr, (char **)NULL, 10)
13682            atoll: strtoll(nptr, (char **)NULL, 10)
13683     Returns
13684 3   The atoi, atol, and atoll functions return the converted value.
13685     Forward references: the strtol, strtoll, strtoul, and strtoull functions
13686     (7.22.1.4).
13687
13688
13689
13690 [page 340]
13691
13692     7.22.1.3 The strtod, strtof, and strtold functions
13693     Synopsis
13694 1           #include <stdlib.h>
13695             double strtod(const char * restrict nptr,
13696                  char ** restrict endptr);
13697             float strtof(const char * restrict nptr,
13698                  char ** restrict endptr);
13699             long double strtold(const char * restrict nptr,
13700                  char ** restrict endptr);
13701     Description
13702 2   The strtod, strtof, and strtold functions convert the initial portion of the string
13703     pointed to by nptr to double, float, and long double representation,
13704     respectively. First, they decompose the input string into three parts: an initial, possibly
13705     empty, sequence of white-space characters (as specified by the isspace function), a
13706     subject sequence resembling a floating-point constant or representing an infinity or NaN;
13707     and a final string of one or more unrecognized characters, including the terminating null
13708     character of the input string. Then, they attempt to convert the subject sequence to a
13709     floating-point number, and return the result.
13710 3   The expected form of the subject sequence is an optional plus or minus sign, then one of
13711     the following:
13712     -- a nonempty sequence of decimal digits optionally containing a decimal-point
13713       character, then an optional exponent part as defined in 6.4.4.2;
13714     -- a 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing a
13715       decimal-point character, then an optional binary exponent part as defined in 6.4.4.2;
13716     -- INF or INFINITY, ignoring case
13717     -- NAN or NAN(n-char-sequenceopt), ignoring case in the NAN part, where:
13718                n-char-sequence:
13719                       digit
13720                       nondigit
13721                       n-char-sequence digit
13722                       n-char-sequence nondigit
13723     The subject sequence is defined as the longest initial subsequence of the input string,
13724     starting with the first non-white-space character, that is of the expected form. The subject
13725     sequence contains no characters if the input string is not of the expected form.
13726 4   If the subject sequence has the expected form for a floating-point number, the sequence of
13727     characters starting with the first digit or the decimal-point character (whichever occurs
13728     first) is interpreted as a floating constant according to the rules of 6.4.4.2, except that the
13729 [page 341]
13730
13731     decimal-point character is used in place of a period, and that if neither an exponent part
13732     nor a decimal-point character appears in a decimal floating point number, or if a binary
13733     exponent part does not appear in a hexadecimal floating point number, an exponent part
13734     of the appropriate type with value zero is assumed to follow the last digit in the string. If
13735     the subject sequence begins with a minus sign, the sequence is interpreted as negated.281)
13736     A character sequence INF or INFINITY is interpreted as an infinity, if representable in
13737     the return type, else like a floating constant that is too large for the range of the return
13738     type. A character sequence NAN or NAN(n-char-sequenceopt), is interpreted as a quiet
13739     NaN, if supported in the return type, else like a subject sequence part that does not have
13740     the expected form; the meaning of the n-char sequences is implementation-defined.282) A
13741     pointer to the final string is stored in the object pointed to by endptr, provided that
13742     endptr is not a null pointer.
13743 5   If the subject sequence has the hexadecimal form and FLT_RADIX is a power of 2, the
13744     value resulting from the conversion is correctly rounded.
13745 6   In other than the "C" locale, additional locale-specific subject sequence forms may be
13746     accepted.
13747 7   If the subject sequence is empty or does not have the expected form, no conversion is
13748     performed; the value of nptr is stored in the object pointed to by endptr, provided
13749     that endptr is not a null pointer.
13750     Recommended practice
13751 8   If the subject sequence has the hexadecimal form, FLT_RADIX is not a power of 2, and
13752     the result is not exactly representable, the result should be one of the two numbers in the
13753     appropriate internal format that are adjacent to the hexadecimal floating source value,
13754     with the extra stipulation that the error should have a correct sign for the current rounding
13755     direction.
13756 9   If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in
13757     <float.h>) significant digits, the result should be correctly rounded. If the subject
13758     sequence D has the decimal form and more than DECIMAL_DIG significant digits,
13759     consider the two bounding, adjacent decimal strings L and U, both having
13760     DECIMAL_DIG significant digits, such that the values of L, D, and U satisfy L <= D <= U.
13761     The result should be one of the (equal or adjacent) values that would be obtained by
13762     correctly rounding L and U according to the current rounding direction, with the extra
13763
13764     281) It is unspecified whether a minus-signed sequence is converted to a negative number directly or by
13765          negating the value resulting from converting the corresponding unsigned sequence (see F.5); the two
13766          methods may yield different results if rounding is toward positive or negative infinity. In either case,
13767          the functions honor the sign of zero if floating-point arithmetic supports signed zeros.
13768     282) An implementation may use the n-char sequence to determine extra information to be represented in
13769          the NaN's significand.
13770
13771 [page 342]
13772
13773      stipulation that the error with respect to D should have a correct sign for the current
13774      rounding direction.283)
13775      Returns
13776 10   The functions return the converted value, if any. If no conversion could be performed,
13777      zero is returned. If the correct value overflows and default rounding is in effect (7.12.1),
13778      plus or minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the
13779      return type and sign of the value), and the value of the macro ERANGE is stored in
13780      errno. If the result underflows (7.12.1), the functions return a value whose magnitude is
13781      no greater than the smallest normalized positive number in the return type; whether
13782      errno acquires the value ERANGE is implementation-defined.
13783      7.22.1.4 The strtol, strtoll, strtoul, and strtoull functions
13784      Synopsis
13785 1            #include <stdlib.h>
13786              long int strtol(
13787                   const char * restrict nptr,
13788                   char ** restrict endptr,
13789                   int base);
13790              long long int strtoll(
13791                   const char * restrict nptr,
13792                   char ** restrict endptr,
13793                   int base);
13794              unsigned long int strtoul(
13795                   const char * restrict nptr,
13796                   char ** restrict endptr,
13797                   int base);
13798              unsigned long long int strtoull(
13799                   const char * restrict nptr,
13800                   char ** restrict endptr,
13801                   int base);
13802      Description
13803 2    The strtol, strtoll, strtoul, and strtoull functions convert the initial
13804      portion of the string pointed to by nptr to long int, long long int, unsigned
13805      long int, and unsigned long long int representation, respectively. First,
13806      they decompose the input string into three parts: an initial, possibly empty, sequence of
13807      white-space characters (as specified by the isspace function), a subject sequence
13808
13809
13810      283) DECIMAL_DIG, defined in <float.h>, should be sufficiently large that L and U will usually round
13811           to the same internal floating value, but if not will round to adjacent values.
13812
13813 [page 343]
13814
13815     resembling an integer represented in some radix determined by the value of base, and a
13816     final string of one or more unrecognized characters, including the terminating null
13817     character of the input string. Then, they attempt to convert the subject sequence to an
13818     integer, and return the result.
13819 3   If the value of base is zero, the expected form of the subject sequence is that of an
13820     integer constant as described in 6.4.4.1, optionally preceded by a plus or minus sign, but
13821     not including an integer suffix. If the value of base is between 2 and 36 (inclusive), the
13822     expected form of the subject sequence is a sequence of letters and digits representing an
13823     integer with the radix specified by base, optionally preceded by a plus or minus sign,
13824     but not including an integer suffix. The letters from a (or A) through z (or Z) are
13825     ascribed the values 10 through 35; only letters and digits whose ascribed values are less
13826     than that of base are permitted. If the value of base is 16, the characters 0x or 0X may
13827     optionally precede the sequence of letters and digits, following the sign if present.
13828 4   The subject sequence is defined as the longest initial subsequence of the input string,
13829     starting with the first non-white-space character, that is of the expected form. The subject
13830     sequence contains no characters if the input string is empty or consists entirely of white
13831     space, or if the first non-white-space character is other than a sign or a permissible letter
13832     or digit.
13833 5   If the subject sequence has the expected form and the value of base is zero, the sequence
13834     of characters starting with the first digit is interpreted as an integer constant according to
13835     the rules of 6.4.4.1. If the subject sequence has the expected form and the value of base
13836     is between 2 and 36, it is used as the base for conversion, ascribing to each letter its value
13837     as given above. If the subject sequence begins with a minus sign, the value resulting from
13838     the conversion is negated (in the return type). A pointer to the final string is stored in the
13839     object pointed to by endptr, provided that endptr is not a null pointer.
13840 6   In other than the "C" locale, additional locale-specific subject sequence forms may be
13841     accepted.
13842 7   If the subject sequence is empty or does not have the expected form, no conversion is
13843     performed; the value of nptr is stored in the object pointed to by endptr, provided
13844     that endptr is not a null pointer.
13845     Returns
13846 8   The strtol, strtoll, strtoul, and strtoull functions return the converted
13847     value, if any. If no conversion could be performed, zero is returned. If the correct value
13848     is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
13849     LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type
13850     and sign of the value, if any), and the value of the macro ERANGE is stored in errno.
13851
13852
13853
13854
13855 [page 344]
13856
13857     7.22.2 Pseudo-random sequence generation functions
13858     7.22.2.1 The rand function
13859     Synopsis
13860 1           #include <stdlib.h>
13861             int rand(void);
13862     Description
13863 2   The rand function computes a sequence of pseudo-random integers in the range 0 to
13864     RAND_MAX.284)
13865 3   The rand function is not required to avoid data races. The implementation shall behave
13866     as if no library function calls the rand function.
13867     Returns
13868 4   The rand function returns a pseudo-random integer.
13869     Environmental limits
13870 5   The value of the RAND_MAX macro shall be at least 32767.
13871     7.22.2.2 The srand function
13872     Synopsis
13873 1           #include <stdlib.h>
13874             void srand(unsigned int seed);
13875     Description
13876 2   The srand function uses the argument as a seed for a new sequence of pseudo-random
13877     numbers to be returned by subsequent calls to rand. If srand is then called with the
13878     same seed value, the sequence of pseudo-random numbers shall be repeated. If rand is
13879     called before any calls to srand have been made, the same sequence shall be generated
13880     as when srand is first called with a seed value of 1.
13881 3   The implementation shall behave as if no library function calls the srand function.
13882     Returns
13883 4   The srand function returns no value.
13884
13885
13886
13887
13888     284) There are no guarantees as to the quality of the random sequence produced and some implementations
13889          are known to produce sequences with distressingly non-random low-order bits. Applications with
13890          particular requirements should use a generator that is known to be sufficient for their needs.
13891
13892 [page 345]
13893
13894 5   EXAMPLE       The following functions define a portable implementation of rand and srand.
13895            static unsigned long int next = 1;
13896            int rand(void)   // RAND_MAX assumed to be 32767
13897            {
13898                  next = next * 1103515245 + 12345;
13899                  return (unsigned int)(next/65536) % 32768;
13900            }
13901            void srand(unsigned int seed)
13902            {
13903                  next = seed;
13904            }
13905
13906     7.22.3 Memory management functions
13907 1   The order and contiguity of storage allocated by successive calls to the
13908     aligned_alloc, calloc, malloc, and realloc functions is unspecified. The
13909     pointer returned if the allocation succeeds is suitably aligned so that it may be assigned to
13910     a pointer to any type of object with a fundamental alignment requirement and then used
13911     to access such an object or an array of such objects in the space allocated (until the space
13912     is explicitly deallocated). The lifetime of an allocated object extends from the allocation
13913     until the deallocation. Each such allocation shall yield a pointer to an object disjoint from
13914     any other object. The pointer returned points to the start (lowest byte address) of the
13915     allocated space. If the space cannot be allocated, a null pointer is returned. If the size of
13916     the space requested is zero, the behavior is implementation-defined: either a null pointer
13917     is returned, or the behavior is as if the size were some nonzero value, except that the
13918     returned pointer shall not be used to access an object.
13919     7.22.3.1 The aligned_alloc function
13920     Synopsis
13921 1          #include <stdlib.h>
13922            void *aligned_alloc(size_t alignment, size_t size);
13923     Description
13924 2   The aligned_alloc function allocates space for an object whose alignment is
13925     specified by alignment, whose size is specified by size, and whose value is
13926     indeterminate. The value of alignment shall be a valid alignment supported by the
13927     implementation and the value of size shall be an integral multiple of alignment.
13928     Returns
13929 3   The aligned_alloc function returns either a null pointer or a pointer to the allocated
13930     space.
13931
13932
13933
13934
13935 [page 346]
13936
13937     7.22.3.2 The calloc function
13938     Synopsis
13939 1           #include <stdlib.h>
13940             void *calloc(size_t nmemb, size_t size);
13941     Description
13942 2   The calloc function allocates space for an array of nmemb objects, each of whose size
13943     is size. The space is initialized to all bits zero.285)
13944     Returns
13945 3   The calloc function returns either a null pointer or a pointer to the allocated space.
13946     7.22.3.3 The free function
13947     Synopsis
13948 1           #include <stdlib.h>
13949             void free(void *ptr);
13950     Description
13951 2   The free function causes the space pointed to by ptr to be deallocated, that is, made
13952     available for further allocation. If ptr is a null pointer, no action occurs. Otherwise, if
13953     the argument does not match a pointer earlier returned by a memory management
13954     function, or if the space has been deallocated by a call to free or realloc, the
13955     behavior is undefined.
13956     Returns
13957 3   The free function returns no value.
13958     7.22.3.4 The malloc function
13959     Synopsis
13960 1           #include <stdlib.h>
13961             void *malloc(size_t size);
13962     Description
13963 2   The malloc function allocates space for an object whose size is specified by size and
13964     whose value is indeterminate.
13965
13966
13967
13968
13969     285) Note that this need not be the same as the representation of floating-point zero or a null pointer
13970          constant.
13971
13972 [page 347]
13973
13974     Returns
13975 3   The malloc function returns either a null pointer or a pointer to the allocated space.
13976     7.22.3.5 The realloc function
13977     Synopsis
13978 1          #include <stdlib.h>
13979            void *realloc(void *ptr, size_t size);
13980     Description
13981 2   The realloc function deallocates the old object pointed to by ptr and returns a
13982     pointer to a new object that has the size specified by size. The contents of the new
13983     object shall be the same as that of the old object prior to deallocation, up to the lesser of
13984     the new and old sizes. Any bytes in the new object beyond the size of the old object have
13985     indeterminate values.
13986 3   If ptr is a null pointer, the realloc function behaves like the malloc function for the
13987     specified size. Otherwise, if ptr does not match a pointer earlier returned by a memory
13988     management function, or if the space has been deallocated by a call to the free or
13989     realloc function, the behavior is undefined. If memory for the new object cannot be
13990     allocated, the old object is not deallocated and its value is unchanged.
13991     Returns
13992 4   The realloc function returns a pointer to the new object (which may have the same
13993     value as a pointer to the old object), or a null pointer if the new object could not be
13994     allocated.
13995     7.22.4 Communication with the environment
13996     7.22.4.1 The abort function
13997     Synopsis
13998 1          #include <stdlib.h>
13999            _Noreturn void abort(void);
14000     Description
14001 2   The abort function causes abnormal program termination to occur, unless the signal
14002     SIGABRT is being caught and the signal handler does not return. Whether open streams
14003     with unwritten buffered data are flushed, open streams are closed, or temporary files are
14004     removed is implementation-defined. An implementation-defined form of the status
14005     unsuccessful termination is returned to the host environment by means of the function
14006     call raise(SIGABRT).
14007
14008
14009
14010
14011 [page 348]
14012
14013     Returns
14014 3   The abort function does not return to its caller.
14015     7.22.4.2 The atexit function
14016     Synopsis
14017 1           #include <stdlib.h>
14018             int atexit(void (*func)(void));
14019     Description
14020 2   The atexit function registers the function pointed to by func, to be called without
14021     arguments at normal program termination.286)
14022     Environmental limits
14023 3   The implementation shall support the registration of at least 32 functions.
14024     Returns
14025 4   The atexit function returns zero if the registration succeeds, nonzero if it fails.
14026     Forward references: the at_quick_exit function (7.22.4.3), the exit function
14027     (7.22.4.4).
14028     7.22.4.3 The at_quick_exit function
14029     Synopsis
14030 1           #include <stdlib.h>
14031             int at_quick_exit(void (*func)(void));
14032     Description
14033 2   The at_quick_exit function registers the function pointed to by func, to be called
14034     without arguments should quick_exit be called.287)
14035     Environmental limits
14036 3   The implementation shall support the registration of at least 32 functions.
14037     Returns
14038 4   The at_quick_exit function returns zero if the registration succeeds, nonzero if it
14039     fails.
14040     Forward references: the quick_exit function (7.22.4.7).
14041
14042     286) The atexit function registrations are distinct from the at_quick_exit registrations, so
14043          applications may need to call both registration functions with the same argument.
14044     287) The at_quick_exit function registrations are distinct from the atexit registrations, so
14045          applications may need to call both registration functions with the same argument.
14046
14047 [page 349]
14048
14049     7.22.4.4 The exit function
14050     Synopsis
14051 1           #include <stdlib.h>
14052             _Noreturn void exit(int status);
14053     Description
14054 2   The exit function causes normal program termination to occur. No functions registered
14055     by the at_quick_exit function are called. If a program calls the exit function
14056     more than once, or calls the quick_exit function in addition to the exit function, the
14057     behavior is undefined.
14058 3   First, all functions registered by the atexit function are called, in the reverse order of
14059     their registration,288) except that a function is called after any previously registered
14060     functions that had already been called at the time it was registered. If, during the call to
14061     any such function, a call to the longjmp function is made that would terminate the call
14062     to the registered function, the behavior is undefined.
14063 4   Next, all open streams with unwritten buffered data are flushed, all open streams are
14064     closed, and all files created by the tmpfile function are removed.
14065 5   Finally, control is returned to the host environment. If the value of status is zero or
14066     EXIT_SUCCESS, an implementation-defined form of the status successful termination is
14067     returned. If the value of status is EXIT_FAILURE, an implementation-defined form
14068     of the status unsuccessful termination is returned. Otherwise the status returned is
14069     implementation-defined.
14070     Returns
14071 6   The exit function cannot return to its caller.
14072     7.22.4.5 The _Exit function
14073     Synopsis
14074 1           #include <stdlib.h>
14075             _Noreturn void _Exit(int status);
14076     Description
14077 2   The _Exit function causes normal program termination to occur and control to be
14078     returned to the host environment. No functions registered by the atexit function, the
14079     at_quick_exit function, or signal handlers registered by the signal function are
14080     called. The status returned to the host environment is determined in the same way as for
14081
14082
14083     288) Each function is called as many times as it was registered, and in the correct order with respect to
14084          other registered functions.
14085
14086 [page 350]
14087
14088     the exit function (7.22.4.4). Whether open streams with unwritten buffered data are
14089     flushed, open streams are closed, or temporary files are removed is implementation-
14090     defined.
14091     Returns
14092 3   The _Exit function cannot return to its caller.
14093     7.22.4.6 The getenv function
14094     Synopsis
14095 1           #include <stdlib.h>
14096             char *getenv(const char *name);
14097     Description
14098 2   The getenv function searches an environment list, provided by the host environment,
14099     for a string that matches the string pointed to by name. The set of environment names
14100     and the method for altering the environment list are implementation-defined. The
14101     getenv function need not avoid data races with other threads of execution that modify
14102     the environment list.289)
14103 3   The implementation shall behave as if no library function calls the getenv function.
14104     Returns
14105 4   The getenv function returns a pointer to a string associated with the matched list
14106     member. The string pointed to shall not be modified by the program, but may be
14107     overwritten by a subsequent call to the getenv function. If the specified name cannot
14108     be found, a null pointer is returned.
14109     7.22.4.7 The quick_exit function
14110     Synopsis
14111 1           #include <stdlib.h>
14112             _Noreturn void quick_exit(int status);
14113     Description
14114 2   The quick_exit function causes normal program termination to occur. No functions
14115     registered by the atexit function or signal handlers registered by the signal function
14116     are called. If a program calls the quick_exit function more than once, or calls the
14117     exit function in addition to the quick_exit function, the behavior is undefined.
14118 3   The quick_exit function first calls all functions registered by the at_quick_exit
14119     function, in the reverse order of their registration,290) except that a function is called after
14120
14121
14122     289) Many implementations provide non-standard functions that modify the environment list.
14123
14124 [page 351]
14125
14126     any previously registered functions that had already been called at the time it was
14127     registered. If, during the call to any such function, a call to the longjmp function is
14128     made that would terminate the call to the registered function, the behavior is undefined.
14129 4   Then control is returned to the host environment by means of the function call
14130     _Exit(status).
14131     Returns
14132 5   The quick_exit function cannot return to its caller.
14133     7.22.4.8 The system function
14134     Synopsis
14135 1           #include <stdlib.h>
14136             int system(const char *string);
14137     Description
14138 2   If string is a null pointer, the system function determines whether the host
14139     environment has a command processor. If string is not a null pointer, the system
14140     function passes the string pointed to by string to that command processor to be
14141     executed in a manner which the implementation shall document; this might then cause the
14142     program calling system to behave in a non-conforming manner or to terminate.
14143     Returns
14144 3   If the argument is a null pointer, the system function returns nonzero only if a
14145     command processor is available. If the argument is not a null pointer, and the system
14146     function does return, it returns an implementation-defined value.
14147     7.22.5 Searching and sorting utilities
14148 1   These utilities make use of a comparison function to search or sort arrays of unspecified
14149     type. Where an argument declared as size_t nmemb specifies the length of the array
14150     for a function, nmemb can have the value zero on a call to that function; the comparison
14151     function is not called, a search finds no matching element, and sorting performs no
14152     rearrangement. Pointer arguments on such a call shall still have valid values, as described
14153     in 7.1.4.
14154 2   The implementation shall ensure that the second argument of the comparison function
14155     (when called from bsearch), or both arguments (when called from qsort), are
14156     pointers to elements of the array.291) The first argument when called from bsearch
14157     shall equal key.
14158
14159
14160
14161     290) Each function is called as many times as it was registered, and in the correct order with respect to
14162          other registered functions.
14163
14164 [page 352]
14165
14166 3   The comparison function shall not alter the contents of the array. The implementation
14167     may reorder elements of the array between calls to the comparison function, but shall not
14168     alter the contents of any individual element.
14169 4   When the same objects (consisting of size bytes, irrespective of their current positions
14170     in the array) are passed more than once to the comparison function, the results shall be
14171     consistent with one another. That is, for qsort they shall define a total ordering on the
14172     array, and for bsearch the same object shall always compare the same way with the
14173     key.
14174 5   A sequence point occurs immediately before and immediately after each call to the
14175     comparison function, and also between any call to the comparison function and any
14176     movement of the objects passed as arguments to that call.
14177     7.22.5.1 The bsearch function
14178     Synopsis
14179 1            #include <stdlib.h>
14180              void *bsearch(const void *key, const void *base,
14181                   size_t nmemb, size_t size,
14182                   int (*compar)(const void *, const void *));
14183     Description
14184 2   The bsearch function searches an array of nmemb objects, the initial element of which
14185     is pointed to by base, for an element that matches the object pointed to by key. The
14186     size of each element of the array is specified by size.
14187 3   The comparison function pointed to by compar is called with two arguments that point
14188     to the key object and to an array element, in that order. The function shall return an
14189     integer less than, equal to, or greater than zero if the key object is considered,
14190     respectively, to be less than, to match, or to be greater than the array element. The array
14191     shall consist of: all the elements that compare less than, all the elements that compare
14192     equal to, and all the elements that compare greater than the key object, in that order.292)
14193     Returns
14194 4   The bsearch function returns a pointer to a matching element of the array, or a null
14195     pointer if no match is found. If two elements compare as equal, which element is
14196
14197
14198     291) That is, if the value passed is p, then the following expressions are always nonzero:
14199                   ((char *)p - (char *)base) % size == 0
14200                   (char *)p >= (char *)base
14201                   (char *)p < (char *)base + nmemb * size
14202
14203     292) In practice, the entire array is sorted according to the comparison function.
14204
14205 [page 353]
14206
14207     matched is unspecified.
14208     7.22.5.2 The qsort function
14209     Synopsis
14210 1           #include <stdlib.h>
14211             void qsort(void *base, size_t nmemb, size_t size,
14212                  int (*compar)(const void *, const void *));
14213     Description
14214 2   The qsort function sorts an array of nmemb objects, the initial element of which is
14215     pointed to by base. The size of each object is specified by size.
14216 3   The contents of the array are sorted into ascending order according to a comparison
14217     function pointed to by compar, which is called with two arguments that point to the
14218     objects being compared. The function shall return an integer less than, equal to, or
14219     greater than zero if the first argument is considered to be respectively less than, equal to,
14220     or greater than the second.
14221 4   If two elements compare as equal, their order in the resulting sorted array is unspecified.
14222     Returns
14223 5   The qsort function returns no value.
14224     7.22.6 Integer arithmetic functions
14225     7.22.6.1 The abs, labs and llabs functions
14226     Synopsis
14227 1           #include <stdlib.h>
14228             int abs(int j);
14229             long int labs(long int j);
14230             long long int llabs(long long int j);
14231     Description
14232 2   The abs, labs, and llabs functions compute the absolute value of an integer j. If the
14233     result cannot be represented, the behavior is undefined.293)
14234     Returns
14235 3   The abs, labs, and llabs, functions return the absolute value.
14236
14237
14238
14239
14240     293) The absolute value of the most negative number cannot be represented in two's complement.
14241
14242 [page 354]
14243
14244     7.22.6.2 The div, ldiv, and lldiv functions
14245     Synopsis
14246 1           #include <stdlib.h>
14247             div_t div(int numer, int denom);
14248             ldiv_t ldiv(long int numer, long int denom);
14249             lldiv_t lldiv(long long int numer, long long int denom);
14250     Description
14251 2   The div, ldiv, and lldiv, functions compute numer / denom and numer %
14252     denom in a single operation.
14253     Returns
14254 3   The div, ldiv, and lldiv functions return a structure of type div_t, ldiv_t, and
14255     lldiv_t, respectively, comprising both the quotient and the remainder. The structures
14256     shall contain (in either order) the members quot (the quotient) and rem (the remainder),
14257     each of which has the same type as the arguments numer and denom. If either part of
14258     the result cannot be represented, the behavior is undefined.
14259     7.22.7 Multibyte/wide character conversion functions
14260 1   The behavior of the multibyte character functions is affected by the LC_CTYPE category
14261     of the current locale. For a state-dependent encoding, each function is placed into its
14262     initial conversion state at program startup and can be returned to that state by a call for
14263     which its character pointer argument, s, is a null pointer. Subsequent calls with s as
14264     other than a null pointer cause the internal conversion state of the function to be altered as
14265     necessary. A call with s as a null pointer causes these functions to return a nonzero value
14266     if encodings have state dependency, and zero otherwise.294) Changing the LC_CTYPE
14267     category causes the conversion state of these functions to be indeterminate.
14268     7.22.7.1 The mblen function
14269     Synopsis
14270 1           #include <stdlib.h>
14271             int mblen(const char *s, size_t n);
14272     Description
14273 2   If s is not a null pointer, the mblen function determines the number of bytes contained
14274     in the multibyte character pointed to by s. Except that the conversion state of the
14275     mbtowc function is not affected, it is equivalent to
14276
14277
14278
14279     294) If the locale employs special bytes to change the shift state, these bytes do not produce separate wide
14280          character codes, but are grouped with an adjacent multibyte character.
14281
14282 [page 355]
14283
14284            mbtowc((wchar_t *)0, (const char *)0, 0);
14285            mbtowc((wchar_t *)0, s, n);
14286 3   The implementation shall behave as if no library function calls the mblen function.
14287     Returns
14288 4   If s is a null pointer, the mblen function returns a nonzero or zero value, if multibyte
14289     character encodings, respectively, do or do not have state-dependent encodings. If s is
14290     not a null pointer, the mblen function either returns 0 (if s points to the null character),
14291     or returns the number of bytes that are contained in the multibyte character (if the next n
14292     or fewer bytes form a valid multibyte character), or returns -1 (if they do not form a valid
14293     multibyte character).
14294     Forward references: the mbtowc function (7.22.7.2).
14295     7.22.7.2 The mbtowc function
14296     Synopsis
14297 1          #include <stdlib.h>
14298            int mbtowc(wchar_t * restrict pwc,
14299                 const char * restrict s,
14300                 size_t n);
14301     Description
14302 2   If s is not a null pointer, the mbtowc function inspects at most n bytes beginning with
14303     the byte pointed to by s to determine the number of bytes needed to complete the next
14304     multibyte character (including any shift sequences). If the function determines that the
14305     next multibyte character is complete and valid, it determines the value of the
14306     corresponding wide character and then, if pwc is not a null pointer, stores that value in
14307     the object pointed to by pwc. If the corresponding wide character is the null wide
14308     character, the function is left in the initial conversion state.
14309 3   The implementation shall behave as if no library function calls the mbtowc function.
14310     Returns
14311 4   If s is a null pointer, the mbtowc function returns a nonzero or zero value, if multibyte
14312     character encodings, respectively, do or do not have state-dependent encodings. If s is
14313     not a null pointer, the mbtowc function either returns 0 (if s points to the null character),
14314     or returns the number of bytes that are contained in the converted multibyte character (if
14315     the next n or fewer bytes form a valid multibyte character), or returns -1 (if they do not
14316     form a valid multibyte character).
14317 5   In no case will the value returned be greater than n or the value of the MB_CUR_MAX
14318     macro.
14319
14320
14321 [page 356]
14322
14323     7.22.7.3 The wctomb function
14324     Synopsis
14325 1           #include <stdlib.h>
14326             int wctomb(char *s, wchar_t wc);
14327     Description
14328 2   The wctomb function determines the number of bytes needed to represent the multibyte
14329     character corresponding to the wide character given by wc (including any shift
14330     sequences), and stores the multibyte character representation in the array whose first
14331     element is pointed to by s (if s is not a null pointer). At most MB_CUR_MAX characters
14332     are stored. If wc is a null wide character, a null byte is stored, preceded by any shift
14333     sequence needed to restore the initial shift state, and the function is left in the initial
14334     conversion state.
14335 3   The implementation shall behave as if no library function calls the wctomb function.
14336     Returns
14337 4   If s is a null pointer, the wctomb function returns a nonzero or zero value, if multibyte
14338     character encodings, respectively, do or do not have state-dependent encodings. If s is
14339     not a null pointer, the wctomb function returns -1 if the value of wc does not correspond
14340     to a valid multibyte character, or returns the number of bytes that are contained in the
14341     multibyte character corresponding to the value of wc.
14342 5   In no case will the value returned be greater than the value of the MB_CUR_MAX macro.
14343     7.22.8 Multibyte/wide string conversion functions
14344 1   The behavior of the multibyte string functions is affected by the LC_CTYPE category of
14345     the current locale.
14346     7.22.8.1 The mbstowcs function
14347     Synopsis
14348 1           #include <stdlib.h>
14349             size_t mbstowcs(wchar_t * restrict pwcs,
14350                  const char * restrict s,
14351                  size_t n);
14352     Description
14353 2   The mbstowcs function converts a sequence of multibyte characters that begins in the
14354     initial shift state from the array pointed to by s into a sequence of corresponding wide
14355     characters and stores not more than n wide characters into the array pointed to by pwcs.
14356     No multibyte characters that follow a null character (which is converted into a null wide
14357     character) will be examined or converted. Each multibyte character is converted as if by
14358     a call to the mbtowc function, except that the conversion state of the mbtowc function is
14359 [page 357]
14360
14361     not affected.
14362 3   No more than n elements will be modified in the array pointed to by pwcs. If copying
14363     takes place between objects that overlap, the behavior is undefined.
14364     Returns
14365 4   If an invalid multibyte character is encountered, the mbstowcs function returns
14366     (size_t)(-1). Otherwise, the mbstowcs function returns the number of array
14367     elements modified, not including a terminating null wide character, if any.295)
14368     7.22.8.2 The wcstombs function
14369     Synopsis
14370 1            #include <stdlib.h>
14371              size_t wcstombs(char * restrict s,
14372                   const wchar_t * restrict pwcs,
14373                   size_t n);
14374     Description
14375 2   The wcstombs function converts a sequence of wide characters from the array pointed
14376     to by pwcs into a sequence of corresponding multibyte characters that begins in the
14377     initial shift state, and stores these multibyte characters into the array pointed to by s,
14378     stopping if a multibyte character would exceed the limit of n total bytes or if a null
14379     character is stored. Each wide character is converted as if by a call to the wctomb
14380     function, except that the conversion state of the wctomb function is not affected.
14381 3   No more than n bytes will be modified in the array pointed to by s. If copying takes place
14382     between objects that overlap, the behavior is undefined.
14383     Returns
14384 4   If a wide character is encountered that does not correspond to a valid multibyte character,
14385     the wcstombs function returns (size_t)(-1). Otherwise, the wcstombs function
14386     returns the number of bytes modified, not including a terminating null character, if
14387     any.295)
14388
14389
14390
14391
14392     295) The array will not be null-terminated if the value returned is n.
14393
14394 [page 358]
14395
14396     7.23 String handling <string.h>
14397     7.23.1 String function conventions
14398 1   The header <string.h> declares one type and several functions, and defines one
14399     macro useful for manipulating arrays of character type and other objects treated as arrays
14400     of character type.296) The type is size_t and the macro is NULL (both described in
14401     7.19). Various methods are used for determining the lengths of the arrays, but in all cases
14402     a char * or void * argument points to the initial (lowest addressed) character of the
14403     array. If an array is accessed beyond the end of an object, the behavior is undefined.
14404 2   Where an argument declared as size_t n specifies the length of the array for a
14405     function, n can have the value zero on a call to that function. Unless explicitly stated
14406     otherwise in the description of a particular function in this subclause, pointer arguments
14407     on such a call shall still have valid values, as described in 7.1.4. On such a call, a
14408     function that locates a character finds no occurrence, a function that compares two
14409     character sequences returns zero, and a function that copies characters copies zero
14410     characters.
14411 3   For all functions in this subclause, each character shall be interpreted as if it had the type
14412     unsigned char (and therefore every possible object representation is valid and has a
14413     different value).
14414     7.23.2 Copying functions
14415     7.23.2.1 The memcpy function
14416     Synopsis
14417 1            #include <string.h>
14418              void *memcpy(void * restrict s1,
14419                   const void * restrict s2,
14420                   size_t n);
14421     Description
14422 2   The memcpy function copies n characters from the object pointed to by s2 into the
14423     object pointed to by s1. If copying takes place between objects that overlap, the behavior
14424     is undefined.
14425     Returns
14426 3   The memcpy function returns the value of s1.
14427
14428
14429
14430
14431     296) See ''future library directions'' (7.30.11).
14432
14433 [page 359]
14434
14435     7.23.2.2 The memmove function
14436     Synopsis
14437 1          #include <string.h>
14438            void *memmove(void *s1, const void *s2, size_t n);
14439     Description
14440 2   The memmove function copies n characters from the object pointed to by s2 into the
14441     object pointed to by s1. Copying takes place as if the n characters from the object
14442     pointed to by s2 are first copied into a temporary array of n characters that does not
14443     overlap the objects pointed to by s1 and s2, and then the n characters from the
14444     temporary array are copied into the object pointed to by s1.
14445     Returns
14446 3   The memmove function returns the value of s1.
14447     7.23.2.3 The strcpy function
14448     Synopsis
14449 1          #include <string.h>
14450            char *strcpy(char * restrict s1,
14451                 const char * restrict s2);
14452     Description
14453 2   The strcpy function copies the string pointed to by s2 (including the terminating null
14454     character) into the array pointed to by s1. If copying takes place between objects that
14455     overlap, the behavior is undefined.
14456     Returns
14457 3   The strcpy function returns the value of s1.
14458     7.23.2.4 The strncpy function
14459     Synopsis
14460 1          #include <string.h>
14461            char *strncpy(char * restrict s1,
14462                 const char * restrict s2,
14463                 size_t n);
14464     Description
14465 2   The strncpy function copies not more than n characters (characters that follow a null
14466     character are not copied) from the array pointed to by s2 to the array pointed to by
14467
14468
14469
14470
14471 [page 360]
14472
14473     s1.297) If copying takes place between objects that overlap, the behavior is undefined.
14474 3   If the array pointed to by s2 is a string that is shorter than n characters, null characters
14475     are appended to the copy in the array pointed to by s1, until n characters in all have been
14476     written.
14477     Returns
14478 4   The strncpy function returns the value of s1.
14479     7.23.3 Concatenation functions
14480     7.23.3.1 The strcat function
14481     Synopsis
14482 1            #include <string.h>
14483              char *strcat(char * restrict s1,
14484                   const char * restrict s2);
14485     Description
14486 2   The strcat function appends a copy of the string pointed to by s2 (including the
14487     terminating null character) to the end of the string pointed to by s1. The initial character
14488     of s2 overwrites the null character at the end of s1. If copying takes place between
14489     objects that overlap, the behavior is undefined.
14490     Returns
14491 3   The strcat function returns the value of s1.
14492     7.23.3.2 The strncat function
14493     Synopsis
14494 1            #include <string.h>
14495              char *strncat(char * restrict s1,
14496                   const char * restrict s2,
14497                   size_t n);
14498     Description
14499 2   The strncat function appends not more than n characters (a null character and
14500     characters that follow it are not appended) from the array pointed to by s2 to the end of
14501     the string pointed to by s1. The initial character of s2 overwrites the null character at the
14502     end of s1. A terminating null character is always appended to the result.298) If copying
14503
14504     297) Thus, if there is no null character in the first n characters of the array pointed to by s2, the result will
14505          not be null-terminated.
14506     298) Thus, the maximum number of characters that can end up in the array pointed to by s1 is
14507          strlen(s1)+n+1.
14508
14509 [page 361]
14510
14511     takes place between objects that overlap, the behavior is undefined.
14512     Returns
14513 3   The strncat function returns the value of s1.
14514     Forward references: the strlen function (7.23.6.3).
14515     7.23.4 Comparison functions
14516 1   The sign of a nonzero value returned by the comparison functions memcmp, strcmp,
14517     and strncmp is determined by the sign of the difference between the values of the first
14518     pair of characters (both interpreted as unsigned char) that differ in the objects being
14519     compared.
14520     7.23.4.1 The memcmp function
14521     Synopsis
14522 1           #include <string.h>
14523             int memcmp(const void *s1, const void *s2, size_t n);
14524     Description
14525 2   The memcmp function compares the first n characters of the object pointed to by s1 to
14526     the first n characters of the object pointed to by s2.299)
14527     Returns
14528 3   The memcmp function returns an integer greater than, equal to, or less than zero,
14529     accordingly as the object pointed to by s1 is greater than, equal to, or less than the object
14530     pointed to by s2.
14531     7.23.4.2 The strcmp function
14532     Synopsis
14533 1           #include <string.h>
14534             int strcmp(const char *s1, const char *s2);
14535     Description
14536 2   The strcmp function compares the string pointed to by s1 to the string pointed to by
14537     s2.
14538     Returns
14539 3   The strcmp function returns an integer greater than, equal to, or less than zero,
14540     accordingly as the string pointed to by s1 is greater than, equal to, or less than the string
14541
14542     299) The contents of ''holes'' used as padding for purposes of alignment within structure objects are
14543          indeterminate. Strings shorter than their allocated space and unions may also cause problems in
14544          comparison.
14545
14546 [page 362]
14547
14548     pointed to by s2.
14549     7.23.4.3 The strcoll function
14550     Synopsis
14551 1           #include <string.h>
14552             int strcoll(const char *s1, const char *s2);
14553     Description
14554 2   The strcoll function compares the string pointed to by s1 to the string pointed to by
14555     s2, both interpreted as appropriate to the LC_COLLATE category of the current locale.
14556     Returns
14557 3   The strcoll function returns an integer greater than, equal to, or less than zero,
14558     accordingly as the string pointed to by s1 is greater than, equal to, or less than the string
14559     pointed to by s2 when both are interpreted as appropriate to the current locale.
14560     7.23.4.4 The strncmp function
14561     Synopsis
14562 1           #include <string.h>
14563             int strncmp(const char *s1, const char *s2, size_t n);
14564     Description
14565 2   The strncmp function compares not more than n characters (characters that follow a
14566     null character are not compared) from the array pointed to by s1 to the array pointed to
14567     by s2.
14568     Returns
14569 3   The strncmp function returns an integer greater than, equal to, or less than zero,
14570     accordingly as the possibly null-terminated array pointed to by s1 is greater than, equal
14571     to, or less than the possibly null-terminated array pointed to by s2.
14572     7.23.4.5 The strxfrm function
14573     Synopsis
14574 1           #include <string.h>
14575             size_t strxfrm(char * restrict s1,
14576                  const char * restrict s2,
14577                  size_t n);
14578     Description
14579 2   The strxfrm function transforms the string pointed to by s2 and places the resulting
14580     string into the array pointed to by s1. The transformation is such that if the strcmp
14581     function is applied to two transformed strings, it returns a value greater than, equal to, or
14582
14583 [page 363]
14584
14585     less than zero, corresponding to the result of the strcoll function applied to the same
14586     two original strings. No more than n characters are placed into the resulting array
14587     pointed to by s1, including the terminating null character. If n is zero, s1 is permitted to
14588     be a null pointer. If copying takes place between objects that overlap, the behavior is
14589     undefined.
14590     Returns
14591 3   The strxfrm function returns the length of the transformed string (not including the
14592     terminating null character). If the value returned is n or more, the contents of the array
14593     pointed to by s1 are indeterminate.
14594 4   EXAMPLE The value of the following expression is the size of the array needed to hold the
14595     transformation of the string pointed to by s.
14596            1 + strxfrm(NULL, s, 0)
14597
14598     7.23.5 Search functions
14599     7.23.5.1 The memchr function
14600     Synopsis
14601 1          #include <string.h>
14602            void *memchr(const void *s, int c, size_t n);
14603     Description
14604 2   The memchr function locates the first occurrence of c (converted to an unsigned
14605     char) in the initial n characters (each interpreted as unsigned char) of the object
14606     pointed to by s.
14607     Returns
14608 3   The memchr function returns a pointer to the located character, or a null pointer if the
14609     character does not occur in the object.
14610     7.23.5.2 The strchr function
14611     Synopsis
14612 1          #include <string.h>
14613            char *strchr(const char *s, int c);
14614     Description
14615 2   The strchr function locates the first occurrence of c (converted to a char) in the
14616     string pointed to by s. The terminating null character is considered to be part of the
14617     string.
14618     Returns
14619 3   The strchr function returns a pointer to the located character, or a null pointer if the
14620     character does not occur in the string.
14621 [page 364]
14622
14623     7.23.5.3 The strcspn function
14624     Synopsis
14625 1           #include <string.h>
14626             size_t strcspn(const char *s1, const char *s2);
14627     Description
14628 2   The strcspn function computes the length of the maximum initial segment of the string
14629     pointed to by s1 which consists entirely of characters not from the string pointed to by
14630     s2.
14631     Returns
14632 3   The strcspn function returns the length of the segment.
14633     7.23.5.4 The strpbrk function
14634     Synopsis
14635 1           #include <string.h>
14636             char *strpbrk(const char *s1, const char *s2);
14637     Description
14638 2   The strpbrk function locates the first occurrence in the string pointed to by s1 of any
14639     character from the string pointed to by s2.
14640     Returns
14641 3   The strpbrk function returns a pointer to the character, or a null pointer if no character
14642     from s2 occurs in s1.
14643     7.23.5.5 The strrchr function
14644     Synopsis
14645 1           #include <string.h>
14646             char *strrchr(const char *s, int c);
14647     Description
14648 2   The strrchr function locates the last occurrence of c (converted to a char) in the
14649     string pointed to by s. The terminating null character is considered to be part of the
14650     string.
14651     Returns
14652 3   The strrchr function returns a pointer to the character, or a null pointer if c does not
14653     occur in the string.
14654
14655
14656
14657
14658 [page 365]
14659
14660     7.23.5.6 The strspn function
14661     Synopsis
14662 1          #include <string.h>
14663            size_t strspn(const char *s1, const char *s2);
14664     Description
14665 2   The strspn function computes the length of the maximum initial segment of the string
14666     pointed to by s1 which consists entirely of characters from the string pointed to by s2.
14667     Returns
14668 3   The strspn function returns the length of the segment.
14669     7.23.5.7 The strstr function
14670     Synopsis
14671 1          #include <string.h>
14672            char *strstr(const char *s1, const char *s2);
14673     Description
14674 2   The strstr function locates the first occurrence in the string pointed to by s1 of the
14675     sequence of characters (excluding the terminating null character) in the string pointed to
14676     by s2.
14677     Returns
14678 3   The strstr function returns a pointer to the located string, or a null pointer if the string
14679     is not found. If s2 points to a string with zero length, the function returns s1.
14680     7.23.5.8 The strtok function
14681     Synopsis
14682 1          #include <string.h>
14683            char *strtok(char * restrict s1,
14684                 const char * restrict s2);
14685     Description
14686 2   A sequence of calls to the strtok function breaks the string pointed to by s1 into a
14687     sequence of tokens, each of which is delimited by a character from the string pointed to
14688     by s2. The first call in the sequence has a non-null first argument; subsequent calls in the
14689     sequence have a null first argument. The separator string pointed to by s2 may be
14690     different from call to call.
14691 3   The first call in the sequence searches the string pointed to by s1 for the first character
14692     that is not contained in the current separator string pointed to by s2. If no such character
14693     is found, then there are no tokens in the string pointed to by s1 and the strtok function
14694
14695 [page 366]
14696
14697     returns a null pointer. If such a character is found, it is the start of the first token.
14698 4   The strtok function then searches from there for a character that is contained in the
14699     current separator string. If no such character is found, the current token extends to the
14700     end of the string pointed to by s1, and subsequent searches for a token will return a null
14701     pointer. If such a character is found, it is overwritten by a null character, which
14702     terminates the current token. The strtok function saves a pointer to the following
14703     character, from which the next search for a token will start.
14704 5   Each subsequent call, with a null pointer as the value of the first argument, starts
14705     searching from the saved pointer and behaves as described above.
14706 6   The strtok function is not required to avoid data races. The implementation shall
14707     behave as if no library function calls the strtok function.
14708     Returns
14709 7   The strtok function returns a pointer to the first character of a token, or a null pointer
14710     if there is no token.
14711 8   EXAMPLE
14712             #include <string.h>
14713             static char str[] = "?a???b,,,#c";
14714             char *t;
14715             t   =   strtok(str, "?");       //   t   points to the token "a"
14716             t   =   strtok(NULL, ",");      //   t   points to the token "??b"
14717             t   =   strtok(NULL, "#,");     //   t   points to the token "c"
14718             t   =   strtok(NULL, "?");      //   t   is a null pointer
14719
14720     7.23.6 Miscellaneous functions
14721     7.23.6.1 The memset function
14722     Synopsis
14723 1           #include <string.h>
14724             void *memset(void *s, int c, size_t n);
14725     Description
14726 2   The memset function copies the value of c (converted to an unsigned char) into
14727     each of the first n characters of the object pointed to by s.
14728     Returns
14729 3   The memset function returns the value of s.
14730
14731
14732
14733
14734 [page 367]
14735
14736     7.23.6.2 The strerror function
14737     Synopsis
14738 1          #include <string.h>
14739            char *strerror(int errnum);
14740     Description
14741 2   The strerror function maps the number in errnum to a message string. Typically,
14742     the values for errnum come from errno, but strerror shall map any value of type
14743     int to a message.
14744 3   The strerror function is not required to avoid data races. The implementation shall
14745     behave as if no library function calls the strerror function.
14746     Returns
14747 4   The strerror function returns a pointer to the string, the contents of which are locale-
14748     specific. The array pointed to shall not be modified by the program, but may be
14749     overwritten by a subsequent call to the strerror function.
14750     7.23.6.3 The strlen function
14751     Synopsis
14752 1          #include <string.h>
14753            size_t strlen(const char *s);
14754     Description
14755 2   The strlen function computes the length of the string pointed to by s.
14756     Returns
14757 3   The strlen function returns the number of characters that precede the terminating null
14758     character.
14759
14760
14761
14762
14763 [page 368]
14764
14765     7.24 Type-generic math <tgmath.h>
14766 1   The header <tgmath.h> includes the headers <math.h> and <complex.h> and
14767     defines several type-generic macros.
14768 2   Of the <math.h> and <complex.h> functions without an f (float) or l (long
14769     double) suffix, several have one or more parameters whose corresponding real type is
14770     double. For each such function, except modf, there is a corresponding type-generic
14771     macro.300) The parameters whose corresponding real type is double in the function
14772     synopsis are generic parameters. Use of the macro invokes a function whose
14773     corresponding real type and type domain are determined by the arguments for the generic
14774     parameters.301)
14775 3   Use of the macro invokes a function whose generic parameters have the corresponding
14776     real type determined as follows:
14777     -- First, if any argument for generic parameters has type long double, the type
14778       determined is long double.
14779     -- Otherwise, if any argument for generic parameters has type double or is of integer
14780       type, the type determined is double.
14781     -- Otherwise, the type determined is float.
14782 4   For each unsuffixed function in <math.h> for which there is a function in
14783     <complex.h> with the same name except for a c prefix, the corresponding type-
14784     generic macro (for both functions) has the same name as the function in <math.h>. The
14785     corresponding type-generic macro for fabs and cabs is fabs.
14786
14787
14788
14789
14790     300) Like other function-like macros in Standard libraries, each type-generic macro can be suppressed to
14791          make available the corresponding ordinary function.
14792     301) If the type of the argument is not compatible with the type of the parameter for the selected function,
14793          the behavior is undefined.
14794
14795 [page 369]
14796
14797             <math.h>          <complex.h>              type-generic
14798              function            function                 macro
14799               acos               cacos                   acos
14800               asin               casin                   asin
14801               atan               catan                   atan
14802               acosh              cacosh                  acosh
14803               asinh              casinh                  asinh
14804               atanh              catanh                  atanh
14805               cos                ccos                    cos
14806               sin                csin                    sin
14807               tan                ctan                    tan
14808               cosh               ccosh                   cosh
14809               sinh               csinh                   sinh
14810               tanh               ctanh                   tanh
14811               exp                cexp                    exp
14812               log                clog                    log
14813               pow                cpow                    pow
14814               sqrt               csqrt                   sqrt
14815               fabs               cabs                    fabs
14816     If at least one argument for a generic parameter is complex, then use of the macro invokes
14817     a complex function; otherwise, use of the macro invokes a real function.
14818 5   For each unsuffixed function in <math.h> without a c-prefixed counterpart in
14819     <complex.h> (except modf), the corresponding type-generic macro has the same
14820     name as the function. These type-generic macros are:
14821           atan2                fma                  llround              remainder
14822           cbrt                 fmax                 log10                remquo
14823           ceil                 fmin                 log1p                rint
14824           copysign             fmod                 log2                 round
14825           erf                  frexp                logb                 scalbn
14826           erfc                 hypot                lrint                scalbln
14827           exp2                 ilogb                lround               tgamma
14828           expm1                ldexp                nearbyint            trunc
14829           fdim                 lgamma               nextafter
14830           floor                llrint               nexttoward
14831     If all arguments for generic parameters are real, then use of the macro invokes a real
14832     function; otherwise, use of the macro results in undefined behavior.
14833
14834
14835
14836
14837 [page 370]
14838
14839 6   For each unsuffixed function in <complex.h> that is not a c-prefixed counterpart to a
14840     function in <math.h>, the corresponding type-generic macro has the same name as the
14841     function. These type-generic macros are:
14842             carg                    conj                     creal
14843             cimag                   cproj
14844     Use of the macro with any real or complex argument invokes a complex function.
14845 7   EXAMPLE       With the declarations
14846             #include <tgmath.h>
14847             int n;
14848             float f;
14849             double d;
14850             long double ld;
14851             float complex fc;
14852             double complex dc;
14853             long double complex ldc;
14854     functions invoked by use of type-generic macros are shown in the following table:
14855                      macro use                                  invokes
14856                 exp(n)                              exp(n), the function
14857                 acosh(f)                            acoshf(f)
14858                 sin(d)                              sin(d), the function
14859                 atan(ld)                            atanl(ld)
14860                 log(fc)                             clogf(fc)
14861                 sqrt(dc)                            csqrt(dc)
14862                 pow(ldc, f)                         cpowl(ldc, f)
14863                 remainder(n, n)                     remainder(n, n), the function
14864                 nextafter(d, f)                     nextafter(d, f), the function
14865                 nexttoward(f, ld)                   nexttowardf(f, ld)
14866                 copysign(n, ld)                     copysignl(n, ld)
14867                 ceil(fc)                            undefined behavior
14868                 rint(dc)                            undefined behavior
14869                 fmax(ldc, ld)                       undefined behavior
14870                 carg(n)                             carg(n), the function
14871                 cproj(f)                            cprojf(f)
14872                 creal(d)                            creal(d), the function
14873                 cimag(ld)                           cimagl(ld)
14874                 fabs(fc)                            cabsf(fc)
14875                 carg(dc)                            carg(dc), the function
14876                 cproj(ldc)                          cprojl(ldc)
14877
14878
14879
14880
14881 [page 371]
14882
14883     7.25 Threads <threads.h>
14884     7.25.1 Introduction
14885 1   The header <threads.h> defines macros, and declares types, enumeration constants,
14886     and functions that support multiple threads of execution.
14887 2   Implementations that define the macro __STDC_NO_THREADS__ need not provide
14888     this header nor support any of its facilities.
14889 3   The macros are
14890            ONCE_FLAG_INIT
14891     which expands to a value that can be used to initialize an object of type once_flag;
14892     and
14893            TSS_DTOR_ITERATIONS
14894     which expands to an integer constant expression representing the maximum number of
14895     times that destructors will be called when a thread terminates.
14896 4   The types are
14897            cnd_t
14898     which is a complete object type that holds an identifier for a condition variable;
14899            thrd_t
14900     which is a complete object type that holds an identifier for a thread;
14901            tss_t
14902     which is a complete object type that holds an identifier for a thread-specific storage
14903     pointer;
14904            mtx_t
14905     which is a complete object type that holds an identifier for a mutex;
14906            tss_dtor_t
14907     which is the function pointer type void (*)(void*), used for a destructor for a
14908     thread-specific storage pointer;
14909            thrd_start_t
14910     which is the function pointer type int (*)(void*) that is passed to thrd_create
14911     to create a new thread;
14912            once_flag
14913     which is a complete object type that holds a flag for use by call_once; and
14914
14915
14916 [page 372]
14917
14918             xtime
14919     which is a structure type that holds a time specified in seconds and nanoseconds. The
14920     structure shall contain at least the following members, in any order.
14921             time_t sec;
14922             long nsec;
14923 5   The enumeration constants are
14924             mtx_plain
14925     which is passed to mtx_init to create a mutex object that supports neither timeout nor
14926     test and return;
14927             mtx_recursive
14928     which is passed to mtx_init to create a mutex object that supports recursive locking;
14929             mtx_timed
14930     which is passed to mtx_init to create a mutex object that supports timeout;
14931             mtx_try
14932     which is passed to mtx_init to create a mutex object that supports test and return;
14933             thrd_timeout
14934     which is returned by a timed wait function to indicate that the time specified in the call
14935     was reached without acquiring the requested resource;
14936             thrd_success
14937     which is returned by a function to indicate that the requested operation succeeded;
14938             thrd_busy
14939     which is returned by a function to indicate that the requested operation failed because a
14940     resource requested by a test and return function is already in use;
14941             thrd_error
14942     which is returned by a function to indicate that the requested operation failed; and
14943             thrd_nomem
14944     which is returned by a function to indicate that the requested operation failed because it
14945     was unable to allocate memory.
14946
14947
14948
14949
14950 [page 373]
14951
14952     7.25.2 Initialization functions
14953     7.25.2.1 The call_once function
14954     Synopsis
14955 1          #include <threads.h>
14956            void call_once(once_flag *flag, void (*func)(void));
14957     Description
14958 2   The call_once function uses the once_flag pointed to by flag to ensure that
14959     func is called exactly once, the first time the call_once function is called with that
14960     value of flag. Completion of an effective call to the call_once function synchronizes
14961     with all subsequent calls to the call_once function with the same value of flag.
14962     Returns
14963 3   The call_once function returns no value.
14964     7.25.3 Condition variable functions
14965     7.25.3.1 The cnd_broadcast function
14966     Synopsis
14967 1          #include <threads.h>
14968            int cnd_broadcast(cnd_t *cond);
14969     Description
14970 2   The cnd_broadcast function unblocks all of the threads that are blocked on the
14971     condition variable pointed to by cond at the time of the call. If no threads are blocked
14972     on the condition variable pointed to by cond at the time of the call, the function does
14973     nothing.
14974     Returns
14975 3   The cnd_broadcast function returns thrd_success on success, or thrd_error
14976     if the request could not be honored.
14977     7.25.3.2 The cnd_destroy function
14978     Synopsis
14979 1          #include <threads.h>
14980            void cnd_destroy(cnd_t *cond);
14981     Description
14982 2   The cnd_destroy function releases all resources used by the condition variable
14983     pointed to by cond. The cnd_destroy function requires that no threads be blocked
14984     waiting for the condition variable pointed to by cond.
14985
14986 [page 374]
14987
14988     Returns
14989 3   The cnd_destroy function returns no value.
14990     7.25.3.3 The cnd_init function
14991     Synopsis
14992 1           #include <threads.h>
14993             int cnd_init(cnd_t *cond);
14994     Description
14995 2   The cnd_init function creates a condition variable. If it succeeds it sets the variable
14996     pointed to by cond to a value that uniquely identifies the newly created condition
14997     variable. A thread that calls cnd_wait on a newly created condition variable will
14998     block.
14999     Returns
15000 3   The cnd_init function returns thrd_success on success, or thrd_nomem if no
15001     memory could be allocated for the newly created condition, or thrd_error if the
15002     request could not be honored.
15003     7.25.3.4 The cnd_signal function
15004     Synopsis
15005 1           #include <threads.h>
15006             int cnd_signal(cnd_t *cond);
15007     Description
15008 2   The cnd_signal function unblocks one of the threads that are blocked on the
15009     condition variable pointed to by cond at the time of the call. If no threads are blocked
15010     on the condition variable at the time of the call, the function does nothing and return
15011     success.
15012     Returns
15013 3   The cnd_signal function returns thrd_success on success or thrd_error if
15014     the request could not be honored.
15015     7.25.3.5 The cnd_timedwait function
15016     Synopsis
15017 1           #include <threads.h>
15018             int cnd_timedwait(cnd_t *cond, mtx_t *mtx,
15019                  const xtime *xt);
15020
15021
15022
15023
15024 [page 375]
15025
15026     Description
15027 2   The cnd_timedwait function atomically unlocks the mutex pointed to by mtx and
15028     endeavors to block until the condition variable pointed to by cond is signaled by a call to
15029     cnd_signal or to cnd_broadcast, or until after the time specified by the xtime
15030     object pointed to by xt. When the calling thread becomes unblocked it locks the variable
15031     pointed to by mtx before it returns. The cnd_timedwait function requires that the
15032     mutex pointed to by mtx be locked by the calling thread.
15033     Returns
15034 3   The cnd_timedwait function returns thrd_success upon success, or
15035     thrd_timeout if the time specified in the call was reached without acquiring the
15036     requested resource, or thrd_error if the request could not be honored.
15037     7.25.3.6 The cnd_wait function
15038     Synopsis
15039 1          #include <threads.h>
15040            int cnd_wait(cnd_t *cond, mtx_t *mtx);
15041     Description
15042 2   The cnd_wait function atomically unlocks the mutex pointed to by mtx and endeavors
15043     to block until the condition variable pointed to by cond is signaled by a call to
15044     cnd_signal or to cnd_broadcast. When the calling thread becomes unblocked it
15045     locks the mutex pointed to by mtx before it returns. If the mutex pointed to by mtx is
15046     not locked by the calling thread, the cnd_wait function will act as if the abort
15047     function is called.
15048     Returns
15049 3   The cnd_wait function returns thrd_success on success or thrd_error if the
15050     request could not be honored.
15051     7.25.4 Mutex functions
15052     7.25.4.1 The mtx_destroy function
15053     Synopsis
15054 1          #include <threads.h>
15055            void mtx_destroy(mtx_t *mtx);
15056     Description
15057 2   The mtx_destroy function releases any resources used by the mutex pointed to by
15058     mtx. No threads can be blocked waiting for the mutex pointed to by mtx.
15059
15060
15061
15062 [page 376]
15063
15064     Returns
15065 3   The mtx_destroy function returns no value.
15066     7.25.4.2 The mtx_init function
15067     Synopsis
15068 1           #include <threads.h>
15069             int mtx_init(mtx_t *mtx, int type);
15070     Description
15071 2   The mtx_init function creates a mutex object with properties indicated by type,
15072     which must have one of the six values:
15073     mtx_plain for a simple non-recursive mutex,
15074     mtx_timed for a non-recursive mutex that supports timeout,
15075     mtx_try      for a non-recursive mutex that supports test and return,
15076     mtx_plain | mtx_recursive for a simple recursive mutex,
15077     mtx_timed | mtx_recursive for a recursive mutex that supports timeout, or
15078     mtx_try | mtx_recursive for a recursive mutex that supports test and return.
15079 3   If the mtx_init function succeeds, it sets the mutex pointed to by mtx to a value that
15080     uniquely identifies the newly created mutex.
15081     Returns
15082 4   The mtx_init function returns thrd_success on success, or thrd_error if the
15083     request could not be honored.
15084     7.25.4.3 The mtx_lock function
15085     Synopsis
15086 1           #include <threads.h>
15087             int mtx_lock(mtx_t *mtx);
15088     Description
15089 2   The mtx_lock function blocks until it locks the mutex pointed to by mtx. If the mutex
15090     is non-recursive, it shall not be locked by the calling thread. Prior calls to mtx_unlock
15091     on the same mutex shall synchronize with this operation.
15092     Returns
15093 3   The mtx_lock function returns thrd_success on success, or thrd_busy if the
15094     resource requested is already in use, or thrd_error if the request could not be
15095     honored.
15096
15097
15098
15099
15100 [page 377]
15101
15102     7.25.4.4 The mtx_timedlock function
15103     Synopsis
15104 1          #include <threads.h>
15105            int mtx_timedlock(mtx_t *mtx, const xtime *xt);
15106     Description
15107 2   The mtx_timedlock function endeavors to block until it locks the mutex pointed to by
15108     mtx or until the time specified by the xtime object xt has passed. The specified mutex
15109     shall support timeout. Prior calls to mtx_unlock on the same mutex shall synchronize
15110     with this operation.                                                                 *
15111     Returns
15112 3   The mtx_timedlock function returns thrd_success on success, or thrd_busy
15113     if the resource requested is already in use, or thrd_timeout if the time specified was
15114     reached without acquiring the requested resource, or thrd_error if the request could
15115     not be honored.
15116     7.25.4.5 The mtx_trylock function
15117     Synopsis
15118 1          #include <threads.h>
15119            int mtx_trylock(mtx_t *mtx);
15120     Description
15121 2   The mtx_trylock function endeavors to lock the mutex pointed to by mtx. The
15122     specified mutex shall support either test and return or timeout. If the mutex is already
15123     locked, the function returns without blocking. Prior calls to mtx_unlock on the same
15124     mutex shall synchronize with this operation.                                            *
15125     Returns
15126 3   The mtx_trylock function returns thrd_success on success, or thrd_busy if
15127     the resource requested is already in use, or thrd_error if the request could not be
15128     honored.
15129     7.25.4.6 The mtx_unlock function
15130     Synopsis
15131 1          #include <threads.h>
15132            int mtx_unlock(mtx_t *mtx);
15133     Description
15134 2   The mtx_unlock function unlocks the mutex pointed to by mtx. The mutex pointed to
15135     by mtx shall be locked by the calling thread.
15136
15137 [page 378]
15138
15139     Returns
15140 3   The mtx_unlock function returns thrd_success on success or thrd_error if
15141     the request could not be honored.
15142     7.25.5 Thread functions
15143     7.25.5.1 The thrd_create function
15144     Synopsis
15145 1           #include <threads.h>
15146             int thrd_create(thrd_t *thr, thrd_start_t func,
15147                  void *arg);
15148     Description
15149 2   The thrd_create function creates a new thread executing func(arg). If the
15150     thrd_create function succeeds, it sets the thread thr to a value that uniquely
15151     identifies the newly created thread.
15152     Returns
15153 3   The thrd_create function returns thrd_success on success, or thrd_nomem if
15154     no memory could be allocated for the thread requested, or thrd_error if the request
15155     could not be honored.
15156     7.25.5.2 The thrd_current function
15157     Synopsis
15158 1           #include <threads.h>
15159             thrd_t thrd_current(void);
15160     Description
15161 2   The thrd_current function identifies the thread that called it.
15162     Returns
15163 3   The thrd_current function returns a value that uniquely identifies the thread that
15164     called it.
15165     7.25.5.3 The thrd_detach function
15166     Synopsis
15167 1           #include <threads.h>
15168             int thrd_detach(thrd_t thr);
15169     Description
15170 2   The thrd_detach function tells the operating system to dispose of any resources
15171     allocated to the thread identified by thr when that thread terminates. The value of the
15172
15173 [page 379]
15174
15175     thread identified by thr value shall not have been set by a call to thrd_join or
15176     thrd_detach.
15177     Returns
15178 3   The thrd_detach function returns thrd_success on success or thrd_error if
15179     the request could not be honored.
15180     7.25.5.4 The thrd_equal function
15181     Synopsis
15182 1          #include <threads.h>
15183            int thrd_equal(thrd_t thr0, thrd_t thr1);
15184     Description
15185 2   The thrd_equal function will determine whether the thread identified by thr0 refers
15186     to the thread identified by thr1.
15187     Returns
15188 3   The thrd_equal function returns zero if the thread thr0 and the thread thr1 refer to
15189     different threads. Otherwise the thrd_equal function returns a nonzero value.
15190     7.25.5.5 The thrd_exit function
15191     Synopsis
15192 1          #include <threads.h>
15193            void thrd_exit(int res);
15194     Description
15195 2   The thrd_exit function terminates execution of the calling thread and sets its result
15196     code to res.
15197     Returns
15198 3   The thrd_exit function returns no value.
15199     7.25.5.6 The thrd_join function
15200     Synopsis
15201 1          #include <threads.h>
15202            int thrd_join(thrd_t thr, int *res);
15203     Description
15204 2   The thrd_join function blocks until the thread identified by thr has terminated. If
15205     the parameter res is not a null pointer, it stores the thread's result code in the integer
15206     pointed to by res. The value of the thread identified by thr shall not have been set by a
15207     call to thrd_join or thrd_detach.
15208
15209 [page 380]
15210
15211     Returns
15212 3   The thrd_join function returns thrd_success on success or thrd_error if the
15213     request could not be honored.
15214     7.25.5.7 The thrd_sleep function
15215     Synopsis
15216 1           #include <threads.h>
15217             void thrd_sleep(const xtime *xt);
15218     Description
15219 2   The thrd_sleep function suspends execution of the calling thread until after the time
15220     specified by the xtime object pointed to by xt.
15221     Returns
15222 3   The thrd_sleep function returns no value.
15223     7.25.5.8 The thrd_yield function
15224     Synopsis
15225 1           #include <threads.h>
15226             void thrd_yield(void);
15227     Description
15228 2   The thrd_yield function endeavors to permit other threads to run, even if the current
15229     thread would ordinarily continue to run.
15230     Returns
15231 3   The thrd_yield function returns no value.
15232     7.25.6 Thread-specific storage functions
15233     7.25.6.1 The tss_create function
15234     Synopsis
15235 1           #include <threads.h>
15236             int tss_create(tss_t *key, tss_dtor_t dtor);
15237     Description
15238 2   The tss_create function creates a thread-specific storage pointer with destructor
15239     dtor, which may be null.
15240     Returns
15241 3   If the tss_create function is successful, it sets the thread-specific storage pointed to
15242     by key to a value that uniquely identifies the newly created pointer and returns
15243     thrd_success; otherwise, thrd_error is returned and the thread-specific storage
15244 [page 381]
15245
15246     pointed to by key is set to an undefined value.
15247     7.25.6.2 The tss_delete function
15248     Synopsis
15249 1          #include <threads.h>
15250            void tss_delete(tss_t key);
15251     Description
15252 2   The tss_delete function releases any resources used by the thread-specific storage
15253     identified by key.
15254     Returns
15255 3   The tss_delete function returns no value.
15256     7.25.6.3 The tss_get function
15257     Synopsis
15258 1          #include <threads.h>
15259            void *tss_get(tss_t key);
15260     Description
15261 2   The tss_get function returns the value for the current thread held in the thread-specific
15262     storage identified by key.
15263     Returns
15264 3   The tss_get function returns the value for the current thread if successful, or zero if
15265     unsuccessful.
15266     7.25.6.4 The tss_set function
15267     Synopsis
15268 1          #include <threads.h>
15269            int tss_set(tss_t key, void *val);
15270     Description
15271 2   The tss_set function sets the value for the current thread held in the thread-specific
15272     storage identified by key to val.
15273     Returns
15274 3   The tss_set function returns thrd_success on success or thrd_error if the
15275     request could not be honored.
15276
15277
15278
15279
15280 [page 382]
15281
15282     7.25.7 Time functions
15283     7.25.7.1 The xtime_get function
15284     Synopsis
15285 1           #include <threads.h>
15286             int xtime_get(xtime *xt, int base);
15287     Description
15288 2   The xtime_get function sets the xtime object pointed to by xt to hold the current
15289     time based on the time base base.
15290     Returns
15291 3   If the xtime_get function is successful it returns the nonzero value base, which must
15292     be TIME_UTC; otherwise, it returns zero.302)
15293
15294
15295
15296
15297     302) Although an xtime object describes times with nanosecond resolution, the actual resolution in an
15298          xtime object is system dependent.
15299
15300 [page 383]
15301
15302     7.26 Date and time <time.h>
15303     7.26.1 Components of time
15304 1   The header <time.h> defines two macros, and declares several types and functions for
15305     manipulating time. Many functions deal with a calendar time that represents the current
15306     date (according to the Gregorian calendar) and time. Some functions deal with local
15307     time, which is the calendar time expressed for some specific time zone, and with Daylight
15308     Saving Time, which is a temporary change in the algorithm for determining local time.
15309     The local time zone and Daylight Saving Time are implementation-defined.
15310 2   The macros defined are NULL (described in 7.19); and
15311             CLOCKS_PER_SEC
15312     which expands to an expression with type clock_t (described below) that is the
15313     number per second of the value returned by the clock function.
15314 3   The types declared are size_t (described in 7.19);
15315             clock_t
15316     and
15317             time_t
15318     which are arithmetic types capable of representing times; and
15319             struct tm
15320     which holds the components of a calendar time, called the broken-down time.
15321 4   The range and precision of times representable in clock_t and time_t are
15322     implementation-defined. The tm structure shall contain at least the following members,
15323     in any order. The semantics of the members and their normal ranges are expressed in the
15324     comments.303)
15325             int    tm_sec;           //   seconds after the minute -- [0, 60]
15326             int    tm_min;           //   minutes after the hour -- [0, 59]
15327             int    tm_hour;          //   hours since midnight -- [0, 23]
15328             int    tm_mday;          //   day of the month -- [1, 31]
15329             int    tm_mon;           //   months since January -- [0, 11]
15330             int    tm_year;          //   years since 1900
15331             int    tm_wday;          //   days since Sunday -- [0, 6]
15332             int    tm_yday;          //   days since January 1 -- [0, 365]
15333             int    tm_isdst;         //   Daylight Saving Time flag
15334
15335
15336
15337     303) The range [0, 60] for tm_sec allows for a positive leap second.
15338
15339 [page 384]
15340
15341     The value of tm_isdst is positive if Daylight Saving Time is in effect, zero if Daylight
15342     Saving Time is not in effect, and negative if the information is not available.
15343     7.26.2 Time manipulation functions
15344     7.26.2.1 The clock function
15345     Synopsis
15346 1           #include <time.h>
15347             clock_t clock(void);
15348     Description
15349 2   The clock function determines the processor time used.
15350     Returns
15351 3   The clock function returns the implementation's best approximation to the processor
15352     time used by the program since the beginning of an implementation-defined era related
15353     only to the program invocation. To determine the time in seconds, the value returned by
15354     the clock function should be divided by the value of the macro CLOCKS_PER_SEC. If
15355     the processor time used is not available or its value cannot be represented, the function
15356     returns the value (clock_t)(-1).304)
15357     7.26.2.2 The difftime function
15358     Synopsis
15359 1           #include <time.h>
15360             double difftime(time_t time1, time_t time0);
15361     Description
15362 2   The difftime function computes the difference between two calendar times: time1 -
15363     time0.
15364     Returns
15365 3   The difftime function returns the difference expressed in seconds as a double.
15366
15367
15368
15369
15370     304) In order to measure the time spent in a program, the clock function should be called at the start of
15371          the program and its return value subtracted from the value returned by subsequent calls.
15372
15373 [page 385]
15374
15375     7.26.2.3 The mktime function
15376     Synopsis
15377 1           #include <time.h>
15378             time_t mktime(struct tm *timeptr);
15379     Description
15380 2   The mktime function converts the broken-down time, expressed as local time, in the
15381     structure pointed to by timeptr into a calendar time value with the same encoding as
15382     that of the values returned by the time function. The original values of the tm_wday
15383     and tm_yday components of the structure are ignored, and the original values of the
15384     other components are not restricted to the ranges indicated above.305) On successful
15385     completion, the values of the tm_wday and tm_yday components of the structure are
15386     set appropriately, and the other components are set to represent the specified calendar
15387     time, but with their values forced to the ranges indicated above; the final value of
15388     tm_mday is not set until tm_mon and tm_year are determined.
15389     Returns
15390 3   The mktime function returns the specified calendar time encoded as a value of type
15391     time_t. If the calendar time cannot be represented, the function returns the value
15392     (time_t)(-1).
15393 4   EXAMPLE       What day of the week is July 4, 2001?
15394             #include <stdio.h>
15395             #include <time.h>
15396             static const char *const wday[] = {
15397                     "Sunday", "Monday", "Tuesday", "Wednesday",
15398                     "Thursday", "Friday", "Saturday", "-unknown-"
15399             };
15400             struct tm time_str;
15401             /* ... */
15402
15403
15404
15405
15406     305) Thus, a positive or zero value for tm_isdst causes the mktime function to presume initially that
15407          Daylight Saving Time, respectively, is or is not in effect for the specified time. A negative value
15408          causes it to attempt to determine whether Daylight Saving Time is in effect for the specified time.
15409
15410 [page 386]
15411
15412             time_str.tm_year   = 2001 - 1900;
15413             time_str.tm_mon    = 7 - 1;
15414             time_str.tm_mday   = 4;
15415             time_str.tm_hour   = 0;
15416             time_str.tm_min    = 0;
15417             time_str.tm_sec    = 1;
15418             time_str.tm_isdst = -1;
15419             if (mktime(&time_str) == (time_t)(-1))
15420                   time_str.tm_wday = 7;
15421             printf("%s\n", wday[time_str.tm_wday]);
15422
15423     7.26.2.4 The time function
15424     Synopsis
15425 1           #include <time.h>
15426             time_t time(time_t *timer);
15427     Description
15428 2   The time function determines the current calendar time. The encoding of the value is
15429     unspecified.
15430     Returns
15431 3   The time function returns the implementation's best approximation to the current
15432     calendar time. The value (time_t)(-1) is returned if the calendar time is not
15433     available. If timer is not a null pointer, the return value is also assigned to the object it
15434     points to.
15435     7.26.3 Time conversion functions
15436 1   Except for the strftime function, these functions each return a pointer to one of two
15437     types of static objects: a broken-down time structure or an array of char. Execution of
15438     any of the functions that return a pointer to one of these object types may overwrite the
15439     information in any object of the same type pointed to by the value returned from any
15440     previous call to any of them and the functions are not required to avoid data races. The
15441     implementation shall behave as if no other library functions call these functions.
15442     7.26.3.1 The asctime function
15443     Synopsis
15444 1           #include <time.h>
15445             char *asctime(const struct tm *timeptr);
15446     Description
15447 2   The asctime function converts the broken-down time in the structure pointed to by
15448     timeptr into a string in the form
15449             Sun Sep 16 01:03:52 1973\n\0
15450
15451 [page 387]
15452
15453     using the equivalent of the following algorithm.
15454     char *asctime(const struct tm *timeptr)
15455     {
15456          static const char wday_name[7][3] = {
15457               "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
15458          };
15459          static const char mon_name[12][3] = {
15460               "Jan", "Feb", "Mar", "Apr", "May", "Jun",
15461               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
15462          };
15463          static char result[26];
15464             sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
15465                  wday_name[timeptr->tm_wday],
15466                  mon_name[timeptr->tm_mon],
15467                  timeptr->tm_mday, timeptr->tm_hour,
15468                  timeptr->tm_min, timeptr->tm_sec,
15469                  1900 + timeptr->tm_year);
15470             return result;
15471     }
15472 3   If any of the fields of the broken-down time contain values that are outside their normal
15473     ranges,306) the behavior of the asctime function is undefined. Likewise, if the
15474     calculated year exceeds four digits or is less than the year 1000, the behavior is
15475     undefined.
15476     Returns
15477 4   The asctime function returns a pointer to the string.
15478     7.26.3.2 The ctime function
15479     Synopsis
15480 1           #include <time.h>
15481             char *ctime(const time_t *timer);
15482     Description
15483 2   The ctime function converts the calendar time pointed to by timer to local time in the
15484     form of a string. It is equivalent to
15485             asctime(localtime(timer))
15486
15487
15488
15489     306) See 7.26.1.
15490
15491 [page 388]
15492
15493     Returns
15494 3   The ctime function returns the pointer returned by the asctime function with that
15495     broken-down time as argument.
15496     Forward references: the localtime function (7.26.3.4).
15497     7.26.3.3 The gmtime function
15498     Synopsis
15499 1           #include <time.h>
15500             struct tm *gmtime(const time_t *timer);
15501     Description
15502 2   The gmtime function converts the calendar time pointed to by timer into a broken-
15503     down time, expressed as UTC.
15504     Returns
15505 3   The gmtime function returns a pointer to the broken-down time, or a null pointer if the
15506     specified time cannot be converted to UTC.
15507     7.26.3.4 The localtime function
15508     Synopsis
15509 1           #include <time.h>
15510             struct tm *localtime(const time_t *timer);
15511     Description
15512 2   The localtime function converts the calendar time pointed to by timer into a
15513     broken-down time, expressed as local time.
15514     Returns
15515 3   The localtime function returns a pointer to the broken-down time, or a null pointer if
15516     the specified time cannot be converted to local time.
15517     7.26.3.5 The strftime function
15518     Synopsis
15519 1           #include <time.h>
15520             size_t strftime(char * restrict s,
15521                  size_t maxsize,
15522                  const char * restrict format,
15523                  const struct tm * restrict timeptr);
15524
15525
15526
15527
15528 [page 389]
15529
15530     Description
15531 2   The strftime function places characters into the array pointed to by s as controlled by
15532     the string pointed to by format. The format shall be a multibyte character sequence,
15533     beginning and ending in its initial shift state. The format string consists of zero or
15534     more conversion specifiers and ordinary multibyte characters. A conversion specifier
15535     consists of a % character, possibly followed by an E or O modifier character (described
15536     below), followed by a character that determines the behavior of the conversion specifier.
15537     All ordinary multibyte characters (including the terminating null character) are copied
15538     unchanged into the array. If copying takes place between objects that overlap, the
15539     behavior is undefined. No more than maxsize characters are placed into the array.
15540 3   Each conversion specifier is replaced by appropriate characters as described in the
15541     following list. The appropriate characters are determined using the LC_TIME category
15542     of the current locale and by the values of zero or more members of the broken-down time
15543     structure pointed to by timeptr, as specified in brackets in the description. If any of
15544     the specified values is outside the normal range, the characters stored are unspecified.
15545     %a    is replaced by the locale's abbreviated weekday name. [tm_wday]
15546     %A    is replaced by the locale's full weekday name. [tm_wday]
15547     %b    is replaced by the locale's abbreviated month name. [tm_mon]
15548     %B    is replaced by the locale's full month name. [tm_mon]
15549     %c    is replaced by the locale's appropriate date and time representation. [all specified
15550           in 7.26.1]
15551     %C    is replaced by the year divided by 100 and truncated to an integer, as a decimal
15552           number (00-99). [tm_year]
15553     %d    is replaced by the day of the month as a decimal number (01-31). [tm_mday]
15554     %D    is equivalent to ''%m/%d/%y''. [tm_mon, tm_mday, tm_year]
15555     %e    is replaced by the day of the month as a decimal number (1-31); a single digit is
15556           preceded by a space. [tm_mday]
15557     %F    is equivalent to ''%Y-%m-%d'' (the ISO 8601 date format). [tm_year, tm_mon,
15558           tm_mday]
15559     %g    is replaced by the last 2 digits of the week-based year (see below) as a decimal
15560           number (00-99). [tm_year, tm_wday, tm_yday]
15561     %G    is replaced by the week-based year (see below) as a decimal number (e.g., 1997).
15562           [tm_year, tm_wday, tm_yday]
15563     %h    is equivalent to ''%b''. [tm_mon]
15564     %H    is replaced by the hour (24-hour clock) as a decimal number (00-23). [tm_hour]
15565     %I    is replaced by the hour (12-hour clock) as a decimal number (01-12). [tm_hour]
15566     %j    is replaced by the day of the year as a decimal number (001-366). [tm_yday]
15567     %m    is replaced by the month as a decimal number (01-12). [tm_mon]
15568     %M    is replaced by the minute as a decimal number (00-59). [tm_min]
15569     %n    is replaced by a new-line character.
15570
15571 [page 390]
15572
15573     %p   is replaced by the locale's equivalent of the AM/PM designations associated with a
15574          12-hour clock. [tm_hour]
15575     %r   is replaced by the locale's 12-hour clock time. [tm_hour, tm_min, tm_sec]
15576     %R   is equivalent to ''%H:%M''. [tm_hour, tm_min]
15577     %S   is replaced by the second as a decimal number (00-60). [tm_sec]
15578     %t   is replaced by a horizontal-tab character.
15579     %T   is equivalent to ''%H:%M:%S'' (the ISO 8601 time format). [tm_hour, tm_min,
15580          tm_sec]
15581     %u   is replaced by the ISO 8601 weekday as a decimal number (1-7), where Monday
15582          is 1. [tm_wday]
15583     %U   is replaced by the week number of the year (the first Sunday as the first day of week
15584          1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
15585     %V   is replaced by the ISO 8601 week number (see below) as a decimal number
15586          (01-53). [tm_year, tm_wday, tm_yday]
15587     %w   is replaced by the weekday as a decimal number (0-6), where Sunday is 0.
15588          [tm_wday]
15589     %W   is replaced by the week number of the year (the first Monday as the first day of
15590          week 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
15591     %x   is replaced by the locale's appropriate date representation. [all specified in 7.26.1]
15592     %X   is replaced by the locale's appropriate time representation. [all specified in 7.26.1]
15593     %y   is replaced by the last 2 digits of the year as a decimal number (00-99).
15594          [tm_year]
15595     %Y   is replaced by the year as a decimal number (e.g., 1997). [tm_year]
15596     %z   is replaced by the offset from UTC in the ISO 8601 format ''-0430'' (meaning 4
15597          hours 30 minutes behind UTC, west of Greenwich), or by no characters if no time
15598          zone is determinable. [tm_isdst]
15599     %Z   is replaced by the locale's time zone name or abbreviation, or by no characters if no
15600          time zone is determinable. [tm_isdst]
15601     %%   is replaced by %.
15602 4   Some conversion specifiers can be modified by the inclusion of an E or O modifier
15603     character to indicate an alternative format or specification. If the alternative format or
15604     specification does not exist for the current locale, the modifier is ignored.
15605     %Ec is replaced by the locale's alternative date and time representation.
15606     %EC is replaced by the name of the base year (period) in the locale's alternative
15607         representation.
15608     %Ex is replaced by the locale's alternative date representation.
15609     %EX is replaced by the locale's alternative time representation.
15610     %Ey is replaced by the offset from %EC (year only) in the locale's alternative
15611         representation.
15612     %EY is replaced by the locale's full alternative year representation.
15613
15614 [page 391]
15615
15616     %Od is replaced by the day of the month, using the locale's alternative numeric symbols
15617         (filled as needed with leading zeros, or with leading spaces if there is no alternative
15618         symbol for zero).
15619     %Oe is replaced by the day of the month, using the locale's alternative numeric symbols
15620         (filled as needed with leading spaces).
15621     %OH is replaced by the hour (24-hour clock), using the locale's alternative numeric
15622         symbols.
15623     %OI is replaced by the hour (12-hour clock), using the locale's alternative numeric
15624         symbols.
15625     %Om is replaced by the month, using the locale's alternative numeric symbols.
15626     %OM is replaced by the minutes, using the locale's alternative numeric symbols.
15627     %OS is replaced by the seconds, using the locale's alternative numeric symbols.
15628     %Ou is replaced by the ISO 8601 weekday as a number in the locale's alternative
15629         representation, where Monday is 1.
15630     %OU is replaced by the week number, using the locale's alternative numeric symbols.
15631     %OV is replaced by the ISO 8601 week number, using the locale's alternative numeric
15632         symbols.
15633     %Ow is replaced by the weekday as a number, using the locale's alternative numeric
15634         symbols.
15635     %OW is replaced by the week number of the year, using the locale's alternative numeric
15636         symbols.
15637     %Oy is replaced by the last 2 digits of the year, using the locale's alternative numeric
15638         symbols.
15639 5   %g, %G, and %V give values according to the ISO 8601 week-based year. In this system,
15640     weeks begin on a Monday and week 1 of the year is the week that includes January 4th,
15641     which is also the week that includes the first Thursday of the year, and is also the first
15642     week that contains at least four days in the year. If the first Monday of January is the
15643     2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year; thus,
15644     for Saturday 2nd January 1999, %G is replaced by 1998 and %V is replaced by 53. If
15645     December 29th, 30th, or 31st is a Monday, it and any following days are part of week 1 of
15646     the following year. Thus, for Tuesday 30th December 1997, %G is replaced by 1998 and
15647     %V is replaced by 01.
15648 6   If a conversion specifier is not one of the above, the behavior is undefined.
15649 7   In the "C" locale, the E and O modifiers are ignored and the replacement strings for the
15650     following specifiers are:
15651     %a    the first three characters of %A.
15652     %A    one of ''Sunday'', ''Monday'', ... , ''Saturday''.
15653     %b    the first three characters of %B.
15654     %B    one of ''January'', ''February'', ... , ''December''.
15655     %c    equivalent to ''%a %b %e %T %Y''.
15656 [page 392]
15657
15658     %p    one of ''AM'' or ''PM''.
15659     %r    equivalent to ''%I:%M:%S %p''.
15660     %x    equivalent to ''%m/%d/%y''.
15661     %X    equivalent to %T.
15662     %Z    implementation-defined.
15663     Returns
15664 8   If the total number of resulting characters including the terminating null character is not
15665     more than maxsize, the strftime function returns the number of characters placed
15666     into the array pointed to by s not including the terminating null character. Otherwise,
15667     zero is returned and the contents of the array are indeterminate.
15668
15669
15670
15671
15672 [page 393]
15673
15674     7.27 Unicode utilities <uchar.h>
15675 1   The header <uchar.h> declares types and functions for manipulating Unicode
15676     characters.
15677 2   The types declared are mbstate_t (described in 7.29.1) and size_t (described in
15678     7.19);
15679            char16_t
15680     which is an unsigned integer type used for 16-bit characters and is the same type as
15681     uint_least16_t (described in 7.20.1.2); and
15682            char32_t
15683     which is an unsigned integer type used for 32-bit characters and is the same type as
15684     uint_least32_t (also described in 7.20.1.2).
15685     7.27.1 Restartable multibyte/wide character conversion functions
15686 1   These functions have a parameter, ps, of type pointer to mbstate_t that points to an
15687     object that can completely describe the current conversion state of the associated
15688     multibyte character sequence, which the functions alter as necessary. If ps is a null
15689     pointer, each function uses its own internal mbstate_t object instead, which is
15690     initialized at program startup to the initial conversion state; the functions are not required
15691     to avoid data races in this case. The implementation behaves as if no library function
15692     calls these functions with a null pointer for ps.
15693     7.27.1.1 The mbrtoc16 function
15694     Synopsis
15695 1          #include <uchar.h>
15696            size_t mbrtoc16(char16_t * restrict pc16,
15697                 const char * restrict s, size_t n,
15698                 mbstate_t * restrict ps);
15699     Description
15700 2   If s is a null pointer, the mbrtoc16 function is equivalent to the call:
15701                    mbrtoc16(NULL, "", 1, ps)
15702     In this case, the values of the parameters pc16 and n are ignored.
15703 3   If s is not a null pointer, the mbrtoc16 function inspects at most n bytes beginning with
15704     the byte pointed to by s to determine the number of bytes needed to complete the next
15705     multibyte character (including any shift sequences). If the function determines that the
15706     next multibyte character is complete and valid, it determines the values of the
15707     corresponding wide characters and then, if pc16 is not a null pointer, stores the value of
15708     the first (or only) such character in the object pointed to by pc16. Subsequent calls will
15709 [page 394]
15710
15711     store successive wide characters without consuming any additional input until all the
15712     characters have been stored. If the corresponding wide character is the null wide
15713     character, the resulting state described is the initial conversion state.
15714     Returns
15715 4   The mbrtoc16 function returns the first of the following that applies (given the current
15716     conversion state):
15717     0                     if the next n or fewer bytes complete the multibyte character that
15718                           corresponds to the null wide character (which is the value stored).
15719     between 1 and n inclusive if the next n or fewer bytes complete a valid multibyte
15720                        character (which is the value stored); the value returned is the number
15721                        of bytes that complete the multibyte character.
15722     (size_t)(-3) if the next character resulting from a previous call has been stored (no
15723                  bytes from the input have been consumed by this call).
15724     (size_t)(-2) if the next n bytes contribute to an incomplete (but potentially valid)
15725                  multibyte character, and all n bytes have been processed (no value is
15726                  stored).307)
15727     (size_t)(-1) if an encoding error occurs, in which case the next n or fewer bytes
15728                  do not contribute to a complete and valid multibyte character (no
15729                  value is stored); the value of the macro EILSEQ is stored in errno,
15730                  and the conversion state is unspecified.
15731     7.27.1.2 The c16rtomb function
15732     Synopsis
15733 1           #include <uchar.h>
15734             size_t c16rtomb(char * restrict s, char16_t c16,
15735                  mbstate_t * restrict ps);
15736     Description
15737 2   If s is a null pointer, the c16rtomb function is equivalent to the call
15738                     c16rtomb(buf, L'\0', ps)
15739     where buf is an internal buffer.
15740 3   If s is not a null pointer, the c16rtomb function determines the number of bytes needed
15741     to represent the multibyte character that corresponds to the wide character given by c16
15742     (including any shift sequences), and stores the multibyte character representation in the
15743
15744     307) When n has at least the value of the MB_CUR_MAX macro, this case can only occur if s points at a
15745          sequence of redundant shift sequences (for implementations with state-dependent encodings).
15746
15747 [page 395]
15748
15749     array whose first element is pointed to by s. At most MB_CUR_MAX bytes are stored. If
15750     c16 is a null wide character, a null byte is stored, preceded by any shift sequence needed
15751     to restore the initial shift state; the resulting state described is the initial conversion state.
15752     Returns
15753 4   The c16rtomb function returns the number of bytes stored in the array object (including
15754     any shift sequences). When c16 is not a valid wide character, an encoding error occurs:
15755     the function stores the value of the macro EILSEQ in errno and returns
15756     (size_t)(-1); the conversion state is unspecified.
15757     7.27.1.3 The mbrtoc32 function
15758     Synopsis
15759 1           #include <uchar.h>
15760             size_t mbrtoc32(char32_t * restrict pc32,
15761                  const char * restrict s, size_t n,
15762                  mbstate_t * restrict ps);
15763     Description
15764 2   If s is a null pointer, the mbrtoc32 function is equivalent to the call:
15765                     mbrtoc32(NULL, "", 1, ps)
15766     In this case, the values of the parameters pc32 and n are ignored.
15767 3   If s is not a null pointer, the mbrtoc32 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 pc32 is not a null pointer, stores the value of
15772     the first (or only) such character in the object pointed to by pc32. Subsequent calls will
15773     store successive wide characters without consuming any additional input until all the
15774     characters have been stored. If the corresponding wide character is the null wide
15775     character, the resulting state described is the initial conversion state.
15776     Returns
15777 4   The mbrtoc32 function returns the first of the following that applies (given the current
15778     conversion state):
15779     0                    if the next n or fewer bytes complete the multibyte character that
15780                          corresponds to the null wide character (which is the value stored).
15781     between 1 and n inclusive if the next n or fewer bytes complete a valid multibyte
15782                        character (which is the value stored); the value returned is the number
15783                        of bytes that complete the multibyte character.
15784
15785
15786 [page 396]
15787
15788     (size_t)(-3) if the next character resulting from a previous call has been stored (no
15789                  bytes from the input have been consumed by this call).
15790     (size_t)(-2) if the next n bytes contribute to an incomplete (but potentially valid)
15791                  multibyte character, and all n bytes have been processed (no value is
15792                  stored).308)
15793     (size_t)(-1) if an encoding error occurs, in which case the next n or fewer bytes
15794                  do not contribute to a complete and valid multibyte character (no
15795                  value is stored); the value of the macro EILSEQ is stored in errno,
15796                  and the conversion state is unspecified.
15797     7.27.1.4 The c32rtomb function
15798     Synopsis
15799 1           #include <uchar.h>
15800             size_t c32rtomb(char * restrict s, char32_t c32,
15801                  mbstate_t * restrict ps);
15802     Description
15803 2   If s is a null pointer, the c32rtomb function is equivalent to the call
15804                     c32rtomb(buf, L'\0', ps)
15805     where buf is an internal buffer.
15806 3   If s is not a null pointer, the c32rtomb function determines the number of bytes needed
15807     to represent the multibyte character that corresponds to the wide character given by c32
15808     (including any shift sequences), and stores the multibyte character representation in the
15809     array whose first element is pointed to by s. At most MB_CUR_MAX bytes are stored. If
15810     c32 is a null wide character, a null byte is stored, preceded by any shift sequence needed
15811     to restore the initial shift state; the resulting state described is the initial conversion state.
15812     Returns
15813 4   The c32rtomb function returns the number of bytes stored in the array object (including
15814     any shift sequences). When c32 is not a valid wide character, an encoding error occurs:
15815     the function stores the value of the macro EILSEQ in errno and returns
15816     (size_t)(-1); the conversion state is unspecified.
15817
15818
15819
15820
15821     308) When n has at least the value of the MB_CUR_MAX macro, this case can only occur if s points at a
15822          sequence of redundant shift sequences (for implementations with state-dependent encodings).
15823
15824 [page 397]
15825
15826     7.28 Extended multibyte and wide character utilities <wchar.h>
15827     7.28.1 Introduction
15828 1   The header <wchar.h> defines four macros, and declares four data types, one tag, and
15829     many functions.309)
15830 2   The types declared are wchar_t and size_t (both described in 7.19);
15831              mbstate_t
15832     which is a complete object type other than an array type that can hold the conversion state
15833     information necessary to convert between sequences of multibyte characters and wide
15834     characters;
15835              wint_t
15836     which is an integer type unchanged by default argument promotions that can hold any
15837     value corresponding to members of the extended character set, as well as at least one
15838     value that does not correspond to any member of the extended character set (see WEOF
15839     below);310) and
15840              struct tm
15841     which is declared as an incomplete structure type (the contents are described in 7.26.1).
15842 3   The macros defined are NULL (described in 7.19); WCHAR_MIN and WCHAR_MAX
15843     (described in 7.20.3); and
15844              WEOF
15845     which expands to a constant expression of type wint_t whose value does not
15846     correspond to any member of the extended character set.311) It is accepted (and returned)
15847     by several functions in this subclause to indicate end-of-file, that is, no more input from a
15848     stream. It is also used as a wide character value that does not correspond to any member
15849     of the extended character set.
15850 4   The functions declared are grouped as follows:
15851     -- Functions that perform input and output of wide characters, or multibyte characters,
15852       or both;
15853     -- Functions that provide wide string numeric conversion;
15854     -- Functions that perform general wide string manipulation;
15855
15856
15857     309) See ''future library directions'' (7.30.12).
15858     310) wchar_t and wint_t can be the same integer type.
15859     311) The value of the macro WEOF may differ from that of EOF and need not be negative.
15860
15861 [page 398]
15862
15863     -- Functions for wide string date and time conversion; and
15864     -- Functions that provide extended capabilities for conversion between multibyte and
15865       wide character sequences.
15866 5   Unless explicitly stated otherwise, if the execution of a function described in this
15867     subclause causes copying to take place between objects that overlap, the behavior is
15868     undefined.
15869     7.28.2 Formatted wide character input/output functions
15870 1   The formatted wide character input/output functions shall behave as if there is a sequence
15871     point after the actions associated with each specifier.312)
15872     7.28.2.1 The fwprintf function
15873     Synopsis
15874 1           #include <stdio.h>
15875             #include <wchar.h>
15876             int fwprintf(FILE * restrict stream,
15877                  const wchar_t * restrict format, ...);
15878     Description
15879 2   The fwprintf function writes output to the stream pointed to by stream, under
15880     control of the wide string pointed to by format that specifies how subsequent arguments
15881     are converted for output. If there are insufficient arguments for the format, the behavior
15882     is undefined. If the format is exhausted while arguments remain, the excess arguments
15883     are evaluated (as always) but are otherwise ignored. The fwprintf function returns
15884     when the end of the format string is encountered.
15885 3   The format is composed of zero or more directives: ordinary wide characters (not %),
15886     which are copied unchanged to the output stream; and conversion specifications, each of
15887     which results in fetching zero or more subsequent arguments, converting them, if
15888     applicable, according to the corresponding conversion specifier, and then writing the
15889     result to the output stream.
15890 4   Each conversion specification is introduced by the wide character %. After the %, the
15891     following appear in sequence:
15892     -- Zero or more flags (in any order) that modify the meaning of the conversion
15893       specification.
15894     -- An optional minimum field width. If the converted value has fewer wide characters
15895       than the field width, it is padded with spaces (by default) on the left (or right, if the
15896
15897
15898     312) The fwprintf functions perform writes to memory for the %n specifier.
15899
15900 [page 399]
15901
15902         left adjustment flag, described later, has been given) to the field width. The field
15903         width takes the form of an asterisk * (described later) or a nonnegative decimal
15904         integer.313)
15905     -- An optional precision that gives the minimum number of digits to appear for the d, i,
15906       o, u, x, and X conversions, the number of digits to appear after the decimal-point
15907       wide character for a, A, e, E, f, and F conversions, the maximum number of
15908       significant digits for the g and G conversions, or the maximum number of wide
15909       characters to be written for s conversions. The precision takes the form of a period
15910       (.) followed either by an asterisk * (described later) or by an optional decimal
15911       integer; if only the period is specified, the precision is taken as zero. If a precision
15912       appears with any other conversion specifier, the behavior is undefined.
15913     -- An optional length modifier that specifies the size of the argument.
15914     -- A conversion specifier wide character that specifies the type of conversion to be
15915       applied.
15916 5   As noted above, a field width, or precision, or both, may be indicated by an asterisk. In
15917     this case, an int argument supplies the field width or precision. The arguments
15918     specifying field width, or precision, or both, shall appear (in that order) before the
15919     argument (if any) to be converted. A negative field width argument is taken as a - flag
15920     followed by a positive field width. A negative precision argument is taken as if the
15921     precision were omitted.
15922 6   The flag wide characters and their meanings are:
15923     -        The result of the conversion is left-justified within the field. (It is right-justified if
15924              this flag is not specified.)
15925     +        The result of a signed conversion always begins with a plus or minus sign. (It
15926              begins with a sign only when a negative value is converted if this flag is not
15927              specified.)314)
15928     space If the first wide character of a signed conversion is not a sign, or if a signed
15929           conversion results in no wide characters, a space is prefixed to the result. If the
15930           space and + flags both appear, the space flag is ignored.
15931     #        The result is converted to an ''alternative form''. For o conversion, it increases
15932              the precision, if and only if necessary, to force the first digit of the result to be a
15933              zero (if the value and precision are both 0, a single 0 is printed). For x (or X)
15934              conversion, a nonzero result has 0x (or 0X) prefixed to it. For a, A, e, E, f, F, g,
15935
15936
15937     313) Note that 0 is taken as a flag, not as the beginning of a field width.
15938     314) The results of all floating conversions of a negative zero, and of negative values that round to zero,
15939          include a minus sign.
15940
15941 [page 400]
15942
15943               and G conversions, the result of converting a floating-point number always
15944               contains a decimal-point wide character, even if no digits follow it. (Normally, a
15945               decimal-point wide character appears in the result of these conversions only if a
15946               digit follows it.) For g and G conversions, trailing zeros are not removed from the
15947               result. For other conversions, the behavior is undefined.
15948     0         For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros
15949               (following any indication of sign or base) are used to pad to the field width rather
15950               than performing space padding, except when converting an infinity or NaN. If the
15951               0 and - flags both appear, the 0 flag is ignored. For d, i, o, u, x, and X
15952               conversions, if a precision is specified, the 0 flag is ignored. For other
15953               conversions, the behavior is undefined.
15954 7   The length modifiers and their meanings are:
15955     hh             Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
15956                    signed char or unsigned char argument (the argument will have
15957                    been promoted according to the integer promotions, but its value shall be
15958                    converted to signed char or unsigned char before printing); or that
15959                    a following n conversion specifier applies to a pointer to a signed char
15960                    argument.
15961     h              Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
15962                    short int or unsigned short int argument (the argument will
15963                    have been promoted according to the integer promotions, but its value shall
15964                    be converted to short int or unsigned short int before printing);
15965                    or that a following n conversion specifier applies to a pointer to a short
15966                    int argument.
15967     l (ell)        Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
15968                    long int or unsigned long int argument; that a following n
15969                    conversion specifier applies to a pointer to a long int argument; that a
15970                    following c conversion specifier applies to a wint_t argument; that a
15971                    following s conversion specifier applies to a pointer to a wchar_t
15972                    argument; or has no effect on a following a, A, e, E, f, F, g, or G conversion
15973                    specifier.
15974     ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
15975                  long long int or unsigned long long int argument; or that a
15976                  following n conversion specifier applies to a pointer to a long long int
15977                  argument.
15978     j              Specifies that a following d, i, o, u, x, or X conversion specifier applies to
15979                    an intmax_t or uintmax_t argument; or that a following n conversion
15980                    specifier applies to a pointer to an intmax_t argument.
15981
15982 [page 401]
15983
15984     z           Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
15985                 size_t or the corresponding signed integer type argument; or that a
15986                 following n conversion specifier applies to a pointer to a signed integer type
15987                 corresponding to size_t argument.
15988     t           Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
15989                 ptrdiff_t or the corresponding unsigned integer type argument; or that a
15990                 following n conversion specifier applies to a pointer to a ptrdiff_t
15991                 argument.
15992     L           Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
15993                 applies to a long double argument.
15994     If a length modifier appears with any conversion specifier other than as specified above,
15995     the behavior is undefined.
15996 8   The conversion specifiers and their meanings are:
15997     d,i        The int argument is converted to signed decimal in the style [-]dddd. The
15998                precision specifies the minimum number of digits to appear; if the value
15999                being converted can be represented in fewer digits, it is expanded with
16000                leading zeros. The default precision is 1. The result of converting a zero
16001                value with a precision of zero is no wide characters.
16002     o,u,x,X The unsigned int argument is converted to unsigned octal (o), unsigned
16003             decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; the
16004             letters abcdef are used for x conversion and the letters ABCDEF for X
16005             conversion. The precision specifies the minimum number of digits to appear;
16006             if the value being converted can be represented in fewer digits, it is expanded
16007             with leading zeros. The default precision is 1. The result of converting a
16008             zero value with a precision of zero is no wide characters.
16009     f,F        A double argument representing a floating-point number is converted to
16010                decimal notation in the style [-]ddd.ddd, where the number of digits after
16011                the decimal-point wide character is equal to the precision specification. If the
16012                precision is missing, it is taken as 6; if the precision is zero and the # flag is
16013                not specified, no decimal-point wide character appears. If a decimal-point
16014                wide character appears, at least one digit appears before it. The value is
16015                rounded to the appropriate number of digits.
16016                A double argument representing an infinity is converted in one of the styles
16017                [-]inf or [-]infinity -- which style is implementation-defined. A
16018                double argument representing a NaN is converted in one of the styles
16019                [-]nan or [-]nan(n-wchar-sequence) -- which style, and the meaning of
16020                any n-wchar-sequence, is implementation-defined. The F conversion
16021                specifier produces INF, INFINITY, or NAN instead of inf, infinity, or
16022
16023 [page 402]
16024
16025              nan, respectively.315)
16026 e,E          A double argument representing a floating-point number is converted in the
16027              style [-]d.ddd e(+-)dd, where there is one digit (which is nonzero if the
16028              argument is nonzero) before the decimal-point wide character and the number
16029              of digits after it is equal to the precision; if the precision is missing, it is taken
16030              as 6; if the precision is zero and the # flag is not specified, no decimal-point
16031              wide character appears. The value is rounded to the appropriate number of
16032              digits. The E conversion specifier produces a number with E instead of e
16033              introducing the exponent. The exponent always contains at least two digits,
16034              and only as many more digits as necessary to represent the exponent. If the
16035              value is zero, the exponent is zero.
16036              A double argument representing an infinity or NaN is converted in the style
16037              of an f or F conversion specifier.
16038 g,G          A double argument representing a floating-point number is converted in
16039              style f or e (or in style F or E in the case of a G conversion specifier),
16040              depending on the value converted and the precision. Let P equal the
16041              precision if nonzero, 6 if the precision is omitted, or 1 if the precision is zero.
16042              Then, if a conversion with style E would have an exponent of X:
16043              -- if P > X >= -4, the conversion is with style f (or F) and precision
16044                P - (X + 1).
16045              -- otherwise, the conversion is with style e (or E) and precision P - 1.
16046              Finally, unless the # flag is used, any trailing zeros are removed from the
16047              fractional portion of the result and the decimal-point wide character is
16048              removed if there is no fractional portion remaining.
16049              A double argument representing an infinity or NaN is converted in the style
16050              of an f or F conversion specifier.
16051 a,A          A double argument representing a floating-point number is converted in the
16052              style [-]0xh.hhhh p(+-)d, where there is one hexadecimal digit (which is
16053              nonzero if the argument is a normalized floating-point number and is
16054              otherwise unspecified) before the decimal-point wide character316) and the
16055              number of hexadecimal digits after it is equal to the precision; if the precision
16056              is missing and FLT_RADIX is a power of 2, then the precision is sufficient
16057
16058
16059 315) When applied to infinite and NaN values, the -, +, and space flag wide characters have their usual
16060      meaning; the # and 0 flag wide characters have no effect.
16061 316) Binary implementations can choose the hexadecimal digit to the left of the decimal-point wide
16062      character so that subsequent digits align to nibble (4-bit) boundaries.
16063
16064 [page 403]
16065
16066              for an exact representation of the value; if the precision is missing and
16067              FLT_RADIX is not a power of 2, then the precision is sufficient to
16068              distinguish317) values of type double, except that trailing zeros may be
16069              omitted; if the precision is zero and the # flag is not specified, no decimal-
16070              point wide character appears. The letters abcdef are used for a conversion
16071              and the letters ABCDEF for A conversion. The A conversion specifier
16072              produces a number with X and P instead of x and p. The exponent always
16073              contains at least one digit, and only as many more digits as necessary to
16074              represent the decimal exponent of 2. If the value is zero, the exponent is
16075              zero.
16076              A double argument representing an infinity or NaN is converted in the style
16077              of an f or F conversion specifier.
16078 c            If no l length modifier is present, the int argument is converted to a wide
16079              character as if by calling btowc and the resulting wide character is written.
16080              If an l length modifier is present, the wint_t argument is converted to
16081              wchar_t and written.
16082 s            If no l length modifier is present, the argument shall be a pointer to the initial
16083              element of a character array containing a multibyte character sequence
16084              beginning in the initial shift state. Characters from the array are converted as
16085              if by repeated calls to the mbrtowc function, with the conversion state
16086              described by an mbstate_t object initialized to zero before the first
16087              multibyte character is converted, and written up to (but not including) the
16088              terminating null wide character. If the precision is specified, no more than
16089              that many wide characters are written. If the precision is not specified or is
16090              greater than the size of the converted array, the converted array shall contain a
16091              null wide character.
16092              If an l length modifier is present, the argument shall be a pointer to the initial
16093              element of an array of wchar_t type. Wide characters from the array are
16094              written up to (but not including) a terminating null wide character. If the
16095              precision is specified, no more than that many wide characters are written. If
16096              the precision is not specified or is greater than the size of the array, the array
16097              shall contain a null wide character.
16098 p            The argument shall be a pointer to void. The value of the pointer is
16099              converted to a sequence of printing wide characters, in an implementation-
16100
16101 317) The precision p is sufficient to distinguish values of the source type if 16 p-1 > b n where b is
16102      FLT_RADIX and n is the number of base-b digits in the significand of the source type. A smaller p
16103      might suffice depending on the implementation's scheme for determining the digit to the left of the
16104      decimal-point wide character.
16105
16106 [page 404]
16107
16108                     defined manner.
16109      n              The argument shall be a pointer to signed integer into which is written the
16110                     number of wide characters written to the output stream so far by this call to
16111                     fwprintf. No argument is converted, but one is consumed. If the
16112                     conversion specification includes any flags, a field width, or a precision, the
16113                     behavior is undefined.
16114      %              A % wide character is written. No argument is converted. The complete
16115                     conversion specification shall be %%.
16116 9    If a conversion specification is invalid, the behavior is undefined.318) If any argument is
16117      not the correct type for the corresponding conversion specification, the behavior is
16118      undefined.
16119 10   In no case does a nonexistent or small field width cause truncation of a field; if the result
16120      of a conversion is wider than the field width, the field is expanded to contain the
16121      conversion result.
16122 11   For a and A conversions, if FLT_RADIX is a power of 2, the value is correctly rounded
16123      to a hexadecimal floating number with the given precision.
16124      Recommended practice
16125 12   For a and A conversions, if FLT_RADIX is not a power of 2 and the result is not exactly
16126      representable in the given precision, the result should be one of the two adjacent numbers
16127      in hexadecimal floating style with the given precision, with the extra stipulation that the
16128      error should have a correct sign for the current rounding direction.
16129 13   For e, E, f, F, g, and G conversions, if the number of significant decimal digits is at most
16130      DECIMAL_DIG, then the result should be correctly rounded.319) If the number of
16131      significant decimal digits is more than DECIMAL_DIG but the source value is exactly
16132      representable with DECIMAL_DIG digits, then the result should be an exact
16133      representation with trailing zeros. Otherwise, the source value is bounded by two
16134      adjacent decimal strings L < U, both having DECIMAL_DIG significant digits; the value
16135      of the resultant decimal string D should satisfy L <= D <= U, with the extra stipulation that
16136      the error should have a correct sign for the current rounding direction.
16137      Returns
16138 14   The fwprintf function returns the number of wide characters transmitted, or a negative
16139      value if an output or encoding error occurred.
16140
16141      318) See ''future library directions'' (7.30.12).
16142      319) For binary-to-decimal conversion, the result format's values are the numbers representable with the
16143           given format specifier. The number of significant digits is determined by the format specifier, and in
16144           the case of fixed-point conversion by the source value as well.
16145
16146 [page 405]
16147
16148      Environmental limits
16149 15   The number of wide characters that can be produced by any single conversion shall be at
16150      least 4095.
16151 16   EXAMPLE       To print a date and time in the form ''Sunday, July 3, 10:02'' followed by pi to five decimal
16152      places:
16153             #include <math.h>
16154             #include <stdio.h>
16155             #include <wchar.h>
16156             /* ... */
16157             wchar_t *weekday, *month; // pointers to wide strings
16158             int day, hour, min;
16159             fwprintf(stdout, L"%ls, %ls %d, %.2d:%.2d\n",
16160                     weekday, month, day, hour, min);
16161             fwprintf(stdout, L"pi = %.5f\n", 4 * atan(1.0));
16162
16163      Forward references:          the btowc function (7.28.6.1.1), the mbrtowc function
16164      (7.28.6.3.2).
16165      7.28.2.2 The fwscanf function
16166      Synopsis
16167 1           #include <stdio.h>
16168             #include <wchar.h>
16169             int fwscanf(FILE * restrict stream,
16170                  const wchar_t * restrict format, ...);
16171      Description
16172 2    The fwscanf function reads input from the stream pointed to by stream, under
16173      control of the wide string pointed to by format that specifies the admissible input
16174      sequences and how they are to be converted for assignment, using subsequent arguments
16175      as pointers to the objects to receive the converted input. If there are insufficient
16176      arguments for the format, the behavior is undefined. If the format is exhausted while
16177      arguments remain, the excess arguments are evaluated (as always) but are otherwise
16178      ignored.
16179 3    The format is composed of zero or more directives: one or more white-space wide
16180      characters, an ordinary wide character (neither % nor a white-space wide character), or a
16181      conversion specification. Each conversion specification is introduced by the wide
16182      character %. After the %, the following appear in sequence:
16183      -- An optional assignment-suppressing wide character *.
16184      -- An optional decimal integer greater than zero that specifies the maximum field width
16185        (in wide characters).
16186
16187
16188
16189 [page 406]
16190
16191      -- An optional length modifier that specifies the size of the receiving object.
16192      -- A conversion specifier wide character that specifies the type of conversion to be
16193        applied.
16194 4    The fwscanf function executes each directive of the format in turn. When all directives
16195      have been executed, or if a directive fails (as detailed below), the function returns.
16196      Failures are described as input failures (due to the occurrence of an encoding error or the
16197      unavailability of input characters), or matching failures (due to inappropriate input).
16198 5    A directive composed of white-space wide character(s) is executed by reading input up to
16199      the first non-white-space wide character (which remains unread), or until no more wide
16200      characters can be read.
16201 6    A directive that is an ordinary wide character is executed by reading the next wide
16202      character of the stream. If that wide character differs from the directive, the directive
16203      fails and the differing and subsequent wide characters remain unread. Similarly, if end-
16204      of-file, an encoding error, or a read error prevents a wide character from being read, the
16205      directive fails.
16206 7    A directive that is a conversion specification defines a set of matching input sequences, as
16207      described below for each specifier. A conversion specification is executed in the
16208      following steps:
16209 8    Input white-space wide characters (as specified by the iswspace function) are skipped,
16210      unless the specification includes a [, c, or n specifier.320)
16211 9    An input item is read from the stream, unless the specification includes an n specifier. An
16212      input item is defined as the longest sequence of input wide characters which does not
16213      exceed any specified field width and which is, or is a prefix of, a matching input
16214      sequence.321) The first wide character, if any, after the input item remains unread. If the
16215      length of the input item is zero, the execution of the directive fails; this condition is a
16216      matching failure unless end-of-file, an encoding error, or a read error prevented input
16217      from the stream, in which case it is an input failure.
16218 10   Except in the case of a % specifier, the input item (or, in the case of a %n directive, the
16219      count of input wide characters) is converted to a type appropriate to the conversion
16220      specifier. If the input item is not a matching sequence, the execution of the directive fails:
16221      this condition is a matching failure. Unless assignment suppression was indicated by a *,
16222      the result of the conversion is placed in the object pointed to by the first argument
16223      following the format argument that has not already received a conversion result. If this
16224
16225
16226      320) These white-space wide characters are not counted against a specified field width.
16227      321) fwscanf pushes back at most one input wide character onto the input stream. Therefore, some
16228           sequences that are acceptable to wcstod, wcstol, etc., are unacceptable to fwscanf.
16229
16230 [page 407]
16231
16232      object does not have an appropriate type, or if the result of the conversion cannot be
16233      represented in the object, the behavior is undefined.
16234 11   The length modifiers and their meanings are:
16235      hh          Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16236                  to an argument with type pointer to signed char or unsigned char.
16237      h           Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16238                  to an argument with type pointer to short int or unsigned short
16239                  int.
16240      l (ell)     Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16241                  to an argument with type pointer to long int or unsigned long
16242                  int; that a following a, A, e, E, f, F, g, or G conversion specifier applies to
16243                  an argument with type pointer to double; or that a following c, s, or [
16244                  conversion specifier applies to an argument with type pointer to wchar_t.
16245      ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16246                   to an argument with type pointer to long long int or unsigned
16247                   long long int.
16248      j           Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16249                  to an argument with type pointer to intmax_t or uintmax_t.
16250      z           Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16251                  to an argument with type pointer to size_t or the corresponding signed
16252                  integer type.
16253      t           Specifies that a following d, i, o, u, x, X, or n conversion specifier applies
16254                  to an argument with type pointer to ptrdiff_t or the corresponding
16255                  unsigned integer type.
16256      L           Specifies that a following a, A, e, E, f, F, g, or G conversion specifier
16257                  applies to an argument with type pointer to long double.
16258      If a length modifier appears with any conversion specifier other than as specified above,
16259      the behavior is undefined.
16260 12   The conversion specifiers and their meanings are:
16261      d          Matches an optionally signed decimal integer, whose format is the same as
16262                 expected for the subject sequence of the wcstol function with the value 10
16263                 for the base argument. The corresponding argument shall be a pointer to
16264                 signed integer.
16265      i          Matches an optionally signed integer, whose format is the same as expected
16266                 for the subject sequence of the wcstol function with the value 0 for the
16267                 base argument. The corresponding argument shall be a pointer to signed
16268
16269 [page 408]
16270
16271             integer.
16272 o           Matches an optionally signed octal integer, whose format is the same as
16273             expected for the subject sequence of the wcstoul function with the value 8
16274             for the base argument. The corresponding argument shall be a pointer to
16275             unsigned integer.
16276 u           Matches an optionally signed decimal integer, whose format is the same as
16277             expected for the subject sequence of the wcstoul function with the value 10
16278             for the base argument. The corresponding argument shall be a pointer to
16279             unsigned integer.
16280 x           Matches an optionally signed hexadecimal integer, whose format is the same
16281             as expected for the subject sequence of the wcstoul function with the value
16282             16 for the base argument. The corresponding argument shall be a pointer to
16283             unsigned integer.
16284 a,e,f,g Matches an optionally signed floating-point number, infinity, or NaN, whose
16285         format is the same as expected for the subject sequence of the wcstod
16286         function. The corresponding argument shall be a pointer to floating.
16287 c           Matches a sequence of wide characters of exactly the number specified by the
16288             field width (1 if no field width is present in the directive).
16289             If no l length modifier is present, characters from the input field are
16290             converted as if by repeated calls to the wcrtomb function, with the
16291             conversion state described by an mbstate_t object initialized to zero
16292             before the first wide character is converted. The corresponding argument
16293             shall be a pointer to the initial element of a character array large enough to
16294             accept the sequence. No null character is added.
16295             If an l length modifier is present, the corresponding argument shall be a
16296             pointer to the initial element of an array of wchar_t large enough to accept
16297             the sequence. No null wide character is added.
16298 s           Matches a sequence of non-white-space wide characters.
16299             If no l length modifier is present, characters from the input field are
16300             converted as if by repeated calls to the wcrtomb function, with the
16301             conversion state described by an mbstate_t object initialized to zero
16302             before the first wide character is converted. The corresponding argument
16303             shall be a pointer to the initial element of a character array large enough to
16304             accept the sequence and a terminating null character, which will be added
16305             automatically.
16306             If an l length modifier is present, the corresponding argument shall be a
16307             pointer to the initial element of an array of wchar_t large enough to accept
16308
16309 [page 409]
16310
16311          the sequence and the terminating null wide character, which will be added
16312          automatically.
16313 [        Matches a nonempty sequence of wide characters from a set of expected
16314          characters (the scanset).
16315          If no l length modifier is present, characters from the input field are
16316          converted as if by repeated calls to the wcrtomb function, with the
16317          conversion state described by an mbstate_t object initialized to zero
16318          before the first wide character is converted. The corresponding argument
16319          shall be a pointer to the initial element of a character array large enough to
16320          accept the sequence and a terminating null character, which will be added
16321          automatically.
16322          If an l length modifier is present, the corresponding argument shall be a
16323          pointer to the initial element of an array of wchar_t large enough to accept
16324          the sequence and the terminating null wide character, which will be added
16325          automatically.
16326          The conversion specifier includes all subsequent wide characters in the
16327          format string, up to and including the matching right bracket (]). The wide
16328          characters between the brackets (the scanlist) compose the scanset, unless the
16329          wide character after the left bracket is a circumflex (^), in which case the
16330          scanset contains all wide characters that do not appear in the scanlist between
16331          the circumflex and the right bracket. If the conversion specifier begins with
16332          [] or [^], the right bracket wide character is in the scanlist and the next
16333          following right bracket wide character is the matching right bracket that ends
16334          the specification; otherwise the first following right bracket wide character is
16335          the one that ends the specification. If a - wide character is in the scanlist and
16336          is not the first, nor the second where the first wide character is a ^, nor the
16337          last character, the behavior is implementation-defined.
16338 p        Matches an implementation-defined set of sequences, which should be the
16339          same as the set of sequences that may be produced by the %p conversion of
16340          the fwprintf function. The corresponding argument shall be a pointer to a
16341          pointer to void. The input item is converted to a pointer value in an
16342          implementation-defined manner. If the input item is a value converted earlier
16343          during the same program execution, the pointer that results shall compare
16344          equal to that value; otherwise the behavior of the %p conversion is undefined.
16345 n        No input is consumed. The corresponding argument shall be a pointer to
16346          signed integer into which is to be written the number of wide characters read
16347          from the input stream so far by this call to the fwscanf function. Execution
16348          of a %n directive does not increment the assignment count returned at the
16349          completion of execution of the fwscanf function. No argument is
16350 [page 410]
16351
16352                     converted, but one is consumed. If the conversion specification includes an
16353                     assignment-suppressing wide character or a field width, the behavior is
16354                     undefined.
16355      %              Matches a single % wide character; no conversion or assignment occurs. The
16356                     complete conversion specification shall be %%.
16357 13   If a conversion specification is invalid, the behavior is undefined.322)
16358 14   The conversion specifiers A, E, F, G, and X are also valid and behave the same as,
16359      respectively, a, e, f, g, and x.
16360 15   Trailing white space (including new-line wide characters) is left unread unless matched
16361      by a directive. The success of literal matches and suppressed assignments is not directly
16362      determinable other than via the %n directive.
16363      Returns
16364 16   The fwscanf function returns the value of the macro EOF if an input failure occurs
16365      before the first conversion (if any) has completed. Otherwise, the function returns the
16366      number of input items assigned, which can be fewer than provided for, or even zero, in
16367      the event of an early matching failure.
16368 17   EXAMPLE 1        The call:
16369               #include <stdio.h>
16370               #include <wchar.h>
16371               /* ... */
16372               int n, i; float x; wchar_t name[50];
16373               n = fwscanf(stdin, L"%d%f%ls", &i, &x, name);
16374      with the input line:
16375               25 54.32E-1 thompson
16376      will assign to n the value 3, to i the value 25, to x the value 5.432, and to name the sequence
16377      thompson\0.
16378
16379 18   EXAMPLE 2        The call:
16380               #include <stdio.h>
16381               #include <wchar.h>
16382               /* ... */
16383               int i; float x; double y;
16384               fwscanf(stdin, L"%2d%f%*d %lf", &i, &x, &y);
16385      with input:
16386               56789 0123 56a72
16387      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
16388      56.0. The next wide character read from the input stream will be a.
16389
16390
16391      322) See ''future library directions'' (7.30.12).
16392
16393 [page 411]
16394
16395     Forward references: the wcstod, wcstof, and wcstold functions (7.28.4.1.1), the
16396     wcstol, wcstoll, wcstoul, and wcstoull functions (7.28.4.1.2), the wcrtomb
16397     function (7.28.6.3.3).
16398     7.28.2.3 The swprintf function
16399     Synopsis
16400 1          #include <wchar.h>
16401            int swprintf(wchar_t * restrict s,
16402                 size_t n,
16403                 const wchar_t * restrict format, ...);
16404     Description
16405 2   The swprintf function is equivalent to fwprintf, except that the argument s
16406     specifies an array of wide characters into which the generated output is to be written,
16407     rather than written to a stream. No more than n wide characters are written, including a
16408     terminating null wide character, which is always added (unless n is zero).
16409     Returns
16410 3   The swprintf function returns the number of wide characters written in the array, not
16411     counting the terminating null wide character, or a negative value if an encoding error
16412     occurred or if n or more wide characters were requested to be written.
16413     7.28.2.4 The swscanf function
16414     Synopsis
16415 1          #include <wchar.h>
16416            int swscanf(const wchar_t * restrict s,
16417                 const wchar_t * restrict format, ...);
16418     Description
16419 2   The swscanf function is equivalent to fwscanf, except that the argument s specifies a
16420     wide string from which the input is to be obtained, rather than from a stream. Reaching
16421     the end of the wide string is equivalent to encountering end-of-file for the fwscanf
16422     function.
16423     Returns
16424 3   The swscanf function returns the value of the macro EOF if an input failure occurs
16425     before the first conversion (if any) has completed. Otherwise, the swscanf function
16426     returns the number of input items assigned, which can be fewer than provided for, or even
16427     zero, in the event of an early matching failure.
16428
16429
16430
16431
16432 [page 412]
16433
16434     7.28.2.5 The vfwprintf function
16435     Synopsis
16436 1           #include <stdarg.h>
16437             #include <stdio.h>
16438             #include <wchar.h>
16439             int vfwprintf(FILE * restrict stream,
16440                  const wchar_t * restrict format,
16441                  va_list arg);
16442     Description
16443 2   The vfwprintf function is equivalent to fwprintf, with the variable argument list
16444     replaced by arg, which shall have been initialized by the va_start macro (and
16445     possibly subsequent va_arg calls). The vfwprintf function does not invoke the
16446     va_end macro.323)
16447     Returns
16448 3   The vfwprintf function returns the number of wide characters transmitted, or a
16449     negative value if an output or encoding error occurred.
16450 4   EXAMPLE       The following shows the use of the vfwprintf function in a general error-reporting
16451     routine.
16452             #include <stdarg.h>
16453             #include <stdio.h>
16454             #include <wchar.h>
16455             void error(char *function_name, wchar_t *format, ...)
16456             {
16457                   va_list args;
16458                     va_start(args, format);
16459                     // print out name of function causing error
16460                     fwprintf(stderr, L"ERROR in %s: ", function_name);
16461                     // print out remainder of message
16462                     vfwprintf(stderr, format, args);
16463                     va_end(args);
16464             }
16465
16466
16467
16468
16469     323) As the functions vfwprintf, vswprintf, vfwscanf, vwprintf, vwscanf, and vswscanf
16470          invoke the va_arg macro, the value of arg after the return is indeterminate.
16471
16472 [page 413]
16473
16474     7.28.2.6 The vfwscanf function
16475     Synopsis
16476 1          #include <stdarg.h>
16477            #include <stdio.h>
16478            #include <wchar.h>
16479            int vfwscanf(FILE * restrict stream,
16480                 const wchar_t * restrict format,
16481                 va_list arg);
16482     Description
16483 2   The vfwscanf function is equivalent to fwscanf, with the variable argument list
16484     replaced by arg, which shall have been initialized by the va_start macro (and
16485     possibly subsequent va_arg calls). The vfwscanf function does not invoke the
16486     va_end macro.323)
16487     Returns
16488 3   The vfwscanf function returns the value of the macro EOF if an input failure occurs
16489     before the first conversion (if any) has completed. Otherwise, the vfwscanf function
16490     returns the number of input items assigned, which can be fewer than provided for, or even
16491     zero, in the event of an early matching failure.
16492     7.28.2.7 The vswprintf function
16493     Synopsis
16494 1          #include <stdarg.h>
16495            #include <wchar.h>
16496            int vswprintf(wchar_t * restrict s,
16497                 size_t n,
16498                 const wchar_t * restrict format,
16499                 va_list arg);
16500     Description
16501 2   The vswprintf function is equivalent to swprintf, with the variable argument list
16502     replaced by arg, which shall have been initialized by the va_start macro (and
16503     possibly subsequent va_arg calls). The vswprintf function does not invoke the
16504     va_end macro.323)
16505     Returns
16506 3   The vswprintf function returns the number of wide characters written in the array, not
16507     counting the terminating null wide character, or a negative value if an encoding error
16508     occurred or if n or more wide characters were requested to be generated.
16509
16510
16511 [page 414]
16512
16513     7.28.2.8 The vswscanf function
16514     Synopsis
16515 1           #include <stdarg.h>
16516             #include <wchar.h>
16517             int vswscanf(const wchar_t * restrict s,
16518                  const wchar_t * restrict format,
16519                  va_list arg);
16520     Description
16521 2   The vswscanf function is equivalent to swscanf, with the variable argument list
16522     replaced by arg, which shall have been initialized by the va_start macro (and
16523     possibly subsequent va_arg calls). The vswscanf function does not invoke the
16524     va_end macro.323)
16525     Returns
16526 3   The vswscanf function returns the value of the macro EOF if an input failure occurs
16527     before the first conversion (if any) has completed. Otherwise, the vswscanf function
16528     returns the number of input items assigned, which can be fewer than provided for, or even
16529     zero, in the event of an early matching failure.
16530     7.28.2.9 The vwprintf function
16531     Synopsis
16532 1           #include <stdarg.h>
16533             #include <wchar.h>
16534             int vwprintf(const wchar_t * restrict format,
16535                  va_list arg);
16536     Description
16537 2   The vwprintf function is equivalent to wprintf, with the variable argument list
16538     replaced by arg, which shall have been initialized by the va_start macro (and
16539     possibly subsequent va_arg calls). The vwprintf function does not invoke the
16540     va_end macro.323)
16541     Returns
16542 3   The vwprintf function returns the number of wide characters transmitted, or a negative
16543     value if an output or encoding error occurred.
16544
16545
16546
16547
16548 [page 415]
16549
16550     7.28.2.10 The vwscanf function
16551     Synopsis
16552 1          #include <stdarg.h>
16553            #include <wchar.h>
16554            int vwscanf(const wchar_t * restrict format,
16555                 va_list arg);
16556     Description
16557 2   The vwscanf function is equivalent to wscanf, with the variable argument list
16558     replaced by arg, which shall have been initialized by the va_start macro (and
16559     possibly subsequent va_arg calls). The vwscanf function does not invoke the
16560     va_end macro.323)
16561     Returns
16562 3   The vwscanf function returns the value of the macro EOF if an input failure occurs
16563     before the first conversion (if any) has completed. Otherwise, the vwscanf function
16564     returns the number of input items assigned, which can be fewer than provided for, or even
16565     zero, in the event of an early matching failure.
16566     7.28.2.11 The wprintf function
16567     Synopsis
16568 1          #include <wchar.h>
16569            int wprintf(const wchar_t * restrict format, ...);
16570     Description
16571 2   The wprintf function is equivalent to fwprintf with the argument stdout
16572     interposed before the arguments to wprintf.
16573     Returns
16574 3   The wprintf function returns the number of wide characters transmitted, or a negative
16575     value if an output or encoding error occurred.
16576     7.28.2.12 The wscanf function
16577     Synopsis
16578 1          #include <wchar.h>
16579            int wscanf(const wchar_t * restrict format, ...);
16580     Description
16581 2   The wscanf function is equivalent to fwscanf with the argument stdin interposed
16582     before the arguments to wscanf.
16583
16584
16585 [page 416]
16586
16587     Returns
16588 3   The wscanf function returns the value of the macro EOF if an input failure occurs
16589     before the first conversion (if any) has completed. Otherwise, the wscanf function
16590     returns the number of input items assigned, which can be fewer than provided for, or even
16591     zero, in the event of an early matching failure.
16592     7.28.3 Wide character input/output functions
16593     7.28.3.1 The fgetwc function
16594     Synopsis
16595 1           #include <stdio.h>
16596             #include <wchar.h>
16597             wint_t fgetwc(FILE *stream);
16598     Description
16599 2   If the end-of-file indicator for the input stream pointed to by stream is not set and a
16600     next wide character is present, the fgetwc function obtains that wide character as a
16601     wchar_t converted to a wint_t and advances the associated file position indicator for
16602     the stream (if defined).
16603     Returns
16604 3   If the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-
16605     of-file indicator for the stream is set and the fgetwc function returns WEOF. Otherwise,
16606     the fgetwc function returns the next wide character from the input stream pointed to by
16607     stream. If a read error occurs, the error indicator for the stream is set and the fgetwc
16608     function returns WEOF. If an encoding error occurs (including too few bytes), the value of
16609     the macro EILSEQ is stored in errno and the fgetwc function returns WEOF.324)
16610     7.28.3.2 The fgetws function
16611     Synopsis
16612 1           #include <stdio.h>
16613             #include <wchar.h>
16614             wchar_t *fgetws(wchar_t * restrict s,
16615                  int n, FILE * restrict stream);
16616     Description
16617 2   The fgetws function reads at most one less than the number of wide characters
16618     specified by n from the stream pointed to by stream into the array pointed to by s. No
16619
16620
16621     324) An end-of-file and a read error can be distinguished by use of the feof and ferror functions.
16622          Also, errno will be set to EILSEQ by input/output functions only if an encoding error occurs.
16623
16624 [page 417]
16625
16626     additional wide characters are read after a new-line wide character (which is retained) or
16627     after end-of-file. A null wide character is written immediately after the last wide
16628     character read into the array.
16629     Returns
16630 3   The fgetws function returns s if successful. If end-of-file is encountered and no
16631     characters have been read into the array, the contents of the array remain unchanged and a
16632     null pointer is returned. If a read or encoding error occurs during the operation, the array
16633     contents are indeterminate and a null pointer is returned.
16634     7.28.3.3 The fputwc function
16635     Synopsis
16636 1          #include <stdio.h>
16637            #include <wchar.h>
16638            wint_t fputwc(wchar_t c, FILE *stream);
16639     Description
16640 2   The fputwc function writes the wide character specified by c to the output stream
16641     pointed to by stream, at the position indicated by the associated file position indicator
16642     for the stream (if defined), and advances the indicator appropriately. If the file cannot
16643     support positioning requests, or if the stream was opened with append mode, the
16644     character is appended to the output stream.
16645     Returns
16646 3   The fputwc function returns the wide character written. If a write error occurs, the
16647     error indicator for the stream is set and fputwc returns WEOF. If an encoding error
16648     occurs, the value of the macro EILSEQ is stored in errno and fputwc returns WEOF.
16649     7.28.3.4 The fputws function
16650     Synopsis
16651 1          #include <stdio.h>
16652            #include <wchar.h>
16653            int fputws(const wchar_t * restrict s,
16654                 FILE * restrict stream);
16655     Description
16656 2   The fputws function writes the wide string pointed to by s to the stream pointed to by
16657     stream. The terminating null wide character is not written.
16658     Returns
16659 3   The fputws function returns EOF if a write or encoding error occurs; otherwise, it
16660     returns a nonnegative value.
16661
16662 [page 418]
16663
16664     7.28.3.5 The fwide function
16665     Synopsis
16666 1           #include <stdio.h>
16667             #include <wchar.h>
16668             int fwide(FILE *stream, int mode);
16669     Description
16670 2   The fwide function determines the orientation of the stream pointed to by stream. If
16671     mode is greater than zero, the function first attempts to make the stream wide oriented. If
16672     mode is less than zero, the function first attempts to make the stream byte oriented.325)
16673     Otherwise, mode is zero and the function does not alter the orientation of the stream.
16674     Returns
16675 3   The fwide function returns a value greater than zero if, after the call, the stream has
16676     wide orientation, a value less than zero if the stream has byte orientation, or zero if the
16677     stream has no orientation.
16678     7.28.3.6 The getwc function
16679     Synopsis
16680 1           #include <stdio.h>
16681             #include <wchar.h>
16682             wint_t getwc(FILE *stream);
16683     Description
16684 2   The getwc function is equivalent to fgetwc, except that if it is implemented as a
16685     macro, it may evaluate stream more than once, so the argument should never be an
16686     expression with side effects.
16687     Returns
16688 3   The getwc function returns the next wide character from the input stream pointed to by
16689     stream, or WEOF.
16690     7.28.3.7 The getwchar function
16691     Synopsis
16692 1           #include <wchar.h>
16693             wint_t getwchar(void);
16694
16695
16696
16697
16698     325) If the orientation of the stream has already been determined, fwide does not change it.
16699
16700 [page 419]
16701
16702     Description
16703 2   The getwchar function is equivalent to getwc with the argument stdin.
16704     Returns
16705 3   The getwchar function returns the next wide character from the input stream pointed to
16706     by stdin, or WEOF.
16707     7.28.3.8 The putwc function
16708     Synopsis
16709 1          #include <stdio.h>
16710            #include <wchar.h>
16711            wint_t putwc(wchar_t c, FILE *stream);
16712     Description
16713 2   The putwc function is equivalent to fputwc, except that if it is implemented as a
16714     macro, it may evaluate stream more than once, so that argument should never be an
16715     expression with side effects.
16716     Returns
16717 3   The putwc function returns the wide character written, or WEOF.
16718     7.28.3.9 The putwchar function
16719     Synopsis
16720 1          #include <wchar.h>
16721            wint_t putwchar(wchar_t c);
16722     Description
16723 2   The putwchar function is equivalent to putwc with the second argument stdout.
16724     Returns
16725 3   The putwchar function returns the character written, or WEOF.
16726     7.28.3.10 The ungetwc function
16727     Synopsis
16728 1          #include <stdio.h>
16729            #include <wchar.h>
16730            wint_t ungetwc(wint_t c, FILE *stream);
16731     Description
16732 2   The ungetwc function pushes the wide character specified by c back onto the input
16733     stream pointed to by stream. Pushed-back wide characters will be returned by
16734     subsequent reads on that stream in the reverse order of their pushing. A successful
16735
16736 [page 420]
16737
16738     intervening call (with the stream pointed to by stream) to a file positioning function
16739     (fseek, fsetpos, or rewind) discards any pushed-back wide characters for the
16740     stream. The external storage corresponding to the stream is unchanged.
16741 3   One wide character of pushback is guaranteed, even if the call to the ungetwc function
16742     follows just after a call to a formatted wide character input function fwscanf,
16743     vfwscanf, vwscanf, or wscanf. If the ungetwc function is called too many times
16744     on the same stream without an intervening read or file positioning operation on that
16745     stream, the operation may fail.
16746 4   If the value of c equals that of the macro WEOF, the operation fails and the input stream is
16747     unchanged.
16748 5   A successful call to the ungetwc function clears the end-of-file indicator for the stream.
16749     The value of the file position indicator for the stream after reading or discarding all
16750     pushed-back wide characters is the same as it was before the wide characters were pushed
16751     back. For a text or binary stream, the value of its file position indicator after a successful
16752     call to the ungetwc function is unspecified until all pushed-back wide characters are
16753     read or discarded.
16754     Returns
16755 6   The ungetwc function returns the wide character pushed back, or WEOF if the operation
16756     fails.
16757     7.28.4 General wide string utilities
16758 1   The header <wchar.h> declares a number of functions useful for wide string
16759     manipulation. Various methods are used for determining the lengths of the arrays, but in
16760     all cases a wchar_t * argument points to the initial (lowest addressed) element of the
16761     array. If an array is accessed beyond the end of an object, the behavior is undefined.
16762 2   Where an argument declared as size_t n determines the length of the array for a
16763     function, n can have the value zero on a call to that function. Unless explicitly stated
16764     otherwise in the description of a particular function in this subclause, pointer arguments
16765     on such a call shall still have valid values, as described in 7.1.4. On such a call, a
16766     function that locates a wide character finds no occurrence, a function that compares two
16767     wide character sequences returns zero, and a function that copies wide characters copies
16768     zero wide characters.
16769
16770
16771
16772
16773 [page 421]
16774
16775     7.28.4.1 Wide string numeric conversion functions
16776     7.28.4.1.1 The wcstod, wcstof, and wcstold functions
16777     Synopsis
16778 1          #include <wchar.h>
16779            double wcstod(const wchar_t * restrict nptr,
16780                 wchar_t ** restrict endptr);
16781            float wcstof(const wchar_t * restrict nptr,
16782                 wchar_t ** restrict endptr);
16783            long double wcstold(const wchar_t * restrict nptr,
16784                 wchar_t ** restrict endptr);
16785     Description
16786 2   The wcstod, wcstof, and wcstold functions convert the initial portion of the wide
16787     string pointed to by nptr to double, float, and long double representation,
16788     respectively. First, they decompose the input string into three parts: an initial, possibly
16789     empty, sequence of white-space wide characters (as specified by the iswspace
16790     function), a subject sequence resembling a floating-point constant or representing an
16791     infinity or NaN; and a final wide string of one or more unrecognized wide characters,
16792     including the terminating null wide character of the input wide string. Then, they attempt
16793     to convert the subject sequence to a floating-point number, and return the result.
16794 3   The expected form of the subject sequence is an optional plus or minus sign, then one of
16795     the following:
16796     -- a nonempty sequence of decimal digits optionally containing a decimal-point wide
16797       character, then an optional exponent part as defined for the corresponding single-byte
16798       characters in 6.4.4.2;
16799     -- a 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing a
16800       decimal-point wide character, then an optional binary exponent part as defined in
16801       6.4.4.2;
16802     -- INF or INFINITY, or any other wide string equivalent except for case
16803     -- NAN or NAN(n-wchar-sequenceopt), or any other wide string equivalent except for
16804       case in the NAN part, where:
16805                n-wchar-sequence:
16806                      digit
16807                      nondigit
16808                      n-wchar-sequence digit
16809                      n-wchar-sequence nondigit
16810     The subject sequence is defined as the longest initial subsequence of the input wide
16811     string, starting with the first non-white-space wide character, that is of the expected form.
16812 [page 422]
16813
16814     The subject sequence contains no wide characters if the input wide string is not of the
16815     expected form.
16816 4   If the subject sequence has the expected form for a floating-point number, the sequence of
16817     wide characters starting with the first digit or the decimal-point wide character
16818     (whichever occurs first) is interpreted as a floating constant according to the rules of
16819     6.4.4.2, except that the decimal-point wide character is used in place of a period, and that
16820     if neither an exponent part nor a decimal-point wide character appears in a decimal
16821     floating point number, or if a binary exponent part does not appear in a hexadecimal
16822     floating point number, an exponent part of the appropriate type with value zero is
16823     assumed to follow the last digit in the string. If the subject sequence begins with a minus
16824     sign, the sequence is interpreted as negated.326) A wide character sequence INF or
16825     INFINITY is interpreted as an infinity, if representable in the return type, else like a
16826     floating constant that is too large for the range of the return type. A wide character
16827     sequence NAN or NAN(n-wchar-sequenceopt) is interpreted as a quiet NaN, if supported
16828     in the return type, else like a subject sequence part that does not have the expected form;
16829     the meaning of the n-wchar sequences is implementation-defined.327) A pointer to the
16830     final wide string is stored in the object pointed to by endptr, provided that endptr is
16831     not a null pointer.
16832 5   If the subject sequence has the hexadecimal form and FLT_RADIX is a power of 2, the
16833     value resulting from the conversion is correctly rounded.
16834 6   In other than the "C" locale, additional locale-specific subject sequence forms may be
16835     accepted.
16836 7   If the subject sequence is empty or does not have the expected form, no conversion is
16837     performed; the value of nptr is stored in the object pointed to by endptr, provided
16838     that endptr is not a null pointer.
16839     Recommended practice
16840 8   If the subject sequence has the hexadecimal form, FLT_RADIX is not a power of 2, and
16841     the result is not exactly representable, the result should be one of the two numbers in the
16842     appropriate internal format that are adjacent to the hexadecimal floating source value,
16843     with the extra stipulation that the error should have a correct sign for the current rounding
16844     direction.
16845
16846
16847
16848     326) It is unspecified whether a minus-signed sequence is converted to a negative number directly or by
16849          negating the value resulting from converting the corresponding unsigned sequence (see F.5); the two
16850          methods may yield different results if rounding is toward positive or negative infinity. In either case,
16851          the functions honor the sign of zero if floating-point arithmetic supports signed zeros.
16852     327) An implementation may use the n-wchar sequence to determine extra information to be represented in
16853          the NaN's significand.
16854
16855 [page 423]
16856
16857 9    If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in
16858      <float.h>) significant digits, the result should be correctly rounded. If the subject
16859      sequence D has the decimal form and more than DECIMAL_DIG significant digits,
16860      consider the two bounding, adjacent decimal strings L and U, both having
16861      DECIMAL_DIG significant digits, such that the values of L, D, and U satisfy L <= D <= U.
16862      The result should be one of the (equal or adjacent) values that would be obtained by
16863      correctly rounding L and U according to the current rounding direction, with the extra
16864      stipulation that the error with respect to D should have a correct sign for the current
16865      rounding direction.328)
16866      Returns
16867 10   The functions return the converted value, if any. If no conversion could be performed,
16868      zero is returned. If the correct value overflows and default rounding is in effect (7.12.1),
16869      plus or minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the
16870      return type and sign of the value), and the value of the macro ERANGE is stored in
16871      errno. If the result underflows (7.12.1), the functions return a value whose magnitude is
16872      no greater than the smallest normalized positive number in the return type; whether
16873      errno acquires the value ERANGE is implementation-defined.
16874
16875
16876
16877
16878      328) DECIMAL_DIG, defined in <float.h>, should be sufficiently large that L and U will usually round
16879           to the same internal floating value, but if not will round to adjacent values.
16880
16881 [page 424]
16882
16883     7.28.4.1.2 The wcstol, wcstoll, wcstoul, and wcstoull functions
16884     Synopsis
16885 1           #include <wchar.h>
16886             long int wcstol(
16887                  const wchar_t * restrict nptr,
16888                  wchar_t ** restrict endptr,
16889                  int base);
16890             long long int wcstoll(
16891                  const wchar_t * restrict nptr,
16892                  wchar_t ** restrict endptr,
16893                  int base);
16894             unsigned long int wcstoul(
16895                  const wchar_t * restrict nptr,
16896                  wchar_t ** restrict endptr,
16897                  int base);
16898             unsigned long long int wcstoull(
16899                  const wchar_t * restrict nptr,
16900                  wchar_t ** restrict endptr,
16901                  int base);
16902     Description
16903 2   The wcstol, wcstoll, wcstoul, and wcstoull functions convert the initial
16904     portion of the wide string pointed to by nptr to long int, long long int,
16905     unsigned long int, and unsigned long long int representation,
16906     respectively. First, they decompose the input string into three parts: an initial, possibly
16907     empty, sequence of white-space wide characters (as specified by the iswspace
16908     function), a subject sequence resembling an integer represented in some radix determined
16909     by the value of base, and a final wide string of one or more unrecognized wide
16910     characters, including the terminating null wide character of the input wide string. Then,
16911     they attempt to convert the subject sequence to an integer, and return the result.
16912 3   If the value of base is zero, the expected form of the subject sequence is that of an
16913     integer constant as described for the corresponding single-byte characters in 6.4.4.1,
16914     optionally preceded by a plus or minus sign, but not including an integer suffix. If the
16915     value of base is between 2 and 36 (inclusive), the expected form of the subject sequence
16916     is a sequence of letters and digits representing an integer with the radix specified by
16917     base, optionally preceded by a plus or minus sign, but not including an integer suffix.
16918     The letters from a (or A) through z (or Z) are ascribed the values 10 through 35; only
16919     letters and digits whose ascribed values are less than that of base are permitted. If the
16920     value of base is 16, the wide characters 0x or 0X may optionally precede the sequence
16921     of letters and digits, following the sign if present.
16922
16923 [page 425]
16924
16925 4   The subject sequence is defined as the longest initial subsequence of the input wide
16926     string, starting with the first non-white-space wide character, that is of the expected form.
16927     The subject sequence contains no wide characters if the input wide string is empty or
16928     consists entirely of white space, or if the first non-white-space wide character is other
16929     than a sign or a permissible letter or digit.
16930 5   If the subject sequence has the expected form and the value of base is zero, the sequence
16931     of wide characters starting with the first digit is interpreted as an integer constant
16932     according to the rules of 6.4.4.1. If the subject sequence has the expected form and the
16933     value of base is between 2 and 36, it is used as the base for conversion, ascribing to each
16934     letter its value as given above. If the subject sequence begins with a minus sign, the value
16935     resulting from the conversion is negated (in the return type). A pointer to the final wide
16936     string is stored in the object pointed to by endptr, provided that endptr is not a null
16937     pointer.
16938 6   In other than the "C" locale, additional locale-specific subject sequence forms may be
16939     accepted.
16940 7   If the subject sequence is empty or does not have the expected form, no conversion is
16941     performed; the value of nptr is stored in the object pointed to by endptr, provided
16942     that endptr is not a null pointer.
16943     Returns
16944 8   The wcstol, wcstoll, wcstoul, and wcstoull functions return the converted
16945     value, if any. If no conversion could be performed, zero is returned. If the correct value
16946     is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
16947     LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type
16948     sign of the value, if any), and the value of the macro ERANGE is stored in errno.
16949     7.28.4.2 Wide string copying functions
16950     7.28.4.2.1 The wcscpy function
16951     Synopsis
16952 1          #include <wchar.h>
16953            wchar_t *wcscpy(wchar_t * restrict s1,
16954                 const wchar_t * restrict s2);
16955     Description
16956 2   The wcscpy function copies the wide string pointed to by s2 (including the terminating
16957     null wide character) into the array pointed to by s1.
16958     Returns
16959 3   The wcscpy function returns the value of s1.
16960
16961
16962 [page 426]
16963
16964     7.28.4.2.2 The wcsncpy function
16965     Synopsis
16966 1            #include <wchar.h>
16967              wchar_t *wcsncpy(wchar_t * restrict s1,
16968                   const wchar_t * restrict s2,
16969                   size_t n);
16970     Description
16971 2   The wcsncpy function copies not more than n wide characters (those that follow a null
16972     wide character are not copied) from the array pointed to by s2 to the array pointed to by
16973     s1.329)
16974 3   If the array pointed to by s2 is a wide string that is shorter than n wide characters, null
16975     wide characters are appended to the copy in the array pointed to by s1, until n wide
16976     characters in all have been written.
16977     Returns
16978 4   The wcsncpy function returns the value of s1.
16979     7.28.4.2.3 The wmemcpy function
16980     Synopsis
16981 1            #include <wchar.h>
16982              wchar_t *wmemcpy(wchar_t * restrict s1,
16983                   const wchar_t * restrict s2,
16984                   size_t n);
16985     Description
16986 2   The wmemcpy function copies n wide characters from the object pointed to by s2 to the
16987     object pointed to by s1.
16988     Returns
16989 3   The wmemcpy function returns the value of s1.
16990
16991
16992
16993
16994     329) Thus, if there is no null wide character in the first n wide characters of the array pointed to by s2, the
16995          result will not be null-terminated.
16996
16997 [page 427]
16998
16999     7.28.4.2.4 The wmemmove function
17000     Synopsis
17001 1          #include <wchar.h>
17002            wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2,
17003                 size_t n);
17004     Description
17005 2   The wmemmove function copies n wide characters from the object pointed to by s2 to
17006     the object pointed to by s1. Copying takes place as if the n wide characters from the
17007     object pointed to by s2 are first copied into a temporary array of n wide characters that
17008     does not overlap the objects pointed to by s1 or s2, and then the n wide characters from
17009     the temporary array are copied into the object pointed to by s1.
17010     Returns
17011 3   The wmemmove function returns the value of s1.
17012     7.28.4.3 Wide string concatenation functions
17013     7.28.4.3.1 The wcscat function
17014     Synopsis
17015 1          #include <wchar.h>
17016            wchar_t *wcscat(wchar_t * restrict s1,
17017                 const wchar_t * restrict s2);
17018     Description
17019 2   The wcscat function appends a copy of the wide string pointed to by s2 (including the
17020     terminating null wide character) to the end of the wide string pointed to by s1. The initial
17021     wide character of s2 overwrites the null wide character at the end of s1.
17022     Returns
17023 3   The wcscat function returns the value of s1.
17024     7.28.4.3.2 The wcsncat function
17025     Synopsis
17026 1          #include <wchar.h>
17027            wchar_t *wcsncat(wchar_t * restrict s1,
17028                 const wchar_t * restrict s2,
17029                 size_t n);
17030     Description
17031 2   The wcsncat function appends not more than n wide characters (a null wide character
17032     and those that follow it are not appended) from the array pointed to by s2 to the end of
17033
17034 [page 428]
17035
17036     the wide string pointed to by s1. The initial wide character of s2 overwrites the null
17037     wide character at the end of s1. A terminating null wide character is always appended to
17038     the result.330)
17039     Returns
17040 3   The wcsncat function returns the value of s1.
17041     7.28.4.4 Wide string comparison functions
17042 1   Unless explicitly stated otherwise, the functions described in this subclause order two
17043     wide characters the same way as two integers of the underlying integer type designated
17044     by wchar_t.
17045     7.28.4.4.1 The wcscmp function
17046     Synopsis
17047 1           #include <wchar.h>
17048             int wcscmp(const wchar_t *s1, const wchar_t *s2);
17049     Description
17050 2   The wcscmp function compares the wide string pointed to by s1 to the wide string
17051     pointed to by s2.
17052     Returns
17053 3   The wcscmp function returns an integer greater than, equal to, or less than zero,
17054     accordingly as the wide string pointed to by s1 is greater than, equal to, or less than the
17055     wide string pointed to by s2.
17056     7.28.4.4.2 The wcscoll function
17057     Synopsis
17058 1           #include <wchar.h>
17059             int wcscoll(const wchar_t *s1, const wchar_t *s2);
17060     Description
17061 2   The wcscoll function compares the wide string pointed to by s1 to the wide string
17062     pointed to by s2, both interpreted as appropriate to the LC_COLLATE category of the
17063     current locale.
17064     Returns
17065 3   The wcscoll function returns an integer greater than, equal to, or less than zero,
17066     accordingly as the wide string pointed to by s1 is greater than, equal to, or less than the
17067
17068
17069     330) Thus, the maximum number of wide characters that can end up in the array pointed to by s1 is
17070          wcslen(s1)+n+1.
17071
17072 [page 429]
17073
17074     wide string pointed to by s2 when both are interpreted as appropriate to the current
17075     locale.
17076     7.28.4.4.3 The wcsncmp function
17077     Synopsis
17078 1          #include <wchar.h>
17079            int wcsncmp(const wchar_t *s1, const wchar_t *s2,
17080                 size_t n);
17081     Description
17082 2   The wcsncmp function compares not more than n wide characters (those that follow a
17083     null wide character are not compared) from the array pointed to by s1 to the array
17084     pointed to by s2.
17085     Returns
17086 3   The wcsncmp function returns an integer greater than, equal to, or less than zero,
17087     accordingly as the possibly null-terminated array pointed to by s1 is greater than, equal
17088     to, or less than the possibly null-terminated array pointed to by s2.
17089     7.28.4.4.4 The wcsxfrm function
17090     Synopsis
17091 1          #include <wchar.h>
17092            size_t wcsxfrm(wchar_t * restrict s1,
17093                 const wchar_t * restrict s2,
17094                 size_t n);
17095     Description
17096 2   The wcsxfrm function transforms the wide string pointed to by s2 and places the
17097     resulting wide string into the array pointed to by s1. The transformation is such that if
17098     the wcscmp function is applied to two transformed wide strings, it returns a value greater
17099     than, equal to, or less than zero, corresponding to the result of the wcscoll function
17100     applied to the same two original wide strings. No more than n wide characters are placed
17101     into the resulting array pointed to by s1, including the terminating null wide character. If
17102     n is zero, s1 is permitted to be a null pointer.
17103     Returns
17104 3   The wcsxfrm function returns the length of the transformed wide string (not including
17105     the terminating null wide character). If the value returned is n or greater, the contents of
17106     the array pointed to by s1 are indeterminate.
17107 4   EXAMPLE The value of the following expression is the length of the array needed to hold the
17108     transformation of the wide string pointed to by s:
17109
17110
17111 [page 430]
17112
17113             1 + wcsxfrm(NULL, s, 0)
17114
17115     7.28.4.4.5 The wmemcmp function
17116     Synopsis
17117 1           #include <wchar.h>
17118             int wmemcmp(const wchar_t *s1, const wchar_t *s2,
17119                  size_t n);
17120     Description
17121 2   The wmemcmp function compares the first n wide characters of the object pointed to by
17122     s1 to the first n wide characters of the object pointed to by s2.
17123     Returns
17124 3   The wmemcmp function returns an integer greater than, equal to, or less than zero,
17125     accordingly as the object pointed to by s1 is greater than, equal to, or less than the object
17126     pointed to by s2.
17127     7.28.4.5 Wide string search functions
17128     7.28.4.5.1 The wcschr function
17129     Synopsis
17130 1           #include <wchar.h>
17131             wchar_t *wcschr(const wchar_t *s, wchar_t c);
17132     Description
17133 2   The wcschr function locates the first occurrence of c in the wide string pointed to by s.
17134     The terminating null wide character is considered to be part of the wide string.
17135     Returns
17136 3   The wcschr function returns a pointer to the located wide character, or a null pointer if
17137     the wide character does not occur in the wide string.
17138     7.28.4.5.2 The wcscspn function
17139     Synopsis
17140 1           #include <wchar.h>
17141             size_t wcscspn(const wchar_t *s1, const wchar_t *s2);
17142     Description
17143 2   The wcscspn function computes the length of the maximum initial segment of the wide
17144     string pointed to by s1 which consists entirely of wide characters not from the wide
17145     string pointed to by s2.
17146
17147
17148
17149 [page 431]
17150
17151     Returns
17152 3   The wcscspn function returns the length of the segment.
17153     7.28.4.5.3 The wcspbrk function
17154     Synopsis
17155 1          #include <wchar.h>
17156            wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2);
17157     Description
17158 2   The wcspbrk function locates the first occurrence in the wide string pointed to by s1 of
17159     any wide character from the wide string pointed to by s2.
17160     Returns
17161 3   The wcspbrk function returns a pointer to the wide character in s1, or a null pointer if
17162     no wide character from s2 occurs in s1.
17163     7.28.4.5.4 The wcsrchr function
17164     Synopsis
17165 1          #include <wchar.h>
17166            wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
17167     Description
17168 2   The wcsrchr function locates the last occurrence of c in the wide string pointed to by
17169     s. The terminating null wide character is considered to be part of the wide string.
17170     Returns
17171 3   The wcsrchr function returns a pointer to the wide character, or a null pointer if c does
17172     not occur in the wide string.
17173     7.28.4.5.5 The wcsspn function
17174     Synopsis
17175 1          #include <wchar.h>
17176            size_t wcsspn(const wchar_t *s1, const wchar_t *s2);
17177     Description
17178 2   The wcsspn function computes the length of the maximum initial segment of the wide
17179     string pointed to by s1 which consists entirely of wide characters from the wide string
17180     pointed to by s2.
17181     Returns
17182 3   The wcsspn function returns the length of the segment.
17183
17184
17185 [page 432]
17186
17187     7.28.4.5.6 The wcsstr function
17188     Synopsis
17189 1           #include <wchar.h>
17190             wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);
17191     Description
17192 2   The wcsstr function locates the first occurrence in the wide string pointed to by s1 of
17193     the sequence of wide characters (excluding the terminating null wide character) in the
17194     wide string pointed to by s2.
17195     Returns
17196 3   The wcsstr function returns a pointer to the located wide string, or a null pointer if the
17197     wide string is not found. If s2 points to a wide string with zero length, the function
17198     returns s1.
17199     7.28.4.5.7 The wcstok function
17200     Synopsis
17201 1           #include <wchar.h>
17202             wchar_t *wcstok(wchar_t * restrict s1,
17203                  const wchar_t * restrict s2,
17204                  wchar_t ** restrict ptr);
17205     Description
17206 2   A sequence of calls to the wcstok function breaks the wide string pointed to by s1 into
17207     a sequence of tokens, each of which is delimited by a wide character from the wide string
17208     pointed to by s2. The third argument points to a caller-provided wchar_t pointer into
17209     which the wcstok function stores information necessary for it to continue scanning the
17210     same wide string.
17211 3   The first call in a sequence has a non-null first argument and stores an initial value in the
17212     object pointed to by ptr. Subsequent calls in the sequence have a null first argument and
17213     the object pointed to by ptr is required to have the value stored by the previous call in
17214     the sequence, which is then updated. The separator wide string pointed to by s2 may be
17215     different from call to call.
17216 4   The first call in the sequence searches the wide string pointed to by s1 for the first wide
17217     character that is not contained in the current separator wide string pointed to by s2. If no
17218     such wide character is found, then there are no tokens in the wide string pointed to by s1
17219     and the wcstok function returns a null pointer. If such a wide character is found, it is
17220     the start of the first token.
17221 5   The wcstok function then searches from there for a wide character that is contained in
17222     the current separator wide string. If no such wide character is found, the current token
17223 [page 433]
17224
17225     extends to the end of the wide string pointed to by s1, and subsequent searches in the
17226     same wide string for a token return a null pointer. If such a wide character is found, it is
17227     overwritten by a null wide character, which terminates the current token.
17228 6   In all cases, the wcstok function stores sufficient information in the pointer pointed to
17229     by ptr so that subsequent calls, with a null pointer for s1 and the unmodified pointer
17230     value for ptr, shall start searching just past the element overwritten by a null wide
17231     character (if any).
17232     Returns
17233 7   The wcstok function returns a pointer to the first wide character of a token, or a null
17234     pointer if there is no token.
17235 8   EXAMPLE
17236            #include <wchar.h>
17237            static wchar_t str1[] = L"?a???b,,,#c";
17238            static wchar_t str2[] = L"\t \t";
17239            wchar_t *t, *ptr1, *ptr2;
17240            t   =   wcstok(str1,   L"?", &ptr1);          //   t   points to the token L"a"
17241            t   =   wcstok(NULL,   L",", &ptr1);          //   t   points to the token L"??b"
17242            t   =   wcstok(str2,   L" \t", &ptr2);        //   t   is a null pointer
17243            t   =   wcstok(NULL,   L"#,", &ptr1);         //   t   points to the token L"c"
17244            t   =   wcstok(NULL,   L"?", &ptr1);          //   t   is a null pointer
17245
17246     7.28.4.5.8 The wmemchr function
17247     Synopsis
17248 1          #include <wchar.h>
17249            wchar_t *wmemchr(const wchar_t *s, wchar_t c,
17250                 size_t n);
17251     Description
17252 2   The wmemchr function locates the first occurrence of c in the initial n wide characters of
17253     the object pointed to by s.
17254     Returns
17255 3   The wmemchr function returns a pointer to the located wide character, or a null pointer if
17256     the wide character does not occur in the object.
17257
17258
17259
17260
17261 [page 434]
17262
17263     7.28.4.6 Miscellaneous functions
17264     7.28.4.6.1 The wcslen function
17265     Synopsis
17266 1           #include <wchar.h>
17267             size_t wcslen(const wchar_t *s);
17268     Description
17269 2   The wcslen function computes the length of the wide string pointed to by s.
17270     Returns
17271 3   The wcslen function returns the number of wide characters that precede the terminating
17272     null wide character.
17273     7.28.4.6.2 The wmemset function
17274     Synopsis
17275 1           #include <wchar.h>
17276             wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);
17277     Description
17278 2   The wmemset function copies the value of c into each of the first n wide characters of
17279     the object pointed to by s.
17280     Returns
17281 3   The wmemset function returns the value of s.
17282     7.28.5 Wide character time conversion functions
17283     7.28.5.1 The wcsftime function
17284     Synopsis
17285 1           #include <time.h>
17286             #include <wchar.h>
17287             size_t wcsftime(wchar_t * restrict s,
17288                  size_t maxsize,
17289                  const wchar_t * restrict format,
17290                  const struct tm * restrict timeptr);
17291     Description
17292 2   The wcsftime function is equivalent to the strftime function, except that:
17293     -- The argument s points to the initial element of an array of wide characters into which
17294       the generated output is to be placed.
17295
17296
17297 [page 435]
17298
17299     -- The argument maxsize indicates the limiting number of wide characters.
17300     -- The argument format is a wide string and the conversion specifiers are replaced by
17301       corresponding sequences of wide characters.
17302     -- The return value indicates the number of wide characters.
17303     Returns
17304 3   If the total number of resulting wide characters including the terminating null wide
17305     character is not more than maxsize, the wcsftime function returns the number of
17306     wide characters placed into the array pointed to by s not including the terminating null
17307     wide character. Otherwise, zero is returned and the contents of the array are
17308     indeterminate.
17309     7.28.6 Extended multibyte/wide character conversion utilities
17310 1   The header <wchar.h> declares an extended set of functions useful for conversion
17311     between multibyte characters and wide characters.
17312 2   Most of the following functions -- those that are listed as ''restartable'', 7.28.6.3 and
17313     7.28.6.4 -- take as a last argument a pointer to an object of type mbstate_t that is used
17314     to describe the current conversion state from a particular multibyte character sequence to
17315     a wide character sequence (or the reverse) under the rules of a particular setting for the
17316     LC_CTYPE category of the current locale.
17317 3   The initial conversion state corresponds, for a conversion in either direction, to the
17318     beginning of a new multibyte character in the initial shift state. A zero-valued
17319     mbstate_t object is (at least) one way to describe an initial conversion state. A zero-
17320     valued mbstate_t object can be used to initiate conversion involving any multibyte
17321     character sequence, in any LC_CTYPE category setting. If an mbstate_t object has
17322     been altered by any of the functions described in this subclause, and is then used with a
17323     different multibyte character sequence, or in the other conversion direction, or with a
17324     different LC_CTYPE category setting than on earlier function calls, the behavior is
17325     undefined.331)
17326 4   On entry, each function takes the described conversion state (either internal or pointed to
17327     by an argument) as current. The conversion state described by the referenced object is
17328     altered as needed to track the shift state, and the position within a multibyte character, for
17329     the associated multibyte character sequence.
17330
17331
17332
17333
17334     331) Thus, a particular mbstate_t object can be used, for example, with both the mbrtowc and
17335          mbsrtowcs functions as long as they are used to step sequentially through the same multibyte
17336          character string.
17337
17338 [page 436]
17339
17340     7.28.6.1 Single-byte/wide character conversion functions
17341     7.28.6.1.1 The btowc function
17342     Synopsis
17343 1           #include <wchar.h>                                                                       *
17344             wint_t btowc(int c);
17345     Description
17346 2   The btowc function determines whether c constitutes a valid single-byte character in the
17347     initial shift state.
17348     Returns
17349 3   The btowc function returns WEOF if c has the value EOF or if (unsigned char)c
17350     does not constitute a valid single-byte character in the initial shift state. Otherwise, it
17351     returns the wide character representation of that character.
17352     7.28.6.1.2 The wctob function
17353     Synopsis
17354 1           #include <wchar.h>                                                                       *
17355             int wctob(wint_t c);
17356     Description
17357 2   The wctob function determines whether c corresponds to a member of the extended
17358     character set whose multibyte character representation is a single byte when in the initial
17359     shift state.
17360     Returns
17361 3   The wctob function returns EOF if c does not correspond to a multibyte character with
17362     length one in the initial shift state. Otherwise, it returns the single-byte representation of
17363     that character as an unsigned char converted to an int.
17364     7.28.6.2 Conversion state functions
17365     7.28.6.2.1 The mbsinit function
17366     Synopsis
17367 1           #include <wchar.h>
17368             int mbsinit(const mbstate_t *ps);
17369     Description
17370 2   If ps is not a null pointer, the mbsinit function determines whether the referenced
17371     mbstate_t object describes an initial conversion state.
17372
17373
17374
17375 [page 437]
17376
17377     Returns
17378 3   The mbsinit function returns nonzero if ps is a null pointer or if the referenced object
17379     describes an initial conversion state; otherwise, it returns zero.
17380     7.28.6.3 Restartable multibyte/wide character conversion functions
17381 1   These functions differ from the corresponding multibyte character functions of 7.22.7
17382     (mblen, mbtowc, and wctomb) in that they have an extra parameter, ps, of type
17383     pointer to mbstate_t that points to an object that can completely describe the current
17384     conversion state of the associated multibyte character sequence. If ps is a null pointer,
17385     each function uses its own internal mbstate_t object instead, which is initialized at
17386     program startup to the initial conversion state; the functions are not required to avoid data
17387     races in this case. The implementation behaves as if no library function calls these
17388     functions with a null pointer for ps.
17389 2   Also unlike their corresponding functions, the return value does not represent whether the
17390     encoding is state-dependent.
17391     7.28.6.3.1 The mbrlen function
17392     Synopsis
17393 1          #include <wchar.h>
17394            size_t mbrlen(const char * restrict s,
17395                 size_t n,
17396                 mbstate_t * restrict ps);
17397     Description
17398 2   The mbrlen function is equivalent to the call:
17399            mbrtowc(NULL, s, n, ps != NULL ? ps : &internal)
17400     where internal is the mbstate_t object for the mbrlen function, except that the
17401     expression designated by ps is evaluated only once.
17402     Returns
17403 3   The mbrlen function returns a value between zero and n, inclusive, (size_t)(-2),
17404     or (size_t)(-1).
17405     Forward references: the mbrtowc function (7.28.6.3.2).
17406
17407
17408
17409
17410 [page 438]
17411
17412     7.28.6.3.2 The mbrtowc function
17413     Synopsis
17414 1           #include <wchar.h>
17415             size_t mbrtowc(wchar_t * restrict pwc,
17416                  const char * restrict s,
17417                  size_t n,
17418                  mbstate_t * restrict ps);
17419     Description
17420 2   If s is a null pointer, the mbrtowc function is equivalent to the call:
17421                     mbrtowc(NULL, "", 1, ps)
17422     In this case, the values of the parameters pwc and n are ignored.
17423 3   If s is not a null pointer, the mbrtowc function inspects at most n bytes beginning with
17424     the byte pointed to by s to determine the number of bytes needed to complete the next
17425     multibyte character (including any shift sequences). If the function determines that the
17426     next multibyte character is complete and valid, it determines the value of the
17427     corresponding wide character and then, if pwc is not a null pointer, stores that value in
17428     the object pointed to by pwc. If the corresponding wide character is the null wide
17429     character, the resulting state described is the initial conversion state.
17430     Returns
17431 4   The mbrtowc function returns the first of the following that applies (given the current
17432     conversion state):
17433     0                     if the next n or fewer bytes complete the multibyte character that
17434                           corresponds to the null wide character (which is the value stored).
17435     between 1 and n inclusive if the next n or fewer bytes complete a valid multibyte
17436                        character (which is the value stored); the value returned is the number
17437                        of bytes that complete the multibyte character.
17438     (size_t)(-2) if the next n bytes contribute to an incomplete (but potentially valid)
17439                  multibyte character, and all n bytes have been processed (no value is
17440                  stored).332)
17441     (size_t)(-1) if an encoding error occurs, in which case the next n or fewer bytes
17442                  do not contribute to a complete and valid multibyte character (no
17443                  value is stored); the value of the macro EILSEQ is stored in errno,
17444                  and the conversion state is unspecified.
17445
17446     332) When n has at least the value of the MB_CUR_MAX macro, this case can only occur if s points at a
17447          sequence of redundant shift sequences (for implementations with state-dependent encodings).
17448
17449 [page 439]
17450
17451     7.28.6.3.3 The wcrtomb function
17452     Synopsis
17453 1           #include <wchar.h>
17454             size_t wcrtomb(char * restrict s,
17455                  wchar_t wc,
17456                  mbstate_t * restrict ps);
17457     Description
17458 2   If s is a null pointer, the wcrtomb function is equivalent to the call
17459                     wcrtomb(buf, L'\0', ps)
17460     where buf is an internal buffer.
17461 3   If s is not a null pointer, the wcrtomb function determines the number of bytes needed
17462     to represent the multibyte character that corresponds to the wide character given by wc
17463     (including any shift sequences), and stores the multibyte character representation in the
17464     array whose first element is pointed to by s. At most MB_CUR_MAX bytes are stored. If
17465     wc is a null wide character, a null byte is stored, preceded by any shift sequence needed
17466     to restore the initial shift state; the resulting state described is the initial conversion state.
17467     Returns
17468 4   The wcrtomb function returns the number of bytes stored in the array object (including
17469     any shift sequences). When wc is not a valid wide character, an encoding error occurs:
17470     the function stores the value of the macro EILSEQ in errno and returns
17471     (size_t)(-1); the conversion state is unspecified.
17472     7.28.6.4 Restartable multibyte/wide string conversion functions
17473 1   These functions differ from the corresponding multibyte string functions of 7.22.8
17474     (mbstowcs and wcstombs) in that they have an extra parameter, ps, of type pointer to
17475     mbstate_t that points to an object that can completely describe the current conversion
17476     state of the associated multibyte character sequence. If ps is a null pointer, each function
17477     uses its own internal mbstate_t object instead, which is initialized at program startup
17478     to the initial conversion state; the functions are not required to avoid data races in this
17479     case. The implementation behaves as if no library function calls these functions with a
17480     null pointer for ps.
17481 2   Also unlike their corresponding functions, the conversion source parameter, src, has a
17482     pointer-to-pointer type. When the function is storing the results of conversions (that is,
17483     when dst is not a null pointer), the pointer object pointed to by this parameter is updated
17484     to reflect the amount of the source processed by that invocation.
17485
17486
17487
17488
17489 [page 440]
17490
17491     7.28.6.4.1 The mbsrtowcs function
17492     Synopsis
17493 1            #include <wchar.h>
17494              size_t mbsrtowcs(wchar_t * restrict dst,
17495                   const char ** restrict src,
17496                   size_t len,
17497                   mbstate_t * restrict ps);
17498     Description
17499 2   The mbsrtowcs function converts a sequence of multibyte characters that begins in the
17500     conversion state described by the object pointed to by ps, from the array indirectly
17501     pointed to by src into a sequence of corresponding wide characters. If dst is not a null
17502     pointer, the converted characters are stored into the array pointed to by dst. Conversion
17503     continues up to and including a terminating null character, which is also stored.
17504     Conversion stops earlier in two cases: when a sequence of bytes is encountered that does
17505     not form a valid multibyte character, or (if dst is not a null pointer) when len wide
17506     characters have been stored into the array pointed to by dst.333) Each conversion takes
17507     place as if by a call to the mbrtowc function.
17508 3   If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
17509     pointer (if conversion stopped due to reaching a terminating null character) or the address
17510     just past the last multibyte character converted (if any). If conversion stopped due to
17511     reaching a terminating null character and if dst is not a null pointer, the resulting state
17512     described is the initial conversion state.
17513     Returns
17514 4   If the input conversion encounters a sequence of bytes that do not form a valid multibyte
17515     character, an encoding error occurs: the mbsrtowcs function stores the value of the
17516     macro EILSEQ in errno and returns (size_t)(-1); the conversion state is
17517     unspecified. Otherwise, it returns the number of multibyte characters successfully
17518     converted, not including the terminating null character (if any).
17519
17520
17521
17522
17523     333) Thus, the value of len is ignored if dst is a null pointer.
17524
17525 [page 441]
17526
17527     7.28.6.4.2 The wcsrtombs function
17528     Synopsis
17529 1           #include <wchar.h>
17530             size_t wcsrtombs(char * restrict dst,
17531                  const wchar_t ** restrict src,
17532                  size_t len,
17533                  mbstate_t * restrict ps);
17534     Description
17535 2   The wcsrtombs function converts a sequence of wide characters from the array
17536     indirectly pointed to by src into a sequence of corresponding multibyte characters that
17537     begins in the conversion state described by the object pointed to by ps. If dst is not a
17538     null pointer, the converted characters are then stored into the array pointed to by dst.
17539     Conversion continues up to and including a terminating null wide character, which is also
17540     stored. Conversion stops earlier in two cases: when a wide character is reached that does
17541     not correspond to a valid multibyte character, or (if dst is not a null pointer) when the
17542     next multibyte character would exceed the limit of len total bytes to be stored into the
17543     array pointed to by dst. Each conversion takes place as if by a call to the wcrtomb
17544     function.334)
17545 3   If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
17546     pointer (if conversion stopped due to reaching a terminating null wide character) or the
17547     address just past the last wide character converted (if any). If conversion stopped due to
17548     reaching a terminating null wide character, the resulting state described is the initial
17549     conversion state.
17550     Returns
17551 4   If conversion stops because a wide character is reached that does not correspond to a
17552     valid multibyte character, an encoding error occurs: the wcsrtombs function stores the
17553     value of the macro EILSEQ in errno and returns (size_t)(-1); the conversion
17554     state is unspecified. Otherwise, it returns the number of bytes in the resulting multibyte
17555     character sequence, not including the terminating null character (if any).
17556
17557
17558
17559
17560     334) If conversion stops because a terminating null wide character has been reached, the bytes stored
17561          include those necessary to reach the initial shift state immediately before the null byte.
17562
17563 [page 442]
17564
17565     7.29 Wide character classification and mapping utilities <wctype.h>
17566     7.29.1 Introduction
17567 1   The header <wctype.h> defines one macro, and declares three data types and many
17568     functions.335)
17569 2   The types declared are
17570               wint_t
17571     described in 7.28.1;
17572               wctrans_t
17573     which is a scalar type that can hold values which represent locale-specific character
17574     mappings; and
17575               wctype_t
17576     which is a scalar type that can hold values which represent locale-specific character
17577     classifications.
17578 3   The macro defined is WEOF (described in 7.28.1).
17579 4   The functions declared are grouped as follows:
17580     -- Functions that provide wide character classification;
17581     -- Extensible functions that provide wide character classification;
17582     -- Functions that provide wide character case mapping;
17583     -- Extensible functions that provide wide character mapping.
17584 5   For all functions described in this subclause that accept an argument of type wint_t, the
17585     value shall be representable as a wchar_t or shall equal the value of the macro WEOF. If
17586     this argument has any other value, the behavior is undefined.
17587 6   The behavior of these functions is affected by the LC_CTYPE category of the current
17588     locale.
17589
17590
17591
17592
17593     335) See ''future library directions'' (7.30.13).
17594
17595 [page 443]
17596
17597     7.29.2 Wide character classification utilities
17598 1   The header <wctype.h> declares several functions useful for classifying wide
17599     characters.
17600 2   The term printing wide character refers to a member of a locale-specific set of wide
17601     characters, each of which occupies at least one printing position on a display device. The
17602     term control wide character refers to a member of a locale-specific set of wide characters
17603     that are not printing wide characters.
17604     7.29.2.1 Wide character classification functions
17605 1   The functions in this subclause return nonzero (true) if and only if the value of the
17606     argument wc conforms to that in the description of the function.
17607 2   Each of the following functions returns true for each wide character that corresponds (as
17608     if by a call to the wctob function) to a single-byte character for which the corresponding
17609     character classification function from 7.4.1 returns true, except that the iswgraph and
17610     iswpunct functions may differ with respect to wide characters other than L' ' that are
17611     both printing and white-space wide characters.336)
17612     Forward references: the wctob function (7.28.6.1.2).
17613     7.29.2.1.1 The iswalnum function
17614     Synopsis
17615 1           #include <wctype.h>
17616             int iswalnum(wint_t wc);
17617     Description
17618 2   The iswalnum function tests for any wide character for which iswalpha or
17619     iswdigit is true.
17620     7.29.2.1.2 The iswalpha function
17621     Synopsis
17622 1           #include <wctype.h>
17623             int iswalpha(wint_t wc);
17624     Description
17625 2   The iswalpha function tests for any wide character for which iswupper or
17626     iswlower is true, or any wide character that is one of a locale-specific set of alphabetic
17627
17628     336) For example, if the expression isalpha(wctob(wc)) evaluates to true, then the call
17629          iswalpha(wc) also returns true. But, if the expression isgraph(wctob(wc)) evaluates to true
17630          (which cannot occur for wc == L' ' of course), then either iswgraph(wc) or iswprint(wc)
17631          && iswspace(wc) is true, but not both.
17632
17633 [page 444]
17634
17635     wide characters for which none of iswcntrl, iswdigit, iswpunct, or iswspace
17636     is true.337)
17637     7.29.2.1.3 The iswblank function
17638     Synopsis
17639 1           #include <wctype.h>
17640             int iswblank(wint_t wc);
17641     Description
17642 2   The iswblank function tests for any wide character that is a standard blank wide
17643     character or is one of a locale-specific set of wide characters for which iswspace is true
17644     and that is used to separate words within a line of text. The standard blank wide
17645     characters are the following: space (L' '), and horizontal tab (L'\t'). In the "C"
17646     locale, iswblank returns true only for the standard blank characters.
17647     7.29.2.1.4 The iswcntrl function
17648     Synopsis
17649 1           #include <wctype.h>
17650             int iswcntrl(wint_t wc);
17651     Description
17652 2   The iswcntrl function tests for any control wide character.
17653     7.29.2.1.5 The iswdigit function
17654     Synopsis
17655 1           #include <wctype.h>
17656             int iswdigit(wint_t wc);
17657     Description
17658 2   The iswdigit function tests for any wide character that corresponds to a decimal-digit
17659     character (as defined in 5.2.1).
17660     7.29.2.1.6 The iswgraph function
17661     Synopsis
17662 1           #include <wctype.h>
17663             int iswgraph(wint_t wc);
17664
17665
17666
17667
17668     337) The functions iswlower and iswupper test true or false separately for each of these additional
17669          wide characters; all four combinations are possible.
17670
17671 [page 445]
17672
17673     Description
17674 2   The iswgraph function tests for any wide character for which iswprint is true and
17675     iswspace is false.338)
17676     7.29.2.1.7 The iswlower function
17677     Synopsis
17678 1           #include <wctype.h>
17679             int iswlower(wint_t wc);
17680     Description
17681 2   The iswlower function tests for any wide character that corresponds to a lowercase
17682     letter or is one of a locale-specific set of wide characters for which none of iswcntrl,
17683     iswdigit, iswpunct, or iswspace is true.
17684     7.29.2.1.8 The iswprint function
17685     Synopsis
17686 1           #include <wctype.h>
17687             int iswprint(wint_t wc);
17688     Description
17689 2   The iswprint function tests for any printing wide character.
17690     7.29.2.1.9 The iswpunct function
17691     Synopsis
17692 1           #include <wctype.h>
17693             int iswpunct(wint_t wc);
17694     Description
17695 2   The iswpunct function tests for any printing wide character that is one of a locale-
17696     specific set of punctuation wide characters for which neither iswspace nor iswalnum
17697     is true.338)
17698     7.29.2.1.10 The iswspace function
17699     Synopsis
17700 1           #include <wctype.h>
17701             int iswspace(wint_t wc);
17702
17703
17704
17705     338) Note that the behavior of the iswgraph and iswpunct functions may differ from their
17706          corresponding functions in 7.4.1 with respect to printing, white-space, single-byte execution
17707          characters other than ' '.
17708
17709 [page 446]
17710
17711     Description
17712 2   The iswspace function tests for any wide character that corresponds to a locale-specific
17713     set of white-space wide characters for which none of iswalnum, iswgraph, or
17714     iswpunct is true.
17715     7.29.2.1.11 The iswupper function
17716     Synopsis
17717 1           #include <wctype.h>
17718             int iswupper(wint_t wc);
17719     Description
17720 2   The iswupper function tests for any wide character that corresponds to an uppercase
17721     letter or is one of a locale-specific set of wide characters for which none of iswcntrl,
17722     iswdigit, iswpunct, or iswspace is true.
17723     7.29.2.1.12 The iswxdigit function
17724     Synopsis
17725 1           #include <wctype.h>
17726             int iswxdigit(wint_t wc);
17727     Description
17728 2   The iswxdigit function tests for any wide character that corresponds to a
17729     hexadecimal-digit character (as defined in 6.4.4.1).
17730     7.29.2.2 Extensible wide character classification functions
17731 1   The functions wctype and iswctype provide extensible wide character classification
17732     as well as testing equivalent to that performed by the functions described in the previous
17733     subclause (7.29.2.1).
17734     7.29.2.2.1 The iswctype function
17735     Synopsis
17736 1           #include <wctype.h>
17737             int iswctype(wint_t wc, wctype_t desc);
17738     Description
17739 2   The iswctype function determines whether the wide character wc has the property
17740     described by desc. The current setting of the LC_CTYPE category shall be the same as
17741     during the call to wctype that returned the value desc.
17742 3   Each of the following expressions has a truth-value equivalent to the call to the wide
17743     character classification function (7.29.2.1) in the comment that follows the expression:
17744
17745
17746 [page 447]
17747
17748            iswctype(wc,       wctype("alnum"))              //   iswalnum(wc)
17749            iswctype(wc,       wctype("alpha"))              //   iswalpha(wc)
17750            iswctype(wc,       wctype("blank"))              //   iswblank(wc)
17751            iswctype(wc,       wctype("cntrl"))              //   iswcntrl(wc)
17752            iswctype(wc,       wctype("digit"))              //   iswdigit(wc)
17753            iswctype(wc,       wctype("graph"))              //   iswgraph(wc)
17754            iswctype(wc,       wctype("lower"))              //   iswlower(wc)
17755            iswctype(wc,       wctype("print"))              //   iswprint(wc)
17756            iswctype(wc,       wctype("punct"))              //   iswpunct(wc)
17757            iswctype(wc,       wctype("space"))              //   iswspace(wc)
17758            iswctype(wc,       wctype("upper"))              //   iswupper(wc)
17759            iswctype(wc,       wctype("xdigit"))             //   iswxdigit(wc)
17760     Returns
17761 4   The iswctype function returns nonzero (true) if and only if the value of the wide
17762     character wc has the property described by desc.
17763     Forward references: the wctype function (7.29.2.2.2).
17764     7.29.2.2.2 The wctype function
17765     Synopsis
17766 1          #include <wctype.h>
17767            wctype_t wctype(const char *property);
17768     Description
17769 2   The wctype function constructs a value with type wctype_t that describes a class of
17770     wide characters identified by the string argument property.
17771 3   The strings listed in the description of the iswctype function shall be valid in all
17772     locales as property arguments to the wctype function.
17773     Returns
17774 4   If property identifies a valid class of wide characters according to the LC_CTYPE
17775     category of the current locale, the wctype function returns a nonzero value that is valid
17776     as the second argument to the iswctype function; otherwise, it returns zero.
17777
17778
17779
17780
17781 [page 448]
17782
17783     7.29.3 Wide character case mapping utilities
17784 1   The header <wctype.h> declares several functions useful for mapping wide characters.
17785     7.29.3.1 Wide character case mapping functions
17786     7.29.3.1.1 The towlower function
17787     Synopsis
17788 1           #include <wctype.h>
17789             wint_t towlower(wint_t wc);
17790     Description
17791 2   The towlower function converts an uppercase letter to a corresponding lowercase letter.
17792     Returns
17793 3   If the argument is a wide character for which iswupper is true and there are one or
17794     more corresponding wide characters, as specified by the current locale, for which
17795     iswlower is true, the towlower function returns one of the corresponding wide
17796     characters (always the same one for any given locale); otherwise, the argument is
17797     returned unchanged.
17798     7.29.3.1.2 The towupper function
17799     Synopsis
17800 1           #include <wctype.h>
17801             wint_t towupper(wint_t wc);
17802     Description
17803 2   The towupper function converts a lowercase letter to a corresponding uppercase letter.
17804     Returns
17805 3   If the argument is a wide character for which iswlower is true and there are one or
17806     more corresponding wide characters, as specified by the current locale, for which
17807     iswupper is true, the towupper function returns one of the corresponding wide
17808     characters (always the same one for any given locale); otherwise, the argument is
17809     returned unchanged.
17810     7.29.3.2 Extensible wide character case mapping functions
17811 1   The functions wctrans and towctrans provide extensible wide character mapping as
17812     well as case mapping equivalent to that performed by the functions described in the
17813     previous subclause (7.29.3.1).
17814
17815
17816
17817
17818 [page 449]
17819
17820     7.29.3.2.1 The towctrans function
17821     Synopsis
17822 1          #include <wctype.h>
17823            wint_t towctrans(wint_t wc, wctrans_t desc);
17824     Description
17825 2   The towctrans function maps the wide character wc using the mapping described by
17826     desc. The current setting of the LC_CTYPE category shall be the same as during the call
17827     to wctrans that returned the value desc.
17828 3   Each of the following expressions behaves the same as the call to the wide character case
17829     mapping function (7.29.3.1) in the comment that follows the expression:
17830            towctrans(wc, wctrans("tolower"))                      // towlower(wc)
17831            towctrans(wc, wctrans("toupper"))                      // towupper(wc)
17832     Returns
17833 4   The towctrans function returns the mapped value of wc using the mapping described
17834     by desc.
17835     7.29.3.2.2 The wctrans function
17836     Synopsis
17837 1          #include <wctype.h>
17838            wctrans_t wctrans(const char *property);
17839     Description
17840 2   The wctrans function constructs a value with type wctrans_t that describes a
17841     mapping between wide characters identified by the string argument property.
17842 3   The strings listed in the description of the towctrans function shall be valid in all
17843     locales as property arguments to the wctrans function.
17844     Returns
17845 4   If property identifies a valid mapping of wide characters according to the LC_CTYPE
17846     category of the current locale, the wctrans function returns a nonzero value that is valid
17847     as the second argument to the towctrans function; otherwise, it returns zero.
17848
17849
17850
17851
17852 [page 450]
17853
17854     7.30 Future library directions
17855 1   The following names are grouped under individual headers for convenience. All external
17856     names described below are reserved no matter what headers are included by the program.
17857     7.30.1 Complex arithmetic <complex.h>
17858 1   The function names
17859          cerf                cexpm1              clog2
17860          cerfc               clog10              clgamma
17861          cexp2               clog1p              ctgamma
17862     and the same names suffixed with f or l may be added to the declarations in the
17863     <complex.h> header.
17864     7.30.2 Character handling <ctype.h>
17865 1   Function names that begin with either is or to, and a lowercase letter may be added to
17866     the declarations in the <ctype.h> header.
17867     7.30.3 Errors <errno.h>
17868 1   Macros that begin with E and a digit or E and an uppercase letter may be added to the
17869     declarations in the <errno.h> header.
17870     7.30.4 Format conversion of integer types <inttypes.h>
17871 1   Macro names beginning with PRI or SCN followed by any lowercase letter or X may be
17872     added to the macros defined in the <inttypes.h> header.
17873     7.30.5 Localization <locale.h>
17874 1   Macros that begin with LC_ and an uppercase letter may be added to the definitions in
17875     the <locale.h> header.
17876     7.30.6 Signal handling <signal.h>
17877 1   Macros that begin with either SIG and an uppercase letter or SIG_ and an uppercase
17878     letter may be added to the definitions in the <signal.h> header.
17879     7.30.7 Boolean type and values <stdbool.h>
17880 1   The ability to undefine and perhaps then redefine the macros bool, true, and false is
17881     an obsolescent feature.
17882     7.30.8 Integer types <stdint.h>
17883 1   Typedef names beginning with int or uint and ending with _t may be added to the
17884     types defined in the <stdint.h> header. Macro names beginning with INT or UINT
17885     and ending with _MAX, _MIN, or _C may be added to the macros defined in the
17886     <stdint.h> header.
17887
17888 [page 451]
17889
17890     7.30.9 Input/output <stdio.h>
17891 1   Lowercase letters may be added to the conversion specifiers and length modifiers in
17892     fprintf and fscanf. Other characters may be used in extensions.
17893 2   The use of ungetc on a binary stream where the file position indicator is zero prior to
17894     the call is an obsolescent feature.
17895     7.30.10 General utilities <stdlib.h>
17896 1   Function names that begin with str and a lowercase letter may be added to the
17897     declarations in the <stdlib.h> header.
17898     7.30.11 String handling <string.h>
17899 1   Function names that begin with str, mem, or wcs and a lowercase letter may be added
17900     to the declarations in the <string.h> header.
17901     7.30.12 Extended multibyte and wide character utilities <wchar.h>
17902 1   Function names that begin with wcs and a lowercase letter may be added to the
17903     declarations in the <wchar.h> header.
17904 2   Lowercase letters may be added to the conversion specifiers and length modifiers in
17905     fwprintf and fwscanf. Other characters may be used in extensions.
17906     7.30.13 Wide character classification and mapping utilities
17907     <wctype.h>
17908 1   Function names that begin with is or to and a lowercase letter may be added to the
17909     declarations in the <wctype.h> header.
17910
17911
17912
17913
17914 [page 452]
17915
17916                                                    Annex A
17917                                                  (informative)
17918                                   Language syntax summary
17919 1   NOTE     The notation is described in 6.1.
17920
17921     A.1 Lexical grammar
17922     A.1.1 Lexical elements
17923     (6.4) token:
17924                      keyword
17925                      identifier
17926                      constant
17927                      string-literal
17928                      punctuator
17929     (6.4) preprocessing-token:
17930                   header-name
17931                   identifier
17932                   pp-number
17933                   character-constant
17934                   string-literal
17935                   punctuator
17936                   each non-white-space character that cannot be one of the above
17937
17938
17939
17940
17941 [page 453]
17942
17943 A.1.2 Keywords
17944 (6.4.1) keyword: one of
17945               alignof                     goto                  union
17946               auto                        if                    unsigned
17947               break                       inline                void
17948               case                        int                   volatile
17949               char                        long                  while
17950               const                       register              _Alignas
17951               continue                    restrict              _Atomic
17952               default                     return                _Bool
17953               do                          short                 _Complex
17954               double                      signed                _Generic
17955               else                        sizeof                _Imaginary
17956               enum                        static                _Noreturn
17957               extern                      struct                _Static_assert
17958               float                       switch                _Thread_local
17959               for                         typedef
17960 A.1.3 Identifiers
17961 (6.4.2.1) identifier:
17962                identifier-nondigit
17963                identifier identifier-nondigit
17964                identifier digit
17965 (6.4.2.1) identifier-nondigit:
17966                nondigit
17967                universal-character-name
17968                other implementation-defined characters
17969 (6.4.2.1) nondigit: one of
17970               _ a b          c    d   e    f   g   h    i   j   k   l   m
17971                    n o       p    q   r    s   t   u    v   w   x   y   z
17972                    A B       C    D   E    F   G   H    I   J   K   L   M
17973                    N O       P    Q   R    S   T   U    V   W   X   Y   Z
17974 (6.4.2.1) digit: one of
17975                0 1 2         3    4   5    6   7   8    9
17976
17977
17978
17979
17980 [page 454]
17981
17982 A.1.4 Universal character names
17983 (6.4.3) universal-character-name:
17984               \u hex-quad
17985               \U hex-quad hex-quad
17986 (6.4.3) hex-quad:
17987               hexadecimal-digit hexadecimal-digit
17988                            hexadecimal-digit hexadecimal-digit
17989 A.1.5 Constants
17990 (6.4.4) constant:
17991               integer-constant
17992               floating-constant
17993               enumeration-constant
17994               character-constant
17995 (6.4.4.1) integer-constant:
17996                decimal-constant integer-suffixopt
17997                octal-constant integer-suffixopt
17998                hexadecimal-constant integer-suffixopt
17999 (6.4.4.1) decimal-constant:
18000               nonzero-digit
18001               decimal-constant digit
18002 (6.4.4.1) octal-constant:
18003                0
18004                octal-constant octal-digit
18005 (6.4.4.1) hexadecimal-constant:
18006               hexadecimal-prefix hexadecimal-digit
18007               hexadecimal-constant hexadecimal-digit
18008 (6.4.4.1) hexadecimal-prefix: one of
18009               0x 0X
18010 (6.4.4.1) nonzero-digit: one of
18011               1 2 3 4 5              6      7   8   9
18012 (6.4.4.1) octal-digit: one of
18013                0 1 2 3           4   5      6   7
18014
18015
18016
18017
18018 [page 455]
18019
18020 (6.4.4.1) hexadecimal-digit: one of
18021               0 1 2 3 4 5                6    7    8   9
18022               a b c d e f
18023               A B C D E F
18024 (6.4.4.1) integer-suffix:
18025                unsigned-suffix long-suffixopt
18026                unsigned-suffix long-long-suffix
18027                long-suffix unsigned-suffixopt
18028                long-long-suffix unsigned-suffixopt
18029 (6.4.4.1) unsigned-suffix: one of
18030                u U
18031 (6.4.4.1) long-suffix: one of
18032                l L
18033 (6.4.4.1) long-long-suffix: one of
18034                ll LL
18035 (6.4.4.2) floating-constant:
18036                decimal-floating-constant
18037                hexadecimal-floating-constant
18038 (6.4.4.2) decimal-floating-constant:
18039               fractional-constant exponent-partopt floating-suffixopt
18040               digit-sequence exponent-part floating-suffixopt
18041 (6.4.4.2) hexadecimal-floating-constant:
18042               hexadecimal-prefix hexadecimal-fractional-constant
18043                             binary-exponent-part floating-suffixopt
18044               hexadecimal-prefix hexadecimal-digit-sequence
18045                             binary-exponent-part floating-suffixopt
18046 (6.4.4.2) fractional-constant:
18047                digit-sequenceopt . digit-sequence
18048                digit-sequence .
18049 (6.4.4.2) exponent-part:
18050               e signopt digit-sequence
18051               E signopt digit-sequence
18052 (6.4.4.2) sign: one of
18053                + -
18054
18055
18056
18057 [page 456]
18058
18059 (6.4.4.2) digit-sequence:
18060                digit
18061                digit-sequence digit
18062 (6.4.4.2) hexadecimal-fractional-constant:
18063               hexadecimal-digit-sequenceopt .
18064                              hexadecimal-digit-sequence
18065               hexadecimal-digit-sequence .
18066 (6.4.4.2) binary-exponent-part:
18067                p signopt digit-sequence
18068                P signopt digit-sequence
18069 (6.4.4.2) hexadecimal-digit-sequence:
18070               hexadecimal-digit
18071               hexadecimal-digit-sequence hexadecimal-digit
18072 (6.4.4.2) floating-suffix: one of
18073                f l F L
18074 (6.4.4.3) enumeration-constant:
18075               identifier
18076 (6.4.4.4) character-constant:
18077               ' c-char-sequence '
18078               L' c-char-sequence '
18079               u' c-char-sequence '
18080               U' c-char-sequence '
18081 (6.4.4.4) c-char-sequence:
18082                c-char
18083                c-char-sequence c-char
18084 (6.4.4.4) c-char:
18085                any member of the source character set except
18086                             the single-quote ', backslash \, or new-line character
18087                escape-sequence
18088 (6.4.4.4) escape-sequence:
18089               simple-escape-sequence
18090               octal-escape-sequence
18091               hexadecimal-escape-sequence
18092               universal-character-name
18093
18094
18095
18096
18097 [page 457]
18098
18099 (6.4.4.4) simple-escape-sequence: one of
18100               \' \" \? \\
18101               \a \b \f \n \r \t                   \v
18102 (6.4.4.4) octal-escape-sequence:
18103                \ octal-digit
18104                \ octal-digit octal-digit
18105                \ octal-digit octal-digit octal-digit
18106 (6.4.4.4) hexadecimal-escape-sequence:
18107               \x hexadecimal-digit
18108               hexadecimal-escape-sequence hexadecimal-digit
18109 A.1.6 String literals
18110 (6.4.5) string-literal:
18111                encoding-prefixopt " s-char-sequenceopt "
18112 (6.4.5) encoding-prefix:
18113               u8
18114               u
18115               U
18116               L
18117 (6.4.5) s-char-sequence:
18118                s-char
18119                s-char-sequence s-char
18120 (6.4.5) s-char:
18121                any member of the source character set except
18122                             the double-quote ", backslash \, or new-line character
18123                escape-sequence
18124 A.1.7 Punctuators
18125 (6.4.6) punctuator: one of
18126               [ ] ( ) { } . ->
18127               ++ -- & * + - ~ !
18128               / % << >> < > <= >=                      ==    !=    ^    |   &&   ||
18129               ? : ; ...
18130               = *= /= %= += -= <<=                     >>=    &=       ^=   |=
18131               , # ##
18132               <: :> <% %> %: %:%:
18133
18134
18135
18136
18137 [page 458]
18138
18139 A.1.8 Header names
18140 (6.4.7) header-name:
18141               < h-char-sequence >
18142               " q-char-sequence "
18143 (6.4.7) h-char-sequence:
18144               h-char
18145               h-char-sequence h-char
18146 (6.4.7) h-char:
18147               any member of the source character set except
18148                            the new-line character and >
18149 (6.4.7) q-char-sequence:
18150               q-char
18151               q-char-sequence q-char
18152 (6.4.7) q-char:
18153               any member of the source character set except
18154                            the new-line character and "
18155 A.1.9 Preprocessing numbers
18156 (6.4.8) pp-number:
18157               digit
18158               . digit
18159               pp-number   digit
18160               pp-number   identifier-nondigit
18161               pp-number   e sign
18162               pp-number   E sign
18163               pp-number   p sign
18164               pp-number   P sign
18165               pp-number   .
18166
18167
18168
18169
18170 [page 459]
18171
18172 A.2 Phrase structure grammar
18173 A.2.1 Expressions
18174 (6.5.1) primary-expression:
18175               identifier
18176               constant
18177               string-literal
18178               ( expression )
18179               generic-selection
18180 (6.5.1.1) generic-selection:
18181               _Generic ( assignment-expression , generic-assoc-list )
18182 (6.5.1.1) generic-assoc-list:
18183               generic-association
18184               generic-assoc-list , generic-association
18185 (6.5.1.1) generic-association:
18186               type-name : assignment-expression
18187               default : assignment-expression
18188 (6.5.2) postfix-expression:
18189               primary-expression
18190               postfix-expression [ expression ]
18191               postfix-expression ( argument-expression-listopt )
18192               postfix-expression . identifier
18193               postfix-expression -> identifier
18194               postfix-expression ++
18195               postfix-expression --
18196               ( type-name ) { initializer-list }
18197               ( type-name ) { initializer-list , }
18198 (6.5.2) argument-expression-list:
18199              assignment-expression
18200              argument-expression-list , assignment-expression
18201 (6.5.3) unary-expression:
18202               postfix-expression
18203               ++ unary-expression
18204               -- unary-expression
18205               unary-operator cast-expression
18206               sizeof unary-expression
18207               sizeof ( type-name )
18208               alignof ( type-name )
18209
18210 [page 460]
18211
18212 (6.5.3) unary-operator: one of
18213               & * + - ~                !
18214 (6.5.4) cast-expression:
18215                unary-expression
18216                ( type-name ) cast-expression
18217 (6.5.5) multiplicative-expression:
18218                cast-expression
18219                multiplicative-expression * cast-expression
18220                multiplicative-expression / cast-expression
18221                multiplicative-expression % cast-expression
18222 (6.5.6) additive-expression:
18223                multiplicative-expression
18224                additive-expression + multiplicative-expression
18225                additive-expression - multiplicative-expression
18226 (6.5.7) shift-expression:
18227                 additive-expression
18228                 shift-expression << additive-expression
18229                 shift-expression >> additive-expression
18230 (6.5.8) relational-expression:
18231                shift-expression
18232                relational-expression   <    shift-expression
18233                relational-expression   >    shift-expression
18234                relational-expression   <=   shift-expression
18235                relational-expression   >=   shift-expression
18236 (6.5.9) equality-expression:
18237                relational-expression
18238                equality-expression == relational-expression
18239                equality-expression != relational-expression
18240 (6.5.10) AND-expression:
18241              equality-expression
18242              AND-expression & equality-expression
18243 (6.5.11) exclusive-OR-expression:
18244               AND-expression
18245               exclusive-OR-expression ^ AND-expression
18246
18247
18248
18249
18250 [page 461]
18251
18252 (6.5.12) inclusive-OR-expression:
18253                exclusive-OR-expression
18254                inclusive-OR-expression | exclusive-OR-expression
18255 (6.5.13) logical-AND-expression:
18256               inclusive-OR-expression
18257               logical-AND-expression && inclusive-OR-expression
18258 (6.5.14) logical-OR-expression:
18259               logical-AND-expression
18260               logical-OR-expression || logical-AND-expression
18261 (6.5.15) conditional-expression:
18262               logical-OR-expression
18263               logical-OR-expression ? expression : conditional-expression
18264 (6.5.16) assignment-expression:
18265               conditional-expression
18266               unary-expression assignment-operator assignment-expression
18267 (6.5.16) assignment-operator: one of
18268               = *= /= %= +=                -=    <<=    >>=      &=   ^=   |=
18269 (6.5.17) expression:
18270               assignment-expression
18271               expression , assignment-expression
18272 (6.6) constant-expression:
18273               conditional-expression
18274 A.2.2 Declarations
18275 (6.7) declaration:
18276                declaration-specifiers init-declarator-listopt ;
18277                static_assert-declaration                                                 *
18278 (6.7) declaration-specifiers:
18279                storage-class-specifier declaration-specifiersopt
18280                type-specifier declaration-specifiersopt
18281                type-qualifier declaration-specifiersopt
18282                function-specifier declaration-specifiersopt
18283                alignment-specifier declaration-specifiersopt
18284 (6.7) init-declarator-list:
18285                init-declarator
18286                init-declarator-list , init-declarator
18287
18288
18289 [page 462]
18290
18291 (6.7) init-declarator:
18292                declarator
18293                declarator = initializer
18294 (6.7.1) storage-class-specifier:
18295               typedef
18296               extern
18297               static
18298               _Thread_local
18299               auto
18300               register
18301 (6.7.2) type-specifier:
18302                void
18303                char
18304                short
18305                int
18306                long
18307                float
18308                double
18309                signed
18310                unsigned
18311                _Bool
18312                _Complex
18313                _Atomic ( type-name )
18314                struct-or-union-specifier
18315                enum-specifier
18316                typedef-name
18317 (6.7.2.1) struct-or-union-specifier:
18318                struct-or-union identifieropt { struct-declaration-list }
18319                struct-or-union identifier
18320 (6.7.2.1) struct-or-union:
18321                struct
18322                union
18323 (6.7.2.1) struct-declaration-list:
18324                struct-declaration
18325                struct-declaration-list struct-declaration
18326 (6.7.2.1) struct-declaration:
18327                specifier-qualifier-list struct-declarator-listopt ;
18328                static_assert-declaration
18329
18330 [page 463]
18331
18332 (6.7.2.1) specifier-qualifier-list:
18333                type-specifier specifier-qualifier-listopt
18334                type-qualifier specifier-qualifier-listopt
18335 (6.7.2.1) struct-declarator-list:
18336                struct-declarator
18337                struct-declarator-list , struct-declarator
18338 (6.7.2.1) struct-declarator:
18339                declarator
18340                declaratoropt : constant-expression
18341 (6.7.2.2) enum-specifier:
18342               enum identifieropt { enumerator-list }
18343               enum identifieropt { enumerator-list , }
18344               enum identifier
18345 (6.7.2.2) enumerator-list:
18346               enumerator
18347               enumerator-list , enumerator
18348 (6.7.2.2) enumerator:
18349               enumeration-constant
18350               enumeration-constant = constant-expression
18351 (6.7.3) type-qualifier:
18352               const
18353               restrict
18354               volatile
18355               _Atomic
18356 (6.7.4) function-specifier:
18357                inline
18358                _Noreturn
18359 (6.7.5) alignment-specifier:
18360               _Alignas ( type-name )
18361               _Alignas ( constant-expression )
18362 (6.7.6) declarator:
18363               pointeropt direct-declarator
18364
18365
18366
18367
18368 [page 464]
18369
18370 (6.7.6) direct-declarator:
18371                identifier
18372                ( declarator )
18373                direct-declarator [ type-qualifier-listopt assignment-expressionopt ]
18374                direct-declarator [ static type-qualifier-listopt assignment-expression ]
18375                direct-declarator [ type-qualifier-list static assignment-expression ]
18376                direct-declarator [ type-qualifier-listopt * ]
18377                direct-declarator ( parameter-type-list )
18378                direct-declarator ( identifier-listopt )
18379 (6.7.6) pointer:
18380                * type-qualifier-listopt
18381                * type-qualifier-listopt pointer
18382 (6.7.6) type-qualifier-list:
18383               type-qualifier
18384               type-qualifier-list type-qualifier
18385 (6.7.6) parameter-type-list:
18386              parameter-list
18387              parameter-list , ...
18388 (6.7.6) parameter-list:
18389              parameter-declaration
18390              parameter-list , parameter-declaration
18391 (6.7.6) parameter-declaration:
18392              declaration-specifiers declarator
18393              declaration-specifiers abstract-declaratoropt
18394 (6.7.6) identifier-list:
18395                identifier
18396                identifier-list , identifier
18397 (6.7.7) type-name:
18398               specifier-qualifier-list abstract-declaratoropt
18399 (6.7.7) abstract-declarator:
18400               pointer
18401               pointeropt direct-abstract-declarator
18402
18403
18404
18405
18406 [page 465]
18407
18408 (6.7.7) direct-abstract-declarator:
18409                ( abstract-declarator )
18410                direct-abstract-declaratoropt [ type-qualifier-listopt
18411                               assignment-expressionopt ]
18412                direct-abstract-declaratoropt [ static type-qualifier-listopt
18413                               assignment-expression ]
18414                direct-abstract-declaratoropt [ type-qualifier-list static
18415                               assignment-expression ]
18416                direct-abstract-declaratoropt [ * ]
18417                direct-abstract-declaratoropt ( parameter-type-listopt )
18418 (6.7.8) typedef-name:
18419               identifier
18420 (6.7.9) initializer:
18421                 assignment-expression
18422                 { initializer-list }
18423                 { initializer-list , }
18424 (6.7.9) initializer-list:
18425                 designationopt initializer
18426                 initializer-list , designationopt initializer
18427 (6.7.9) designation:
18428               designator-list =
18429 (6.7.9) designator-list:
18430               designator
18431               designator-list designator
18432 (6.7.9) designator:
18433               [ constant-expression ]
18434               . identifier
18435 (6.7.10) static_assert-declaration:
18436                _Static_assert ( constant-expression , string-literal ) ;
18437
18438
18439
18440
18441 [page 466]
18442
18443 A.2.3 Statements
18444 (6.8) statement:
18445               labeled-statement
18446               compound-statement
18447               expression-statement
18448               selection-statement
18449               iteration-statement
18450               jump-statement
18451 (6.8.1) labeled-statement:
18452                identifier : statement
18453                case constant-expression : statement
18454                default : statement
18455 (6.8.2) compound-statement:
18456              { block-item-listopt }
18457 (6.8.2) block-item-list:
18458                block-item
18459                block-item-list block-item
18460 (6.8.2) block-item:
18461                declaration
18462                statement
18463 (6.8.3) expression-statement:
18464               expressionopt ;
18465 (6.8.4) selection-statement:
18466                if ( expression ) statement
18467                if ( expression ) statement else statement
18468                switch ( expression ) statement
18469 (6.8.5) iteration-statement:
18470                 while ( expression ) statement
18471                 do statement while ( expression ) ;
18472                 for ( expressionopt ; expressionopt ; expressionopt ) statement
18473                 for ( declaration expressionopt ; expressionopt ) statement
18474 (6.8.6) jump-statement:
18475               goto identifier ;
18476               continue ;
18477               break ;
18478               return expressionopt ;
18479
18480 [page 467]
18481
18482 A.2.4 External definitions
18483 (6.9) translation-unit:
18484                external-declaration
18485                translation-unit external-declaration
18486 (6.9) external-declaration:
18487                function-definition
18488                declaration
18489 (6.9.1) function-definition:
18490                declaration-specifiers declarator declaration-listopt compound-statement
18491 (6.9.1) declaration-list:
18492               declaration
18493               declaration-list declaration
18494 A.3 Preprocessing directives
18495 (6.10) preprocessing-file:
18496               groupopt
18497 (6.10) group:
18498                 group-part
18499                 group group-part
18500 (6.10) group-part:
18501               if-section
18502               control-line
18503               text-line
18504               # non-directive
18505 (6.10) if-section:
18506                 if-group elif-groupsopt else-groupopt endif-line
18507 (6.10) if-group:
18508                # if     constant-expression new-line groupopt
18509                # ifdef identifier new-line groupopt
18510                # ifndef identifier new-line groupopt
18511 (6.10) elif-groups:
18512                elif-group
18513                elif-groups elif-group
18514 (6.10) elif-group:
18515                # elif        constant-expression new-line groupopt
18516
18517
18518 [page 468]
18519
18520 (6.10) else-group:
18521                # else        new-line groupopt
18522 (6.10) endif-line:
18523                # endif       new-line
18524 (6.10) control-line:
18525               # include pp-tokens new-line
18526               # define identifier replacement-list new-line
18527               # define identifier lparen identifier-listopt )
18528                                               replacement-list new-line
18529               # define identifier lparen ... ) replacement-list new-line
18530               # define identifier lparen identifier-list , ... )
18531                                               replacement-list new-line
18532               # undef   identifier new-line
18533               # line    pp-tokens new-line
18534               # error   pp-tokensopt new-line
18535               # pragma pp-tokensopt new-line
18536               #         new-line
18537 (6.10) text-line:
18538                pp-tokensopt new-line
18539 (6.10) non-directive:
18540               pp-tokens new-line
18541 (6.10) lparen:
18542                  a ( character not immediately preceded by white-space
18543 (6.10) replacement-list:
18544               pp-tokensopt
18545 (6.10) pp-tokens:
18546               preprocessing-token
18547               pp-tokens preprocessing-token
18548 (6.10) new-line:
18549               the new-line character
18550
18551
18552
18553
18554 [page 469]
18555
18556                               Annex B
18557                             (informative)
18558                          Library summary
18559 B.1 Diagnostics <assert.h>
18560       NDEBUG
18561       static_assert
18562       void assert(scalar expression);
18563 B.2 Complex <complex.h>
18564       __STDC_NO_COMPLEX__            imaginary
18565       complex                          _Imaginary_I
18566       _Complex_I                       I
18567       #pragma STDC CX_LIMITED_RANGE on-off-switch
18568       double complex cacos(double complex z);
18569       float complex cacosf(float complex z);
18570       long double complex cacosl(long double complex z);
18571       double complex casin(double complex z);
18572       float complex casinf(float complex z);
18573       long double complex casinl(long double complex z);
18574       double complex catan(double complex z);
18575       float complex catanf(float complex z);
18576       long double complex catanl(long double complex z);
18577       double complex ccos(double complex z);
18578       float complex ccosf(float complex z);
18579       long double complex ccosl(long double complex z);
18580       double complex csin(double complex z);
18581       float complex csinf(float complex z);
18582       long double complex csinl(long double complex z);
18583       double complex ctan(double complex z);
18584       float complex ctanf(float complex z);
18585       long double complex ctanl(long double complex z);
18586       double complex cacosh(double complex z);
18587       float complex cacoshf(float complex z);
18588       long double complex cacoshl(long double complex z);
18589       double complex casinh(double complex z);
18590       float complex casinhf(float complex z);
18591       long double complex casinhl(long double complex z);
18592
18593 [page 470]
18594
18595         double complex catanh(double complex z);
18596         float complex catanhf(float complex z);
18597         long double complex catanhl(long double complex z);
18598         double complex ccosh(double complex z);
18599         float complex ccoshf(float complex z);
18600         long double complex ccoshl(long double complex z);
18601         double complex csinh(double complex z);
18602         float complex csinhf(float complex z);
18603         long double complex csinhl(long double complex z);
18604         double complex ctanh(double complex z);
18605         float complex ctanhf(float complex z);
18606         long double complex ctanhl(long double complex z);
18607         double complex cexp(double complex z);
18608         float complex cexpf(float complex z);
18609         long double complex cexpl(long double complex z);
18610         double complex clog(double complex z);
18611         float complex clogf(float complex z);
18612         long double complex clogl(long double complex z);
18613         double cabs(double complex z);
18614         float cabsf(float complex z);
18615         long double cabsl(long double complex z);
18616         double complex cpow(double complex x, double complex y);
18617         float complex cpowf(float complex x, float complex y);
18618         long double complex cpowl(long double complex x,
18619              long double complex y);
18620         double complex csqrt(double complex z);
18621         float complex csqrtf(float complex z);
18622         long double complex csqrtl(long double complex z);
18623         double carg(double complex z);
18624         float cargf(float complex z);
18625         long double cargl(long double complex z);
18626         double cimag(double complex z);
18627         float cimagf(float complex z);
18628         long double cimagl(long double complex z);
18629         double complex CMPLX(double x, double y);
18630         float complex CMPLXF(float x, float y);
18631         long double complex CMPLXL(long double x, long double y);
18632         double complex conj(double complex z);
18633         float complex conjf(float complex z);
18634         long double complex conjl(long double complex z);
18635         double complex cproj(double complex z);
18636
18637 [page 471]
18638
18639       float complex cprojf(float complex z);
18640       long double complex cprojl(long double complex z);
18641       double creal(double complex z);
18642       float crealf(float complex z);
18643       long double creall(long double complex z);
18644 B.3 Character handling <ctype.h>
18645       int   isalnum(int c);
18646       int   isalpha(int c);
18647       int   isblank(int c);
18648       int   iscntrl(int c);
18649       int   isdigit(int c);
18650       int   isgraph(int c);
18651       int   islower(int c);
18652       int   isprint(int c);
18653       int   ispunct(int c);
18654       int   isspace(int c);
18655       int   isupper(int c);
18656       int   isxdigit(int c);
18657       int   tolower(int c);
18658       int   toupper(int c);
18659 B.4 Errors <errno.h>
18660       EDOM            EILSEQ            ERANGE           errno
18661       __STDC_WANT_LIB_EXT1__
18662       errno_t
18663 B.5 Floating-point environment <fenv.h>
18664       fenv_t                FE_OVERFLOW              FE_TOWARDZERO
18665       fexcept_t             FE_UNDERFLOW             FE_UPWARD
18666       FE_DIVBYZERO          FE_ALL_EXCEPT            FE_DFL_ENV
18667       FE_INEXACT            FE_DOWNWARD
18668       FE_INVALID            FE_TONEAREST
18669       #pragma STDC FENV_ACCESS on-off-switch
18670       int feclearexcept(int excepts);
18671       int fegetexceptflag(fexcept_t *flagp, int excepts);
18672       int feraiseexcept(int excepts);
18673       int fesetexceptflag(const fexcept_t *flagp,
18674            int excepts);
18675       int fetestexcept(int excepts);
18676
18677 [page 472]
18678
18679         int   fegetround(void);
18680         int   fesetround(int round);
18681         int   fegetenv(fenv_t *envp);
18682         int   feholdexcept(fenv_t *envp);
18683         int   fesetenv(const fenv_t *envp);
18684         int   feupdateenv(const fenv_t *envp);
18685 B.6 Characteristics of floating types <float.h>
18686         FLT_ROUNDS            DBL_DIG                  FLT_MAX
18687         FLT_EVAL_METHOD       LDBL_DIG                 DBL_MAX
18688         FLT_HAS_SUBNORM       FLT_MIN_EXP              LDBL_MAX
18689         DBL_HAS_SUBNORM       DBL_MIN_EXP              FLT_EPSILON
18690         LDBL_HAS_SUBNORM      LDBL_MIN_EXP             DBL_EPSILON
18691         FLT_RADIX             FLT_MIN_10_EXP           LDBL_EPSILON
18692         FLT_MANT_DIG          DBL_MIN_10_EXP           FLT_MIN
18693         DBL_MANT_DIG          LDBL_MIN_10_EXP          DBL_MIN
18694         LDBL_MANT_DIG         FLT_MAX_EXP              LDBL_MIN
18695         FLT_DECIMAL_DIG       DBL_MAX_EXP              FLT_TRUE_MIN
18696         DBL_DECIMAL_DIG       LDBL_MAX_EXP             DBL_TRUE_MIN
18697         LDBL_DECIMAL_DIG      FLT_MAX_10_EXP           LDBL_TRUE_MIN
18698         DECIMAL_DIG           DBL_MAX_10_EXP
18699         FLT_DIG               LDBL_MAX_10_EXP
18700 B.7 Format conversion of integer types <inttypes.h>
18701         imaxdiv_t
18702         PRIdN       PRIdLEASTN       PRIdFASTN         PRIdMAX     PRIdPTR
18703         PRIiN       PRIiLEASTN       PRIiFASTN         PRIiMAX     PRIiPTR
18704         PRIoN       PRIoLEASTN       PRIoFASTN         PRIoMAX     PRIoPTR
18705         PRIuN       PRIuLEASTN       PRIuFASTN         PRIuMAX     PRIuPTR
18706         PRIxN       PRIxLEASTN       PRIxFASTN         PRIxMAX     PRIxPTR
18707         PRIXN       PRIXLEASTN       PRIXFASTN         PRIXMAX     PRIXPTR
18708         SCNdN       SCNdLEASTN       SCNdFASTN         SCNdMAX     SCNdPTR
18709         SCNiN       SCNiLEASTN       SCNiFASTN         SCNiMAX     SCNiPTR
18710         SCNoN       SCNoLEASTN       SCNoFASTN         SCNoMAX     SCNoPTR
18711         SCNuN       SCNuLEASTN       SCNuFASTN         SCNuMAX     SCNuPTR
18712         SCNxN       SCNxLEASTN       SCNxFASTN         SCNxMAX     SCNxPTR
18713         intmax_t imaxabs(intmax_t j);
18714         imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
18715         intmax_t strtoimax(const char * restrict nptr,
18716                 char ** restrict endptr, int base);
18717
18718 [page 473]
18719
18720       uintmax_t strtoumax(const char * restrict nptr,
18721               char ** restrict endptr, int base);
18722       intmax_t wcstoimax(const wchar_t * restrict nptr,
18723               wchar_t ** restrict endptr, int base);
18724       uintmax_t wcstoumax(const wchar_t * restrict nptr,
18725               wchar_t ** restrict endptr, int base);
18726 B.8 Alternative spellings <iso646.h>
18727       and             bitor             not_eq           xor
18728       and_eq          compl             or               xor_eq
18729       bitand          not               or_eq
18730 B.9 Sizes of integer types <limits.h>
18731       CHAR_BIT        CHAR_MAX          INT_MIN          ULONG_MAX
18732       SCHAR_MIN       MB_LEN_MAX        INT_MAX          LLONG_MIN
18733       SCHAR_MAX       SHRT_MIN          UINT_MAX         LLONG_MAX
18734       UCHAR_MAX       SHRT_MAX          LONG_MIN         ULLONG_MAX
18735       CHAR_MIN        USHRT_MAX         LONG_MAX
18736 B.10 Localization <locale.h>
18737       struct lconv    LC_ALL            LC_CTYPE         LC_NUMERIC
18738       NULL            LC_COLLATE        LC_MONETARY      LC_TIME
18739       char *setlocale(int category, const char *locale);
18740       struct lconv *localeconv(void);
18741 B.11 Mathematics <math.h>
18742       float_t               FP_INFINITE              FP_FAST_FMAL
18743       double_t              FP_NAN                   FP_ILOGB0
18744       HUGE_VAL              FP_NORMAL                FP_ILOGBNAN
18745       HUGE_VALF             FP_SUBNORMAL             MATH_ERRNO
18746       HUGE_VALL             FP_ZERO                  MATH_ERREXCEPT
18747       INFINITY              FP_FAST_FMA              math_errhandling
18748       NAN                   FP_FAST_FMAF
18749       #pragma STDC FP_CONTRACT on-off-switch
18750       int fpclassify(real-floating x);
18751       int isfinite(real-floating x);
18752       int isinf(real-floating x);
18753       int isnan(real-floating x);
18754       int isnormal(real-floating x);
18755       int signbit(real-floating x);
18756 [page 474]
18757
18758         double acos(double x);
18759         float acosf(float x);
18760         long double acosl(long double x);
18761         double asin(double x);
18762         float asinf(float x);
18763         long double asinl(long double x);
18764         double atan(double x);
18765         float atanf(float x);
18766         long double atanl(long double x);
18767         double atan2(double y, double x);
18768         float atan2f(float y, float x);
18769         long double atan2l(long double y, long double x);
18770         double cos(double x);
18771         float cosf(float x);
18772         long double cosl(long double x);
18773         double sin(double x);
18774         float sinf(float x);
18775         long double sinl(long double x);
18776         double tan(double x);
18777         float tanf(float x);
18778         long double tanl(long double x);
18779         double acosh(double x);
18780         float acoshf(float x);
18781         long double acoshl(long double x);
18782         double asinh(double x);
18783         float asinhf(float x);
18784         long double asinhl(long double x);
18785         double atanh(double x);
18786         float atanhf(float x);
18787         long double atanhl(long double x);
18788         double cosh(double x);
18789         float coshf(float x);
18790         long double coshl(long double x);
18791         double sinh(double x);
18792         float sinhf(float x);
18793         long double sinhl(long double x);
18794         double tanh(double x);
18795         float tanhf(float x);
18796         long double tanhl(long double x);
18797         double exp(double x);
18798         float expf(float x);
18799
18800 [page 475]
18801
18802       long double expl(long double x);
18803       double exp2(double x);
18804       float exp2f(float x);
18805       long double exp2l(long double x);
18806       double expm1(double x);
18807       float expm1f(float x);
18808       long double expm1l(long double x);
18809       double frexp(double value, int *exp);
18810       float frexpf(float value, int *exp);
18811       long double frexpl(long double value, int *exp);
18812       int ilogb(double x);
18813       int ilogbf(float x);
18814       int ilogbl(long double x);
18815       double ldexp(double x, int exp);
18816       float ldexpf(float x, int exp);
18817       long double ldexpl(long double x, int exp);
18818       double log(double x);
18819       float logf(float x);
18820       long double logl(long double x);
18821       double log10(double x);
18822       float log10f(float x);
18823       long double log10l(long double x);
18824       double log1p(double x);
18825       float log1pf(float x);
18826       long double log1pl(long double x);
18827       double log2(double x);
18828       float log2f(float x);
18829       long double log2l(long double x);
18830       double logb(double x);
18831       float logbf(float x);
18832       long double logbl(long double x);
18833       double modf(double value, double *iptr);
18834       float modff(float value, float *iptr);
18835       long double modfl(long double value, long double *iptr);
18836       double scalbn(double x, int n);
18837       float scalbnf(float x, int n);
18838       long double scalbnl(long double x, int n);
18839       double scalbln(double x, long int n);
18840       float scalblnf(float x, long int n);
18841       long double scalblnl(long double x, long int n);
18842       double cbrt(double x);
18843
18844 [page 476]
18845
18846         float cbrtf(float x);
18847         long double cbrtl(long double x);
18848         double fabs(double x);
18849         float fabsf(float x);
18850         long double fabsl(long double x);
18851         double hypot(double x, double y);
18852         float hypotf(float x, float y);
18853         long double hypotl(long double x, long double y);
18854         double pow(double x, double y);
18855         float powf(float x, float y);
18856         long double powl(long double x, long double y);
18857         double sqrt(double x);
18858         float sqrtf(float x);
18859         long double sqrtl(long double x);
18860         double erf(double x);
18861         float erff(float x);
18862         long double erfl(long double x);
18863         double erfc(double x);
18864         float erfcf(float x);
18865         long double erfcl(long double x);
18866         double lgamma(double x);
18867         float lgammaf(float x);
18868         long double lgammal(long double x);
18869         double tgamma(double x);
18870         float tgammaf(float x);
18871         long double tgammal(long double x);
18872         double ceil(double x);
18873         float ceilf(float x);
18874         long double ceill(long double x);
18875         double floor(double x);
18876         float floorf(float x);
18877         long double floorl(long double x);
18878         double nearbyint(double x);
18879         float nearbyintf(float x);
18880         long double nearbyintl(long double x);
18881         double rint(double x);
18882         float rintf(float x);
18883         long double rintl(long double x);
18884         long int lrint(double x);
18885         long int lrintf(float x);
18886         long int lrintl(long double x);
18887
18888 [page 477]
18889
18890       long long int llrint(double x);
18891       long long int llrintf(float x);
18892       long long int llrintl(long double x);
18893       double round(double x);
18894       float roundf(float x);
18895       long double roundl(long double x);
18896       long int lround(double x);
18897       long int lroundf(float x);
18898       long int lroundl(long double x);
18899       long long int llround(double x);
18900       long long int llroundf(float x);
18901       long long int llroundl(long double x);
18902       double trunc(double x);
18903       float truncf(float x);
18904       long double truncl(long double x);
18905       double fmod(double x, double y);
18906       float fmodf(float x, float y);
18907       long double fmodl(long double x, long double y);
18908       double remainder(double x, double y);
18909       float remainderf(float x, float y);
18910       long double remainderl(long double x, long double y);
18911       double remquo(double x, double y, int *quo);
18912       float remquof(float x, float y, int *quo);
18913       long double remquol(long double x, long double y,
18914            int *quo);
18915       double copysign(double x, double y);
18916       float copysignf(float x, float y);
18917       long double copysignl(long double x, long double y);
18918       double nan(const char *tagp);
18919       float nanf(const char *tagp);
18920       long double nanl(const char *tagp);
18921       double nextafter(double x, double y);
18922       float nextafterf(float x, float y);
18923       long double nextafterl(long double x, long double y);
18924       double nexttoward(double x, long double y);
18925       float nexttowardf(float x, long double y);
18926       long double nexttowardl(long double x, long double y);
18927       double fdim(double x, double y);
18928       float fdimf(float x, float y);
18929       long double fdiml(long double x, long double y);
18930       double fmax(double x, double y);
18931
18932 [page 478]
18933
18934         float fmaxf(float x, float y);
18935         long double fmaxl(long double x, long double y);
18936         double fmin(double x, double y);
18937         float fminf(float x, float y);
18938         long double fminl(long double x, long double y);
18939         double fma(double x, double y, double z);
18940         float fmaf(float x, float y, float z);
18941         long double fmal(long double x, long double y,
18942              long double z);
18943         int isgreater(real-floating x, real-floating y);
18944         int isgreaterequal(real-floating x, real-floating y);
18945         int isless(real-floating x, real-floating y);
18946         int islessequal(real-floating x, real-floating y);
18947         int islessgreater(real-floating x, real-floating y);
18948         int isunordered(real-floating x, real-floating y);
18949 B.12 Nonlocal jumps <setjmp.h>
18950         jmp_buf
18951         int setjmp(jmp_buf env);
18952         _Noreturn void longjmp(jmp_buf env, int val);
18953 B.13 Signal handling <signal.h>
18954         sig_atomic_t    SIG_IGN           SIGILL           SIGTERM
18955         SIG_DFL         SIGABRT           SIGINT
18956         SIG_ERR         SIGFPE            SIGSEGV
18957         void (*signal(int sig, void (*func)(int)))(int);
18958         int raise(int sig);
18959
18960
18961
18962
18963 [page 479]
18964
18965 B.14 Alignment <stdalign.h>
18966       alignas
18967       __alignas_is_defined
18968 B.15 Variable arguments <stdarg.h>
18969       va_list
18970       type va_arg(va_list ap, type);
18971       void va_copy(va_list dest, va_list src);
18972       void va_end(va_list ap);
18973       void va_start(va_list ap, parmN);
18974 B.16 Atomics <stdatomic.h>
18975       ATOMIC_CHAR_LOCK_FREE            atomic_uint
18976       ATOMIC_CHAR16_T_LOCK_FREE        atomic_long
18977       ATOMIC_CHAR32_T_LOCK_FREE        atomic_ulong
18978       ATOMIC_WCHAR_T_LOCK_FREE         atomic_llong
18979       ATOMIC_SHORT_LOCK_FREE           atomic_ullong
18980       ATOMIC_INT_LOCK_FREE             atomic_char16_t
18981       ATOMIC_LONG_LOCK_FREE            atomic_char32_t
18982       ATOMIC_LLONG_LOCK_FREE           atomic_wchar_t
18983       ATOMIC_ADDRESS_LOCK_FREE         atomic_int_least8_t
18984       ATOMIC_FLAG_INIT                 atomic_uint_least8_t
18985       memory_order                     atomic_int_least16_t
18986       atomic_flag                      atomic_uint_least16_t
18987       atomic_bool                      atomic_int_least32_t
18988       atomic_address                   atomic_uint_least32_t
18989       memory_order_relaxed             atomic_int_least64_t
18990       memory_order_consume             atomic_uint_least64_t
18991       memory_order_acquire             atomic_int_fast8_t
18992       memory_order_release             atomic_uint_fast8_t
18993       memory_order_acq_rel             atomic_int_fast16_t
18994       memory_order_seq_cst             atomic_uint_fast16_t
18995       atomic_char                      atomic_int_fast32_t
18996       atomic_schar                     atomic_uint_fast32_t
18997       atomic_uchar                     atomic_int_fast64_t
18998       atomic_short                     atomic_uint_fast64_t
18999       atomic_ushort                    atomic_intptr_t
19000       atomic_int                       atomic_uintptr_t
19001
19002
19003
19004 [page 480]
19005
19006         atomic_size_t                   atomic_intmax_t
19007         atomic_ptrdiff_t                atomic_uintmax_t
19008         #define ATOMIC_VAR_INIT(C value)
19009         void atomic_init(volatile A *obj, C value);
19010         type kill_dependency(type y);
19011         void atomic_thread_fence(memory_order order);
19012         void atomic_signal_fence(memory_order order);
19013         _Bool atomic_is_lock_free(atomic_type const volatile *obj);
19014         void atomic_store(volatile A *object, C desired);
19015         void atomic_store_explicit(volatile A *object,
19016               C desired, memory_order order);
19017         C atomic_load(volatile A *object);
19018         C atomic_load_explicit(volatile A *object,
19019               memory_order order);
19020         C atomic_exchange(volatile A *object, C desired);
19021         C atomic_exchange_explicit(volatile A *object,
19022               C desired, memory_order order);
19023         _Bool atomic_compare_exchange_strong(volatile A *object,
19024               C *expected, C desired);
19025         _Bool atomic_compare_exchange_strong_explicit(
19026               volatile A *object, C *expected, C desired,
19027               memory_order success, memory_order failure);
19028         _Bool atomic_compare_exchange_weak(volatile A *object,
19029               C *expected, C desired);
19030         _Bool atomic_compare_exchange_weak_explicit(
19031               volatile A *object, C *expected, C desired,
19032               memory_order success, memory_order failure);
19033         C atomic_fetch_key(volatile A *object, M operand);
19034         C atomic_fetch_key_explicit(volatile A *object,
19035               M operand, memory_order order);
19036         bool atomic_flag_test_and_set(
19037               volatile atomic_flag *object);
19038         bool atomic_flag_test_and_set_explicit(
19039               volatile atomic_flag *object, memory_order order);
19040         void atomic_flag_clear(volatile atomic_flag *object);
19041         void atomic_flag_clear_explicit(
19042               volatile atomic_flag *object, memory_order order);
19043
19044
19045
19046
19047 [page 481]
19048
19049 B.17 Boolean type and values <stdbool.h>
19050       bool
19051       true
19052       false
19053       __bool_true_false_are_defined
19054 B.18 Common definitions <stddef.h>
19055       ptrdiff_t       max_align_t       NULL
19056       size_t          wchar_t
19057       offsetof(type, member-designator)
19058       __STDC_WANT_LIB_EXT1__
19059       rsize_t
19060 B.19 Integer types <stdint.h>
19061       intN_t                INT_LEASTN_MIN           PTRDIFF_MAX
19062       uintN_t               INT_LEASTN_MAX           SIG_ATOMIC_MIN
19063       int_leastN_t          UINT_LEASTN_MAX          SIG_ATOMIC_MAX
19064       uint_leastN_t         INT_FASTN_MIN            SIZE_MAX
19065       int_fastN_t           INT_FASTN_MAX            WCHAR_MIN
19066       uint_fastN_t          UINT_FASTN_MAX           WCHAR_MAX
19067       intptr_t              INTPTR_MIN               WINT_MIN
19068       uintptr_t             INTPTR_MAX               WINT_MAX
19069       intmax_t              UINTPTR_MAX              INTN_C(value)
19070       uintmax_t             INTMAX_MIN               UINTN_C(value)
19071       INTN_MIN              INTMAX_MAX               INTMAX_C(value)
19072       INTN_MAX              UINTMAX_MAX              UINTMAX_C(value)
19073       UINTN_MAX             PTRDIFF_MIN
19074       __STDC_WANT_LIB_EXT1__
19075       RSIZE_MAX
19076
19077
19078
19079
19080 [page 482]
19081
19082 B.20 Input/output <stdio.h>
19083         size_t       _IOLBF            FILENAME_MAX     TMP_MAX
19084         FILE         _IONBF            L_tmpnam         stderr
19085         fpos_t       BUFSIZ            SEEK_CUR         stdin
19086         NULL         EOF               SEEK_END         stdout
19087         _IOFBF       FOPEN_MAX         SEEK_SET
19088         int remove(const char *filename);
19089         int rename(const char *old, const char *new);
19090         FILE *tmpfile(void);
19091         char *tmpnam(char *s);
19092         int fclose(FILE *stream);
19093         int fflush(FILE *stream);
19094         FILE *fopen(const char * restrict filename,
19095              const char * restrict mode);
19096         FILE *freopen(const char * restrict filename,
19097              const char * restrict mode,
19098              FILE * restrict stream);
19099         void setbuf(FILE * restrict stream,
19100              char * restrict buf);
19101         int setvbuf(FILE * restrict stream,
19102              char * restrict buf,
19103              int mode, size_t size);
19104         int fprintf(FILE * restrict stream,
19105              const char * restrict format, ...);
19106         int fscanf(FILE * restrict stream,
19107              const char * restrict format, ...);
19108         int printf(const char * restrict format, ...);
19109         int scanf(const char * restrict format, ...);
19110         int snprintf(char * restrict s, size_t n,
19111              const char * restrict format, ...);
19112         int sprintf(char * restrict s,
19113              const char * restrict format, ...);
19114         int sscanf(const char * restrict s,
19115              const char * restrict format, ...);
19116         int vfprintf(FILE * restrict stream,
19117              const char * restrict format, va_list arg);
19118         int vfscanf(FILE * restrict stream,
19119              const char * restrict format, va_list arg);
19120         int vprintf(const char * restrict format, va_list arg);
19121         int vscanf(const char * restrict format, va_list arg);
19122
19123 [page 483]
19124
19125       int vsnprintf(char * restrict s, size_t n,
19126            const char * restrict format, va_list arg);
19127       int vsprintf(char * restrict s,
19128            const char * restrict format, va_list arg);
19129       int vsscanf(const char * restrict s,
19130            const char * restrict format, va_list arg);
19131       int fgetc(FILE *stream);
19132       char *fgets(char * restrict s, int n,
19133            FILE * restrict stream);
19134       int fputc(int c, FILE *stream);
19135       int fputs(const char * restrict s,
19136            FILE * restrict stream);
19137       int getc(FILE *stream);
19138       int getchar(void);
19139       int putc(int c, FILE *stream);
19140       int putchar(int c);
19141       int puts(const char *s);
19142       int ungetc(int c, FILE *stream);
19143       size_t fread(void * restrict ptr,
19144            size_t size, size_t nmemb,
19145            FILE * restrict stream);
19146       size_t fwrite(const void * restrict ptr,
19147            size_t size, size_t nmemb,
19148            FILE * restrict stream);
19149       int fgetpos(FILE * restrict stream,
19150            fpos_t * restrict pos);
19151       int fseek(FILE *stream, long int offset, int whence);
19152       int fsetpos(FILE *stream, const fpos_t *pos);
19153       long int ftell(FILE *stream);
19154       void rewind(FILE *stream);
19155       void clearerr(FILE *stream);
19156       int feof(FILE *stream);
19157       int ferror(FILE *stream);
19158       void perror(const char *s);
19159       __STDC_WANT_LIB_EXT1__
19160       L_tmpnam_s    TMP_MAX_S          errno_t          rsize_t
19161       errno_t tmpfile_s(FILE * restrict * restrict streamptr);
19162       errno_t tmpnam_s(char *s, rsize_t maxsize);
19163
19164
19165
19166 [page 484]
19167
19168         errno_t fopen_s(FILE * restrict * restrict streamptr,
19169              const char * restrict filename,
19170              const char * restrict mode);
19171         errno_t freopen_s(FILE * restrict * restrict newstreamptr,
19172              const char * restrict filename,
19173              const char * restrict mode,
19174              FILE * restrict stream);
19175         int fprintf_s(FILE * restrict stream,
19176              const char * restrict format, ...);
19177         int fscanf_s(FILE * restrict stream,
19178              const char * restrict format, ...);
19179         int printf_s(const char * restrict format, ...);
19180         int scanf_s(const char * restrict format, ...);
19181         int snprintf_s(char * restrict s, rsize_t n,
19182              const char * restrict format, ...);
19183         int sprintf_s(char * restrict s, rsize_t n,
19184              const char * restrict format, ...);
19185         int sscanf_s(const char * restrict s,
19186              const char * restrict format, ...);
19187         int vfprintf_s(FILE * restrict stream,
19188              const char * restrict format,
19189              va_list arg);
19190         int vfscanf_s(FILE * restrict stream,
19191              const char * restrict format,
19192              va_list arg);
19193         int vprintf_s(const char * restrict format,
19194              va_list arg);
19195         int vscanf_s(const char * restrict format,
19196              va_list arg);
19197         int vsnprintf_s(char * restrict s, rsize_t n,
19198              const char * restrict format,
19199              va_list arg);
19200         int vsprintf_s(char * restrict s, rsize_t n,
19201              const char * restrict format,
19202              va_list arg);
19203         int vsscanf_s(const char * restrict s,
19204              const char * restrict format,
19205              va_list arg);
19206         char *gets_s(char *s, rsize_t n);
19207
19208
19209
19210 [page 485]
19211
19212 B.21 General utilities <stdlib.h>
19213       size_t         ldiv_t            EXIT_FAILURE     MB_CUR_MAX
19214       wchar_t        lldiv_t           EXIT_SUCCESS
19215       div_t          NULL              RAND_MAX
19216       double atof(const char *nptr);
19217       int atoi(const char *nptr);
19218       long int atol(const char *nptr);
19219       long long int atoll(const char *nptr);
19220       double strtod(const char * restrict nptr,
19221            char ** restrict endptr);
19222       float strtof(const char * restrict nptr,
19223            char ** restrict endptr);
19224       long double strtold(const char * restrict nptr,
19225            char ** restrict endptr);
19226       long int strtol(const char * restrict nptr,
19227            char ** restrict endptr, int base);
19228       long long int strtoll(const char * restrict nptr,
19229            char ** restrict endptr, int base);
19230       unsigned long int strtoul(
19231            const char * restrict nptr,
19232            char ** restrict endptr, int base);
19233       unsigned long long int strtoull(
19234            const char * restrict nptr,
19235            char ** restrict endptr, int base);
19236       int rand(void);
19237       void srand(unsigned int seed);
19238       void *aligned_alloc(size_t alignment, size_t size);
19239       void *calloc(size_t nmemb, size_t size);
19240       void free(void *ptr);
19241       void *malloc(size_t size);
19242       void *realloc(void *ptr, size_t size);
19243       _Noreturn void abort(void);
19244       int atexit(void (*func)(void));
19245       int at_quick_exit(void (*func)(void));
19246       _Noreturn void exit(int status);
19247       _Noreturn void _Exit(int status);
19248       char *getenv(const char *name);
19249       _Noreturn void quick_exit(int status);
19250       int system(const char *string);
19251
19252
19253 [page 486]
19254
19255         void *bsearch(const void *key, const void *base,
19256              size_t nmemb, size_t size,
19257              int (*compar)(const void *, const void *));
19258         void qsort(void *base, size_t nmemb, size_t size,
19259              int (*compar)(const void *, const void *));
19260         int abs(int j);
19261         long int labs(long int j);
19262         long long int llabs(long long int j);
19263         div_t div(int numer, int denom);
19264         ldiv_t ldiv(long int numer, long int denom);
19265         lldiv_t lldiv(long long int numer,
19266              long long int denom);
19267         int mblen(const char *s, size_t n);
19268         int mbtowc(wchar_t * restrict pwc,
19269              const char * restrict s, size_t n);
19270         int wctomb(char *s, wchar_t wchar);
19271         size_t mbstowcs(wchar_t * restrict pwcs,
19272              const char * restrict s, size_t n);
19273         size_t wcstombs(char * restrict s,
19274              const wchar_t * restrict pwcs, size_t n);
19275         __STDC_WANT_LIB_EXT1__
19276         errno_t
19277         rsize_t
19278         constraint_handler_t
19279         constraint_handler_t set_constraint_handler_s(
19280              constraint_handler_t handler);
19281         void abort_handler_s(
19282              const char * restrict msg,
19283              void * restrict ptr,
19284              errno_t error);
19285         void ignore_handler_s(
19286              const char * restrict msg,
19287              void * restrict ptr,
19288              errno_t error);
19289         errno_t getenv_s(size_t * restrict len,
19290                   char * restrict value, rsize_t maxsize,
19291                   const char * restrict name);
19292
19293
19294
19295
19296 [page 487]
19297
19298       void *bsearch_s(const void *key, const void *base,
19299            rsize_t nmemb, rsize_t size,
19300            int (*compar)(const void *k, const void *y,
19301                            void *context),
19302            void *context);
19303       errno_t qsort_s(void *base, rsize_t nmemb, rsize_t size,
19304            int (*compar)(const void *x, const void *y,
19305                            void *context),
19306            void *context);
19307       errno_t wctomb_s(int * restrict status,
19308            char * restrict s,
19309            rsize_t smax,
19310            wchar_t wc);
19311       errno_t mbstowcs_s(size_t * restrict retval,
19312            wchar_t * restrict dst, rsize_t dstmax,
19313            const char * restrict src, rsize_t len);
19314       errno_t wcstombs_s(size_t * restrict retval,
19315            char * restrict dst, rsize_t dstmax,
19316            const wchar_t * restrict src, rsize_t len);
19317 B.22 String handling <string.h>
19318       size_t
19319       NULL
19320       void *memcpy(void * restrict s1,
19321            const void * restrict s2, size_t n);
19322       void *memmove(void *s1, const void *s2, size_t n);
19323       char *strcpy(char * restrict s1,
19324            const char * restrict s2);
19325       char *strncpy(char * restrict s1,
19326            const char * restrict s2, size_t n);
19327       char *strcat(char * restrict s1,
19328            const char * restrict s2);
19329       char *strncat(char * restrict s1,
19330            const char * restrict s2, size_t n);
19331       int memcmp(const void *s1, const void *s2, size_t n);
19332       int strcmp(const char *s1, const char *s2);
19333       int strcoll(const char *s1, const char *s2);
19334       int strncmp(const char *s1, const char *s2, size_t n);
19335       size_t strxfrm(char * restrict s1,
19336            const char * restrict s2, size_t n);
19337       void *memchr(const void *s, int c, size_t n);
19338 [page 488]
19339
19340         char *strchr(const char *s, int c);
19341         size_t strcspn(const char *s1, const char *s2);
19342         char *strpbrk(const char *s1, const char *s2);
19343         char *strrchr(const char *s, int c);
19344         size_t strspn(const char *s1, const char *s2);
19345         char *strstr(const char *s1, const char *s2);
19346         char *strtok(char * restrict s1,
19347              const char * restrict s2);
19348         void *memset(void *s, int c, size_t n);
19349         char *strerror(int errnum);
19350         size_t strlen(const char *s);
19351         __STDC_WANT_LIB_EXT1__
19352         errno_t
19353         rsize_t
19354         errno_t memcpy_s(void * restrict s1, rsize_t s1max,
19355              const void * restrict s2, rsize_t n);
19356         errno_t memmove_s(void *s1, rsize_t s1max,
19357              const void *s2, rsize_t n);
19358         errno_t strcpy_s(char * restrict s1,
19359              rsize_t s1max,
19360              const char * restrict s2);
19361         errno_t strncpy_s(char * restrict s1,
19362              rsize_t s1max,
19363              const char * restrict s2,
19364              rsize_t n);
19365         errno_t strcat_s(char * restrict s1,
19366              rsize_t s1max,
19367              const char * restrict s2);
19368         errno_t strncat_s(char * restrict s1,
19369              rsize_t s1max,
19370              const char * restrict s2,
19371              rsize_t n);
19372         char *strtok_s(char * restrict s1,
19373              rsize_t * restrict s1max,
19374              const char * restrict s2,
19375              char ** restrict ptr);
19376         errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n)
19377         errno_t strerror_s(char *s, rsize_t maxsize,
19378              errno_t errnum);
19379         size_t strerrorlen_s(errno_t errnum);
19380
19381 [page 489]
19382
19383       size_t strnlen_s(const char *s, size_t maxsize);
19384 B.23 Type-generic math <tgmath.h>
19385       acos           sqrt              fmod             nextafter
19386       asin           fabs              frexp            nexttoward
19387       atan           atan2             hypot            remainder
19388       acosh          cbrt              ilogb            remquo
19389       asinh          ceil              ldexp            rint
19390       atanh          copysign          lgamma           round
19391       cos            erf               llrint           scalbn
19392       sin            erfc              llround          scalbln
19393       tan            exp2              log10            tgamma
19394       cosh           expm1             log1p            trunc
19395       sinh           fdim              log2             carg
19396       tanh           floor             logb             cimag
19397       exp            fma               lrint            conj
19398       log            fmax              lround           cproj
19399       pow            fmin              nearbyint        creal
19400 B.24 Threads <threads.h>
19401       ONCE_FLAG_INIT                   mtx_plain
19402       TSS_DTOR_ITERATIONS              mtx_recursive
19403       cnd_t                            mtx_timed
19404       thrd_t                           mtx_try
19405       tss_t                            thrd_timeout
19406       mtx_t                            thrd_success
19407       tss_dtor_t                       thrd_busy
19408       thrd_start_t                     thrd_error
19409       once_flag                        thrd_nomem
19410       xtime
19411       void call_once(once_flag *flag, void (*func)(void));
19412       int cnd_broadcast(cnd_t *cond);
19413       void cnd_destroy(cnd_t *cond);
19414       int cnd_init(cnd_t *cond);
19415       int cnd_signal(cnd_t *cond);
19416       int cnd_timedwait(cnd_t *cond, mtx_t *mtx,
19417            const xtime *xt);
19418       int cnd_wait(cnd_t *cond, mtx_t *mtx);
19419       void mtx_destroy(mtx_t *mtx);
19420       int mtx_init(mtx_t *mtx, int type);
19421       int mtx_lock(mtx_t *mtx);
19422 [page 490]
19423
19424         int mtx_timedlock(mtx_t *mtx, const xtime *xt);
19425         int mtx_trylock(mtx_t *mtx);
19426         int mtx_unlock(mtx_t *mtx);
19427         int thrd_create(thrd_t *thr, thrd_start_t func,
19428              void *arg);
19429         thrd_t thrd_current(void);
19430         int thrd_detach(thrd_t thr);
19431         int thrd_equal(thrd_t thr0, thrd_t thr1);
19432         void thrd_exit(int res);
19433         int thrd_join(thrd_t thr, int *res);
19434         void thrd_sleep(const xtime *xt);
19435         void thrd_yield(void);
19436         int tss_create(tss_t *key, tss_dtor_t dtor);
19437         void tss_delete(tss_t key);
19438         void *tss_get(tss_t key);
19439         int tss_set(tss_t key, void *val);
19440         int xtime_get(xtime *xt, int base);
19441 B.25 Date and time <time.h>
19442         NULL                size_t                   time_t
19443         CLOCKS_PER_SEC      clock_t                  struct tm
19444         clock_t clock(void);
19445         double difftime(time_t time1, time_t time0);
19446         time_t mktime(struct tm *timeptr);
19447         time_t time(time_t *timer);
19448         char *asctime(const struct tm *timeptr);
19449         char *ctime(const time_t *timer);
19450         struct tm *gmtime(const time_t *timer);
19451         struct tm *localtime(const time_t *timer);
19452         size_t strftime(char * restrict s,
19453              size_t maxsize,
19454              const char * restrict format,
19455              const struct tm * restrict timeptr);
19456         __STDC_WANT_LIB_EXT1__
19457         errno_t
19458         rsize_t
19459         errno_t asctime_s(char *s, rsize_t maxsize,
19460              const struct tm *timeptr);
19461
19462
19463
19464 [page 491]
19465
19466       errno_t ctime_s(char *s, rsize_t maxsize,
19467            const time_t *timer);
19468       struct tm *gmtime_s(const time_t * restrict timer,
19469            struct tm * restrict result);
19470       struct tm *localtime_s(const time_t * restrict timer,
19471            struct tm * restrict result);
19472 B.26 Unicode utilities <uchar.h>
19473       mbstate_t      size_t            char16_t         char32_t
19474       size_t mbrtoc16(char16_t * restrict pc16,
19475            const char * restrict s, size_t n,
19476            mbstate_t * restrict ps);
19477       size_t c16rtomb(char * restrict s, char16_t c16,
19478            mbstate_t * restrict ps);
19479       size_t mbrtoc32(char32_t * restrict pc32,
19480            const char * restrict s, size_t n,
19481            mbstate_t * restrict ps);
19482       size_t c32rtomb(char * restrict s, char32_t c32,
19483            mbstate_t * restrict ps);
19484 B.27 Extended multibyte/wide character utilities <wchar.h>
19485       wchar_t              wint_t                   WCHAR_MAX
19486       size_t               struct tm                WCHAR_MIN
19487       mbstate_t            NULL                     WEOF
19488       int fwprintf(FILE * restrict stream,
19489            const wchar_t * restrict format, ...);
19490       int fwscanf(FILE * restrict stream,
19491            const wchar_t * restrict format, ...);
19492       int swprintf(wchar_t * restrict s, size_t n,
19493            const wchar_t * restrict format, ...);
19494       int swscanf(const wchar_t * restrict s,
19495            const wchar_t * restrict format, ...);
19496       int vfwprintf(FILE * restrict stream,
19497            const wchar_t * restrict format, va_list arg);
19498       int vfwscanf(FILE * restrict stream,
19499            const wchar_t * restrict format, va_list arg);
19500       int vswprintf(wchar_t * restrict s, size_t n,
19501            const wchar_t * restrict format, va_list arg);
19502
19503
19504
19505 [page 492]
19506
19507         int vswscanf(const wchar_t * restrict s,
19508              const wchar_t * restrict format, va_list arg);
19509         int vwprintf(const wchar_t * restrict format,
19510              va_list arg);
19511         int vwscanf(const wchar_t * restrict format,
19512              va_list arg);
19513         int wprintf(const wchar_t * restrict format, ...);
19514         int wscanf(const wchar_t * restrict format, ...);
19515         wint_t fgetwc(FILE *stream);
19516         wchar_t *fgetws(wchar_t * restrict s, int n,
19517              FILE * restrict stream);
19518         wint_t fputwc(wchar_t c, FILE *stream);
19519         int fputws(const wchar_t * restrict s,
19520              FILE * restrict stream);
19521         int fwide(FILE *stream, int mode);
19522         wint_t getwc(FILE *stream);
19523         wint_t getwchar(void);
19524         wint_t putwc(wchar_t c, FILE *stream);
19525         wint_t putwchar(wchar_t c);
19526         wint_t ungetwc(wint_t c, FILE *stream);
19527         double wcstod(const wchar_t * restrict nptr,
19528              wchar_t ** restrict endptr);
19529         float wcstof(const wchar_t * restrict nptr,
19530              wchar_t ** restrict endptr);
19531         long double wcstold(const wchar_t * restrict nptr,
19532              wchar_t ** restrict endptr);
19533         long int wcstol(const wchar_t * restrict nptr,
19534              wchar_t ** restrict endptr, int base);
19535         long long int wcstoll(const wchar_t * restrict nptr,
19536              wchar_t ** restrict endptr, int base);
19537         unsigned long int wcstoul(const wchar_t * restrict nptr,
19538              wchar_t ** restrict endptr, int base);
19539         unsigned long long int wcstoull(
19540              const wchar_t * restrict nptr,
19541              wchar_t ** restrict endptr, int base);
19542         wchar_t *wcscpy(wchar_t * restrict s1,
19543              const wchar_t * restrict s2);
19544         wchar_t *wcsncpy(wchar_t * restrict s1,
19545              const wchar_t * restrict s2, size_t n);
19546
19547
19548
19549 [page 493]
19550
19551       wchar_t *wmemcpy(wchar_t * restrict s1,
19552            const wchar_t * restrict s2, size_t n);
19553       wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2,
19554            size_t n);
19555       wchar_t *wcscat(wchar_t * restrict s1,
19556            const wchar_t * restrict s2);
19557       wchar_t *wcsncat(wchar_t * restrict s1,
19558            const wchar_t * restrict s2, size_t n);
19559       int wcscmp(const wchar_t *s1, const wchar_t *s2);
19560       int wcscoll(const wchar_t *s1, const wchar_t *s2);
19561       int wcsncmp(const wchar_t *s1, const wchar_t *s2,
19562            size_t n);
19563       size_t wcsxfrm(wchar_t * restrict s1,
19564            const wchar_t * restrict s2, size_t n);
19565       int wmemcmp(const wchar_t *s1, const wchar_t *s2,
19566            size_t n);
19567       wchar_t *wcschr(const wchar_t *s, wchar_t c);
19568       size_t wcscspn(const wchar_t *s1, const wchar_t *s2);
19569       wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2);
19570       wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
19571       size_t wcsspn(const wchar_t *s1, const wchar_t *s2);
19572       wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);
19573       wchar_t *wcstok(wchar_t * restrict s1,
19574            const wchar_t * restrict s2,
19575            wchar_t ** restrict ptr);
19576       wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n);
19577       size_t wcslen(const wchar_t *s);
19578       wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);
19579       size_t wcsftime(wchar_t * restrict s, size_t maxsize,
19580            const wchar_t * restrict format,
19581            const struct tm * restrict timeptr);
19582       wint_t btowc(int c);
19583       int wctob(wint_t c);
19584       int mbsinit(const mbstate_t *ps);
19585       size_t mbrlen(const char * restrict s, size_t n,
19586            mbstate_t * restrict ps);
19587       size_t mbrtowc(wchar_t * restrict pwc,
19588            const char * restrict s, size_t n,
19589            mbstate_t * restrict ps);
19590
19591
19592
19593 [page 494]
19594
19595         size_t wcrtomb(char * restrict s, wchar_t wc,
19596              mbstate_t * restrict ps);
19597         size_t mbsrtowcs(wchar_t * restrict dst,
19598              const char ** restrict src, size_t len,
19599              mbstate_t * restrict ps);
19600         size_t wcsrtombs(char * restrict dst,
19601              const wchar_t ** restrict src, size_t len,
19602              mbstate_t * restrict ps);
19603         __STDC_WANT_LIB_EXT1__
19604         errno_t
19605         rsize_t
19606         int fwprintf_s(FILE * restrict stream,
19607              const wchar_t * restrict format, ...);
19608         int fwscanf_s(FILE * restrict stream,
19609              const wchar_t * restrict format, ...);
19610         int snwprintf_s(wchar_t * restrict s,
19611              rsize_t n,
19612              const wchar_t * restrict format, ...);
19613         int swprintf_s(wchar_t * restrict s, rsize_t n,
19614              const wchar_t * restrict format, ...);
19615         int swscanf_s(const wchar_t * restrict s,
19616              const wchar_t * restrict format, ...);
19617         int vfwprintf_s(FILE * restrict stream,
19618              const wchar_t * restrict format,
19619              va_list arg);
19620         int vfwscanf_s(FILE * restrict stream,
19621              const wchar_t * restrict format, va_list arg);
19622         int vsnwprintf_s(wchar_t * restrict s,
19623              rsize_t n,
19624              const wchar_t * restrict format,
19625              va_list arg);
19626         int vswprintf_s(wchar_t * restrict s,
19627              rsize_t n,
19628              const wchar_t * restrict format,
19629              va_list arg);
19630         int vswscanf_s(const wchar_t * restrict s,
19631              const wchar_t * restrict format,
19632              va_list arg);
19633
19634
19635
19636 [page 495]
19637
19638       int vwprintf_s(const wchar_t * restrict format,
19639            va_list arg);
19640       int vwscanf_s(const wchar_t * restrict format,
19641            va_list arg);
19642       int wprintf_s(const wchar_t * restrict format, ...);
19643       int wscanf_s(const wchar_t * restrict format, ...);
19644       errno_t wcscpy_s(wchar_t * restrict s1,
19645            rsize_t s1max,
19646            const wchar_t * restrict s2);
19647       errno_t wcsncpy_s(wchar_t * restrict s1,
19648            rsize_t s1max,
19649            const wchar_t * restrict s2,
19650            rsize_t n);
19651       errno_t wmemcpy_s(wchar_t * restrict s1,
19652            rsize_t s1max,
19653            const wchar_t * restrict s2,
19654            rsize_t n);
19655       errno_t wmemmove_s(wchar_t *s1, rsize_t s1max,
19656            const wchar_t *s2, rsize_t n);
19657       errno_t wcscat_s(wchar_t * restrict s1,
19658            rsize_t s1max,
19659            const wchar_t * restrict s2);
19660       errno_t wcsncat_s(wchar_t * restrict s1,
19661            rsize_t s1max,
19662            const wchar_t * restrict s2,
19663            rsize_t n);
19664       wchar_t *wcstok_s(wchar_t * restrict s1,
19665            rsize_t * restrict s1max,
19666            const wchar_t * restrict s2,
19667            wchar_t ** restrict ptr);
19668       size_t wcsnlen_s(const wchar_t *s, size_t maxsize);
19669       errno_t wcrtomb_s(size_t * restrict retval,
19670            char * restrict s, rsize_t smax,
19671            wchar_t wc, mbstate_t * restrict ps);
19672       errno_t mbsrtowcs_s(size_t * restrict retval,
19673            wchar_t * restrict dst, rsize_t dstmax,
19674            const char ** restrict src, rsize_t len,
19675            mbstate_t * restrict ps);
19676
19677
19678
19679
19680 [page 496]
19681
19682         errno_t wcsrtombs_s(size_t * restrict retval,
19683              char * restrict dst, rsize_t dstmax,
19684              const wchar_t ** restrict src, rsize_t len,
19685              mbstate_t * restrict ps);
19686 B.28 Wide character classification and mapping utilities <wctype.h>
19687         wint_t       wctrans_t         wctype_t         WEOF
19688         int iswalnum(wint_t wc);
19689         int iswalpha(wint_t wc);
19690         int iswblank(wint_t wc);
19691         int iswcntrl(wint_t wc);
19692         int iswdigit(wint_t wc);
19693         int iswgraph(wint_t wc);
19694         int iswlower(wint_t wc);
19695         int iswprint(wint_t wc);
19696         int iswpunct(wint_t wc);
19697         int iswspace(wint_t wc);
19698         int iswupper(wint_t wc);
19699         int iswxdigit(wint_t wc);
19700         int iswctype(wint_t wc, wctype_t desc);
19701         wctype_t wctype(const char *property);
19702         wint_t towlower(wint_t wc);
19703         wint_t towupper(wint_t wc);
19704         wint_t towctrans(wint_t wc, wctrans_t desc);
19705         wctrans_t wctrans(const char *property);
19706
19707
19708
19709
19710 [page 497]
19711
19712                                           Annex C
19713                                         (informative)
19714                                       Sequence points
19715 1   The following are the sequence points described in 5.1.2.3:
19716     -- Between the evaluations of the function designator and actual arguments in a function
19717       call and the actual call. (6.5.2.2).
19718     -- Between the evaluations of the first and second operands of the following operators:
19719       logical AND && (6.5.13); logical OR || (6.5.14); comma , (6.5.17).
19720     -- Between the evaluations of the first operand of the conditional ? : operator and
19721       whichever of the second and third operands is evaluated (6.5.15).
19722     -- The end of a full declarator: declarators (6.7.6);
19723     -- Between the evaluation of a full expression and the next full expression to be
19724       evaluated. The following are full expressions: an initializer that is not part of a
19725       compound literal (6.7.9); the expression in an expression statement (6.8.3); the
19726       controlling expression of a selection statement (if or switch) (6.8.4); the
19727       controlling expression of a while or do statement (6.8.5); each of the (optional)
19728       expressions of a for statement (6.8.5.3); the (optional) expression in a return
19729       statement (6.8.6.4).
19730     -- Immediately before a library function returns (7.1.4).
19731     -- After the actions associated with each formatted input/output function conversion
19732       specifier (7.21.6, 7.28.2).
19733     -- Immediately before and immediately after each call to a comparison function, and
19734       also between any call to a comparison function and any movement of the objects
19735       passed as arguments to that call (7.22.5).
19736
19737
19738
19739
19740 [page 498]
19741
19742                                          Annex D
19743                                         (normative)
19744                    Universal character names for identifiers
19745 1   This clause lists the hexadecimal code values that are valid in universal character names
19746     in identifiers.
19747 2   This table is reproduced unchanged from ISO/IEC TR 10176:1998, produced by ISO/IEC
19748     JTC 1/SC 22/WG 20, except for the omission of ranges that are part of the basic character
19749     sets.
19750     Latin:            00AA, 00BA, 00C0-00D6, 00D8-00F6, 00F8-01F5, 01FA-0217,
19751                       0250-02A8, 1E00-1E9B, 1EA0-1EF9, 207F
19752     Greek:            0386, 0388-038A, 038C, 038E-03A1, 03A3-03CE, 03D0-03D6,
19753                       03DA, 03DC, 03DE, 03E0, 03E2-03F3, 1F00-1F15, 1F18-1F1D,
19754                       1F20-1F45, 1F48-1F4D, 1F50-1F57, 1F59, 1F5B, 1F5D,
19755                       1F5F-1F7D, 1F80-1FB4, 1FB6-1FBC, 1FC2-1FC4, 1FC6-1FCC,
19756                       1FD0-1FD3, 1FD6-1FDB, 1FE0-1FEC, 1FF2-1FF4, 1FF6-1FFC
19757     Cyrillic:         0401-040C, 040E-044F, 0451-045C, 045E-0481, 0490-04C4,
19758                       04C7-04C8, 04CB-04CC, 04D0-04EB, 04EE-04F5, 04F8-04F9
19759     Armenian:         0531-0556, 0561-0587
19760     Hebrew:           05B0-05B9,      05BB-05BD,       05BF,   05C1-05C2,      05D0-05EA,
19761                       05F0-05F2
19762     Arabic:           0621-063A, 0640-0652, 0670-06B7, 06BA-06BE, 06C0-06CE,
19763                       06D0-06DC, 06E5-06E8, 06EA-06ED
19764     Devanagari:       0901-0903, 0905-0939, 093E-094D, 0950-0952, 0958-0963
19765     Bengali:          0981-0983, 0985-098C, 098F-0990, 0993-09A8, 09AA-09B0,
19766                       09B2, 09B6-09B9, 09BE-09C4, 09C7-09C8, 09CB-09CD,
19767                       09DC-09DD, 09DF-09E3, 09F0-09F1
19768     Gurmukhi:         0A02, 0A05-0A0A, 0A0F-0A10, 0A13-0A28, 0A2A-0A30,
19769                       0A32-0A33, 0A35-0A36, 0A38-0A39, 0A3E-0A42, 0A47-0A48,
19770                       0A4B-0A4D, 0A59-0A5C, 0A5E, 0A74
19771     Gujarati:         0A81-0A83, 0A85-0A8B, 0A8D, 0A8F-0A91, 0A93-0AA8,
19772                       0AAA-0AB0,    0AB2-0AB3,     0AB5-0AB9, 0ABD-0AC5,
19773                       0AC7-0AC9, 0ACB-0ACD, 0AD0, 0AE0
19774     Oriya:            0B01-0B03, 0B05-0B0C, 0B0F-0B10, 0B13-0B28, 0B2A-0B30,
19775                       0B32-0B33, 0B36-0B39, 0B3E-0B43, 0B47-0B48, 0B4B-0B4D,
19776 [page 499]
19777
19778                 0B5C-0B5D, 0B5F-0B61
19779 Tamil:          0B82-0B83, 0B85-0B8A, 0B8E-0B90, 0B92-0B95, 0B99-0B9A,
19780                 0B9C, 0B9E-0B9F, 0BA3-0BA4, 0BA8-0BAA, 0BAE-0BB5,
19781                 0BB7-0BB9, 0BBE-0BC2, 0BC6-0BC8, 0BCA-0BCD
19782 Telugu:         0C01-0C03, 0C05-0C0C, 0C0E-0C10, 0C12-0C28, 0C2A-0C33,
19783                 0C35-0C39, 0C3E-0C44, 0C46-0C48, 0C4A-0C4D, 0C60-0C61
19784 Kannada:        0C82-0C83, 0C85-0C8C, 0C8E-0C90, 0C92-0CA8, 0CAA-0CB3,
19785                 0CB5-0CB9, 0CBE-0CC4, 0CC6-0CC8, 0CCA-0CCD, 0CDE,
19786                 0CE0-0CE1
19787 Malayalam:      0D02-0D03, 0D05-0D0C, 0D0E-0D10, 0D12-0D28, 0D2A-0D39,
19788                 0D3E-0D43, 0D46-0D48, 0D4A-0D4D, 0D60-0D61
19789 Thai:           0E01-0E3A, 0E40-0E5B
19790 Lao:            0E81-0E82, 0E84, 0E87-0E88, 0E8A, 0E8D, 0E94-0E97,
19791                 0E99-0E9F,   0EA1-0EA3,  0EA5,  0EA7,  0EAA-0EAB,
19792                 0EAD-0EAE, 0EB0-0EB9, 0EBB-0EBD, 0EC0-0EC4, 0EC6,
19793                 0EC8-0ECD, 0EDC-0EDD
19794 Tibetan:        0F00, 0F18-0F19, 0F35, 0F37, 0F39, 0F3E-0F47, 0F49-0F69,
19795                 0F71-0F84, 0F86-0F8B, 0F90-0F95, 0F97, 0F99-0FAD,
19796                 0FB1-0FB7, 0FB9
19797 Georgian:       10A0-10C5, 10D0-10F6
19798 Hiragana:       3041-3093, 309B-309C
19799 Katakana:       30A1-30F6, 30FB-30FC
19800 Bopomofo:       3105-312C
19801 CJK Unified Ideographs: 4E00-9FA5
19802 Hangul:         AC00-D7A3
19803 Digits:         0660-0669, 06F0-06F9, 0966-096F, 09E6-09EF, 0A66-0A6F,
19804                 0AE6-0AEF, 0B66-0B6F, 0BE7-0BEF, 0C66-0C6F, 0CE6-0CEF,
19805                 0D66-0D6F, 0E50-0E59, 0ED0-0ED9, 0F20-0F33
19806 Special characters: 00B5, 00B7, 02B0-02B8, 02BB, 02BD-02C1, 02D0-02D1,
19807                    02E0-02E4, 037A, 0559, 093D, 0B3D, 1FBE, 203F-2040, 2102,
19808                    2107, 210A-2113, 2115, 2118-211D, 2124, 2126, 2128, 212A-2131,
19809                    2133-2138, 2160-2182, 3005-3007, 3021-3029
19810
19811
19812
19813
19814 [page 500]
19815
19816                                          Annex E
19817                                        (informative)
19818                                 Implementation limits
19819 1   The contents of the header <limits.h> are given below, in alphabetical order. The
19820     minimum magnitudes shown shall be replaced by implementation-defined magnitudes
19821     with the same sign. The values shall all be constant expressions suitable for use in #if
19822     preprocessing directives. The components are described further in 5.2.4.2.1.
19823             #define    CHAR_BIT                               8
19824             #define    CHAR_MAX          UCHAR_MAX or SCHAR_MAX
19825             #define    CHAR_MIN                  0 or SCHAR_MIN
19826             #define    INT_MAX                           +32767
19827             #define    INT_MIN                           -32767
19828             #define    LONG_MAX                     +2147483647
19829             #define    LONG_MIN                     -2147483647
19830             #define    LLONG_MAX           +9223372036854775807
19831             #define    LLONG_MIN           -9223372036854775807
19832             #define    MB_LEN_MAX                             1
19833             #define    SCHAR_MAX                           +127
19834             #define    SCHAR_MIN                           -127
19835             #define    SHRT_MAX                          +32767
19836             #define    SHRT_MIN                          -32767
19837             #define    UCHAR_MAX                            255
19838             #define    USHRT_MAX                          65535
19839             #define    UINT_MAX                           65535
19840             #define    ULONG_MAX                     4294967295
19841             #define    ULLONG_MAX          18446744073709551615
19842 2   The contents of the header <float.h> are given below. All integer values, except
19843     FLT_ROUNDS, shall be constant expressions suitable for use in #if preprocessing
19844     directives; all floating values shall be constant expressions. The components are
19845     described further in 5.2.4.2.2.
19846 3   The values given in the following list shall be replaced by implementation-defined
19847     expressions:
19848             #define FLT_EVAL_METHOD
19849             #define FLT_ROUNDS
19850 4   The values given in the following list shall be replaced by implementation-defined
19851     constant expressions that are greater or equal in magnitude (absolute value) to those
19852     shown, with the same sign:
19853 [page 501]
19854
19855            #define    DLB_DECIMAL_DIG                                10
19856            #define    DBL_DIG                                        10
19857            #define    DBL_MANT_DIG
19858            #define    DBL_MAX_10_EXP                               +37
19859            #define    DBL_MAX_EXP
19860            #define    DBL_MIN_10_EXP                               -37
19861            #define    DBL_MIN_EXP
19862            #define    DECIMAL_DIG                                    10
19863            #define    FLT_DECIMAL_DIG                                 6
19864            #define    FLT_DIG                                         6
19865            #define    FLT_MANT_DIG
19866            #define    FLT_MAX_10_EXP                               +37
19867            #define    FLT_MAX_EXP
19868            #define    FLT_MIN_10_EXP                               -37
19869            #define    FLT_MIN_EXP
19870            #define    FLT_RADIX                                       2
19871            #define    LDLB_DECIMAL_DIG                               10
19872            #define    LDBL_DIG                                       10
19873            #define    LDBL_MANT_DIG
19874            #define    LDBL_MAX_10_EXP                              +37
19875            #define    LDBL_MAX_EXP
19876            #define    LDBL_MIN_10_EXP                              -37
19877            #define    LDBL_MIN_EXP
19878 5   The values given in the following list shall be replaced by implementation-defined
19879     constant expressions with values that are greater than or equal to those shown:
19880            #define DBL_MAX                                      1E+37
19881            #define FLT_MAX                                      1E+37
19882            #define LDBL_MAX                                     1E+37
19883 6   The values given in the following list shall be replaced by implementation-defined
19884     constant expressions with (positive) values that are less than or equal to those shown:
19885            #define    DBL_EPSILON                                1E-9
19886            #define    DBL_MIN                                   1E-37
19887            #define    FLT_EPSILON                                1E-5
19888            #define    FLT_MIN                                   1E-37
19889            #define    LDBL_EPSILON                               1E-9
19890            #define    LDBL_MIN                                  1E-37
19891
19892
19893
19894
19895 [page 502]
19896
19897                                                Annex F
19898                                               (normative)
19899                           IEC 60559 floating-point arithmetic
19900     F.1 Introduction
19901 1   This annex specifies C language support for the IEC 60559 floating-point standard. The
19902     IEC 60559 floating-point standard is specifically Binary floating-point arithmetic for
19903     microprocessor systems, second edition (IEC 60559:1989), previously designated
19904     IEC 559:1989 and as IEEE Standard for Binary Floating-Point Arithmetic
19905     (ANSI/IEEE 754-1985). IEEE Standard for Radix-Independent Floating-Point
19906     Arithmetic (ANSI/IEEE 854-1987) generalizes the binary standard to remove
19907     dependencies on radix and word length. IEC 60559 generally refers to the floating-point
19908     standard, as in IEC 60559 operation, IEC 60559 format, etc. An implementation that
19909     defines __STDC_IEC_559__ shall conform to the specifications in this annex.339)
19910     Where a binding between the C language and IEC 60559 is indicated, the
19911     IEC 60559-specified behavior is adopted by reference, unless stated otherwise. Since
19912     negative and positive infinity are representable in IEC 60559 formats, all real numbers lie
19913     within the range of representable values.
19914     F.2 Types
19915 1   The C floating types match the IEC 60559 formats as follows:
19916     -- The float type matches the IEC 60559 single format.
19917     -- The double type matches the IEC 60559 double format.
19918     -- The long double type matches an IEC 60559 extended format,340) else a
19919       non-IEC 60559 extended format, else the IEC 60559 double format.
19920     Any non-IEC 60559 extended format used for the long double type shall have more
19921     precision than IEC 60559 double and at least the range of IEC 60559 double.341)
19922
19923
19924
19925
19926     339) Implementations that do not define __STDC_IEC_559__ are not required to conform to these
19927          specifications.
19928     340) ''Extended'' is IEC 60559's double-extended data format. Extended refers to both the common 80-bit
19929          and quadruple 128-bit IEC 60559 formats.
19930     341) A non-IEC 60559 long double type is required to provide infinity and NaNs, as its values include
19931          all double values.
19932
19933 [page 503]
19934
19935     Recommended practice
19936 2   The long double type should match an IEC 60559 extended format.
19937     F.2.1 Infinities, signed zeros, and NaNs
19938 1   This specification does not define the behavior of signaling NaNs.342) It generally uses
19939     the term NaN to denote quiet NaNs. The NAN and INFINITY macros and the nan
19940     functions in <math.h> provide designations for IEC 60559 NaNs and infinities.
19941     F.3 Operators and functions
19942 1   C operators and functions provide IEC 60559 required and recommended facilities as
19943     listed below.
19944     -- The +, -, *, and / operators provide the IEC 60559 add, subtract, multiply, and
19945       divide operations.
19946     -- The sqrt functions in <math.h> provide the IEC 60559 square root operation.
19947     -- The remainder functions in <math.h> provide the IEC 60559 remainder
19948       operation. The remquo functions in <math.h> provide the same operation but
19949       with additional information.
19950     -- The rint functions in <math.h> provide the IEC 60559 operation that rounds a
19951       floating-point number to an integer value (in the same precision). The nearbyint
19952       functions in <math.h> provide the nearbyinteger function recommended in the
19953       Appendix to ANSI/IEEE 854.
19954     -- The conversions for floating types provide the IEC 60559 conversions between
19955       floating-point precisions.
19956     -- The conversions from integer to floating types provide the IEC 60559 conversions
19957       from integer to floating point.
19958     -- The conversions from floating to integer types provide IEC 60559-like conversions
19959       but always round toward zero.
19960     -- The lrint and llrint functions in <math.h> provide the IEC 60559
19961       conversions, which honor the directed rounding mode, from floating point to the
19962       long int and long long int integer formats. The lrint and llrint
19963       functions can be used to implement IEC 60559 conversions from floating to other
19964       integer formats.
19965     -- The translation time conversion of floating constants and the strtod, strtof,
19966       strtold, fprintf, fscanf, and related library functions in <stdlib.h>,
19967
19968
19969     342) Since NaNs created by IEC 60559 operations are always quiet, quiet NaNs (along with infinities) are
19970          sufficient for closure of the arithmetic.
19971
19972 [page 504]
19973
19974    <stdio.h>, and <wchar.h> provide IEC 60559 binary-decimal conversions. The
19975    strtold function in <stdlib.h> provides the conv function recommended in the
19976    Appendix to ANSI/IEEE 854.
19977 -- The relational and equality operators provide IEC 60559 comparisons. IEC 60559
19978   identifies a need for additional comparison predicates to facilitate writing code that
19979   accounts for NaNs. The comparison macros (isgreater, isgreaterequal,
19980   isless, islessequal, islessgreater, and isunordered) in <math.h>
19981   supplement the language operators to address this need. The islessgreater and
19982   isunordered macros provide respectively a quiet version of the <> predicate and
19983   the unordered predicate recommended in the Appendix to IEC 60559.
19984 -- The feclearexcept, feraiseexcept, and fetestexcept functions in
19985   <fenv.h> provide the facility to test and alter the IEC 60559 floating-point
19986   exception status flags. The fegetexceptflag and fesetexceptflag
19987   functions in <fenv.h> provide the facility to save and restore all five status flags at
19988   one time. These functions are used in conjunction with the type fexcept_t and the
19989   floating-point     exception      macros      (FE_INEXACT,         FE_DIVBYZERO,
19990   FE_UNDERFLOW, FE_OVERFLOW, FE_INVALID) also in <fenv.h>.
19991 -- The fegetround and fesetround functions in <fenv.h> provide the facility
19992   to select among the IEC 60559 directed rounding modes represented by the rounding
19993   direction macros in <fenv.h> (FE_TONEAREST, FE_UPWARD, FE_DOWNWARD,
19994   FE_TOWARDZERO) and the values 0, 1, 2, and 3 of FLT_ROUNDS are the
19995   IEC 60559 directed rounding modes.
19996 -- The fegetenv, feholdexcept, fesetenv, and feupdateenv functions in
19997   <fenv.h> provide a facility to manage the floating-point environment, comprising
19998   the IEC 60559 status flags and control modes.
19999 -- The copysign functions in <math.h> provide the copysign function
20000   recommended in the Appendix to IEC 60559.
20001 -- The fabs functions in <math.h> provide the abs function recommended in the
20002   Appendix to IEC 60559.
20003 -- The unary minus (-) operator provides the unary minus (-) operation recommended
20004   in the Appendix to IEC 60559.
20005 -- The scalbn and scalbln functions in <math.h> provide the scalb function
20006   recommended in the Appendix to IEC 60559.
20007 -- The logb functions in <math.h> provide the logb function recommended in the
20008   Appendix to IEC 60559, but following the newer specifications in ANSI/IEEE 854.
20009 -- The nextafter and nexttoward functions in <math.h> provide the nextafter
20010   function recommended in the Appendix to IEC 60559 (but with a minor change to
20011
20012 [page 505]
20013
20014         better handle signed zeros).
20015     -- The isfinite macro in <math.h> provides the finite function recommended in
20016       the Appendix to IEC 60559.
20017     -- The isnan macro in <math.h> provides the isnan function recommended in the
20018       Appendix to IEC 60559.
20019     -- The signbit macro and the fpclassify macro in <math.h>, used in
20020       conjunction with the number classification macros (FP_NAN, FP_INFINITE,
20021       FP_NORMAL, FP_SUBNORMAL, FP_ZERO), provide the facility of the class
20022       function recommended in the Appendix to IEC 60559 (except that the classification
20023       macros defined in 7.12.3 do not distinguish signaling from quiet NaNs).
20024     F.4 Floating to integer conversion
20025 1   If the integer type is _Bool, 6.3.1.2 applies and no floating-point exceptions are raised
20026     (even for NaN). Otherwise, if the floating value is infinite or NaN or if the integral part
20027     of the floating value exceeds the range of the integer type, then the ''invalid'' floating-
20028     point exception is raised and the resulting value is unspecified. Otherwise, the resulting
20029     value is determined by 6.3.1.4. Conversion of an integral floating value that does not
20030     exceed the range of the integer type raises no floating-point exceptions; whether
20031     conversion of a non-integral floating value raises the ''inexact'' floating-point exception is
20032     unspecified.343)
20033     F.5 Binary-decimal conversion
20034 1   Conversion from the widest supported IEC 60559 format to decimal with
20035     DECIMAL_DIG digits and back is the identity function.344)
20036 2   Conversions involving IEC 60559 formats follow all pertinent recommended practice. In
20037     particular, conversion between any supported IEC 60559 format and decimal with
20038     DECIMAL_DIG or fewer significant digits is correctly rounded (honoring the current
20039     rounding mode), which assures that conversion from the widest supported IEC 60559
20040     format to decimal with DECIMAL_DIG digits and back is the identity function.
20041
20042
20043
20044     343) ANSI/IEEE 854, but not IEC 60559 (ANSI/IEEE 754), directly specifies that floating-to-integer
20045          conversions raise the ''inexact'' floating-point exception for non-integer in-range values. In those
20046          cases where it matters, library functions can be used to effect such conversions with or without raising
20047          the ''inexact'' floating-point exception. See rint, lrint, llrint, and nearbyint in
20048          <math.h>.
20049     344) If the minimum-width IEC 60559 extended format (64 bits of precision) is supported,
20050          DECIMAL_DIG shall be at least 21. If IEC 60559 double (53 bits of precision) is the widest
20051          IEC 60559 format supported, then DECIMAL_DIG shall be at least 17. (By contrast, LDBL_DIG and
20052          DBL_DIG are 18 and 15, respectively, for these formats.)
20053
20054 [page 506]
20055
20056 3   Functions such as strtod that convert character sequences to floating types honor the
20057     rounding direction. Hence, if the rounding direction might be upward or downward, the
20058     implementation cannot convert a minus-signed sequence by negating the converted
20059     unsigned sequence.
20060     F.6 The return statement
20061     If the return expression is evaluated in a floating-point format different from the return
20062     type, the expression is converted to the return type of the function and the resulting value
20063     is returned to the caller.
20064     F.7 Contracted expressions
20065 1   A contracted expression is correctly rounded (once) and treats infinities, NaNs, signed
20066     zeros, subnormals, and the rounding directions in a manner consistent with the basic
20067     arithmetic operations covered by IEC 60559.
20068     Recommended practice
20069 2   A contracted expression should raise floating-point exceptions in a manner generally
20070     consistent with the basic arithmetic operations.
20071     F.8 Floating-point environment
20072 1   The floating-point environment defined in <fenv.h> includes the IEC 60559 floating-
20073     point exception status flags and directed-rounding control modes. It includes also
20074     IEC 60559 dynamic rounding precision and trap enablement modes, if the
20075     implementation supports them.345)
20076     F.8.1 Environment management
20077 1   IEC 60559 requires that floating-point operations implicitly raise floating-point exception
20078     status flags, and that rounding control modes can be set explicitly to affect result values of
20079     floating-point operations. When the state for the FENV_ACCESS pragma (defined in
20080     <fenv.h>) is ''on'', these changes to the floating-point state are treated as side effects
20081     which respect sequence points.346)
20082
20083
20084
20085
20086     345) This specification does not require dynamic rounding precision nor trap enablement modes.
20087     346) If the state for the FENV_ACCESS pragma is ''off'', the implementation is free to assume the floating-
20088          point control modes will be the default ones and the floating-point status flags will not be tested,
20089          which allows certain optimizations (see F.9).
20090
20091 [page 507]
20092
20093     F.8.2 Translation
20094 1   During translation the IEC 60559 default modes are in effect:
20095     -- The rounding direction mode is rounding to nearest.
20096     -- The rounding precision mode (if supported) is set so that results are not shortened.
20097     -- Trapping or stopping (if supported) is disabled on all floating-point exceptions.
20098     Recommended practice
20099 2   The implementation should produce a diagnostic message for each translation-time
20100     floating-point exception, other than ''inexact'';347) the implementation should then
20101     proceed with the translation of the program.
20102     F.8.3 Execution
20103 1   At program startup the floating-point environment is initialized as prescribed by
20104     IEC 60559:
20105     -- All floating-point exception status flags are cleared.
20106     -- The rounding direction mode is rounding to nearest.
20107     -- The dynamic rounding precision mode (if supported) is set so that results are not
20108       shortened.
20109     -- Trapping or stopping (if supported) is disabled on all floating-point exceptions.
20110     F.8.4 Constant expressions
20111 1   An arithmetic constant expression of floating type, other than one in an initializer for an
20112     object that has static or thread storage duration, is evaluated (as if) during execution; thus,
20113     it is affected by any operative floating-point control modes and raises floating-point
20114     exceptions as required by IEC 60559 (provided the state for the FENV_ACCESS pragma
20115     is ''on'').348)
20116 2   EXAMPLE
20117
20118
20119
20120     347) As floating constants are converted to appropriate internal representations at translation time, their
20121          conversion is subject to default rounding modes and raises no execution-time floating-point exceptions
20122          (even where the state of the FENV_ACCESS pragma is ''on''). Library functions, for example
20123          strtod, provide execution-time conversion of numeric strings.
20124     348) Where the state for the FENV_ACCESS pragma is ''on'', results of inexact expressions like 1.0/3.0
20125          are affected by rounding modes set at execution time, and expressions such as 0.0/0.0 and
20126          1.0/0.0 generate execution-time floating-point exceptions. The programmer can achieve the
20127          efficiency of translation-time evaluation through static initialization, such as
20128                   const static double one_third = 1.0/3.0;
20129
20130
20131 [page 508]
20132
20133              #include <fenv.h>
20134              #pragma STDC FENV_ACCESS ON
20135              void f(void)
20136              {
20137                    float w[] = { 0.0/0.0 };                  //   raises an exception
20138                    static float x = 0.0/0.0;                 //   does not raise an exception
20139                    float y = 0.0/0.0;                        //   raises an exception
20140                    double z = 0.0/0.0;                       //   raises an exception
20141                    /* ... */
20142              }
20143 3   For the static initialization, the division is done at translation time, raising no (execution-time) floating-
20144     point exceptions. On the other hand, for the three automatic initializations the invalid division occurs at
20145     execution time.
20146
20147     F.8.5 Initialization
20148 1   All computation for automatic initialization is done (as if) at execution time; thus, it is
20149     affected by any operative modes and raises floating-point exceptions as required by
20150     IEC 60559 (provided the state for the FENV_ACCESS pragma is ''on''). All computation
20151     for initialization of objects that have static or thread storage duration is done (as if) at
20152     translation time.
20153 2   EXAMPLE
20154              #include <fenv.h>
20155              #pragma STDC FENV_ACCESS ON
20156              void f(void)
20157              {
20158                    float u[] = { 1.1e75 };                  //   raises exceptions
20159                    static float v = 1.1e75;                 //   does not raise exceptions
20160                    float w = 1.1e75;                        //   raises exceptions
20161                    double x = 1.1e75;                       //   may raise exceptions
20162                    float y = 1.1e75f;                       //   may raise exceptions
20163                    long double z = 1.1e75;                  //   does not raise exceptions
20164                    /* ... */
20165              }
20166 3   The static initialization of v raises no (execution-time) floating-point exceptions because its computation is
20167     done at translation time. The automatic initialization of u and w require an execution-time conversion to
20168     float of the wider value 1.1e75, which raises floating-point exceptions. The automatic initializations
20169     of x and y entail execution-time conversion; however, in some expression evaluation methods, the
20170     conversions is not to a narrower format, in which case no floating-point exception is raised.349) The
20171     automatic initialization of z entails execution-time conversion, but not to a narrower format, so no floating-
20172     point exception is raised. Note that the conversions of the floating constants 1.1e75 and 1.1e75f to
20173
20174
20175
20176     349) Use of float_t and double_t variables increases the likelihood of translation-time computation.
20177          For example, the automatic initialization
20178                   double_t x = 1.1e75;
20179          could be done at translation time, regardless of the expression evaluation method.
20180
20181 [page 509]
20182
20183     their internal representations occur at translation time in all cases.
20184
20185     F.8.6 Changing the environment
20186 1   Operations defined in 6.5 and functions and macros defined for the standard libraries
20187     change floating-point status flags and control modes just as indicated by their
20188     specifications (including conformance to IEC 60559). They do not change flags or modes
20189     (so as to be detectable by the user) in any other cases.
20190 2   If the argument to the feraiseexcept function in <fenv.h> represents IEC 60559
20191     valid coincident floating-point exceptions for atomic operations (namely ''overflow'' and
20192     ''inexact'', or ''underflow'' and ''inexact''), then ''overflow'' or ''underflow'' is raised
20193     before ''inexact''.
20194     F.9 Optimization
20195 1   This section identifies code transformations that might subvert IEC 60559-specified
20196     behavior, and others that do not.
20197     F.9.1 Global transformations
20198 1   Floating-point arithmetic operations and external function calls may entail side effects
20199     which optimization shall honor, at least where the state of the FENV_ACCESS pragma is
20200     ''on''. The flags and modes in the floating-point environment may be regarded as global
20201     variables; floating-point operations (+, *, etc.) implicitly read the modes and write the
20202     flags.
20203 2   Concern about side effects may inhibit code motion and removal of seemingly useless
20204     code. For example, in
20205              #include <fenv.h>
20206              #pragma STDC FENV_ACCESS ON
20207              void f(double x)
20208              {
20209                   /* ... */
20210                   for (i = 0; i < n; i++) x + 1;
20211                   /* ... */
20212              }
20213     x + 1 might raise floating-point exceptions, so cannot be removed. And since the loop
20214     body might not execute (maybe 0 >= n), x + 1 cannot be moved out of the loop. (Of
20215     course these optimizations are valid if the implementation can rule out the nettlesome
20216     cases.)
20217 3   This specification does not require support for trap handlers that maintain information
20218     about the order or count of floating-point exceptions. Therefore, between function calls,
20219     floating-point exceptions need not be precise: the actual order and number of occurrences
20220     of floating-point exceptions (> 1) may vary from what the source code expresses. Thus,
20221 [page 510]
20222
20223     the preceding loop could be treated as
20224              if (0 < n) x + 1;
20225     F.9.2 Expression transformations
20226 1   x/2 (<->) x x 0.5          Although similar transformations involving inexact constants
20227                            generally do not yield numerically equivalent expressions, if the
20228                            constants are exact then such transformations can be made on
20229                            IEC 60559 machines and others that round perfectly.
20230     1 x x and x/1 (->) x The expressions 1 x x, x/1, and x are equivalent (on IEC 60559
20231                       machines, among others).350)
20232     x/x (->) 1.0             The expressions x/x and 1.0 are not equivalent if x can be zero,
20233                            infinite, or NaN.
20234     x - y (<->) x + (-y)       The expressions x - y, x + (-y), and (-y) + x are equivalent (on
20235                            IEC 60559 machines, among others).
20236     x - y (<->) -(y - x)       The expressions x - y and -(y - x) are not equivalent because 1 - 1
20237                            is +0 but -(1 - 1) is -0 (in the default rounding direction).351)
20238     x - x (->) 0.0           The expressions x - x and 0.0 are not equivalent if x is a NaN or
20239                            infinite.
20240     0 x x (->) 0.0           The expressions 0 x x and 0.0 are not equivalent if x is a NaN,
20241                            infinite, or -0.
20242     x+0(->) x                 The expressions x + 0 and x are not equivalent if x is -0, because
20243                            (-0) + (+0) yields +0 (in the default rounding direction), not -0.
20244     x-0(->) x                 (+0) - (+0) yields -0 when rounding is downward (toward -(inf)), but
20245                            +0 otherwise, and (-0) - (+0) always yields -0; so, if the state of the
20246                            FENV_ACCESS pragma is ''off'', promising default rounding, then
20247                            the implementation can replace x - 0 by x, even if x might be zero.
20248     -x (<->) 0 - x             The expressions -x and 0 - x are not equivalent if x is +0, because
20249                            -(+0) yields -0, but 0 - (+0) yields +0 (unless rounding is
20250                            downward).
20251
20252     350) Strict support for signaling NaNs -- not required by this specification -- would invalidate these and
20253          other transformations that remove arithmetic operators.
20254     351) IEC 60559 prescribes a signed zero to preserve mathematical identities across certain discontinuities.
20255          Examples include:
20256             1/(1/ (+-) (inf)) is (+-) (inf)
20257          and
20258             conj(csqrt(z)) is csqrt(conj(z)),
20259          for complex z.
20260
20261 [page 511]
20262
20263     F.9.3 Relational operators
20264 1   x != x (->) false           The expression x != x is true if x is a NaN.
20265     x = x (->) true            The expression x = x is false if x is a NaN.
20266     x < y (->) isless(x,y) (and similarly for <=, >, >=) Though numerically equal, these
20267                    expressions are not equivalent because of side effects when x or y is a
20268                    NaN and the state of the FENV_ACCESS pragma is ''on''. This
20269                    transformation, which would be desirable if extra code were required
20270                    to cause the ''invalid'' floating-point exception for unordered cases,
20271                    could be performed provided the state of the FENV_ACCESS pragma
20272                    is ''off''.
20273     The sense of relational operators shall be maintained. This includes handling unordered
20274     cases as expressed by the source code.
20275 2   EXAMPLE
20276              // calls g and raises ''invalid'' if a and b are unordered
20277              if (a < b)
20278                      f();
20279              else
20280                      g();
20281     is not equivalent to
20282              // calls f and raises ''invalid'' if a and b are unordered
20283              if (a >= b)
20284                      g();
20285              else
20286                      f();
20287     nor to
20288              // calls f without raising ''invalid'' if a and b are unordered
20289              if (isgreaterequal(a,b))
20290                      g();
20291              else
20292                      f();
20293     nor, unless the state of the FENV_ACCESS pragma is ''off'', to
20294              // calls g without raising ''invalid'' if a and b are unordered
20295              if (isless(a,b))
20296                      f();
20297              else
20298                      g();
20299     but is equivalent to
20300
20301
20302
20303
20304 [page 512]
20305
20306             if (!(a < b))
20307                   g();
20308             else
20309                   f();
20310
20311     F.9.4 Constant arithmetic
20312 1   The implementation shall honor floating-point exceptions raised by execution-time
20313     constant arithmetic wherever the state of the FENV_ACCESS pragma is ''on''. (See F.8.4
20314     and F.8.5.) An operation on constants that raises no floating-point exception can be
20315     folded during translation, except, if the state of the FENV_ACCESS pragma is ''on'', a
20316     further check is required to assure that changing the rounding direction to downward does
20317     not alter the sign of the result,352) and implementations that support dynamic rounding
20318     precision modes shall assure further that the result of the operation raises no floating-
20319     point exception when converted to the semantic type of the operation.
20320     F.10 Mathematics <math.h>
20321 1   This subclause contains specifications of <math.h> facilities that are particularly suited
20322     for IEC 60559 implementations.
20323 2   The Standard C macro HUGE_VAL and its float and long double analogs,
20324     HUGE_VALF and HUGE_VALL, expand to expressions whose values are positive
20325     infinities.
20326 3   Special cases for functions in <math.h> are covered directly or indirectly by
20327     IEC 60559. The functions that IEC 60559 specifies directly are identified in F.3. The
20328     other functions in <math.h> treat infinities, NaNs, signed zeros, subnormals, and
20329     (provided the state of the FENV_ACCESS pragma is ''on'') the floating-point status flags
20330     in a manner consistent with the basic arithmetic operations covered by IEC 60559.
20331 4   The expression math_errhandling & MATH_ERREXCEPT shall evaluate to a
20332     nonzero value.
20333 5   The ''invalid'' and ''divide-by-zero'' floating-point exceptions are raised as specified in
20334     subsequent subclauses of this annex.
20335 6   The ''overflow'' floating-point exception is raised whenever an infinity -- or, because of
20336     rounding direction, a maximal-magnitude finite number -- is returned in lieu of a value
20337     whose magnitude is too large.
20338 7   The ''underflow'' floating-point exception is raised whenever a result is tiny (essentially
20339     subnormal or zero) and suffers loss of accuracy.353)
20340
20341
20342     352) 0 - 0 yields -0 instead of +0 just when the rounding direction is downward.
20343     353) IEC 60559 allows different definitions of underflow. They all result in the same values, but differ on
20344          when the floating-point exception is raised.
20345
20346 [page 513]
20347
20348 8    Whether or when library functions raise the ''inexact'' floating-point exception is
20349      unspecified, unless explicitly specified otherwise.
20350 9    Whether or when library functions raise an undeserved ''underflow'' floating-point
20351      exception is unspecified.354) Otherwise, as implied by F.8.6, the <math.h> functions do
20352      not raise spurious floating-point exceptions (detectable by the user), other than the
20353      ''inexact'' floating-point exception.
20354 10   Whether the functions honor the rounding direction mode is implementation-defined,
20355      unless explicitly specified otherwise.
20356 11   Functions with a NaN argument return a NaN result and raise no floating-point exception,
20357      except where stated otherwise.
20358 12   The specifications in the following subclauses append to the definitions in <math.h>.
20359      For families of functions, the specifications apply to all of the functions even though only
20360      the principal function is shown. Unless otherwise specified, where the symbol ''(+-)''
20361      occurs in both an argument and the result, the result has the same sign as the argument.
20362      Recommended practice
20363 13   If a function with one or more NaN arguments returns a NaN result, the result should be
20364      the same as one of the NaN arguments (after possible type conversion), except perhaps
20365      for the sign.
20366      F.10.1 Trigonometric functions
20367      F.10.1.1 The acos functions
20368 1    -- acos(1) returns +0.
20369      -- acos(x) returns a NaN and raises the ''invalid'' floating-point exception for
20370        | x | > 1.
20371      F.10.1.2 The asin functions
20372 1    -- asin((+-)0) returns (+-)0.
20373      -- asin(x) returns a NaN and raises the ''invalid'' floating-point exception for
20374        | x | > 1.
20375
20376
20377
20378
20379      354) It is intended that undeserved ''underflow'' and ''inexact'' floating-point exceptions are raised only if
20380           avoiding them would be too costly.
20381
20382 [page 514]
20383
20384     F.10.1.3 The atan functions
20385 1   -- atan((+-)0) returns (+-)0.
20386     -- atan((+-)(inf)) returns (+-)pi /2.
20387     F.10.1.4 The atan2 functions
20388 1   -- atan2((+-)0, -0) returns (+-)pi .355)
20389     -- atan2((+-)0, +0) returns (+-)0.
20390     -- atan2((+-)0, x) returns (+-)pi for x < 0.
20391     -- atan2((+-)0, x) returns (+-)0 for x > 0.
20392     -- atan2(y, (+-)0) returns -pi /2 for y < 0.
20393     -- atan2(y, (+-)0) returns pi /2 for y > 0.
20394     -- atan2((+-)y, -(inf)) returns (+-)pi for finite y > 0.
20395     -- atan2((+-)y, +(inf)) returns (+-)0 for finite y > 0.
20396     -- atan2((+-)(inf), x) returns (+-)pi /2 for finite x.
20397     -- atan2((+-)(inf), -(inf)) returns (+-)3pi /4.
20398     -- atan2((+-)(inf), +(inf)) returns (+-)pi /4.
20399     F.10.1.5 The cos functions
20400 1   -- cos((+-)0) returns 1.
20401     -- cos((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
20402     F.10.1.6 The sin functions
20403 1   -- sin((+-)0) returns (+-)0.
20404     -- sin((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
20405     F.10.1.7 The tan functions
20406 1   -- tan((+-)0) returns (+-)0.
20407     -- tan((+-)(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
20408
20409
20410
20411
20412     355) atan2(0, 0) does not raise the ''invalid'' floating-point exception, nor does atan2( y , 0) raise
20413          the ''divide-by-zero'' floating-point exception.
20414
20415 [page 515]
20416
20417     F.10.2 Hyperbolic functions
20418     F.10.2.1 The acosh functions
20419 1   -- acosh(1) returns +0.
20420     -- acosh(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 1.
20421     -- acosh(+(inf)) returns +(inf).
20422     F.10.2.2 The asinh functions
20423 1   -- asinh((+-)0) returns (+-)0.
20424     -- asinh((+-)(inf)) returns (+-)(inf).
20425     F.10.2.3 The atanh functions
20426 1   -- atanh((+-)0) returns (+-)0.
20427     -- atanh((+-)1) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception.
20428     -- atanh(x) returns a NaN and raises the ''invalid'' floating-point exception for
20429       | x | > 1.
20430     F.10.2.4 The cosh functions
20431 1   -- cosh((+-)0) returns 1.
20432     -- cosh((+-)(inf)) returns +(inf).
20433     F.10.2.5 The sinh functions
20434 1   -- sinh((+-)0) returns (+-)0.
20435     -- sinh((+-)(inf)) returns (+-)(inf).
20436     F.10.2.6 The tanh functions
20437 1   -- tanh((+-)0) returns (+-)0.
20438     -- tanh((+-)(inf)) returns (+-)1.
20439     F.10.3 Exponential and logarithmic functions
20440     F.10.3.1 The exp functions
20441 1   -- exp((+-)0) returns 1.
20442     -- exp(-(inf)) returns +0.
20443     -- exp(+(inf)) returns +(inf).
20444
20445
20446
20447
20448 [page 516]
20449
20450     F.10.3.2 The exp2 functions
20451 1   -- exp2((+-)0) returns 1.
20452     -- exp2(-(inf)) returns +0.
20453     -- exp2(+(inf)) returns +(inf).
20454     F.10.3.3 The expm1 functions
20455 1   -- expm1((+-)0) returns (+-)0.
20456     -- expm1(-(inf)) returns -1.
20457     -- expm1(+(inf)) returns +(inf).
20458     F.10.3.4 The frexp functions
20459 1   -- frexp((+-)0, exp) returns (+-)0, and stores 0 in the object pointed to by exp.
20460     -- frexp((+-)(inf), exp) returns (+-)(inf), and stores an unspecified value in the object
20461       pointed to by exp.
20462     -- frexp(NaN, exp) stores an unspecified value in the object pointed to by exp
20463       (and returns a NaN).
20464 2   frexp raises no floating-point exceptions.
20465 3   When the radix of the argument is a power of 2, the returned value is exact and is
20466     independent of the current rounding direction mode.
20467 4   On a binary system, the body of the frexp function might be
20468             {
20469                    *exp = (value == 0) ? 0 : (int)(1 + logb(value));
20470                    return scalbn(value, -(*exp));
20471             }
20472     F.10.3.5 The ilogb functions
20473 1   When the correct result is representable in the range of the return type, the returned value
20474     is exact and is independent of the current rounding direction mode.
20475 2   If the correct result is outside the range of the return type, the numeric result is
20476     unspecified and the ''invalid'' floating-point exception is raised.
20477
20478
20479
20480
20481 [page 517]
20482
20483     F.10.3.6 The ldexp functions
20484 1   On a binary system, ldexp(x, exp) is equivalent to scalbn(x, exp).
20485     F.10.3.7 The log functions
20486 1   -- log((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
20487     -- log(1) returns +0.
20488     -- log(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
20489     -- log(+(inf)) returns +(inf).
20490     F.10.3.8 The log10 functions
20491 1   -- log10((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
20492     -- log10(1) returns +0.
20493     -- log10(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
20494     -- log10(+(inf)) returns +(inf).
20495     F.10.3.9 The log1p functions
20496 1   -- log1p((+-)0) returns (+-)0.
20497     -- log1p(-1) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
20498     -- log1p(x) returns a NaN and raises the ''invalid'' floating-point exception for
20499       x < -1.
20500     -- log1p(+(inf)) returns +(inf).
20501     F.10.3.10 The log2 functions
20502 1   -- log2((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
20503     -- log2(1) returns +0.
20504     -- log2(x) returns a NaN and raises the ''invalid'' floating-point exception for x < 0.
20505     -- log2(+(inf)) returns +(inf).
20506     F.10.3.11 The logb functions
20507 1   -- logb((+-)0) returns -(inf) and raises the ''divide-by-zero'' floating-point exception.
20508     -- logb((+-)(inf)) returns +(inf).
20509 2   The returned value is exact and is independent of the current rounding direction mode.
20510
20511
20512
20513
20514 [page 518]
20515
20516     F.10.3.12 The modf functions
20517 1   -- modf((+-)x, iptr) returns a result with the same sign as x.
20518     -- modf((+-)(inf), iptr) returns (+-)0 and stores (+-)(inf) in the object pointed to by iptr.
20519     -- modf(NaN, iptr) stores a NaN in the object pointed to by iptr (and returns a
20520       NaN).
20521 2   The returned values are exact and are independent of the current rounding direction
20522     mode.
20523 3   modf behaves as though implemented by
20524             #include <math.h>
20525             #include <fenv.h>
20526             #pragma STDC FENV_ACCESS ON
20527             double modf(double value, double *iptr)
20528             {
20529                  int save_round = fegetround();
20530                  fesetround(FE_TOWARDZERO);
20531                  *iptr = nearbyint(value);
20532                  fesetround(save_round);
20533                  return copysign(
20534                       isinf(value) ? 0.0 :
20535                            value - (*iptr), value);
20536             }
20537     F.10.3.13 The scalbn and scalbln functions
20538 1   -- scalbn((+-)0, n) returns (+-)0.
20539     -- scalbn(x, 0) returns x.
20540     -- scalbn((+-)(inf), n) returns (+-)(inf).
20541     F.10.4 Power and absolute value functions
20542     F.10.4.1 The cbrt functions
20543 1   -- cbrt((+-)0) returns (+-)0.
20544     -- cbrt((+-)(inf)) returns (+-)(inf).
20545
20546
20547
20548
20549 [page 519]
20550
20551     F.10.4.2 The fabs functions
20552 1   -- fabs((+-)0) returns +0.
20553     -- fabs((+-)(inf)) returns +(inf).
20554 2   The returned value is exact and is independent of the current rounding direction mode.
20555     F.10.4.3 The hypot functions
20556 1   -- hypot(x, y), hypot(y, x), and hypot(x, -y) are equivalent.
20557     -- hypot(x, (+-)0) is equivalent to fabs(x).
20558     -- hypot((+-)(inf), y) returns +(inf), even if y is a NaN.
20559     F.10.4.4 The pow functions
20560 1   -- pow((+-)0, y) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception
20561       for y an odd integer < 0.
20562     -- pow((+-)0, y) returns +(inf) and raises the ''divide-by-zero'' floating-point exception
20563       for y < 0 and not an odd integer.
20564     -- pow((+-)0, y) returns (+-)0 for y an odd integer > 0.
20565     -- pow((+-)0, y) returns +0 for y > 0 and not an odd integer.
20566     -- pow(-1, (+-)(inf)) returns 1.
20567     -- pow(+1, y) returns 1 for any y, even a NaN.
20568     -- pow(x, (+-)0) returns 1 for any x, even a NaN.
20569     -- pow(x, y) returns a NaN and raises the ''invalid'' floating-point exception for
20570       finite x < 0 and finite non-integer y.
20571     -- pow(x, -(inf)) returns +(inf) for | x | < 1.
20572     -- pow(x, -(inf)) returns +0 for | x | > 1.
20573     -- pow(x, +(inf)) returns +0 for | x | < 1.
20574     -- pow(x, +(inf)) returns +(inf) for | x | > 1.
20575     -- pow(-(inf), y) returns -0 for y an odd integer < 0.
20576     -- pow(-(inf), y) returns +0 for y < 0 and not an odd integer.
20577     -- pow(-(inf), y) returns -(inf) for y an odd integer > 0.
20578     -- pow(-(inf), y) returns +(inf) for y > 0 and not an odd integer.
20579     -- pow(+(inf), y) returns +0 for y < 0.
20580     -- pow(+(inf), y) returns +(inf) for y > 0.
20581
20582
20583 [page 520]
20584
20585     F.10.4.5 The sqrt functions
20586 1   sqrt is fully specified as a basic arithmetic operation in IEC 60559. The returned value
20587     is dependent on the current rounding direction mode.
20588     F.10.5 Error and gamma functions
20589     F.10.5.1 The erf functions
20590 1   -- erf((+-)0) returns (+-)0.
20591     -- erf((+-)(inf)) returns (+-)1.
20592     F.10.5.2 The erfc functions
20593 1   -- erfc(-(inf)) returns 2.
20594     -- erfc(+(inf)) returns +0.
20595     F.10.5.3 The lgamma functions
20596 1   -- lgamma(1) returns +0.
20597     -- lgamma(2) returns +0.
20598     -- lgamma(x) returns +(inf) and raises the ''divide-by-zero'' floating-point exception for
20599       x a negative integer or zero.
20600     -- lgamma(-(inf)) returns +(inf).
20601     -- lgamma(+(inf)) returns +(inf).
20602     F.10.5.4 The tgamma functions
20603 1   -- tgamma((+-)0) returns (+-)(inf) and raises the ''divide-by-zero'' floating-point exception.
20604     -- tgamma(x) returns a NaN and raises the ''invalid'' floating-point exception for x a
20605       negative integer.
20606     -- tgamma(-(inf)) returns a NaN and raises the ''invalid'' floating-point exception.
20607     -- tgamma(+(inf)) returns +(inf).
20608     F.10.6 Nearest integer functions
20609     F.10.6.1 The ceil functions
20610 1   -- ceil((+-)0) returns (+-)0.
20611     -- ceil((+-)(inf)) returns (+-)(inf).
20612 2   The returned value is exact and is independent of the current rounding direction mode.
20613 3   The double version of ceil behaves as though implemented by
20614
20615
20616
20617 [page 521]
20618
20619            #include <math.h>
20620            #include <fenv.h>
20621            #pragma STDC FENV_ACCESS ON
20622            double ceil(double x)
20623            {
20624                 double result;
20625                 int save_round = fegetround();
20626                 fesetround(FE_UPWARD);
20627                 result = rint(x); // or nearbyint instead of rint
20628                 fesetround(save_round);
20629                 return result;
20630            }
20631     F.10.6.2 The floor functions
20632 1   -- floor((+-)0) returns (+-)0.
20633     -- floor((+-)(inf)) returns (+-)(inf).
20634 2   The returned value is exact and is independent of the current rounding direction mode.
20635 3   See the sample implementation for ceil in F.10.6.1.
20636     F.10.6.3 The nearbyint functions
20637 1   The nearbyint functions use IEC 60559 rounding according to the current rounding
20638     direction. They do not raise the ''inexact'' floating-point exception if the result differs in
20639     value from the argument.
20640     -- nearbyint((+-)0) returns (+-)0 (for all rounding directions).
20641     -- nearbyint((+-)(inf)) returns (+-)(inf) (for all rounding directions).
20642     F.10.6.4 The rint functions
20643 1   The rint functions differ from the nearbyint functions only in that they do raise the
20644     ''inexact'' floating-point exception if the result differs in value from the argument.
20645     F.10.6.5 The lrint and llrint functions
20646 1   The lrint and llrint functions provide floating-to-integer conversion as prescribed
20647     by IEC 60559. They round according to the current rounding direction. If the rounded
20648     value is outside the range of the return type, the numeric result is unspecified and the
20649     ''invalid'' floating-point exception is raised. When they raise no other floating-point
20650     exception and the result differs from the argument, they raise the ''inexact'' floating-point
20651     exception.
20652
20653
20654
20655
20656 [page 522]
20657
20658     F.10.6.6 The round functions
20659 1   -- round((+-)0) returns (+-)0.
20660     -- round((+-)(inf)) returns (+-)(inf).
20661 2   The double version of round behaves as though implemented by
20662             #include <math.h>
20663             #include <fenv.h>
20664             #pragma STDC FENV_ACCESS ON
20665             double round(double x)
20666             {
20667                  double result;
20668                  fenv_t save_env;
20669                  feholdexcept(&save_env);
20670                  result = rint(x);
20671                  if (fetestexcept(FE_INEXACT)) {
20672                       fesetround(FE_TOWARDZERO);
20673                       result = rint(copysign(0.5 + fabs(x), x));
20674                  }
20675                  feupdateenv(&save_env);
20676                  return result;
20677             }
20678     The round functions may, but are not required to, raise the ''inexact'' floating-point
20679     exception for non-integer numeric arguments, as this implementation does.
20680     F.10.6.7 The lround and llround functions
20681 1   The lround and llround functions differ from the lrint and llrint functions
20682     with the default rounding direction just in that the lround and llround functions
20683     round halfway cases away from zero and need not raise the ''inexact'' floating-point
20684     exception for non-integer arguments that round to within the range of the return type.
20685     F.10.6.8 The trunc functions
20686 1   The trunc functions use IEC 60559 rounding toward zero (regardless of the current
20687     rounding direction). The returned value is exact.
20688     -- trunc((+-)0) returns (+-)0.
20689     -- trunc((+-)(inf)) returns (+-)(inf).
20690
20691
20692
20693
20694 [page 523]
20695
20696     F.10.7 Remainder functions
20697     F.10.7.1 The fmod functions
20698 1   -- fmod((+-)0, y) returns (+-)0 for y not zero.
20699     -- fmod(x, y) returns a NaN and raises the ''invalid'' floating-point exception for x
20700       infinite or y zero.
20701     -- fmod(x, (+-)(inf)) returns x for x not infinite.
20702 2   When subnormal results are supported, the returned value is exact and is independent of
20703     the current rounding direction mode.
20704 3   The double version of fmod behaves as though implemented by
20705            #include <math.h>
20706            #include <fenv.h>
20707            #pragma STDC FENV_ACCESS ON
20708            double fmod(double x, double y)
20709            {
20710                 double result;
20711                 result = remainder(fabs(x), (y = fabs(y)));
20712                 if (signbit(result)) result += y;
20713                 return copysign(result, x);
20714            }
20715     F.10.7.2 The remainder functions
20716 1   The remainder functions are fully specified as a basic arithmetic operation in
20717     IEC 60559.
20718 2   When subnormal results are supported, the returned value is exact and is independent of
20719     the current rounding direction mode.
20720     F.10.7.3 The remquo functions
20721 1   The remquo functions follow the specifications for the remainder functions. They
20722     have no further specifications special to IEC 60559 implementations.
20723 2   When subnormal results are supported, the returned value is exact and is independent of
20724     the current rounding direction mode.
20725
20726
20727
20728
20729 [page 524]
20730
20731     F.10.8 Manipulation functions
20732     F.10.8.1 The copysign functions
20733 1   copysign is specified in the Appendix to IEC 60559.
20734 2   The returned value is exact and is independent of the current rounding direction mode.
20735     F.10.8.2 The nan functions
20736 1   All IEC 60559 implementations support quiet NaNs, in all floating formats.
20737 2   The returned value is exact and is independent of the current rounding direction mode.
20738     F.10.8.3 The nextafter functions
20739 1   -- nextafter(x, y) raises the ''overflow'' and ''inexact'' floating-point exceptions
20740       for x finite and the function value infinite.
20741     -- nextafter(x, y) raises the ''underflow'' and ''inexact'' floating-point
20742       exceptions for the function value subnormal or zero and x != y.
20743 2   Even though underflow or overflow can occur, the returned value is independent of the
20744     current rounding direction mode.
20745     F.10.8.4 The nexttoward functions
20746 1   No additional requirements beyond those on nextafter.
20747 2   Even though underflow or overflow can occur, the returned value is independent of the
20748     current rounding direction mode.
20749     F.10.9 Maximum, minimum, and positive difference functions
20750     F.10.9.1 The fdim functions
20751 1   No additional requirements.
20752     F.10.9.2 The fmax functions
20753 1   If just one argument is a NaN, the fmax functions return the other argument (if both
20754     arguments are NaNs, the functions return a NaN).
20755 2   The returned value is exact and is independent of the current rounding direction mode.
20756 3   The body of the fmax function might be356)
20757             { return (isgreaterequal(x, y) ||
20758                  isnan(y)) ? x : y; }
20759
20760
20761
20762     356) Ideally, fmax would be sensitive to the sign of zero, for example fmax(-0.0, +0.0) would
20763          return +0; however, implementation in software might be impractical.
20764
20765 [page 525]
20766
20767     F.10.9.3 The fmin functions
20768 1   The fmin functions are analogous to the fmax functions (see F.10.9.2).
20769 2   The returned value is exact and is independent of the current rounding direction mode.
20770     F.10.10 Floating multiply-add
20771     F.10.10.1 The fma functions
20772 1   -- fma(x, y, z) computes xy + z, correctly rounded once.
20773     -- fma(x, y, z) returns a NaN and optionally raises the ''invalid'' floating-point
20774       exception if one of x and y is infinite, the other is zero, and z is a NaN.
20775     -- fma(x, y, z) returns a NaN and raises the ''invalid'' floating-point exception if
20776       one of x and y is infinite, the other is zero, and z is not a NaN.
20777     -- fma(x, y, z) returns a NaN and raises the ''invalid'' floating-point exception if x
20778       times y is an exact infinity and z is also an infinity but with the opposite sign.
20779     F.10.11 Comparison macros
20780 1   Relational operators and their corresponding comparison macros (7.12.14) produce
20781     equivalent result values, even if argument values are represented in wider formats. Thus,
20782     comparison macro arguments represented in formats wider than their semantic types are
20783     not converted to the semantic types, unless the wide evaluation method converts operands
20784     of relational operators to their semantic types. The standard wide evaluation methods
20785     characterized by FLT_EVAL_METHOD equal to 1 or 2 (5.2.4.2.2), do not convert
20786     operands of relational operators to their semantic types.
20787
20788
20789
20790
20791 [page 526]
20792
20793                                           Annex G
20794                                         (informative)
20795                   IEC 60559-compatible complex arithmetic
20796     G.1 Introduction
20797 1   This annex supplements annex F to specify complex arithmetic for compatibility with
20798     IEC 60559 real floating-point arithmetic. Although these specifications have been
20799     carefully designed, there is little existing practice to validate the design decisions.
20800     Therefore, these specifications are not normative, but should be viewed more as
20801     recommended          practice.       An         implementation        that     defines
20802     __STDC_IEC_559_COMPLEX__ should conform to the specifications in this annex.
20803     G.2 Types
20804 1   There is a new keyword _Imaginary, which is used to specify imaginary types. It is
20805     used as a type specifier within declaration specifiers in the same way as _Complex is
20806     (thus, _Imaginary float is a valid type name).
20807 2   There are three imaginary types, designated as float _Imaginary, double
20808     _Imaginary, and long double _Imaginary. The imaginary types (along with
20809     the real floating and complex types) are floating types.
20810 3   For imaginary types, the corresponding real type is given by deleting the keyword
20811     _Imaginary from the type name.
20812 4   Each imaginary type has the same representation and alignment requirements as the
20813     corresponding real type. The value of an object of imaginary type is the value of the real
20814     representation times the imaginary unit.
20815 5   The imaginary type domain comprises the imaginary types.
20816     G.3 Conventions
20817 1   A complex or imaginary value with at least one infinite part is regarded as an infinity
20818     (even if its other part is a NaN). A complex or imaginary value is a finite number if each
20819     of its parts is a finite number (neither infinite nor NaN). A complex or imaginary value is
20820     a zero if each of its parts is a zero.
20821
20822
20823
20824
20825 [page 527]
20826
20827     G.4 Conversions
20828     G.4.1 Imaginary types
20829 1   Conversions among imaginary types follow rules analogous to those for real floating
20830     types.
20831     G.4.2 Real and imaginary
20832 1   When a value of imaginary type is converted to a real type other than _Bool,357) the
20833     result is a positive zero.
20834 2   When a value of real type is converted to an imaginary type, the result is a positive
20835     imaginary zero.
20836     G.4.3 Imaginary and complex
20837 1   When a value of imaginary type is converted to a complex type, the real part of the
20838     complex result value is a positive zero and the imaginary part of the complex result value
20839     is determined by the conversion rules for the corresponding real types.
20840 2   When a value of complex type is converted to an imaginary type, the real part of the
20841     complex value is discarded and the value of the imaginary part is converted according to
20842     the conversion rules for the corresponding real types.
20843     G.5 Binary operators
20844 1   The following subclauses supplement 6.5 in order to specify the type of the result for an
20845     operation with an imaginary operand.
20846 2   For most operand types, the value of the result of a binary operator with an imaginary or
20847     complex operand is completely determined, with reference to real arithmetic, by the usual
20848     mathematical formula. For some operand types, the usual mathematical formula is
20849     problematic because of its treatment of infinities and because of undue overflow or
20850     underflow; in these cases the result satisfies certain properties (specified in G.5.1), but is
20851     not completely determined.
20852
20853
20854
20855
20856     357) See 6.3.1.2.
20857
20858 [page 528]
20859
20860     G.5.1 Multiplicative operators
20861     Semantics
20862 1   If one operand has real type and the other operand has imaginary type, then the result has
20863     imaginary type. If both operands have imaginary type, then the result has real type. (If
20864     either operand has complex type, then the result has complex type.)
20865 2   If the operands are not both complex, then the result and floating-point exception
20866     behavior of the * operator is defined by the usual mathematical formula:
20867            *                  u                   iv                 u + iv
20868
20869            x                  xu                i(xv)            (xu) + i(xv)
20870
20871            iy               i(yu)                -yv            (-yv) + i(yu)
20872
20873            x + iy       (xu) + i(yu)        (-yv) + i(xv)
20874 3   If the second operand is not complex, then the result and floating-point exception
20875     behavior of the / operator is defined by the usual mathematical formula:
20876            /                   u                       iv
20877
20878            x                  x/u                 i(-x/v)
20879
20880            iy               i(y/u)                     y/v
20881
20882            x + iy       (x/u) + i(y/u)        (y/v) + i(-x/v)
20883 4   The * and / operators satisfy the following infinity properties for all real, imaginary, and
20884     complex operands:358)
20885     -- if one operand is an infinity and the other operand is a nonzero finite number or an
20886       infinity, then the result of the * operator is an infinity;
20887     -- if the first operand is an infinity and the second operand is a finite number, then the
20888       result of the / operator is an infinity;
20889     -- if the first operand is a finite number and the second operand is an infinity, then the
20890       result of the / operator is a zero;
20891
20892
20893
20894
20895     358) These properties are already implied for those cases covered in the tables, but are required for all cases
20896          (at least where the state for CX_LIMITED_RANGE is ''off'').
20897
20898 [page 529]
20899
20900     -- if the first operand is a nonzero finite number or an infinity and the second operand is
20901       a zero, then the result of the / operator is an infinity.
20902 5   If both operands of the * operator are complex or if the second operand of the / operator
20903     is complex, the operator raises floating-point exceptions if appropriate for the calculation
20904     of the parts of the result, and may raise spurious floating-point exceptions.
20905 6   EXAMPLE 1 Multiplication of double _Complex operands could be implemented as follows. Note
20906     that the imaginary unit I has imaginary type (see G.6).
20907            #include <math.h>
20908            #include <complex.h>
20909            /* Multiply z * w ... */
20910            double complex _Cmultd(double complex z, double complex w)
20911            {
20912                   #pragma STDC FP_CONTRACT OFF
20913                   double a, b, c, d, ac, bd, ad, bc, x, y;
20914                   a = creal(z); b = cimag(z);
20915                   c = creal(w); d = cimag(w);
20916                   ac = a * c;       bd = b * d;
20917                   ad = a * d;       bc = b * c;
20918                   x = ac - bd; y = ad + bc;
20919                   if (isnan(x) && isnan(y)) {
20920                           /* Recover infinities that computed as NaN+iNaN ... */
20921                           int recalc = 0;
20922                           if ( isinf(a) || isinf(b) ) { // z is infinite
20923                                   /* "Box" the infinity and change NaNs in the other factor to 0 */
20924                                   a = copysign(isinf(a) ? 1.0 : 0.0, a);
20925                                   b = copysign(isinf(b) ? 1.0 : 0.0, b);
20926                                   if (isnan(c)) c = copysign(0.0, c);
20927                                   if (isnan(d)) d = copysign(0.0, d);
20928                                   recalc = 1;
20929                           }
20930                           if ( isinf(c) || isinf(d) ) { // w is infinite
20931                                   /* "Box" the infinity and change NaNs in the other factor to 0 */
20932                                   c = copysign(isinf(c) ? 1.0 : 0.0, c);
20933                                   d = copysign(isinf(d) ? 1.0 : 0.0, d);
20934                                   if (isnan(a)) a = copysign(0.0, a);
20935                                   if (isnan(b)) b = copysign(0.0, b);
20936                                   recalc = 1;
20937                           }
20938                           if (!recalc && (isinf(ac) || isinf(bd) ||
20939                                                  isinf(ad) || isinf(bc))) {
20940                                   /* Recover infinities from overflow by changing NaNs to 0 ... */
20941                                   if (isnan(a)) a = copysign(0.0, a);
20942                                   if (isnan(b)) b = copysign(0.0, b);
20943                                   if (isnan(c)) c = copysign(0.0, c);
20944                                   if (isnan(d)) d = copysign(0.0, d);
20945                                   recalc = 1;
20946                           }
20947                           if (recalc) {
20948
20949 [page 530]
20950
20951                                       x = INFINITY * ( a * c - b * d );
20952                                       y = INFINITY * ( a * d + b * c );
20953                            }
20954                      }
20955                      return x + I * y;
20956              }
20957 7   This implementation achieves the required treatment of infinities at the cost of only one isnan test in
20958     ordinary (finite) cases. It is less than ideal in that undue overflow and underflow may occur.
20959
20960 8   EXAMPLE 2      Division of two double _Complex operands could be implemented as follows.
20961              #include <math.h>
20962              #include <complex.h>
20963              /* Divide z / w ... */
20964              double complex _Cdivd(double complex z, double complex w)
20965              {
20966                     #pragma STDC FP_CONTRACT OFF
20967                     double a, b, c, d, logbw, denom, x, y;
20968                     int ilogbw = 0;
20969                     a = creal(z); b = cimag(z);
20970                     c = creal(w); d = cimag(w);
20971                     logbw = logb(fmax(fabs(c), fabs(d)));
20972                     if (isfinite(logbw)) {
20973                            ilogbw = (int)logbw;
20974                            c = scalbn(c, -ilogbw); d = scalbn(d, -ilogbw);
20975                     }
20976                     denom = c * c + d * d;
20977                     x = scalbn((a * c + b * d) / denom, -ilogbw);
20978                     y = scalbn((b * c - a * d) / denom, -ilogbw);
20979                      /* Recover infinities and zeros that computed as NaN+iNaN;                 */
20980                      /* the only cases are nonzero/zero, infinite/finite, and finite/infinite, ... */
20981                      if (isnan(x) && isnan(y)) {
20982                            if ((denom == 0.0) &&
20983                                  (!isnan(a) || !isnan(b))) {
20984                                  x = copysign(INFINITY, c) * a;
20985                                  y = copysign(INFINITY, c) * b;
20986                            }
20987                            else if ((isinf(a) || isinf(b)) &&
20988                                  isfinite(c) && isfinite(d)) {
20989                                  a = copysign(isinf(a) ? 1.0 : 0.0,                        a);
20990                                  b = copysign(isinf(b) ? 1.0 : 0.0,                        b);
20991                                  x = INFINITY * ( a * c + b * d );
20992                                  y = INFINITY * ( b * c - a * d );
20993                            }
20994                            else if (isinf(logbw) &&
20995                                  isfinite(a) && isfinite(b)) {
20996                                  c = copysign(isinf(c) ? 1.0 : 0.0,                        c);
20997                                  d = copysign(isinf(d) ? 1.0 : 0.0,                        d);
20998                                  x = 0.0 * ( a * c + b * d );
20999                                  y = 0.0 * ( b * c - a * d );
21000
21001 [page 531]
21002
21003                            }
21004                      }
21005                      return x + I * y;
21006             }
21007 9   Scaling the denominator alleviates the main overflow and underflow problem, which is more serious than
21008     for multiplication. In the spirit of the multiplication example above, this code does not defend against
21009     overflow and underflow in the calculation of the numerator. Scaling with the scalbn function, instead of
21010     with division, provides better roundoff characteristics.
21011
21012     G.5.2 Additive operators
21013     Semantics
21014 1   If both operands have imaginary type, then the result has imaginary type. (If one operand
21015     has real type and the other operand has imaginary type, or if either operand has complex
21016     type, then the result has complex type.)
21017 2   In all cases the result and floating-point exception behavior of a + or - operator is defined
21018     by the usual mathematical formula:
21019            + or -              u                       iv                    u + iv
21020
21021            x                 x(+-)u                     x (+-) iv              (x (+-) u) (+-) iv
21022
21023            iy               (+-)u + iy                 i(y (+-) v)             (+-)u + i(y (+-) v)
21024
21025            x + iy         (x (+-) u) + iy            x + i(y (+-) v)        (x (+-) u) + i(y (+-) v)
21026     G.6 Complex arithmetic <complex.h>
21027 1   The macros
21028             imaginary
21029     and
21030             _Imaginary_I
21031     are defined, respectively, as _Imaginary and a constant expression of type const
21032     float _Imaginary with the value of the imaginary unit. The macro
21033             I
21034     is defined to be _Imaginary_I (not _Complex_I as stated in 7.3). Notwithstanding
21035     the provisions of 7.1.3, a program may undefine and then perhaps redefine the macro
21036     imaginary.
21037 2   This subclause contains specifications for the <complex.h> functions that are
21038     particularly suited to IEC 60559 implementations. For families of functions, the
21039     specifications apply to all of the functions even though only the principal function is
21040
21041 [page 532]
21042
21043     shown. Unless otherwise specified, where the symbol ''(+-)'' occurs in both an argument
21044     and the result, the result has the same sign as the argument.
21045 3   The functions are continuous onto both sides of their branch cuts, taking into account the
21046     sign of zero. For example, csqrt(-2 (+-) i0) = (+-)isqrt:2.  -
21047 4   Since complex and imaginary values are composed of real values, each function may be
21048     regarded as computing real values from real values. Except as noted, the functions treat
21049     real infinities, NaNs, signed zeros, subnormals, and the floating-point exception flags in a
21050     manner consistent with the specifications for real functions in F.10.359)
21051 5   The functions cimag, conj, cproj, and creal are fully specified for all
21052     implementations, including IEC 60559 ones, in 7.3.9. These functions raise no floating-
21053     point exceptions.
21054 6   Each of the functions cabs and carg is specified by a formula in terms of a real
21055     function (whose special cases are covered in annex F):
21056             cabs(x + iy) = hypot(x, y)
21057             carg(x + iy) = atan2(y, x)
21058 7   Each of the functions casin, catan, ccos, csin, and ctan is specified implicitly by
21059     a formula in terms of other complex functions (whose special cases are specified below):
21060             casin(z)        =   -i casinh(iz)
21061             catan(z)        =   -i catanh(iz)
21062             ccos(z)         =   ccosh(iz)
21063             csin(z)         =   -i csinh(iz)
21064             ctan(z)         =   -i ctanh(iz)
21065 8   For the other functions, the following subclauses specify behavior for special cases,
21066     including treatment of the ''invalid'' and ''divide-by-zero'' floating-point exceptions. For
21067     families of functions, the specifications apply to all of the functions even though only the
21068     principal function is shown. For a function f satisfying f (conj(z)) = conj( f (z)), the
21069     specifications for the upper half-plane imply the specifications for the lower half-plane; if
21070     the function f is also either even, f (-z) = f (z), or odd, f (-z) = - f (z), then the
21071     specifications for the first quadrant imply the specifications for the other three quadrants.
21072 9   In the following subclauses, cis(y) is defined as cos(y) + i sin(y).
21073
21074
21075
21076
21077     359) As noted in G.3, a complex value with at least one infinite part is regarded as an infinity even if its
21078          other part is a NaN.
21079
21080 [page 533]
21081
21082     G.6.1 Trigonometric functions
21083     G.6.1.1 The cacos functions
21084 1   -- cacos(conj(z)) = conj(cacos(z)).
21085     -- cacos((+-)0 + i0) returns pi /2 - i0.
21086     -- cacos((+-)0 + iNaN) returns pi /2 + iNaN.
21087     -- cacos(x + i (inf)) returns pi /2 - i (inf), for finite x.
21088     -- cacos(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21089       point exception, for nonzero finite x.
21090     -- cacos(-(inf) + iy) returns pi - i (inf), for positive-signed finite y.
21091     -- cacos(+(inf) + iy) returns +0 - i (inf), for positive-signed finite y.
21092     -- cacos(-(inf) + i (inf)) returns 3pi /4 - i (inf).
21093     -- cacos(+(inf) + i (inf)) returns pi /4 - i (inf).
21094     -- cacos((+-)(inf) + iNaN) returns NaN (+-) i (inf) (where the sign of the imaginary part of the
21095       result is unspecified).
21096     -- cacos(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21097       point exception, for finite y.
21098     -- cacos(NaN + i (inf)) returns NaN - i (inf).
21099     -- cacos(NaN + iNaN) returns NaN + iNaN.
21100     G.6.2 Hyperbolic functions
21101     G.6.2.1 The cacosh functions
21102 1   -- cacosh(conj(z)) = conj(cacosh(z)).
21103     -- cacosh((+-)0 + i0) returns +0 + ipi /2.
21104     -- cacosh(x + i (inf)) returns +(inf) + ipi /2, for finite x.
21105     -- cacosh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
21106       floating-point exception, for finite x.
21107     -- cacosh(-(inf) + iy) returns +(inf) + ipi , for positive-signed finite y.
21108     -- cacosh(+(inf) + iy) returns +(inf) + i0, for positive-signed finite y.
21109     -- cacosh(-(inf) + i (inf)) returns +(inf) + i3pi /4.
21110     -- cacosh(+(inf) + i (inf)) returns +(inf) + ipi /4.
21111     -- cacosh((+-)(inf) + iNaN) returns +(inf) + iNaN.
21112
21113
21114 [page 534]
21115
21116     -- cacosh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
21117       floating-point exception, for finite y.
21118     -- cacosh(NaN + i (inf)) returns +(inf) + iNaN.
21119     -- cacosh(NaN + iNaN) returns NaN + iNaN.
21120     G.6.2.2 The casinh functions
21121 1   -- casinh(conj(z)) = conj(casinh(z)) and casinh is odd.
21122     -- casinh(+0 + i0) returns 0 + i0.
21123     -- casinh(x + i (inf)) returns +(inf) + ipi /2 for positive-signed finite x.
21124     -- casinh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
21125       floating-point exception, for finite x.
21126     -- casinh(+(inf) + iy) returns +(inf) + i0 for positive-signed finite y.
21127     -- casinh(+(inf) + i (inf)) returns +(inf) + ipi /4.
21128     -- casinh(+(inf) + iNaN) returns +(inf) + iNaN.
21129     -- casinh(NaN + i0) returns NaN + i0.
21130     -- casinh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
21131       floating-point exception, for finite nonzero y.
21132     -- casinh(NaN + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result
21133       is unspecified).
21134     -- casinh(NaN + iNaN) returns NaN + iNaN.
21135     G.6.2.3 The catanh functions
21136 1   -- catanh(conj(z)) = conj(catanh(z)) and catanh is odd.
21137     -- catanh(+0 + i0) returns +0 + i0.
21138     -- catanh(+0 + iNaN) returns +0 + iNaN.
21139     -- catanh(+1 + i0) returns +(inf) + i0 and raises the ''divide-by-zero'' floating-point
21140       exception.
21141     -- catanh(x + i (inf)) returns +0 + ipi /2, for finite positive-signed x.
21142     -- catanh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid''
21143       floating-point exception, for nonzero finite x.
21144     -- catanh(+(inf) + iy) returns +0 + ipi /2, for finite positive-signed y.
21145     -- catanh(+(inf) + i (inf)) returns +0 + ipi /2.
21146     -- catanh(+(inf) + iNaN) returns +0 + iNaN.
21147
21148 [page 535]
21149
21150     -- catanh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid''
21151       floating-point exception, for finite y.
21152     -- catanh(NaN + i (inf)) returns (+-)0 + ipi /2 (where the sign of the real part of the result is
21153       unspecified).
21154     -- catanh(NaN + iNaN) returns NaN + iNaN.
21155     G.6.2.4 The ccosh functions
21156 1   -- ccosh(conj(z)) = conj(ccosh(z)) and ccosh is even.
21157     -- ccosh(+0 + i0) returns 1 + i0.
21158     -- ccosh(+0 + i (inf)) returns NaN (+-) i0 (where the sign of the imaginary part of the
21159       result is unspecified) and raises the ''invalid'' floating-point exception.
21160     -- ccosh(+0 + iNaN) returns NaN (+-) i0 (where the sign of the imaginary part of the
21161       result is unspecified).
21162     -- ccosh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
21163       exception, for finite nonzero x.
21164     -- ccosh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21165       point exception, for finite nonzero x.
21166     -- ccosh(+(inf) + i0) returns +(inf) + i0.
21167     -- ccosh(+(inf) + iy) returns +(inf) cis(y), for finite nonzero y.
21168     -- ccosh(+(inf) + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result is
21169       unspecified) and raises the ''invalid'' floating-point exception.
21170     -- ccosh(+(inf) + iNaN) returns +(inf) + iNaN.
21171     -- ccosh(NaN + i0) returns NaN (+-) i0 (where the sign of the imaginary part of the
21172       result is unspecified).
21173     -- ccosh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21174       point exception, for all nonzero numbers y.
21175     -- ccosh(NaN + iNaN) returns NaN + iNaN.
21176     G.6.2.5 The csinh functions
21177 1   -- csinh(conj(z)) = conj(csinh(z)) and csinh is odd.
21178     -- csinh(+0 + i0) returns +0 + i0.
21179     -- csinh(+0 + i (inf)) returns (+-)0 + iNaN (where the sign of the real part of the result is
21180       unspecified) and raises the ''invalid'' floating-point exception.
21181     -- csinh(+0 + iNaN) returns (+-)0 + iNaN (where the sign of the real part of the result is
21182       unspecified).
21183 [page 536]
21184
21185     -- csinh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
21186       exception, for positive finite x.
21187     -- csinh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21188       point exception, for finite nonzero x.
21189     -- csinh(+(inf) + i0) returns +(inf) + i0.
21190     -- csinh(+(inf) + iy) returns +(inf) cis(y), for positive finite y.
21191     -- csinh(+(inf) + i (inf)) returns (+-)(inf) + iNaN (where the sign of the real part of the result is
21192       unspecified) and raises the ''invalid'' floating-point exception.
21193     -- csinh(+(inf) + iNaN) returns (+-)(inf) + iNaN (where the sign of the real part of the result
21194       is unspecified).
21195     -- csinh(NaN + i0) returns NaN + i0.
21196     -- csinh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21197       point exception, for all nonzero numbers y.
21198     -- csinh(NaN + iNaN) returns NaN + iNaN.
21199     G.6.2.6 The ctanh functions
21200 1   -- ctanh(conj(z)) = conj(ctanh(z))and ctanh is odd.
21201     -- ctanh(+0 + i0) returns +0 + i0.
21202     -- ctanh(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
21203       exception, for finite x.
21204     -- ctanh(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21205       point exception, for finite x.
21206     -- ctanh(+(inf) + iy) returns 1 + i0 sin(2y), for positive-signed finite y.
21207     -- ctanh(+(inf) + i (inf)) returns 1 (+-) i0 (where the sign of the imaginary part of the result
21208       is unspecified).
21209     -- ctanh(+(inf) + iNaN) returns 1 (+-) i0 (where the sign of the imaginary part of the
21210       result is unspecified).
21211     -- ctanh(NaN + i0) returns NaN + i0.
21212     -- ctanh(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21213       point exception, for all nonzero numbers y.
21214     -- ctanh(NaN + iNaN) returns NaN + iNaN.
21215
21216
21217
21218
21219 [page 537]
21220
21221     G.6.3 Exponential and logarithmic functions
21222     G.6.3.1 The cexp functions
21223 1   -- cexp(conj(z)) = conj(cexp(z)).
21224     -- cexp((+-)0 + i0) returns 1 + i0.
21225     -- cexp(x + i (inf)) returns NaN + iNaN and raises the ''invalid'' floating-point
21226       exception, for finite x.
21227     -- cexp(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21228       point exception, for finite x.
21229     -- cexp(+(inf) + i0) returns +(inf) + i0.
21230     -- cexp(-(inf) + iy) returns +0 cis(y), for finite y.
21231     -- cexp(+(inf) + iy) returns +(inf) cis(y), for finite nonzero y.
21232     -- cexp(-(inf) + i (inf)) returns (+-)0 (+-) i0 (where the signs of the real and imaginary parts of
21233       the result are unspecified).
21234     -- cexp(+(inf) + i (inf)) returns (+-)(inf) + iNaN and raises the ''invalid'' floating-point
21235       exception (where the sign of the real part of the result is unspecified).
21236     -- cexp(-(inf) + iNaN) returns (+-)0 (+-) i0 (where the signs of the real and imaginary parts
21237       of the result are unspecified).
21238     -- cexp(+(inf) + iNaN) returns (+-)(inf) + iNaN (where the sign of the real part of the result
21239       is unspecified).
21240     -- cexp(NaN + i0) returns NaN + i0.
21241     -- cexp(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21242       point exception, for all nonzero numbers y.
21243     -- cexp(NaN + iNaN) returns NaN + iNaN.
21244     G.6.3.2 The clog functions
21245 1   -- clog(conj(z)) = conj(clog(z)).
21246     -- clog(-0 + i0) returns -(inf) + ipi and raises the ''divide-by-zero'' floating-point
21247       exception.
21248     -- clog(+0 + i0) returns -(inf) + i0 and raises the ''divide-by-zero'' floating-point
21249       exception.
21250     -- clog(x + i (inf)) returns +(inf) + ipi /2, for finite x.
21251     -- clog(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21252       point exception, for finite x.
21253
21254 [page 538]
21255
21256     -- clog(-(inf) + iy) returns +(inf) + ipi , for finite positive-signed y.
21257     -- clog(+(inf) + iy) returns +(inf) + i0, for finite positive-signed y.
21258     -- clog(-(inf) + i (inf)) returns +(inf) + i3pi /4.
21259     -- clog(+(inf) + i (inf)) returns +(inf) + ipi /4.
21260     -- clog((+-)(inf) + iNaN) returns +(inf) + iNaN.
21261     -- clog(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21262       point exception, for finite y.
21263     -- clog(NaN + i (inf)) returns +(inf) + iNaN.
21264     -- clog(NaN + iNaN) returns NaN + iNaN.
21265     G.6.4 Power and absolute-value functions
21266     G.6.4.1 The cpow functions
21267 1   The cpow functions raise floating-point exceptions if appropriate for the calculation of
21268     the parts of the result, and may raise spurious exceptions.360)
21269     G.6.4.2 The csqrt functions
21270 1   -- csqrt(conj(z)) = conj(csqrt(z)).
21271     -- csqrt((+-)0 + i0) returns +0 + i0.
21272     -- csqrt(x + i (inf)) returns +(inf) + i (inf), for all x (including NaN).
21273     -- csqrt(x + iNaN) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21274       point exception, for finite x.
21275     -- csqrt(-(inf) + iy) returns +0 + i (inf), for finite positive-signed y.
21276     -- csqrt(+(inf) + iy) returns +(inf) + i0, for finite positive-signed y.
21277     -- csqrt(-(inf) + iNaN) returns NaN (+-) i (inf) (where the sign of the imaginary part of the
21278       result is unspecified).
21279     -- csqrt(+(inf) + iNaN) returns +(inf) + iNaN.
21280     -- csqrt(NaN + iy) returns NaN + iNaN and optionally raises the ''invalid'' floating-
21281       point exception, for finite y.
21282     -- csqrt(NaN + iNaN) returns NaN + iNaN.
21283
21284
21285
21286
21287     360) This allows cpow( z , c ) to be implemented as cexp(c      clog( z )) without precluding
21288          implementations that treat special cases more carefully.
21289
21290 [page 539]
21291
21292     G.7 Type-generic math <tgmath.h>
21293 1   Type-generic macros that accept complex arguments also accept imaginary arguments. If
21294     an argument is imaginary, the macro expands to an expression whose type is real,
21295     imaginary, or complex, as appropriate for the particular function: if the argument is
21296     imaginary, then the types of cos, cosh, fabs, carg, cimag, and creal are real; the
21297     types of sin, tan, sinh, tanh, asin, atan, asinh, and atanh are imaginary; and
21298     the types of the others are complex.
21299 2   Given an imaginary argument, each of the type-generic macros cos, sin, tan, cosh,
21300     sinh, tanh, asin, atan, asinh, atanh is specified by a formula in terms of real
21301     functions:
21302            cos(iy)      =   cosh(y)
21303            sin(iy)      =   i sinh(y)
21304            tan(iy)      =   i tanh(y)
21305            cosh(iy)     =   cos(y)
21306            sinh(iy)     =   i sin(y)
21307            tanh(iy)     =   i tan(y)
21308            asin(iy)     =   i asinh(y)
21309            atan(iy)     =   i atanh(y)
21310            asinh(iy)    =   i asin(y)
21311            atanh(iy)    =   i atan(y)
21312
21313
21314
21315
21316 [page 540]
21317
21318                                           Annex H
21319                                         (informative)
21320                         Language independent arithmetic
21321     H.1 Introduction
21322 1   This annex documents the extent to which the C language supports the ISO/IEC 10967-1
21323     standard for language-independent arithmetic (LIA-1). LIA-1 is more general than
21324     IEC 60559 (annex F) in that it covers integer and diverse floating-point arithmetics.
21325     H.2 Types
21326 1   The relevant C arithmetic types meet the requirements of LIA-1 types if an
21327     implementation adds notification of exceptional arithmetic operations and meets the 1
21328     unit in the last place (ULP) accuracy requirement (LIA-1 subclause 5.2.8).
21329     H.2.1 Boolean type
21330 1   The LIA-1 data type Boolean is implemented by the C data type bool with values of
21331     true and false, all from <stdbool.h>.
21332     H.2.2 Integer types
21333 1   The signed C integer types int, long int, long long int, and the corresponding
21334     unsigned types are compatible with LIA-1. If an implementation adds support for the
21335     LIA-1 exceptional values ''integer_overflow'' and ''undefined'', then those types are
21336     LIA-1 conformant types. C's unsigned integer types are ''modulo'' in the LIA-1 sense
21337     in that overflows or out-of-bounds results silently wrap. An implementation that defines
21338     signed integer types as also being modulo need not detect integer overflow, in which case,
21339     only integer divide-by-zero need be detected.
21340 2   The parameters for the integer data types can be accessed by the following:
21341     maxint        INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX,
21342                   ULLONG_MAX
21343     minint        INT_MIN, LONG_MIN, LLONG_MIN
21344 3   The parameter ''bounded'' is always true, and is not provided. The parameter ''minint''
21345     is always 0 for the unsigned types, and is not provided for those types.
21346
21347
21348
21349
21350 [page 541]
21351
21352     H.2.2.1 Integer operations
21353 1   The integer operations on integer types are the following:
21354     addI           x + y
21355     subI           x - y
21356     mulI           x * y
21357     divI, divtI    x / y
21358     remI, remtI    x % y
21359     negI           -x
21360     absI           abs(x), labs(x), llabs(x)
21361     eqI            x == y
21362     neqI           x != y
21363     lssI           x < y
21364     leqI           x <= y
21365     gtrI           x > y
21366     geqI           x >= y
21367     where x and y are expressions of the same integer type.
21368     H.2.3 Floating-point types
21369 1   The C floating-point types float, double, and long double are compatible with
21370     LIA-1. If an implementation adds support for the LIA-1 exceptional values
21371     ''underflow'', ''floating_overflow'', and ''"undefined'', then those types are conformant
21372     with LIA-1. An implementation that uses IEC 60559 floating-point formats and
21373     operations (see annex F) along with IEC 60559 status flags and traps has LIA-1
21374     conformant types.
21375     H.2.3.1 Floating-point parameters
21376 1   The parameters for a floating point data type can be accessed by the following:
21377     r              FLT_RADIX
21378     p              FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG
21379     emax           FLT_MAX_EXP, DBL_MAX_EXP, LDBL_MAX_EXP
21380     emin           FLT_MIN_EXP, DBL_MIN_EXP, LDBL_MIN_EXP
21381 2   The derived constants for the floating point types are accessed by the following:
21382
21383
21384 [page 542]
21385
21386     fmax          FLT_MAX, DBL_MAX, LDBL_MAX
21387     fminN         FLT_MIN, DBL_MIN, LDBL_MIN
21388     epsilon       FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON
21389     rnd_style     FLT_ROUNDS
21390     H.2.3.2 Floating-point operations
21391 1   The floating-point operations on floating-point types are the following:
21392     addF          x + y
21393     subF          x - y
21394     mulF          x * y
21395     divF          x / y
21396     negF          -x
21397     absF          fabsf(x), fabs(x), fabsl(x)
21398     exponentF     1.f+logbf(x), 1.0+logb(x), 1.L+logbl(x)
21399     scaleF        scalbnf(x, n), scalbn(x, n), scalbnl(x, n),
21400                   scalblnf(x, li), scalbln(x, li), scalblnl(x, li)
21401     intpartF      modff(x, &y), modf(x, &y), modfl(x, &y)
21402     fractpartF    modff(x, &y), modf(x, &y), modfl(x, &y)
21403     eqF           x == y
21404     neqF          x != y
21405     lssF          x < y
21406     leqF          x <= y
21407     gtrF          x > y
21408     geqF          x >= y
21409     where x and y are expressions of the same floating point type, n is of type int, and li
21410     is of type long int.
21411     H.2.3.3 Rounding styles
21412 1   The C Standard requires all floating types to use the same radix and rounding style, so
21413     that only one identifier for each is provided to map to LIA-1.
21414 2   The FLT_ROUNDS parameter can be used to indicate the LIA-1 rounding styles:
21415     truncate      FLT_ROUNDS == 0
21416
21417
21418 [page 543]
21419
21420     nearest       FLT_ROUNDS == 1
21421     other         FLT_ROUNDS != 0 && FLT_ROUNDS != 1
21422     provided that an implementation extends FLT_ROUNDS to cover the rounding style used
21423     in all relevant LIA-1 operations, not just addition as in C.
21424     H.2.4 Type conversions
21425 1   The LIA-1 type conversions are the following type casts:
21426     cvtI' (->) I     (int)i, (long int)i, (long long int)i,
21427                   (unsigned int)i, (unsigned long int)i,
21428                   (unsigned long long int)i
21429     cvtF (->) I      (int)x, (long int)x, (long long int)x,
21430                   (unsigned int)x, (unsigned long int)x,
21431                   (unsigned long long int)x
21432     cvtI (->) F      (float)i, (double)i, (long double)i
21433     cvtF' (->) F     (float)x, (double)x, (long double)x
21434 2   In the above conversions from floating to integer, the use of (cast)x can be replaced with
21435     (cast)round(x), (cast)rint(x), (cast)nearbyint(x), (cast)trunc(x),
21436     (cast)ceil(x), or (cast)floor(x). In addition, C's floating-point to integer
21437     conversion functions, lrint(), llrint(), lround(), and llround(), can be
21438     used. They all meet LIA-1's requirements on floating to integer rounding for in-range
21439     values. For out-of-range values, the conversions shall silently wrap for the modulo types.
21440 3   The fmod() function is useful for doing silent wrapping to unsigned integer types, e.g.,
21441     fmod( fabs(rint(x)), 65536.0 ) or (0.0 <= (y = fmod( rint(x),
21442     65536.0 )) ? y : 65536.0 + y) will compute an integer value in the range 0.0
21443     to 65535.0 which can then be cast to unsigned short int. But, the
21444     remainder() function is not useful for doing silent wrapping to signed integer types,
21445     e.g., remainder( rint(x), 65536.0 ) will compute an integer value in the
21446     range -32767.0 to +32768.0 which is not, in general, in the range of signed short
21447     int.
21448 4   C's conversions (casts) from floating-point to floating-point can meet LIA-1
21449     requirements if an implementation uses round-to-nearest (IEC 60559 default).
21450 5   C's conversions (casts) from integer to floating-point can meet LIA-1 requirements if an
21451     implementation uses round-to-nearest.
21452
21453
21454
21455
21456 [page 544]
21457
21458     H.3 Notification
21459 1   Notification is the process by which a user or program is informed that an exceptional
21460     arithmetic operation has occurred. C's operations are compatible with LIA-1 in that C
21461     allows an implementation to cause a notification to occur when any arithmetic operation
21462     returns an exceptional value as defined in LIA-1 clause 5.
21463     H.3.1 Notification alternatives
21464 1   LIA-1 requires at least the following two alternatives for handling of notifications:
21465     setting indicators or trap-and-terminate. LIA-1 allows a third alternative: trap-and-
21466     resume.
21467 2   An implementation need only support a given notification alternative for the entire
21468     program. An implementation may support the ability to switch between notification
21469     alternatives during execution, but is not required to do so. An implementation can
21470     provide separate selection for each kind of notification, but this is not required.
21471 3   C allows an implementation to provide notification. C's SIGFPE (for traps) and
21472     FE_INVALID, FE_DIVBYZERO, FE_OVERFLOW, FE_UNDERFLOW (for indicators)
21473     can provide LIA-1 notification.
21474 4   C's signal handlers are compatible with LIA-1. Default handling of SIGFPE can
21475     provide trap-and-terminate behavior, except for those LIA-1 operations implemented by
21476     math library function calls. User-provided signal handlers for SIGFPE allow for trap-
21477     and-resume behavior with the same constraint.
21478     H.3.1.1 Indicators
21479 1   C's <fenv.h> status flags are compatible with the LIA-1 indicators.
21480 2   The following mapping is for floating-point types:
21481     undefined                FE_INVALID, FE_DIVBYZERO
21482     floating_overflow         FE_OVERFLOW
21483     underflow                FE_UNDERFLOW
21484 3   The floating-point indicator interrogation and manipulation operations are:
21485     set_indicators          feraiseexcept(i)
21486     clear_indicators        feclearexcept(i)
21487     test_indicators         fetestexcept(i)
21488     current_indicators      fetestexcept(FE_ALL_EXCEPT)
21489     where i is an expression of type int representing a subset of the LIA-1 indicators.
21490 4   C allows an implementation to provide the following LIA-1 required behavior: at
21491     program termination if any indicator is set the implementation shall send an unambiguous
21492 [page 545]
21493
21494     and ''hard to ignore'' message (see LIA-1 subclause 6.1.2)
21495 5   LIA-1 does not make the distinction between floating-point and integer for ''undefined''.
21496     This documentation makes that distinction because <fenv.h> covers only the floating-
21497     point indicators.
21498     H.3.1.2 Traps
21499 1   C is compatible with LIA-1's trap requirements for arithmetic operations, but not for
21500     math library functions (which are not permitted to invoke a user's signal handler for
21501     SIGFPE). An implementation can provide an alternative of notification through
21502     termination with a ''hard-to-ignore'' message (see LIA-1 subclause 6.1.3).
21503 2   LIA-1 does not require that traps be precise.
21504 3   C does require that SIGFPE be the signal corresponding to arithmetic exceptions, if there
21505     is any signal raised for them.
21506 4   C supports signal handlers for SIGFPE and allows trapping of arithmetic exceptions.
21507     When arithmetic exceptions do trap, C's signal-handler mechanism allows trap-and-
21508     terminate (either default implementation behavior or user replacement for it) or trap-and-
21509     resume, at the programmer's option.
21510
21511
21512
21513
21514 [page 546]
21515
21516                                            Annex I
21517                                         (informative)
21518                                    Common warnings
21519 1   An implementation may generate warnings in many situations, none of which are
21520     specified as part of this International Standard. The following are a few of the more
21521     common situations.
21522 2   -- A new struct or union type appears in a function prototype (6.2.1, 6.7.2.3).
21523     -- A block with initialization of an object that has automatic storage duration is jumped
21524       into (6.2.4).
21525     -- An implicit narrowing conversion is encountered, such as the assignment of a long
21526       int or a double to an int, or a pointer to void to a pointer to any type other than
21527       a character type (6.3).
21528     -- A hexadecimal floating constant cannot be represented exactly in its evaluation format
21529       (6.4.4.2).
21530     -- An integer character constant includes more than one character or a wide character
21531       constant includes more than one multibyte character (6.4.4.4).
21532     -- The characters /* are found in a comment (6.4.7).
21533     -- An ''unordered'' binary operator (not comma, &&, or ||) contains a side effect to an
21534       lvalue in one operand, and a side effect to, or an access to the value of, the identical
21535       lvalue in the other operand (6.5).
21536     -- A function is called but no prototype has been supplied (6.5.2.2).
21537     -- The arguments in a function call do not agree in number and type with those of the
21538       parameters in a function definition that is not a prototype (6.5.2.2).
21539     -- An object is defined but not used (6.7).
21540     -- A value is given to an object of an enumerated type other than by assignment of an
21541       enumeration constant that is a member of that type, or an enumeration object that has
21542       the same type, or the value of a function that returns the same enumerated type
21543       (6.7.2.2).
21544     -- An aggregate has a partly bracketed initialization (6.7.8).
21545     -- A statement cannot be reached (6.8).
21546     -- A statement with no apparent effect is encountered (6.8).
21547     -- A constant expression is used as the controlling expression of a selection statement
21548       (6.8.4).
21549 [page 547]
21550
21551 -- An incorrectly formed preprocessing group is encountered while skipping a
21552   preprocessing group (6.10.1).
21553 -- An unrecognized #pragma directive is encountered (6.10.6).
21554
21555
21556
21557
21558 [page 548]
21559
21560                                             Annex J
21561                                          (informative)
21562                                       Portability issues
21563 1   This annex collects some information about portability that appears in this International
21564     Standard.
21565     J.1 Unspecified behavior
21566 1   The following are unspecified:
21567     -- The manner and timing of static initialization (5.1.2).
21568     -- The termination status returned to the hosted environment if the return type of main
21569       is not compatible with int (5.1.2.2.3).
21570     -- The behavior of the display device if a printing character is written when the active
21571       position is at the final position of a line (5.2.2).
21572     -- The behavior of the display device if a backspace character is written when the active
21573       position is at the initial position of a line (5.2.2).
21574     -- The behavior of the display device if a horizontal tab character is written when the
21575       active position is at or past the last defined horizontal tabulation position (5.2.2).
21576     -- The behavior of the display device if a vertical tab character is written when the active
21577       position is at or past the last defined vertical tabulation position (5.2.2).
21578     -- How an extended source character that does not correspond to a universal character
21579       name counts toward the significant initial characters in an external identifier (5.2.4.1).
21580     -- Many aspects of the representations of types (6.2.6).
21581     -- The value of padding bytes when storing values in structures or unions (6.2.6.1).
21582     -- The values of bytes that correspond to union members other than the one last stored
21583       into (6.2.6.1).
21584     -- The representation used when storing a value in an object that has more than one
21585       object representation for that value (6.2.6.1).
21586     -- The values of any padding bits in integer representations (6.2.6.2).
21587     -- Whether certain operators can generate negative zeros and whether a negative zero
21588       becomes a normal zero when stored in an object (6.2.6.2).
21589     -- Whether two string literals result in distinct arrays (6.4.5).
21590     -- The order in which subexpressions are evaluated and the order in which side effects
21591       take place, except as specified for the function-call (), &&, ||, ? :, and comma
21592 [page 549]
21593
21594       operators (6.5).
21595 -- The order in which the function designator, arguments, and subexpressions within the
21596   arguments are evaluated in a function call (6.5.2.2).
21597 -- The order of side effects among compound literal initialization list expressions
21598   (6.5.2.5).
21599 -- The order in which the operands of an assignment operator are evaluated (6.5.16).
21600 -- The alignment of the addressable storage unit allocated to hold a bit-field (6.7.2.1).
21601 -- Whether a call to an inline function uses the inline definition or the external definition
21602   of the function (6.7.4).
21603 -- Whether or not a size expression is evaluated when it is part of the operand of a
21604   sizeof operator and changing the value of the size expression would not affect the
21605   result of the operator (6.7.6.2).
21606 -- The order in which any side effects occur among the initialization list expressions in
21607   an initializer (6.7.9).
21608 -- The layout of storage for function parameters (6.9.1).
21609 -- When a fully expanded macro replacement list contains a function-like macro name
21610   as its last preprocessing token and the next preprocessing token from the source file is
21611   a (, and the fully expanded replacement of that macro ends with the name of the first
21612   macro and the next preprocessing token from the source file is again a (, whether that
21613   is considered a nested replacement (6.10.3).
21614 -- The order in which # and ## operations are evaluated during macro substitution
21615   (6.10.3.2, 6.10.3.3).
21616 -- The state of the floating-point status flags when execution passes from a part of the
21617   program translated with FENV_ACCESS ''off'' to a part translated with
21618   FENV_ACCESS ''on'' (7.6.1).
21619 -- The order in which feraiseexcept raises floating-point exceptions, except as
21620   stated in F.8.6 (7.6.2.3).
21621 -- Whether math_errhandling is a macro or an identifier with external linkage
21622   (7.12).
21623 -- The results of the frexp functions when the specified value is not a floating-point
21624   number (7.12.6.4).
21625 -- The numeric result of the ilogb functions when the correct value is outside the
21626   range of the return type (7.12.6.5, F.10.3.5).
21627 -- The result of rounding when the value is out of range (7.12.9.5, 7.12.9.7, F.10.6.5).
21628
21629
21630 [page 550]
21631
21632 -- The value stored by the remquo functions in the object pointed to by quo when y is
21633   zero (7.12.10.3).
21634 -- Whether a comparison macro argument that is represented in a format wider than its
21635   semantic type is converted to the semantic type (7.12.14).
21636 -- Whether setjmp is a macro or an identifier with external linkage (7.13).
21637 -- Whether va_copy and va_end are macros or identifiers with external linkage
21638   (7.16.1).
21639 -- The hexadecimal digit before the decimal point when a non-normalized floating-point
21640   number is printed with an a or A conversion specifier (7.21.6.1, 7.28.2.1).
21641 -- The value of the file position indicator after a successful call to the ungetc function
21642   for a text stream, or the ungetwc function for any stream, until all pushed-back
21643   characters are read or discarded (7.21.7.10, 7.28.3.10).
21644 -- The details of the value stored by the fgetpos function (7.21.9.1).
21645 -- The details of the value returned by the ftell function for a text stream (7.21.9.4).
21646 -- Whether the strtod, strtof, strtold, wcstod, wcstof, and wcstold
21647   functions convert a minus-signed sequence to a negative number directly or by
21648   negating the value resulting from converting the corresponding unsigned sequence
21649   (7.22.1.3, 7.28.4.1.1).
21650 -- The order and contiguity of storage allocated by successive calls to the calloc,
21651   malloc, and realloc functions (7.22.3).
21652 -- The amount of storage allocated by a successful call to the calloc, malloc, or
21653   realloc function when 0 bytes was requested (7.22.3).
21654 -- Which of two elements that compare as equal is matched by the bsearch function
21655   (7.22.5.1).
21656 -- The order of two elements that compare as equal in an array sorted by the qsort
21657   function (7.22.5.2).
21658 -- The encoding of the calendar time returned by the time function (7.26.2.4).
21659 -- The characters stored by the strftime or wcsftime function if any of the time
21660   values being converted is outside the normal range (7.26.3.5, 7.28.5.1).
21661 -- The conversion state after an encoding error occurs (7.28.6.3.2, 7.28.6.3.3, 7.28.6.4.1,
21662   7.28.6.4.2,
21663 -- The resulting value when the ''invalid'' floating-point exception is raised during
21664   IEC 60559 floating to integer conversion (F.4).
21665
21666
21667
21668 [page 551]
21669
21670     -- Whether conversion of non-integer IEC 60559 floating values to integer raises the
21671       ''inexact'' floating-point exception (F.4).
21672     -- Whether or when library functions in <math.h> raise the ''inexact'' floating-point
21673       exception in an IEC 60559 conformant implementation (F.10).
21674     -- Whether or when library functions in <math.h> raise an undeserved ''underflow''
21675       floating-point exception in an IEC 60559 conformant implementation (F.10).
21676     -- The exponent value stored by frexp for a NaN or infinity (F.10.3.4).
21677     -- The numeric result returned by the lrint, llrint, lround, and llround
21678       functions if the rounded value is outside the range of the return type (F.10.6.5,
21679       F.10.6.7).
21680     -- The sign of one part of the complex result of several math functions for certain
21681       exceptional values in IEC 60559 compatible implementations (G.6.1.1, G.6.2.2,
21682       G.6.2.3, G.6.2.4, G.6.2.5, G.6.2.6, G.6.3.1, G.6.4.2).
21683     J.2 Undefined behavior
21684 1   The behavior is undefined in the following circumstances:
21685     -- A ''shall'' or ''shall not'' requirement that appears outside of a constraint is violated
21686       (clause 4).
21687     -- A nonempty source file does not end in a new-line character which is not immediately
21688       preceded by a backslash character or ends in a partial preprocessing token or
21689       comment (5.1.1.2).
21690     -- Token concatenation produces a character sequence matching the syntax of a
21691       universal character name (5.1.1.2).
21692     -- A program in a hosted environment does not define a function named main using one
21693       of the specified forms (5.1.2.2.1).
21694     -- The execution of a program contains a data race (5.1.2.4).
21695     -- A character not in the basic source character set is encountered in a source file, except
21696       in an identifier, a character constant, a string literal, a header name, a comment, or a
21697       preprocessing token that is never converted to a token (5.2.1).
21698     -- An identifier, comment, string literal, character constant, or header name contains an
21699       invalid multibyte character or does not begin and end in the initial shift state (5.2.1.2).
21700     -- The same identifier has both internal and external linkage in the same translation unit
21701       (6.2.2).
21702     -- An object is referred to outside of its lifetime (6.2.4).
21703
21704
21705
21706 [page 552]
21707
21708 -- The value of a pointer to an object whose lifetime has ended is used (6.2.4).
21709 -- The value of an object with automatic storage duration is used while it is
21710   indeterminate (6.2.4, 6.7.9, 6.8).
21711 -- A trap representation is read by an lvalue expression that does not have character type
21712   (6.2.6.1).
21713 -- A trap representation is produced by a side effect that modifies any part of the object
21714   using an lvalue expression that does not have character type (6.2.6.1).
21715 -- The operands to certain operators are such that they could produce a negative zero
21716   result, but the implementation does not support negative zeros (6.2.6.2).
21717 -- Two declarations of the same object or function specify types that are not compatible
21718   (6.2.7).
21719 -- A program requires the formation of a composite type from a variable length array
21720   type whose size is specified by an expression that is not evaluated (6.2.7).
21721 -- Conversion to or from an integer type produces a value outside the range that can be
21722   represented (6.3.1.4).
21723 -- Demotion of one real floating type to another produces a value outside the range that
21724   can be represented (6.3.1.5).
21725 -- An lvalue does not designate an object when evaluated (6.3.2.1).
21726 -- A non-array lvalue with an incomplete type is used in a context that requires the value
21727   of the designated object (6.3.2.1).
21728 -- An lvalue designating an object of automatic storage duration that could have been
21729   declared with the register storage class is used in a context that requires the value
21730   of the designated object, but the object is uninitialized. (6.3.2.1).
21731 -- An lvalue having array type is converted to a pointer to the initial element of the
21732   array, and the array object has register storage class (6.3.2.1).
21733 -- An attempt is made to use the value of a void expression, or an implicit or explicit
21734   conversion (except to void) is applied to a void expression (6.3.2.2).
21735 -- Conversion of a pointer to an integer type produces a value outside the range that can
21736   be represented (6.3.2.3).
21737 -- Conversion between two pointer types produces a result that is incorrectly aligned
21738   (6.3.2.3).
21739 -- A pointer is used to call a function whose type is not compatible with the referenced
21740   type (6.3.2.3).
21741
21742
21743
21744 [page 553]
21745
21746 -- An unmatched ' or " character is encountered on a logical source line during
21747   tokenization (6.4).
21748 -- A reserved keyword token is used in translation phase 7 or 8 for some purpose other
21749   than as a keyword (6.4.1).
21750 -- A universal character name in an identifier does not designate a character whose
21751   encoding falls into one of the specified ranges (6.4.2.1).
21752 -- The initial character of an identifier is a universal character name designating a digit
21753   (6.4.2.1).
21754 -- Two identifiers differ only in nonsignificant characters (6.4.2.1).
21755 -- The identifier __func__ is explicitly declared (6.4.2.2).
21756 -- The program attempts to modify a string literal (6.4.5).
21757 -- The characters ', \, ", //, or /* occur in the sequence between the < and >
21758   delimiters, or the characters ', \, //, or /* occur in the sequence between the "
21759   delimiters, in a header name preprocessing token (6.4.7).
21760 -- A side effect on a scalar object is unsequenced relative to either a different side effect
21761   on the same scalar object or a value computation using the value of the same scalar
21762   object (6.5).
21763 -- An exceptional condition occurs during the evaluation of an expression (6.5).
21764 -- An object has its stored value accessed other than by an lvalue of an allowable type
21765   (6.5).
21766 -- For a call to a function without a function prototype in scope, the number of
21767   arguments does not equal the number of parameters (6.5.2.2).
21768 -- For call to a function without a function prototype in scope where the function is
21769   defined with a function prototype, either the prototype ends with an ellipsis or the
21770   types of the arguments after promotion are not compatible with the types of the
21771   parameters (6.5.2.2).
21772 -- For a call to a function without a function prototype in scope where the function is not
21773   defined with a function prototype, the types of the arguments after promotion are not
21774   compatible with those of the parameters after promotion (with certain exceptions)
21775   (6.5.2.2).
21776 -- A function is defined with a type that is not compatible with the type (of the
21777   expression) pointed to by the expression that denotes the called function (6.5.2.2).
21778 -- A member of an _Atomic-qualified structure or union is accessed (6.5.2.3).
21779 -- The operand of the unary * operator has an invalid value (6.5.3.2).
21780
21781
21782 [page 554]
21783
21784 -- A pointer is converted to other than an integer or pointer type (6.5.4).
21785 -- The value of the second operand of the / or % operator is zero (6.5.5).
21786 -- Addition or subtraction of a pointer into, or just beyond, an array object and an
21787   integer type produces a result that does not point into, or just beyond, the same array
21788   object (6.5.6).
21789 -- Addition or subtraction of a pointer into, or just beyond, an array object and an
21790   integer type produces a result that points just beyond the array object and is used as
21791   the operand of a unary * operator that is evaluated (6.5.6).
21792 -- Pointers that do not point into, or just beyond, the same array object are subtracted
21793   (6.5.6).
21794 -- An array subscript is out of range, even if an object is apparently accessible with the
21795   given subscript (as in the lvalue expression a[1][7] given the declaration int
21796   a[4][5]) (6.5.6).
21797 -- The result of subtracting two pointers is not representable in an object of type
21798   ptrdiff_t (6.5.6).
21799 -- An expression is shifted by a negative number or by an amount greater than or equal
21800   to the width of the promoted expression (6.5.7).
21801 -- An expression having signed promoted type is left-shifted and either the value of the
21802   expression is negative or the result of shifting would be not be representable in the
21803   promoted type (6.5.7).
21804 -- Pointers that do not point to the same aggregate or union (nor just beyond the same
21805   array object) are compared using relational operators (6.5.8).
21806 -- An object is assigned to an inexactly overlapping object or to an exactly overlapping
21807   object with incompatible type (6.5.16.1).
21808 -- An expression that is required to be an integer constant expression does not have an
21809   integer type; has operands that are not integer constants, enumeration constants,
21810   character constants, sizeof expressions whose results are integer constants, or
21811   immediately-cast floating constants; or contains casts (outside operands to sizeof
21812   operators) other than conversions of arithmetic types to integer types (6.6).
21813 -- A constant expression in an initializer is not, or does not evaluate to, one of the
21814   following: an arithmetic constant expression, a null pointer constant, an address
21815   constant, or an address constant for a complete object type plus or minus an integer
21816   constant expression (6.6).
21817 -- An arithmetic constant expression does not have arithmetic type; has operands that
21818   are not integer constants, floating constants, enumeration constants, character
21819   constants, or sizeof expressions; or contains casts (outside operands to sizeof
21820
21821 [page 555]
21822
21823    operators) other than conversions of arithmetic types to arithmetic types (6.6).
21824 -- The value of an object is accessed by an array-subscript [], member-access . or ->,
21825   address &, or indirection * operator or a pointer cast in creating an address constant
21826   (6.6).
21827 -- An identifier for an object is declared with no linkage and the type of the object is
21828   incomplete after its declarator, or after its init-declarator if it has an initializer (6.7).
21829 -- A function is declared at block scope with an explicit storage-class specifier other
21830   than extern (6.7.1).
21831 -- A structure or union is defined as containing no named members, no anonymous
21832   structures, and no anonymous unions (6.7.2.1).
21833 -- An attempt is made to access, or generate a pointer to just past, a flexible array
21834   member of a structure when the referenced object provides no elements for that array
21835   (6.7.2.1).
21836 -- When the complete type is needed, an incomplete structure or union type is not
21837   completed in the same scope by another declaration of the tag that defines the content
21838   (6.7.2.3).
21839 -- An attempt is made to modify an object defined with a const-qualified type through
21840   use of an lvalue with non-const-qualified type (6.7.3).
21841 -- An attempt is made to refer to an object defined with a volatile-qualified type through
21842   use of an lvalue with non-volatile-qualified type (6.7.3).
21843 -- An attempt is made to refer to an object defined with an _Atomic-qualified type
21844   through use of an lvalue with non-_Atomic-qualified type (6.7.3).
21845 -- The specification of a function type includes any type qualifiers (6.7.3).
21846 -- Two qualified types that are required to be compatible do not have the identically
21847   qualified version of a compatible type (6.7.3).
21848 -- An object which has been modified is accessed through a restrict-qualified pointer to
21849   a const-qualified type, or through a restrict-qualified pointer and another pointer that
21850   are not both based on the same object (6.7.3.1).
21851 -- A restrict-qualified pointer is assigned a value based on another restricted pointer
21852   whose associated block neither began execution before the block associated with this
21853   pointer, nor ended before the assignment (6.7.3.1).
21854 -- A function with external linkage is declared with an inline function specifier, but is
21855   not also defined in the same translation unit (6.7.4).
21856 -- A function declared with a _Noreturn function specifier returns to its caller (6.7.4).
21857
21858
21859 [page 556]
21860
21861 -- The definition of an object has an alignment specifier and another declaration of that
21862   object has a different alignment specifier (6.7.5).
21863 -- Declarations of an object in different translation units have different alignment
21864   specifiers (6.7.5).
21865 -- Two pointer types that are required to be compatible are not identically qualified, or
21866   are not pointers to compatible types (6.7.6.1).
21867 -- The size expression in an array declaration is not a constant expression and evaluates
21868   at program execution time to a nonpositive value (6.7.6.2).
21869 -- In a context requiring two array types to be compatible, they do not have compatible
21870   element types, or their size specifiers evaluate to unequal values (6.7.6.2).
21871 -- A declaration of an array parameter includes the keyword static within the [ and
21872   ] and the corresponding argument does not provide access to the first element of an
21873   array with at least the specified number of elements (6.7.6.3).
21874 -- A storage-class specifier or type qualifier modifies the keyword void as a function
21875   parameter type list (6.7.6.3).
21876 -- In a context requiring two function types to be compatible, they do not have
21877   compatible return types, or their parameters disagree in use of the ellipsis terminator
21878   or the number and type of parameters (after default argument promotion, when there
21879   is no parameter type list or when one type is specified by a function definition with an
21880   identifier list) (6.7.6.3).
21881 -- The value of an unnamed member of a structure or union is used (6.7.9).
21882 -- The initializer for a scalar is neither a single expression nor a single expression
21883   enclosed in braces (6.7.9).
21884 -- The initializer for a structure or union object that has automatic storage duration is
21885   neither an initializer list nor a single expression that has compatible structure or union
21886   type (6.7.9).
21887 -- The initializer for an aggregate or union, other than an array initialized by a string
21888   literal, is not a brace-enclosed list of initializers for its elements or members (6.7.9).
21889 -- An identifier with external linkage is used, but in the program there does not exist
21890   exactly one external definition for the identifier, or the identifier is not used and there
21891   exist multiple external definitions for the identifier (6.9).
21892 -- A function definition includes an identifier list, but the types of the parameters are not
21893   declared in a following declaration list (6.9.1).
21894 -- An adjusted parameter type in a function definition is not a complete object type
21895   (6.9.1).
21896
21897 [page 557]
21898
21899 -- A function that accepts a variable number of arguments is defined without a
21900   parameter type list that ends with the ellipsis notation (6.9.1).
21901 -- The } that terminates a function is reached, and the value of the function call is used
21902   by the caller (6.9.1).
21903 -- An identifier for an object with internal linkage and an incomplete type is declared
21904   with a tentative definition (6.9.2).
21905 -- The token defined is generated during the expansion of a #if or #elif
21906   preprocessing directive, or the use of the defined unary operator does not match
21907   one of the two specified forms prior to macro replacement (6.10.1).
21908 -- The #include preprocessing directive that results after expansion does not match
21909   one of the two header name forms (6.10.2).
21910 -- The character sequence in an #include preprocessing directive does not start with a
21911   letter (6.10.2).
21912 -- There are sequences of preprocessing tokens within the list of macro arguments that
21913   would otherwise act as preprocessing directives (6.10.3).
21914 -- The result of the preprocessing operator # is not a valid character string literal
21915   (6.10.3.2).
21916 -- The result of the preprocessing operator ## is not a valid preprocessing token
21917   (6.10.3.3).
21918 -- The #line preprocessing directive that results after expansion does not match one of
21919   the two well-defined forms, or its digit sequence specifies zero or a number greater
21920   than 2147483647 (6.10.4).
21921 -- A non-STDC #pragma preprocessing directive that is documented as causing
21922   translation failure or some other form of undefined behavior is encountered (6.10.6).
21923 -- A #pragma STDC preprocessing directive does not match one of the well-defined
21924   forms (6.10.6).
21925 -- The name of a predefined macro, or the identifier defined, is the subject of a
21926   #define or #undef preprocessing directive (6.10.8).
21927 -- An attempt is made to copy an object to an overlapping object by use of a library
21928   function, other than as explicitly allowed (e.g., memmove) (clause 7).
21929 -- A file with the same name as one of the standard headers, not provided as part of the
21930   implementation, is placed in any of the standard places that are searched for included
21931   source files (7.1.2).
21932 -- A header is included within an external declaration or definition (7.1.2).
21933
21934
21935 [page 558]
21936
21937 -- A function, object, type, or macro that is specified as being declared or defined by
21938   some standard header is used before any header that declares or defines it is included
21939   (7.1.2).
21940 -- A standard header is included while a macro is defined with the same name as a
21941   keyword (7.1.2).
21942 -- The program attempts to declare a library function itself, rather than via a standard
21943   header, but the declaration does not have external linkage (7.1.2).
21944 -- The program declares or defines a reserved identifier, other than as allowed by 7.1.4
21945   (7.1.3).
21946 -- The program removes the definition of a macro whose name begins with an
21947   underscore and either an uppercase letter or another underscore (7.1.3).
21948 -- An argument to a library function has an invalid value or a type not expected by a
21949   function with variable number of arguments (7.1.4).
21950 -- The pointer passed to a library function array parameter does not have a value such
21951   that all address computations and object accesses are valid (7.1.4).
21952 -- The macro definition of assert is suppressed in order to access an actual function
21953   (7.2).
21954 -- The argument to the assert macro does not have a scalar type (7.2).
21955 -- The CX_LIMITED_RANGE, FENV_ACCESS, or FP_CONTRACT pragma is used in
21956   any context other than outside all external declarations or preceding all explicit
21957   declarations and statements inside a compound statement (7.3.4, 7.6.1, 7.12.2).
21958 -- The value of an argument to a character handling function is neither equal to the value
21959   of EOF nor representable as an unsigned char (7.4).
21960 -- A macro definition of errno is suppressed in order to access an actual object, or the
21961   program defines an identifier with the name errno (7.5).
21962 -- Part of the program tests floating-point status flags, sets floating-point control modes,
21963   or runs under non-default mode settings, but was translated with the state for the
21964   FENV_ACCESS pragma ''off'' (7.6.1).
21965 -- The exception-mask argument for one of the functions that provide access to the
21966   floating-point status flags has a nonzero value not obtained by bitwise OR of the
21967   floating-point exception macros (7.6.2).
21968 -- The fesetexceptflag function is used to set floating-point status flags that were
21969   not specified in the call to the fegetexceptflag function that provided the value
21970   of the corresponding fexcept_t object (7.6.2.4).
21971
21972
21973
21974 [page 559]
21975
21976 -- The argument to fesetenv or feupdateenv is neither an object set by a call to
21977   fegetenv or feholdexcept, nor is it an environment macro (7.6.4.3, 7.6.4.4).
21978 -- The value of the result of an integer arithmetic or conversion function cannot be
21979   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).
21980 -- The program modifies the string pointed to by the value returned by the setlocale
21981   function (7.11.1.1).
21982 -- The program modifies the structure pointed to by the value returned by the
21983   localeconv function (7.11.2.1).
21984 -- A macro definition of math_errhandling is suppressed or the program defines
21985   an identifier with the name math_errhandling (7.12).
21986 -- An argument to a floating-point classification or comparison macro is not of real
21987   floating type (7.12.3, 7.12.14).
21988 -- A macro definition of setjmp is suppressed in order to access an actual function, or
21989   the program defines an external identifier with the name setjmp (7.13).
21990 -- An invocation of the setjmp macro occurs other than in an allowed context
21991   (7.13.2.1).
21992 -- The longjmp function is invoked to restore a nonexistent environment (7.13.2.1).
21993 -- After a longjmp, there is an attempt to access the value of an object of automatic
21994   storage duration that does not have volatile-qualified type, local to the function
21995   containing the invocation of the corresponding setjmp macro, that was changed
21996   between the setjmp invocation and longjmp call (7.13.2.1).
21997 -- The program specifies an invalid pointer to a signal handler function (7.14.1.1).
21998 -- A signal handler returns when the signal corresponded to a computational exception
21999   (7.14.1.1).
22000 -- A signal occurs as the result of calling the abort or raise function, and the signal
22001   handler calls the raise function (7.14.1.1).
22002 -- A signal occurs other than as the result of calling the abort or raise function, and
22003   the signal handler refers to an object with static storage duration other than by
22004   assigning a value to an object declared as volatile sig_atomic_t, or calls any
22005   function in the standard library other than the abort function, the _Exit function,
22006   the quick_exit function, or the signal function (for the same signal number)
22007   (7.14.1.1).
22008 -- The value of errno is referred to after a signal occurred other than as the result of
22009   calling the abort or raise function and the corresponding signal handler obtained
22010   a SIG_ERR return from a call to the signal function (7.14.1.1).
22011
22012 [page 560]
22013
22014 -- A signal is generated by an asynchronous signal handler (7.14.1.1).
22015 -- A function with a variable number of arguments attempts to access its varying
22016   arguments other than through a properly declared and initialized va_list object, or
22017   before the va_start macro is invoked (7.16, 7.16.1.1, 7.16.1.4).
22018 -- The macro va_arg is invoked using the parameter ap that was passed to a function
22019   that invoked the macro va_arg with the same parameter (7.16).
22020 -- A macro definition of va_start, va_arg, va_copy, or va_end is suppressed in
22021   order to access an actual function, or the program defines an external identifier with
22022   the name va_copy or va_end (7.16.1).
22023 -- The va_start or va_copy macro is invoked without a corresponding invocation
22024   of the va_end macro in the same function, or vice versa (7.16.1, 7.16.1.2, 7.16.1.3,
22025   7.16.1.4).
22026 -- The type parameter to the va_arg macro is not such that a pointer to an object of
22027   that type can be obtained simply by postfixing a * (7.16.1.1).
22028 -- The va_arg macro is invoked when there is no actual next argument, or with a
22029   specified type that is not compatible with the promoted type of the actual next
22030   argument, with certain exceptions (7.16.1.1).
22031 -- The va_copy or va_start macro is called to initialize a va_list that was
22032   previously initialized by either macro without an intervening invocation of the
22033   va_end macro for the same va_list (7.16.1.2, 7.16.1.4).
22034 -- The parameter parmN of a va_start macro is declared with the register
22035   storage class, with a function or array type, or with a type that is not compatible with
22036   the type that results after application of the default argument promotions (7.16.1.4).
22037 -- The member designator parameter of an offsetof macro is an invalid right
22038   operand of the . operator for the type parameter, or designates a bit-field (7.19).
22039 -- The argument in an instance of one of the integer-constant macros is not a decimal,
22040   octal, or hexadecimal constant, or it has a value that exceeds the limits for the
22041   corresponding type (7.20.4).
22042 -- A byte input/output function is applied to a wide-oriented stream, or a wide character
22043   input/output function is applied to a byte-oriented stream (7.21.2).
22044 -- Use is made of any portion of a file beyond the most recent wide character written to
22045   a wide-oriented stream (7.21.2).
22046 -- The value of a pointer to a FILE object is used after the associated file is closed
22047   (7.21.3).
22048 -- The stream for the fflush function points to an input stream or to an update stream
22049     in which the most recent operation was input (7.21.5.2).
22050 [page 561]
22051
22052 -- The string pointed to by the mode argument in a call to the fopen function does not
22053   exactly match one of the specified character sequences (7.21.5.3).
22054 -- An output operation on an update stream is followed by an input operation without an
22055   intervening call to the fflush function or a file positioning function, or an input
22056   operation on an update stream is followed by an output operation with an intervening
22057   call to a file positioning function (7.21.5.3).
22058 -- An attempt is made to use the contents of the array that was supplied in a call to the
22059   setvbuf function (7.21.5.6).
22060 -- There are insufficient arguments for the format in a call to one of the formatted
22061   input/output functions, or an argument does not have an appropriate type (7.21.6.1,
22062   7.21.6.2, 7.28.2.1, 7.28.2.2).
22063 -- The format in a call to one of the formatted input/output functions or to the
22064   strftime or wcsftime function is not a valid multibyte character sequence that
22065   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,
22066   7.28.5.1).
22067 -- In a call to one of the formatted output functions, a precision appears with a
22068   conversion specifier other than those described (7.21.6.1, 7.28.2.1).
22069 -- A conversion specification for a formatted output function uses an asterisk to denote
22070   an argument-supplied field width or precision, but the corresponding argument is not
22071   provided (7.21.6.1, 7.28.2.1).
22072 -- A conversion specification for a formatted output function uses a # or 0 flag with a
22073   conversion specifier other than those described (7.21.6.1, 7.28.2.1).
22074 -- A conversion specification for one of the formatted input/output functions uses a
22075   length modifier with a conversion specifier other than those described (7.21.6.1,
22076   7.21.6.2, 7.28.2.1, 7.28.2.2).
22077 -- An s conversion specifier is encountered by one of the formatted output functions,
22078   and the argument is missing the null terminator (unless a precision is specified that
22079   does not require null termination) (7.21.6.1, 7.28.2.1).
22080 -- An n conversion specification for one of the formatted input/output functions includes
22081   any flags, an assignment-suppressing character, a field width, or a precision (7.21.6.1,
22082   7.21.6.2, 7.28.2.1, 7.28.2.2).
22083 -- A % conversion specifier is encountered by one of the formatted input/output
22084   functions, but the complete conversion specification is not exactly %% (7.21.6.1,
22085   7.21.6.2, 7.28.2.1, 7.28.2.2).
22086 -- An invalid conversion specification is found in the format for one of the formatted
22087   input/output functions, or the strftime or wcsftime function (7.21.6.1, 7.21.6.2,
22088
22089 [page 562]
22090
22091    7.26.3.5, 7.28.2.1, 7.28.2.2, 7.28.5.1).
22092 -- The number of characters transmitted by a formatted output function is greater than
22093   INT_MAX (7.21.6.1, 7.21.6.3, 7.21.6.8, 7.21.6.10).
22094 -- The result of a conversion by one of the formatted input functions cannot be
22095   represented in the corresponding object, or the receiving object does not have an
22096   appropriate type (7.21.6.2, 7.28.2.2).
22097 -- A c, s, or [ conversion specifier is encountered by one of the formatted input
22098   functions, and the array pointed to by the corresponding argument is not large enough
22099   to accept the input sequence (and a null terminator if the conversion specifier is s or
22100   [) (7.21.6.2, 7.28.2.2).
22101 -- A c, s, or [ conversion specifier with an l qualifier is encountered by one of the
22102   formatted input functions, but the input is not a valid multibyte character sequence
22103   that begins in the initial shift state (7.21.6.2, 7.28.2.2).
22104 -- The input item for a %p conversion by one of the formatted input functions is not a
22105   value converted earlier during the same program execution (7.21.6.2, 7.28.2.2).
22106 -- The vfprintf, vfscanf, vprintf, vscanf, vsnprintf, vsprintf,
22107   vsscanf, vfwprintf, vfwscanf, vswprintf, vswscanf, vwprintf, or
22108   vwscanf function is called with an improperly initialized va_list argument, or
22109   the argument is used (other than in an invocation of va_end) after the function
22110   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,
22111   7.28.2.5, 7.28.2.6, 7.28.2.7, 7.28.2.8, 7.28.2.9, 7.28.2.10).
22112 -- The contents of the array supplied in a call to the fgets or fgetws function are
22113   used after a read error occurred (7.21.7.2, 7.28.3.2).
22114 -- The file position indicator for a binary stream is used after a call to the ungetc
22115   function where its value was zero before the call (7.21.7.10).
22116 -- The file position indicator for a stream is used after an error occurred during a call to
22117   the fread or fwrite function (7.21.8.1, 7.21.8.2).
22118 -- A partial element read by a call to the fread function is used (7.21.8.1).
22119 -- The fseek function is called for a text stream with a nonzero offset and either the
22120   offset was not returned by a previous successful call to the ftell function on a
22121   stream associated with the same file or whence is not SEEK_SET (7.21.9.2).
22122 -- The fsetpos function is called to set a position that was not returned by a previous
22123   successful call to the fgetpos function on a stream associated with the same file
22124   (7.21.9.3).
22125 -- A non-null pointer returned by a call to the calloc, malloc, or realloc function
22126   with a zero requested size is used to access an object (7.22.3).
22127
22128 [page 563]
22129
22130 -- The value of a pointer that refers to space deallocated by a call to the free or
22131   realloc function is used (7.22.3).
22132 -- The alignment requested of the aligned_alloc function is not valid or not
22133   supported by the implementation, or the size requested is not an integral multiple of
22134   the alignment (7.22.3.1).
22135 -- The pointer argument to the free or realloc function does not match a pointer
22136   earlier returned by a memory management function, or the space has been deallocated
22137   by a call to free or realloc (7.22.3.3, 7.22.3.5).
22138 -- The value of the object allocated by the malloc function is used (7.22.3.4).
22139 -- The value of any bytes in a new object allocated by the realloc function beyond
22140   the size of the old object are used (7.22.3.5).
22141 -- The program calls the exit or quick_exit function more than once, or calls both
22142   functions (7.22.4.4, 7.22.4.7).
22143 -- During the call to a function registered with the atexit or at_quick_exit
22144   function, a call is made to the longjmp function that would terminate the call to the
22145   registered function (7.22.4.4, 7.22.4.7).
22146 -- The string set up by the getenv or strerror function is modified by the program
22147   (7.22.4.6, 7.23.6.2).
22148 -- A command is executed through the system function in a way that is documented as
22149   causing termination or some other form of undefined behavior (7.22.4.8).
22150 -- A searching or sorting utility function is called with an invalid pointer argument, even
22151   if the number of elements is zero (7.22.5).
22152 -- The comparison function called by a searching or sorting utility function alters the
22153   contents of the array being searched or sorted, or returns ordering values
22154   inconsistently (7.22.5).
22155 -- The array being searched by the bsearch function does not have its elements in
22156   proper order (7.22.5.1).
22157 -- The current conversion state is used by a multibyte/wide character conversion
22158   function after changing the LC_CTYPE category (7.22.7).
22159 -- A string or wide string utility function is instructed to access an array beyond the end
22160   of an object (7.23.1, 7.28.4).
22161 -- A string or wide string utility function is called with an invalid pointer argument, even
22162   if the length is zero (7.23.1, 7.28.4).
22163 -- The contents of the destination array are used after a call to the strxfrm,
22164   strftime, wcsxfrm, or wcsftime function in which the specified length was
22165
22166 [page 564]
22167
22168    too small to hold the entire null-terminated result (7.23.4.5, 7.26.3.5, 7.28.4.4.4,
22169    7.28.5.1).
22170 -- The first argument in the very first call to the strtok or wcstok is a null pointer
22171   (7.23.5.8, 7.28.4.5.7).
22172 -- The type of an argument to a type-generic macro is not compatible with the type of
22173   the corresponding parameter of the selected function (7.24).
22174 -- A complex argument is supplied for a generic parameter of a type-generic macro that
22175   has no corresponding complex function (7.24).
22176 -- At least one field of the broken-down time passed to asctime contains a value
22177   outside its normal range, or the calculated year exceeds four digits or is less than the
22178   year 1000 (7.26.3.1).
22179 -- The argument corresponding to an s specifier without an l qualifier in a call to the
22180   fwprintf function does not point to a valid multibyte character sequence that
22181   begins in the initial shift state (7.28.2.11).
22182 -- In a call to the wcstok function, the object pointed to by ptr does not have the
22183   value stored by the previous call for the same wide string (7.28.4.5.7).
22184 -- An mbstate_t object is used inappropriately (7.28.6).
22185 -- The value of an argument of type wint_t to a wide character classification or case
22186   mapping function is neither equal to the value of WEOF nor representable as a
22187   wchar_t (7.29.1).
22188 -- The iswctype function is called using a different LC_CTYPE category from the
22189   one in effect for the call to the wctype function that returned the description
22190   (7.29.2.2.1).
22191 -- The towctrans function is called using a different LC_CTYPE category from the
22192   one in effect for the call to the wctrans function that returned the description
22193   (7.29.3.2.1).
22194
22195
22196
22197
22198 [page 565]
22199
22200     J.3 Implementation-defined behavior
22201 1   A conforming implementation is required to document its choice of behavior in each of
22202     the areas listed in this subclause. The following are implementation-defined:
22203     J.3.1 Translation
22204 1   -- How a diagnostic is identified (3.10, 5.1.1.3).
22205     -- Whether each nonempty sequence of white-space characters other than new-line is
22206       retained or replaced by one space character in translation phase 3 (5.1.1.2).
22207     J.3.2 Environment
22208 1   -- The mapping between physical source file multibyte characters and the source
22209       character set in translation phase 1 (5.1.1.2).
22210     -- The name and type of the function called at program startup in a freestanding
22211       environment (5.1.2.1).
22212     -- The effect of program termination in a freestanding environment (5.1.2.1).
22213     -- An alternative manner in which the main function may be defined (5.1.2.2.1).
22214     -- The values given to the strings pointed to by the argv argument to main (5.1.2.2.1).
22215     -- What constitutes an interactive device (5.1.2.3).
22216     -- Whether a program can have more than one thread of execution in a freestanding
22217       environment (5.1.2.4).
22218     -- The set of signals, their semantics, and their default handling (7.14).
22219     -- Signal values other than SIGFPE, SIGILL, and SIGSEGV that correspond to a
22220       computational exception (7.14.1.1).
22221     -- Signals for which the equivalent of signal(sig, SIG_IGN); is executed at
22222       program startup (7.14.1.1).
22223     -- The set of environment names and the method for altering the environment list used
22224       by the getenv function (7.22.4.6).
22225     -- The manner of execution of the string by the system function (7.22.4.8).
22226
22227
22228
22229
22230 [page 566]
22231
22232     J.3.3 Identifiers
22233 1   -- Which additional multibyte characters may appear in identifiers and their
22234       correspondence to universal character names (6.4.2).
22235     -- The number of significant initial characters in an identifier (5.2.4.1, 6.4.2).
22236     J.3.4 Characters
22237 1   -- The number of bits in a byte (3.6).
22238     -- The values of the members of the execution character set (5.2.1).
22239     -- The unique value of the member of the execution character set produced for each of
22240       the standard alphabetic escape sequences (5.2.2).
22241     -- The value of a char object into which has been stored any character other than a
22242       member of the basic execution character set (6.2.5).
22243     -- Which of signed char or unsigned char has the same range, representation,
22244       and behavior as ''plain'' char (6.2.5, 6.3.1.1).
22245     -- The mapping of members of the source character set (in character constants and string
22246       literals) to members of the execution character set (6.4.4.4, 5.1.1.2).
22247     -- The value of an integer character constant containing more than one character or
22248       containing a character or escape sequence that does not map to a single-byte
22249       execution character (6.4.4.4).
22250     -- The value of a wide character constant containing more than one multibyte character
22251       or a single multibyte character that maps to multiple members of the extended
22252       execution character set, or containing a multibyte character or escape sequence not
22253       represented in the extended execution character set (6.4.4.4).
22254     -- The current locale used to convert a wide character constant consisting of a single
22255       multibyte character that maps to a member of the extended execution character set
22256       into a corresponding wide character code (6.4.4.4).
22257     -- Whether differently-prefixed wide string literal tokens can be concatenated and, if so,
22258       the treatment of the resulting multibyte character sequence (6.4.5).
22259     -- The current locale used to convert a wide string literal into corresponding wide
22260       character codes (6.4.5).
22261     -- The value of a string literal containing a multibyte character or escape sequence not
22262       represented in the execution character set (6.4.5).
22263     -- The encoding of any of wchar_t, char16_t, and char32_t where the
22264       corresponding  standard   encoding macro      (__STDC_ISO_10646__,
22265       __STDC_UTF_16__, or __STDC_UTF_32__) is not defined (6.10.8.2).
22266
22267 [page 567]
22268
22269     J.3.5 Integers
22270 1   -- Any extended integer types that exist in the implementation (6.2.5).
22271     -- Whether signed integer types are represented using sign and magnitude, two's
22272       complement, or ones' complement, and whether the extraordinary value is a trap
22273       representation or an ordinary value (6.2.6.2).
22274     -- The rank of any extended integer type relative to another extended integer type with
22275       the same precision (6.3.1.1).
22276     -- The result of, or the signal raised by, converting an integer to a signed integer type
22277       when the value cannot be represented in an object of that type (6.3.1.3).
22278     -- The results of some bitwise operations on signed integers (6.5).
22279     J.3.6 Floating point
22280 1   -- The accuracy of the floating-point operations and of the library functions in
22281       <math.h> and <complex.h> that return floating-point results (5.2.4.2.2).
22282     -- The accuracy of the conversions between floating-point internal representations and
22283       string representations performed by the library functions in <stdio.h>,
22284       <stdlib.h>, and <wchar.h> (5.2.4.2.2).
22285     -- The rounding behaviors characterized by non-standard values of FLT_ROUNDS
22286       (5.2.4.2.2).
22287     -- The evaluation methods characterized by non-standard negative values of
22288       FLT_EVAL_METHOD (5.2.4.2.2).
22289     -- The direction of rounding when an integer is converted to a floating-point number that
22290       cannot exactly represent the original value (6.3.1.4).
22291     -- The direction of rounding when a floating-point number is converted to a narrower
22292       floating-point number (6.3.1.5).
22293     -- How the nearest representable value or the larger or smaller representable value
22294       immediately adjacent to the nearest representable value is chosen for certain floating
22295       constants (6.4.4.2).
22296     -- Whether and how floating expressions are contracted when not disallowed by the
22297       FP_CONTRACT pragma (6.5).
22298     -- The default state for the FENV_ACCESS pragma (7.6.1).
22299     -- Additional floating-point exceptions, rounding           modes,     environments,     and
22300       classifications, and their macro names (7.6, 7.12).
22301     -- The default state for the FP_CONTRACT pragma (7.12.2).
22302
22303
22304 [page 568]
22305
22306     J.3.7 Arrays and pointers
22307 1   -- The result of converting a pointer to an integer or vice versa (6.3.2.3).
22308     -- The size of the result of subtracting two pointers to elements of the same array
22309       (6.5.6).
22310     J.3.8 Hints
22311 1   -- The extent to which suggestions made by using the register storage-class
22312       specifier are effective (6.7.1).
22313     -- The extent to which suggestions made by using the inline function specifier are
22314       effective (6.7.4).
22315     J.3.9 Structures, unions, enumerations, and bit-fields
22316 1   -- Whether a ''plain'' int bit-field is treated as a signed int bit-field or as an
22317       unsigned int bit-field (6.7.2, 6.7.2.1).
22318     -- Allowable bit-field types other than _Bool, signed int, and unsigned int
22319       (6.7.2.1).
22320     -- Whether a bit-field can straddle a storage-unit boundary (6.7.2.1).
22321     -- The order of allocation of bit-fields within a unit (6.7.2.1).
22322     -- The alignment of non-bit-field members of structures (6.7.2.1). This should present
22323       no problem unless binary data written by one implementation is read by another.
22324     -- The integer type compatible with each enumerated type (6.7.2.2).
22325     J.3.10 Qualifiers
22326 1   -- What constitutes an access to an object that has volatile-qualified type (6.7.3).
22327     J.3.11 Preprocessing directives
22328 1   -- The locations within #pragma directives where header name preprocessing tokens
22329       are recognized (6.4, 6.4.7).
22330     -- How sequences in both forms of header names are mapped to headers or external
22331       source file names (6.4.7).
22332     -- Whether the value of a character constant in a constant expression that controls
22333       conditional inclusion matches the value of the same character constant in the
22334       execution character set (6.10.1).
22335     -- Whether the value of a single-character character constant in a constant expression
22336       that controls conditional inclusion may have a negative value (6.10.1).
22337     -- The places that are searched for an included < > delimited header, and how the places
22338       are specified or the header is identified (6.10.2).
22339 [page 569]
22340
22341     -- How the named source file is searched for in an included " " delimited header
22342       (6.10.2).
22343     -- The method by which preprocessing tokens (possibly resulting from macro
22344       expansion) in a #include directive are combined into a header name (6.10.2).
22345     -- The nesting limit for #include processing (6.10.2).
22346     -- Whether the # operator inserts a \ character before the \ character that begins a
22347       universal character name in a character constant or string literal (6.10.3.2).
22348     -- The behavior on each recognized non-STDC #pragma directive (6.10.6).
22349     -- The definitions for __DATE__ and __TIME__ when respectively, the date and
22350       time of translation are not available (6.10.8.1).
22351     J.3.12 Library functions
22352 1   -- Any library facilities available to a freestanding program, other than the minimal set
22353       required by clause 4 (5.1.2.1).
22354     -- The format of the diagnostic printed by the assert macro (7.2.1.1).
22355     -- The representation of the floating-point               status   flags   stored   by   the
22356       fegetexceptflag function (7.6.2.2).
22357     -- Whether the feraiseexcept function raises the ''inexact'' floating-point
22358       exception in addition to the ''overflow'' or ''underflow'' floating-point exception
22359       (7.6.2.3).
22360     -- Strings other than "C" and "" that may be passed as the second argument to the
22361       setlocale function (7.11.1.1).
22362     -- The types defined for float_t and double_t when the value of the
22363       FLT_EVAL_METHOD macro is less than 0 (7.12).
22364     -- Domain errors for the mathematics functions, other than those required by this
22365       International Standard (7.12.1).
22366     -- The values returned by the mathematics functions on domain errors or pole errors
22367       (7.12.1).
22368     -- The values returned by the mathematics functions on underflow range errors, whether
22369       errno is set to the value of the macro ERANGE when the integer expression
22370       math_errhandling & MATH_ERRNO is nonzero, and whether the ''underflow''
22371       floating-point exception is raised when the integer expression math_errhandling
22372       & MATH_ERREXCEPT is nonzero. (7.12.1).
22373     -- Whether a domain error occurs or zero is returned when an fmod function has a
22374       second argument of zero (7.12.10.1).
22375
22376 [page 570]
22377
22378 -- Whether a domain error occurs or zero is returned when a remainder function has
22379   a second argument of zero (7.12.10.2).
22380 -- The base-2 logarithm of the modulus used by the remquo functions in reducing the
22381   quotient (7.12.10.3).
22382 -- Whether a domain error occurs or zero is returned when a remquo function has a
22383   second argument of zero (7.12.10.3).
22384 -- Whether the equivalent of signal(sig, SIG_DFL); is executed prior to the call
22385   of a signal handler, and, if not, the blocking of signals that is performed (7.14.1.1).
22386 -- The null pointer constant to which the macro NULL expands (7.19).
22387 -- Whether the last line of a text stream requires a terminating new-line character
22388   (7.21.2).
22389 -- Whether space characters that are written out to a text stream immediately before a
22390   new-line character appear when read in (7.21.2).
22391 -- The number of null characters that may be appended to data written to a binary
22392   stream (7.21.2).
22393 -- Whether the file position indicator of an append-mode stream is initially positioned at
22394   the beginning or end of the file (7.21.3).
22395 -- Whether a write on a text stream causes the associated file to be truncated beyond that
22396   point (7.21.3).
22397 -- The characteristics of file buffering (7.21.3).
22398 -- Whether a zero-length file actually exists (7.21.3).
22399 -- The rules for composing valid file names (7.21.3).
22400 -- Whether the same file can be simultaneously open multiple times (7.21.3).
22401 -- The nature and choice of encodings used for multibyte characters in files (7.21.3).
22402 -- The effect of the remove function on an open file (7.21.4.1).
22403 -- The effect if a file with the new name exists prior to a call to the rename function
22404   (7.21.4.2).
22405 -- Whether an open temporary file is removed upon abnormal program termination
22406   (7.21.4.3).
22407 -- Which changes of mode are permitted (if any), and under what circumstances
22408   (7.21.5.4).
22409 -- The style used to print an infinity or NaN, and the meaning of any n-char or n-wchar
22410   sequence printed for a NaN (7.21.6.1, 7.28.2.1).
22411
22412 [page 571]
22413
22414 -- The output for %p conversion in the fprintf or fwprintf function (7.21.6.1,
22415   7.28.2.1).
22416 -- The interpretation of a - character that is neither the first nor the last character, nor
22417   the second where a ^ character is the first, in the scanlist for %[ conversion in the
22418   fscanf or fwscanf function (7.21.6.2, 7.28.2.1).
22419 -- The set of sequences matched by a %p conversion and the interpretation of the
22420   corresponding input item in the fscanf or fwscanf function (7.21.6.2, 7.28.2.2).
22421 -- The value to which the macro errno is set by the fgetpos, fsetpos, or ftell
22422   functions on failure (7.21.9.1, 7.21.9.3, 7.21.9.4).
22423 -- The meaning of any n-char or n-wchar sequence in a string representing a NaN that is
22424   converted by the strtod, strtof, strtold, wcstod, wcstof, or wcstold
22425   function (7.22.1.3, 7.28.4.1.1).
22426 -- Whether or not the strtod, strtof, strtold, wcstod, wcstof, or wcstold
22427   function sets errno to ERANGE when underflow occurs (7.22.1.3, 7.28.4.1.1).
22428 -- Whether the calloc, malloc, and realloc functions return a null pointer or a
22429   pointer to an allocated object when the size requested is zero (7.22.3).
22430 -- Whether open streams with unwritten buffered data are flushed, open streams are
22431   closed, or temporary files are removed when the abort or _Exit function is called
22432   (7.22.4.1, 7.22.4.5).
22433 -- The termination status returned to the host environment by the abort, exit,
22434   _Exit, or quick_exit function (7.22.4.1, 7.22.4.4, 7.22.4.5, 7.22.4.7).
22435 -- The value returned by the system function when its argument is not a null pointer
22436   (7.22.4.8).
22437 -- The local time zone and Daylight Saving Time (7.26.1).
22438 -- The range and precision of times representable in clock_t and time_t (7.26).
22439 -- The era for the clock function (7.26.2.1).
22440 -- The replacement string for the %Z specifier to the strftime, and wcsftime
22441   functions in the "C" locale (7.26.3.5, 7.28.5.1).
22442 -- Whether the functions in <math.h> honor the rounding direction mode in an
22443   IEC 60559 conformant implementation, unless explicitly specified otherwise (F.10).
22444
22445
22446
22447
22448 [page 572]
22449
22450     J.3.13 Architecture
22451 1   -- The values or expressions assigned to the macros specified in the headers
22452       <float.h>, <limits.h>, and <stdint.h> (5.2.4.2, 7.20.2, 7.20.3).
22453     -- The result of attempting to indirectly access an object with automatic or thread
22454       storage duration from a thread other than the one with which it is associated (6.2.4).
22455     -- The number, order, and encoding of bytes in any object (when not explicitly specified
22456       in this International Standard) (6.2.6.1).
22457     -- Whether any extended alignments are supported and the contexts in which they are
22458       supported (6.2.8).
22459     -- Valid alignment values other than those returned by an alignof expression for
22460       fundamental types, if any (6.2.8).
22461     -- The value of the result of the sizeof and alignof operators (6.5.3.4).
22462     J.4 Locale-specific behavior
22463 1   The following characteristics of a hosted environment are locale-specific and are required
22464     to be documented by the implementation:
22465     -- Additional members of the source and execution character sets beyond the basic
22466       character set (5.2.1).
22467     -- The presence, meaning, and representation of additional multibyte characters in the
22468       execution character set beyond the basic character set (5.2.1.2).
22469     -- The shift states used for the encoding of multibyte characters (5.2.1.2).
22470     -- The direction of writing of successive printing characters (5.2.2).
22471     -- The decimal-point character (7.1.1).
22472     -- The set of printing characters (7.4, 7.29.2).
22473     -- The set of control characters (7.4, 7.29.2).
22474     -- The sets of characters tested for by the isalpha, isblank, islower, ispunct,
22475       isspace, isupper, iswalpha, iswblank, iswlower, iswpunct,
22476       iswspace, or iswupper functions (7.4.1.2, 7.4.1.3, 7.4.1.7, 7.4.1.9, 7.4.1.10,
22477       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).
22478     -- The native environment (7.11.1.1).
22479     -- Additional subject sequences accepted by the numeric conversion functions (7.22.1,
22480       7.28.4.1).
22481     -- The collation sequence of the execution character set (7.23.4.3, 7.28.4.4.2).
22482
22483
22484 [page 573]
22485
22486     -- The contents of the error message strings set up by the strerror function
22487       (7.23.6.2).
22488     -- The formats for time and date (7.26.3.5, 7.28.5.1).
22489     -- Character mappings that are supported by the towctrans function (7.29.1).
22490     -- Character classifications that are supported by the iswctype function (7.29.1).
22491     J.5 Common extensions
22492 1   The following extensions are widely used in many systems, but are not portable to all
22493     implementations. The inclusion of any extension that may cause a strictly conforming
22494     program to become invalid renders an implementation nonconforming. Examples of such
22495     extensions are new keywords, extra library functions declared in standard headers, or
22496     predefined macros with names that do not begin with an underscore.
22497     J.5.1 Environment arguments
22498 1   In a hosted environment, the main function receives a third argument, char *envp[],
22499     that points to a null-terminated array of pointers to char, each of which points to a string
22500     that provides information about the environment for this execution of the program
22501     (5.1.2.2.1).
22502     J.5.2 Specialized identifiers
22503 1   Characters other than the underscore _, letters, and digits, that are not part of the basic
22504     source character set (such as the dollar sign $, or characters in national character sets)
22505     may appear in an identifier (6.4.2).
22506     J.5.3 Lengths and cases of identifiers
22507 1   All characters in identifiers (with or without external linkage) are significant (6.4.2).
22508     J.5.4 Scopes of identifiers
22509 1   A function identifier, or the identifier of an object the declaration of which contains the
22510     keyword extern, has file scope (6.2.1).
22511     J.5.5 Writable string literals
22512 1   String literals are modifiable (in which case, identical string literals should denote distinct
22513     objects) (6.4.5).
22514
22515
22516
22517
22518 [page 574]
22519
22520     J.5.6 Other arithmetic types
22521 1   Additional arithmetic types, such as __int128 or double double, and their
22522     appropriate conversions are defined (6.2.5, 6.3.1). Additional floating types may have
22523     more range or precision than long double, may be used for evaluating expressions of
22524     other floating types, and may be used to define float_t or double_t.
22525     J.5.7 Function pointer casts
22526 1   A pointer to an object or to void may be cast to a pointer to a function, allowing data to
22527     be invoked as a function (6.5.4).
22528 2   A pointer to a function may be cast to a pointer to an object or to void, allowing a
22529     function to be inspected or modified (for example, by a debugger) (6.5.4).
22530     J.5.8 Extended bit-field types
22531 1   A bit-field may be declared with a type other than _Bool, unsigned int, or
22532     signed int, with an appropriate maximum width (6.7.2.1).
22533     J.5.9 The fortran keyword
22534 1   The fortran function specifier may be used in a function declaration to indicate that
22535     calls suitable for FORTRAN should be generated, or that a different representation for the
22536     external name is to be generated (6.7.4).
22537     J.5.10 The asm keyword
22538 1   The asm keyword may be used to insert assembly language directly into the translator
22539     output (6.8). The most common implementation is via a statement of the form:
22540               asm ( character-string-literal );
22541     J.5.11 Multiple external definitions
22542 1   There may be more than one external definition for the identifier of an object, with or
22543     without the explicit use of the keyword extern; if the definitions disagree, or more than
22544     one is initialized, the behavior is undefined (6.9.2).
22545     J.5.12 Predefined macro names
22546 1   Macro names that do not begin with an underscore, describing the translation and
22547     execution environments, are defined by the implementation before translation begins
22548     (6.10.8).
22549
22550
22551
22552
22553 [page 575]
22554
22555     J.5.13 Floating-point status flags
22556 1   If any floating-point status flags are set on normal termination after all calls to functions
22557     registered by the atexit function have been made (see 7.22.4.4), the implementation
22558     writes some diagnostics indicating the fact to the stderr stream, if it is still open,
22559     J.5.14 Extra arguments for signal handlers
22560 1   Handlers for specific signals are called with extra arguments in addition to the signal
22561     number (7.14.1.1).
22562     J.5.15 Additional stream types and file-opening modes
22563 1   Additional mappings from files to streams are supported (7.21.2).
22564 2   Additional file-opening modes may be specified by characters appended to the mode
22565     argument of the fopen function (7.21.5.3).
22566     J.5.16 Defined file position indicator
22567 1   The file position indicator is decremented by each successful call to the ungetc or
22568     ungetwc function for a text stream, except if its value was zero before a call (7.21.7.10,
22569     7.28.3.10).
22570     J.5.17 Math error reporting
22571 1   Functions declared in <complex.h> and <math.h> raise SIGFPE to report errors
22572     instead of, or in addition to, setting errno or raising floating-point exceptions (7.3,
22573     7.12).
22574
22575
22576
22577
22578 [page 576]
22579
22580                                            Annex K
22581                                           (normative)
22582                               Bounds-checking interfaces
22583     K.1 Background
22584 1   Traditionally, the C Library has contained many functions that trust the programmer to
22585     provide output character arrays big enough to hold the result being produced. Not only
22586     do these functions not check that the arrays are big enough, they frequently lack the
22587     information needed to perform such checks. While it is possible to write safe, robust, and
22588     error-free code using the existing library, the library tends to promote programming styles
22589     that lead to mysterious failures if a result is too big for the provided array.
22590 2   A common programming style is to declare character arrays large enough to handle most
22591     practical cases. However, if these arrays are not large enough to handle the resulting
22592     strings, data can be written past the end of the array overwriting other data and program
22593     structures. The program never gets any indication that a problem exists, and so never has
22594     a chance to recover or to fail gracefully.
22595 3   Worse, this style of programming has compromised the security of computers and
22596     networks. Buffer overflows can often be exploited to run arbitrary code with the
22597     permissions of the vulnerable (defective) program.
22598 4   If the programmer writes runtime checks to verify lengths before calling library
22599     functions, then those runtime checks frequently duplicate work done inside the library
22600     functions, which discover string lengths as a side effect of doing their job.
22601 5   This annex provides alternative library functions that promote safer, more secure
22602     programming. The alternative functions verify that output buffers are large enough for
22603     the intended result and return a failure indicator if they are not. Data is never written past
22604     the end of an array. All string results are null terminated.
22605 6   This annex also addresses another problem that complicates writing robust code:
22606     functions that are not reentrant because they return pointers to static objects owned by the
22607     function. Such functions can be troublesome since a previously returned result can
22608     change if the function is called again, perhaps by another thread.
22609
22610
22611
22612
22613 [page 577]
22614
22615     K.2 Scope
22616 1   This annex specifies a series of optional extensions that can be useful in the mitigation of
22617     security vulnerabilities in programs, and comprise new functions, macros, and types
22618     declared or defined in existing standard headers.
22619 2   An implementation that defines __STDC_LIB_EXT1__ shall conform to the
22620     specifications in this annex.361)
22621 3   Subclause K.3 should be read as if it were merged into the parallel structure of named
22622     subclauses of clause 7.
22623     K.3 Library
22624     K.3.1 Introduction
22625     K.3.1.1 Standard headers
22626 1   The functions, macros, and types declared or defined in K.3 and its subclauses are not
22627     declared or defined by their respective headers if __STDC_WANT_LIB_EXT1__ is
22628     defined as a macro which expands to the integer constant 0 at the point in the source file
22629     where the appropriate header is first included.
22630 2   The functions, macros, and types declared or defined in K.3 and its subclauses are
22631     declared and defined by their respective headers if __STDC_WANT_LIB_EXT1__ is
22632     defined as a macro which expands to the integer constant 1 at the point in the source file
22633     where the appropriate header is first included.362)
22634 3   It is implementation-defined whether the functions, macros, and types declared or defined
22635     in K.3 and its subclauses are declared or defined by their respective headers if
22636     __STDC_WANT_LIB_EXT1__ is not defined as a macro at the point in the source file
22637     where the appropriate header is first included.363)
22638 4   Within a preprocessing translation unit, __STDC_WANT_LIB_EXT1__ shall be
22639     defined identically for all inclusions of any headers from subclause K.3. If
22640     __STDC_WANT_LIB_EXT1__ is defined differently for any such inclusion, the
22641     implementation shall issue a diagnostic as if a preprocessor error directive were used.
22642
22643
22644     361) Implementations that do not define __STDC_LIB_EXT1__ are not required to conform to these
22645          specifications.
22646     362) Future revisions of this International Standard may define meanings for other values of
22647          __STDC_WANT_LIB_EXT1__.
22648     363) Subclause 7.1.3 reserves certain names and patterns of names that an implementation may use in
22649          headers. All other names are not reserved, and a conforming implementation is not permitted to use
22650          them. While some of the names defined in K.3 and its subclauses are reserved, others are not. If an
22651          unreserved name is defined in a header when __STDC_WANT_LIB_EXT1__ is defined as 0, the
22652          implementation is not conforming.
22653
22654 [page 578]
22655
22656     K.3.1.2 Reserved identifiers
22657 1   Each macro name in any of the following subclauses is reserved for use as specified if it
22658     is defined by any of its associated headers when included; unless explicitly stated
22659     otherwise (see 7.1.4).
22660 2   All identifiers with external linkage in any of the following subclauses are reserved for
22661     use as identifiers with external linkage if any of them are used by the program. None of
22662     them are reserved if none of them are used.
22663 3   Each identifier with file scope listed in any of the following subclauses is reserved for use
22664     as a macro name and as an identifier with file scope in the same name space if it is
22665     defined by any of its associated headers when included.
22666     K.3.1.3 Use of errno
22667 1   An implementation may set errno for the functions defined in this annex, but is not
22668     required to.
22669     K.3.1.4 Runtime-constraint violations
22670 1   Most functions in this annex include as part of their specification a list of runtime-
22671     constraints. These runtime-constraints are requirements on the program using the
22672     library.364)
22673 2   Implementations shall verify that the runtime-constraints for a function are not violated
22674     by the program. If a runtime-constraint is violated, the implementation shall call the
22675     currently registered runtime-constraint handler (see set_constraint_handler_s
22676     in <stdlib.h>). Multiple runtime-constraint violations in the same call to a library
22677     function result in only one call to the runtime-constraint handler. It is unspecified which
22678     one of the multiple runtime-constraint violations cause the handler to be called.
22679 3   If the runtime-constraints section for a function states an action to be performed when a
22680     runtime-constraint violation occurs, the function shall perform the action before calling
22681     the runtime-constraint handler. If the runtime-constraints section lists actions that are
22682     prohibited when a runtime-constraint violation occurs, then such actions are prohibited to
22683     the function both before calling the handler and after the handler returns.
22684 4   The runtime-constraint handler might not return. If the handler does return, the library
22685     function whose runtime-constraint was violated shall return some indication of failure as
22686     given by the returns section in the function's specification.
22687
22688
22689
22690     364) Although runtime-constraints replace many cases of undefined behavior, undefined behavior still
22691          exists in this annex. Implementations are free to detect any case of undefined behavior and treat it as a
22692          runtime-constraint violation by calling the runtime-constraint handler. This license comes directly
22693          from the definition of undefined behavior.
22694
22695 [page 579]
22696
22697     K.3.2 Errors <errno.h>
22698 1   The header <errno.h> defines a type.
22699 2   The type is
22700             errno_t
22701     which is type int.365)
22702     K.3.3 Common definitions <stddef.h>
22703 1   The header <stddef.h> defines a type.
22704 2   The type is
22705             rsize_t
22706     which is the type size_t.366)
22707     K.3.4 Integer types <stdint.h>
22708 1   The header <stdint.h> defines a macro.
22709 2   The macro is
22710             RSIZE_MAX
22711     which expands to a value367) of type size_t. Functions that have parameters of type
22712     rsize_t consider it a runtime-constraint violation if the values of those parameters are
22713     greater than RSIZE_MAX.
22714     Recommended practice
22715 3   Extremely large object sizes are frequently a sign that an object's size was calculated
22716     incorrectly. For example, negative numbers appear as very large positive numbers when
22717     converted to an unsigned type like size_t. Also, some implementations do not support
22718     objects as large as the maximum value that can be represented by type size_t.
22719 4   For those reasons, it is sometimes beneficial to restrict the range of object sizes to detect
22720     programming errors. For implementations targeting machines with large address spaces,
22721     it is recommended that RSIZE_MAX be defined as the smaller of the size of the largest
22722     object supported or (SIZE_MAX >> 1), even if this limit is smaller than the size of
22723     some legitimate, but very large, objects. Implementations targeting machines with small
22724     address spaces may wish to define RSIZE_MAX as SIZE_MAX, which means that there
22725
22726     365) As a matter of programming style, errno_t may be used as the type of something that deals only
22727          with the values that might be found in errno. For example, a function which returns the value of
22728          errno might be declared as having the return type errno_t.
22729     366) See the description of the RSIZE_MAX macro in <stdint.h>.
22730     367) The macro RSIZE_MAX need not expand to a constant expression.
22731
22732 [page 580]
22733
22734     is no object size that is considered a runtime-constraint violation.
22735     K.3.5 Input/output <stdio.h>
22736 1   The header <stdio.h> defines several macros and two types.
22737 2   The macros are
22738             L_tmpnam_s
22739     which expands to an integer constant expression that is the size needed for an array of
22740     char large enough to hold a temporary file name string generated by the tmpnam_s
22741     function;
22742             TMP_MAX_S
22743     which expands to an integer constant expression that is the maximum number of unique
22744     file names that can be generated by the tmpnam_s function.
22745 3   The types are
22746             errno_t
22747     which is type int; and
22748             rsize_t
22749     which is the type size_t.
22750     K.3.5.1 Operations on files
22751     K.3.5.1.1 The tmpfile_s function
22752     Synopsis
22753 1           #define __STDC_WANT_LIB_EXT1__ 1
22754             #include <stdio.h>
22755             errno_t tmpfile_s(FILE * restrict * restrict streamptr);
22756     Runtime-constraints
22757 2   streamptr shall not be a null pointer.
22758 3   If there is a runtime-constraint violation, tmpfile_s does not attempt to create a file.
22759     Description
22760 4   The tmpfile_s function creates a temporary binary file that is different from any other
22761     existing file and that will automatically be removed when it is closed or at program
22762     termination. If the program terminates abnormally, whether an open temporary file is
22763     removed is implementation-defined. The file is opened for update with "wb+" mode
22764     with the meaning that mode has in the fopen_s function (including the mode's effect
22765     on exclusive access and file permissions).
22766
22767
22768 [page 581]
22769
22770 5   If the file was created successfully, then the pointer to FILE pointed to by streamptr
22771     will be set to the pointer to the object controlling the opened file. Otherwise, the pointer
22772     to FILE pointed to by streamptr will be set to a null pointer.
22773     Recommended practice
22774     It should be possible to open at least TMP_MAX_S temporary files during the lifetime of
22775     the program (this limit may be shared with tmpnam_s) and there should be no limit on
22776     the number simultaneously open other than this limit and any limit on the number of open
22777     files (FOPEN_MAX).
22778     Returns
22779 6   The tmpfile_s function returns zero if it created the file. If it did not create the file or
22780     there was a runtime-constraint violation, tmpfile_s returns a nonzero value.
22781     K.3.5.1.2 The tmpnam_s function
22782     Synopsis
22783 1           #define __STDC_WANT_LIB_EXT1__ 1
22784             #include <stdio.h>
22785             errno_t tmpnam_s(char *s, rsize_t maxsize);
22786     Runtime-constraints
22787 2   s shall not be a null pointer. maxsize shall be less than or equal to RSIZE_MAX.
22788     maxsize shall be greater than the length of the generated file name string.
22789     Description
22790 3   The tmpnam_s function generates a string that is a valid file name and that is not the
22791     same as the name of an existing file.368) The function is potentially capable of generating
22792     TMP_MAX_S different strings, but any or all of them may already be in use by existing
22793     files and thus not be suitable return values. The lengths of these strings shall be less than
22794     the value of the L_tmpnam_s macro.
22795 4   The tmpnam_s function generates a different string each time it is called.
22796 5   It is assumed that s points to an array of at least maxsize characters. This array will be
22797     set to generated string, as specified below.
22798
22799
22800
22801     368) Files created using strings generated by the tmpnam_s function are temporary only in the sense that
22802          their names should not collide with those generated by conventional naming rules for the
22803          implementation. It is still necessary to use the remove function to remove such files when their use
22804          is ended, and before program termination. Implementations should take care in choosing the patterns
22805          used for names returned by tmpnam_s. For example, making a thread id part of the names avoids the
22806          race condition and possible conflict when multiple programs run simultaneously by the same user
22807          generate the same temporary file names.
22808
22809 [page 582]
22810
22811 6    The implementation shall behave as if no library function except tmpnam calls the
22812      tmpnam_s function.369)
22813      Recommended practice
22814 7    After a program obtains a file name using the tmpnam_s function and before the
22815      program creates a file with that name, the possibility exists that someone else may create
22816      a file with that same name. To avoid this race condition, the tmpfile_s function
22817      should be used instead of tmpnam_s when possible. One situation that requires the use
22818      of the tmpnam_s function is when the program needs to create a temporary directory
22819      rather than a temporary file.
22820      Returns
22821 8    If no suitable string can be generated, or if there is a runtime-constraint violation, the
22822      tmpnam_s function writes a null character to s[0] (only if s is not null and maxsize
22823      is greater than zero) and returns a nonzero value.
22824 9    Otherwise, the tmpnam_s function writes the string in the array pointed to by s and
22825      returns zero.
22826      Environmental limits
22827 10   The value of the macro TMP_MAX_S shall be at least 25.
22828      K.3.5.2 File access functions
22829      K.3.5.2.1 The fopen_s function
22830      Synopsis
22831 1            #define __STDC_WANT_LIB_EXT1__ 1
22832              #include <stdio.h>
22833              errno_t fopen_s(FILE * restrict * restrict streamptr,
22834                   const char * restrict filename,
22835                   const char * restrict mode);
22836      Runtime-constraints
22837 2    None of streamptr, filename, or mode shall be a null pointer.
22838 3    If there is a runtime-constraint violation, fopen_s does not attempt to open a file.
22839      Furthermore, if streamptr is not a null pointer, fopen_s sets *streamptr to the
22840      null pointer.
22841
22842
22843
22844
22845      369) An implementation may have tmpnam call tmpnam_s (perhaps so there is only one naming
22846           convention for temporary files), but this is not required.
22847
22848 [page 583]
22849
22850     Description
22851 4   The fopen_s function opens the file whose name is the string pointed to by
22852     filename, and associates a stream with it.
22853 5   The mode string shall be as described for fopen, with the addition that modes starting
22854     with the character 'w' or 'a' may be preceded by the character 'u', see below:
22855     uw             truncate to zero length or create text file for writing, default
22856                    permissions
22857     uwx            create text file for writing, default permissions
22858     ua             append; open or create text file for writing at end-of-file, default
22859                    permissions
22860     uwb            truncate to zero length or create binary file for writing, default
22861                    permissions
22862     uwbx           create binary file for writing, default permissions
22863     uab            append; open or create binary file for writing at end-of-file, default
22864                    permissions
22865     uw+            truncate to zero length or create text file for update, default
22866                    permissions
22867     uw+x           create text file for update, default permissions
22868     ua+            append; open or create text file for update, writing at end-of-file,
22869                    default permissions
22870     uw+b or uwb+   truncate to zero length or create binary file for update, default
22871                    permissions
22872     uw+bx or uwb+x create binary file for update, default permissions
22873     ua+b or uab+   append; open or create binary file for update, writing at end-of-file,
22874                    default permissions
22875 6   Opening a file with exclusive mode ('x' as the last character in the mode argument)
22876     fails if the file already exists or cannot be created.
22877 7   To the extent that the underlying system supports the concepts, files opened for writing
22878     shall be opened with exclusive (also known as non-shared) access. If the file is being
22879     created, and the first character of the mode string is not 'u', to the extent that the
22880     underlying system supports it, the file shall have a file permission that prevents other
22881     users on the system from accessing the file. If the file is being created and first character
22882     of the mode string is 'u', then by the time the file has been closed, it shall have the
22883     system default file access permissions.370)
22884 8   If the file was opened successfully, then the pointer to FILE pointed to by streamptr
22885     will be set to the pointer to the object controlling the opened file. Otherwise, the pointer
22886
22887
22888     370) These are the same permissions that the file would have been created with by fopen.
22889
22890 [page 584]
22891
22892     to FILE pointed to by streamptr will be set to a null pointer.
22893     Returns
22894 9   The fopen_s function returns zero if it opened the file. If it did not open the file or if
22895     there was a runtime-constraint violation, fopen_s returns a nonzero value.
22896     K.3.5.2.2 The freopen_s function
22897     Synopsis
22898 1           #define __STDC_WANT_LIB_EXT1__ 1
22899             #include <stdio.h>
22900             errno_t freopen_s(FILE * restrict * restrict newstreamptr,
22901                  const char * restrict filename,
22902                  const char * restrict mode,
22903                  FILE * restrict stream);
22904     Runtime-constraints
22905 2   None of newstreamptr, mode, and stream shall be a null pointer.
22906 3   If there is a runtime-constraint violation, freopen_s neither attempts to close any file
22907     associated with stream nor attempts to open a file. Furthermore, if newstreamptr is
22908     not a null pointer, fopen_s sets *newstreamptr to the null pointer.
22909     Description
22910 4   The freopen_s function opens the file whose name is the string pointed to by
22911     filename and associates the stream pointed to by stream with it. The mode
22912     argument has the same meaning as in the fopen_s function (including the mode's effect
22913     on exclusive access and file permissions).
22914 5   If filename is a null pointer, the freopen_s function attempts to change the mode of
22915     the stream to that specified by mode, as if the name of the file currently associated with
22916     the stream had been used. It is implementation-defined which changes of mode are
22917     permitted (if any), and under what circumstances.
22918 6   The freopen_s function first attempts to close any file that is associated with stream.
22919     Failure to close the file is ignored. The error and end-of-file indicators for the stream are
22920     cleared.
22921 7   If the file was opened successfully, then the pointer to FILE pointed to by
22922     newstreamptr will be set to the value of stream. Otherwise, the pointer to FILE
22923     pointed to by newstreamptr will be set to a null pointer.
22924     Returns
22925 8   The freopen_s function returns zero if it opened the file. If it did not open the file or
22926     there was a runtime-constraint violation, freopen_s returns a nonzero value.
22927
22928 [page 585]
22929
22930     K.3.5.3 Formatted input/output functions
22931 1   Unless explicitly stated otherwise, if the execution of a function described in this
22932     subclause causes copying to take place between objects that overlap, the objects take on
22933     unspecified values.
22934     K.3.5.3.1 The fprintf_s function
22935     Synopsis
22936 1            #define __STDC_WANT_LIB_EXT1__ 1
22937              #include <stdio.h>
22938              int fprintf_s(FILE * restrict stream,
22939                   const char * restrict format, ...);
22940     Runtime-constraints
22941 2   Neither stream nor format shall be a null pointer. The %n specifier371) (modified or
22942     not by flags, field width, or precision) shall not appear in the string pointed to by
22943     format. Any argument to fprintf_s corresponding to a %s specifier shall not be a
22944     null pointer.
22945 3   If there is a runtime-constraint violation,372) the fprintf_s function does not attempt
22946     to produce further output, and it is unspecified to what extent fprintf_s produced
22947     output before discovering the runtime-constraint violation.
22948     Description
22949 4   The fprintf_s function is equivalent to the fprintf function except for the explicit
22950     runtime-constraints listed above.
22951     Returns
22952 5   The fprintf_s function returns the number of characters transmitted, or a negative
22953     value if an output error, encoding error, or runtime-constraint violation occurred.
22954
22955
22956
22957
22958     371) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
22959          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
22960          format string was %%n.
22961     372) Because an implementation may treat any undefined behavior as a runtime-constraint violation, an
22962          implementation may treat any unsupported specifiers in the string pointed to by format as a runtime-
22963          constraint violation.
22964
22965 [page 586]
22966
22967     K.3.5.3.2 The fscanf_s function
22968     Synopsis
22969 1           #define __STDC_WANT_LIB_EXT1__ 1
22970             #include <stdio.h>
22971             int fscanf_s(FILE * restrict stream,
22972                  const char * restrict format, ...);
22973     Runtime-constraints
22974 2   Neither stream nor format shall be a null pointer. Any argument indirected though in
22975     order to store converted input shall not be a null pointer.
22976 3   If there is a runtime-constraint violation,373) the fscanf_s function does not attempt to
22977     perform further input, and it is unspecified to what extent fscanf_s performed input
22978     before discovering the runtime-constraint violation.
22979     Description
22980 4   The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion
22981     specifiers apply to a pair of arguments (unless assignment suppression is indicated by a
22982     *). The first of these arguments is the same as for fscanf. That argument is
22983     immediately followed in the argument list by the second argument, which has type
22984     rsize_t and gives the number of elements in the array pointed to by the first argument
22985     of the pair. If the first argument points to a scalar object, it is considered to be an array of
22986     one element.374)
22987 5   A matching failure occurs if the number of elements in a receiving object is insufficient to
22988     hold the converted input (including any trailing null character).
22989     Returns
22990 6   The fscanf_s function returns the value of the macro EOF if an input failure occurs
22991     before any conversion or if there is a runtime-constraint violation. Otherwise, the
22992
22993     373) Because an implementation may treat any undefined behavior as a runtime-constraint violation, an
22994          implementation may treat any unsupported specifiers in the string pointed to by format as a runtime-
22995          constraint violation.
22996     374) If the format is known at translation time, an implementation may issue a diagnostic for any argument
22997          used to store the result from a c, s, or [ conversion specifier if that argument is not followed by an
22998          argument of a type compatible with rsize_t. A limited amount of checking may be done if even if
22999          the format is not known at translation time. For example, an implementation may issue a diagnostic
23000          for each argument after format that has of type pointer to one of char, signed char,
23001          unsigned char, or void that is not followed by an argument of a type compatible with
23002          rsize_t. The diagnostic could warn that unless the pointer is being used with a conversion specifier
23003          using the hh length modifier, a length argument must follow the pointer argument. Another useful
23004          diagnostic could flag any non-pointer argument following format that did not have a type
23005          compatible with rsize_t.
23006
23007 [page 587]
23008
23009     fscanf_s function returns the number of input items assigned, which can be fewer than
23010     provided for, or even zero, in the event of an early matching failure.
23011 7   EXAMPLE 1        The call:
23012              #define __STDC_WANT_LIB_EXT1__ 1
23013              #include <stdio.h>
23014              /* ... */
23015              int n, i; float x; char name[50];
23016              n = fscanf_s(stdin, "%d%f%s", &i, &x, name, (rsize_t) 50);
23017     with the input line:
23018              25 54.32E-1 thompson
23019     will assign to n the value 3, to i the value 25, to x the value 5.432, and to name the sequence
23020     thompson\0.
23021
23022 8   EXAMPLE 2        The call:
23023              #define __STDC_WANT_LIB_EXT1__ 1
23024              #include <stdio.h>
23025              /* ... */
23026              int n; char s[5];
23027              n = fscanf_s(stdin, "%s", s, sizeof s);
23028     with the input line:
23029              hello
23030     will assign to n the value 0 since a matching failure occurred because the sequence hello\0 requires an
23031     array of six characters to store it.
23032
23033     K.3.5.3.3 The printf_s function
23034     Synopsis
23035 1            #define __STDC_WANT_LIB_EXT1__ 1
23036              #include <stdio.h>
23037              int printf_s(const char * restrict format, ...);
23038     Runtime-constraints
23039 2   format shall not be a null pointer. The %n specifier375) (modified or not by flags, field
23040     width, or precision) shall not appear in the string pointed to by format. Any argument
23041     to printf_s corresponding to a %s specifier shall not be a null pointer.
23042 3   If there is a runtime-constraint violation, the printf_s function does not attempt to
23043     produce further output, and it is unspecified to what extent printf_s produced output
23044     before discovering the runtime-constraint violation.
23045
23046
23047     375) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23048          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23049          format string was %%n.
23050
23051 [page 588]
23052
23053     Description
23054 4   The printf_s function is equivalent to the printf function except for the explicit
23055     runtime-constraints listed above.
23056     Returns
23057 5   The printf_s function returns the number of characters transmitted, or a negative
23058     value if an output error, encoding error, or runtime-constraint violation occurred.
23059     K.3.5.3.4 The scanf_s function
23060     Synopsis
23061 1           #define __STDC_WANT_LIB_EXT1__ 1
23062             #include <stdio.h>
23063             int scanf_s(const char * restrict format, ...);
23064     Runtime-constraints
23065 2   format shall not be a null pointer. Any argument indirected though in order to store
23066     converted input shall not be a null pointer.
23067 3   If there is a runtime-constraint violation, the scanf_s function does not attempt to
23068     perform further input, and it is unspecified to what extent scanf_s performed input
23069     before discovering the runtime-constraint violation.
23070     Description
23071 4   The scanf_s function is equivalent to fscanf_s with the argument stdin
23072     interposed before the arguments to scanf_s.
23073     Returns
23074 5   The scanf_s function returns the value of the macro EOF if an input failure occurs
23075     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23076     scanf_s function returns the number of input items assigned, which can be fewer than
23077     provided for, or even zero, in the event of an early matching failure.
23078     K.3.5.3.5 The snprintf_s function
23079     Synopsis
23080 1           #define __STDC_WANT_LIB_EXT1__ 1
23081             #include <stdio.h>
23082             int snprintf_s(char * restrict s, rsize_t n,
23083                  const char * restrict format, ...);
23084     Runtime-constraints
23085 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
23086     than RSIZE_MAX. The %n specifier376) (modified or not by flags, field width, or
23087     precision) shall not appear in the string pointed to by format. Any argument to
23088 [page 589]
23089
23090     snprintf_s corresponding to a %s specifier shall not be a null pointer. No encoding
23091     error shall occur.
23092 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
23093     than zero and less than RSIZE_MAX, then the snprintf_s function sets s[0] to the
23094     null character.
23095     Description
23096 4   The snprintf_s function is equivalent to the snprintf function except for the
23097     explicit runtime-constraints listed above.
23098 5   The snprintf_s function, unlike sprintf_s, will truncate the result to fit within the
23099     array pointed to by s.
23100     Returns
23101 6   The snprintf_s function returns the number of characters that would have been
23102     written had n been sufficiently large, not counting the terminating null character, or a
23103     negative value if a runtime-constraint violation occurred. Thus, the null-terminated
23104     output has been completely written if and only if the returned value is nonnegative and
23105     less than n.
23106     K.3.5.3.6 The sprintf_s function
23107     Synopsis
23108 1            #define __STDC_WANT_LIB_EXT1__ 1
23109              #include <stdio.h>
23110              int sprintf_s(char * restrict s, rsize_t n,
23111                   const char * restrict format, ...);
23112     Runtime-constraints
23113 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
23114     than RSIZE_MAX. The number of characters (including the trailing null) required for the
23115     result to be written to the array pointed to by s shall not be greater than n. The %n
23116     specifier377) (modified or not by flags, field width, or precision) shall not appear in the
23117     string pointed to by format. Any argument to sprintf_s corresponding to a %s
23118     specifier shall not be a null pointer. No encoding error shall occur.
23119
23120
23121
23122     376) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23123          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23124          format string was %%n.
23125     377) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23126          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23127          format string was %%n.
23128
23129 [page 590]
23130
23131 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
23132     than zero and less than RSIZE_MAX, then the sprintf_s function sets s[0] to the
23133     null character.
23134     Description
23135 4   The sprintf_s function is equivalent to the sprintf function except for the
23136     parameter n and the explicit runtime-constraints listed above.
23137 5   The sprintf_s function, unlike snprintf_s, treats a result too big for the array
23138     pointed to by s as a runtime-constraint violation.
23139     Returns
23140 6   If no runtime-constraint violation occurred, the sprintf_s function returns the number
23141     of characters written in the array, not counting the terminating null character. If an
23142     encoding error occurred, sprintf_s returns a negative value. If any other runtime-
23143     constraint violation occurred, sprintf_s returns zero.
23144     K.3.5.3.7 The sscanf_s function
23145     Synopsis
23146 1           #define __STDC_WANT_LIB_EXT1__ 1
23147             #include <stdio.h>
23148             int sscanf_s(const char * restrict s,
23149                  const char * restrict format, ...);
23150     Runtime-constraints
23151 2   Neither s nor format shall be a null pointer. Any argument indirected though in order
23152     to store converted input shall not be a null pointer.
23153 3   If there is a runtime-constraint violation, the sscanf_s function does not attempt to
23154     perform further input, and it is unspecified to what extent sscanf_s performed input
23155     before discovering the runtime-constraint violation.
23156     Description
23157 4   The sscanf_s function is equivalent to fscanf_s, except that input is obtained from
23158     a string (specified by the argument s) rather than from a stream. Reaching the end of the
23159     string is equivalent to encountering end-of-file for the fscanf_s function. If copying
23160     takes place between objects that overlap, the objects take on unspecified values.
23161     Returns
23162 5   The sscanf_s function returns the value of the macro EOF if an input failure occurs
23163     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23164     sscanf_s function returns the number of input items assigned, which can be fewer than
23165     provided for, or even zero, in the event of an early matching failure.
23166
23167 [page 591]
23168
23169     K.3.5.3.8 The vfprintf_s function
23170     Synopsis
23171 1            #define __STDC_WANT_LIB_EXT1__ 1
23172              #include <stdarg.h>
23173              #include <stdio.h>
23174              int vfprintf_s(FILE * restrict stream,
23175                   const char * restrict format,
23176                   va_list arg);
23177     Runtime-constraints
23178 2   Neither stream nor format shall be a null pointer. The %n specifier378) (modified or
23179     not by flags, field width, or precision) shall not appear in the string pointed to by
23180     format. Any argument to vfprintf_s corresponding to a %s specifier shall not be a
23181     null pointer.
23182 3   If there is a runtime-constraint violation, the vfprintf_s function does not attempt to
23183     produce further output, and it is unspecified to what extent vfprintf_s produced
23184     output before discovering the runtime-constraint violation.
23185     Description
23186 4   The vfprintf_s function is equivalent to the vfprintf function except for the
23187     explicit runtime-constraints listed above.
23188     Returns
23189 5   The vfprintf_s function returns the number of characters transmitted, or a negative
23190     value if an output error, encoding error, or runtime-constraint violation occurred.
23191     K.3.5.3.9 The vfscanf_s function
23192     Synopsis
23193 1            #define __STDC_WANT_LIB_EXT1__ 1
23194              #include <stdarg.h>
23195              #include <stdio.h>
23196              int vfscanf_s(FILE * restrict stream,
23197                   const char * restrict format,
23198                   va_list arg);
23199
23200
23201
23202
23203     378) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23204          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23205          format string was %%n.
23206
23207 [page 592]
23208
23209     Runtime-constraints
23210 2   Neither stream nor format shall be a null pointer. Any argument indirected though in
23211     order to store converted input shall not be a null pointer.
23212 3   If there is a runtime-constraint violation, the vfscanf_s function does not attempt to
23213     perform further input, and it is unspecified to what extent vfscanf_s performed input
23214     before discovering the runtime-constraint violation.
23215     Description
23216 4   The vfscanf_s function is equivalent to fscanf_s, with the variable argument list
23217     replaced by arg, which shall have been initialized by the va_start macro (and
23218     possibly subsequent va_arg calls). The vfscanf_s function does not invoke the
23219     va_end macro.379)
23220     Returns
23221 5   The vfscanf_s function returns the value of the macro EOF if an input failure occurs
23222     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23223     vfscanf_s function returns the number of input items assigned, which can be fewer
23224     than provided for, or even zero, in the event of an early matching failure.
23225     K.3.5.3.10 The vprintf_s function
23226     Synopsis
23227 1            #define __STDC_WANT_LIB_EXT1__ 1
23228              #include <stdarg.h>
23229              #include <stdio.h>
23230              int vprintf_s(const char * restrict format,
23231                   va_list arg);
23232     Runtime-constraints
23233 2   format shall not be a null pointer. The %n specifier380) (modified or not by flags, field
23234     width, or precision) shall not appear in the string pointed to by format. Any argument
23235     to vprintf_s corresponding to a %s specifier shall not be a null pointer.
23236 3   If there is a runtime-constraint violation, the vprintf_s function does not attempt to
23237     produce further output, and it is unspecified to what extent vprintf_s produced output
23238     before discovering the runtime-constraint violation.
23239
23240     379) As the functions vfprintf_s, vfscanf_s, vprintf_s, vscanf_s, vsnprintf_s,
23241          vsprintf_s, and vsscanf_s invoke the va_arg macro, the value of arg after the return is
23242          indeterminate.
23243     380) 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     Description
23250 4   The vprintf_s function is equivalent to the vprintf function except for the explicit
23251     runtime-constraints listed above.
23252     Returns
23253 5   The vprintf_s function returns the number of characters transmitted, or a negative
23254     value if an output error, encoding error, or runtime-constraint violation occurred.
23255     K.3.5.3.11 The vscanf_s function
23256     Synopsis
23257 1          #define __STDC_WANT_LIB_EXT1__ 1
23258            #include <stdarg.h>
23259            #include <stdio.h>
23260            int vscanf_s(const char * restrict format,
23261                 va_list arg);
23262     Runtime-constraints
23263 2   format shall not be a null pointer. Any argument indirected though in order to store
23264     converted input shall not be a null pointer.
23265 3   If there is a runtime-constraint violation, the vscanf_s function does not attempt to
23266     perform further input, and it is unspecified to what extent vscanf_s performed input
23267     before discovering the runtime-constraint violation.
23268     Description
23269 4   The vscanf_s function is equivalent to scanf_s, with the variable argument list
23270     replaced by arg, which shall have been initialized by the va_start macro (and
23271     possibly subsequent va_arg calls). The vscanf_s function does not invoke the
23272     va_end macro.381)
23273     Returns
23274 5   The vscanf_s function returns the value of the macro EOF if an input failure occurs
23275     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23276     vscanf_s function returns the number of input items assigned, which can be fewer than
23277     provided for, or even zero, in the event of an early matching failure.
23278
23279
23280
23281
23282     381) As the functions vfprintf_s, vfscanf_s, vprintf_s, vscanf_s, vsnprintf_s,
23283          vsprintf_s, and vsscanf_s invoke the va_arg macro, the value of arg after the return is
23284          indeterminate.
23285
23286 [page 594]
23287
23288     K.3.5.3.12 The vsnprintf_s function
23289     Synopsis
23290 1            #define __STDC_WANT_LIB_EXT1__ 1
23291              #include <stdarg.h>
23292              #include <stdio.h>
23293              int vsnprintf_s(char * restrict s, rsize_t n,
23294                   const char * restrict format,
23295                   va_list arg);
23296     Runtime-constraints
23297 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
23298     than RSIZE_MAX. The %n specifier382) (modified or not by flags, field width, or
23299     precision) shall not appear in the string pointed to by format. Any argument to
23300     vsnprintf_s corresponding to a %s specifier shall not be a null pointer. No encoding
23301     error shall occur.
23302 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
23303     than zero and less than RSIZE_MAX, then the vsnprintf_s function sets s[0] to the
23304     null character.
23305     Description
23306 4   The vsnprintf_s function is equivalent to the vsnprintf function except for the
23307     explicit runtime-constraints listed above.
23308 5   The vsnprintf_s function, unlike vsprintf_s, will truncate the result to fit within
23309     the array pointed to by s.
23310     Returns
23311 6   The vsnprintf_s function returns the number of characters that would have been
23312     written had n been sufficiently large, not counting the terminating null character, or a
23313     negative value if a runtime-constraint violation occurred. Thus, the null-terminated
23314     output has been completely written if and only if the returned value is nonnegative and
23315     less than n.
23316
23317
23318
23319
23320     382) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23321          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23322          format string was %%n.
23323
23324 [page 595]
23325
23326     K.3.5.3.13 The vsprintf_s function
23327     Synopsis
23328 1            #define __STDC_WANT_LIB_EXT1__ 1
23329              #include <stdarg.h>
23330              #include <stdio.h>
23331              int vsprintf_s(char * restrict s, rsize_t n,
23332                   const char * restrict format,
23333                   va_list arg);
23334     Runtime-constraints
23335 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
23336     than RSIZE_MAX. The number of characters (including the trailing null) required for the
23337     result to be written to the array pointed to by s shall not be greater than n. The %n
23338     specifier383) (modified or not by flags, field width, or precision) shall not appear in the
23339     string pointed to by format. Any argument to vsprintf_s corresponding to a %s
23340     specifier shall not be a null pointer. No encoding error shall occur.
23341 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
23342     than zero and less than RSIZE_MAX, then the vsprintf_s function sets s[0] to the
23343     null character.
23344     Description
23345 4   The vsprintf_s function is equivalent to the vsprintf function except for the
23346     parameter n and the explicit runtime-constraints listed above.
23347 5   The vsprintf_s function, unlike vsnprintf_s, treats a result too big for the array
23348     pointed to by s as a runtime-constraint violation.
23349     Returns
23350 6   If no runtime-constraint violation occurred, the vsprintf_s function returns the
23351     number of characters written in the array, not counting the terminating null character. If
23352     an encoding error occurred, vsprintf_s returns a negative value. If any other
23353     runtime-constraint violation occurred, vsprintf_s returns zero.
23354
23355
23356
23357
23358     383) It is not a runtime-constraint violation for the characters %n to appear in sequence in the string pointed
23359          at by format when those characters are not a interpreted as a %n specifier. For example, if the entire
23360          format string was %%n.
23361
23362 [page 596]
23363
23364     K.3.5.3.14 The vsscanf_s function
23365     Synopsis
23366 1           #define __STDC_WANT_LIB_EXT1__ 1
23367             #include <stdarg.h>
23368             #include <stdio.h>
23369             int vsscanf_s(const char * restrict s,
23370                  const char * restrict format,
23371                  va_list arg);
23372     Runtime-constraints
23373 2   Neither s nor format shall be a null pointer. Any argument indirected though in order
23374     to store converted input shall not be a null pointer.
23375 3   If there is a runtime-constraint violation, the vsscanf_s function does not attempt to
23376     perform further input, and it is unspecified to what extent vsscanf_s performed input
23377     before discovering the runtime-constraint violation.
23378     Description
23379 4   The vsscanf_s function is equivalent to sscanf_s, with the variable argument list
23380     replaced by arg, which shall have been initialized by the va_start macro (and
23381     possibly subsequent va_arg calls). The vsscanf_s function does not invoke the
23382     va_end macro.384)
23383     Returns
23384 5   The vsscanf_s function returns the value of the macro EOF if an input failure occurs
23385     before any conversion or if there is a runtime-constraint violation. Otherwise, the
23386     vscanf_s function returns the number of input items assigned, which can be fewer than
23387     provided for, or even zero, in the event of an early matching failure.
23388     K.3.5.4 Character input/output functions
23389     K.3.5.4.1 The gets_s function
23390     Synopsis
23391 1           #define __STDC_WANT_LIB_EXT1__ 1
23392             #include <stdio.h>
23393             char *gets_s(char *s, rsize_t n);
23394
23395
23396
23397
23398     384) As the functions vfprintf_s, vfscanf_s, vprintf_s, vscanf_s, vsnprintf_s,
23399          vsprintf_s, and vsscanf_s invoke the va_arg macro, the value of arg after the return is
23400          indeterminate.
23401
23402 [page 597]
23403
23404     Runtime-constraints
23405 2   s shall not be a null pointer. n shall neither be equal to zero nor be greater than
23406     RSIZE_MAX. A new-line character, end-of-file, or read error shall occur within reading
23407     n-1 characters from stdin.385)
23408 3   If there is a runtime-constraint violation, s[0] is set to the null character, and characters
23409     are read and discarded from stdin until a new-line character is read, or end-of-file or a
23410     read error occurs.
23411     Description
23412 4   The gets_s function reads at most one less than the number of characters specified by n
23413     from the stream pointed to by stdin, into the array pointed to by s. No additional
23414     characters are read after a new-line character (which is discarded) or after end-of-file.
23415     The discarded new-line character does not count towards number of characters read. A
23416     null character is written immediately after the last character read into the array.
23417 5   If end-of-file is encountered and no characters have been read into the array, or if a read
23418     error occurs during the operation, then s[0] is set to the null character, and the other
23419     elements of s take unspecified values.
23420     Recommended practice
23421 6   The fgets function allows properly-written programs to safely process input lines too
23422     long to store in the result array. In general this requires that callers of fgets pay
23423     attention to the presence or absence of a new-line character in the result array. Consider
23424     using fgets (along with any needed processing based on new-line characters) instead of
23425     gets_s.
23426     Returns
23427 7   The gets_s function returns s if successful. If there was a runtime-constraint violation,
23428     or if end-of-file is encountered and no characters have been read into the array, or if a
23429     read error occurs during the operation, then a null pointer is returned.
23430
23431
23432
23433
23434     385) The gets_s function, unlike the historical gets function, makes it a runtime-constraint violation for
23435          a line of input to overflow the buffer to store it. Unlike the fgets function, gets_s maintains a
23436          one-to-one relationship between input lines and successful calls to gets_s. Programs that use gets
23437          expect such a relationship.
23438
23439 [page 598]
23440
23441     K.3.6 General utilities <stdlib.h>
23442 1   The header <stdlib.h> defines three types.
23443 2   The types are
23444             errno_t
23445     which is type int; and
23446             rsize_t
23447     which is the type size_t; and
23448             constraint_handler_t
23449     which has the following definition
23450             typedef void (*constraint_handler_t)(
23451                  const char * restrict msg,
23452                  void * restrict ptr,
23453                  errno_t error);
23454     K.3.6.1 Runtime-constraint handling
23455     K.3.6.1.1 The set_constraint_handler_s function
23456     Synopsis
23457 1           #define __STDC_WANT_LIB_EXT1__ 1
23458             #include <stdlib.h>
23459             constraint_handler_t set_constraint_handler_s(
23460                  constraint_handler_t handler);
23461     Description
23462 2   The set_constraint_handler_s function sets the runtime-constraint handler to
23463     be handler. The runtime-constraint handler is the function to be called when a library
23464     function detects a runtime-constraint violation. Only the most recent handler registered
23465     with set_constraint_handler_s is called when a runtime-constraint violation
23466     occurs.
23467 3   When the handler is called, it is passed the following arguments in the following order:
23468        1.   A pointer to a character string describing the runtime-constraint violation.
23469        2.   A null pointer or a pointer to an implementation defined object.
23470        3.   If the function calling the handler has a return type declared as errno_t, the
23471             return value of the function is passed. Otherwise, a positive value of type
23472             errno_t is passed.
23473
23474
23475
23476 [page 599]
23477
23478 4   The implementation has a default constraint handler that is used if no calls to the
23479     set_constraint_handler_s function have been made. The behavior of the
23480     default handler is implementation-defined, and it may cause the program to exit or abort.
23481 5   If the handler argument to set_constraint_handler_s is a null pointer, the
23482     implementation default handler becomes the current constraint handler.
23483     Returns
23484 6   The set_constraint_handler_s function returns a pointer to the previously
23485     registered handler.386)
23486     K.3.6.1.2 The abort_handler_s function
23487     Synopsis
23488 1           #define __STDC_WANT_LIB_EXT1__ 1
23489             #include <stdlib.h>
23490             void abort_handler_s(
23491                  const char * restrict msg,
23492                  void * restrict ptr,
23493                  errno_t error);
23494     Description
23495 2   A pointer to the abort_handler_s function shall be a suitable argument to the
23496     set_constraint_handler_s function.
23497 3   The abort_handler_s function writes a message on the standard error stream in an
23498     implementation-defined format. The message shall include the string pointed to by msg.
23499     The abort_handler_s function then calls the abort function.387)
23500     Returns
23501 4   The abort_handler_s function does not return to its caller.
23502
23503
23504
23505
23506     386) If the previous handler was registered by calling set_constraint_handler_s with a null
23507          pointer argument, a pointer to the implementation default handler is returned (not NULL).
23508     387) Many implementations invoke a debugger when the abort function is called.
23509
23510 [page 600]
23511
23512     K.3.6.1.3 The ignore_handler_s function
23513     Synopsis
23514 1            #define __STDC_WANT_LIB_EXT1__ 1
23515              #include <stdlib.h>
23516              void ignore_handler_s(
23517                   const char * restrict msg,
23518                   void * restrict ptr,
23519                   errno_t error);
23520     Description
23521 2   A pointer to the ignore_handler_s function shall be a suitable argument to the
23522     set_constraint_handler_s function.
23523 3   The ignore_handler_s function simply returns to its caller.388)
23524     Returns
23525 4   The ignore_handler_s function returns no value.
23526     K.3.6.2 Communication with the environment
23527     K.3.6.2.1 The getenv_s function
23528     Synopsis
23529 1            #define __STDC_WANT_LIB_EXT1__ 1
23530              #include <stdlib.h>
23531              errno_t getenv_s(size_t * restrict len,
23532                         char * restrict value, rsize_t maxsize,
23533                         const char * restrict name);
23534     Runtime-constraints
23535 2   name shall not be a null pointer. maxsize shall neither equal zero nor be greater than
23536     RSIZE_MAX. If maxsize is not equal to zero, then value shall not be a null pointer.
23537 3   If there is a runtime-constraint violation, the integer pointed to by len is set to 0 (if len
23538     is not null), and the environment list is not searched.
23539     Description
23540 4   The getenv_s function searches an environment list, provided by the host environment,
23541     for a string that matches the string pointed to by name.
23542
23543
23544     388) If the runtime-constraint handler is set to the ignore_handler_s function, any library function in
23545          which a runtime-constraint violation occurs will return to its caller. The caller can determine whether
23546          a runtime-constraint violation occurred based on the library function's specification (usually, the
23547          library function returns a nonzero errno_t).
23548
23549 [page 601]
23550
23551 5   If that name is found then getenv_s performs the following actions. If len is not a
23552     null pointer, the length of the string associated with the matched list member is stored in
23553     the integer pointed to by len. If the length of the associated string is less than maxsize,
23554     then the associated string is copied to the array pointed to by value.
23555 6   If that name is not found then getenv_s performs the following actions. If len is not
23556     a null pointer, zero is stored in the integer pointed to by len. If maxsize is greater than
23557     zero, then value[0] is set to the null character.
23558 7   The set of environment names and the method for altering the environment list are
23559     implementation-defined.
23560     Returns
23561 8   The getenv_s function returns zero if the specified name is found and the associated
23562     string was successfully stored in value. Otherwise, a nonzero value is returned.
23563     K.3.6.3 Searching and sorting utilities
23564 1   These utilities make use of a comparison function to search or sort arrays of unspecified
23565     type. Where an argument declared as size_t nmemb specifies the length of the array
23566     for a function, if nmemb has the value zero on a call to that function, then the comparison
23567     function is not called, a search finds no matching element, sorting performs no
23568     rearrangement, and the pointer to the array may be null.
23569 2   The implementation shall ensure that the second argument of the comparison function
23570     (when called from bsearch_s), or both arguments (when called from qsort_s), are
23571     pointers to elements of the array.389) The first argument when called from bsearch_s
23572     shall equal key.
23573 3   The comparison function shall not alter the contents of either the array or search key. The
23574     implementation may reorder elements of the array between calls to the comparison
23575     function, but shall not otherwise alter the contents of any individual element.
23576 4   When the same objects (consisting of size bytes, irrespective of their current positions
23577     in the array) are passed more than once to the comparison function, the results shall be
23578     consistent with one another. That is, for qsort_s they shall define a total ordering on
23579     the array, and for bsearch_s the same object shall always compare the same way with
23580     the key.
23581
23582
23583
23584
23585     389) That is, if the value passed is p, then the following expressions are always valid and nonzero:
23586                   ((char *)p - (char *)base) % size == 0
23587                   (char *)p >= (char *)base
23588                   (char *)p < (char *)base + nmemb * size
23589
23590
23591 [page 602]
23592
23593 5   A sequence point occurs immediately before and immediately after each call to the
23594     comparison function, and also between any call to the comparison function and any
23595     movement of the objects passed as arguments to that call.
23596     K.3.6.3.1 The bsearch_s function
23597     Synopsis
23598 1            #define __STDC_WANT_LIB_EXT1__ 1
23599              #include <stdlib.h>
23600              void *bsearch_s(const void *key, const void *base,
23601                   rsize_t nmemb, rsize_t size,
23602                   int (*compar)(const void *k, const void *y,
23603                                   void *context),
23604                   void *context);
23605     Runtime-constraints
23606 2   Neither nmemb nor size shall be greater than RSIZE_MAX. If nmemb is not equal to
23607     zero, then none of key, base, or compar shall be a null pointer.
23608 3   If there is a runtime-constraint violation, the bsearch_s function does not search the
23609     array.
23610     Description
23611 4   The bsearch_s function searches an array of nmemb objects, the initial element of
23612     which is pointed to by base, for an element that matches the object pointed to by key.
23613     The size of each element of the array is specified by size.
23614 5   The comparison function pointed to by compar is called with three arguments. The first
23615     two point to the key object and to an array element, in that order. The function shall
23616     return an integer less than, equal to, or greater than zero if the key object is considered,
23617     respectively, to be less than, to match, or to be greater than the array element. The array
23618     shall consist of: all the elements that compare less than, all the elements that compare
23619     equal to, and all the elements that compare greater than the key object, in that order.390)
23620     The third argument to the comparison function is the context argument passed to
23621     bsearch_s. The sole use of context by bsearch_s is to pass it to the comparison
23622     function.391)
23623
23624
23625
23626
23627     390) In practice, this means that the entire array has been sorted according to the comparison function.
23628     391) The context argument is for the use of the comparison function in performing its duties. For
23629          example, it might specify a collating sequence used by the comparison function.
23630
23631 [page 603]
23632
23633     Returns
23634 6   The bsearch_s function returns a pointer to a matching element of the array, or a null
23635     pointer if no match is found or there is a runtime-constraint violation. If two elements
23636     compare as equal, which element is matched is unspecified.
23637     K.3.6.3.2 The qsort_s function
23638     Synopsis
23639 1           #define __STDC_WANT_LIB_EXT1__ 1
23640             #include <stdlib.h>
23641             errno_t qsort_s(void *base, rsize_t nmemb, rsize_t size,
23642                  int (*compar)(const void *x, 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 neither base nor compar shall be a null pointer.
23648 3   If there is a runtime-constraint violation, the qsort_s function does not sort the array.
23649     Description
23650 4   The qsort_s function sorts an array of nmemb objects, the initial element of which is
23651     pointed to by base. The size of each object is specified by size.
23652 5   The contents of the array are sorted into ascending order according to a comparison
23653     function pointed to by compar, which is called with three arguments. The first two
23654     point to the objects being compared. The function shall return an integer less than, equal
23655     to, or greater than zero if the first argument is considered to be respectively less than,
23656     equal to, or greater than the second. The third argument to the comparison function is the
23657     context argument passed to qsort_s. The sole use of context by qsort_s is to
23658     pass it to the comparison function.392)
23659 6   If two elements compare as equal, their relative order in the resulting sorted array is
23660     unspecified.
23661     Returns
23662 7   The qsort_s function returns zero if there was no runtime-constraint violation.
23663     Otherwise, a nonzero value is returned.
23664
23665
23666
23667
23668     392) 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     K.3.6.4 Multibyte/wide character conversion functions
23674 1   The behavior of the multibyte character functions is affected by the LC_CTYPE category
23675     of the current locale. For a state-dependent encoding, each function is placed into its
23676     initial conversion state by a call for which its character pointer argument, s, is a null
23677     pointer. Subsequent calls with s as other than a null pointer cause the internal conversion
23678     state of the function to be altered as necessary. A call with s as a null pointer causes
23679     these functions to set the int pointed to by their status argument to a nonzero value if
23680     encodings have state dependency, and zero otherwise.393) Changing the LC_CTYPE
23681     category causes the conversion state of these functions to be indeterminate.
23682     K.3.6.4.1 The wctomb_s function
23683     Synopsis
23684 1           #define __STDC_WANT_LIB_EXT1__ 1
23685             #include <stdlib.h>
23686             errno_t wctomb_s(int * restrict status,
23687                  char * restrict s,
23688                  rsize_t smax,
23689                  wchar_t wc);
23690     Runtime-constraints
23691 2   Let n denote the number of bytes needed to represent the multibyte character
23692     corresponding to the wide character given by wc (including any shift sequences).
23693 3   If s is not a null pointer, then smax shall not be less than n, and smax shall not be
23694     greater than RSIZE_MAX. If s is a null pointer, then smax shall equal zero.
23695 4   If there is a runtime-constraint violation, wctomb_s does not modify the int pointed to
23696     by status, and if s is not a null pointer, no more than smax elements in the array
23697     pointed to by s will be accessed.
23698     Description
23699 5   The wctomb_s function determines n and stores the multibyte character representation
23700     of wc in the array whose first element is pointed to by s (if s is not a null pointer). The
23701     number of characters stored never exceeds MB_CUR_MAX or smax. If wc is a null wide
23702     character, a null byte is stored, preceded by any shift sequence needed to restore the
23703     initial shift state, and the function is left in the initial conversion state.
23704 6   The implementation shall behave as if no library function calls the wctomb_s function.
23705
23706
23707
23708     393) If the locale employs special bytes to change the shift state, these bytes do not produce separate wide
23709          character codes, but are grouped with an adjacent multibyte character.
23710
23711 [page 605]
23712
23713 7    If s is a null pointer, the wctomb_s function stores into the int pointed to by status a
23714      nonzero or zero value, if multibyte character encodings, respectively, do or do not have
23715      state-dependent encodings.
23716 8    If s is not a null pointer, the wctomb_s function stores into the int pointed to by
23717      status either n or -1 if wc, respectively, does or does not correspond to a valid
23718      multibyte character.
23719 9    In no case will the int pointed to by status be set to a value greater than the
23720      MB_CUR_MAX macro.
23721      Returns
23722 10   The wctomb_s function returns zero if successful, and a nonzero value if there was a
23723      runtime-constraint violation or wc did not correspond to a valid multibyte character.
23724      K.3.6.5 Multibyte/wide string conversion functions
23725 1    The behavior of the multibyte string functions is affected by the LC_CTYPE category of
23726      the current locale.
23727      K.3.6.5.1 The mbstowcs_s function
23728      Synopsis
23729 1           #include <stdlib.h>
23730             errno_t mbstowcs_s(size_t * restrict retval,
23731                  wchar_t * restrict dst, rsize_t dstmax,
23732                  const char * restrict src, rsize_t len);
23733      Runtime-constraints
23734 2    Neither retval nor src shall be a null pointer. If dst is not a null pointer, then
23735      neither len nor dstmax shall be greater than RSIZE_MAX. If dst is a null pointer,
23736      then dstmax shall equal zero. If dst is not a null pointer, then dstmax shall not equal
23737      zero. If dst is not a null pointer and len is not less than dstmax, then a null character
23738      shall occur within the first dstmax multibyte characters of the array pointed to by src.
23739 3    If there is a runtime-constraint violation, then mbstowcs_s does the following. If
23740      retval is not a null pointer, then mbstowcs_s sets *retval to (size_t)(-1). If
23741      dst is not a null pointer and dstmax is greater than zero and less than RSIZE_MAX,
23742      then mbstowcs_s sets dst[0] to the null wide character.
23743      Description
23744 4    The mbstowcs_s function converts a sequence of multibyte characters that begins in
23745      the initial shift state from the array pointed to by src into a sequence of corresponding
23746      wide characters. If dst is not a null pointer, the converted characters are stored into the
23747      array pointed to by dst. Conversion continues up to and including a terminating null
23748      character, which is also stored. Conversion stops earlier in two cases: when a sequence of
23749 [page 606]
23750
23751     bytes is encountered that does not form a valid multibyte character, or (if dst is not a
23752     null pointer) when len wide characters have been stored into the array pointed to by
23753     dst.394) If dst is not a null pointer and no null wide character was stored into the array
23754     pointed to by dst, then dst[len] is set to the null wide character. Each conversion
23755     takes place as if by a call to the mbrtowc function.
23756 5   Regardless of whether dst is or is not a null pointer, if the input conversion encounters a
23757     sequence of bytes that do not form a valid multibyte character, an encoding error occurs:
23758     the mbstowcs_s function stores the value (size_t)(-1) into *retval.
23759     Otherwise, the mbstowcs_s function stores into *retval the number of multibyte
23760     characters successfully converted, not including the terminating null character (if any).
23761 6   All elements following the terminating null wide character (if any) written by
23762     mbstowcs_s in the array of dstmax wide characters pointed to by dst take
23763     unspecified values when mbstowcs_s returns.395)
23764 7   If copying takes place between objects that overlap, the objects take on unspecified
23765     values.
23766     Returns
23767 8   The mbstowcs_s function returns zero if no runtime-constraint violation and no
23768     encoding error occurred. Otherwise, a nonzero value is returned.
23769     K.3.6.5.2 The wcstombs_s function
23770     Synopsis
23771 1            #include <stdlib.h>
23772              errno_t wcstombs_s(size_t * restrict retval,
23773                   char * restrict dst, rsize_t dstmax,
23774                   const wchar_t * restrict src, rsize_t len);
23775     Runtime-constraints
23776 2   Neither retval nor src shall be a null pointer. If dst is not a null pointer, then
23777     neither len nor dstmax shall be greater than RSIZE_MAX. If dst is a null pointer,
23778     then dstmax shall equal zero. If dst is not a null pointer, then dstmax shall not equal
23779     zero. If dst is not a null pointer and len is not less than dstmax, then the conversion
23780     shall have been stopped (see below) because a terminating null wide character was
23781     reached or because an encoding error occurred.
23782
23783
23784
23785
23786     394) Thus, the value of len is ignored if dst is a null pointer.
23787     395) This allows an implementation to attempt converting the multibyte string before discovering a
23788          terminating null character did not occur where required.
23789
23790 [page 607]
23791
23792 3   If there is a runtime-constraint violation, then wcstombs_s does the following. If
23793     retval is not a null pointer, then wcstombs_s sets *retval to (size_t)(-1). If
23794     dst is not a null pointer and dstmax is greater than zero and less than RSIZE_MAX,
23795     then wcstombs_s sets dst[0] to the null character.
23796     Description
23797 4   The wcstombs_s function converts a sequence of wide characters from the array
23798     pointed to by src into a sequence of corresponding multibyte characters that begins in
23799     the initial shift state. If dst is not a null pointer, the converted characters are then stored
23800     into the array pointed to by dst. Conversion continues up to and including a terminating
23801     null wide character, which is also stored. Conversion stops earlier in two cases:
23802     -- when a wide character is reached that does not correspond to a valid multibyte
23803       character;
23804     -- (if dst is not a null pointer) when the next multibyte character would exceed the
23805         limit of n total bytes to be stored into the array pointed to by dst. If the wide
23806         character being converted is the null wide character, then n is the lesser of len or
23807         dstmax. Otherwise, n is the lesser of len or dstmax-1.
23808     If the conversion stops without converting a null wide character and dst is not a null
23809     pointer, then a null character is stored into the array pointed to by dst immediately
23810     following any multibyte characters already stored. Each conversion takes place as if by a
23811     call to the wcrtomb function.396)
23812 5   Regardless of whether dst is or is not a null pointer, if the input conversion encounters a
23813     wide character that does not correspond to a valid multibyte character, an encoding error
23814     occurs: the wcstombs_s function stores the value (size_t)(-1) into *retval.
23815     Otherwise, the wcstombs_s function stores into *retval the number of bytes in the
23816     resulting multibyte character sequence, not including the terminating null character (if
23817     any).
23818 6   All elements following the terminating null character (if any) written by wcstombs_s
23819     in the array of dstmax elements pointed to by dst take unspecified values when
23820     wcstombs_s returns.397)
23821 7   If copying takes place between objects that overlap, the objects take on unspecified
23822     values.
23823
23824
23825     396) If conversion stops because a terminating null wide character has been reached, the bytes stored
23826          include those necessary to reach the initial shift state immediately before the null byte. However, if
23827          the conversion stops before a terminating null wide character has been reached, the result will be null
23828          terminated, but might not end in the initial shift state.
23829     397) When len is not less than dstmax, the implementation might fill the array before discovering a
23830          runtime-constraint violation.
23831
23832 [page 608]
23833
23834     Returns
23835 8   The wcstombs_s function returns zero if no runtime-constraint violation and no
23836     encoding error occurred. Otherwise, a nonzero value is returned.
23837     K.3.7 String handling <string.h>
23838 1   The header <string.h> defines two types.
23839 2   The types are
23840             errno_t
23841     which is type int; and
23842             rsize_t
23843     which is the type size_t.
23844     K.3.7.1 Copying functions
23845     K.3.7.1.1 The memcpy_s function
23846     Synopsis
23847 1           #define __STDC_WANT_LIB_EXT1__ 1
23848             #include <string.h>
23849             errno_t memcpy_s(void * restrict s1, rsize_t s1max,
23850                  const void * restrict s2, rsize_t n);
23851     Runtime-constraints
23852 2   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
23853     RSIZE_MAX. n shall not be greater than s1max. Copying shall not take place between
23854     objects that overlap.
23855 3   If there is a runtime-constraint violation, the memcpy_s function stores zeros in the first
23856     s1max characters of the object pointed to by s1 if s1 is not a null pointer and s1max is
23857     not greater than RSIZE_MAX.
23858     Description
23859 4   The memcpy_s function copies n characters from the object pointed to by s2 into the
23860     object pointed to by s1.
23861     Returns
23862 5   The memcpy_s function returns zero if there was no runtime-constraint violation.
23863     Otherwise, a nonzero value is returned.
23864
23865
23866
23867
23868 [page 609]
23869
23870     K.3.7.1.2 The memmove_s function
23871     Synopsis
23872 1          #define __STDC_WANT_LIB_EXT1__ 1
23873            #include <string.h>
23874            errno_t memmove_s(void *s1, rsize_t s1max,
23875                 const void *s2, rsize_t n);
23876     Runtime-constraints
23877 2   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
23878     RSIZE_MAX. n shall not be greater than s1max.
23879 3   If there is a runtime-constraint violation, the memmove_s function stores zeros in the
23880     first s1max characters of the object pointed to by s1 if s1 is not a null pointer and
23881     s1max is not greater than RSIZE_MAX.
23882     Description
23883 4   The memmove_s function copies n characters from the object pointed to by s2 into the
23884     object pointed to by s1. This copying takes place as if the n characters from the object
23885     pointed to by s2 are first copied into a temporary array of n characters that does not
23886     overlap the objects pointed to by s1 or s2, and then the n characters from the temporary
23887     array are copied into the object pointed to by s1.
23888     Returns
23889 5   The memmove_s function returns zero if there was no runtime-constraint violation.
23890     Otherwise, a nonzero value is returned.
23891     K.3.7.1.3 The strcpy_s function
23892     Synopsis
23893 1          #define __STDC_WANT_LIB_EXT1__ 1
23894            #include <string.h>
23895            errno_t strcpy_s(char * restrict s1,
23896                 rsize_t s1max,
23897                 const char * restrict s2);
23898     Runtime-constraints
23899 2   Neither s1 nor s2 shall be a null pointer. s1max shall not be greater than RSIZE_MAX.
23900     s1max shall not equal zero. s1max shall be greater than strnlen_s(s2, s1max).
23901     Copying shall not take place between objects that overlap.
23902 3   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
23903     greater than zero and not greater than RSIZE_MAX, then strcpy_s sets s1[0] to the
23904     null character.
23905
23906 [page 610]
23907
23908     Description
23909 4   The strcpy_s function copies the string pointed to by s2 (including the terminating
23910     null character) into the array pointed to by s1.
23911 5   All elements following the terminating null character (if any) written by strcpy_s in
23912     the array of s1max characters pointed to by s1 take unspecified values when
23913     strcpy_s returns.398)
23914     Returns
23915 6   The strcpy_s function returns zero399) if there was no runtime-constraint violation.
23916     Otherwise, a nonzero value is returned.
23917     K.3.7.1.4 The strncpy_s function
23918     Synopsis
23919 1           #define __STDC_WANT_LIB_EXT1__ 1
23920             #include <string.h>
23921             errno_t strncpy_s(char * restrict s1,
23922                  rsize_t s1max,
23923                  const char * restrict s2,
23924                  rsize_t n);
23925     Runtime-constraints
23926 2   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
23927     RSIZE_MAX. s1max shall not equal zero. If n is not less than s1max, then s1max
23928     shall be greater than strnlen_s(s2, s1max). Copying shall not take place between
23929     objects that overlap.
23930 3   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
23931     greater than zero and not greater than RSIZE_MAX, then strncpy_s sets s1[0] to the
23932     null character.
23933     Description
23934 4   The strncpy_s function copies not more than n successive characters (characters that
23935     follow a null character are not copied) from the array pointed to by s2 to the array
23936     pointed to by s1. If no null character was copied from s2, then s1[n] is set to a null
23937     character.
23938
23939
23940     398) This allows an implementation to copy characters from s2 to s1 while simultaneously checking if
23941          any of those characters are null. Such an approach might write a character to every element of s1
23942          before discovering that the first element should be set to the null character.
23943     399) A zero return value implies that all of the requested characters from the string pointed to by s2 fit
23944          within the array pointed to by s1 and that the result in s1 is null terminated.
23945
23946 [page 611]
23947
23948 5   All elements following the terminating null character (if any) written by strncpy_s in
23949     the array of s1max characters pointed to by s1 take unspecified values when
23950     strncpy_s returns.400)
23951     Returns
23952 6   The strncpy_s function returns zero401) if there was no runtime-constraint violation.
23953     Otherwise, a nonzero value is returned.
23954 7   EXAMPLE 1 The strncpy_s function can be used to copy a string without the danger that the result
23955     will not be null terminated or that characters will be written past the end of the destination array.
23956             #define __STDC_WANT_LIB_EXT1__ 1
23957             #include <string.h>
23958             /* ... */
23959             char src1[100] = "hello";
23960             char src2[7] = {'g', 'o', 'o', 'd', 'b', 'y', 'e'};
23961             char dst1[6], dst2[5], dst3[5];
23962             int r1, r2, r3;
23963             r1 = strncpy_s(dst1, 6, src1, 100);
23964             r2 = strncpy_s(dst2, 5, src2, 7);
23965             r3 = strncpy_s(dst3, 5, src2, 4);
23966     The first call will assign to r1 the value zero and to dst1 the sequence hello\0.
23967     The second call will assign to r2 a nonzero value and to dst2 the sequence \0.
23968     The third call will assign to r3 the value zero and to dst3 the sequence good\0.
23969
23970     K.3.7.2 Concatenation functions
23971     K.3.7.2.1 The strcat_s function
23972     Synopsis
23973 1           #define __STDC_WANT_LIB_EXT1__ 1
23974             #include <string.h>
23975             errno_t strcat_s(char * restrict s1,
23976                  rsize_t s1max,
23977                  const char * restrict s2);
23978     Runtime-constraints
23979 2   Let m denote the value s1max - strnlen_s(s1, s1max) upon entry to
23980     strcat_s.
23981
23982
23983
23984
23985     400) This allows an implementation to copy characters from s2 to s1 while simultaneously checking if
23986          any of those characters are null. Such an approach might write a character to every element of s1
23987          before discovering that the first element should be set to the null character.
23988     401) A zero return value implies that all of the requested characters from the string pointed to by s2 fit
23989          within the array pointed to by s1 and that the result in s1 is null terminated.
23990
23991 [page 612]
23992
23993 3   Neither s1 nor s2 shall be a null pointer. s1max shall not be greater than RSIZE_MAX.
23994     s1max shall not equal zero. m shall not equal zero.402) m shall be greater than
23995     strnlen_s(s2, m). Copying shall not take place between objects that overlap.
23996 4   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
23997     greater than zero and not greater than RSIZE_MAX, then strcat_s sets s1[0] to the
23998     null character.
23999     Description
24000 5   The strcat_s function appends a copy of the string pointed to by s2 (including the
24001     terminating null character) to the end of the string pointed to by s1. The initial character
24002     from s2 overwrites the null character at the end of s1.
24003 6   All elements following the terminating null character (if any) written by strcat_s in
24004     the array of s1max characters pointed to by s1 take unspecified values when
24005     strcat_s returns.403)
24006     Returns
24007 7   The strcat_s function returns zero404) if there was no runtime-constraint violation.
24008     Otherwise, a nonzero value is returned.
24009     K.3.7.2.2 The strncat_s function
24010     Synopsis
24011 1           #define __STDC_WANT_LIB_EXT1__ 1
24012             #include <string.h>
24013             errno_t strncat_s(char * restrict s1,
24014                  rsize_t s1max,
24015                  const char * restrict s2,
24016                  rsize_t n);
24017     Runtime-constraints
24018 2   Let m denote the value s1max - strnlen_s(s1, s1max) upon entry to
24019     strncat_s.
24020 3   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
24021     RSIZE_MAX. s1max shall not equal zero. m shall not equal zero.405) If n is not less
24022
24023
24024     402) Zero means that s1 was not null terminated upon entry to strcat_s.
24025     403) This allows an implementation to append characters from s2 to s1 while simultaneously checking if
24026          any of those characters are null. Such an approach might write a character to every element of s1
24027          before discovering that the first element should be set to the null character.
24028     404) A zero return value implies that all of the requested characters from the string pointed to by s2 were
24029          appended to the string pointed to by s1 and that the result in s1 is null terminated.
24030
24031 [page 613]
24032
24033     than m, then m shall be greater than strnlen_s(s2, m). Copying shall not take
24034     place between objects that overlap.
24035 4   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
24036     greater than zero and not greater than RSIZE_MAX, then strncat_s sets s1[0] to the
24037     null character.
24038     Description
24039 5   The strncat_s function appends not more than n successive characters (characters
24040     that follow a null character are not copied) from the array pointed to by s2 to the end of
24041     the string pointed to by s1. The initial character from s2 overwrites the null character at
24042     the end of s1. If no null character was copied from s2, then s1[s1max-m+n] is set to
24043     a null character.
24044 6   All elements following the terminating null character (if any) written by strncat_s in
24045     the array of s1max characters pointed to by s1 take unspecified values when
24046     strncat_s returns.406)
24047     Returns
24048 7   The strncat_s function returns zero407) if there was no runtime-constraint violation.
24049     Otherwise, a nonzero value is returned.
24050 8   EXAMPLE 1 The strncat_s function can be used to copy a string without the danger that the result
24051     will not be null terminated or that characters will be written past the end of the destination array.
24052             #define __STDC_WANT_LIB_EXT1__ 1
24053             #include <string.h>
24054             /* ... */
24055             char s1[100] = "good";
24056             char s2[6] = "hello";
24057             char s3[6] = "hello";
24058             char s4[7] = "abc";
24059             char s5[1000] = "bye";
24060             int r1, r2, r3, r4;
24061             r1 = strncat_s(s1, 100, s5, 1000);
24062             r2 = strncat_s(s2, 6, "", 1);
24063             r3 = strncat_s(s3, 6, "X", 2);
24064             r4 = strncat_s(s4, 7, "defghijklmn", 3);
24065     After the first call r1 will have the value zero and s1 will contain the sequence goodbye\0.
24066
24067
24068
24069     405) Zero means that s1 was not null terminated upon entry to strncat_s.
24070     406) This allows an implementation to append characters from s2 to s1 while simultaneously checking if
24071          any of those characters are null. Such an approach might write a character to every element of s1
24072          before discovering that the first element should be set to the null character.
24073     407) A zero return value implies that all of the requested characters from the string pointed to by s2 were
24074          appended to the string pointed to by s1 and that the result in s1 is null terminated.
24075
24076 [page 614]
24077
24078     After the second call r2 will have the value zero and s2 will contain the sequence hello\0.
24079     After the third call r3 will have a nonzero value and s3 will contain the sequence \0.
24080     After the fourth call r4 will have the value zero and s4 will contain the sequence abcdef\0.
24081
24082     K.3.7.3 Search functions
24083     K.3.7.3.1 The strtok_s function
24084     Synopsis
24085 1           #define __STDC_WANT_LIB_EXT1__ 1
24086             #include <string.h>
24087             char *strtok_s(char * restrict s1,
24088                  rsize_t * restrict s1max,
24089                  const char * restrict s2,
24090                  char ** restrict ptr);
24091     Runtime-constraints
24092 2   None of s1max, s2, or ptr shall be a null pointer. If s1 is a null pointer, then *ptr
24093     shall not be a null pointer. The value of *s1max shall not be greater than RSIZE_MAX.
24094     The end of the token found shall occur within the first *s1max characters of s1 for the
24095     first call, and shall occur within the first *s1max characters of where searching resumes
24096     on subsequent calls.
24097 3   If there is a runtime-constraint violation, the strtok_s function does not indirect
24098     through the s1 or s2 pointers, and does not store a value in the object pointed to by ptr.
24099     Description
24100 4   A sequence of calls to the strtok_s function breaks the string pointed to by s1 into a
24101     sequence of tokens, each of which is delimited by a character from the string pointed to
24102     by s2. The fourth argument points to a caller-provided char pointer into which the
24103     strtok_s function stores information necessary for it to continue scanning the same
24104     string.
24105 5   The first call in a sequence has a non-null first argument and s1max points to an object
24106     whose value is the number of elements in the character array pointed to by the first
24107     argument. The first call stores an initial value in the object pointed to by ptr and
24108     updates the value pointed to by s1max to reflect the number of elements that remain in
24109     relation to ptr. Subsequent calls in the sequence have a null first argument and the
24110     objects pointed to by s1max and ptr are required to have the values stored by the
24111     previous call in the sequence, which are then updated. The separator string pointed to by
24112     s2 may be different from call to call.
24113 6   The first call in the sequence searches the string pointed to by s1 for the first character
24114     that is not contained in the current separator string pointed to by s2. If no such character
24115     is found, then there are no tokens in the string pointed to by s1 and the strtok_s
24116     function returns a null pointer. If such a character is found, it is the start of the first token.
24117 [page 615]
24118
24119 7    The strtok_s function then searches from there for the first character in s1 that is
24120      contained in the current separator string. If no such character is found, the current token
24121      extends to the end of the string pointed to by s1, and subsequent searches in the same
24122      string for a token return a null pointer. If such a character is found, it is overwritten by a
24123      null character, which terminates the current token.
24124 8    In all cases, the strtok_s function stores sufficient information in the pointer pointed
24125      to by ptr so that subsequent calls, with a null pointer for s1 and the unmodified pointer
24126      value for ptr, shall start searching just past the element overwritten by a null character
24127      (if any).
24128      Returns
24129 9    The strtok_s function returns a pointer to the first character of a token, or a null
24130      pointer if there is no token or there is a runtime-constraint violation.
24131 10   EXAMPLE
24132             #define __STDC_WANT_LIB_EXT1__ 1
24133             #include <string.h>
24134             static char str1[] = "?a???b,,,#c";
24135             static char str2[] = "\t \t";
24136             char *t, *ptr1, *ptr2;
24137             rsize_t max1 = sizeof(str1);
24138             rsize_t max2 = sizeof(str2);
24139             t   =   strtok_s(str1,   &max1,   "?", &ptr1);         //   t   points to the token "a"
24140             t   =   strtok_s(NULL,   &max1,   ",", &ptr1);         //   t   points to the token "??b"
24141             t   =   strtok_s(str2,   &max2,   " \t", &ptr2);       //   t   is a null pointer
24142             t   =   strtok_s(NULL,   &max1,   "#,", &ptr1);        //   t   points to the token "c"
24143             t   =   strtok_s(NULL,   &max1,   "?", &ptr1);         //   t   is a null pointer
24144
24145      K.3.7.4 Miscellaneous functions
24146      K.3.7.4.1 The memset_s function
24147      Synopsis
24148 1           #define __STDC_WANT_LIB_EXT1__ 1
24149             #include <string.h>
24150             errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n)
24151      Runtime-constraints
24152 2    s shall not be a null pointer. Neither smax nor n shall be greater than RSIZE_MAX. n
24153      shall not be greater than smax.
24154 3    If there is a runtime-constraint violation, then if s is not a null pointer and smax is not
24155      greater than RSIZE_MAX, the memset_s function stores the value of c (converted to an
24156      unsigned char) into each of the first smax characters of the object pointed to by s.
24157
24158
24159
24160 [page 616]
24161
24162     Description
24163 4   The memset_s function copies the value of c (converted to an unsigned char) into
24164     each of the first n characters of the object pointed to by s. Unlike memset, any call to
24165     the memset_s function shall be evaluated strictly according to the rules of the abstract
24166     machine as described in (5.1.2.3). That is, any call to the memset_s function shall
24167     assume that the memory indicated by s and n may be accessible in the future and thus
24168     must contain the values indicated by c.
24169     Returns
24170 5   The memset_s function returns zero if there was no runtime-constraint violation.
24171     Otherwise, a nonzero value is returned.
24172     K.3.7.4.2 The strerror_s function
24173     Synopsis
24174 1           #define __STDC_WANT_LIB_EXT1__ 1
24175             #include <string.h>
24176             errno_t strerror_s(char *s, rsize_t maxsize,
24177                  errno_t errnum);
24178     Runtime-constraints
24179 2   s shall not be a null pointer. maxsize shall not be greater than RSIZE_MAX.
24180     maxsize shall not equal zero.
24181 3   If there is a runtime-constraint violation, then the array (if any) pointed to by s is not
24182     modified.
24183     Description
24184 4   The strerror_s function maps the number in errnum to a locale-specific message
24185     string. Typically, the values for errnum come from errno, but strerror_s shall
24186     map any value of type int to a message.
24187 5   If the length of the desired string is less than maxsize, then the string is copied to the
24188     array pointed to by s.
24189 6   Otherwise, if maxsize is greater than zero, then maxsize-1 characters are copied
24190     from the string to the array pointed to by s and then s[maxsize-1] is set to the null
24191     character. Then, if maxsize is greater than 3, then s[maxsize-2],
24192     s[maxsize-3], and s[maxsize-4] are set to the character period (.).
24193     Returns
24194 7   The strerror_s function returns zero if the length of the desired string was less than
24195     maxsize and there was no runtime-constraint violation. Otherwise, the strerror_s
24196     function returns a nonzero value.
24197
24198 [page 617]
24199
24200     K.3.7.4.3 The strerrorlen_s function
24201     Synopsis
24202 1           #define __STDC_WANT_LIB_EXT1__ 1
24203             #include <string.h>
24204             size_t strerrorlen_s(errno_t errnum);
24205     Description
24206 2   The strerrorlen_s function calculates the length of the (untruncated) locale-specific
24207     message string that the strerror_s function maps to errnum.
24208     Returns
24209 3   The strerrorlen_s function returns the number of characters (not including the null
24210     character) in the full message string.
24211     K.3.7.4.4 The strnlen_s function
24212     Synopsis
24213 1           #define __STDC_WANT_LIB_EXT1__ 1
24214             #include <string.h>
24215             size_t strnlen_s(const char *s, size_t maxsize);
24216     Description
24217 2   The strnlen_s function computes the length of the string pointed to by s.
24218     Returns
24219 3   If s is a null pointer,408) then the strnlen_s function returns zero.
24220 4   Otherwise, the strnlen_s function returns the number of characters that precede the
24221     terminating null character. If there is no null character in the first maxsize characters of
24222     s then strnlen_s returns maxsize. At most the first maxsize characters of s shall
24223     be accessed by strnlen_s.
24224
24225
24226
24227
24228     408) Note that the strnlen_s function has no runtime-constraints. This lack of runtime-constraints
24229          along with the values returned for a null pointer or an unterminated string argument make
24230          strnlen_s useful in algorithms that gracefully handle such exceptional data.
24231
24232 [page 618]
24233
24234     K.3.8 Date and time <time.h>
24235 1   The header <time.h> defines two types.
24236 2   The types are
24237             errno_t
24238     which is type int; and
24239             rsize_t
24240     which is the type size_t.
24241     K.3.8.1 Components of time
24242 1   A broken-down time is normalized if the values of the members of the tm structure are in
24243     their normal rages.409)
24244     K.3.8.2 Time conversion functions
24245 1   Like the strftime function, the asctime_s and ctime_s functions do not return a
24246     pointer to a static object, and other library functions are permitted to call them.
24247     K.3.8.2.1 The asctime_s function
24248     Synopsis
24249 1           #define __STDC_WANT_LIB_EXT1__ 1
24250             #include <time.h>
24251             errno_t asctime_s(char *s, rsize_t maxsize,
24252                  const struct tm *timeptr);
24253     Runtime-constraints
24254 2   Neither s nor timeptr shall be a null pointer. maxsize shall not be less than 26 and
24255     shall not be greater than RSIZE_MAX. The broken-down time pointed to by timeptr
24256     shall be normalized. The calendar year represented by the broken-down time pointed to
24257     by timeptr shall not be less than calendar year 0 and shall not be greater than calendar
24258     year 9999.
24259 3   If there is a runtime-constraint violation, there is no attempt to convert the time, and
24260     s[0] is set to a null character if s is not a null pointer and maxsize is not zero and is
24261     not greater than RSIZE_MAX.
24262     Description
24263 4   The asctime_s function converts the normalized broken-down time in the structure
24264     pointed to by timeptr into a 26 character (including the null character) string in the
24265
24266
24267     409) The normal ranges are defined in 7.26.1.
24268
24269 [page 619]
24270
24271     form
24272             Sun Sep 16 01:03:52 1973\n\0
24273     The fields making up this string are (in order):
24274        1.   The name of the day of the week represented by timeptr->tm_wday using the
24275             following three character weekday names: Sun, Mon, Tue, Wed, Thu, Fri, and Sat.
24276        2.   The character space.
24277        3. The name of the month represented by timeptr->tm_mon using the following
24278           three character month names: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct,
24279           Nov, and Dec.
24280        4.   The character space.
24281        5.   The value of timeptr->tm_mday as if printed using the fprintf format
24282             "%2d".
24283        6.   The character space.
24284        7.   The value of timeptr->tm_hour as if printed using the fprintf format
24285             "%.2d".
24286        8.   The character colon.
24287        9.   The value of timeptr->tm_min as if printed using the fprintf format
24288             "%.2d".
24289      10.    The character colon.
24290      11.    The value of timeptr->tm_sec as if printed using the fprintf format
24291             "%.2d".
24292      12.    The character space.
24293      13.    The value of timeptr->tm_year + 1900 as if printed using the fprintf
24294             format "%4d".
24295      14.    The character new line.
24296      15.    The null character.
24297     Recommended practice
24298     The strftime function allows more flexible formatting and supports locale-specific
24299     behavior. If you do not require the exact form of the result string produced by the
24300     asctime_s function, consider using the strftime function instead.
24301     Returns
24302 5   The asctime_s function returns zero if the time was successfully converted and stored
24303     into the array pointed to by s. Otherwise, it returns a nonzero value.
24304 [page 620]
24305
24306     K.3.8.2.2 The ctime_s function
24307     Synopsis
24308 1           #define __STDC_WANT_LIB_EXT1__ 1
24309             #include <time.h>
24310             errno_t ctime_s(char *s, rsize_t maxsize,
24311                  const time_t *timer);
24312     Runtime-constraints
24313 2   Neither s nor timer shall be a null pointer. maxsize shall not be less than 26 and
24314     shall not be greater than RSIZE_MAX.
24315 3   If there is a runtime-constraint violation, s[0] is set to a null character if s is not a null
24316     pointer and maxsize is not equal zero and is not greater than RSIZE_MAX.
24317     Description
24318 4   The ctime_s function converts the calendar time pointed to by timer to local time in
24319     the form of a string. It is equivalent to
24320             asctime_s(s, maxsize, localtime_s(timer))
24321     Recommended practice
24322     The strftime function allows more flexible formatting and supports locale-specific
24323     behavior. If you do not require the exact form of the result string produced by the
24324     ctime_s function, consider using the strftime function instead.
24325     Returns
24326 5   The ctime_s function returns zero if the time was successfully converted and stored
24327     into the array pointed to by s. Otherwise, it returns a nonzero value.
24328     K.3.8.2.3 The gmtime_s function
24329     Synopsis
24330 1           #define __STDC_WANT_LIB_EXT1__ 1
24331             #include <time.h>
24332             struct tm *gmtime_s(const time_t * restrict timer,
24333                  struct tm * restrict result);
24334     Runtime-constraints
24335 2   Neither timer nor result shall be a null pointer.
24336 3   If there is a runtime-constraint violation, there is no attempt to convert the time.
24337     Description
24338 4   The gmtime_s function converts the calendar time pointed to by timer into a broken-
24339     down time, expressed as UTC. The broken-down time is stored in the structure pointed
24340 [page 621]
24341
24342     to by result.
24343     Returns
24344 5   The gmtime_s function returns result, or a null pointer if the specified time cannot
24345     be converted to UTC or there is a runtime-constraint violation.
24346     K.3.8.2.4 The localtime_s function
24347     Synopsis
24348 1          #define __STDC_WANT_LIB_EXT1__ 1
24349            #include <time.h>
24350            struct tm *localtime_s(const time_t * restrict timer,
24351                 struct tm * restrict result);
24352     Runtime-constraints
24353 2   Neither timer nor result shall be a null pointer.
24354 3   If there is a runtime-constraint violation, there is no attempt to convert the time.
24355     Description
24356 4   The localtime_s function converts the calendar time pointed to by timer into a
24357     broken-down time, expressed as local time. The broken-down time is stored in the
24358     structure pointed to by result.
24359     Returns
24360 5   The localtime_s function returns result, or a null pointer if the specified time
24361     cannot be converted to local time or there is a runtime-constraint violation.
24362     K.3.9 Extended multibyte and wide character utilities <wchar.h>
24363 1   The header <wchar.h> defines two types.
24364 2   The types are
24365            errno_t
24366     which is type int; and
24367            rsize_t
24368     which is the type size_t.
24369 3   Unless explicitly stated otherwise, if the execution of a function described in this
24370     subclause causes copying to take place between objects that overlap, the objects take on
24371     unspecified values.
24372
24373
24374
24375
24376 [page 622]
24377
24378     K.3.9.1 Formatted wide character input/output functions
24379     K.3.9.1.1 The fwprintf_s function
24380     Synopsis
24381 1           #define __STDC_WANT_LIB_EXT1__ 1
24382             #include <wchar.h>
24383             int fwprintf_s(FILE * restrict stream,
24384                  const wchar_t * restrict format, ...);
24385     Runtime-constraints
24386 2   Neither stream nor format shall be a null pointer. The %n specifier410) (modified or
24387     not by flags, field width, or precision) shall not appear in the wide string pointed to by
24388     format. Any argument to fwprintf_s corresponding to a %s specifier shall not be a
24389     null pointer.
24390 3   If there is a runtime-constraint violation, the fwprintf_s function does not attempt to
24391     produce further output, and it is unspecified to what extent fwprintf_s produced
24392     output before discovering the runtime-constraint violation.
24393     Description
24394 4   The fwprintf_s function is equivalent to the fwprintf function except for the
24395     explicit runtime-constraints listed above.
24396     Returns
24397 5   The fwprintf_s function returns the number of wide characters transmitted, or a
24398     negative value if an output error, encoding error, or runtime-constraint violation occurred.
24399     K.3.9.1.2 The fwscanf_s function
24400     Synopsis
24401 1           #define __STDC_WANT_LIB_EXT1__ 1
24402             #include <stdio.h>
24403             #include <wchar.h>
24404             int fwscanf_s(FILE * restrict stream,
24405                  const wchar_t * restrict format, ...);
24406     Runtime-constraints
24407 2   Neither stream nor format shall be a null pointer. Any argument indirected though in
24408     order to store converted input shall not be a null pointer.
24409
24410
24411     410) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24412          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24413          example, if the entire format string was L"%%n".
24414
24415 [page 623]
24416
24417 3   If there is a runtime-constraint violation, the fwscanf_s function does not attempt to
24418     perform further input, and it is unspecified to what extent fwscanf_s performed input
24419     before discovering the runtime-constraint violation.
24420     Description
24421 4   The fwscanf_s function is equivalent to fwscanf except that the c, s, and [
24422     conversion specifiers apply to a pair of arguments (unless assignment suppression is
24423     indicated by a *). The first of these arguments is the same as for fwscanf. That
24424     argument is immediately followed in the argument list by the second argument, which has
24425     type size_t and gives the number of elements in the array pointed to by the first
24426     argument of the pair. If the first argument points to a scalar object, it is considered to be
24427     an array of one element.411)
24428 5   A matching failure occurs if the number of elements in a receiving object is insufficient to
24429     hold the converted input (including any trailing null character).
24430     Returns
24431 6   The fwscanf_s function returns the value of the macro EOF if an input failure occurs
24432     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24433     fwscanf_s function returns the number of input items assigned, which can be fewer
24434     than provided for, or even zero, in the event of an early matching failure.
24435     K.3.9.1.3 The snwprintf_s function
24436     Synopsis
24437 1           #define __STDC_WANT_LIB_EXT1__ 1
24438             #include <wchar.h>
24439             int snwprintf_s(wchar_t * restrict s,
24440                  rsize_t n,
24441                  const wchar_t * restrict format, ...);
24442     Runtime-constraints
24443 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
24444     than RSIZE_MAX. The %n specifier412) (modified or not by flags, field width, or
24445
24446     411) If the format is known at translation time, an implementation may issue a diagnostic for any argument
24447          used to store the result from a c, s, or [ conversion specifier if that argument is not followed by an
24448          argument of a type compatible with rsize_t. A limited amount of checking may be done if even if
24449          the format is not known at translation time. For example, an implementation may issue a diagnostic
24450          for each argument after format that has of type pointer to one of char, signed char,
24451          unsigned char, or void that is not followed by an argument of a type compatible with
24452          rsize_t. The diagnostic could warn that unless the pointer is being used with a conversion specifier
24453          using the hh length modifier, a length argument must follow the pointer argument. Another useful
24454          diagnostic could flag any non-pointer argument following format that did not have a type
24455          compatible with rsize_t.
24456
24457 [page 624]
24458
24459     precision) shall not appear in the wide string pointed to by format. Any argument to
24460     snwprintf_s corresponding to a %s specifier shall not be a null pointer. No encoding
24461     error shall occur.
24462 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
24463     than zero and less than RSIZE_MAX, then the snwprintf_s function sets s[0] to the
24464     null wide character.
24465     Description
24466 4   The snwprintf_s function is equivalent to the swprintf function except for the
24467     explicit runtime-constraints listed above.
24468 5   The snwprintf_s function, unlike swprintf_s, will truncate the result to fit within
24469     the array pointed to by s.
24470     Returns
24471 6   The snwprintf_s function returns the number of wide characters that would have
24472     been written had n been sufficiently large, not counting the terminating wide null
24473     character, or a negative value if a runtime-constraint violation occurred. Thus, the null-
24474     terminated output has been completely written if and only if the returned value is
24475     nonnegative and less than n.
24476     K.3.9.1.4 The swprintf_s function
24477     Synopsis
24478 1           #define __STDC_WANT_LIB_EXT1__ 1
24479             #include <wchar.h>
24480             int swprintf_s(wchar_t * restrict s, rsize_t n,
24481                  const wchar_t * restrict format, ...);
24482     Runtime-constraints
24483 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
24484     than RSIZE_MAX. The number of wide characters (including the trailing null) required
24485     for the result to be written to the array pointed to by s shall not be greater than n. The %n
24486     specifier413) (modified or not by flags, field width, or precision) shall not appear in the
24487     wide string pointed to by format. Any argument to swprintf_s corresponding to a
24488     %s specifier shall not be a null pointer. No encoding error shall occur.
24489
24490
24491     412) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24492          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24493          example, if the entire format string was L"%%n".
24494     413) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24495          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24496          example, if the entire format string was L"%%n".
24497
24498 [page 625]
24499
24500 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
24501     than zero and less than RSIZE_MAX, then the swprintf_s function sets s[0] to the
24502     null wide character.
24503     Description
24504 4   The swprintf_s function is equivalent to the swprintf function except for the
24505     explicit runtime-constraints listed above.
24506 5   The swprintf_s function, unlike snwprintf_s, treats a result too big for the array
24507     pointed to by s as a runtime-constraint violation.
24508     Returns
24509 6   If no runtime-constraint violation occurred, the swprintf_s function returns the
24510     number of wide characters written in the array, not counting the terminating null wide
24511     character. If an encoding error occurred or if n or more wide characters are requested to
24512     be written, swprintf_s returns a negative value. If any other runtime-constraint
24513     violation occurred, swprintf_s returns zero.
24514     K.3.9.1.5 The swscanf_s function
24515     Synopsis
24516 1          #define __STDC_WANT_LIB_EXT1__ 1
24517            #include <wchar.h>
24518            int swscanf_s(const wchar_t * restrict s,
24519                 const wchar_t * restrict format, ...);
24520     Runtime-constraints
24521 2   Neither s nor format shall be a null pointer. Any argument indirected though in order
24522     to store converted input shall not be a null pointer.
24523 3   If there is a runtime-constraint violation, the swscanf_s function does not attempt to
24524     perform further input, and it is unspecified to what extent swscanf_s performed input
24525     before discovering the runtime-constraint violation.
24526     Description
24527 4   The swscanf_s function is equivalent to fwscanf_s, except that the argument s
24528     specifies a wide string from which the input is to be obtained, rather than from a stream.
24529     Reaching the end of the wide string is equivalent to encountering end-of-file for the
24530     fwscanf_s function.
24531     Returns
24532 5   The swscanf_s function returns the value of the macro EOF if an input failure occurs
24533     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24534     swscanf_s function returns the number of input items assigned, which can be fewer
24535     than provided for, or even zero, in the event of an early matching failure.
24536 [page 626]
24537
24538     K.3.9.1.6 The vfwprintf_s function
24539     Synopsis
24540 1           #define __STDC_WANT_LIB_EXT1__ 1
24541             #include <stdarg.h>
24542             #include <stdio.h>
24543             #include <wchar.h>
24544             int vfwprintf_s(FILE * restrict stream,
24545                  const wchar_t * restrict format,
24546                  va_list arg);
24547     Runtime-constraints
24548 2   Neither stream nor format shall be a null pointer. The %n specifier414) (modified or
24549     not by flags, field width, or precision) shall not appear in the wide string pointed to by
24550     format. Any argument to vfwprintf_s corresponding to a %s specifier shall not be
24551     a null pointer.
24552 3   If there is a runtime-constraint violation, the vfwprintf_s function does not attempt
24553     to produce further output, and it is unspecified to what extent vfwprintf_s produced
24554     output before discovering the runtime-constraint violation.
24555     Description
24556 4   The vfwprintf_s function is equivalent to the vfwprintf function except for the
24557     explicit runtime-constraints listed above.
24558     Returns
24559 5   The vfwprintf_s function returns the number of wide characters transmitted, or a
24560     negative value if an output error, encoding error, or runtime-constraint violation occurred.
24561     K.3.9.1.7 The vfwscanf_s function
24562     Synopsis
24563 1           #define __STDC_WANT_LIB_EXT1__ 1
24564             #include <stdarg.h>
24565             #include <stdio.h>
24566             #include <wchar.h>
24567             int vfwscanf_s(FILE * restrict stream,
24568                  const wchar_t * restrict format, va_list arg);
24569
24570
24571
24572     414) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24573          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24574          example, if the entire format string was L"%%n".
24575
24576 [page 627]
24577
24578     Runtime-constraints
24579 2   Neither stream nor format shall be a null pointer. Any argument indirected though in
24580     order to store converted input shall not be a null pointer.
24581 3   If there is a runtime-constraint violation, the vfwscanf_s function does not attempt to
24582     perform further input, and it is unspecified to what extent vfwscanf_s performed input
24583     before discovering the runtime-constraint violation.
24584     Description
24585 4   The vfwscanf_s function is equivalent to fwscanf_s, with the variable argument
24586     list replaced by arg, which shall have been initialized by the va_start macro (and
24587     possibly subsequent va_arg calls). The vfwscanf_s function does not invoke the
24588     va_end macro.415)
24589     Returns
24590 5   The vfwscanf_s function returns the value of the macro EOF if an input failure occurs
24591     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24592     vfwscanf_s function returns the number of input items assigned, which can be fewer
24593     than provided for, or even zero, in the event of an early matching failure.
24594     K.3.9.1.8 The vsnwprintf_s function
24595     Synopsis
24596 1           #define __STDC_WANT_LIB_EXT1__ 1
24597             #include <stdarg.h>
24598             #include <wchar.h>
24599             int vsnwprintf_s(wchar_t * restrict s,
24600                  rsize_t n,
24601                  const wchar_t * restrict format,
24602                  va_list arg);
24603     Runtime-constraints
24604 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
24605     than RSIZE_MAX. The %n specifier416) (modified or not by flags, field width, or
24606     precision) shall not appear in the wide string pointed to by format. Any argument to
24607     vsnwprintf_s corresponding to a %s specifier shall not be a null pointer. No
24608     encoding error shall occur.
24609
24610     415) As the functions vfwscanf_s, vwscanf_s, and vswscanf_s invoke the va_arg macro, the
24611          value of arg after the return is indeterminate.
24612     416) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24613          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24614          example, if the entire format string was L"%%n".
24615
24616 [page 628]
24617
24618 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
24619     than zero and less than RSIZE_MAX, then the vsnwprintf_s function sets s[0] to
24620     the null wide character.
24621     Description
24622 4   The vsnwprintf_s function is equivalent to the vswprintf function except for the
24623     explicit runtime-constraints listed above.
24624 5   The vsnwprintf_s function, unlike vswprintf_s, will truncate the result to fit
24625     within the array pointed to by s.
24626     Returns
24627 6   The vsnwprintf_s function returns the number of wide characters that would have
24628     been written had n been sufficiently large, not counting the terminating null character, or
24629     a negative value if a runtime-constraint violation occurred. Thus, the null-terminated
24630     output has been completely written if and only if the returned value is nonnegative and
24631     less than n.
24632     K.3.9.1.9 The vswprintf_s function
24633     Synopsis
24634 1           #define __STDC_WANT_LIB_EXT1__ 1
24635             #include <stdarg.h>
24636             #include <wchar.h>
24637             int vswprintf_s(wchar_t * restrict s,
24638                  rsize_t n,
24639                  const wchar_t * restrict format,
24640                  va_list arg);
24641     Runtime-constraints
24642 2   Neither s nor format shall be a null pointer. n shall neither equal zero nor be greater
24643     than RSIZE_MAX. The number of wide characters (including the trailing null) required
24644     for the result to be written to the array pointed to by s shall not be greater than n. The %n
24645     specifier417) (modified or not by flags, field width, or precision) shall not appear in the
24646     wide string pointed to by format. Any argument to vswprintf_s corresponding to a
24647     %s specifier shall not be a null pointer. No encoding error shall occur.
24648 3   If there is a runtime-constraint violation, then if s is not a null pointer and n is greater
24649     than zero and less than RSIZE_MAX, then the vswprintf_s function sets s[0] to the
24650     null wide character.
24651
24652     417) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24653          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24654          example, if the entire format string was L"%%n".
24655
24656 [page 629]
24657
24658     Description
24659 4   The vswprintf_s function is equivalent to the vswprintf function except for the
24660     explicit runtime-constraints listed above.
24661 5   The vswprintf_s function, unlike vsnwprintf_s, treats a result too big for the
24662     array pointed to by s as a runtime-constraint violation.
24663     Returns
24664 6   If no runtime-constraint violation occurred, the vswprintf_s function returns the
24665     number of wide characters written in the array, not counting the terminating null wide
24666     character. If an encoding error occurred or if n or more wide characters are requested to
24667     be written, vswprintf_s returns a negative value. If any other runtime-constraint
24668     violation occurred, vswprintf_s returns zero.
24669     K.3.9.1.10 The vswscanf_s function
24670     Synopsis
24671 1          #define __STDC_WANT_LIB_EXT1__ 1
24672            #include <stdarg.h>
24673            #include <wchar.h>
24674            int vswscanf_s(const wchar_t * restrict s,
24675                 const wchar_t * restrict format,
24676                 va_list arg);
24677     Runtime-constraints
24678 2   Neither s nor format shall be a null pointer. Any argument indirected though in order
24679     to store converted input shall not be a null pointer.
24680 3   If there is a runtime-constraint violation, the vswscanf_s function does not attempt to
24681     perform further input, and it is unspecified to what extent vswscanf_s performed input
24682     before discovering the runtime-constraint violation.
24683     Description
24684 4   The vswscanf_s function is equivalent to swscanf_s, with the variable argument
24685     list replaced by arg, which shall have been initialized by the va_start macro (and
24686     possibly subsequent va_arg calls). The vswscanf_s function does not invoke the
24687     va_end macro.418)
24688
24689
24690
24691
24692     418) As the functions vfwscanf_s, vwscanf_s, and vswscanf_s invoke the va_arg macro, the
24693          value of arg after the return is indeterminate.
24694
24695 [page 630]
24696
24697     Returns
24698 5   The vswscanf_s function returns the value of the macro EOF if an input failure occurs
24699     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24700     vswscanf_s function returns the number of input items assigned, which can be fewer
24701     than provided for, or even zero, in the event of an early matching failure.
24702     K.3.9.1.11 The vwprintf_s function
24703     Synopsis
24704 1           #define __STDC_WANT_LIB_EXT1__ 1
24705             #include <stdarg.h>
24706             #include <wchar.h>
24707             int vwprintf_s(const wchar_t * restrict format,
24708                  va_list arg);
24709     Runtime-constraints
24710 2   format shall not be a null pointer. The %n specifier419) (modified or not by flags, field
24711     width, or precision) shall not appear in the wide string pointed to by format. Any
24712     argument to vwprintf_s corresponding to a %s specifier shall not be a null pointer.
24713 3   If there is a runtime-constraint violation, the vwprintf_s function does not attempt to
24714     produce further output, and it is unspecified to what extent vwprintf_s produced
24715     output before discovering the runtime-constraint violation.
24716     Description
24717 4   The vwprintf_s function is equivalent to the vwprintf function except for the
24718     explicit runtime-constraints listed above.
24719     Returns
24720 5   The vwprintf_s function returns the number of wide characters transmitted, or a
24721     negative value if an output error, encoding error, or runtime-constraint violation occurred.
24722
24723
24724
24725
24726     419) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24727          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24728          example, if the entire format string was L"%%n".
24729
24730 [page 631]
24731
24732     K.3.9.1.12 The vwscanf_s function
24733     Synopsis
24734 1           #define __STDC_WANT_LIB_EXT1__ 1
24735             #include <stdarg.h>
24736             #include <wchar.h>
24737             int vwscanf_s(const wchar_t * restrict format,
24738                  va_list arg);
24739     Runtime-constraints
24740 2   format shall not be a null pointer. Any argument indirected though in order to store
24741     converted input shall not be a null pointer.
24742 3   If there is a runtime-constraint violation, the vwscanf_s function does not attempt to
24743     perform further input, and it is unspecified to what extent vwscanf_s performed input
24744     before discovering the runtime-constraint violation.
24745     Description
24746 4   The vwscanf_s function is equivalent to wscanf_s, with the variable argument list
24747     replaced by arg, which shall have been initialized by the va_start macro (and
24748     possibly subsequent va_arg calls). The vwscanf_s function does not invoke the
24749     va_end macro.420)
24750     Returns
24751 5   The vwscanf_s function returns the value of the macro EOF if an input failure occurs
24752     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24753     vwscanf_s function returns the number of input items assigned, which can be fewer
24754     than provided for, or even zero, in the event of an early matching failure.
24755     K.3.9.1.13 The wprintf_s function
24756     Synopsis
24757 1           #define __STDC_WANT_LIB_EXT1__ 1
24758             #include <wchar.h>
24759             int wprintf_s(const wchar_t * restrict format, ...);
24760     Runtime-constraints
24761 2   format shall not be a null pointer. The %n specifier421) (modified or not by flags, field
24762
24763     420) As the functions vfwscanf_s, vwscanf_s, and vswscanf_s invoke the va_arg macro, the
24764          value of arg after the return is indeterminate.
24765     421) It is not a runtime-constraint violation for the wide characters %n to appear in sequence in the wide
24766          string pointed at by format when those wide characters are not a interpreted as a %n specifier. For
24767          example, if the entire format string was L"%%n".
24768
24769 [page 632]
24770
24771     width, or precision) shall not appear in the wide string pointed to by format. Any
24772     argument to wprintf_s corresponding to a %s specifier shall not be a null pointer.
24773 3   If there is a runtime-constraint violation, the wprintf_s function does not attempt to
24774     produce further output, and it is unspecified to what extent wprintf_s produced output
24775     before discovering the runtime-constraint violation.
24776     Description
24777 4   The wprintf_s function is equivalent to the wprintf function except for the explicit
24778     runtime-constraints listed above.
24779     Returns
24780 5   The wprintf_s function returns the number of wide characters transmitted, or a
24781     negative value if an output error, encoding error, or runtime-constraint violation occurred.
24782     K.3.9.1.14 The wscanf_s function
24783     Synopsis
24784 1           #define __STDC_WANT_LIB_EXT1__ 1
24785             #include <wchar.h>
24786             int wscanf_s(const wchar_t * restrict format, ...);
24787     Runtime-constraints
24788 2   format shall not be a null pointer. Any argument indirected though in order to store
24789     converted input shall not be a null pointer.
24790 3   If there is a runtime-constraint violation, the wscanf_s function does not attempt to
24791     perform further input, and it is unspecified to what extent wscanf_s performed input
24792     before discovering the runtime-constraint violation.
24793     Description
24794 4   The wscanf_s function is equivalent to fwscanf_s with the argument stdin
24795     interposed before the arguments to wscanf_s.
24796     Returns
24797 5   The wscanf_s function returns the value of the macro EOF if an input failure occurs
24798     before any conversion or if there is a runtime-constraint violation. Otherwise, the
24799     wscanf_s function returns the number of input items assigned, which can be fewer than
24800     provided for, or even zero, in the event of an early matching failure.
24801
24802
24803
24804
24805 [page 633]
24806
24807     K.3.9.2 General wide string utilities
24808     K.3.9.2.1 Wide string copying functions
24809     K.3.9.2.1.1 The wcscpy_s function
24810     Synopsis
24811 1           #define __STDC_WANT_LIB_EXT1__ 1
24812             #include <wchar.h>
24813             errno_t wcscpy_s(wchar_t * restrict s1,
24814                  rsize_t s1max,
24815                  const wchar_t * restrict s2);
24816     Runtime-constraints
24817 2   Neither s1 nor s2 shall be a null pointer. s1max shall not be greater than RSIZE_MAX.
24818     s1max shall not equal zero. s1max shall be greater than wcsnlen_s(s2, s1max).
24819     Copying shall not take place between objects that overlap.
24820 3   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
24821     greater than zero and not greater than RSIZE_MAX, then wcscpy_s sets s1[0] to the
24822     null wide character.
24823     Description
24824 4   The wcscpy_s function copies the wide string pointed to by s2 (including the
24825     terminating null wide character) into the array pointed to by s1.
24826 5   All elements following the terminating null wide character (if any) written by
24827     wcscpy_s in the array of s1max wide characters pointed to by s1 take unspecified
24828     values when wcscpy_s returns.422)
24829     Returns
24830 6   The wcscpy_s function returns zero423) if there was no runtime-constraint violation.
24831     Otherwise, a nonzero value is returned.
24832
24833
24834
24835
24836     422) This allows an implementation to copy wide characters from s2 to s1 while simultaneously checking
24837          if any of those wide characters are null. Such an approach might write a wide character to every
24838          element of s1 before discovering that the first element should be set to the null wide character.
24839     423) A zero return value implies that all of the requested wide characters from the string pointed to by s2
24840          fit within the array pointed to by s1 and that the result in s1 is null terminated.
24841
24842 [page 634]
24843
24844      K.3.9.2.1.2 The wcsncpy_s function
24845      Synopsis
24846 7            #define __STDC_WANT_LIB_EXT1__ 1
24847              #include <wchar.h>
24848              errno_t wcsncpy_s(wchar_t * restrict s1,
24849                   rsize_t s1max,
24850                   const wchar_t * restrict s2,
24851                   rsize_t n);
24852      Runtime-constraints
24853 8    Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
24854      RSIZE_MAX. s1max shall not equal zero. If n is not less than s1max, then s1max
24855      shall be greater than wcsnlen_s(s2, s1max). Copying shall not take place between
24856      objects that overlap.
24857 9    If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
24858      greater than zero and not greater than RSIZE_MAX, then wcsncpy_s sets s1[0] to the
24859      null wide character.
24860      Description
24861 10   The wcsncpy_s function copies not more than n successive wide characters (wide
24862      characters that follow a null wide character are not copied) from the array pointed to by
24863      s2 to the array pointed to by s1. If no null wide character was copied from s2, then
24864      s1[n] is set to a null wide character.
24865 11   All elements following the terminating null wide character (if any) written by
24866      wcsncpy_s in the array of s1max wide characters pointed to by s1 take unspecified
24867      values when wcsncpy_s returns.424)
24868      Returns
24869 12   The wcsncpy_s function returns zero425) if there was no runtime-constraint violation.
24870      Otherwise, a nonzero value is returned.
24871 13   EXAMPLE 1 The wcsncpy_s function can be used to copy a wide string without the danger that the
24872      result will not be null terminated or that wide characters will be written past the end of the destination
24873      array.
24874
24875
24876
24877
24878      424) This allows an implementation to copy wide characters from s2 to s1 while simultaneously checking
24879           if any of those wide characters are null. Such an approach might write a wide character to every
24880           element of s1 before discovering that the first element should be set to the null wide character.
24881      425) A zero return value implies that all of the requested wide characters from the string pointed to by s2
24882           fit within the array pointed to by s1 and that the result in s1 is null terminated.
24883
24884 [page 635]
24885
24886              #define __STDC_WANT_LIB_EXT1__ 1
24887              #include <wchar.h>
24888              /* ... */
24889              wchar_t src1[100] = L"hello";
24890              wchar_t src2[7] = {L'g', L'o', L'o', L'd', L'b', L'y', L'e'};
24891              wchar_t dst1[6], dst2[5], dst3[5];
24892              int r1, r2, r3;
24893              r1 = wcsncpy_s(dst1, 6, src1, 100);
24894              r2 = wcsncpy_s(dst2, 5, src2, 7);
24895              r3 = wcsncpy_s(dst3, 5, src2, 4);
24896      The first call will assign to r1 the value zero and to dst1 the sequence of wide characters hello\0.
24897      The second call will assign to r2 a nonzero value and to dst2 the sequence of wide characters \0.
24898      The third call will assign to r3 the value zero and to dst3 the sequence of wide characters good\0.
24899
24900      K.3.9.2.1.3 The wmemcpy_s function
24901      Synopsis
24902 14           #define __STDC_WANT_LIB_EXT1__ 1
24903              #include <wchar.h>
24904              errno_t wmemcpy_s(wchar_t * restrict s1,
24905                   rsize_t s1max,
24906                   const wchar_t * restrict s2,
24907                   rsize_t n);
24908      Runtime-constraints
24909 15   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
24910      RSIZE_MAX. n shall not be greater than s1max. Copying shall not take place between
24911      objects that overlap.
24912 16   If there is a runtime-constraint violation, the wmemcpy_s function stores zeros in the
24913      first s1max wide characters of the object pointed to by s1 if s1 is not a null pointer and
24914      s1max is not greater than RSIZE_MAX.
24915      Description
24916 17   The wmemcpy_s function copies n successive wide characters from the object pointed
24917      to by s2 into the object pointed to by s1.
24918      Returns
24919 18   The wmemcpy_s function returns zero if there was no runtime-constraint violation.
24920      Otherwise, a nonzero value is returned.
24921
24922
24923
24924
24925 [page 636]
24926
24927      K.3.9.2.1.4 The wmemmove_s function
24928      Synopsis
24929 19           #define __STDC_WANT_LIB_EXT1__ 1
24930              #include <wchar.h>
24931              errno_t wmemmove_s(wchar_t *s1, rsize_t s1max,
24932                   const wchar_t *s2, rsize_t n);
24933      Runtime-constraints
24934 20   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
24935      RSIZE_MAX. n shall not be greater than s1max.
24936 21   If there is a runtime-constraint violation, the wmemmove_s function stores zeros in the
24937      first s1max wide characters of the object pointed to by s1 if s1 is not a null pointer and
24938      s1max is not greater than RSIZE_MAX.
24939      Description
24940 22   The wmemmove_s function copies n successive wide characters from the object pointed
24941      to by s2 into the object pointed to by s1. This copying takes place as if the n wide
24942      characters from the object pointed to by s2 are first copied into a temporary array of n
24943      wide characters that does not overlap the objects pointed to by s1 or s2, and then the n
24944      wide characters from the temporary array are copied into the object pointed to by s1.
24945      Returns
24946 23   The wmemmove_s function returns zero if there was no runtime-constraint violation.
24947      Otherwise, a nonzero value is returned.
24948      K.3.9.2.2 Wide string concatenation functions
24949      K.3.9.2.2.1 The wcscat_s function
24950      Synopsis
24951 1            #define __STDC_WANT_LIB_EXT1__ 1
24952              #include <wchar.h>
24953              errno_t wcscat_s(wchar_t * restrict s1,
24954                   rsize_t s1max,
24955                   const wchar_t * restrict s2);
24956      Runtime-constraints
24957 2    Let m denote the value s1max - wcsnlen_s(s1, s1max) upon entry to
24958      wcscat_s.
24959 3    Neither s1 nor s2 shall be a null pointer. s1max shall not be greater than RSIZE_MAX.
24960      s1max shall not equal zero. m shall not equal zero.426) m shall be greater than
24961      wcsnlen_s(s2, m). Copying shall not take place between objects that overlap.
24962
24963 [page 637]
24964
24965 4    If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
24966      greater than zero and not greater than RSIZE_MAX, then wcscat_s sets s1[0] to the
24967      null wide character.
24968      Description
24969 5    The wcscat_s function appends a copy of the wide string pointed to by s2 (including
24970      the terminating null wide character) to the end of the wide string pointed to by s1. The
24971      initial wide character from s2 overwrites the null wide character at the end of s1.
24972 6    All elements following the terminating null wide character (if any) written by
24973      wcscat_s in the array of s1max wide characters pointed to by s1 take unspecified
24974      values when wcscat_s returns.427)
24975      Returns
24976 7    The wcscat_s function returns zero428) if there was no runtime-constraint violation.
24977      Otherwise, a nonzero value is returned.
24978      K.3.9.2.2.2 The wcsncat_s function
24979      Synopsis
24980 8             #define __STDC_WANT_LIB_EXT1__ 1
24981               #include <wchar.h>
24982               errno_t wcsncat_s(wchar_t * restrict s1,
24983                    rsize_t s1max,
24984                    const wchar_t * restrict s2,
24985                    rsize_t n);
24986      Runtime-constraints
24987 9    Let m denote the value s1max - wcsnlen_s(s1, s1max) upon entry to
24988      wcsncat_s.
24989 10   Neither s1 nor s2 shall be a null pointer. Neither s1max nor n shall be greater than
24990      RSIZE_MAX. s1max shall not equal zero. m shall not equal zero.429) If n is not less
24991      than m, then m shall be greater than wcsnlen_s(s2, m). Copying shall not take
24992      place between objects that overlap.
24993
24994
24995      426) Zero means that s1 was not null terminated upon entry to wcscat_s.
24996      427) This allows an implementation to append wide characters from s2 to s1 while simultaneously
24997           checking if any of those wide characters are null. Such an approach might write a wide character to
24998           every element of s1 before discovering that the first element should be set to the null wide character.
24999      428) A zero return value implies that all of the requested wide characters from the wide string pointed to by
25000           s2 were appended to the wide string pointed to by s1 and that the result in s1 is null terminated.
25001      429) Zero means that s1 was not null terminated upon entry to wcsncat_s.
25002
25003 [page 638]
25004
25005 11   If there is a runtime-constraint violation, then if s1 is not a null pointer and s1max is
25006      greater than zero and not greater than RSIZE_MAX, then wcsncat_s sets s1[0] to the
25007      null wide character.
25008      Description
25009 12   The wcsncat_s function appends not more than n successive wide characters (wide
25010      characters that follow a null wide character are not copied) from the array pointed to by
25011      s2 to the end of the wide string pointed to by s1. The initial wide character from s2
25012      overwrites the null wide character at the end of s1. If no null wide character was copied
25013      from s2, then s1[s1max-m+n] is set to a null wide character.
25014 13   All elements following the terminating null wide character (if any) written by
25015      wcsncat_s in the array of s1max wide characters pointed to by s1 take unspecified
25016      values when wcsncat_s returns.430)
25017      Returns
25018 14   The wcsncat_s function returns zero431) if there was no runtime-constraint violation.
25019      Otherwise, a nonzero value is returned.
25020 15   EXAMPLE 1 The wcsncat_s function can be used to copy a wide string without the danger that the
25021      result will not be null terminated or that wide characters will be written past the end of the destination
25022      array.
25023               #define __STDC_WANT_LIB_EXT1__ 1
25024               #include <wchar.h>
25025               /* ... */
25026               wchar_t s1[100] = L"good";
25027               wchar_t s2[6] = L"hello";
25028               wchar_t s3[6] = L"hello";
25029               wchar_t s4[7] = L"abc";
25030               wchar_t s5[1000] = L"bye";
25031               int r1, r2, r3, r4;
25032               r1 = wcsncat_s(s1, 100, s5, 1000);
25033               r2 = wcsncat_s(s2, 6, L"", 1);
25034               r3 = wcsncat_s(s3, 6, L"X", 2);
25035               r4 = wcsncat_s(s4, 7, L"defghijklmn", 3);
25036      After the first call r1 will have the value zero and s1 will be the wide character sequence goodbye\0.
25037      After the second call r2 will have the value zero and s2 will be the wide character sequence hello\0.
25038      After the third call r3 will have a nonzero value and s3 will be the wide character sequence \0.
25039      After the fourth call r4 will have the value zero and s4 will be the wide character sequence abcdef\0.
25040
25041
25042
25043
25044      430) This allows an implementation to append wide characters from s2 to s1 while simultaneously
25045           checking if any of those wide characters are null. Such an approach might write a wide character to
25046           every element of s1 before discovering that the first element should be set to the null wide character.
25047      431) A zero return value implies that all of the requested wide characters from the wide string pointed to by
25048           s2 were appended to the wide string pointed to by s1 and that the result in s1 is null terminated.
25049
25050 [page 639]
25051
25052     K.3.9.2.3 Wide string search functions
25053     K.3.9.2.3.1 The wcstok_s function
25054     Synopsis
25055 1          #define __STDC_WANT_LIB_EXT1__ 1
25056            #include <wchar.h>
25057            wchar_t *wcstok_s(wchar_t * restrict s1,
25058                 rsize_t * restrict s1max,
25059                 const wchar_t * restrict s2,
25060                 wchar_t ** restrict ptr);
25061     Runtime-constraints
25062 2   None of s1max, s2, or ptr shall be a null pointer. If s1 is a null pointer, then *ptr
25063     shall not be a null pointer. The value of *s1max shall not be greater than RSIZE_MAX.
25064     The end of the token found shall occur within the first *s1max wide characters of s1 for
25065     the first call, and shall occur within the first *s1max wide characters of where searching
25066     resumes on subsequent calls.
25067 3   If there is a runtime-constraint violation, the wcstok_s function does not indirect
25068     through the s1 or s2 pointers, and does not store a value in the object pointed to by ptr.
25069     Description
25070 4   A sequence of calls to the wcstok_s function breaks the wide string pointed to by s1
25071     into a sequence of tokens, each of which is delimited by a wide character from the wide
25072     string pointed to by s2. The fourth argument points to a caller-provided wchar_t
25073     pointer into which the wcstok_s function stores information necessary for it to
25074     continue scanning the same wide string.
25075 5   The first call in a sequence has a non-null first argument and s1max points to an object
25076     whose value is the number of elements in the wide character array pointed to by the first
25077     argument. The first call stores an initial value in the object pointed to by ptr and
25078     updates the value pointed to by s1max to reflect the number of elements that remain in
25079     relation to ptr. Subsequent calls in the sequence have a null first argument and the
25080     objects pointed to by s1max and ptr are required to have the values stored by the
25081     previous call in the sequence, which are then updated. The separator wide string pointed
25082     to by s2 may be different from call to call.
25083 6   The first call in the sequence searches the wide string pointed to by s1 for the first wide
25084     character that is not contained in the current separator wide string pointed to by s2. If no
25085     such wide character is found, then there are no tokens in the wide string pointed to by s1
25086     and the wcstok_s function returns a null pointer. If such a wide character is found, it is
25087     the start of the first token.
25088
25089
25090 [page 640]
25091
25092 7    The wcstok_s function then searches from there for the first wide character in s1 that
25093      is contained in the current separator wide string. If no such wide character is found, the
25094      current token extends to the end of the wide string pointed to by s1, and subsequent
25095      searches in the same wide string for a token return a null pointer. If such a wide character
25096      is found, it is overwritten by a null wide character, which terminates the current token.
25097 8    In all cases, the wcstok_s function stores sufficient information in the pointer pointed
25098      to by ptr so that subsequent calls, with a null pointer for s1 and the unmodified pointer
25099      value for ptr, shall start searching just past the element overwritten by a null wide
25100      character (if any).
25101      Returns
25102 9    The wcstok_s function returns a pointer to the first wide character of a token, or a null
25103      pointer if there is no token or there is a runtime-constraint violation.
25104 10   EXAMPLE
25105              #define __STDC_WANT_LIB_EXT1__ 1
25106              #include <wchar.h>
25107              static wchar_t str1[] = L"?a???b,,,#c";
25108              static wchar_t str2[] = L"\t \t";
25109              wchar_t *t, *ptr1, *ptr2;
25110              rsize_t max1 = wcslen(str1)+1;
25111              rsize_t max2 = wcslen(str2)+1;
25112              t   =   wcstok_s(str1,   &max1,   "?", &ptr1);        //   t   points to the token "a"
25113              t   =   wcstok_s(NULL,   &max1,   ",", &ptr1);        //   t   points to the token "??b"
25114              t   =   wcstok_s(str2,   &max2,   " \t", &ptr2);      //   t   is a null pointer
25115              t   =   wcstok_s(NULL,   &max1,   "#,", &ptr1);       //   t   points to the token "c"
25116              t   =   wcstok_s(NULL,   &max1,   "?", &ptr1);        //   t   is a null pointer
25117
25118      K.3.9.2.4 Miscellaneous functions
25119      K.3.9.2.4.1 The wcsnlen_s function
25120      Synopsis
25121 1            #define __STDC_WANT_LIB_EXT1__ 1
25122              #include <wchar.h>
25123              size_t wcsnlen_s(const wchar_t *s, size_t maxsize);
25124      Description
25125 2    The wcsnlen_s function computes the length of the wide string pointed to by s.
25126      Returns
25127 3    If s is a null pointer,432) then the wcsnlen_s function returns zero.
25128 4    Otherwise, the wcsnlen_s function returns the number of wide characters that precede
25129      the terminating null wide character. If there is no null wide character in the first
25130      maxsize wide characters of s then wcsnlen_s returns maxsize. At most the first
25131
25132 [page 641]
25133
25134     maxsize wide characters of s shall be accessed by wcsnlen_s.
25135     K.3.9.3 Extended multibyte/wide character conversion utilities
25136     K.3.9.3.1 Restartable multibyte/wide character conversion functions
25137 1   Unlike wcrtomb, wcrtomb_s does not permit the ps parameter (the pointer to the
25138     conversion state) to be a null pointer.
25139     K.3.9.3.1.1 The wcrtomb_s function
25140     Synopsis
25141 2           #include <wchar.h>
25142             errno_t wcrtomb_s(size_t * restrict retval,
25143                  char * restrict s, rsize_t smax,
25144                  wchar_t wc, mbstate_t * restrict ps);
25145     Runtime-constraints
25146 3   Neither retval nor ps shall be a null pointer. If s is not a null pointer, then smax
25147     shall not equal zero and shall not be greater than RSIZE_MAX. If s is not a null pointer,
25148     then smax shall be not be less than the number of bytes to be stored in the array pointed
25149     to by s. If s is a null pointer, then smax shall equal zero.
25150 4   If there is a runtime-constraint violation, then wcrtomb_s does the following. If s is
25151     not a null pointer and smax is greater than zero and not greater than RSIZE_MAX, then
25152     wcrtomb_s sets s[0] to the null character. If retval is not a null pointer, then
25153     wcrtomb_s sets *retval to (size_t)(-1).
25154     Description
25155 5   If s is a null pointer, the wcrtomb_s function is equivalent to the call
25156                     wcrtomb_s(&retval, buf, sizeof buf, L'\0', ps)
25157     where retval and buf are internal variables of the appropriate types, and the size of
25158     buf is greater than MB_CUR_MAX.
25159 6   If s is not a null pointer, the wcrtomb_s function determines the number of bytes
25160     needed to represent the multibyte character that corresponds to the wide character given
25161     by wc (including any shift sequences), and stores the multibyte character representation
25162     in the array whose first element is pointed to by s. At most MB_CUR_MAX bytes are
25163     stored. If wc is a null wide character, a null byte is stored, preceded by any shift
25164     sequence needed to restore the initial shift state; the resulting state described is the initial
25165     conversion state.
25166
25167     432) Note that the wcsnlen_s function has no runtime-constraints. This lack of runtime-constraints
25168          along with the values returned for a null pointer or an unterminated wide string argument make
25169          wcsnlen_s useful in algorithms that gracefully handle such exceptional data.
25170
25171 [page 642]
25172
25173 7   If wc does not correspond to a valid multibyte character, an encoding error occurs: the
25174     wcrtomb_s function stores the value (size_t)(-1) into *retval and the
25175     conversion state is unspecified. Otherwise, the wcrtomb_s function stores into
25176     *retval the number of bytes (including any shift sequences) stored in the array pointed
25177     to by s.
25178     Returns
25179 8   The wcrtomb_s function returns zero if no runtime-constraint violation and no
25180     encoding error occurred. Otherwise, a nonzero value is returned.
25181     K.3.9.3.2 Restartable multibyte/wide string conversion functions
25182 1   Unlike mbsrtowcs and wcsrtombs, mbsrtowcs_s and wcsrtombs_s do not
25183     permit the ps parameter (the pointer to the conversion state) to be a null pointer.
25184     K.3.9.3.2.1 The mbsrtowcs_s function
25185     Synopsis
25186 2           #include <wchar.h>
25187             errno_t mbsrtowcs_s(size_t * restrict retval,
25188                  wchar_t * restrict dst, rsize_t dstmax,
25189                  const char ** restrict src, rsize_t len,
25190                  mbstate_t * restrict ps);
25191     Runtime-constraints
25192 3   None of retval, src, *src, or ps shall be null pointers. If dst is not a null pointer,
25193     then neither len nor dstmax shall be greater than RSIZE_MAX. If dst is a null
25194     pointer, then dstmax shall equal zero. If dst is not a null pointer, then dstmax shall
25195     not equal zero. If dst is not a null pointer and len is not less than dstmax, then a null
25196     character shall occur within the first dstmax multibyte characters of the array pointed to
25197     by *src.
25198 4   If there is a runtime-constraint violation, then mbsrtowcs_s does the following. If
25199     retval is not a null pointer, then mbsrtowcs_s sets *retval to (size_t)(-1).
25200     If dst is not a null pointer and dstmax is greater than zero and less than RSIZE_MAX,
25201     then mbsrtowcs_s sets dst[0] to the null wide character.
25202     Description
25203 5   The mbsrtowcs_s function converts a sequence of multibyte characters that begins in
25204     the conversion state described by the object pointed to by ps, from the array indirectly
25205     pointed to by src into a sequence of corresponding wide characters. If dst is not a null
25206     pointer, the converted characters are stored into the array pointed to by dst. Conversion
25207     continues up to and including a terminating null character, which is also stored.
25208     Conversion stops earlier in two cases: when a sequence of bytes is encountered that does
25209     not form a valid multibyte character, or (if dst is not a null pointer) when len wide
25210 [page 643]
25211
25212      characters have been stored into the array pointed to by dst.433) If dst is not a null
25213      pointer and no null wide character was stored into the array pointed to by dst, then
25214      dst[len] is set to the null wide character. Each conversion takes place as if by a call
25215      to the mbrtowc function.
25216 6    If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
25217      pointer (if conversion stopped due to reaching a terminating null character) or the address
25218      just past the last multibyte character converted (if any). If conversion stopped due to
25219      reaching a terminating null character and if dst is not a null pointer, the resulting state
25220      described is the initial conversion state.
25221 7    Regardless of whether dst is or is not a null pointer, if the input conversion encounters a
25222      sequence of bytes that do not form a valid multibyte character, an encoding error occurs:
25223      the mbsrtowcs_s function stores the value (size_t)(-1) into *retval and the
25224      conversion state is unspecified. Otherwise, the mbsrtowcs_s function stores into
25225      *retval the number of multibyte characters successfully converted, not including the
25226      terminating null character (if any).
25227 8    All elements following the terminating null wide character (if any) written by
25228      mbsrtowcs_s in the array of dstmax wide characters pointed to by dst take
25229      unspecified values when mbsrtowcs_s returns.434)
25230 9    If copying takes place between objects that overlap, the objects take on unspecified
25231      values.
25232      Returns
25233 10   The mbsrtowcs_s function returns zero if no runtime-constraint violation and no
25234      encoding error occurred. Otherwise, a nonzero value is returned.
25235      K.3.9.3.2.2 The wcsrtombs_s function
25236      Synopsis
25237 11            #include <wchar.h>
25238               errno_t wcsrtombs_s(size_t * restrict retval,
25239                    char * restrict dst, rsize_t dstmax,
25240                    const wchar_t ** restrict src, rsize_t len,
25241                    mbstate_t * restrict ps);
25242
25243
25244
25245
25246      433) Thus, the value of len is ignored if dst is a null pointer.
25247      434) This allows an implementation to attempt converting the multibyte string before discovering a
25248           terminating null character did not occur where required.
25249
25250 [page 644]
25251
25252      Runtime-constraints
25253 12   None of retval, src, *src, or ps shall be null pointers. If dst is not a null pointer,
25254      then neither len nor dstmax shall be greater than RSIZE_MAX. If dst is a null
25255      pointer, then dstmax shall equal zero. If dst is not a null pointer, then dstmax shall
25256      not equal zero. If dst is not a null pointer and len is not less than dstmax, then the
25257      conversion shall have been stopped (see below) because a terminating null wide character
25258      was reached or because an encoding error occurred.
25259 13   If there is a runtime-constraint violation, then wcsrtombs_s does the following. If
25260      retval is not a null pointer, then wcsrtombs_s sets *retval to (size_t)(-1).
25261      If dst is not a null pointer and dstmax is greater than zero and less than RSIZE_MAX,
25262      then wcsrtombs_s sets dst[0] to the null character.
25263      Description
25264 14   The wcsrtombs_s function converts a sequence of wide characters from the array
25265      indirectly pointed to by src into a sequence of corresponding multibyte characters that
25266      begins in the conversion state described by the object pointed to by ps. If dst is not a
25267      null pointer, the converted characters are then stored into the array pointed to by dst.
25268      Conversion continues up to and including a terminating null wide character, which is also
25269      stored. Conversion stops earlier in two cases:
25270      -- when a wide character is reached that does not correspond to a valid multibyte
25271        character;
25272      -- (if dst is not a null pointer) when the next multibyte character would exceed the
25273          limit of n total bytes to be stored into the array pointed to by dst. If the wide
25274          character being converted is the null wide character, then n is the lesser of len or
25275          dstmax. Otherwise, n is the lesser of len or dstmax-1.
25276      If the conversion stops without converting a null wide character and dst is not a null
25277      pointer, then a null character is stored into the array pointed to by dst immediately
25278      following any multibyte characters already stored. Each conversion takes place as if by a
25279      call to the wcrtomb function.435)
25280 15   If dst is not a null pointer, the pointer object pointed to by src is assigned either a null
25281      pointer (if conversion stopped due to reaching a terminating null wide character) or the
25282      address just past the last wide character converted (if any). If conversion stopped due to
25283      reaching a terminating null wide character, the resulting state described is the initial
25284      conversion state.
25285
25286
25287      435) If conversion stops because a terminating null wide character has been reached, the bytes stored
25288           include those necessary to reach the initial shift state immediately before the null byte. However, if
25289           the conversion stops before a terminating null wide character has been reached, the result will be null
25290           terminated, but might not end in the initial shift state.
25291
25292 [page 645]
25293
25294 16   Regardless of whether dst is or is not a null pointer, if the input conversion encounters a
25295      wide character that does not correspond to a valid multibyte character, an encoding error
25296      occurs: the wcsrtombs_s function stores the value (size_t)(-1) into *retval
25297      and the conversion state is unspecified. Otherwise, the wcsrtombs_s function stores
25298      into *retval the number of bytes in the resulting multibyte character sequence, not
25299      including the terminating null character (if any).
25300 17   All elements following the terminating null character (if any) written by wcsrtombs_s
25301      in the array of dstmax elements pointed to by dst take unspecified values when
25302      wcsrtombs_s returns.436)
25303 18   If copying takes place between objects that overlap, the objects take on unspecified
25304      values.
25305      Returns
25306 19   The wcsrtombs_s function returns zero if no runtime-constraint violation and no
25307      encoding error occurred. Otherwise, a nonzero value is returned.
25308
25309
25310
25311
25312      436) When len is not less than dstmax, the implementation might fill the array before discovering a
25313           runtime-constraint violation.
25314
25315 [page 646]
25316
25317                                                 Annex L
25318                                                (normative)
25319                                             Analyzability
25320     L.1 Scope
25321 1   This annex specifies optional behavior that can aid in the analyzability of C programs.
25322 2   An implementation that defines __STDC_ANALYZABLE__ shall conform to the
25323     specifications in this annex.437)
25324     L.2 Definitions
25325     L.2.1
25326 1   out-of-bounds store
25327     an (attempted) access (3.1) that, at run time, for a given computational state, would
25328     modify (or, for an object declared volatile, fetch) one or more bytes that lie outside
25329     the bounds permitted by this Standard.
25330     L.2.2
25331 1   bounded undefined behavior
25332     undefined behavior (3.4.3) that does not perform an out-of-bounds store.
25333 2   NOTE 1    The behavior might perform a trap.
25334
25335 3   NOTE 2    Any values produced or stored might be indeterminate values.
25336
25337     L.2.3
25338 1   critical undefined behavior
25339     undefined behavior that is not bounded undefined behavior.
25340 2   NOTE     The behavior might perform an out-of-bounds store or perform a trap.
25341
25342
25343
25344
25345     437) Implementations that do not define __STDC_ANALYZABLE__ are not required to conform to these
25346          specifications.
25347
25348 [page 647]
25349
25350     L.3 Requirements
25351 1   If the program performs a trap (3.19.5), the implementation is permitted to invoke a
25352     runtime-constraint handler. Any such semantics are implementation-defined.
25353 2   All undefined behavior shall be limited to bounded undefined behavior, except for the
25354     following which are permitted to result in critical undefined behavior:
25355     -- An object is referred to outside of its lifetime (6.2.4).
25356     -- An lvalue does not designate an object when evaluated (6.3.2.1).
25357     -- A pointer is used to call a function whose type is not compatible with the referenced
25358       type (6.3.2.3).
25359     -- The operand of the unary * operator has an invalid value (6.5.3.2).
25360     -- Addition or subtraction of a pointer into, or just beyond, an array object and an
25361       integer type produces a result that points just beyond the array object and is used as
25362       the operand of a unary * operator that is evaluated (6.5.6).
25363     -- An argument to a library function has an invalid value or a type not expected by a
25364       function with variable number of arguments (7.1.4).
25365     -- The value of a pointer that refers to space deallocated by a call to the free or realloc
25366       function is used (7.22.3).
25367     -- A string or wide string utility function is instructed to access an array beyond the end
25368       of an object (7.23.1, 7.28.4).
25369
25370
25371
25372
25373 [page 648]
25374
25375
25376                                    Bibliography
25377   1.    ''The C Reference Manual'' by Dennis M. Ritchie, a version of which was
25378         published in The C Programming Language by Brian W. Kernighan and Dennis
25379         M. Ritchie, Prentice-Hall, Inc., (1978). Copyright owned by AT&T.
25380   2.    1984 /usr/group Standard by the /usr/group Standards Committee, Santa Clara,
25381         California, USA, November 1984.
25382   3.    ANSI X3/TR-1-82 (1982), American National Dictionary for Information
25383         Processing Systems, Information Processing Systems Technical Report.
25384   4.    ANSI/IEEE 754-1985, American National Standard for Binary Floating-Point
25385         Arithmetic.
25386   5.    ANSI/IEEE 854-1988, American National Standard for Radix-Independent
25387         Floating-Point Arithmetic.
25388   6.    IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems,
25389         second edition (previously designated IEC 559:1989).
25390   7.    ISO 31-11:1992, Quantities and units -- Part 11: Mathematical signs and
25391         symbols for use in the physical sciences and technology.
25392   8.    ISO/IEC 646:1991, Information technology -- ISO 7-bit coded character set for
25393         information interchange.
25394   9.    ISO/IEC 2382-1:1993, Information technology -- Vocabulary -- Part 1:
25395         Fundamental terms.
25396  10.    ISO 4217:1995, Codes for the representation of currencies and funds.
25397  11.    ISO 8601:1988, Data elements and interchange formats -- Information
25398         interchange -- Representation of dates and times.
25399  12.    ISO/IEC 9899:1990, Programming languages -- C.
25400  13.    ISO/IEC 9899/COR1:1994, Technical Corrigendum 1.
25401  14.    ISO/IEC 9899/COR2:1996, Technical Corrigendum 2.
25402  15.    ISO/IEC 9899/AMD1:1995, Amendment 1 to ISO/IEC 9899:1990 C Integrity.
25403  16.    ISO/IEC 9899:1999, Programming languages -- C.
25404  17.    ISO/IEC 9899:1999/Cor.1:2001, Technical Corrigendum 1.
25405  18.    ISO/IEC 9899:1999/Cor.2:2004, Technical Corrigendum 2.
25406  19.    ISO/IEC 9899:1999/Cor.3:2007, Technical Corrigendum 3.
25407
25408
25409
25410 [page 649]
25411
25412  20.   ISO/IEC 9945-2:1993, Information technology -- Portable Operating System
25413        Interface (POSIX) -- Part 2: Shell and Utilities.
25414  21.   ISO/IEC TR 10176:1998, Information technology -- Guidelines for the
25415        preparation of programming language standards.
25416  22.   ISO/IEC 10646-1:1993, Information technology -- Universal Multiple-Octet
25417        Coded Character Set (UCS) -- Part 1: Architecture and Basic Multilingual Plane.
25418  23.   ISO/IEC 10646-1/COR1:1996,         Technical       Corrigendum       1      to
25419        ISO/IEC 10646-1:1993.
25420  24.   ISO/IEC 10646-1/COR2:1998,         Technical       Corrigendum       2      to
25421        ISO/IEC 10646-1:1993.
25422  25.   ISO/IEC 10646-1/AMD1:1996, Amendment 1 to ISO/IEC 10646-1:1993
25423        Transformation Format for 16 planes of group 00 (UTF-16).
25424  26.   ISO/IEC 10646-1/AMD2:1996, Amendment 2 to ISO/IEC 10646-1:1993 UCS
25425        Transformation Format 8 (UTF-8).
25426  27.   ISO/IEC 10646-1/AMD3:1996, Amendment 3 to ISO/IEC 10646-1:1993.
25427  28.   ISO/IEC 10646-1/AMD4:1996, Amendment 4 to ISO/IEC 10646-1:1993.
25428  29.   ISO/IEC 10646-1/AMD5:1998, Amendment 5 to ISO/IEC 10646-1:1993 Hangul
25429        syllables.
25430  30.   ISO/IEC 10646-1/AMD6:1997,       Amendment     6   to   ISO/IEC 10646-1:1993
25431        Tibetan.
25432  31.   ISO/IEC 10646-1/AMD7:1997, Amendment 7 to ISO/IEC 10646-1:1993 33
25433        additional characters.
25434  32.   ISO/IEC 10646-1/AMD8:1997, Amendment 8 to ISO/IEC 10646-1:1993.
25435  33.   ISO/IEC 10646-1/AMD9:1997,       Amendment     9   to   ISO/IEC 10646-1:1993
25436        Identifiers for characters.
25437  34.   ISO/IEC 10646-1/AMD10:1998, Amendment 10 to ISO/IEC 10646-1:1993
25438        Ethiopic.
25439  35.   ISO/IEC 10646-1/AMD11:1998, Amendment 11 to ISO/IEC 10646-1:1993
25440        Unified Canadian Aboriginal Syllabics.
25441  36.   ISO/IEC 10646-1/AMD12:1998, Amendment 12 to ISO/IEC 10646-1:1993
25442        Cherokee.
25443  37.   ISO/IEC 10967-1:1994, Information technology -- Language independent
25444        arithmetic -- Part 1: Integer and floating point arithmetic.
25445
25446
25447 [page 650]
25448
25449  38.    ISO/IEC TR 19769:2004, Information technology -- Programming languages,
25450         their environments and system software interfaces -- Extensions for the
25451         programming language C to support new character data types.
25452  39.    ISO/IEC TR 24731-1:2007, Information technology -- Programming languages,
25453         their environments and system software interfaces -- Extensions to the C library
25454         -- Part 1: Bounds-checking interfaces.
25455
25456
25457
25458
25459 [page 651]
25460
25461
25462
25463 [page 652]
25464
25465
25466 Index
25467 [^ x ^], 3.20                                                    , (comma operator), 5.1.2.4, 6.5.17
25468                                                                , (comma punctuator), 6.5.2, 6.7, 6.7.2.1, 6.7.2.2,
25469 [_ x _], 3.21                                                         6.7.2.3, 6.7.9
25470 ! (logical negation operator), 6.5.3.3                         - (subtraction operator), 6.2.6.2, 6.5.6, F.3, G.5.2
25471 != (inequality operator), 6.5.9                                - (unary minus operator), 6.5.3.3, F.3
25472 # operator, 6.10.3.2                                           -- (postfix decrement operator), 6.3.2.1, 6.5.2.4
25473 # preprocessing directive, 6.10.7                              -- (prefix decrement operator), 6.3.2.1, 6.5.3.1
25474 # punctuator, 6.10                                             -= (subtraction assignment operator), 6.5.16.2
25475 ## operator, 6.10.3.3                                          -> (structure/union pointer operator), 6.5.2.3
25476 #define preprocessing directive, 6.10.3                        . (structure/union member operator), 6.3.2.1,
25477 #elif preprocessing directive, 6.10.1                               6.5.2.3
25478 #else preprocessing directive, 6.10.1                          . punctuator, 6.7.9
25479 #endif preprocessing directive, 6.10.1                         ... (ellipsis punctuator), 6.5.2.2, 6.7.6.3, 6.10.3
25480 #error preprocessing directive, 4, 6.10.5                      / (division operator), 6.2.6.2, 6.5.5, F.3, G.5.1
25481 #if preprocessing directive, 5.2.4.2.1, 5.2.4.2.2,             /* */ (comment delimiters), 6.4.9
25482      6.10.1, 7.1.4                                             // (comment delimiter), 6.4.9
25483 #ifdef preprocessing directive, 6.10.1                         /= (division assignment operator), 6.5.16.2
25484 #ifndef preprocessing directive, 6.10.1                        : (colon punctuator), 6.7.2.1
25485 #include preprocessing directive, 5.1.1.2,                     :> (alternative spelling of ]), 6.4.6
25486      6.10.2                                                    ; (semicolon punctuator), 6.7, 6.7.2.1, 6.8.3,
25487 #line preprocessing directive, 6.10.4                               6.8.5, 6.8.6
25488 #pragma preprocessing directive, 6.10.6                        < (less-than operator), 6.5.8
25489 #undef preprocessing directive, 6.10.3.5, 7.1.3,               <% (alternative spelling of {), 6.4.6
25490      7.1.4                                                     <: (alternative spelling of [), 6.4.6
25491 % (remainder operator), 6.2.6.2, 6.5.5                         << (left-shift operator), 6.2.6.2, 6.5.7
25492 %: (alternative spelling of #), 6.4.6                          <<= (left-shift assignment operator), 6.5.16.2
25493 %:%: (alternative spelling of ##), 6.4.6                       <= (less-than-or-equal-to operator), 6.5.8
25494 %= (remainder assignment operator), 6.5.16.2                   <assert.h> header, 7.2
25495 %> (alternative spelling of }), 6.4.6                          <complex.h> header, 5.2.4.2.2, 6.10.8.3, 7.1.2,
25496 & (address operator), 6.3.2.1, 6.5.3.2                              7.3, 7.24, 7.30.1, G.6, J.5.17
25497 & (bitwise AND operator), 6.2.6.2, 6.5.10                      <ctype.h> header, 7.4, 7.30.2
25498 && (logical AND operator), 5.1.2.4, 6.5.13                     <errno.h> header, 7.5, 7.30.3, K.3.2
25499 &= (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,
25500 ' ' (space character), 5.1.1.2, 5.2.1, 6.4, 7.4.1.3,                H
25501      7.4.1.10, 7.29.2.1.3                                      <float.h> header, 4, 5.2.4.2.2, 7.7, 7.22.1.3,
25502 ( ) (cast operator), 6.5.4                                          7.28.4.1.1
25503 ( ) (function-call operator), 6.5.2.2                          <inttypes.h> header, 7.8, 7.30.4
25504 ( ) (parentheses punctuator), 6.7.6.3, 6.8.4, 6.8.5            <iso646.h> header, 4, 7.9
25505 ( ){ } (compound-literal operator), 6.5.2.5                    <limits.h> header, 4, 5.2.4.2.1, 6.2.5, 7.10
25506 * (asterisk punctuator), 6.7.6.1, 6.7.6.2                      <locale.h> header, 7.11, 7.30.5
25507 * (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,
25508 * (multiplication operator), 6.2.6.2, 6.5.5, F.3,                   F.10, J.5.17
25509      G.5.1                                                     <setjmp.h> header, 7.13
25510 *= (multiplication assignment operator), 6.5.16.2              <signal.h> header, 7.14, 7.30.6
25511 + (addition operator), 6.2.6.2, 6.5.2.1, 6.5.3.2,              <stdalign.h> header, 4, 7.15
25512      6.5.6, F.3, G.5.2                                         <stdarg.h> header, 4, 6.7.6.3, 7.16
25513 + (unary plus operator), 6.5.3.3                               <stdatomic.h> header, 6.10.8.3, 7.1.2, 7.17
25514 ++ (postfix increment operator), 6.3.2.1, 6.5.2.4               <stdbool.h> header, 4, 7.18, 7.30.7, H
25515 ++ (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,
25516 += (addition assignment operator), 6.5.16.2
25517 [page 653]
25518
25519      6.4.5, 6.5.3.4, 6.5.6, 7.19, K.3.3                      \x hexadecimal digits (hexadecimal-character
25520 <stdint.h> header, 4, 5.2.4.2, 6.10.1, 7.8,                       escape sequence), 6.4.4.4
25521      7.20, 7.30.8, K.3.3, K.3.4                              ^ (bitwise exclusive OR operator), 6.2.6.2, 6.5.11
25522 <stdio.h> header, 5.2.4.2.2, 7.21, 7.30.9, F,                ^= (bitwise exclusive OR assignment operator),
25523      K.3.5                                                        6.5.16.2
25524 <stdlib.h> header, 5.2.4.2.2, 7.22, 7.30.10, F,              __alignas_is_defined macro, 7.15
25525      K.3.1.4, K.3.6                                          __bool_true_false_are_defined
25526 <string.h> header, 7.23, 7.30.11, K.3.7                           macro, 7.18
25527 <tgmath.h> header, 7.24, G.7                                 __cplusplus macro, 6.10.8
25528 <threads.h> header, 6.10.8.3, 7.1.2, 7.25                    __DATE__ macro, 6.10.8.1
25529 <time.h> header, 7.26, K.3.8                                 __FILE__ macro, 6.10.8.1, 7.2.1.1
25530 <uchar.h> header, 6.4.4.4, 6.4.5, 7.27                       __func__ identifier, 6.4.2.2, 7.2.1.1
25531 <wchar.h> header, 5.2.4.2.2, 7.21.1, 7.28,                   __LINE__ macro, 6.10.8.1, 7.2.1.1
25532      7.30.12, F, K.3.9                                       __STDC_, 6.11.9
25533 <wctype.h> header, 7.29, 7.30.13                             __STDC__ macro, 6.10.8.1
25534 = (equal-sign punctuator), 6.7, 6.7.2.2, 6.7.9               __STDC_ANALYZABLE__ macro, 6.10.8.3, L.1
25535 = (simple assignment operator), 6.5.16.1                     __STDC_HOSTED__ macro, 6.10.8.1
25536 == (equality operator), 6.5.9                                __STDC_IEC_559__ macro, 6.10.8.3, F.1
25537 > (greater-than operator), 6.5.8                             __STDC_IEC_559_COMPLEX__ macro,
25538 >= (greater-than-or-equal-to operator), 6.5.8                     6.10.8.3, G.1
25539 >> (right-shift operator), 6.2.6.2, 6.5.7                    __STDC_ISO_10646__ macro, 6.10.8.2
25540 >>= (right-shift assignment operator), 6.5.16.2              __STDC_LIB_EXT1__ macro, 6.10.8.3, K.2
25541 ? : (conditional operator), 5.1.2.4, 6.5.15                  __STDC_MB_MIGHT_NEQ_WC__ macro,
25542 ?? (trigraph sequences), 5.2.1.1                                  6.10.8.2, 7.19
25543 [ ] (array subscript operator), 6.5.2.1, 6.5.3.2             __STDC_NO_COMPLEX__ macro, 6.10.8.3,
25544 [ ] (brackets punctuator), 6.7.6.2, 6.7.9                         7.3.1
25545 \ (backslash character), 5.1.1.2, 5.2.1, 6.4.4.4             __STDC_NO_THREADS__ macro, 6.10.8.3,
25546 \ (escape character), 6.4.4.4                                     7.17.1, 7.25.1
25547 \" (double-quote escape sequence), 6.4.4.4,                  __STDC_NO_VLA__ macro, 6.10.8.3
25548      6.4.5, 6.10.9                                           __STDC_UTF_16__ macro, 6.10.8.2
25549 \\ (backslash escape sequence), 6.4.4.4, 6.10.9              __STDC_UTF_32__ macro, 6.10.8.2
25550 \' (single-quote escape sequence), 6.4.4.4, 6.4.5            __STDC_VERSION__ macro, 6.10.8.1
25551 \0 (null character), 5.2.1, 6.4.4.4, 6.4.5                   __STDC_WANT_LIB_EXT1__ macro, K.3.1.1
25552   padding of binary stream, 7.21.2                           __TIME__ macro, 6.10.8.1
25553 \? (question-mark escape sequence), 6.4.4.4                  __VA_ARGS__ identifier, 6.10.3, 6.10.3.1
25554 \a (alert escape sequence), 5.2.2, 6.4.4.4                   _Alignas, 6.7.5
25555 \b (backspace escape sequence), 5.2.2, 6.4.4.4               _Atomic type qualifier, 6.7.2, 6.7.3
25556 \f (form-feed escape sequence), 5.2.2, 6.4.4.4,              _Atomic-qualified type, 6.2.5, 6.2.6.1, 6.5.2.3,
25557      7.4.1.10                                                     6.5.2.4, 6.5.16.2, 6.7.2, 6.7.3
25558 \n (new-line 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,
25559      7.4.1.10                                                     F.4
25560 \octal digits (octal-character escape sequence),             _Bool type conversions, 6.3.1.2
25561      6.4.4.4                                                 _Complex types, 6.2.5, 6.7.2, 7.3.1, G
25562 \r (carriage-return escape sequence), 5.2.2,                 _Complex_I macro, 7.3.1
25563      6.4.4.4, 7.4.1.10                                       _Exit function, 7.22.4.5, 7.22.4.7
25564 \t (horizontal-tab escape sequence), 5.2.2,                  _Imaginary keyword, G.2
25565      6.4.4.4, 7.4.1.3, 7.4.1.10, 7.29.2.1.3                  _Imaginary types, 7.3.1, G
25566 \U (universal character names), 6.4.3                        _Imaginary_I macro, 7.3.1, G.6
25567 \u (universal character names), 6.4.3                        _IOFBF macro, 7.21.1, 7.21.5.5, 7.21.5.6
25568 \v (vertical-tab escape sequence), 5.2.2, 6.4.4.4,           _IOLBF macro, 7.21.1, 7.21.5.6
25569      7.4.1.10                                                _IONBF macro, 7.21.1, 7.21.5.5, 7.21.5.6
25570
25571 [page 654]
25572
25573 _Noreturn, 6.7.4                                             alignment specifier, 6.7.5
25574 _Pragma operator, 5.1.1.2, 6.10.9                            alignof operator, 6.5.3, 6.5.3.4
25575 _Static_assert, 6.7.10, 7.2                                  allocated storage, order and contiguity, 7.22.3
25576 _Thread_local storage-class specifier, 6.2.4,                 and macro, 7.9
25577      6.7.1                                                   AND operators
25578 { } (braces punctuator), 6.7.2.2, 6.7.2.3, 6.7.9,               bitwise (&), 6.2.6.2, 6.5.10
25579      6.8.2                                                      bitwise assignment (&=), 6.5.16.2
25580 { } (compound-literal operator), 6.5.2.5                        logical (&&), 5.1.2.4, 6.5.13
25581 | (bitwise inclusive OR operator), 6.2.6.2, 6.5.12           and_eq macro, 7.9
25582 |= (bitwise inclusive OR assignment operator),               anonymous structure, 6.7.2.1
25583      6.5.16.2                                                anonymous union, 6.7.2.1
25584 || (logical OR operator), 5.1.2.4, 6.5.14                    ANSI/IEEE 754, F.1
25585 ~ (bitwise complement operator), 6.2.6.2, 6.5.3.3            ANSI/IEEE 854, F.1
25586                                                              argc (main function parameter), 5.1.2.2.1
25587 abort function, 7.2.1.1, 7.14.1.1, 7.21.3,                   argument, 3.3
25588       7.22.4.1, 7.25.3.6, K.3.6.1.2                             array, 6.9.1
25589 abort_handler_s function, K.3.6.1.2                             default promotions, 6.5.2.2
25590 abs function, 7.22.6.1                                          function, 6.5.2.2, 6.9.1
25591 absolute-value functions                                        macro, substitution, 6.10.3.1
25592    complex, 7.3.8, G.6.4                                     argument, complex, 7.3.9.1
25593    integer, 7.8.2.1, 7.22.6.1                                argv (main function parameter), 5.1.2.2.1
25594    real, 7.12.7, F.10.4                                      arithmetic constant expression, 6.6
25595 abstract declarator, 6.7.7                                   arithmetic conversions, usual, see usual arithmetic
25596 abstract machine, 5.1.2.3                                          conversions
25597 access, 3.1, 6.7.3, L.2.1                                    arithmetic operators
25598 accuracy, see floating-point accuracy                            additive, 6.2.6.2, 6.5.6, G.5.2
25599 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
25600 acos type-generic macro, 7.24                                   increment and decrement, 6.5.2.4, 6.5.3.1
25601 acosh functions, 7.12.5.1, F.10.2.1                             multiplicative, 6.2.6.2, 6.5.5, G.5.1
25602 acosh type-generic macro, 7.24                                  shift, 6.2.6.2, 6.5.7
25603 acquire fence, 7.17.4                                           unary, 6.5.3.3
25604 acquire operation, 5.1.2.4                                   arithmetic types, 6.2.5
25605 active position, 5.2.2                                       arithmetic, pointer, 6.5.6
25606 actual argument, 3.3                                         array
25607 actual parameter (deprecated), 3.3                              argument, 6.9.1
25608 addition assignment operator (+=), 6.5.16.2                     declarator, 6.7.6.2
25609 addition operator (+), 6.2.6.2, 6.5.2.1, 6.5.3.2,               initialization, 6.7.9
25610       6.5.6, F.3, G.5.2                                         multidimensional, 6.5.2.1
25611 additive expressions, 6.5.6, G.5.2                              parameter, 6.9.1
25612 address constant, 6.6                                           storage order, 6.5.2.1
25613 address operator (&), 6.3.2.1, 6.5.3.2                          subscript operator ([ ]), 6.5.2.1, 6.5.3.2
25614 address-free, 7.17.5                                            subscripting, 6.5.2.1
25615 aggregate initialization, 6.7.9                                 type, 6.2.5
25616 aggregate types, 6.2.5                                          type conversion, 6.3.2.1
25617 alert escape sequence (\a), 5.2.2, 6.4.4.4                      variable length, 6.7.6, 6.7.6.2, 6.10.8.3
25618 aliasing, 6.5                                                arrow operator (->), 6.5.2.3
25619 alignas macro, 7.15                                          as-if rule, 5.1.2.3
25620 aligned_alloc function, 7.22.3, 7.22.3.1                     ASCII code set, 5.2.1.1
25621 alignment, 3.2, 6.2.8, 7.22.3.1                              asctime function, 7.26.3.1
25622    pointer, 6.2.5, 6.3.2.3                                   asctime_s function, K.3.8.2, K.3.8.2.1
25623    structure/union member, 6.7.2.1                           asin functions, 7.12.4.2, F.10.1.2
25624
25625 [page 655]
25626
25627 asin type-generic macro, 7.24, G.7                       atomic_is_lock_free generic function,
25628 asinh functions, 7.12.5.2, F.10.2.2                          7.17.5.1
25629 asinh type-generic macro, 7.24, G.7                      ATOMIC_LLONG_LOCK_FREE macro, 7.17.1
25630 asm keyword, J.5.10                                      atomic_load generic functions, 7.17.7.2
25631 assert macro, 7.2.1.1                                    ATOMIC_LONG_LOCK_FREE macro, 7.17.1
25632 assert.h header, 7.2                                     ATOMIC_SHORT_LOCK_FREE macro, 7.17.1
25633 assignment                                               atomic_signal_fence function, 7.17.4.2
25634    compound, 6.5.16.2                                    atomic_store generic functions, 7.17.7.1
25635    conversion, 6.5.16.1                                  atomic_thread_fence function, 7.17.4.1
25636    expression, 6.5.16                                    ATOMIC_VAR_INIT macro, 7.17.2.1
25637    operators, 6.3.2.1, 6.5.16                            ATOMIC_WCHAR_T_LOCK_FREE macro, 7.17.1
25638    simple, 6.5.16.1                                      atomics header, 7.17
25639 associativity of operators, 6.5                          auto storage-class specifier, 6.7.1, 6.9
25640 asterisk punctuator (*), 6.7.6.1, 6.7.6.2                automatic storage duration, 5.2.3, 6.2.4
25641 at_quick_exit function, 7.22.4.2, 7.22.4.3,
25642      7.22.4.4, 7.22.4.5, 7.22.4.7                        backslash character (\), 5.1.1.2, 5.2.1, 6.4.4.4
25643 atan functions, 7.12.4.3, F.10.1.3                       backslash escape sequence (\\), 6.4.4.4, 6.10.9
25644 atan type-generic macro, 7.24, G.7                       backspace escape sequence (\b), 5.2.2, 6.4.4.4
25645 atan2 functions, 7.12.4.4, F.10.1.4                      basic character set, 3.6, 3.7.2, 5.2.1
25646 atan2 type-generic macro, 7.24                           basic types, 6.2.5
25647 atanh functions, 7.12.5.3, F.10.2.3                      behavior, 3.4
25648 atanh type-generic macro, 7.24, G.7                      binary streams, 7.21.2, 7.21.7.10, 7.21.9.2,
25649 atexit function, 7.22.4.2, 7.22.4.3, 7.22.4.4,                 7.21.9.4
25650      7.22.4.5, 7.22.4.7, J.5.13                          bit, 3.5
25651 atof function, 7.22.1, 7.22.1.1                             high order, 3.6
25652 atoi function, 7.22.1, 7.22.1.2                             low order, 3.6
25653 atol function, 7.22.1, 7.22.1.2                          bit-field, 6.7.2.1
25654 atoll function, 7.22.1, 7.22.1.2                         bitand macro, 7.9
25655 atomic lock-free macros, 7.17.1, 7.17.5                  bitor macro, 7.9
25656 atomic operations, 5.1.2.4                               bitwise operators, 6.5
25657 atomic types, 5.1.2.3, 6.10.8.3, 7.17.6                     AND, 6.2.6.2, 6.5.10
25658 atomic_address type, 7.17.1, 7.17.6                         AND assignment (&=), 6.5.16.2
25659 ATOMIC_ADDRESS_LOCK_FREE macro, 7.17.1                      complement (~), 6.2.6.2, 6.5.3.3
25660 atomic_bool type, 7.17.1, 7.17.6                            exclusive OR, 6.2.6.2, 6.5.11
25661 ATOMIC_CHAR16_T_LOCK_FREE macro,                            exclusive OR assignment (^=), 6.5.16.2
25662      7.17.1                                                 inclusive OR, 6.2.6.2, 6.5.12
25663 ATOMIC_CHAR32_T_LOCK_FREE macro,                            inclusive OR assignment (|=), 6.5.16.2
25664      7.17.1                                                 shift, 6.2.6.2, 6.5.7
25665 ATOMIC_CHAR_LOCK_FREE macro, 7.17.1                      blank character, 7.4.1.3
25666 atomic_compare_exchange generic                          block, 6.8, 6.8.2, 6.8.4, 6.8.5
25667      functions, 7.17.7.4                                 block scope, 6.2.1
25668 atomic_exchange generic functions, 7.17.7.3              block structure, 6.2.1
25669 atomic_fetch and modify generic functions,               bold type convention, 6.1
25670      7.17.7.5                                            bool macro, 7.18
25671 atomic_flag type, 7.17.1, 7.17.8                         boolean type, 6.3.1.2
25672 atomic_flag_clear functions, 7.17.8.2                    boolean type conversion, 6.3.1.1, 6.3.1.2
25673 ATOMIC_FLAG_INIT macro, 7.17.1, 7.17.8                   bounded undefined behavior, L.2.2
25674 atomic_flag_test_and_set functions,                      braces punctuator ({ }), 6.7.2.2, 6.7.2.3, 6.7.9,
25675      7.17.8.1                                                  6.8.2
25676 atomic_init generic function, 7.17.2.2                   brackets operator ([ ]), 6.5.2.1, 6.5.3.2
25677 ATOMIC_INT_LOCK_FREE macro, 7.17.1                       brackets punctuator ([ ]), 6.7.6.2, 6.7.9
25678
25679 [page 656]
25680
25681 branch cuts, 7.3.3                                                type-generic macro for, 7.24
25682 break statement, 6.8.6.3                                       ccosh functions, 7.3.6.4, G.6.2.4
25683 broken-down time, 7.26.1, 7.26.2.3, 7.26.3,                       type-generic macro for, 7.24
25684      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
25685      K.3.8.2.1, K.3.8.2.3, K.3.8.2.4                           ceil type-generic macro, 7.24
25686 bsearch function, 7.22.5, 7.22.5.1                             cerf function, 7.30.1
25687 bsearch_s function, K.3.6.3, K.3.6.3.1                         cerfc function, 7.30.1
25688 btowc function, 7.28.6.1.1                                     cexp functions, 7.3.7.1, G.6.3.1
25689 BUFSIZ macro, 7.21.1, 7.21.2, 7.21.5.5                            type-generic macro for, 7.24
25690 byte, 3.6, 6.5.3.4                                             cexp2 function, 7.30.1
25691 byte input/output functions, 7.21.1                            cexpm1 function, 7.30.1
25692 byte-oriented stream, 7.21.2                                   char type, 6.2.5, 6.3.1.1, 6.7.2, K.3.5.3.2,
25693                                                                      K.3.9.1.2
25694 C program, 5.1.1.1                                             char type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,
25695 c16rtomb function, 7.27.1.2                                          6.3.1.8
25696 c32rtomb function, 7.27.1.4                                    char16_t type, 6.4.4.4, 6.4.5, 6.10.8.2, 7.27
25697 cabs functions, 7.3.8.1, G.6                                   char32_t type, 6.4.4.4, 6.4.5, 6.10.8.2, 7.27
25698   type-generic macro for, 7.24                                 CHAR_BIT macro, 5.2.4.2.1, 6.7.2.1
25699 cacos functions, 7.3.5.1, G.6.1.1                              CHAR_MAX macro, 5.2.4.2.1, 7.11.2.1
25700   type-generic macro for, 7.24                                 CHAR_MIN macro, 5.2.4.2.1
25701 cacosh functions, 7.3.6.1, G.6.2.1                             character, 3.7, 3.7.1
25702   type-generic macro for, 7.24                                 character array initialization, 6.7.9
25703 calendar time, 7.26.1, 7.26.2.2, 7.26.2.3, 7.26.2.4,           character case mapping functions, 7.4.2
25704       7.26.3.2, 7.26.3.3, 7.26.3.4, K.3.8.2.2,                    wide character, 7.29.3.1
25705       K.3.8.2.3, K.3.8.2.4                                           extensible, 7.29.3.2
25706 call by value, 6.5.2.2                                         character classification functions, 7.4.1
25707 call_once function, 7.25.1, 7.25.2.1                              wide character, 7.29.2.1
25708 calloc function, 7.22.3, 7.22.3.2                                    extensible, 7.29.2.2
25709 carg functions, 7.3.9.1, G.6                                   character constant, 5.1.1.2, 5.2.1, 6.4.4.4
25710 carg type-generic macro, 7.24, G.7                             character display semantics, 5.2.2
25711 carriage-return escape sequence (\r), 5.2.2,                   character handling header, 7.4, 7.11.1.1
25712       6.4.4.4, 7.4.1.10                                        character input/output functions, 7.21.7, K.3.5.4
25713 carries a dependency, 5.1.2.4                                     wide character, 7.28.3
25714 case label, 6.8.1, 6.8.4.2                                     character sets, 5.2.1
25715 case mapping functions                                         character string literal, see string literal
25716   character, 7.4.2                                             character type conversion, 6.3.1.1
25717   wide character, 7.29.3.1                                     character types, 6.2.5, 6.7.9
25718       extensible, 7.29.3.2                                     cimag functions, 7.3.9.2, 7.3.9.5, G.6
25719 casin functions, 7.3.5.2, G.6                                  cimag type-generic macro, 7.24, G.7
25720   type-generic macro for, 7.24                                 cis function, G.6
25721 casinh functions, 7.3.6.2, G.6.2.2                             classification functions
25722   type-generic macro for, 7.24                                    character, 7.4.1
25723 cast expression, 6.5.4                                            floating-point, 7.12.3
25724 cast operator (( )), 6.5.4                                        wide character, 7.29.2.1
25725 catan functions, 7.3.5.3, G.6                                        extensible, 7.29.2.2
25726   type-generic macro for, 7.24                                 clearerr function, 7.21.10.1
25727 catanh functions, 7.3.6.3, G.6.2.3                             clgamma function, 7.30.1
25728   type-generic macro for, 7.24                                 clock function, 7.26.2.1
25729 cbrt functions, 7.12.7.1, F.10.4.1                             clock_t type, 7.26.1, 7.26.2.1
25730 cbrt type-generic macro, 7.24                                  CLOCKS_PER_SEC macro, 7.26.1, 7.26.2.1
25731 ccos functions, 7.3.5.4, G.6                                   clog functions, 7.3.7.2, G.6.3.2
25732
25733 [page 657]
25734
25735   type-generic macro for, 7.24                                  string, 7.23.3, K.3.7.2
25736 clog10 function, 7.30.1                                         wide string, 7.28.4.3, K.3.9.2.2
25737 clog1p function, 7.30.1                                       concatenation, preprocessing, see preprocessing
25738 clog2 function, 7.30.1                                             concatenation
25739 CMPLX macros, 7.3.9.3                                         conceptual models, 5.1
25740 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,
25741      7.25.3.6                                                      7.1.2, F.1, G.1, K.2, L.1
25742 cnd_destroy function, 7.25.3.2                                conditional inclusion, 6.10.1
25743 cnd_init function, 7.25.3.3                                   conditional operator (? :), 5.1.2.4, 6.5.15
25744 cnd_signal function, 7.25.3.4, 7.25.3.5,                      conflict, 5.1.2.4
25745      7.25.3.6                                                 conformance, 4
25746 cnd_t type, 7.25.1                                            conj functions, 7.3.9.4, G.6
25747 cnd_timedwait function, 7.25.3.5                              conj type-generic macro, 7.24
25748 cnd_wait function, 7.25.3.3, 7.25.3.6                         const type qualifier, 6.7.3
25749 collating sequences, 5.2.1                                    const-qualified type, 6.2.5, 6.3.2.1, 6.7.3
25750 colon punctuator (:), 6.7.2.1                                 constant expression, 6.6, F.8.4
25751 comma operator (,), 5.1.2.4, 6.5.17                           constants, 6.4.4
25752 comma punctuator (,), 6.5.2, 6.7, 6.7.2.1, 6.7.2.2,             as primary expression, 6.5.1
25753      6.7.2.3, 6.7.9                                             character, 6.4.4.4
25754 command processor, 7.22.4.8                                     enumeration, 6.2.1, 6.4.4.3
25755 comment delimiters (/* */ and //), 6.4.9                        floating, 6.4.4.2
25756 comments, 5.1.1.2, 6.4, 6.4.9                                   hexadecimal, 6.4.4.1
25757 common extensions, J.5                                          integer, 6.4.4.1
25758 common initial sequence, 6.5.2.3                                octal, 6.4.4.1
25759 common real type, 6.3.1.8                                     constraint, 3.8, 4
25760 common warnings, I                                            constraint_handler_t type, K.3.6
25761 comparison functions, 7.22.5, 7.22.5.1, 7.22.5.2,             consume operation, 5.1.2.4
25762      K.3.6.3, K.3.6.3.1, K.3.6.3.2                            content of structure/union/enumeration, 6.7.2.3
25763   string, 7.23.4                                              contiguity of allocated storage, 7.22.3
25764   wide string, 7.28.4.4                                       continue statement, 6.8.6.2
25765 comparison macros, 7.12.14                                    contracted expression, 6.5, 7.12.2, F.7
25766 comparison, pointer, 6.5.8                                    control character, 5.2.1, 7.4
25767 compatible type, 6.2.7, 6.7.2, 6.7.3, 6.7.6                   control wide character, 7.29.2
25768 compl macro, 7.9                                              conversion, 6.3
25769 complement operator (~), 6.2.6.2, 6.5.3.3                       arithmetic operands, 6.3.1
25770 complete type, 6.2.5                                            array argument, 6.9.1
25771 complex macro, 7.3.1                                            array parameter, 6.9.1
25772 complex numbers, 6.2.5, G                                       arrays, 6.3.2.1
25773 complex type conversion, 6.3.1.6, 6.3.1.7                       boolean, 6.3.1.2
25774 complex type domain, 6.2.5                                      boolean, characters, and integers, 6.3.1.1
25775 complex types, 6.2.5, 6.7.2, 6.10.8.3, G                        by assignment, 6.5.16.1
25776 complex.h header, 5.2.4.2.2, 6.10.8.3, 7.1.2,                   by return statement, 6.8.6.4
25777      7.3, 7.24, 7.30.1, G.6, J.5.17                             complex types, 6.3.1.6
25778 compliance, see conformance                                     explicit, 6.3
25779 components of time, 7.26.1, K.3.8.1                             function, 6.3.2.1
25780 composite type, 6.2.7                                           function argument, 6.5.2.2, 6.9.1
25781 compound assignment, 6.5.16.2                                   function designators, 6.3.2.1
25782 compound literals, 6.5.2.5                                      function parameter, 6.9.1
25783 compound statement, 6.8.2                                       imaginary, G.4.1
25784 compound-literal operator (( ){ }), 6.5.2.5                     imaginary and complex, G.4.3
25785 concatenation functions                                         implicit, 6.3
25786
25787 [page 658]
25788
25789    lvalues, 6.3.2.1                                             csinh functions, 7.3.6.5, G.6.2.5
25790    pointer, 6.3.2.1, 6.3.2.3                                      type-generic macro for, 7.24
25791    real and complex, 6.3.1.7                                    csqrt functions, 7.3.8.3, G.6.4.2
25792    real and imaginary, G.4.2                                      type-generic macro for, 7.24
25793    real floating and integer, 6.3.1.4, F.3, F.4                  ctan functions, 7.3.5.6, G.6
25794    real floating types, 6.3.1.5, F.3                               type-generic macro for, 7.24
25795    signed and unsigned integers, 6.3.1.3                        ctanh functions, 7.3.6.6, G.6.2.6
25796    usual arithmetic, see usual arithmetic                         type-generic macro for, 7.24
25797          conversions                                            ctgamma function, 7.30.1
25798    void type, 6.3.2.2                                           ctime function, 7.26.3.2
25799 conversion functions                                            ctime_s function, K.3.8.2, K.3.8.2.2
25800    multibyte/wide character, 7.22.7, K.3.6.4                    ctype.h header, 7.4, 7.30.2
25801       extended, 7.28.6, K.3.9.3                                 current object, 6.7.9
25802       restartable, 7.27.1, 7.28.6.3, K.3.9.3.1                  CX_LIMITED_RANGE pragma, 6.10.6, 7.3.4
25803    multibyte/wide string, 7.22.8, K.3.6.5
25804       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,
25805    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,
25806       wide string, 7.8.2.4, 7.28.4.1                                 7.28.6.4
25807    single byte/wide character, 7.28.6.1                         data stream, see streams
25808    time, 7.26.3, K.3.8.2                                        date and time header, 7.26, K.3.8
25809       wide character, 7.28.5                                    Daylight Saving Time, 7.26.1
25810 conversion specifier, 7.21.6.1, 7.21.6.2, 7.28.2.1,              DBL_DECIMAL_DIG macro, 5.2.4.2.2
25811       7.28.2.2                                                  DBL_DIG macro, 5.2.4.2.2
25812 conversion state, 7.22.7, 7.27.1, 7.27.1.1,                     DBL_EPSILON macro, 5.2.4.2.2
25813       7.27.1.2, 7.27.1.3, 7.27.1.4, 7.28.6,                     DBL_HAS_SUBNORM macro, 5.2.4.2.2
25814       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
25815       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
25816       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
25817       K.3.9.3.2.2                                               DBL_MAX_EXP macro, 5.2.4.2.2
25818 conversion state functions, 7.28.6.2                            DBL_MIN macro, 5.2.4.2.2
25819 copying functions                                               DBL_MIN_10_EXP macro, 5.2.4.2.2
25820    string, 7.23.2, K.3.7.1                                      DBL_MIN_EXP macro, 5.2.4.2.2
25821    wide string, 7.28.4.2, K.3.9.2.1                             DBL_TRUE_MIN macro, 5.2.4.2.2
25822 copysign functions, 7.3.9.5, 7.12.11.1, F.3,                    decimal constant, 6.4.4.1
25823       F.10.8.1                                                  decimal digit, 5.2.1
25824 copysign type-generic macro, 7.24                               decimal-point character, 7.1.1, 7.11.2.1
25825 correctly rounded result, 3.9                                   DECIMAL_DIG macro, 5.2.4.2.2, 7.21.6.1,
25826 corresponding real type, 6.2.5                                       7.22.1.3, 7.28.2.1, 7.28.4.1.1, F.5
25827 cos functions, 7.12.4.5, F.10.1.5                               declaration specifiers, 6.7
25828 cos type-generic macro, 7.24, G.7                               declarations, 6.7
25829 cosh functions, 7.12.5.4, F.10.2.4                                function, 6.7.6.3
25830 cosh type-generic macro, 7.24, G.7                                pointer, 6.7.6.1
25831 cpow functions, 7.3.8.2, G.6.4.1                                  structure/union, 6.7.2.1
25832    type-generic macro for, 7.24                                   typedef, 6.7.8
25833 cproj functions, 7.3.9.5, G.6                                   declarator, 6.7.6
25834 cproj type-generic macro, 7.24                                    abstract, 6.7.7
25835 creal functions, 7.3.9.6, G.6                                   declarator type derivation, 6.2.5, 6.7.6
25836 creal type-generic macro, 7.24, G.7                             decrement operators, see arithmetic operators,
25837 critical undefined behavior, L.2.3                                    increment and decrement
25838 csin functions, 7.3.5.5, G.6                                    default argument promotions, 6.5.2.2
25839    type-generic macro for, 7.24                                 default initialization, 6.7.9
25840
25841 [page 659]
25842
25843 default label, 6.8.1, 6.8.4.2                                  elif preprocessing directive, 6.10.1
25844 define preprocessing directive, 6.10.3                         ellipsis punctuator (...), 6.5.2.2, 6.7.6.3, 6.10.3
25845 defined operator, 6.10.1, 6.10.8                               else preprocessing directive, 6.10.1
25846 definition, 6.7                                                 else statement, 6.8.4.1
25847    function, 6.9.1                                             empty statement, 6.8.3
25848 dependency-ordered before, 5.1.2.4                             encoding error, 7.21.3, 7.27.1.1, 7.27.1.2,
25849 derived declarator types, 6.2.5                                      7.27.1.3, 7.27.1.4, 7.28.3.1, 7.28.3.3,
25850 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,
25851 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,
25852 destringizing, 6.10.9                                                K.3.9.3.2.2
25853 device input/output, 5.1.2.3                                   end-of-file, 7.28.1
25854 diagnostic message, 3.10, 5.1.1.3                              end-of-file indicator, 7.21.1, 7.21.5.3, 7.21.7.1,
25855 diagnostics, 5.1.1.3                                                 7.21.7.5, 7.21.7.6, 7.21.7.10, 7.21.9.2,
25856 diagnostics header, 7.2                                              7.21.9.3, 7.21.10.1, 7.21.10.2, 7.28.3.1,
25857 difftime function, 7.26.2.2                                          7.28.3.10
25858 digit, 5.2.1, 7.4                                              end-of-file macro, see EOF macro
25859 digraphs, 6.4.6                                                end-of-line indicator, 5.2.1
25860 direct input/output functions, 7.21.8                          endif preprocessing directive, 6.10.1
25861 display device, 5.2.2                                          enum type, 6.2.5, 6.7.2, 6.7.2.2
25862 div function, 7.22.6.2                                         enumerated type, 6.2.5
25863 div_t type, 7.22                                               enumeration, 6.2.5, 6.7.2.2
25864 division assignment operator (/=), 6.5.16.2                    enumeration constant, 6.2.1, 6.4.4.3
25865 division operator (/), 6.2.6.2, 6.5.5, F.3, G.5.1              enumeration content, 6.7.2.3
25866 do statement, 6.8.5.2                                          enumeration members, 6.7.2.2
25867 documentation of implementation, 4                             enumeration specifiers, 6.7.2.2
25868 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
25869       7.12.5.1, 7.12.5.3, 7.12.6.5, 7.12.6.7,                  enumerator, 6.7.2.2
25870       7.12.6.8, 7.12.6.9, 7.12.6.10, 7.12.6.11,                environment, 5
25871       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
25872       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
25873 dot operator (.), 6.5.2.3                                      environmental considerations, 5.2
25874 double _Complex type, 6.2.5                                    environmental limits, 5.2.4, 7.13.1.1, 7.21.2,
25875 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,
25876       6.3.1.7, 6.3.1.8                                               7.22.4.3, 7.28.2.1, K.3.5.1.2
25877 double _Imaginary type, G.2                                    EOF macro, 7.4, 7.21.1, 7.21.5.1, 7.21.5.2,
25878 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,
25879       7.28.2.2, F.2                                                  7.21.6.14, 7.21.7.1, 7.21.7.3, 7.21.7.4,
25880 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,
25881       6.3.1.8                                                        7.21.7.10, 7.28.1, 7.28.2.2, 7.28.2.4,
25882 double-precision arithmetic, 5.1.2.3                                 7.28.2.6, 7.28.2.8, 7.28.2.10, 7.28.2.12,
25883 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,
25884       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,
25885 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,
25886                                                                      K.3.9.1.14
25887 EDOM macro, 7.5, 7.12.1, see also domain error                 equal-sign punctuator (=), 6.7, 6.7.2.2, 6.7.9
25888 effective type, 6.5                                            equal-to operator, see equality operator
25889 EILSEQ macro, 7.5, 7.21.3, 7.27.1.1, 7.27.1.2,                 equality expressions, 6.5.9
25890      7.27.1.3, 7.27.1.4, 7.28.3.1, 7.28.3.3,                   equality operator (==), 6.5.9
25891      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,
25892      see also encoding error                                         7.22.1.3, 7.22.1.4, 7.28.4.1.1, 7.28.4.1.2, see
25893 element type, 6.2.5                                                  also range error, pole error
25894
25895 [page 660]
25896
25897 erf functions, 7.12.8.1, F.10.5.1                               exp type-generic macro, 7.24
25898 erf type-generic macro, 7.24                                    exp2 functions, 7.12.6.2, F.10.3.2
25899 erfc functions, 7.12.8.2, F.10.5.2                              exp2 type-generic macro, 7.24
25900 erfc type-generic macro, 7.24                                   explicit conversion, 6.3
25901 errno macro, 7.1.3, 7.3.2, 7.5, 7.8.2.3, 7.8.2.4,               expm1 functions, 7.12.6.3, F.10.3.3
25902       7.12.1, 7.14.1.1, 7.21.3, 7.21.9.3, 7.21.10.4,            expm1 type-generic macro, 7.24
25903       7.22.1, 7.22.1.3, 7.22.1.4, 7.23.6.2, 7.27.1.1,           exponent part, 6.4.4.2
25904       7.27.1.2, 7.27.1.3, 7.27.1.4, 7.28.3.1,                   exponential functions
25905       7.28.3.3, 7.28.4.1.1, 7.28.4.1.2, 7.28.6.3.2,               complex, 7.3.7, G.6.3
25906       7.28.6.3.3, 7.28.6.4.1, 7.28.6.4.2, J.5.17,                 real, 7.12.6, F.10.3
25907       K.3.1.3, K.3.7.4.2                                        expression, 6.5
25908 errno.h header, 7.5, 7.30.3, K.3.2                                assignment, 6.5.16
25909 errno_t type, K.3.2, K.3.5, K.3.6, K.3.6.1.1,                     cast, 6.5.4
25910       K.3.7, K.3.8, K.3.9                                         constant, 6.6
25911 error                                                             evaluation, 5.1.2.3
25912    domain, see domain error                                       full, 6.8
25913    encoding, see encoding error                                   order of evaluation, see order of evaluation
25914    pole, see pole error                                           parenthesized, 6.5.1
25915    range, see range error                                         primary, 6.5.1
25916 error conditions, 7.12.1                                          unary, 6.5.3
25917 error functions, 7.12.8, F.10.5                                 expression statement, 6.8.3
25918 error indicator, 7.21.1, 7.21.5.3, 7.21.7.1,                    extended alignment, 6.2.8
25919       7.21.7.3, 7.21.7.5, 7.21.7.6, 7.21.7.7,                   extended character set, 3.7.2, 5.2.1, 5.2.1.2
25920       7.21.7.8, 7.21.9.2, 7.21.10.1, 7.21.10.3,                 extended characters, 5.2.1
25921       7.28.3.1, 7.28.3.3                                        extended integer types, 6.2.5, 6.3.1.1, 6.4.4.1,
25922 error preprocessing directive, 4, 6.10.5                             7.20
25923 error-handling functions, 7.21.10, 7.23.6.2,                    extended multibyte/wide character conversion
25924       K.3.7.4.2, K.3.7.4.3                                           utilities, 7.28.6, K.3.9.3
25925 escape character (\), 6.4.4.4                                   extensible wide character case mapping functions,
25926 escape sequences, 5.2.1, 5.2.2, 6.4.4.4, 6.11.4                      7.29.3.2
25927 evaluation format, 5.2.4.2.2, 6.4.4.2, 7.12                     extensible wide character classification functions,
25928 evaluation method, 5.2.4.2.2, 6.5, F.8.5                             7.29.2.2
25929 evaluation of expression, 5.1.2.3                               extern storage-class specifier, 6.2.2, 6.7.1
25930 evaluation order, see order of evaluation                       external definition, 6.9
25931 exceptional condition, 6.5                                      external identifiers, underscore, 7.1.3
25932 excess precision, 5.2.4.2.2, 6.3.1.5, 6.3.1.8,                  external linkage, 6.2.2
25933       6.8.6.4                                                   external name, 6.4.2.1
25934 excess range, 5.2.4.2.2, 6.3.1.5, 6.3.1.8, 6.8.6.4              external object definitions, 6.9.2
25935 exclusive OR operators
25936    bitwise (^), 6.2.6.2, 6.5.11                                 fabs functions, 7.12.7.2, F.3, F.10.4.2
25937    bitwise assignment (^=), 6.5.16.2                            fabs type-generic macro, 7.24, G.7
25938 executable program, 5.1.1.1                                     false macro, 7.18
25939 execution character set, 5.2.1                                  fclose function, 7.21.5.1
25940 execution environment, 5, 5.1.2, see also                       fdim functions, 7.12.12.1, F.10.9.1
25941       environmental limits                                      fdim type-generic macro, 7.24
25942 execution sequence, 5.1.2.3, 6.8                                FE_ALL_EXCEPT macro, 7.6
25943 exit function, 5.1.2.2.3, 7.21.3, 7.22, 7.22.4.4,               FE_DFL_ENV macro, 7.6
25944       7.22.4.5, 7.22.4.7                                        FE_DIVBYZERO macro, 7.6, 7.12, F.3
25945 EXIT_FAILURE macro, 7.22, 7.22.4.4                              FE_DOWNWARD macro, 7.6, F.3
25946 EXIT_SUCCESS macro, 7.22, 7.22.4.4                              FE_INEXACT macro, 7.6, F.3
25947 exp functions, 7.12.6.1, F.10.3.1                               FE_INVALID macro, 7.6, 7.12, F.3
25948
25949 [page 661]
25950
25951 FE_OVERFLOW macro, 7.6, 7.12, F.3                            float _Complex type, 6.2.5
25952 FE_TONEAREST macro, 7.6, F.3                                 float _Complex type conversion, 6.3.1.6,
25953 FE_TOWARDZERO macro, 7.6, F.3                                     6.3.1.7, 6.3.1.8
25954 FE_UNDERFLOW macro, 7.6, F.3                                 float _Imaginary type, G.2
25955 FE_UPWARD macro, 7.6, F.3                                    float type, 6.2.5, 6.4.4.2, 6.7.2, F.2
25956 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,
25957 fegetenv function, 7.6.4.1, 7.6.4.3, 7.6.4.4, F.3                 6.3.1.8
25958 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,
25959 fegetround function, 7.6, 7.6.3.1, F.3                            7.28.4.1.1
25960 feholdexcept function, 7.6.4.2, 7.6.4.3,                     float_t type, 7.12, J.5.6
25961      7.6.4.4, F.3                                            floating constant, 6.4.4.2
25962 fence, 5.1.2.4                                               floating suffix, f or F, 6.4.4.2
25963 fences, 7.17.4                                               floating type conversion, 6.3.1.4, 6.3.1.5, 6.3.1.7,
25964 fenv.h header, 5.1.2.3, 5.2.4.2.2, 7.6, 7.12, F, H                F.3, F.4
25965 FENV_ACCESS pragma, 6.10.6, 7.6.1, F.8, F.9,                 floating types, 6.2.5, 6.11.1
25966      F.10                                                    floating-point accuracy, 5.2.4.2.2, 6.4.4.2, 6.5,
25967 fenv_t type, 7.6                                                  7.22.1.3, F.5, see also contracted expression
25968 feof function, 7.21.10.2                                     floating-point arithmetic functions, 7.12, F.10
25969 feraiseexcept function, 7.6.2, 7.6.2.3, F.3                  floating-point classification functions, 7.12.3
25970 ferror function, 7.21.10.3                                   floating-point control mode, 7.6, F.8.6
25971 fesetenv function, 7.6.4.3, F.3                              floating-point environment, 7.6, F.8, F.8.6
25972 fesetexceptflag function, 7.6.2, 7.6.2.4, F.3                floating-point exception, 7.6, 7.6.2, F.10
25973 fesetround function, 7.6, 7.6.3.2, F.3                       floating-point number, 5.2.4.2.2, 6.2.5
25974 fetestexcept function, 7.6.2, 7.6.2.5, F.3                   floating-point rounding mode, 5.2.4.2.2
25975 feupdateenv function, 7.6.4.2, 7.6.4.4, F.3                  floating-point status flag, 7.6, F.8.6
25976 fexcept_t type, 7.6, F.3                                     floor functions, 7.12.9.2, F.10.6.2
25977 fflush function, 7.21.5.2, 7.21.5.3                          floor type-generic macro, 7.24
25978 fgetc function, 7.21.1, 7.21.3, 7.21.7.1,                    FLT_DECIMAL_DIG macro, 5.2.4.2.2
25979      7.21.7.5, 7.21.8.1                                      FLT_DIG macro, 5.2.4.2.2
25980 fgetpos function, 7.21.2, 7.21.9.1, 7.21.9.3                 FLT_EPSILON macro, 5.2.4.2.2
25981 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,
25982 fgetwc function, 7.21.1, 7.21.3, 7.28.3.1,                        F.10.11
25983      7.28.3.6                                                FLT_HAS_SUBNORM macro, 5.2.4.2.2
25984 fgetws function, 7.21.1, 7.28.3.2                            FLT_MANT_DIG macro, 5.2.4.2.2
25985 field width, 7.21.6.1, 7.28.2.1                               FLT_MAX macro, 5.2.4.2.2
25986 file, 7.21.3                                                  FLT_MAX_10_EXP macro, 5.2.4.2.2
25987   access functions, 7.21.5, K.3.5.2                          FLT_MAX_EXP macro, 5.2.4.2.2
25988   name, 7.21.3                                               FLT_MIN macro, 5.2.4.2.2
25989   operations, 7.21.4, K.3.5.1                                FLT_MIN_10_EXP macro, 5.2.4.2.2
25990   position indicator, 7.21.1, 7.21.2, 7.21.3,                FLT_MIN_EXP macro, 5.2.4.2.2
25991         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,
25992         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
25993         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
25994         7.28.3.3, 7.28.3.10                                  FLT_TRUE_MIN macro, 5.2.4.2.2
25995   positioning functions, 7.21.9                              fma functions, 7.12, 7.12.13.1, F.10.10.1
25996 file scope, 6.2.1, 6.9                                        fma type-generic macro, 7.24
25997 FILE type, 7.21.1, 7.21.3                                    fmax functions, 7.12.12.2, F.10.9.2
25998 FILENAME_MAX macro, 7.21.1                                   fmax type-generic macro, 7.24
25999 flags, 7.21.6.1, 7.28.2.1, see also floating-point             fmin functions, 7.12.12.3, F.10.9.3
26000      status flag                                              fmin type-generic macro, 7.24
26001 flexible array member, 6.7.2.1                                fmod functions, 7.12.10.1, F.10.7.1
26002
26003 [page 662]
26004
26005 fmod type-generic macro, 7.24                                 fscanf_s function, K.3.5.3.2, K.3.5.3.4,
26006 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
26007 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,
26008      K.3.5.1.1                                                      7.21.9.2, 7.21.9.4, 7.21.9.5, 7.28.3.10
26009 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,
26010      K.3.5.2.2                                                      7.21.9.1, 7.21.9.3, 7.28.3.10
26011 for statement, 6.8.5, 6.8.5.3                                 ftell function, 7.21.9.2, 7.21.9.4
26012 form-feed character, 5.2.1, 6.4                               full declarator, 6.7.6
26013 form-feed escape sequence (\f), 5.2.2, 6.4.4.4,               full expression, 6.8
26014      7.4.1.10                                                 fully buffered stream, 7.21.3
26015 formal argument (deprecated), 3.16                            function
26016 formal parameter, 3.16                                           argument, 6.5.2.2, 6.9.1
26017 formatted input/output functions, 7.11.1.1, 7.21.6,              body, 6.9.1
26018      K.3.5.3                                                     call, 6.5.2.2
26019    wide character, 7.28.2, K.3.9.1                                  library, 7.1.4
26020 fortran keyword, J.5.9                                           declarator, 6.7.6.3, 6.11.6
26021 forward reference, 3.11                                          definition, 6.7.6.3, 6.9.1, 6.11.7
26022 FP_CONTRACT pragma, 6.5, 6.10.6, 7.12.2, see                     designator, 6.3.2.1
26023      also contracted expression                                  image, 5.2.3
26024 FP_FAST_FMA macro, 7.12                                          inline, 6.7.4
26025 FP_FAST_FMAF macro, 7.12                                         library, 5.1.1.1, 7.1.4
26026 FP_FAST_FMAL macro, 7.12                                         name length, 5.2.4.1, 6.4.2.1, 6.11.3
26027 FP_ILOGB0 macro, 7.12, 7.12.6.5                                  no-return, 6.7.4
26028 FP_ILOGBNAN macro, 7.12, 7.12.6.5                                parameter, 5.1.2.2.1, 6.5.2.2, 6.7, 6.9.1
26029 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,
26030 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
26031 FP_NORMAL macro, 7.12, F.3                                       prototype scope, 6.2.1, 6.7.6.2
26032 FP_SUBNORMAL macro, 7.12, F.3                                    recursive call, 6.5.2.2
26033 FP_ZERO macro, 7.12, F.3                                         return, 6.8.6.4, F.6
26034 fpclassify macro, 7.12.3.1, F.3                                  scope, 6.2.1
26035 fpos_t type, 7.21.1, 7.21.2                                      type, 6.2.5
26036 fprintf function, 7.8.1, 7.21.1, 7.21.6.1,                       type conversion, 6.3.2.1
26037      7.21.6.2, 7.21.6.3, 7.21.6.5, 7.21.6.6,                  function specifiers, 6.7.4
26038      7.21.6.8, 7.28.2.2, F.3, K.3.5.3.1                       function type, 6.2.5
26039 fprintf_s function, K.3.5.3.1                                 function-call operator (( )), 6.5.2.2
26040 fputc function, 5.2.2, 7.21.1, 7.21.3, 7.21.7.3,              function-like macro, 6.10.3
26041      7.21.7.7, 7.21.8.2                                       fundamental alignment, 6.2.8
26042 fputs function, 7.21.1, 7.21.7.4                              future directions
26043 fputwc function, 7.21.1, 7.21.3, 7.28.3.3,                       language, 6.11
26044      7.28.3.8                                                    library, 7.30
26045 fputws function, 7.21.1, 7.28.3.4                             fwide function, 7.21.2, 7.28.3.5
26046 fread function, 7.21.1, 7.21.8.1                              fwprintf function, 7.8.1, 7.21.1, 7.21.6.2,
26047 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,
26048 freestanding execution environment, 4, 5.1.2,                       7.28.2.11, K.3.9.1.1
26049      5.1.2.1                                                  fwprintf_s function, K.3.9.1.1
26050 freopen function, 7.21.2, 7.21.5.4                            fwrite function, 7.21.1, 7.21.8.2
26051 freopen_s function, K.3.5.2.2                                 fwscanf function, 7.8.1, 7.21.1, 7.28.2.2,
26052 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,
26053 frexp type-generic macro, 7.24                                      K.3.9.1.2
26054 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,
26055      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
26056
26057 [page 663]
26058
26059 gamma functions, 7.12.8, F.10.5                                name spaces, 6.2.3
26060 general utilities, 7.22, K.3.6                                 reserved, 6.4.1, 7.1.3, K.3.1.2
26061   wide string, 7.28.4, K.3.9.2                                 scope, 6.2.1
26062 general wide string utilities, 7.28.4, K.3.9.2                 type, 6.2.5
26063 generic parameters, 7.24                                    identifier list, 6.7.6
26064 generic selection, 6.5.1.1                                  identifier nondigit, 6.4.2.1
26065 getc function, 7.21.1, 7.21.7.5, 7.21.7.6                   IEC 559, F.1
26066 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,
26067 getenv function, 7.22.4.6                                         7.6, 7.6.4.2, 7.12.1, 7.12.10.2, 7.12.14, F, G,
26068 getenv_s function, K.3.6.2.1                                      H.1
26069 gets function, K.3.5.4.1                                    IEEE 754, F.1
26070 gets_s function, K.3.5.4.1                                  IEEE 854, F.1
26071 getwc function, 7.21.1, 7.28.3.6, 7.28.3.7                  IEEE floating-point arithmetic standard, see
26072 getwchar function, 7.21.1, 7.28.3.7                               IEC 60559, ANSI/IEEE 754,
26073 gmtime function, 7.26.3.3                                         ANSI/IEEE 854
26074 gmtime_s function, K.3.8.2.3                                if preprocessing directive, 5.2.4.2.1, 5.2.4.2.2,
26075 goto statement, 6.2.1, 6.8.1, 6.8.6.1                             6.10.1, 7.1.4
26076 graphic characters, 5.2.1                                   if statement, 6.8.4.1
26077 greater-than operator (>), 6.5.8                            ifdef preprocessing directive, 6.10.1
26078 greater-than-or-equal-to operator (>=), 6.5.8               ifndef preprocessing directive, 6.10.1
26079                                                             ignore_handler_s function, K.3.6.1.3
26080 happens before, 5.1.2.4                                     ilogb functions, 7.12, 7.12.6.5, F.10.3.5
26081 header, 5.1.1.1, 7.1.2, see also standard headers           ilogb type-generic macro, 7.24
26082 header names, 6.4, 6.4.7, 6.10.2                            imaginary macro, 7.3.1, G.6
26083 hexadecimal constant, 6.4.4.1                               imaginary numbers, G
26084 hexadecimal digit, 6.4.4.1, 6.4.4.2, 6.4.4.4                imaginary type domain, G.2
26085 hexadecimal prefix, 6.4.4.1                                  imaginary types, G
26086 hexadecimal-character escape sequence                       imaxabs function, 7.8.2.1
26087      (\x hexadecimal digits), 6.4.4.4                       imaxdiv function, 7.8, 7.8.2.2
26088 high-order bit, 3.6                                         imaxdiv_t type, 7.8
26089 horizontal-tab character, 5.2.1, 6.4                        implementation, 3.12
26090 horizontal-tab escape sequence (\r), 7.29.2.1.3             implementation limit, 3.13, 4, 5.2.4.2, 6.4.2.1,
26091 horizontal-tab escape sequence (\t), 5.2.2,                       6.7.6, 6.8.4.2, E, see also environmental
26092      6.4.4.4, 7.4.1.3, 7.4.1.10                                   limits
26093 hosted execution environment, 4, 5.1.2, 5.1.2.2             implementation-defined behavior, 3.4.1, 4, J.3
26094 HUGE_VAL macro, 7.12, 7.12.1, 7.22.1.3,                     implementation-defined value, 3.19.1
26095      7.28.4.1.1, F.10                                       implicit conversion, 6.3
26096 HUGE_VALF macro, 7.12, 7.12.1, 7.22.1.3,                    implicit initialization, 6.7.9
26097      7.28.4.1.1, F.10                                       include preprocessing directive, 5.1.1.2, 6.10.2
26098 HUGE_VALL macro, 7.12, 7.12.1, 7.22.1.3,                    inclusive OR operators
26099      7.28.4.1.1, F.10                                          bitwise (|), 6.2.6.2, 6.5.12
26100 hyperbolic functions                                           bitwise assignment (|=), 6.5.16.2
26101   complex, 7.3.6, G.6.2                                     incomplete type, 6.2.5
26102   real, 7.12.5, F.10.2                                      increment operators, see arithmetic operators,
26103 hypot functions, 7.12.7.3, F.10.4.3                               increment and decrement
26104 hypot type-generic macro, 7.24                              indeterminate value, 3.19.2
26105                                                             indeterminately sequenced, 5.1.2.3, 6.5.2.2,
26106 I macro, 7.3.1, 7.3.9.5, G.6                                      6.5.2.4, 6.5.16.2, see also sequenced before,
26107 identifier, 6.4.2.1, 6.5.1                                         unsequenced
26108    linkage, see linkage                                     indirection operator (*), 6.5.2.1, 6.5.3.2
26109    maximum length, 6.4.2.1                                  inequality operator (!=), 6.5.9
26110
26111 [page 664]
26112
26113 infinitary, 7.12.1                                                    extended, 6.2.5, 6.3.1.1, 6.4.4.1, 7.20
26114 INFINITY macro, 7.3.9.5, 7.12, F.2.1                              inter-thread happens before, 5.1.2.4
26115 initial position, 5.2.2                                           interactive device, 5.1.2.3, 7.21.3, 7.21.5.3
26116 initial shift state, 5.2.1.2                                      internal linkage, 6.2.2
26117 initialization, 5.1.2, 6.2.4, 6.3.2.1, 6.5.2.5, 6.7.9,            internal name, 6.4.2.1
26118       F.8.5                                                       interrupt, 5.2.3
26119    in blocks, 6.8                                                 INTMAX_C macro, 7.20.4.2
26120 initializer, 6.7.9                                                INTMAX_MAX macro, 7.8.2.3, 7.8.2.4, 7.20.2.5
26121    permitted form, 6.6                                            INTMAX_MIN macro, 7.8.2.3, 7.8.2.4, 7.20.2.5
26122    string literal, 6.3.2.1                                        intmax_t type, 7.20.1.5, 7.21.6.1, 7.21.6.2,
26123 inline, 6.7.4                                                           7.28.2.1, 7.28.2.2
26124 inner scope, 6.2.1                                                INTN_C macros, 7.20.4.1
26125 input failure, 7.28.2.6, 7.28.2.8, 7.28.2.10,                     INTN_MAX macros, 7.20.2.1
26126       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
26127       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
26128       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
26129 input/output functions                                            INTPTR_MIN macro, 7.20.2.4
26130    character, 7.21.7, K.3.5.4                                     intptr_t type, 7.20.1.4
26131    direct, 7.21.8                                                 inttypes.h header, 7.8, 7.30.4
26132    formatted, 7.21.6, K.3.5.3                                     isalnum function, 7.4.1.1, 7.4.1.9, 7.4.1.10
26133       wide character, 7.28.2, K.3.9.1                             isalpha function, 7.4.1.1, 7.4.1.2
26134    wide character, 7.28.3                                         isblank function, 7.4.1.3
26135       formatted, 7.28.2, K.3.9.1                                  iscntrl function, 7.4.1.2, 7.4.1.4, 7.4.1.7,
26136 input/output header, 7.21, K.3.5                                        7.4.1.11
26137 input/output, device, 5.1.2.3                                     isdigit function, 7.4.1.1, 7.4.1.2, 7.4.1.5,
26138 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
26139 int type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,                   isfinite macro, 7.12.3.2, F.3
26140       6.3.1.8                                                     isgraph function, 7.4.1.6
26141 INT_FASTN_MAX macros, 7.20.2.3                                    isgreater macro, 7.12.14.1, F.3
26142 INT_FASTN_MIN macros, 7.20.2.3                                    isgreaterequal macro, 7.12.14.2, F.3
26143 int_fastN_t types, 7.20.1.3                                       isinf macro, 7.12.3.3
26144 INT_LEASTN_MAX macros, 7.20.2.2                                   isless macro, 7.12.14.3, F.3
26145 INT_LEASTN_MIN macros, 7.20.2.2                                   islessequal macro, 7.12.14.4, F.3
26146 int_leastN_t types, 7.20.1.2                                      islessgreater macro, 7.12.14.5, F.3
26147 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,
26148 INT_MIN macro, 5.2.4.2.1, 7.12                                          7.4.2.2
26149 integer arithmetic functions, 7.8.2.1, 7.8.2.2,                   isnan macro, 7.12.3.4, F.3
26150       7.22.6                                                      isnormal macro, 7.12.3.5
26151 integer character constant, 6.4.4.4                               ISO 31-11, 2, 3
26152 integer constant, 6.4.4.1                                         ISO 4217, 2, 7.11.2.1
26153 integer constant expression, 6.3.2.3, 6.6, 6.7.2.1,               ISO 8601, 2, 7.26.3.5
26154       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
26155       7.1.4                                                       ISO/IEC 10976-1, H.1
26156 integer conversion rank, 6.3.1.1                                  ISO/IEC 2382-1, 2, 3
26157 integer promotions, 5.1.2.3, 5.2.4.2.1, 6.3.1.1,                  ISO/IEC 646, 2, 5.2.1.1
26158       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
26159       7.21.6.1, 7.28.2.1                                          ISO/IEC TR 10176, D
26160 integer suffix, 6.4.4.1                                            iso646.h header, 4, 7.9
26161 integer type conversion, 6.3.1.1, 6.3.1.3, 6.3.1.4,               isprint function, 5.2.2, 7.4.1.8
26162       F.3, F.4                                                    ispunct function, 7.4.1.2, 7.4.1.7, 7.4.1.9,
26163 integer types, 6.2.5, 7.20                                              7.4.1.11
26164
26165 [page 665]
26166
26167 isspace function, 7.4.1.2, 7.4.1.7, 7.4.1.9,                    Latin alphabet, 5.2.1, 6.4.2.1
26168       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
26169       7.22.1.4, 7.28.2.2                                        LC_COLLATE macro, 7.11, 7.11.1.1, 7.23.4.3,
26170 isunordered macro, 7.12.14.6, F.3                                     7.28.4.4.2
26171 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,
26172       7.4.2.2                                                         7.22.8, 7.28.6, 7.29.1, 7.29.2.2.1, 7.29.2.2.2,
26173 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
26174       7.29.2.1.10, 7.29.2.2.1                                   LC_MONETARY macro, 7.11, 7.11.1.1, 7.11.2.1
26175 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
26176       7.29.2.2.1                                                LC_TIME macro, 7.11, 7.11.1.1, 7.26.3.5
26177 iswblank function, 7.29.2.1.3, 7.29.2.2.1                       lconv structure type, 7.11
26178 iswcntrl function, 7.29.2.1.2, 7.29.2.1.4,                      LDBL_DECIMAL_DIG macro, 5.2.4.2.2
26179       7.29.2.1.7, 7.29.2.1.11, 7.29.2.2.1                       LDBL_DIG macro, 5.2.4.2.2
26180 iswctype function, 7.29.2.2.1, 7.29.2.2.2                       LDBL_EPSILON macro, 5.2.4.2.2
26181 iswdigit function, 7.29.2.1.1, 7.29.2.1.2,                      LDBL_HAS_SUBNORM macro, 5.2.4.2.2
26182       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
26183 iswgraph function, 7.29.2.1, 7.29.2.1.6,                        LDBL_MAX macro, 5.2.4.2.2
26184       7.29.2.1.10, 7.29.2.2.1                                   LDBL_MAX_10_EXP macro, 5.2.4.2.2
26185 iswlower function, 7.29.2.1.2, 7.29.2.1.7,                      LDBL_MAX_EXP macro, 5.2.4.2.2
26186       7.29.2.2.1, 7.29.3.1.1, 7.29.3.1.2                        LDBL_MIN macro, 5.2.4.2.2
26187 iswprint function, 7.29.2.1.6, 7.29.2.1.8,                      LDBL_MIN_10_EXP macro, 5.2.4.2.2
26188       7.29.2.2.1                                                LDBL_MIN_EXP macro, 5.2.4.2.2
26189 iswpunct function, 7.29.2.1, 7.29.2.1.2,                        LDBL_TRUE_MIN macro, 5.2.4.2.2
26190       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
26191       7.29.2.1.11, 7.29.2.2.1                                   ldexp type-generic macro, 7.24
26192 iswspace function, 7.21.6.2, 7.28.2.2,                          ldiv function, 7.22.6.2
26193       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
26194       7.29.2.1.7, 7.29.2.1.9, 7.29.2.1.10,                      leading underscore in identifiers, 7.1.3
26195       7.29.2.1.11, 7.29.2.2.1                                   left-shift assignment operator (<<=), 6.5.16.2
26196 iswupper function, 7.29.2.1.2, 7.29.2.1.11,                     left-shift operator (<<), 6.2.6.2, 6.5.7
26197       7.29.2.2.1, 7.29.3.1.1, 7.29.3.1.2                        length
26198 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
26199 isxdigit function, 7.4.1.12, 7.11.1.1                              function name, 5.2.4.1, 6.4.2.1, 6.11.3
26200 italic type convention, 3, 6.1                                     identifier, 6.4.2.1
26201 iteration statements, 6.8.5                                        internal name, 5.2.4.1, 6.4.2.1
26202                                                                 length function, 7.22.7.1, 7.23.6.3, 7.28.4.6.1,
26203 jmp_buf type, 7.13                                                    7.28.6.3.1, K.3.7.4.4, K.3.9.2.4.1
26204 jump statements, 6.8.6                                          length modifier, 7.21.6.1, 7.21.6.2, 7.28.2.1,
26205                                                                       7.28.2.2
26206 keywords, 6.4.1, G.2, J.5.9, J.5.10                             less-than operator (<), 6.5.8
26207 kill_dependency macro, 5.1.2.4, 7.17.3.1                        less-than-or-equal-to operator (<=), 6.5.8
26208 known constant size, 6.2.5                                      letter, 5.2.1, 7.4
26209                                                                 lexical elements, 5.1.1.2, 6.4
26210 L_tmpnam macro, 7.21.1, 7.21.4.4                                lgamma functions, 7.12.8.3, F.10.5.3
26211 L_tmpnam_s macro, K.3.5, K.3.5.1.2                              lgamma type-generic macro, 7.24
26212 label name, 6.2.1, 6.2.3                                        library, 5.1.1.1, 7, K.3
26213 labeled statement, 6.8.1                                           future directions, 7.30
26214 labs function, 7.22.6.1                                            summary, B
26215 language, 6                                                        terms, 7.1.1
26216    future directions, 6.11                                         use of functions, 7.1.4
26217    syntax summary, A                                            lifetime, 6.2.4
26218
26219 [page 666]
26220
26221 limits                                                     long double _Complex type conversion,
26222    environmental, see environmental limits                      6.3.1.6, 6.3.1.7, 6.3.1.8
26223    implementation, see implementation limits               long double _Imaginary type, G.2
26224    numerical, see numerical limits                         long double suffix, l or L, 6.4.4.2
26225    translation, see translation limits                     long double type, 6.2.5, 6.4.4.2, 6.7.2,
26226 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
26227 line buffered stream, 7.21.3                               long double type conversion, 6.3.1.4, 6.3.1.5,
26228 line number, 6.10.4, 6.10.8.1                                   6.3.1.7, 6.3.1.8
26229 line preprocessing directive, 6.10.4                       long int type, 6.2.5, 6.3.1.1, 6.7.2, 7.21.6.1,
26230 lines, 5.1.1.2, 7.21.2                                          7.21.6.2, 7.28.2.1, 7.28.2.2
26231    preprocessing directive, 6.10                           long int type conversion, 6.3.1.1, 6.3.1.3,
26232 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
26233       6.11.2                                               long integer suffix, l or L, 6.4.4.1
26234 llabs function, 7.22.6.1                                   long long int type, 6.2.5, 6.3.1.1, 6.7.2,
26235 lldiv function, 7.22.6.2                                        7.21.6.1, 7.21.6.2, 7.28.2.1, 7.28.2.2
26236 lldiv_t type, 7.22                                         long long int type conversion, 6.3.1.1,
26237 LLONG_MAX macro, 5.2.4.2.1, 7.22.1.4,                           6.3.1.3, 6.3.1.4, 6.3.1.8
26238       7.28.4.1.2                                           long long integer suffix, ll or LL, 6.4.4.1
26239 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
26240       7.28.4.1.2                                           LONG_MIN macro, 5.2.4.2.1, 7.22.1.4, 7.28.4.1.2
26241 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,
26242 llrint type-generic macro, 7.24                                 7.22.4.7
26243 llround functions, 7.12.9.7, F.10.6.7                      loop body, 6.8.5
26244 llround type-generic macro, 7.24                           low-order bit, 3.6
26245 local time, 7.26.1                                         lowercase letter, 5.2.1
26246 locale, 3.4.2                                              lrint functions, 7.12.9.5, F.3, F.10.6.5
26247 locale-specific behavior, 3.4.2, J.4                        lrint type-generic macro, 7.24
26248 locale.h header, 7.11, 7.30.5                              lround functions, 7.12.9.7, F.10.6.7
26249 localeconv function, 7.11.1.1, 7.11.2.1                    lround type-generic macro, 7.24
26250 localization, 7.11                                         lvalue, 6.3.2.1, 6.5.1, 6.5.2.4, 6.5.3.1, 6.5.16
26251 localtime function, 7.26.3.4
26252 localtime_s function, K.3.8.2.4                            macro argument substitution, 6.10.3.1
26253 log functions, 7.12.6.7, F.10.3.7                          macro definition
26254 log type-generic macro, 7.24                                 library function, 7.1.4
26255 log10 functions, 7.12.6.8, F.10.3.8                        macro invocation, 6.10.3
26256 log10 type-generic macro, 7.24                             macro name, 6.10.3
26257 log1p functions, 7.12.6.9, F.10.3.9                          length, 5.2.4.1
26258 log1p type-generic macro, 7.24                               predefined, 6.10.8, 6.11.9
26259 log2 functions, 7.12.6.10, F.10.3.10                         redefinition, 6.10.3
26260 log2 type-generic macro, 7.24                                scope, 6.10.3.5
26261 logarithmic functions                                      macro parameter, 6.10.3
26262    complex, 7.3.7, G.6.3                                   macro preprocessor, 6.10
26263    real, 7.12.6, F.10.3                                    macro replacement, 6.10.3
26264 logb functions, 7.12.6.11, F.3, F.10.3.11                  magnitude, complex, 7.3.8.1
26265 logb type-generic macro, 7.24                              main function, 5.1.2.2.1, 5.1.2.2.3, 6.7.3.1, 6.7.4,
26266 logical operators                                               7.21.3
26267    AND (&&), 5.1.2.4, 6.5.13                               malloc function, 7.22.3, 7.22.3.4, 7.22.3.5
26268    negation (!), 6.5.3.3                                   manipulation functions
26269    OR (||), 5.1.2.4, 6.5.14                                  complex, 7.3.9
26270 logical source lines, 5.1.1.2                                real, 7.12.11, F.10.8
26271 long double _Complex type, 6.2.5                           matching failure, 7.28.2.6, 7.28.2.8, 7.28.2.10,
26272
26273 [page 667]
26274
26275      K.3.9.1.7, K.3.9.1.10, K.3.9.1.12                     modification order, 5.1.2.4
26276 math.h header, 5.2.4.2.2, 6.5, 7.12, 7.24, F,              modulus functions, 7.12.6.12
26277      F.10, J.5.17                                          modulus, complex, 7.3.8.1
26278 MATH_ERREXCEPT macro, 7.12, F.10                           mtx_destroy function, 7.25.4.1
26279 math_errhandling macro, 7.1.3, 7.12, F.10                  mtx_init function, 7.25.1, 7.25.4.2
26280 MATH_ERRNO macro, 7.12                                     mtx_lock function, 7.25.4.3
26281 max_align_t type, 7.19                                     mtx_t type, 7.25.1
26282 maximum functions, 7.12.12, F.10.9                         mtx_timedlock function, 7.25.4.4
26283 MB_CUR_MAX macro, 7.1.1, 7.22, 7.22.7.2,                   mtx_trylock function, 7.25.4.5
26284      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,
26285      K.3.6.4.1, K.3.9.3.1.1                                     7.25.4.5, 7.25.4.6
26286 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
26287 mblen function, 7.22.7.1, 7.28.6.3                         multibyte conversion functions
26288 mbrlen function, 7.28.6.3.1                                  wide character, 7.22.7, K.3.6.4
26289 mbrtoc16 function, 6.4.4.4, 6.4.5, 7.27.1.1                     extended, 7.28.6, K.3.9.3
26290 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
26291 mbrtowc function, 7.21.3, 7.21.6.1, 7.21.6.2,                wide string, 7.22.8, K.3.6.5
26292      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
26293      7.28.6.4.1, K.3.6.5.1, K.3.9.3.2.1                    multibyte string, 7.1.1
26294 mbsinit function, 7.28.6.2.1                               multibyte/wide character conversion functions,
26295 mbsrtowcs function, 7.28.6.4.1, K.3.9.3.2                       7.22.7, K.3.6.4
26296 mbsrtowcs_s function, K.3.9.3.2, K.3.9.3.2.1                 extended, 7.28.6, K.3.9.3
26297 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
26298      7.21.6.2, 7.27, 7.27.1, 7.28.1, 7.28.2.1,             multibyte/wide string conversion functions,
26299      7.28.2.2, 7.28.6, 7.28.6.2.1, 7.28.6.3,                    7.22.8, K.3.6.5
26300      7.28.6.3.1, 7.28.6.4                                    restartable, 7.28.6.4, K.3.9.3.2
26301 mbstowcs function, 6.4.5, 7.22.8.1, 7.28.6.4               multidimensional array, 6.5.2.1
26302 mbstowcs_s function, K.3.6.5.1                             multiplication assignment operator (*=), 6.5.16.2
26303 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,
26304      7.22.8.1, 7.28.6.3                                         G.5.1
26305 member access operators (. and ->), 6.5.2.3                multiplicative expressions, 6.5.5, G.5.1
26306 member alignment, 6.7.2.1
26307 memchr function, 7.23.5.1                                  n-char sequence, 7.22.1.3
26308 memcmp function, 7.23.4, 7.23.4.1                          n-wchar sequence, 7.28.4.1.1
26309 memcpy function, 7.23.2.1                                  name
26310 memcpy_s function, K.3.7.1.1                                 external, 5.2.4.1, 6.4.2.1, 6.11.3
26311 memmove function, 7.23.2.2                                   file, 7.21.3
26312 memmove_s function, K.3.7.1.2                                internal, 5.2.4.1, 6.4.2.1
26313 memory location, 3.14                                        label, 6.2.3
26314 memory management functions, 7.22.3                          structure/union member, 6.2.3
26315 memory_order type, 7.17.1, 7.17.3                          name spaces, 6.2.3
26316 memset function, 7.23.6.1, K.3.7.4.1                       named label, 6.8.1
26317 memset_s function, K.3.7.4.1                               NaN, 5.2.4.2.2
26318 minimum functions, 7.12.12, F.10.9                         nan functions, 7.12.11.2, F.2.1, F.10.8.2
26319 minus operator, unary, 6.5.3.3                             NAN macro, 7.12, F.2.1
26320 miscellaneous functions                                    NDEBUG macro, 7.2
26321   string, 7.23.6, K.3.7.4                                  nearbyint functions, 7.12.9.3, 7.12.9.4, F.3,
26322   wide string, 7.28.4.6, K.3.9.2.4                              F.10.6.3
26323 mktime function, 7.26.2.3                                  nearbyint type-generic macro, 7.24
26324 modf functions, 7.12.6.12, F.10.3.12                       nearest integer functions, 7.12.9, F.10.6
26325 modifiable lvalue, 6.3.2.1                                  negation operator (!), 6.5.3.3
26326
26327 [page 668]
26328
26329 negative zero, 6.2.6.2, 7.12.11.1                               operator, 6.4.6
26330 new-line character, 5.1.1.2, 5.2.1, 6.4, 6.10, 6.10.4           operators, 6.5
26331 new-line escape sequence (\n), 5.2.2, 6.4.4.4,                     additive, 6.2.6.2, 6.5.6
26332      7.4.1.10                                                      alignof, 6.5.3.4
26333 nextafter functions, 7.12.11.3, 7.12.11.4, F.3,                    assignment, 6.5.16
26334      F.10.8.3                                                      associativity, 6.5
26335 nextafter type-generic macro, 7.24                                 equality, 6.5.9
26336 nexttoward functions, 7.12.11.4, F.3, F.10.8.4                     multiplicative, 6.2.6.2, 6.5.5, G.5.1
26337 nexttoward type-generic macro, 7.24                                postfix, 6.5.2
26338 no linkage, 6.2.2                                                  precedence, 6.5
26339 no-return function, 6.7.4                                          preprocessing, 6.10.1, 6.10.3.2, 6.10.3.3, 6.10.9
26340 non-stop floating-point control mode, 7.6.4.2                       relational, 6.5.8
26341 nongraphic characters, 5.2.2, 6.4.4.4                              shift, 6.5.7
26342 nonlocal jumps header, 7.13                                        sizeof, 6.5.3.4
26343 norm, complex, 7.3.8.1                                             unary, 6.5.3
26344 normalized broken-down time, K.3.8.1, K.3.8.2.1                    unary arithmetic, 6.5.3.3
26345 not macro, 7.9                                                  optional features, see conditional features
26346 not-equal-to operator, see inequality operator                  or macro, 7.9
26347 not_eq macro, 7.9                                               OR operators
26348 null character (\0), 5.2.1, 6.4.4.4, 6.4.5                         bitwise exclusive (^), 6.2.6.2, 6.5.11
26349   padding of binary stream, 7.21.2                                 bitwise exclusive assignment (^=), 6.5.16.2
26350 NULL macro, 7.11, 7.19, 7.21.1, 7.22, 7.23.1,                      bitwise inclusive (|), 6.2.6.2, 6.5.12
26351      7.26.1, 7.28.1                                                bitwise inclusive assignment (|=), 6.5.16.2
26352 null pointer, 6.3.2.3                                              logical (||), 5.1.2.4, 6.5.14
26353 null pointer constant, 6.3.2.3                                  or_eq macro, 7.9
26354 null preprocessing directive, 6.10.7                            order of allocated storage, 7.22.3
26355 null statement, 6.8.3                                           order of evaluation, 6.5, 6.5.16, 6.10.3.2, 6.10.3.3,
26356 null wide character, 7.1.1                                            see also sequence points
26357 number classification macros, 7.12, 7.12.3.1                     ordinary identifier name space, 6.2.3
26358 numeric conversion functions, 7.8.2.3, 7.22.1                   orientation of stream, 7.21.2, 7.28.3.5
26359   wide string, 7.8.2.4, 7.28.4.1                                out-of-bounds store, L.2.1
26360 numerical limits, 5.2.4.2                                       outer scope, 6.2.1
26361                                                                 over-aligned, 6.2.8
26362 object, 3.15
26363 object representation, 6.2.6.1                                  padding
26364 object type, 6.2.5                                                binary stream, 7.21.2
26365 object-like macro, 6.10.3                                         bits, 6.2.6.2, 7.20.1.1
26366 observable behavior, 5.1.2.3                                      structure/union, 6.2.6.1, 6.7.2.1
26367 obsolescence, 6.11, 7.30                                        parameter, 3.16
26368 octal constant, 6.4.4.1                                           array, 6.9.1
26369 octal digit, 6.4.4.1, 6.4.4.4                                     ellipsis, 6.7.6.3, 6.10.3
26370 octal-character escape sequence (\octal digits),                  function, 6.5.2.2, 6.7, 6.9.1
26371      6.4.4.4                                                      macro, 6.10.3
26372 offsetof macro, 7.19                                              main function, 5.1.2.2.1
26373 on-off switch, 6.10.6                                             program, 5.1.2.2.1
26374 once_flag type, 7.25.1                                          parameter type list, 6.7.6.3
26375 ONCE_FLAG_INIT macro, 7.25.1                                    parentheses punctuator (( )), 6.7.6.3, 6.8.4, 6.8.5
26376 ones' complement, 6.2.6.2                                       parenthesized expression, 6.5.1
26377 operand, 6.4.6, 6.5                                             parse state, 7.21.2
26378 operating system, 5.1.2.1, 7.22.4.8                             perform a trap, 3.19.5
26379 operations on files, 7.21.4, K.3.5.1                             permitted form of initializer, 6.6
26380
26381 [page 669]
26382
26383 perror function, 7.21.10.4                                    PRIcLEASTN macros, 7.8.1
26384 phase angle, complex, 7.3.9.1                                 PRIcMAX macros, 7.8.1
26385 physical source lines, 5.1.1.2                                PRIcN macros, 7.8.1
26386 placemarker, 6.10.3.3                                         PRIcPTR macros, 7.8.1
26387 plus operator, unary, 6.5.3.3                                 primary expression, 6.5.1
26388 pointer arithmetic, 6.5.6                                     printf function, 7.21.1, 7.21.6.3, 7.21.6.10,
26389 pointer comparison, 6.5.8                                           K.3.5.3.3
26390 pointer declarator, 6.7.6.1                                   printf_s function, K.3.5.3.3
26391 pointer operator (->), 6.5.2.3                                printing character, 5.2.2, 7.4, 7.4.1.8
26392 pointer to function, 6.5.2.2                                  printing wide character, 7.29.2
26393 pointer type, 6.2.5                                           program diagnostics, 7.2.1
26394 pointer type conversion, 6.3.2.1, 6.3.2.3                     program execution, 5.1.2.2.2, 5.1.2.3
26395 pointer, null, 6.3.2.3                                        program file, 5.1.1.1
26396 pole error, 7.12.1, 7.12.5.3, 7.12.6.7, 7.12.6.8,             program image, 5.1.1.2
26397      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
26398      7.12.8.3, 7.12.8.4                                       program parameters, 5.1.2.2.1
26399 portability, 4, J                                             program startup, 5.1.2, 5.1.2.1, 5.1.2.2.1
26400 position indicator, file, see file position indicator           program structure, 5.1.1.1
26401 positive difference, 7.12.12.1                                program termination, 5.1.2, 5.1.2.1, 5.1.2.2.3,
26402 positive difference functions, 7.12.12, F.10.9                      5.1.2.3
26403 postfix decrement operator (--), 6.3.2.1, 6.5.2.4              program, conforming, 4
26404 postfix expressions, 6.5.2                                     program, strictly conforming, 4
26405 postfix increment operator (++), 6.3.2.1, 6.5.2.4              promotions
26406 pow functions, 7.12.7.4, F.10.4.4                                default argument, 6.5.2.2
26407 pow type-generic macro, 7.24                                     integer, 5.1.2.3, 6.3.1.1
26408 power functions                                               prototype, see function prototype
26409   complex, 7.3.8, G.6.4                                       pseudo-random sequence functions, 7.22.2
26410   real, 7.12.7, F.10.4                                        PTRDIFF_MAX macro, 7.20.3
26411 pp-number, 6.4.8                                              PTRDIFF_MIN macro, 7.20.3
26412 pragma operator, 6.10.9                                       ptrdiff_t type, 7.17.1, 7.19, 7.20.3, 7.21.6.1,
26413 pragma preprocessing directive, 6.10.6, 6.11.8                      7.21.6.2, 7.28.2.1, 7.28.2.2
26414 precedence of operators, 6.5                                  punctuators, 6.4.6
26415 precedence of syntax rules, 5.1.1.2                           putc function, 7.21.1, 7.21.7.7, 7.21.7.8
26416 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
26417   excess, 5.2.4.2.2, 6.3.1.5, 6.3.1.8, 6.8.6.4                puts function, 7.21.1, 7.21.7.9
26418 predefined macro names, 6.10.8, 6.11.9                         putwc function, 7.21.1, 7.28.3.8, 7.28.3.9
26419 prefix decrement operator (--), 6.3.2.1, 6.5.3.1               putwchar function, 7.21.1, 7.28.3.9
26420 prefix increment operator (++), 6.3.2.1, 6.5.3.1
26421 preprocessing concatenation, 6.10.3.3                         qsort function, 7.22.5, 7.22.5.2
26422 preprocessing directives, 5.1.1.2, 6.10                       qsort_s function, K.3.6.3, K.3.6.3.2
26423 preprocessing file, 5.1.1.1, 6.10                              qualified types, 6.2.5
26424 preprocessing numbers, 6.4, 6.4.8                             qualified version of type, 6.2.5
26425 preprocessing operators                                       question-mark escape sequence (\?), 6.4.4.4
26426   #, 6.10.3.2                                                 quick_exit function, 7.22.4.3, 7.22.4.4,
26427   ##, 6.10.3.3                                                     7.22.4.7
26428   _Pragma, 5.1.1.2, 6.10.9                                    quiet NaN, 5.2.4.2.2
26429   defined, 6.10.1
26430 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
26431 preprocessing translation unit, 5.1.1.1                       rand function, 7.22, 7.22.2.1, 7.22.2.2
26432 preprocessor, 6.10                                            RAND_MAX macro, 7.22, 7.22.2.1
26433 PRIcFASTN macros, 7.8.1                                       range
26434
26435 [page 670]
26436
26437    excess, 5.2.4.2.2, 6.3.1.5, 6.3.1.8, 6.8.6.4              rewind function, 7.21.5.3, 7.21.7.10, 7.21.9.5,
26438 range error, 7.12.1, 7.12.5.4, 7.12.5.5, 7.12.6.1,                7.28.3.10
26439       7.12.6.2, 7.12.6.3, 7.12.6.5, 7.12.6.6,                right-shift assignment operator (>>=), 6.5.16.2
26440       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
26441       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
26442       7.12.11.3, 7.12.12.1, 7.12.13.1                        rint type-generic macro, 7.24
26443 rank, see integer conversion rank                            round functions, 7.12.9.6, F.10.6.6
26444 read-modify-write operations, 5.1.2.4                        round type-generic macro, 7.24
26445 real floating type conversion, 6.3.1.4, 6.3.1.5,              rounding mode, floating point, 5.2.4.2.2
26446       6.3.1.7, F.3, F.4                                      RSIZE_MAX macro, K.3.3, K.3.4, K.3.5.1.2,
26447 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,
26448 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,
26449 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,
26450 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,
26451 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,
26452 recommended practice, 3.17                                        K.3.8.2.1, K.3.8.2.2, K.3.9.1.3, K.3.9.1.4,
26453 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,
26454 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,
26455 redefinition of macro, 6.10.3                                      K.3.9.2.2.2, K.3.9.2.3.1, K.3.9.3.1.1,
26456 reentrancy, 5.1.2.3, 5.2.3                                        K.3.9.3.2.1, K.3.9.3.2.2
26457    library functions, 7.1.4                                  rsize_t type, K.3.3, K.3.4, K.3.5, K.3.5.3.2,
26458 referenced type, 6.2.5                                            K.3.6, K.3.7, K.3.8, K.3.9, K.3.9.1.2
26459 register storage-class specifier, 6.7.1, 6.9                  runtime-constraint, 3.18
26460 relational expressions, 6.5.8                                Runtime-constraint handling functions, K.3.6.1
26461 relaxed atomic operations, 5.1.2.4                           rvalue, 6.3.2.1
26462 release fence, 7.17.4
26463 release operation, 5.1.2.4                                   same scope, 6.2.1
26464 release sequence, 5.1.2.4                                    save calling environment function, 7.13.1
26465 reliability of data, interrupted, 5.1.2.3                    scalar types, 6.2.5
26466 remainder assignment operator (%=), 6.5.16.2                 scalbln function, 7.12.6.13, F.3, F.10.3.13
26467 remainder functions, 7.12.10, F.10.7                         scalbln type-generic macro, 7.24
26468 remainder functions, 7.12.10.2, 7.12.10.3, F.3,              scalbn function, 7.12.6.13, F.3, F.10.3.13
26469       F.10.7.2                                               scalbn type-generic macro, 7.24
26470 remainder operator (%), 6.2.6.2, 6.5.5                       scanf function, 7.21.1, 7.21.6.4, 7.21.6.11
26471 remainder type-generic macro, 7.24                           scanf_s function, K.3.5.3.4, K.3.5.3.11
26472 remove function, 7.21.4.1, 7.21.4.4, K.3.5.1.2               scanlist, 7.21.6.2, 7.28.2.2
26473 remquo functions, 7.12.10.3, F.3, F.10.7.3                   scanset, 7.21.6.2, 7.28.2.2
26474 remquo type-generic macro, 7.24                              SCHAR_MAX macro, 5.2.4.2.1
26475 rename function, 7.21.4.2                                    SCHAR_MIN macro, 5.2.4.2.1
26476 representations of types, 6.2.6                              SCNcFASTN macros, 7.8.1
26477    pointer, 6.2.5                                            SCNcLEASTN macros, 7.8.1
26478 rescanning and replacement, 6.10.3.4                         SCNcMAX macros, 7.8.1
26479 reserved identifiers, 6.4.1, 7.1.3, K.3.1.2                   SCNcN macros, 7.8.1
26480 restartable multibyte/wide character conversion              SCNcPTR macros, 7.8.1
26481       functions, 7.27.1, 7.28.6.3, K.3.9.3.1                 scope of identifier, 6.2.1, 6.9.2
26482 restartable multibyte/wide string conversion                 search functions
26483       functions, 7.28.6.4, K.3.9.3.2                           string, 7.23.5, K.3.7.3
26484 restore calling environment function, 7.13.2                   utility, 7.22.5, K.3.6.3
26485 restrict type qualifier, 6.7.3, 6.7.3.1                         wide string, 7.28.4.5, K.3.9.2.3
26486 restrict-qualified type, 6.2.5, 6.7.3                         SEEK_CUR macro, 7.21.1, 7.21.9.2
26487 return statement, 6.8.6.4, F.6                               SEEK_END macro, 7.21.1, 7.21.9.2
26488
26489 [page 671]
26490
26491 SEEK_SET macro, 7.21.1, 7.21.9.2                                 signal function, 7.14.1.1, 7.22.4.5, 7.22.4.7
26492 selection statements, 6.8.4                                      signal handler, 5.1.2.3, 5.2.3, 7.14.1.1, 7.14.2.1
26493 self-referential structure, 6.7.2.3                              signal handling functions, 7.14.1
26494 semicolon punctuator (;), 6.7, 6.7.2.1, 6.8.3,                   signal.h header, 7.14, 7.30.6
26495       6.8.5, 6.8.6                                               signaling NaN, 5.2.4.2.2, F.2.1
26496 separate compilation, 5.1.1.1                                    signals, 5.1.2.3, 5.2.3, 7.14.1
26497 separate translation, 5.1.1.1                                    signbit macro, 7.12.3.6, F.3
26498 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,
26499       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
26500       7.1.4, 7.21.6, 7.22.5, 7.28.2, C, K.3.6.3                  signed character, 6.3.1.1
26501 sequenced after, see sequenced before                            signed integer types, 6.2.5, 6.3.1.3, 6.4.4.1
26502 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,
26503       6.5.16, see also indeterminately sequenced,                     6.3.1.8
26504       unsequenced                                                signed types, 6.2.5, 6.7.2
26505 sequencing of statements, 6.8                                    significand part, 6.4.4.2
26506 set_constraint_handler_s function,                               SIGSEGV macro, 7.14, 7.14.1.1
26507       K.3.1.4, K.3.6.1.1, K.3.6.1.2, K.3.6.1.3                   SIGTERM macro, 7.14
26508 setbuf function, 7.21.3, 7.21.5.1, 7.21.5.5                      simple assignment operator (=), 6.5.16.1
26509 setjmp macro, 7.1.3, 7.13.1.1, 7.13.2.1                          sin functions, 7.12.4.6, F.10.1.6
26510 setjmp.h header, 7.13                                            sin type-generic macro, 7.24, G.7
26511 setlocale function, 7.11.1.1, 7.11.2.1                           single-byte character, 3.7.1, 5.2.1.2
26512 setvbuf function, 7.21.1, 7.21.3, 7.21.5.1,                      single-byte/wide character conversion functions,
26513       7.21.5.5, 7.21.5.6                                              7.28.6.1
26514 shall, 4                                                         single-precision arithmetic, 5.1.2.3
26515 shift expressions, 6.5.7                                         single-quote escape sequence (\'), 6.4.4.4, 6.4.5
26516 shift sequence, 7.1.1                                            singularity, 7.12.1
26517 shift states, 5.2.1.2                                            sinh functions, 7.12.5.5, F.10.2.5
26518 short identifier, character, 5.2.4.1, 6.4.3                       sinh type-generic macro, 7.24, G.7
26519 short int type, 6.2.5, 6.3.1.1, 6.7.2, 7.21.6.1,                 SIZE_MAX macro, 7.20.3
26520       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,
26521 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,
26522       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,
26523 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
26524 SHRT_MIN macro, 5.2.4.2.1                                        sizeof operator, 6.3.2.1, 6.5.3, 6.5.3.4
26525 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,
26526       6.5.16, 6.7.9, 6.8.3, 7.6, 7.6.1, 7.21.7.5,                     K.3.5.3.5
26527       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
26528       F.9.3                                                      snwprintf_s function, K.3.9.1.3, K.3.9.1.4
26529 SIG_ATOMIC_MAX macro, 7.20.3                                     sorting utility functions, 7.22.5, K.3.6.3
26530 SIG_ATOMIC_MIN macro, 7.20.3                                     source character set, 5.1.1.2, 5.2.1
26531 sig_atomic_t type, 5.1.2.3, 7.14, 7.14.1.1,                      source file, 5.1.1.1
26532       7.20.3                                                        name, 6.10.4, 6.10.8.1
26533 SIG_DFL macro, 7.14, 7.14.1.1                                    source file inclusion, 6.10.2
26534 SIG_ERR macro, 7.14, 7.14.1.1                                    source lines, 5.1.1.2
26535 SIG_IGN macro, 7.14, 7.14.1.1                                    source text, 5.1.1.2
26536 SIGABRT macro, 7.14, 7.22.4.1                                    space character (' '), 5.1.1.2, 5.2.1, 6.4, 7.4.1.3,
26537 SIGFPE macro, 7.12.1, 7.14, 7.14.1.1, J.5.17                          7.4.1.10, 7.29.2.1.3
26538 SIGILL macro, 7.14, 7.14.1.1                                     sprintf function, 7.21.6.6, 7.21.6.13, K.3.5.3.6
26539 SIGINT macro, 7.14                                               sprintf_s function, K.3.5.3.5, K.3.5.3.6
26540 sign and magnitude, 6.2.6.2                                      sqrt functions, 7.12.7.5, F.3, F.10.4.5
26541 sign bit, 6.2.6.2                                                sqrt type-generic macro, 7.24
26542
26543 [page 672]
26544
26545 srand function, 7.22.2.2                                        expression, 6.8.3
26546 sscanf function, 7.21.6.7, 7.21.6.14                            for, 6.8.5.3
26547 sscanf_s function, K.3.5.3.7, K.3.5.3.14                        goto, 6.8.6.1
26548 standard error stream, 7.21.1, 7.21.3, 7.21.10.4                if, 6.8.4.1
26549 standard headers, 4, 7.1.2                                      iteration, 6.8.5
26550    <assert.h>, 7.2                                              jump, 6.8.6
26551    <complex.h>, 5.2.4.2.2, 6.10.8.3, 7.1.2, 7.3,                labeled, 6.8.1
26552         7.24, 7.30.1, G.6, J.5.17                               null, 6.8.3
26553    <ctype.h>, 7.4, 7.30.2                                       return, 6.8.6.4, F.6
26554    <errno.h>, 7.5, 7.30.3, K.3.2                                selection, 6.8.4
26555    <fenv.h>, 5.1.2.3, 5.2.4.2.2, 7.6, 7.12, F, H                sequencing, 6.8
26556    <float.h>, 4, 5.2.4.2.2, 7.7, 7.22.1.3,                      switch, 6.8.4.2
26557         7.28.4.1.1                                              while, 6.8.5.1
26558    <inttypes.h>, 7.8, 7.30.4                                 static assertions, 6.7.10
26559    <iso646.h>, 4, 7.9                                        static storage duration, 6.2.4
26560    <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
26561    <locale.h>, 7.11, 7.30.5                                  static, in array declarators, 6.7.6.2, 6.7.6.3
26562    <math.h>, 5.2.4.2.2, 6.5, 7.12, 7.24, F, F.10,            static_assert declaration, 6.7.10
26563         J.5.17                                               static_assert macro, 7.2
26564    <setjmp.h>, 7.13                                          stdalign.h header, 4, 7.15
26565    <signal.h>, 7.14, 7.30.6                                  stdarg.h header, 4, 6.7.6.3, 7.16
26566    <stdalign.h>, 4, 7.15                                     stdatomic.h header, 6.10.8.3, 7.1.2, 7.17
26567    <stdarg.h>, 4, 6.7.6.3, 7.16                              stdbool.h header, 4, 7.18, 7.30.7, H
26568    <stdatomic.h>, 6.10.8.3, 7.1.2, 7.17                      STDC, 6.10.6, 6.11.8
26569    <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,
26570    <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
26571         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
26572    <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,
26573         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,
26574    <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
26575    <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,
26576         K.3.1.4, K.3.6                                             7.30.8, K.3.3, K.3.4
26577    <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
26578    <tgmath.h>, 7.24, G.7                                     stdlib.h header, 5.2.4.2.2, 7.22, 7.30.10, F,
26579    <threads.h>, 6.10.8.3, 7.1.2, 7.25                              K.3.1.4, K.3.6
26580    <time.h>, 7.26, K.3.8                                     stdout macro, 7.21.1, 7.21.2, 7.21.3, 7.21.6.3,
26581    <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
26582    <wchar.h>, 5.2.4.2.2, 7.21.1, 7.28, 7.30.12,              storage duration, 6.2.4
26583         F, K.3.9                                             storage order of array, 6.5.2.1
26584    <wctype.h>, 7.29, 7.30.13                                 storage unit (bit-field), 6.2.6.1, 6.7.2.1
26585 standard input stream, 7.21.1, 7.21.3                        storage-class specifiers, 6.7.1, 6.11.5
26586 standard integer types, 6.2.5                                strcat function, 7.23.3.1
26587 standard output stream, 7.21.1, 7.21.3                       strcat_s function, K.3.7.2.1
26588 standard signed integer types, 6.2.5                         strchr function, 7.23.5.2
26589 state-dependent encoding, 5.2.1.2, 7.22.7, K.3.6.4           strcmp function, 7.23.4, 7.23.4.2
26590 statements, 6.8                                              strcoll function, 7.11.1.1, 7.23.4.3, 7.23.4.5
26591    break, 6.8.6.3                                            strcpy function, 7.23.2.3
26592    compound, 6.8.2                                           strcpy_s function, K.3.7.1.3
26593    continue, 6.8.6.2                                         strcspn function, 7.23.5.3
26594    do, 6.8.5.2                                               streams, 7.21.2, 7.22.4.4
26595    else, 6.8.4.1                                                fully buffered, 7.21.3
26596
26597 [page 673]
26598
26599    line buffered, 7.21.3                                           strtoumax function, 7.8.2.3
26600    orientation, 7.21.2                                             struct hack, see flexible array member
26601    standard error, 7.21.1, 7.21.3                                  struct lconv, 7.11
26602    standard input, 7.21.1, 7.21.3                                  struct tm, 7.26.1
26603    standard output, 7.21.1, 7.21.3                                 structure
26604    unbuffered, 7.21.3                                                 arrow operator (->), 6.5.2.3
26605 strerror function, 7.21.10.4, 7.23.6.2                                content, 6.7.2.3
26606 strerror_s function, K.3.7.4.2, K.3.7.4.3                             dot operator (.), 6.5.2.3
26607 strerrorlen_s function, K.3.7.4.3                                     initialization, 6.7.9
26608 strftime function, 7.11.1.1, 7.26.3, 7.26.3.5,                        member alignment, 6.7.2.1
26609       7.28.5.1, K.3.8.2, K.3.8.2.1, K.3.8.2.2                         member name space, 6.2.3
26610 stricter, 6.2.8                                                       member operator (.), 6.3.2.1, 6.5.2.3
26611 strictly conforming program, 4                                        pointer operator (->), 6.5.2.3
26612 string, 7.1.1                                                         specifier, 6.7.2.1
26613    comparison functions, 7.23.4                                       tag, 6.2.3, 6.7.2.3
26614    concatenation functions, 7.23.3, K.3.7.2                           type, 6.2.5, 6.7.2.1
26615    conversion functions, 7.11.1.1                                  strxfrm function, 7.11.1.1, 7.23.4.5
26616    copying functions, 7.23.2, K.3.7.1                              subnormal floating-point numbers, 5.2.4.2.2
26617    library function conventions, 7.23.1                            subscripting, 6.5.2.1
26618    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
26619    miscellaneous functions, 7.23.6, K.3.7.4                        subtraction operator (-), 6.2.6.2, 6.5.6, F.3, G.5.2
26620    numeric conversion functions, 7.8.2.3, 7.22.1                   suffix
26621    search functions, 7.23.5, K.3.7.3                                  floating constant, 6.4.4.2
26622 string handling header, 7.23, K.3.7                                   integer constant, 6.4.4.1
26623 string.h header, 7.23, 7.30.11, K.3.7                              switch body, 6.8.4.2
26624 stringizing, 6.10.3.2, 6.10.9                                      switch case label, 6.8.1, 6.8.4.2
26625 strlen function, 7.23.6.3                                          switch default label, 6.8.1, 6.8.4.2
26626 strncat function, 7.23.3.2                                         switch statement, 6.8.1, 6.8.4.2
26627 strncat_s function, K.3.7.2.2                                      swprintf function, 7.28.2.3, 7.28.2.7,
26628 strncmp function, 7.23.4, 7.23.4.4                                       K.3.9.1.3, K.3.9.1.4
26629 strncpy function, 7.23.2.4                                         swprintf_s function, K.3.9.1.3, K.3.9.1.4
26630 strncpy_s function, K.3.7.1.4                                      swscanf function, 7.28.2.4, 7.28.2.8
26631 strnlen_s function, K.3.7.4.4                                      swscanf_s function, K.3.9.1.5, K.3.9.1.10
26632 stronger, 6.2.8                                                    symbols, 3
26633 strpbrk function, 7.23.5.4                                         synchronization operation, 5.1.2.4
26634 strrchr function, 7.23.5.5                                         synchronize with, 5.1.2.4
26635 strspn function, 7.23.5.6                                          syntactic categories, 6.1
26636 strstr function, 7.23.5.7                                          syntax notation, 6.1
26637 strtod function, 7.12.11.2, 7.21.6.2, 7.22.1.3,                    syntax rule precedence, 5.1.1.2
26638       7.28.2.2, F.3                                                syntax summary, language, A
26639 strtof function, 7.12.11.2, 7.22.1.3, F.3                          system function, 7.22.4.8
26640 strtoimax function, 7.8.2.3
26641 strtok function, 7.23.5.8                                          tab characters, 5.2.1, 6.4
26642 strtok_s function, K.3.7.3.1                                       tag compatibility, 6.2.7
26643 strtol function, 7.8.2.3, 7.21.6.2, 7.22.1.2,                      tag name space, 6.2.3
26644       7.22.1.4, 7.28.2.2                                           tags, 6.7.2.3
26645 strtold function, 7.12.11.2, 7.22.1.3, F.3                         tan functions, 7.12.4.7, F.10.1.7
26646 strtoll function, 7.8.2.3, 7.22.1.2, 7.22.1.4                      tan type-generic macro, 7.24, G.7
26647 strtoul function, 7.8.2.3, 7.21.6.2, 7.22.1.2,                     tanh functions, 7.12.5.6, F.10.2.6
26648       7.22.1.4, 7.28.2.2                                           tanh type-generic macro, 7.24, G.7
26649 strtoull function, 7.8.2.3, 7.22.1.2, 7.22.1.4                     temporary lifetime, 6.2.4
26650
26651 [page 674]
26652
26653 tentative definition, 6.9.2                                    towlower function, 7.29.3.1.1, 7.29.3.2.1
26654 terms, 3                                                      towupper function, 7.29.3.1.2, 7.29.3.2.1
26655 text streams, 7.21.2, 7.21.7.10, 7.21.9.2, 7.21.9.4           translation environment, 5, 5.1.1
26656 tgamma functions, 7.12.8.4, F.10.5.4                          translation limits, 5.2.4.1
26657 tgamma type-generic macro, 7.24                               translation phases, 5.1.1.2
26658 tgmath.h header, 7.24, G.7                                    translation unit, 5.1.1.1, 6.9
26659 thrd_create function, 7.25.1, 7.25.5.1                        trap, see perform a trap
26660 thrd_current function, 7.25.5.2                               trap representation, 3.19.4, 6.2.6.1, 6.2.6.2,
26661 thrd_detach function, 7.25.5.3, 7.25.5.6                            6.3.2.3, 6.5.2.3
26662 thrd_equal function, 7.25.5.4                                 trigonometric functions
26663 thrd_exit function, 7.25.5.5                                     complex, 7.3.5, G.6.1
26664 thrd_join function, 7.25.5.3, 7.25.5.6                           real, 7.12.4, F.10.1
26665 thrd_sleep function, 7.25.5.7                                 trigraph sequences, 5.1.1.2, 5.2.1.1
26666 thrd_start_t type, 7.25.1                                     true macro, 7.18
26667 thrd_t type, 7.25.1                                           trunc functions, 7.12.9.8, F.10.6.8
26668 thrd_yield function, 7.25.5.8                                 trunc type-generic macro, 7.24
26669 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
26670 thread storage duration, 6.2.4, 7.6                           truncation toward zero, 6.5.5
26671 threads header, 7.25                                          tss_create function, 7.25.6.1
26672 threads.h header, 6.10.8.3, 7.1.2, 7.25                       tss_delete function, 7.25.6.2
26673 time                                                          TSS_DTOR_ITERATIONS macro, 7.25.1
26674    broken down, 7.26.1, 7.26.2.3, 7.26.3, 7.26.3.1,           tss_dtor_t type, 7.25.1
26675          7.26.3.3, 7.26.3.4, 7.26.3.5, K.3.8.2.1,             tss_get function, 7.25.6.3
26676          K.3.8.2.3, K.3.8.2.4                                 tss_set function, 7.25.6.4
26677    calendar, 7.26.1, 7.26.2.2, 7.26.2.3, 7.26.2.4,            tss_t type, 7.25.1
26678          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
26679          K.3.8.2.3, K.3.8.2.4                                 type category, 6.2.5
26680    components, 7.26.1, K.3.8.1                                type conversion, 6.3
26681    conversion functions, 7.26.3, K.3.8.2                      type definitions, 6.7.8
26682       wide character, 7.28.5                                  type domain, 6.2.5, G.2
26683    local, 7.26.1                                              type names, 6.7.7
26684    manipulation functions, 7.26.2                             type punning, 6.5.2.3
26685    normalized broken down, K.3.8.1, K.3.8.2.1                 type qualifiers, 6.7.3
26686 time function, 7.26.2.4                                       type specifiers, 6.7.2
26687 time.h header, 7.26, K.3.8                                    type-generic macro, 7.24, G.7
26688 time_t type, 7.26.1                                           typedef declaration, 6.7.8
26689 TIME_UTC macro, 7.25.7.1                                      typedef storage-class specifier, 6.7.1, 6.7.8
26690 tm structure type, 7.26.1, 7.28.1, K.3.8.1                    types, 6.2.5
26691 TMP_MAX macro, 7.21.1, 7.21.4.3, 7.21.4.4                        _Atomic qualified, 6.2.5, 6.2.6.1, 6.5.2.3,
26692 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, 6.7.3
26693 tmpfile function, 7.21.4.3, 7.22.4.4                             atomic, 5.1.2.3, 6.10.8.3, 7.17.6
26694 tmpfile_s function, K.3.5.1.1, K.3.5.1.2                         character, 6.7.9
26695 tmpnam function, 7.21.1, 7.21.4.3, 7.21.4.4,                     compatible, 6.2.7, 6.7.2, 6.7.3, 6.7.6
26696       K.3.5.1.2                                                  complex, 6.2.5, G
26697 tmpnam_s function, K.3.5, K.3.5.1.1, K.3.5.1.2                   composite, 6.2.7
26698 token, 5.1.1.2, 6.4, see also preprocessing tokens               const qualified, 6.7.3
26699 token concatenation, 6.10.3.3                                    conversions, 6.3
26700 token pasting, 6.10.3.3                                          imaginary, G
26701 tolower function, 7.4.2.1                                        restrict qualified, 6.7.3
26702 toupper function, 7.4.2.2                                        volatile qualified, 6.7.3
26703 towctrans function, 7.29.3.2.1, 7.29.3.2.2
26704
26705 [page 675]
26706
26707 uchar.h header, 6.4.4.4, 6.4.5, 7.27                      universal character name, 6.4.3
26708 UCHAR_MAX macro, 5.2.4.2.1                                unnormalized floating-point numbers, 5.2.4.2.2
26709 UINT_FASTN_MAX macros, 7.20.2.3                           unqualified type, 6.2.5
26710 uint_fastN_t types, 7.20.1.3                              unqualified version of type, 6.2.5
26711 uint_least16_t type, 7.27                                 unsequenced, 5.1.2.3, 6.5, 6.5.16, see also
26712 uint_least32_t type, 7.27                                       indeterminately sequenced, sequenced
26713 UINT_LEASTN_MAX macros, 7.20.2.2                                before
26714 uint_leastN_t types, 7.20.1.2                             unsigned char type, K.3.5.3.2, K.3.9.1.2
26715 UINT_MAX macro, 5.2.4.2.1                                 unsigned integer suffix, u or U, 6.4.4.1
26716 UINTMAX_C macro, 7.20.4.2                                 unsigned integer types, 6.2.5, 6.3.1.3, 6.4.4.1
26717 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,
26718 uintmax_t type, 7.20.1.5, 7.21.6.1, 7.21.6.2,                   6.3.1.4, 6.3.1.8
26719      7.28.2.1, 7.28.2.2                                   unsigned types, 6.2.5, 6.7.2, 7.21.6.1, 7.21.6.2,
26720 UINTN_C macros, 7.20.4.1                                        7.28.2.1, 7.28.2.2
26721 UINTN_MAX macros, 7.20.2.1                                unspecified behavior, 3.4.4, 4, J.1
26722 uintN_t types, 7.20.1.1                                   unspecified value, 3.19.3
26723 UINTPTR_MAX macro, 7.20.2.4                               uppercase letter, 5.2.1
26724 uintptr_t type, 7.20.1.4                                  use of library functions, 7.1.4
26725 ULLONG_MAX macro, 5.2.4.2.1, 7.22.1.4,                    USHRT_MAX macro, 5.2.4.2.1
26726      7.28.4.1.2                                           usual arithmetic conversions, 6.3.1.8, 6.5.5, 6.5.6,
26727 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
26728      7.28.4.1.2                                           UTF-16, 6.10.8.2
26729 unary arithmetic operators, 6.5.3.3                       UTF-32, 6.10.8.2
26730 unary expression, 6.5.3                                   UTF-8 string literal, see string literal
26731 unary minus operator (-), 6.5.3.3, F.3                    utilities, general, 7.22, K.3.6
26732 unary operators, 6.5.3                                       wide string, 7.28.4, K.3.9.2
26733 unary plus operator (+), 6.5.3.3
26734 unbuffered stream, 7.21.3                                 va_arg macro, 7.16, 7.16.1, 7.16.1.1, 7.16.1.2,
26735 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,
26736      7.1.4                                                     7.21.6.11, 7.21.6.12, 7.21.6.13, 7.21.6.14,
26737 undefined behavior, 3.4.3, 4, J.2                               7.28.2.5, 7.28.2.6, 7.28.2.7, 7.28.2.8,
26738 underscore character, 6.4.2.1                                  7.28.2.9, 7.28.2.10, K.3.5.3.9, K.3.5.3.11,
26739 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
26740 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,
26741      7.21.9.3                                                  7.16.1.2, 7.16.1.3
26742 ungetwc function, 7.21.1, 7.28.3.10                       va_end macro, 7.1.3, 7.16, 7.16.1, 7.16.1.3,
26743 Unicode, 7.27, see also char16_t type,                         7.16.1.4, 7.21.6.8, 7.21.6.9, 7.21.6.10,
26744      char32_t type, wchar_t type                               7.21.6.11, 7.21.6.12, 7.21.6.13, 7.21.6.14,
26745 Unicode required set, 6.10.8.2                                 7.28.2.5, 7.28.2.6, 7.28.2.7, 7.28.2.8,
26746 union                                                          7.28.2.9, 7.28.2.10, K.3.5.3.9, K.3.5.3.11,
26747   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
26748   content, 6.7.2.3                                        va_list type, 7.16, 7.16.1.3
26749   dot operator (.), 6.5.2.3                               va_start macro, 7.16, 7.16.1, 7.16.1.1,
26750   initialization, 6.7.9                                        7.16.1.2, 7.16.1.3, 7.16.1.4, 7.21.6.8,
26751   member alignment, 6.7.2.1                                    7.21.6.9, 7.21.6.10, 7.21.6.11, 7.21.6.12,
26752   member name space, 6.2.3                                     7.21.6.13, 7.21.6.14, 7.28.2.5, 7.28.2.6,
26753   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,
26754   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,
26755   specifier, 6.7.2.1                                            K.3.9.1.10, K.3.9.1.12
26756   tag, 6.2.3, 6.7.2.3                                     value, 3.19
26757   type, 6.2.5, 6.7.2.1                                    value bits, 6.2.6.2
26758
26759 [page 676]
26760
26761 variable arguments, 6.10.3, 7.16                             vswscanf function, 7.28.2.8
26762 variable arguments header, 7.16                              vswscanf_s function, K.3.9.1.10
26763 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
26764 variably modified type, 6.7.6, 6.7.6.2, 6.10.8.3              vwprintf_s function, K.3.9.1.11
26765 vertical-tab character, 5.2.1, 6.4                           vwscanf function, 7.21.1, 7.28.2.10, 7.28.3.10
26766 vertical-tab escape sequence (\v), 5.2.2, 6.4.4.4,           vwscanf_s function, K.3.9.1.12
26767      7.4.1.10
26768 vfprintf function, 7.21.1, 7.21.6.8, K.3.5.3.8               warnings, I
26769 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,
26770      K.3.5.3.11, K.3.5.3.14                                      F, K.3.9
26771 vfscanf function, 7.21.1, 7.21.6.8, 7.21.6.9                 WCHAR_MAX macro, 7.20.3, 7.28.1
26772 vfscanf_s function, K.3.5.3.9, K.3.5.3.11,                   WCHAR_MIN macro, 7.20.3, 7.28.1
26773      K.3.5.3.14                                              wchar_t type, 3.7.3, 6.4.5, 6.7.9, 6.10.8.2, 7.19,
26774 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,
26775 vfwprintf_s function, K.3.9.1.6                                  7.28.2.1, 7.28.2.2
26776 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,
26777 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,
26778 visibility of identifier, 6.2.1                                   K.3.9.3.2.2
26779 visible sequence of side effects, 5.1.2.4                    wcrtomb_s function, K.3.9.3.1, K.3.9.3.1.1
26780 visible side effect, 5.1.2.4                                 wcscat function, 7.28.4.3.1
26781 VLA, see variable length array                               wcscat_s function, K.3.9.2.2.1
26782 void expression, 6.3.2.2                                     wcschr function, 7.28.4.5.1
26783 void function parameter, 6.7.6.3                             wcscmp function, 7.28.4.4.1, 7.28.4.4.4
26784 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
26785      K.3.9.1.2                                               wcscpy function, 7.28.4.2.1
26786 void type conversion, 6.3.2.2                                wcscpy_s function, K.3.9.2.1.1
26787 volatile storage, 5.1.2.3                                    wcscspn function, 7.28.4.5.2
26788 volatile type qualifier, 6.7.3                                wcsftime function, 7.11.1.1, 7.28.5.1
26789 volatile-qualified type, 6.2.5, 6.7.3                         wcslen function, 7.28.4.6.1
26790 vprintf function, 7.21.1, 7.21.6.8, 7.21.6.10,               wcsncat function, 7.28.4.3.2
26791      K.3.5.3.10                                              wcsncat_s function, K.3.9.2.2.2
26792 vprintf_s function, K.3.5.3.9, K.3.5.3.10,                   wcsncmp function, 7.28.4.4.3
26793      K.3.5.3.11, K.3.5.3.14                                  wcsncpy function, 7.28.4.2.2
26794 vscanf function, 7.21.1, 7.21.6.8, 7.21.6.11                 wcsncpy_s function, K.3.9.2.1.2
26795 vscanf_s function, K.3.5.3.9, K.3.5.3.11,                    wcsnlen_s function, K.3.9.2.4.1
26796      K.3.5.3.14                                              wcspbrk function, 7.28.4.5.3
26797 vsnprintf function, 7.21.6.8, 7.21.6.12,                     wcsrchr function, 7.28.4.5.4
26798      K.3.5.3.12                                              wcsrtombs function, 7.28.6.4.2, K.3.9.3.2
26799 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
26800      K.3.5.3.12, K.3.5.3.13, K.3.5.3.14                      wcsspn function, 7.28.4.5.5
26801 vsnwprintf_s function, K.3.9.1.8, K.3.9.1.9                  wcsstr function, 7.28.4.5.6
26802 vsprintf function, 7.21.6.8, 7.21.6.13,                      wcstod function, 7.21.6.2, 7.28.2.2
26803      K.3.5.3.13                                              wcstod function, 7.28.4.1.1
26804 vsprintf_s function, K.3.5.3.9, K.3.5.3.11,                  wcstof function, 7.28.4.1.1
26805      K.3.5.3.12, K.3.5.3.13, K.3.5.3.14                      wcstoimax function, 7.8.2.4
26806 vsscanf function, 7.21.6.8, 7.21.6.14                        wcstok function, 7.28.4.5.7
26807 vsscanf_s function, K.3.5.3.9, K.3.5.3.11,                   wcstok_s function, K.3.9.2.3.1
26808      K.3.5.3.14                                              wcstol function, 7.8.2.4, 7.21.6.2, 7.28.2.2,
26809 vswprintf function, 7.28.2.7, K.3.9.1.8,                         7.28.4.1.2
26810      K.3.9.1.9                                               wcstold function, 7.28.4.1.1
26811 vswprintf_s function, K.3.9.1.8, K.3.9.1.9                   wcstoll function, 7.8.2.4, 7.28.4.1.2
26812
26813 [page 677]
26814
26815 wcstombs function, 7.22.8.2, 7.28.6.4                           7.29.1
26816 wcstombs_s function, K.3.6.5.2                               wmemchr function, 7.28.4.5.8
26817 wcstoul function, 7.8.2.4, 7.21.6.2, 7.28.2.2,               wmemcmp function, 7.28.4.4.5
26818      7.28.4.1.2                                              wmemcpy function, 7.28.4.2.3
26819 wcstoull function, 7.8.2.4, 7.28.4.1.2                       wmemcpy_s function, K.3.9.2.1.3
26820 wcstoumax function, 7.8.2.4                                  wmemmove function, 7.28.4.2.4
26821 wcsxfrm function, 7.28.4.4.4                                 wmemmove_s function, K.3.9.2.1.4
26822 wctob function, 7.28.6.1.2, 7.29.2.1                         wmemset function, 7.28.4.6.2
26823 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,
26824 wctomb_s function, K.3.6.4.1                                    K.3.9.1.13
26825 wctrans function, 7.29.3.2.1, 7.29.3.2.2                     wprintf_s function, K.3.9.1.13
26826 wctrans_t type, 7.29.1, 7.29.3.2.2                           wscanf function, 7.21.1, 7.28.2.10, 7.28.2.12,
26827 wctype function, 7.29.2.2.1, 7.29.2.2.2                         7.28.3.10
26828 wctype.h header, 7.29, 7.30.13                               wscanf_s function, K.3.9.1.12, K.3.9.1.14
26829 wctype_t type, 7.29.1, 7.29.2.2.2
26830 weaker, 6.2.8                                                xor macro, 7.9
26831 WEOF macro, 7.28.1, 7.28.3.1, 7.28.3.3, 7.28.3.6,            xor_eq macro, 7.9
26832      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,
26833      7.28.6.1.1, 7.29.1                                          7.25.7.1
26834 while statement, 6.8.5.1                                     xtime_get function, 7.25.7.1
26835 white space, 5.1.1.2, 6.4, 6.10, 7.4.1.10,
26836      7.29.2.1.10
26837 white-space characters, 6.4
26838 wide character, 3.7.3
26839   case mapping functions, 7.29.3.1
26840      extensible, 7.29.3.2
26841   classification functions, 7.29.2.1
26842      extensible, 7.29.2.2
26843   constant, 6.4.4.4
26844   formatted input/output functions, 7.28.2,
26845         K.3.9.1
26846   input functions, 7.21.1
26847   input/output functions, 7.21.1, 7.28.3
26848   output functions, 7.21.1
26849   single-byte conversion functions, 7.28.6.1
26850 wide string, 7.1.1
26851 wide string comparison functions, 7.28.4.4
26852 wide string concatenation functions, 7.28.4.3,
26853      K.3.9.2.2
26854 wide string copying functions, 7.28.4.2, K.3.9.2.1
26855 wide string literal, see string literal
26856 wide string miscellaneous functions, 7.28.4.6,
26857      K.3.9.2.4
26858 wide string numeric conversion functions, 7.8.2.4,
26859      7.28.4.1
26860 wide string search functions, 7.28.4.5, K.3.9.2.3
26861 wide-oriented stream, 7.21.2
26862 width, 6.2.6.2
26863 WINT_MAX macro, 7.20.3
26864 WINT_MIN macro, 7.20.3
26865 wint_t type, 7.20.3, 7.21.6.1, 7.28.1, 7.28.2.1,
26866
26867 [page 678]