ISO/IEC 9899:2011
(Main)Information technology - Programming languages - C
Information technology - Programming languages - C
ISO/IEC 9899:2011 specifies the form and establishes the interpretation of programs written in the C programming language.It specifies the representation of C programs; the syntax and constraints of the C language; the semantic rules for interpreting C programs; the representation of input data to be processed by C programs; the representation of output data produced by C programs; the restrictions and limits imposed by a conforming implementation of C. ISO/IEC 9899:2011 does not specify the mechanism by which C programs are transformed for use by a data-processing system; the mechanism by which C programs are invoked for use by a data-processing system; the mechanism by which input data are transformed for use by a C program; the mechanism by which output data are transformed after being produced by a C program; the size or complexity of a program and its data that will exceed the capacity of any specific data-processing system or the capacity of a particular processor; all minimal requirements of a data-processing system that is capable of supporting a conforming implementation. ISO/IEC 9899:2011 is designed to promote the portability of C programs among a variety of data-processing systems. It is intended for use by implementers and programmers.
Technologies de l'information — Langages de programmation — C
General Information
Relations
Frequently Asked Questions
ISO/IEC 9899:2011 is a standard published by the International Organization for Standardization (ISO). Its full title is "Information technology - Programming languages - C". This standard covers: ISO/IEC 9899:2011 specifies the form and establishes the interpretation of programs written in the C programming language.It specifies the representation of C programs; the syntax and constraints of the C language; the semantic rules for interpreting C programs; the representation of input data to be processed by C programs; the representation of output data produced by C programs; the restrictions and limits imposed by a conforming implementation of C. ISO/IEC 9899:2011 does not specify the mechanism by which C programs are transformed for use by a data-processing system; the mechanism by which C programs are invoked for use by a data-processing system; the mechanism by which input data are transformed for use by a C program; the mechanism by which output data are transformed after being produced by a C program; the size or complexity of a program and its data that will exceed the capacity of any specific data-processing system or the capacity of a particular processor; all minimal requirements of a data-processing system that is capable of supporting a conforming implementation. ISO/IEC 9899:2011 is designed to promote the portability of C programs among a variety of data-processing systems. It is intended for use by implementers and programmers.
ISO/IEC 9899:2011 specifies the form and establishes the interpretation of programs written in the C programming language.It specifies the representation of C programs; the syntax and constraints of the C language; the semantic rules for interpreting C programs; the representation of input data to be processed by C programs; the representation of output data produced by C programs; the restrictions and limits imposed by a conforming implementation of C. ISO/IEC 9899:2011 does not specify the mechanism by which C programs are transformed for use by a data-processing system; the mechanism by which C programs are invoked for use by a data-processing system; the mechanism by which input data are transformed for use by a C program; the mechanism by which output data are transformed after being produced by a C program; the size or complexity of a program and its data that will exceed the capacity of any specific data-processing system or the capacity of a particular processor; all minimal requirements of a data-processing system that is capable of supporting a conforming implementation. ISO/IEC 9899:2011 is designed to promote the portability of C programs among a variety of data-processing systems. It is intended for use by implementers and programmers.
ISO/IEC 9899:2011 is classified under the following ICS (International Classification for Standards) categories: 35.060 - Languages used in information technology. The ICS classification helps identify the subject area and facilitates finding related standards.
ISO/IEC 9899:2011 has the following relationships with other standards: It is inter standard links to ISO/IEC 9899:2011/Cor 1:2012, ISO/IEC 9899:2018, ISO/IEC 9899:1999. Understanding these relationships helps ensure you are using the most current and applicable version of the standard.
You can purchase ISO/IEC 9899:2011 directly from iTeh Standards. The document is available in PDF format and is delivered instantly after payment. Add the standard to your cart and complete the secure checkout process. iTeh Standards is an authorized distributor of ISO standards.
Standards Content (Sample)
INTERNATIONAL ISO/IEC
STANDARD 9899
Third edition
2011-12-15
Information technology — Programming
languages — C
Technologies de l'information — Langages de programmation — C
Reference number
©
ISO/IEC 2011
This CD-ROM contains the publication ISO/IEC 9899:2011 in portable document format (PDF), which can be
viewed using Adobe® Acrobat® Reader.
Adobe and Acrobat are trademarks of Adobe Systems Incorporated.
This third edition cancels and replaces the second edition (ISO/IEC 9899:1999), which has been technically
revised. It also incorporates the Technical Corrigenda ISO/IEC 9899:1999/Cor.1:2001,
ISO/IEC 9899:1999/Cor.2:2004 and ISO/IEC 9899:1999/Cor.3:2007.
© ISO/IEC 2011
All rights reserved. Unless required for installation or otherwise specified, no part of this CD-ROM may be reproduced, stored in a retrieval
system or transmitted in any form or by any means without prior permission from ISO. Requests for permission to reproduce this product
should be addressed to
ISO copyright office Case postale 56 CH-1211 Geneva 20 Switzerland
Internet copyright@iso.org
Reproduction may be subject to royalty payments or a licensing agreement.
Violators may be prosecuted.
Published in Switzerland
ii © ISO/IEC 2011 – All rights reserved
Installation
If this publication has been packaged as a zipped file, do NOT open the file from the CD-ROM, but cop
...
INTERNATIONAL ISO/IEC
STANDARD 9899
Third edition
2011-12-15
Information technology — Programming
languages — C
Technologies de l'information — Langages de programmation — C
Reference number
©
ISO/IEC 2011
© ISO/IEC 2011
All rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized in any form or by any means,
electronic or mechanical, including photocopying and microfilm, without permission in writing from either ISO at the address below or
ISO's member body in the country of the requester.
ISO copyright office
Case postale 56 CH-1211 Geneva 20
Tel. + 41 22 749 01 11
Fax + 41 22 749 09 47
E-mail copyright@iso.org
Web www.iso.org
Published in Switzerland
ii © ISO/IEC 2011 – All rights reserved
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
Contents
Foreword . xiii
Introduction . xvii
1. Scope . 1
2. Normative references . 2
3. Terms, definitions, and symbols . 3
4. Conformance . 8
5. Environment . 10
5.1 Conceptualmodels . 10
5.1.1 Translation environment . 10
5.1.2 Execution environments . 12
5.2 Environmental considerations . 22
5.2.1 Charactersets . 22
5.2.2 Characterdisplay semantics . 24
5.2.3 Signalsand interrupts . 25
5.2.4 Environmental limits . 25
6. Language . 35
6.1 Notation . 35
6.2 Concepts . 35
6.2.1 Scopesof identifiers . 35
6.2.2 Linkagesof identifiers . 36
6.2.3 Name spaces of identifiers . 37
6.2.4 Storage durations of objects . 38
6.2.5 Types . 39
6.2.6 Representationsof types . 44
6.2.7 Compatible type and composite type . 47
6.2.8 Alignmentof objects . 48
6.3 Conversions . 50
6.3.1 Arithmeticoperands . 50
6.3.2 Otheroperands . 54
6.4 Lexical elements . 57
6.4.1 Keywords . 58
6.4.2 Identifiers . 59
6.4.3 Universal character names . 61
6.4.4 Constants . 62
6.4.5 Stringliterals . 70
6.4.6 Punctuators . 72
6.4.7 Headernames . 73
6.4.8 Preprocessingnumbers . 74
6.4.9 Comments . 75
Contents iii
6.5 Expressions . 76
6.5.1 Primaryexpressions . 78
6.5.2 Postfixoperators . 79
6.5.3 Unaryoperators . 88
6.5.4 Castoperators . 91
6.5.5 Multiplicative operators . 92
6.5.6 Additive operators . 92
6.5.7 Bitwiseshift operators . 94
6.5.8 Relationaloperators . 95
6.5.9 Equalityoperators . 96
AND operator . 97
6.5.10 Bitwise
OR operator . 98
6.5.11 Bitwiseexclusive
OR operator . 98
6.5.12 Bitwiseinclusive
AND operator . 99
6.5.13 Logical
OR operator . 99
6.5.14 Logical
6.5.15 Conditionaloperator . 100
6.5.16 Assignmentoperators . 101
6.5.17 Commaoperator . 105
6.6 Constantexpressions . 106
6.7 Declarations . 108
6.7.1 Storage-classspecifiers . 109
6.7.2 Type specifiers . 111
6.7.3 Type qualifiers . 121
6.7.4 Functionspecifiers . 125
6.7.5 Alignmentspecifier . 127
6.7.6 Declarators . 128
6.7.7 Type names . 136
6.7.8 Type definitions . 137
6.7.9 Initialization . 139
6.7.10 Staticassertions . 145
6.8 Statementsand blocks . 146
6.8.1 Labeledstatements . 146
6.8.2 Compoundstatement . 147
6.8.3 Expression and null statements . 147
6.8.4 Selectionstatements . 148
6.8.5 Iterationstatements . 150
6.8.6 Jumpstatements . 151
6.9 Externaldefinitions . 155
6.9.1 Functiondefinitions . 156
6.9.2 Externalobject definitions . 158
6.10 Preprocessingdirectives . 160
6.10.1 Conditionalinclusion . 162
6.10.2 Sourcefile inclusion . 164
6.10.3 Macroreplacement . 166
iv Contents
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
6.10.4 Linecontrol . 173
6.10.5 Errordirective . 174
6.10.6 Pragmadirective . 174
6.10.7 Nulldirective . 175
6.10.8 Predefinedmacro names . 175
6.10.9 Pragmaoperator . 178
6.11 Futurelanguage directions . 179
6.11.1 Floatingtypes . 179
6.11.2 Linkagesof identifiers . 179
6.11.3 Externalnames . 179
6.11.4 Characterescape sequences . 179
6.11.5 Storage-classspecifiers . 179
6.11.6 Functiondeclarators . 179
6.11.7 Functiondefinitions . 179
6.11.8 Pragmadirectives . 179
6.11.9 Predefinedmacro names . 179
7. Library . 180
7.1 Introduction . 180
7.1.1 Definitionsof terms . 180
7.1.2 Standardheaders . 181
7.1.3 Reserved identifiers . 182
7.1.4 Use of library functions . 183
7.2 Diagnostics . 186
7.2.1 Programdiagnostics . 186
7.3 Complexarithmetic . 188
7.3.1 Introduction . 188
7.3.2 Conventions . 189
7.3.3 Branchcuts . 189
7.3.4 TheCX_LIMITED_RANGE pragma . 189
7.3.5 Trigonometric functions . 190
7.3.6 Hyperbolicfunctions . 192
7.3.7 Exponential and logarithmic functions . 194
7.3.8 Power and absolute-value functions . 195
7.3.9 Manipulationfunctions . 196
7.4 Characterhandling . 200
7.4.1 Characterclassification functions . 200
7.4.2 Character case mapping functions . 203
7.5 Errors . 205
7.6 Floating-pointenvironment . 206
7.6.1 TheFENV_ACCESS pragma . 208
7.6.2 Floating-pointexceptions . 209
7.6.3 Rounding . 212
7.6.4 Environment . 213
7.7 Characteristics of floating types . 216
Contents v
7.8 Format conversion of integer types . 217
7.8.1 Macros for format specifiers . 217
7.8.2 Functions for greatest-width integer types . 218
7.9 Alternative spellings . 221
7.10 Sizes of integer types . 222
7.11 Localization . 223
7.11.1 Localecontrol . 224
7.11.2 Numeric formatting convention inquiry . 225
7.12 Mathematics . 231
7.12.1 Treatment of error conditions . 233
7.12.2 TheFP_CONTRACT pragma . 235
7.12.3 Classificationmacros . 235
7.12.4 Trigonometric functions . 238
7.12.5 Hyperbolicfunctions . 240
7.12.6 Exponential and logarithmic functions . 242
7.12.7 Power and absolute-value functions . 247
7.12.8 Error and gamma functions . 249
7.12.9 Nearestinteger functions . 251
7.12.10 Remainderfunctions . 254
7.12.11 Manipulationfunctions . 255
7.12.12 Maximum, minimum, and positive difference functions . 257
7.12.13 Floatingmultiply-add . 258
7.12.14 Comparisonmacros . 259
7.13 Nonlocaljumps . 262
7.13.1 Save calling environment . 262
7.13.2 Restorecalling environment . 263
7.14 Signalhandling . 265
7.14.1 Specifysignal handling . 266
7.14.2 Sendsignal . 267
7.15 Alignment . 268
7.16 Variable arguments . 269
7.16.1 Variable argument list access macros . 269
7.17 Atomics . 273
7.17.1 Introduction . 273
7.17.2 Initialization . 274
7.17.3 Orderand consistency . 275
7.17.4 Fences . 278
7.17.5 Lock-freeproperty . 279
7.17.6 Atomicinteger types . 280
7.17.7 Operations on atomic types . 282
7.17.8 Atomic flag type and operations . 285
7.18 Boolean type and values . 287
7.19 Commondefinitions . 288
7.20 Integer types . 289
vi Contents
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
7.20.1 Integer types . 289
7.20.2 Limits of specified-width integer types . 291
7.20.3 Limits of other integer types . 293
7.20.4 Macros for integer constants . 294
7.21 Input/output . 296
7.21.1 Introduction . 296
7.21.2 Streams . 298
7.21.3 Files . 300
7.21.4 Operationson files . 302
7.21.5 Fileaccess functions . 304
7.21.6 Formatted input/output functions . 309
7.21.7 Characterinput/output functions . 330
7.21.8 Directinput/output functions . 335
7.21.9 Filepositioning functions . 336
7.21.10 Error-handling functions . 338
7.22 Generalutilities . 340
7.22.1 Numericconversion functions . 341
7.22.2 Pseudo-random sequence generation functions . 346
7.22.3 Memorymanagement functions . 347
7.22.4 Communication with the environment . 350
7.22.5 Searching and sorting utilities . 354
7.22.6 Integer arithmetic functions . 356
7.22.7 Multibyte/wide character conversion functions . 357
7.22.8 Multibyte/wide string conversion functions . 359
7.23 _Noreturn . 361
7.24 Stringhandling . 362
7.24.1 Stringfunction conventions . 362
7.24.2 Copying functions . 362
7.24.3 Concatenationfunctions . 364
7.24.4 Comparisonfunctions . 365
7.24.5 Searchfunctions . 367
7.24.6 Miscellaneousfunctions . 371
7.25 Type-generic math . 373
7.26 Threads . 376
7.26.1 Introduction . 376
7.26.2 Initializationfunctions . 378
7.26.3 Conditionvariable functions . 378
7.26.4 Mutexfunctions . 380
7.26.5 Threadfunctions . 383
7.26.6 Thread-specificstorage functions . 386
7.27 Dateand time . 388
7.27.1 Componentsof time . 388
7.27.2 Time manipulation functions . 389
7.27.3 Time conversion functions . 392
Contents vii
7.28 Unicodeutilities . 398
7.28.1 Restartable multibyte/wide character conversion functions . 398
7.29 Extended multibyte and wide character utilities . 402
7.29.1 Introduction . 402
7.29.2 Formatted wide character input/output functions . 403
7.29.3 Wide character input/output functions . 421
7.29.4 General wide string utilities . 426
7.29.4.1 Wide string numeric conversion functions . 426
7.29.4.2 Wide string copying functions . 430
7.29.4.3 Wide string concatenation functions . 432
7.29.4.4 Wide string comparison functions . 433
7.29.4.5 Wide string search functions . 435
7.29.4.6 Miscellaneousfunctions . 439
7.29.5 Wide character time conversion functions . 439
7.29.6 Extended multibyte/wide character conversion utilities . 440
7.29.6.1 Single-byte/wide character conversion functions . 441
7.29.6.2 Conversion state functions . 441
7.29.6.3 Restartable multibyte/wide character conversion
functions . 442
7.29.6.4 Restartable multibyte/wide string conversion
functions . 444
7.30 Wide character classification and mapping utilities . 447
7.30.1 Introduction . 447
7.30.2 Wide character classification utilities . 448
7.30.2.1 Wide character classification functions . 448
7.30.2.2 Extensible wide character classification
functions . 451
7.30.3 Wide character case mapping utilities . 453
7.30.3.1 Wide character case mapping functions . 453
7.30.3.2 Extensible wide character case mapping
functions . 453
7.31 Futurelibrary directions . 455
7.31.1 Complexarithmetic . 455
7.31.2 Characterhandling . 455
7.31.3 Errors . 455
7.31.4 Floating-pointenvironment . 455
7.31.5 Format conversion of integer types . 455
7.31.6 Localization . 455
7.31.7 Signalhandling . 455
7.31.8 Atomics . 455
7.31.9 Boolean type and values . 456
7.31.10 Integer types . 456
7.31.11 Input/output . 456
7.31.12 Generalutilities . 456
viii Contents
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
7.31.13 Stringhandling . 456
7.31.14 Dateand time . 456
7.31.15 Threads . 456
7.31.16 Extended multibyte and wide character utilities
. 456
7.31.17 Wide character classification and mapping utilities
. 457
Annex A (informative) Language syntax summary . 458
A.1 Lexical grammar . 458
A.2 Phrasestructure grammar . 465
A.3 Preprocessingdirectives . 473
Annex B (informative) Library summary . 475
B.1 Diagnostics . 475
B.2 Complex . 475
B.3 Characterhandling . 477
B.4 Errors . 477
B.5 Floating-pointenvironment . 477
B.6 Characteristics of floating types . 478
B.7 Format conversion of integer types . 478
B.8 Alternative spellings . 479
B.9 Sizes of integer types . 479
B.10 Localization . 479
B.11 Mathematics . 479
B.12 Nonlocaljumps . 484
B.13 Signalhandling . 484
B.14 Alignment . 485
B.15 Variable arguments . 485
B.16 Atomics . 485
B.17 Boolean type and values . 487
B.18 Commondefinitions . 487
B.19 Integer types . 487
B.20 Input/output . 488
B.21 Generalutilities . 491
B.22 _Noreturn . 493
B.23 Stringhandling . 493
B.24 Type-generic math . 495
B.25 Threads . 495
B.26 Dateand time . 496
B.27 Unicodeutilities . 497
B.28 Extended multibyte/wide character utilities . 497
B.29 Wide character classification and mapping utilities . 502
Annex C (informative) Sequence points . 503
Contents ix
Annex D (normative) Universal character names for identifiers . 504
D.1 Ranges of characters allowed . 504
D.2 Ranges of characters disallowed initially . 504
Annex E (informative) Implementation limits . 505
Annex F (normative) IEC 60559 floating-point arithmetic . 507
F.1 Introduction . 507
F.2 Types . 507
F.3 Operators and functions . 508
F.4 Floating to integer conversion . 510
F.5 Binary-decimal conversion . 510
F.6 Thereturn statement . 511
F.7 Contracted expressions . 511
F.8 Floating-point environment . 511
F.9 Optimization . 514
F.10 Mathematics . 517
F.10.1 Trigonometric functions . 518
F.10.2 Hyperbolicfunctions . 520
F.10.3 Exponential and logarithmic functions . 520
F.10.4 Power and absolute value functions . 524
F.10.5 Error and gamma functions . 525
F.10.6 Nearestinteger functions . 526
F.10.7 Remainderfunctions . 528
F.10.8 Manipulationfunctions . 529
F.10.9 Maximum, minimum, and positive difference functions . 530
F.10.10 Floatingmultiply-add . 530
F.10.11 Comparisonmacros . 531
Annex G (normative) IEC 60559-compatible complex arithmetic . 532
G.1 Introduction . 532
G.2 Types . 532
G.3 Conventions . 532
G.4 Conversions . 533
G.4.1 Imaginarytypes . 533
G.4.2 Realand imaginary . 533
G.4.3 Imaginaryand complex . 533
G.5 Binaryoperators . 533
G.5.1 Multiplicative operators . 534
G.5.2 Additive operators . 537
G.6 Complexarithmetic . 537
G.6.1 Trigonometric functions . 539
G.6.2 Hyperbolicfunctions . 539
G.6.3 Exponential and logarithmic functions . 543
G.6.4 Power and absolute-value functions . 544
G.7 Type-generic math . 545
x Contents
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
Annex H (informative) Language independent arithmetic . 546
H.1 Introduction . 546
H.2 Types . 546
H.3 Notification . 550
Annex I (informative) Common warnings . 552
Annex J (informative) Portability issues . 554
J.1 Unspecifiedbehavior . 554
J.2 Undefinedbehavior . 557
J.3 Implementation-definedbehavior . 571
J.4 Locale-specificbehavior . 578
J.5 Commonextensions . 579
Annex K (normative) Bounds-checking interfaces . 582
K.1 Background . 582
K.2 Scope . 583
K.3 Library . 583
K.3.1 Introduction . 583
K.3.1.1 Standardheaders . 583
K.3.1.2 Reserved identifiers . 584
K.3.1.3 Useof errno . 584
K.3.1.4 Runtime-constraintviolations . 584
K.3.2 Errors . 585
K.3.3 Commondefinitions . 585
K.3.4 Integer types . 585
K.3.5 Input/output . 586
K.3.5.1 Operationson files . 586
K.3.5.2 Fileaccess functions . 588
K.3.5.3 Formatted input/output functions . 591
K.3.5.4 Characterinput/output functions . 602
K.3.6 Generalutilities . 604
K.3.6.1 Runtime-constrainthandling . 604
K.3.6.2 Communication with the environment . 606
K.3.6.3 Searching and sorting utilities . 607
K.3.6.4 Multibyte/wide character conversion functions . 610
K.3.6.5 Multibyte/wide string conversion functions . 611
K.3.7 Stringhandling . 614
K.3.7.1 Copying functions . 614
K.3.7.2 Concatenationfunctions . 617
K.3.7.3 Searchfunctions . 620
K.3.7.4 Miscellaneousfunctions . 621
K.3.8 Dateand time . 624
K.3.8.1 Componentsof time . 624
K.3.8.2 Time conversion functions . 624
Contents xi
K.3.9 Extended multibyte and wide character utilities
. 627
K.3.9.1 Formatted wide character input/output functions . 628
K.3.9.2 General wide string utilities . 639
K.3.9.3 Extended multibyte/wide character conversion
utilities . 647
Annex L (normative) Analyzability . 652
L.1 Scope . 652
L.2 Definitions . 652
L.3 Requirements . 653
Bibliography . 654
Index . 657
xii Contents
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
Foreword
1 ISO (the International Organization for Standardization) and IEC (the International
Electrotechnical Commission) form the specialized system for worldwide
standardization. National bodies 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
take part in the work. In the field of information technology, ISO and IEC have
established a joint technical committee, ISO/IEC JTC 1.
2 International Standards are drafted in accordance with the rules given in the ISO/IEC
Directives, Part 2.
3 The main task of the joint technical committee is to prepare International Standards.
Draft International Standards adopted by the joint technical committee are circulated to
national bodies for voting. Publication as an International Standard requires approval by
at least 75% of the national bodies casting a vote.
4 Attention is drawn to the possibility that some of the elements of this document may be
the subject of patent rights. ISO and IEC shall not be held responsible for identifying any
or all such patent rights.
5 ISO/IEC 9899 was prepared by Joint Technical Committee ISO/IEC JTC 1, Information
technology, Subcommittee SC22, Programming languages, their environments and
system software interfaces.
6 This third edition cancels and replaces the second edition, ISO/IEC 9899:1999, which has
been technically revised. It also incorporates the Technical Corrigenda
ISO/IEC 9899:1999/Cor 1:2001, ISO/IEC 9899:1999/Cor 2:2004, and
ISO/IEC 9899:1999/Cor 3:2007. Major changes from the previous edition include:
— conditional (optional) features (including some that were previously mandatory)
— support for multiple threads of execution including an improved memory sequencing
model, atomic objects, and thread-local storage ( and
)
— additional floating-point characteristic macros ()
— querying and specifying alignment of objects (,)
—Unicode characters and strings () (originally specified in
ISO/IEC TR 19769:2004)
— type-generic expressions
— static assertions
— anonymous structures and unions
Foreword xiii
— no-return functions
— macros to create complex numbers ()
— support for opening files for exclusive access
— removed thegets function ()
— added the aligned_alloc, at_quick_exit, and quick_exit functions
()
— (conditional) support for bounds-checking interfaces (originally specified in
ISO/IEC TR 24731−1:2007)
— (conditional) support for analyzability
7 Major changes in the second edition included:
— restricted character set support via digraphs and (originally specified
in ISO/IEC 9899:1990/Amd.1:1995)
— wide character library support in and (originally
specified in ISO/IEC 9899:1990/Amd.1:1995)
— more precise aliasing rules via effective type
— restricted pointers
— variable length arrays
— flexible array members
— static and type qualifiers in parameter array declarators
— complex (and imaginary) support in
— type-generic math macros in
— thelong long int type and library functions
— extended integer types
— increased minimum translation limits
— additional floating-point characteristics in
— remove implicitint
— reliable integer division
— universal character names (\u and\U)
— extended identifiers
— hexadecimal floating-point constants and %a and %A printf/scanf conversion
specifiers
— compound literals
xiv Foreword
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
— designated initializers
— // comments
— specified width integer types and corresponding library functions in
and
— remove implicit function declaration
— preprocessor arithmetic done inintmax_t/uintmax_t
— mixed declarations and statements
— new block scopes for selection and iteration statements
— integer constant type rules
— integer promotion rules
— macros with a variable number of arguments
— thevscanf family of functions in and
— additional math library functions in
— treatment of error conditions by math library functions (math_errhandling)
— floating-point environment access in
— IEC 60559 (also known as IEC 559 or IEEE arithmetic) support
— trailing comma allowed inenum declaration
— %lf conversion specifier allowed inprintf
— inline functions
— thesnprintf family of functions in
— boolean type in
— idempotent type qualifiers
— empty macro arguments
— new structure type compatibility rules (tag compatibility)
— additional predefined macro names
— _Pragma preprocessing operator
— standard pragmas
— __func_ _ predefined identifier
— va_copy macro
— additionalstrftime conversion specifiers
— LIA compatibility annex
Foreword xv
— deprecateungetc at the beginning of a binary file
— remove deprecation of aliased array parameters
— conversion of array to pointer not limited to lvalues
— relaxed constraints on aggregate and union initialization
— relaxed restrictions on portable header names
— return without expression not permitted in function that returns a value (and vice
versa)
xvi Foreword
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
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
conflict 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.11] or library features [7.31]) is discouraged.
3 This International Standard is divided into four major subdivisions:
— preliminary elements (clauses 1−4);
— the characteristics of environments that translate and execute C programs (clause 5);
— the language syntax, constraints, and semantics (clause 6);
— the library facilities (clause 7).
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. Recommendations are provided to give advice or guidance to
implementors. Annexes provide additional information and summarize the information
contained in this International Standard. A bibliography lists documents that were
referred to during the preparation of the standard.
5 The language clause (clause 6) is derived from ‘‘The C Reference Manual’’.
6 The library clause (clause 7) is based on the 1984 /usr/group Standard.
7 The Working Group responsible for this standard (WG 14) 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 many of the
decisions made during its preparation and a log of Defect Reports and Responses.
Introduction xvii
xviii Introduction
INTERNATIONAL STANDARD ©ISO/IEC ISO/IEC 9899:2011 (E)
Information technology — Programming languages — C
1. Scope
1 This International Standard specifies the form and establishes the interpretation of
1)
programs written in the C programming language. It specifies
— the representation of C programs;
— the syntax and constraints of the C language;
— the semantic rules for interpreting C programs;
— the representation of input data to be processed by C programs;
— the representation of output data produced by C programs;
— the restrictions and limits imposed by a conforming implementation of C.
2 This International Standard does not specify
— the mechanism by which C programs are transformed for use by a data-processing
system;
— the mechanism by which C programs are invoked for use by a data-processing
system;
— the mechanism by which input data are transformed for use by a C program;
— the mechanism by which output data are transformed after being produced by a C
program;
— the size or complexity of a program and its data that will exceed the capacity of any
specific data-processing system or the capacity of a particular processor;
— all minimal requirements of a data-processing system that is capable of supporting a
conforming implementation.
1) This International Standard is designed to promote the portability of C programs among a variety of
data-processing systems. It is intended for use by implementors and programmers.
§1 General 1
2. Normative references
1 The following referenced documents are indispensable for the application of this
document. For dated references, only the edition cited applies. For undated references,
the latest edition of the referenced document (including any amendments) applies.
2 ISO/IEC 2382−1:1993, Information technology — Vocabulary — Part 1: Fundamental
terms.
3 ISO 4217, Codes for the representation of currencies and funds.
4 ISO 8601, Data elements and interchange formats — Information interchange —
Representation of dates and times.
5 ISO/IEC 10646, Information technology — Universal Coded Character Set (UCS).
6 IEC 60559:1989, Binary floating-point arithmetic for microprocessor systems (previously
designated IEC 559:1989).
7 ISO 80000−2, Quantities and units — Part 2: Mathematical signs and symbols to be used
in the natural sciences and technology.
2 General §2
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
3. Terms, definitions, and symbols
1 For the purposes of this document, the following terms and definitions apply. Other
terms are defined where they appear in italic type or on the left side of a syntax rule.
Terms explicitly defined in this International Standard are not to be presumed to refer
implicitly to similar terms defined elsewhere. Terms not defined in this International
Standard are to be interpreted according to ISO/IEC 2382−1. Mathematical symbols not
defined in this International Standard are to be interpreted according to ISO 80000−2.
3.1
1 access
〈execution-time action〉 to read or modify the value of an object
NOTE 1 Where only one of these two actions is meant, ‘‘read’’ or ‘‘modify’’ is used.
NOTE 2 ‘‘Modify’’ includes the case where the new value being stored is the same as the previous value.
NOTE 3 Expressions that are not evaluated do not access objects.
3.2
1 alignment
requirement that objects of a particular type be located on storage boundaries with
addresses that are particular multiples of a byte address
3.3
1 argument
actual argument
actual parameter (deprecated)
expression in the comma-separated list bounded by the parentheses in a function call
expression, or a sequence of preprocessing tokens in the comma-separated list bounded
by the parentheses in a function-like macro invocation
3.4
1 behavior
external appearance or action
3.4.1
1 implementation-defined behavior
unspecified behavior where each implementation documents how the choice is made
EXAMPLE An example of implementation-defined behavior is the propagation of the high-order bit
when a signed integer is shifted right.
3.4.2
1 locale-specific behavior
behavior that depends on local conventions of nationality, culture, and language that each
implementation documents
§3.4.2 General 3
EXAMPLE An example of locale-specific behavior is whether the islower function returns true for
characters other than the 26 lowercase Latin letters.
3.4.3
1 undefined behavior
behavior, upon use of a nonportable or erroneous program construct or of erroneous data,
for which this International Standard imposes no requirements
NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable
results, to behaving during translation or program execution in a documented manner characteristic of the
environment (with or without the issuance of a diagnostic message), to terminating a translation or
execution (with the issuance of a diagnostic message).
EXAMPLE An example of undefined behavior is the behavior on integer overflow.
3.4.4
1 unspecified behavior
use of an unspecified value, or other behavior where this International Standard provides
two or more possibilities and imposes no further requirements on which is chosen in any
instance
EXAMPLE An example of unspecified behavior is the order in which the arguments to a function are
evaluated.
3.5
1 bit
unit of data storage in the execution environment large enough to hold an object that may
have one of two values
NOTE It need not be possible to express the address of each individual bit of an object.
3.6
1 byte
addressable unit of data storage large enough to hold any member of the basic character
set of the execution environment
NOTE 1 It is possible to express the address of each individual byte of an object uniquely.
NOTE 2 A byte is composed of a contiguous sequence of bits, the number of which is implementation-
defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order
bit.
3.7
1 character
〈abstract〉 member of a set of elements used for the organization, control, or
representation of data
3.7.1
1 character
single-byte character
〈C〉 bit representation that fits in a byte
4 General §3.7.1
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
3.7.2
1 multibyte character
sequence of one or more bytes representing a member of the extended character set of
either the source or the execution environment
NOTE The extended character set is a superset of the basic character set.
3.7.3
1 wide character
value representable by an object of typewchar_t, capable of representing any character
in the current locale
3.8
1 constraint
restriction, either syntactic or semantic, by which the exposition of language elements is
to be interpreted
3.9
1 correctly rounded result
representation in the result format that is nearest in value, subject to the current rounding
mode, to what the result would be given unlimited range and precision
3.10
1 diagnostic message
message belonging to an implementation-defined subset of the implementation’s message
output
3.11
1 forward reference
reference to a later subclause of this International Standard that contains additional
information relevant to this subclause
3.12
1 implementation
particular set of software, running in a particular translation environment under particular
control options, that performs translation of programs for, and supports execution of
functions in, a particular execution environment
3.13
1 implementation limit
restriction imposed upon programs by the implementation
3.14
1 memory location
either an object of scalar type, or a maximal sequence of adjacent bit-fields all having
nonzero width
§3.14 General 5
NOTE 1 Tw o threads of execution can update and access separate memory locations without interfering
with each other.
NOTE 2 A bit-field and an adjacent non-bit-field member are in separate memory locations. The same
applies to two bit-fields, if one is declared inside a nested structure declaration and the other is not, or if the
two are separated by a zero-length bit-field declaration, or if they are separated by a non-bit-field member
declaration. It is not safe to concurrently update two non-atomic bit-fields in the same structure if all
members declared between them are also (non-zero-length) bit-fields, no matter what the sizes of those
intervening bit-fields happen to be.
EXAMPLE A structure declared as
struct {
char a;
int b:5, c:11, :0, d:8;
struct { int ee:8; } e;
}
contains four separate memory locations: The member a, and bit-fields d and e.ee are each separate
memory locations, and can be modified concurrently without interfering with each other. The bit-fields b
and c together constitute the fourth memory location. The bit-fields b and c cannot be concurrently
modified, butb anda, for example, can be.
3.15
1 object
region of data storage in the execution environment, the contents of which can represent
values
NOTE When referenced, an object may be interpreted as having a particular type; see 6.3.2.1.
3.16
1 parameter
formal parameter
formal argument (deprecated)
object declared as part of a function declaration or definition that acquires a value on
entry to the function, or an identifier from the comma-separated list bounded by the
parentheses immediately following the macro name in a function-like macro definition
3.17
1 recommended practice
specification that is strongly recommended as being in keeping with the intent of the
standard, but that may be impractical for some implementations
3.18
1 runtime-constraint
requirement on a program when calling a library function
NOTE 1 Despite the similar terms, a runtime-constraint is not a kind of constraint as defined by 3.8, and
need not be diagnosed at translation time.
NOTE 2 Implementations that support the extensions in annex K are required to verify that the runtime-
constraints for a library function are not violated by the program; see K.3.1.4.
6 General §3.18
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
3.19
1 value
precise meaning of the contents of an object when interpreted as having a specific type
3.19.1
1 implementation-defined value
unspecified value where each implementation documents how the choice is made
3.19.2
1 indeterminate value
either an unspecified value or a trap representation
3.19.3
1 unspecified value
valid value of the relevant type where this International Standard imposes no
requirements on which value is chosen in any instance
NOTE An unspecified value cannot be a trap representation.
3.19.4
1 trap representation
an object representation that need not represent a value of the object type
3.19.5
1 perform a trap
interrupt execution of the program such that no further operations are performed
NOTE In this International Standard, when the word ‘‘trap’’ is not immediately followed by
2)
‘‘representation’’, this is the intended usage.
3.20
1 x
⎡ ⎤
ceiling of x: the least integer greater than or equal to x
EXAMPLE 2. 4 is 3, −2. 4 is −2.
⎡ ⎤ ⎡ ⎤
3.21
1 x
⎣ ⎦
floor of x: the greatest integer less than or equal to x
EXAMPLE 2. 4 is 2, −2. 4 is −3.
⎣ ⎦ ⎣ ⎦
2) For example, ‘‘Trapping or stopping (if supported) is disabled.’’ (F.8.2). Note that fetching a trap
representation might perform a trap but is not required to (see 6.2.6.1).
§3.21 General 7
4. Conformance
1 In this International Standard, ‘‘shall’’ is to be interpreted as a requirement on an
implementation or on a program; conversely, ‘‘shall not’’ is to be interpreted as a
prohibition.
2 If a ‘‘shall’’ or ‘‘shall not’’ requirement that appears outside of a constraint or runtime-
constraint is violated, the behavior is undefined. Undefined behavior is otherwise
indicated in this International Standard by the words ‘‘undefined behavior’’ or by the
omission of any explicit definition of behavior. There is no difference in emphasis among
these three; they all describe ‘‘behavior that is undefined’’.
3 A program that is correct in all other aspects, operating on correct data, containing
unspecified behavior shall be a correct program and act in accordance with 5.1.2.3.
4 The implementation shall not successfully translate a preprocessing translation unit
containing a #error preprocessing directive unless it is part of a group skipped by
conditional inclusion.
5A strictly conforming program shall use only those features of the language and library
3)
specified in this International Standard. It shall not produce output dependent on any
unspecified, undefined, or implementation-defined behavior, and shall not exceed any
minimum implementation limit.
6 The two forms of conforming implementation are hosted and freestanding. A conforming
hosted implementation shall accept any strictly conforming program. A conforming
freestanding implementation shall accept any strictly conforming program in which the
use of the features specified in the library clause (clause 7) is confined to the contents of
the standard headers , , , ,
, , , , and
. A conforming implementation may have extensions (including
additional library functions), provided they do not alter the behavior of any strictly
4)
conforming program.
3) A strictly conforming program can use conditional features (see 6.10.8.3) provided the use is guarded
by an appropriate conditional inclusion preprocessing directive using the related macro. For example:
#ifdef __STDC_IEC_559_ _ /* FE_UPWARD defined */
/* . */
fesetround(FE_UPWARD);
/* . */
#endif
4) This implies that a conforming implementation reserves no identifiers other than those explicitly
reserved in this International Standard.
8 General §4
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E)
5)
7A conforming program is one
...










Questions, Comments and Discussion
Ask us and Technical Secretary will try to provide an answer. You can facilitate discussion about the standard in here.
Loading comments...