Linguagem de Programação C - NORMA ISO/IEC 9899TC2

Linguagem de Programação C - NORMA ISO/IEC 9899TC2

(Parte 1 de 11)

WG14/N1124 CommitteeDraft — May 6, 2005ISO/IEC 9899:TC2

Forewordxi
Introductionxiv
1. Scope1
2. Normati ve references2
3. Terms, definitions, and symbols3
4. Conformance7
5. En vironment9
5.1 Conceptual models9
5.1.1 T ranslation environment9
5.1.2 Ex ecution environments1
5.2 En vironmental considerations17
5.2.1 Character sets17
5.2.2 Character display semantics19
5.2.3 Signals and interrupts20
5.2.4 En vironmental limits20
6. Language29
6.1 Notation29
6.2 Concepts29
6.2.1 Scopes of identifiers29
6.2.2 Linkages of identifiers30
6.2.3 Namespaces of identifiers31
6.2.4 Storagedurations of objects32
6.2.5 T ypes3
6.2.6 Representations of types37
6.2.7 Compatibletype and composite type40
6.3 Con versions42
6.3.1 Arithmetic operands42
6.3.2 Other operands46
6.4 Le xical elements49
6.4.1 K eywords50
6.4.2 Identifiers51
6.4.3 Universal character names53
6.4.4 Constants54
6.4.5 String literals62
6.4.6 Punctuators63
6.4.7 Header names64
6.4.8 Preprocessing numbers65
6.4.9 Comments6
6.5 Expressions67

Contents Contents i

6.5.1 Primary expressions69
6.5.2 Postfix operators69
6.5.3 Unary operators78
6.5.4 Cast operators81
6.5.5 Multiplicati ve operators82
6.5.6 Additi ve operators82
6.5.7 Bitwise shift operators84
6.5.8 Relational operators85
6.5.9 Equality operators86
6.5.10 Bitwise AND operator87
6.5.1 Bitwise exclusive OR operator8
6.5.12 Bitwise inclusive OR operator8
6.5.13 Logical AND operator89
6.5.14 Logical OR operator89
6.5.15 Conditional operator90
6.5.16 Assignment operators91
6.5.17 Comma operator94
6.6 Constant expressions95
6.7 Declarations97
6.7.1 Storage-class specifiers98
6.7.2 T ype specifiers9
6.7.3 T ype qualifiers108
6.7.4 Function specifiers112
6.7.5 Declarators114
6.7.6 T ype names122
6.7.7 T ype definitions123
6.7.8 Initialization125
6.8 Statements and blocks131
6.8.1 Labeled statements131
6.8.2 Compound statement132
6.8.3 Expressionand null statements132
6.8.4 Selection statements133
6.8.5 Iteration statements135
6.8.6 Jump statements136
6.9 External definitions140
6.9.1 Function definitions141
6.9.2 External object definitions143
6.10 Preprocessing directives145
6.10.1 Conditional inclusion147
6.10.2 Source file inclusion149
6.10.3 Macro replacement151
6.10.4 Line control158
6.10.5 Error directive159
6.10.6 Pragma directive159

ISO/IEC 9899:TC2Committee Draft — May 6, 2005WG14/N1124 iv Contents

6.10.7 Null directive160
6.10.8 Predefined macro names160
6.10.9 Pragma operator161
6.1 Future language directions163
6.1.1 Floating types163
6.1.2 Linkages of identifiers163
6.1.3 External names163
6.1.4 Character escape sequences163
6.1.5 Storage-class specifiers163
6.1.6 Function declarators163
6.1.7 Function definitions163
6.1.8 Pragma directives163
6.1.9 Predefined macro names163
7. Library164
7.1 Introduction164
7.1.1 Definitions of terms164
7.1.2 Standard headers165
7.1.3 Reserv ed identifiers166
7.1.4 Useof library functions166
7.2 Diagnostics <assert.h>169
7.2.1 Program diagnostics169
7.3 Comple x arithmetic <complex.h>170
7.3.1 Introduction170
7.3.2 Con ventions170
7.3.3 Branch cuts171
7.3.4 The CX_LIMITED_RANGE pragma171
7.3.5 T rigonometric functions172
7.3.6 Hyperbolic functions174
7.3.7 Exponentialand logarithmic functions176
7.3.8 Power and absolute-value functions177
7.3.9 Manipulation functions178
7.4 Character handling <ctype.h>181
7.4.1 Character classification functions181
7.4.2 Charactercase mapping functions184
7.5 Errors <errno.h>186
7.6 Floating-point environment <fenv.h>187
7.6.1 The FENV_ACCESS pragma189
7.6.2 Floating-point exceptions190
7.6.3 Rounding193
7.6.4 En vironment194
7.7 Characteristicsof floating types<float.h>197
7.8 Format conversion of integer types<inttypes.h>198
7.8.1 Macrosfor format specifiers198
7.8.2 Functionsfor greatest-width integer types199

WG14/N1124 CommitteeDraft — May 6, 2005ISO/IEC 9899:TC2 Contents v

