Programming Languages Ð C
Total Page:16
File Type:pdf, Size:1020Kb
Programming languages Ð C ABSTRACT (Cover sheet to be provided by ISO Secretariat.) This International Standard speci®es the form and establishes the interpretation of programs expressed in the programming language C. Its purpose is to promote portability, reliability, maintainability, and ef®cient execution of C language programs on a variety of computing systems. Clauses are included that detail the C language itself and the contents of the C language execution library. Annexes summarize aspects of both of them, and enumerate factors that in¯uence the portability of C programs. Although this International Standard is intended to guide knowledgeable C language programmers as well as implementors of C language translation systems, the document itself is not designed to serve as a tutorial. -- -- Introduction 1 With the introduction of new devices and extended character sets, new features may be added to this International Standard. Subclauses in the language and library clauses warn implementors and programmers of usages which, though valid in themselves, may con¯ict with future additions. 2 Certain features are obsolescent, which means that they may be considered for withdrawal in future revisions of this International Standard. They are retained because of their widespread use, but their use in new implementations (for implementation features) or new programs (for language [6.9] or library features [7.20]) is discouraged. 3 This International Standard is divided into four major subdivisions: Ð the introduction and preliminary elements; Ð the characteristics of environments that translate and execute C programs; Ð the language syntax, constraints, and semantics; Ð the library facilities. 4 Examples are provided to illustrate possible forms of the constructions described. Footnotes are provided to emphasize consequences of the rules described in that subclause or elsewhere in this International Standard. References are used to refer to other related subclauses. A set of annexes summarizes information contained in this International Standard. The introduction, the examples, the footnotes, the references, and the annexes are not part of this International Standard. 5 The language clause (Clause 6) is derived from ``The C Reference Manual'' (see annex A). 6 The library clause (Clause 7) is based on the 1984 /usr/group Standard (see annex A). Contents 1. Scope . 1 2. Normative references . 2 3. De®nitions and conventions . 3 4. Compliance . 7 5. Environment . 8 5.1 Conceptual models . 8 5.1.1 Translation environment . 8 5.1.2 Execution environments . 11 5.2 Environmental considerations . 18 5.2.1 Character sets . 18 5.2.2 Character display semantics . 21 5.2.3 Signals and interrupts . 22 5.2.4 Environmental limits . 22 6. Language . 31 6.1 Lexical elements . 31 6.1.1 Keywords . 33 6.1.2 Identi®ers . 33 6.1.3 Constants . 46 6.1.4 String literals . 54 6.1.5 Operators . 55 6.1.6 Punctuators . 56 6.1.7 Header names . 57 6.1.8 Preprocessing numbers . 58 6.1.9 Comments . 59 6.2 Conversions . 60 6.2.1 Arithmetic operands . 60 6.2.2 Other operands . 63 6.3 Expressions . 67 6.3.1 Primary expressions . 69 6.3.2 Post®x operators . 70 6.3.3 Unary operators . 79 6.3.4 Cast operators . 83 6.3.5 Multiplicative operators . 84 6.3.6 Additive operators . 85 6.3.7 Bitwise shift operators . 87 6.3.8 Relational operators . 88 6.3.9 Equality operators . 89 6.3.10 Bitwise AND operator . 90 6.3.11 Bitwise exclusive OR operator . 90 6.3.12 Bitwise inclusive OR operator . 91 6.3.13 Logical AND operator . 91 6.3.14 Logical OR operator . 92 6.3.15 Conditional operator . 92 6.3.16 Assignment operators . 94 6.3.17 Comma operator . 96 6.4 Constant expressions . 98 6.5 Declarations . 100 6.5.1 Storage-class speci®ers . 101 6.5.2 Type speci®ers . 102 6.5.3 Type quali®ers . 111 6.5.4 Function speci®ers . 116 6.5.5 Declarators . 118 6.5.6 Type names . 127 6.5.7 Type de®nitions . 128 6.5.8 Initialization . 131 6.6 Statements . 139 6.6.1 Labeled statements . 139 6.6.2 Compound statement, or block . 140 6.6.3 Expression and null statements . 140 6.6.4 Selection statements . 141 6.6.5 Iteration statements . 143 6.6.6 Jump statements . 145 6.7 External de®nitions . 149 6.7.1 Function de®nitions . 150 6.7.2 External object de®nitions . 153 6.8 Preprocessing directives . 154 6.8.1 Conditional inclusion . 157 6.8.2 Source ®le inclusion . 159 6.8.3 Macro replacement . 160 6.8.4 Line control . 169 6.8.5 Error directive . 169 6.8.6 Pragma directive . 170 6.8.7 Null directive . 170 6.8.8 Prede®ned macro names . 170 6.8.9 Pragma operator . 172 6.9 Future language directions . 173 6.9.1 Character escape sequences . 173 6.9.2 Storage-class speci®ers . 173 6.9.3 Function declarators . 173 6.9.4 Function de®nitions . 173 6.9.5 Pragma directives . 173 7. Library . 174 7.1 Introduction . 174 7.1.1 De®nitions of terms . 174 7.1.2 Standard headers . 175 7.1.3 Reserved identi®ers . 176 7.1.4 Errors <errno.h> . 177 7.1.5 Limits <float.h> and <limits.h> . 178 7.1.6 Common de®nitions <stddef.h> . 178 7.1.7 Boolean type and values <stdbool.h> . 179 7.1.8 Use of library functions . 180 7.2 Diagnostics <assert.h> . 183 7.2.1 Program diagnostics . 183 7.3 Character handling <ctype.h> . 185 7.3.1 Character testing functions . 185 7.3.2 Character case mapping functions . 189 7.4 Integer types <inttypes.h> . 190 7.4.1 Typedef names for integer types . 190 7.4.2 Limits of speci®ed-width integer types . 193 7.4.3 Macros for integer constants . 195 7.4.4 Macros for format speci®ers . 196 7.4.5 Limits of other integer types . 199 7.4.6 Conversion functions for greatest-width integer types . 200 7.5 Localization <locale.h> . 202 7.5.1 Locale control . 203 7.5.2 Numeric formatting convention inquiry . 204 7.6 Floating-point environment <fenv.h> . 208 7.6.1 The FENV_ACCESS pragma . 210 7.6.2 Exceptions . 211 7.6.3 Rounding . 214 7.6.4 Environment . 215 7.7 Mathematics <math.h> . 218 7.7.1 Treatment of error conditions . 220 7.7.2 The FP_CONTRACT pragma . 221 7.7.3 Classi®cation macros . 222 7.7.4 Trigonometric functions . 225 7.7.5 Hyperbolic functions . 227 7.7.6 Exponential and logarithmic functions . 229 7.7.7 Power and absolute value functions . 234 7.7.8 Error and gamma functions . 236 7.7.9 Nearest integer functions . 237 7.7.10 Remainder functions . 240 7.7.11 Manipulation functions . 242 7.7.12 Maximum, minimum, and positive difference functions . 243 7.7.13 Floating multiply-add . 245 7.7.14 Comparison macros . 245 7.8 Complex arithmetic <complex.h> . 249 7.8.1 The CX_LIMITED_RANGE pragma . 249 7.8.2 Complex functions . 250 7.9 Type-generic math <tgmath.h> . 259 7.9.1 Type-generic macros . 259 7.10 Nonlocal jumps <setjmp.h> . 263 7.10.1 Save calling environment . 263 7.10.2 Restore calling environment . 264 7.11 Signal handling <signal.h> . 266 7.11.1 Specify signal handling . 267 7.11.2 Send signal . 268 7.12 Variable arguments <stdarg.h> . 269 7.12.1 Variable argument list access macros . 269 7.13 Input/output <stdio.h> . 274 7.13.1 Introduction . 274 7.13.2 Streams . 276 7.13.3 Files . 278 7.13.4 Operations on ®les . 280 7.13.5 File access functions . 282 7.13.6 Formatted input/output functions . 287 7.13.7 Character input/output functions . 309 7.13.8 Direct input/output functions . 315 7.13.9 File positioning functions . 316 7.13.10 Error-handling functions . 318 7.14 General utilities <stdlib.h> . 321 7.14.1 String conversion functions . 322 7.14.2 Pseudo-random sequence generation functions . 330 7.14.3 Memory management functions . 332 7.14.4 Communication with the environment . 334 7.14.5 Searching and sorting utilities . 336 7.14.6 Integer arithmetic functions . 338 7.14.7 Multibyte character functions . 340 7.14.8 Multibyte string functions . 343 7.15 String handling <string.h> . 345 7.15.1 String function conventions . 345 7.15.2 Copying functions . 345 7.15.3 Concatenation functions . 347 7.15.4 Comparison functions . 348 7.15.5 Search functions . 351 7.15.6 Miscellaneous functions . 355 7.16 Date and time <time.h> . 357 7.16.1 Components of time . 357 7.16.2 Time manipulation functions . 359 7.16.3 Time conversion functions . 364 7.17 Alternative spellings <iso646.h> . 370 7.18 Wide-character classi®cation and mapping utilities <wctype.h> . 371 7.18.1 Introduction . 371 7.18.2 Wide-character classi®cation utilities . 372 7.18.3 Wide-character mapping utilities . ..