WG14/N1336Committee Draft August 11, 2008ISO/IEC9899:201x3027.19.9Filepositioningfunctions3047.19.10 Error-handling functions3067.20General utilities<stdlib.h>3077.20.1 Numeric conversion functions3127.20.2Pseudo-random sequence generation functions3137.20.3Memory management functions3157.20.4Communicationwiththeenvironment7.20.5318Searching and sorting utilities3207.20.6Integer arithmetic functions3217.20.7Multibyte/widecharacterconversionfunctions3237.20.8Multibyte/widestring conversionfunctions3257.21String handling<string.h>3257.21.1String function conventions3257.21.2Copying functions3277.21.3Concatenation functions3287.21.4Comparisonfunctions7.21.5330Search functions3337.21.6Miscellaneousfunctions3357.22 Type-genericmath<tgmath.h>3387.23 Date and time<time.h>3387.23.1 Componentsoftime3397.23.2Timemanipulation functions3417.23.3Timeconversionfunctions3487.24 Extended multibyte and wide character utilities<wchar.h>3487.24.1 Introduction7.24.2349Formattedwidecharacterinput/outputfunctions3677.24.3Widecharacterinput/output functions3717.24.4General wide string utilities7.24.5385Wide character time conversion functions3867.24.6Extendedmultibyte/wide characterconversion utilities3937.25Widecharacterclassificationandmappingutilities<wctype.h>3937.25.1Introduction3947.25.2Wide character classification utilities3997.25.3Wide character case mapping utilities4017.26 Future library directions4017.26.1Complexarithmetic<complex.h>7.26.2401Character handling<ctype.h>4017.26.3Errors<errno.h>4017.26.4Formatconversion of integertypes<inttypes.h>4017.26.5Localization<locale.h>7.26.6401Signal handling<signal.h>4017.26.7Boolean type and values<stdbool.h>4017.26.8Integertypes<stdint.h>4027.26.9Input/output <stdio.h>Contentsvii
WG14/N1336 Committee Draft — August 11, 2008 ISO/IEC 9899:201x 7.19.9 File positioning functions . 302 7.19.10 Error-handling functions . 304 7.20 General utilities <stdlib.h> . 306 7.20.1 Numeric conversion functions . 307 7.20.2 Pseudo-random sequence generation functions . 312 7.20.3 Memory management functions . 313 7.20.4 Communication with the environment . 315 7.20.5 Searching and sorting utilities . 318 7.20.6 Integer arithmetic functions . 320 7.20.7 Multibyte/wide character conversion functions . 321 7.20.8 Multibyte/wide string conversion functions . 323 7.21 String handling <string.h> . 325 7.21.1 String function conventions . 325 7.21.2 Copying functions . 325 7.21.3 Concatenation functions . 327 7.21.4 Comparison functions . 328 7.21.5 Search functions . 330 7.21.6 Miscellaneous functions . 333 7.22 Type-generic math <tgmath.h> . 335 7.23 Date and time <time.h> . 338 7.23.1 Components of time . 338 7.23.2 Time manipulation functions . 339 7.23.3 Time conversion functions . 341 7.24 Extended multibyte and wide character utilities <wchar.h> . 348 7.24.1 Introduction . 348 7.24.2 Formatted wide character input/output functions . 349 7.24.3 Wide character input/output functions . 367 7.24.4 General wide string utilities . 371 7.24.5 Wide character time conversion functions . 385 7.24.6 Extended multibyte/wide character conversion utilities . 386 7.25 Wide character classification and mapping utilities <wctype.h> . 393 7.25.1 Introduction . 393 7.25.2 Wide character classification utilities . 394 7.25.3 Wide character case mapping utilities . 399 7.26 Future library directions . 401 7.26.1 Complex 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 Boolean type and values <stdbool.h> . 401 7.26.8 Integer types <stdint.h> . 401 7.26.9 Input/output <stdio.h> . 402 Contents vii
ISO/IEC9899:201xCommittee Draft — August 11, 2008WG14/N13364027.26.10 General utilities<std1ib.h>4027.26.11 Stringhandling<string.h>7.26.12Extendedmultibyteand widecharacterutilities402<wchar.h>7.26.13Wide characterclassification andmappingutilities402<wctype.h>403AnnexA(informative)Languagesyntaxsummary403A.1 Lexical grammar409A.2Phrase structuregrammar416A.3Preprocessingdirectives419AnnexB(informative)Library summary419B.1Diagnostics<assert.h>B.2419Complex<complex.h>B.3421Characterhandling<ctype.h>B.4421Errors<errno.h>421B.5Floating-point environment<fenv.h>B.6422Characteristicsof floatingtypes<float.h>422B.7Formatconversionofintegertypes<inttypes.h>423B.8Alternative spellings<iso646.h>423B.9Sizes of integertypes<limits.h>423B.10 Localization<locale.h>423B.11 Mathematics<math.h>428B.12 Nonlocal jumps<setjmp.h>428B.13 Signal handling<signal.h>428B.14 Variable arguments<stdarg.h>428B.15 Boolean type and values<stdboo1.h>429B.16 Common definitions<stddef.h>429B.17 Integertypes<stdint.h>429B.18 Input/output<stdio.h>431B.19 General utilities<std1ib.h>433B.20 String handling<string.h>434B.21 Type-genericmath<tgmath.h>434B.22 Dateandtime<time.h>435B.23 Extended multibyte/wide character utilities <wchar.h>437B.24 Wide character classification and mapping utilities<wctype.h>439Annex C(informative)Sequence points440AnnexD (normative)Universal character names for identifiers442AnnexE(informative)Implementationlimits444AnnexF (normative)IEC60559floating-point arithmetic444F.1IntroductionF.2444TypesF.3445Operators and functionsviliContents
ISO/IEC 9899:201x Committee Draft — August 11, 2008 WG14/N1336 7.26.10 General utilities <stdlib.h> . 402 7.26.11 String handling <string.h> . 402 7.26.12 Extended multibyte and wide character utilities <wchar.h> . 402 7.26.13 Wide character classification and mapping utilities <wctype.h> . 402 AnnexA(informative) Language syntax summary . 403 A.1 Lexical grammar . 403 A.2 Phrase structure grammar . 409 A.3 Preprocessing directives . 416 AnnexB(informative) Library summary . 419 B.1 Diagnostics <assert.h> . 419 B.2 Complex <complex.h> . 419 B.3 Character handling <ctype.h> . 421 B.4 Errors <errno.h> . 421 B.5 Floating-point environment <fenv.h> . 421 B.6 Characteristics of floating types <float.h> . 422 B.7 Format conversion of integer types <inttypes.h> . 422 B.8 Alternative spellings <iso646.h> . 423 B.9 Sizes of integer types <limits.h> . 423 B.10 Localization <locale.h> . 423 B.11 Mathematics <math.h> . 423 B.12 Nonlocal jumps <setjmp.h> . 428 B.13 Signal handling <signal.h> . 428 B.14 Variable arguments <stdarg.h> . 428 B.15 Boolean type and values <stdbool.h> . 428 B.16 Common definitions <stddef.h> . 429 B.17 Integer types <stdint.h> . 429 B.18 Input/output <stdio.h> . 429 B.19 General utilities <stdlib.h> . 431 B.20 String handling <string.h> . 433 B.21 Type-generic math <tgmath.h> . 434 B.22 Date and time <time.h> . 434 B.23 Extended multibyte/wide character utilities <wchar.h> . 435 B.24 Wide character classification and mapping utilities <wctype.h> . 437 AnnexC(informative) Sequence points . 439 AnnexD(normative) Universal character names for identifiers . 440 AnnexE(informative) Implementation limits . 442 AnnexF(normative) IEC 60559 floating-point arithmetic . 444 F.1 Introduction . 444 F.2 Types . 444 F.3 Operators and functions . 445 viii Contents
WG14/N1336Committee Draft—August 11, 2008ISO/IEC9899:201xF.4447Floatingto integer conversionF.5447Binary-decimal conversionF.6448Contracted expressionsF.7448Floating-pointenvironmentF.8451OptimizationF.9454Mathematics<math.h>467AnnexG(informative)IEC60559-compatiblecomplexarithmeticG.1467IntroductionG.2467TypesG.3467ConventionsG.4468ConversionsG.5468Binaryoperators472G.6Complexarithmetic<complex.h>480G.7Type-generic math<tgmath.h>481Annex H (informative) Language independent arithmetic481H.1 Introduction481H.2TypesH.3 Notification485487AnnexI(informative)Commonwarnings489AnnexJ(informative)Portabilityissues489J.1Unspecified behaviorJ.2492Undefined behaviorJ.3505Implementation-defined behaviorJ.4512Locale-specific behaviorJ.5513CommonextensionsBibliography516519IndexContentsix
WG14/N1336 Committee Draft — August 11, 2008 ISO/IEC 9899:201x F.4 Floating to integer conversion . 447 F.5 Binary-decimal conversion . 447 F.6 Contracted expressions . 448 F.7 Floating-point environment . 448 F.8 Optimization . 451 F.9 Mathematics <math.h> . 454 AnnexG(informative) IEC 60559-compatible complex arithmetic . 467 G.1 Introduction . 467 G.2 Types . 467 G.3 Conventions . 467 G.4 Conversions . 468 G.5 Binary operators . 468 G.6 Complex arithmetic <complex.h> . 472 G.7 Type-generic math <tgmath.h> . 480 AnnexH(informative) Language independent arithmetic . 481 H.1 Introduction . 481 H.2 Types . 481 H.3 Notification . 485 AnnexI(informative) Common warnings . 487 AnnexJ(informative) Portability issues . 489 J.1 Unspecified behavior . 489 J.2 Undefined behavior . 492 J.3 Implementation-defined behavior . 505 J.4 Locale-specific behavior . 512 J.5 Common extensions . 513 Bibliography . 516 Index . 519 Contents ix
ISO/IEC9899:201xCommittee Draft August 11, 2008WG14/N1336ContentsX
ISO/IEC 9899:201x Committee Draft — August 11, 2008 WG14/N1336 x Contents
WG14/N1336ISO/IEC9899:201xCommittee Draft—August 11, 2008ForewordISO (the International Organization for Standardization) and IEC (the InternationalElectrotechnical Commission)formthespecializedsystem for worldwidestandardization. National bodies that are member of ISO or IEC participate in thedevelopmentofInternationalStandardsthroughtechnicalcommitteesestablishedbytherespective organization todeal with particular fields of technical activity.ISOand IECtechnicalcommitteescollaboratein fields ofmutualinterest.Otherinternationalorganizations, governmental and non-governmental, in liaison with ISO and IEC, alsotake part in the work.2International Standards are drafted in accordance with the rules given in the ISO/IECDirectives,Part2.ThisInternationalStandard was drafted inaccordancewiththefifthedition (2004)3In the field of information technology, ISO and IEC have established a joint technicalcommittee,ISO/IECJTC1.DraftInternationalStandardsadoptedbythejointtechnicalcommittee are circulated to national bodies for voting.Publication as an InternationalStandard requires approval by at least 75% of the national bodies casting a vote.XAttention is drawn to the possibility that some of the elements of this document may bethe subject of patentrights.ISO andIEC shall not be held responsiblefor identifying anyorallsuchpatentrights.5This International Standard was prepared by Joint Technical Committee ISO/IEC JTC 1,Information technology,SubcommitteeSC22,Programminglanguages,theirenvironments and system sofiware interfaces.The Working Group responsible for thisstandard (WG 14) maintains a site on the World Wide Web at http://www.open-std.org/JTc1/sc22/wG14/ containing additional information relevant to thisstandard such as a Rationale for many of the decisions made during its preparation and alogofDefectReportsandResponses6Thisthird editioncancelsandreplaces the second edition,ISO/IEC9899:1999,ascorrectedbyISO/IEC9899:1999/Cor1:2001,ISO/IEC9899:1999/Cor2:2004,andISO/IEC9899:1999/Cor3:2007.Majorchangesfrom theprevious edition include:- (To be determined)Major changes in the second edition included:- restricted character set support via digraphs and <iso646.h> (originally specifiedin AMD1)wide character library support in <wchar.h>and <wctype.h> (originallyspecified inAMDI)moreprecisealiasingrulesviaeffectivetyperestrictedpointers-variable length arraysForewordxi
WG14/N1336 Committee Draft — August 11, 2008 ISO/IEC 9899:201x 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. 2 International Standards are drafted in accordance with the rules given in the ISO/IEC Directives, Part 2. This International Standard was drafted in accordance with the fifth edition (2004). 3 In the field of information technology, ISO and IEC have established a joint technical committee, ISO/IEC JTC 1. 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 This International Standard was prepared by Joint Technical Committee ISO/IEC JTC 1, Information technology, Subcommittee SC 22, Programming languages, their environments and system software interfaces. The Working Group responsible for this standard (WG 14) maintains a site on the World Wide Web at http://www.openstd.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. 6 This third edition cancels and replaces the second edition, ISO/IEC 9899:1999, as corrected by 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: — (To be determined) 7 Major changes in the second edition included: — 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 Foreword xi