ISO/IEC 2011 - All rights reservedISO/IEC9899:2011(E)546Annex H (informative) Language independent arithmetic546H.1 Introduction546H.2Types550H.3Notification552AnnexI(informative)Commonwarnings554AnnexJ(informative)Portabilityissues554J.1Unspecifiedbehavior557J.2Undefined behaviorJ.3571Implementation-defined behaviorJ.4578Locale-specific behaviorJ.5579Commonextensions582AnnexK (normative)Bounds-checking interfaces582BackgroundK.1583K.2Scope583K.3LibraryK.3.1583Introduction583K.3.1.1 Standard headers584K.3.1.2 Reserved identifiers584K.3.1.3 Use of errno584K.3.1.4 Runtime-constraint violations585K.3.2Errors<errno.h>K.3.3585Commondefinitions<stddef.h>K.3.4585Integertypes<stdint.h>586K.3.5Input/output<stdio.h>586K.3.5.1 Operations on files588K.3.5.2 File access functions591K.3.5.3 Formatted input/output functions602K.3.5.4Character input/outputfunctions604K.3.6General utilities<stdlib.h>604K.3.6.1Runtime-constrainthandling606K.3.6.2Communicationwiththeenvironment607K.3.6.3Searching and sorting utilities610K.3.6.4Multibyte/wide characterconversionfunctionsK.3.6.5611Multibyte/widestringconversionfunctions614K.3.7String handling<string.h>614K.3.7.1 Copying functions617K.3.7.2Concatenation functions620K.3.7.3 Search functions621K.3.7.4 Miscellaneous functionsK.3.8624Dateandtime<time.h>624K.3.8.1 Components of time624K.3.8.2Time conversion functionsContentsxi
© 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 Unspecified behavior . 554 J.2 Undefined behavior . 557 J.3 Implementation-defined behavior . 571 J.4 Locale-specific behavior . 578 J.5 Common extensions . 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 Standard headers . 583 K.3.1.2 Reserved identifiers . 584 K.3.1.3 Use of errno . 584 K.3.1.4 Runtime-constraint violations . 584 K.3.2 Errors <errno.h> . 585 K.3.3 Common definitions <stddef.h> . 585 K.3.4 Integer types <stdint.h> . 585 K.3.5 Input/output <stdio.h> . 586 K.3.5.1 Operations on files . 586 K.3.5.2 File access functions . 588 K.3.5.3 Formatted input/output functions . 591 K.3.5.4 Character input/output functions . 602 K.3.6 General utilities <stdlib.h> . 604 K.3.6.1 Runtime-constraint handling . 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 String handling <string.h> . 614 K.3.7.1 Copying functions . 614 K.3.7.2 Concatenation functions . 617 K.3.7.3 Search functions . 620 K.3.7.4 Miscellaneous functions . 621 K.3.8 Date and time <time.h> . 624 K.3.8.1 Components of time . 624 K.3.8.2 Time conversion functions . 624 Contents xi
ISO/IEC9899:2011(E)ISO/IEC 2011-All rights reservedK.3.9Extendedmultibyteandwidecharacterutilities627<wchar.h>628K.3.9.1 Formatted wide character input/outputfunctions639K.3.9.2 General wide string utilitiesK.3.9.3Extendedmultibyte/widecharacter conversion647utilities652Annex L (normative)Analyzability652L.1ScopeL.2652DefinitionsL.3653Requirements654BibliographyIndex657xiiContents
ISO/IEC 9899:2011 (E) © ISO/IEC 2011 − All rights reserved K.3.9 Extended multibyte and wide character utilities <wchar.h> . 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/IEC9899:2011(E)ISO/IEC2011-All rights reservedForewordISo (theInternational Organizationfor Standardization)andIEC(theInternationalElectrotechnical Commission) formthe specializedsystem for worldwidestandardization. National bodies that are member of ISO or IEC participate in thedevelopmentofInternationalStandardsthroughtechnicalcommitteesestablishedbytherespective organization to deal with particular fields of technical activity.ISO and IECtechnicalcommitteescollaborate in fieldsof mutual interest.Otherinternationalorganizations, governmental and non-governmental, in liaison with ISO and IEC, alsotake part in the work. In the field of information technology, ISO and IEC haveestablishedajointtechnicalcommittee,ISO/IECJTC1.2International Standards are drafted in accordance with the rules given in the ISO/IECDirectives, Part 2.3The main task of the joint technical committee is to prepare International StandardsDraft International Standards adopted by the joint technical committee are circulated tonational bodies for voting.Publication as an International Standard requires approval byat least 75%ofthenational bodies casting a vote.4Attention is drawn to the possibility that some of the elements of this document may bethe subject of patentrights.ISOandIEC shall not beheld responsiblefor identifying anyor all such patent rights.5ISO/IEC 9899 was prepared by Joint Technical Committee ISO/IEC JTC 1, Informationtechnology,Subcommittee SC22,Programming languages,their environments andsystem sofiware interfaces.This third edition cancels and replaces the second edition, ISO/IEC 9899:1999, which has6ItalsoincorporatestheTechnicalCorrigendabeentechnicallyrevised.ISO/IEC9899:1999/Cor1:2001,ISO/IEC9899:1999/Cor2:2004,andISO/IEC9899:1999/Cor3:2007.Major changes from theprevious edition include:conditional (optional)features (including some that were previously mandatory)support for multiple threads of execution including an improved memory sequencingmodel,atomicobjects,andthread-local storage(<stdatomic.h>and<threads.h>)- additional floating-point characteristic macros (<f1oat.h>)- querying and specifying alignment ofobjects (<stdalign.h>,<stdlib.h>)Unicodecharactersandstrings(<uchar.h>)(originallyspecifiedinISO/IECTR19769:2004)-type-genericexpressionsstaticassertions-anonymous structures and unionsForewordxili
© 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 SC 22, 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 (<stdatomic.h> and <threads.h>) — additional floating-point characteristic macros (<float.h>) — querying and specifying alignment of objects (<stdalign.h>, <stdlib.h>) — Unicode characters and strings (<uchar.h>) (originally specified in ISO/IEC TR 19769:2004) — type-generic expressions — static assertions — anonymous structures and unions Foreword xiii
ISO/IEC9899:2011(E)ISO/IEC 2011 - All rights reservedno-returnfunctionsmacrostocreatecomplexnumbers(<complex.h>)supportforopeningfilesforexclusiveaccessremoved thegetsfunction(<stdio.h>)added the aligned_alloc, at_quick_exit, and quick_exit functions(<stdlib.h>)(conditional) support for bounds-checking interfaces (originally specified inISO/IEC TR 2473i-1:2007)(conditional) support for analyzability7Major changes in the second edition includedrestricted character set support via digraphs and<iso646.h>(originally specifiedinISO/IEC9899:1990/Amd.1:1995)wide character library support in<wchar.h>and <wctype.h>(originallyspecifiedinISO/IEC9899:1990/Amd.1:1995)more precise aliasing rules via effective typerestrictedpointersvariablelengtharrays-flexiblearraymembersstaticandtypequalifiers inparameterarraydeclaratorscomplex(andimaginary)supportin<complex.h>type-generic mathmacros in<tgmath.h>thelong long inttypeand libraryfunctionsextended integertypesincreased minimumtranslation limitsadditional floating-point characteristics in<float.h>removeimplicitintreliableintegerdivisionuniversal characternames (uand lu)-extended identifiershexadecimal floating-point constants and%a and %Aprintf/scanf conversionspecifierscompound literalsxivForeword
ISO/IEC 9899:2011 (E) © ISO/IEC 2011 − All rights reserved — no-return functions — macros to create complex numbers (<complex.h>) — support for opening files for exclusive access — removed the gets function (<stdio.h>) — added the aligned_alloc, at_quick_exit, and quick_exit functions (<stdlib.h>) — (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 <iso646.h> (originally specified in ISO/IEC 9899:1990/Amd.1:1995) — wide character library support in <wchar.h> and <wctype.h> (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 <complex.h> — type-generic math macros in <tgmath.h> — the long long int type and library functions — extended integer types — increased minimum translation limits — additional floating-point characteristics in <float.h> — remove implicit int — 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
CISO/IEC 2011 -All rights reservedISO/IEC9899:2011 (E)designated initializers//comments specifed width integer types and corresponding library functions in<inttypes.h>and<stdint.h>-removeimplicitfunctiondeclarationpreprocessorarithmeticdoneinintmax_t/uintmax_t-mixed declarations and statements-newblock scopes for selection and iteration statements-integerconstanttyperules-integerpromotionrules-macroswithavariablenumberofargumentsthevscanffamilyoffunctionsin<stdio.h>and<wchar.h>additional mathlibraryfunctions in<math.h>treatment oferror conditionsbymathlibraryfunctions (math_errhandiing)floating-pointenvironmentaccessin<fenv.h>—IEC60559(alsoknownasIEC559orIEEEarithmetic)support-trailingcommaallowed inenumdeclaration%lfconversionspecifierallowedinprintfinlinefunctions-thesnprintffamilyoffunctionsin<stdio.h>—boolean type in<stdbool.h>idempotenttypequalifiers-emptymacroargumentsnewstructuretypecompatibilityrules(tagcompatibility)additional predefinedmacronames_Pragmapreprocessingoperatorstandardpragmasfuncpredefinedidentifier-va_copymacro-additional strftime conversion specifiersLIA compatibilityannexForewordXV
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E) — designated initializers — // comments — specified width integer types and corresponding library functions in <inttypes.h> and <stdint.h> — remove implicit function declaration — preprocessor arithmetic done in intmax_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 — the vscanf family 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> — IEC 60559 (also known as IEC 559 or IEEE arithmetic) support — trailing comma allowed in enum declaration — %lf conversion specifier allowed in printf — inline functions — the snprintf family of functions in <stdio.h> — boolean type in <stdbool.h> — 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 — additional strftime conversion specifiers — LIA compatibility annex Foreword xv