7.9 Alternati ve spellings <iso646.h>202
7.10 Sizesof integer types<limits.h>203
7.1 Localization <locale.h>204
7.1.1 Locale control205
7.1.2 Numericformatting convention inquiry206
7.12 Mathematics <math.h>212
7.12.1 Treatment of error conditions214
7.12.2 The FP_CONTRACT pragma215
7.12.3 Classification macros216
7.12.4 T rigonometric functions218
7.12.5 Hyperbolic functions221
7.12.6 Exponentialand logarithmic functions223
7.12.7 Power and absolute-value functions228
7.12.8 Errorand gamma functions230
7.12.9 Nearest integer functions231
7.12.10 Remainder functions235
7.12.1 Manipulation functions236
7.12.13 Floating multiply-add239
7.12.14 Comparison macros240
7.13 Nonlocal jumps <setjmp.h>243
7.13.1 Save calling environment243
7.13.2 Restore calling environment244
7.14 Signal handling <signal.h>246
7.14.1 Specify signal handling247
7.14.2 Send signal248
7.15 V ariable arguments <stdarg.h>249
7.15.1 Variable argument list access macros249
7.16 Booleantype and values<stdbool.h>253
7.17 Common definitions <stddef.h>254
7.18 Inte ger types <stdint.h>255
7.18.1 Inte ger types255
7.18.2 Limitsof specified-width integer types257
7.18.3 Limitsof other integer types259
7.18.4 Macrosfor integer constants260
7.19 Input/output <stdio.h>262
7.19.1 Introduction262
7.19.2 Streams264
7.19.3 Files266
7.19.4 Operations on files268
7.19.5 File access functions270
7.19.6 Formatted input/output functions274
7.19.7 Character input/output functions296
7.19.8 Direct input/output functions301

ISO/IEC 9899:TC2Committee Draft — May 6, 2005WG14/N1124 7.12.12 Maximum,minimum, and positive difference functions...238 vi Contents

7.19.9 File positioning functions302
7.19.10 Error -handling functions304
7.20 General utilities <stdlib.h>306
7.20.1 Numeric conversion functions307
7.20.2 Pseudo-randomsequence generation functions312
7.20.3 Memory management functions313
7.20.4 Communicationwith the environment315
7.20.5 Searchingand sorting utilities318
7.20.6 Integer arithmetic functions320
7.20.7 Multibyte/wide character conversion functions321
7.20.8 Multibyte/widestring conversion functions323
7.21 String handling <string.h>325
7.21.1 String function conventions325
7.21.2 Cop ying functions325
7.21.3 Concatenation functions327
7.21.4 Comparison functions328
7.21.5 Search functions330
7.21.6 Miscellaneous functions3
7.2 T ype-generic math <tgmath.h>335
7.23 Date and time <time.h>338
7.23.1 Components of time338
7.23.2 Time manipulation functions339
7.23.3 Time conversion functions341
7.24 Extendedmultibyte and wide character utilities<wchar.h>348
7.24.1 Introduction348
7.24.2 Formatted wide character input/output functions349
7.24.3 Wide character input/output functions367
7.24.4 Generalwide string utilities371
7.24.5 Wide character time conversion functions385
7.24.6 Extendedmultibyte/wide character conversion utilities386
7.25.1 Introduction393
7.25.2 Wide character classification utilities394
7.25.3 Wide character case mapping utilities399
7.26 Future library directions401
7.26.1 Comple x arithmetic <complex.h>401
7.26.2 Character handling <ctype.h>401
7.26.3 Errors <errno.h>401
7.26.4 Format conversion of integer types<inttypes.h>401
7.26.5 Localization <locale.h>401
7.26.6 Signal handling <signal.h>401
7.26.7 Booleantype and values<stdbool.h>401
7.26.8 Inte ger types <stdint.h>401
7.26.9 Input/output <stdio.h>402

WG14/N1124 CommitteeDraft — May 6, 2005ISO/IEC 9899:TC2 7.25 Wide character classification and mapping utilities<wctype.h>...393 Contents vii

7.26.10 General utilities <stdlib.h>402
7.26.1 String handling <string.h>402
<wchar.h>402
<wctype.h>402
Annex A (informative) Language syntax summary403
A.1 Le xical grammar403
A.2 Phrase structure grammar409
A.3 Preprocessing directives416
Annex B (informative) Library summary418
B.1 Diagnostics <assert.h>418
B.2 Comple x <complex.h>418
B.3 Character handling <ctype.h>420
B.4 Errors <errno.h>420
B.5 Floating-point environment <fenv.h>420
B.6 Characteristicsof floating types<float.h>421
B.7 Format conversion of integer types<inttypes.h>421
B.8 Alternati ve spellings <iso646.h>422
B.9 Sizesof integer types<limits.h>422
B.10 Localization <locale.h>422
B.1 Mathematics <math.h>422
B.12 Nonlocal jumps <setjmp.h>427
B.13 Signal handling <signal.h>427
B.14 Variable arguments <stdarg.h>427
B.15 Booleantype and values<stdbool.h>427
B.16 Common definitions <stddef.h>428
B.17 Inte ger types <stdint.h>428
B.18 Input/output <stdio.h>428
B.19 General utilities <stdlib.h>430
B.20 String handling <string.h>432
B.21 T ype-generic math <tgmath.h>433
B.2 Date and time <time.h>433
B.23 Extended multibyte/wide character utilities <wchar.h>434

ISO/IEC 9899:TC2Committee Draft — May 6, 2005WG14/N1124 7.26.12 Extendedmultibyte and wide character utilities 7.26.13 Wide character classification and mapping utilities B.24 Wide character classification and mapping utilities<wctype.h>...436

Annex C (informative) Sequence points438
AnnexD(normative)Universal character names for identifiers439
Annex E (informative) Implementation limits441
Annex F (normative) IEC 60559 floating-point arithmetic443
F.1 Introduction443
F.2 Types443
F.3 Operators and functions4

viii Contents

F.4Floating to integer conversion446
F.5 Binary-decimal conversion446
F.6 Contracted expressions447
F.7 Floating-point environment447
F.8 Optimization450
F.9 Mathematics <math.h>453
Annex G (informative) IEC 60559-compatible complex arithmetic466
G.1 Introduction466
G.2 T ypes466
G.3 Con ventions466
G.4 Con versions467
G.5 Binary operators467
G.6 Comple x arithmetic <complex.h>471
G.7 T ype-generic math <tgmath.h>479
Annex H (informative) Language independent arithmetic480
H.1 Introduction480
H.2 T ypes480
H.3 Notification484
Annex I (informative) Common warnings486
Annex J (informative) Portability issues488
J.1 Unspecified behavior488
J.2 Undefined behavior491
J.3 Implementation-defined behavior504
J.4 Locale-specific behavior511
J.5 Common extensions512
Bibliography515
Index517

WG14/N1124 CommitteeDraft — May 6, 2005ISO/IEC 9899:TC2 Contents ix

ISO/IEC 9899:TC2Committee Draft — May 6, 2005WG14/N1124 x Contents

WG14/N1124 CommitteeDraft — May 6, 2005ISO/IEC 9899:TC2

Foreword

1ISO (the International Organization for Standardization) and IEC (the International

Electrotechnical Commission) form the specialized system for worldwide standardization. Nationalbodies that are member of ISO or IEC participate in the development of International Standards through technical committees established by the respective org anization to deal with particular fields of technical activity.ISO and IEC technical committees collaborate in fields of mutual interest.Other international organizations, governmental and non-governmental, in liaison with ISO and IEC, also takepart in the work.

2International Standards are drafted in accordance with the rules giveninthe ISO/IEC Directives, Part 3.

3In the field of information technology,ISO and IEC have established a joint technical committee, ISO/IEC JTC1. DraftInternational Standards adopted by the joint technical committee are circulated to national bodies for voting. Publicationas an International Standard requires approvalbyatleast 75% of the national bodies casting a vote.

4International Standard ISO/IEC9899 was prepared by Joint Technical Committee

ISO/IEC JTC1,Information technology,Subcommittee SC22,Programming languages, their environments and system softwareinterfaces.The Working Group responsible for this standard (WG14) maintains a site on the World Wide Web at http://www.open-std.org/JTC1/SC22/WG14/ containing additional information relevant to this standard such as a Rationale for manyofthe decisions made during its preparation and a log of Defect Reports and Responses.

5This second edition cancels and replaces the first edition, ISO/IEC9899:1990, as amended and corrected by ISO/IEC9899/COR1:1994, ISO/IEC9899/AMD1:1995, and ISO/IEC 9899/COR2:1996.Major changes from the previous edition include:

—restricted character set support via digraphs and<iso646.h>(originally specified in AMD1)

—wide character library support in<wchar.h>and<wctype.h>(originally specified in AMD1)

—more precise aliasing rules via effective type

— restricted pointers

—variable length arrays

—flexible array members

—staticand type qualifiers in parameter array declarators

—complex(and imaginary) support in<complex.h>

—type-generic math macros in<tgmath.h>

—thelong long inttype and library functions

Foreword xi

ISO/IEC 9899:TC2Committee Draft — May 6, 2005WG14/N1124

—increased minimum translation limits —additional floating-point characteristics in<float.h>

—remove implicitint

—reliable integer division

—universal character names (\uand\U)

—hexadecimal floating-point constants and%aand%A printf/scanfconversion specifiers

—compound literals

— designated initializers

—extended integer types and library functions in<inttypes.h>and<stdint.h>

—remove implicit function declaration

—preprocessor arithmetic done inintmax_t/uintmax_t

—mixed declarations and code

—new block scopes for selection and iteration statements

—integer constant type rules

—integer promotion rules

—macros with a variable number of arguments

—thevscanffamily of functions in<stdio.h>and<wchar.h>

—additional math library functions in<math.h>

—treatment of error conditions by math library functions (math_errhandling)

—floating-point environment access in<fenv.h>

(Parte 1 de 11)

Comentários