ISO/IEC9899:2011 (E)ISO/IEC 2011-All rights reserved4. ConformanceIn this International Standard,“shallis to be interpreted as a requirement on an1implementation or on a program; conversely,“shall not"is to be interpreted as aprohibition2If a “shall" or “shall not" requirement that appears outside of a constraint or runtime-constraint is violated, the behavior is undefined.Undefined behavior is otherwiseindicated in this International Standard by the words"undefined behavioror by theomission of any explicit definition ofbehavior.There is no difference in emphasis amongthese three; they all describe “behavior that is undefined'".3A program that is correct in all other aspects, operating on correct data, containingunspecified behavior shall be a correct program and act in accordance with 5.1.2.3The implementation shall not successfully translate a preprocessing translation unit4containing a #error preprocessing directive unless it is part of a group skipped byconditional inclusion.5A strictly conforming program shall use only those features of the language and libraryspecified in this International Standard.3) It shall not produce output dependent on anyunspecified, undefined, or implementation-defined behavior, and shall not exceed anyminimum implementation limit.6The twoforms of conforming implementationarehosted and freestanding.Aconforminghosted implementation shall accept any strictly conforming program. A conformingfreestanding implementation shall accept any strictly conforming program in which theuseofthefeaturesspecifiedinthelibraryclause(clause7)isconfinedtothecontentsofthe standard headers<float.h>, <iso646.h>, <limits.h>, <stdalign.h>and<stdarg.h>,<stdbool.h>,<stddef.h>,<stdint.h>,<stdnoreturn.h>.A conforming implementation may have extensions (includingadditional library functions),provided they do not alter the behavior of any strictlyconforming program.4)Astrictlyconformingprogramcanuseconditionalfeatures(see6.10.8.3)providedtheuseisguarded3by an appropriate conditional inclusion preprocessing directive using the related macro. For example:#ifdefSTDCIEc_559_/*FE_UPWARDdefined*//*..*/fesetround(FE_UPWARD) ;/**#endifThis implies that a conforming implementation reserves no identifiers other than those explicitly4)reserved in this International Standard.8$4General
ISO/IEC 9899:2011 (E) © ISO/IEC 2011 − All rights reserved 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 runtimeconstraint 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. 5 A strictly conforming program shall use only those features of the language and library specified in this International Standard.3) 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 <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h>. A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program.4) 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
CISO/IEC2011-All rightsreservedISO/IEC9899:2011 (E)A conforming program is one that is acceptable to a conforming implementation.5)78An implementation shall be accompanied by a document that defines all implementation-defined and locale-specific characteristics and all extensions.Forward references:conditional inclusion (6.10.1),errordirective(6.10.5)characteristics of floating types <f1oat.h> (7.7), alternative spellings <iso646.h>(7.9),sizes of integertypes<1imits.h>(7.10), alignment<stdalign,h>(7.15),variable arguments <stdarg.h> (7.16), boolean type and values <stdboo1.h>(7.18), common definitions <stddef.h> (7.19), integer types <stdint.h> (7.20),<stdnoreturn.h>(7.23).5)Strictly conforming programs are intended to be maximally portable among conformingimplementations.Conforming programs may depend upon nonportable features of a conformingimplementation.9$4General
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E) 7 A conforming program is one that is acceptable to a conforming implementation.5) 8 An implementation shall be accompanied by a document that defines all implementationdefined and locale-specific characteristics and all extensions. Forward references: conditional inclusion (6.10.1), error directive (6.10.5), characteristics of floating types <float.h> (7.7), alternative spellings <iso646.h> (7.9), sizes of integer types <limits.h> (7.10), alignment <stdalign.h> (7.15), variable arguments <stdarg.h> (7.16), boolean type and values <stdbool.h> (7.18), common definitions <stddef.h> (7.19), integer types <stdint.h> (7.20), <stdnoreturn.h> (7.23). 5) Strictly conforming programs are intended to be maximally portable among conforming implementations. Conforming programs may depend upon nonportable features of a conforming implementation. §4 General 9
ISO/IEC9899:2011 (E)ISO/IEC2011-Allrightsreserved5.EnvironmentAn implementation translates C source files and executes C programs in two data-1processing-system environments, which will be called the translation emvironment andthe execution environment in this International Standard.Their characteristics define andconstrain the results of executing conforming C programs constructed according to thesyntactic and semantic rules for conforming implementations.Forward references:In this clause, only a few of many possible forward referenceshave been noted.5.1 Conceptual models5.1.1 Translationenvironment5.1.1.1 Program structureA C program need not all be translated at the same time. The text of the program is keptin units called source files, (or preprocessing files) in this International Standard.Asource file together with all the headers and source files included via the preprocessingdirective #include is known as a preprocessing translation unit.After preprocessing,apreprocessing translation unit is called a translation unit.Previously translated translationunits may be preserved individually or in libraries. The separate translation units of aprogram communicateby (forexample)calls tofunctions whose identifiers have externallinkage,manipulation of objects whose identifiers have external linkage, or manipulationof data files. Translation units may be separately translated and then later linked toproduce an executable program.Forward references:linkages of identifiers (6.2.2),external definitions (6.9),preprocessingdirectives (6.10).5.1.1.2 Translation phasesThe precedence among the syntax rules of translation is specified by the following1phases.6)Physical source file multibyte characters are mapped, in an implementation1.defined manner, to the source character set (introducing new-line characters forend-of-line indicators) if necessary.Trigraph sequences are replaced bycorresponding single-character internal representations.Implementations shall behave as if these separatephases occur,even though many are typically folded61together in practice.Source files, translation units, and translated translation units need notnecessarilybe stored as files,nor need there beany one-to-one correspondencebetween these entitiesand any external representation. The description is conceptual only, and does not specify anyparticularimplementation.10$5.1.1.2Environment
ISO/IEC 9899:2011 (E) © ISO/IEC 2011 − All rights reserved 5. Environment 1 An implementation translates C source files and executes C programs in two dataprocessing-system environments, which will be called the translation environment and the execution environment in this International Standard. Their characteristics define and constrain the results of executing conforming C programs constructed according to the syntactic and semantic rules for conforming implementations. Forward references: In this clause, only a few of many possible forward references have been noted. 5.1 Conceptual models 5.1.1 Translation environment 5.1.1.1 Program structure 1 A C program need not all be translated at the same time. The text of the program is kept in units called source files, (or preprocessing files) in this International Standard. A source file together with all the headers and source files included via the preprocessing directive #include is known as a preprocessing translation unit. After preprocessing, a preprocessing translation unit is called a translation unit. Previously translated translation units may be preserved individually or in libraries. The separate translation units of a program communicate by (for example) calls to functions whose identifiers have external linkage, manipulation of objects whose identifiers have external linkage, or manipulation of data files. Translation units may be separately translated and then later linked to produce an executable program. Forward references: linkages of identifiers (6.2.2), external definitions (6.9), preprocessing directives (6.10). 5.1.1.2 Translation phases 1 The precedence among the syntax rules of translation is specified by the following phases.6) 1. Physical source file multibyte characters are mapped, in an implementationdefined manner, to the source character set (introducing new-line characters for end-of-line indicators) if necessary. Trigraph sequences are replaced by corresponding single-character internal representations. 6) Implementations shall behave as if these separate phases occur, even though many are typically folded together in practice. Source files, translation units, and translated translation units need not necessarily be stored as files, nor need there be any one-to-one correspondence between these entities and any external representation. The description is conceptual only, and does not specify any particular implementation. 10 Environment §5.1.1.2
ISO/IEC 2011 -All rights reservedISO/IEC9899:2011 (E)Each instance of a backslash character () immediately followed by a new-line2character is deleted, splicing physical source lines to form logical source lines.Only the last backslash on any physical source line shall be eligible for being partof such a splice. A source file that is not empty shall end in a new-line character,which shall not be immediately preceded by a backslash character before any suchsplicingtakesplace.The source file is decomposed into preprocessing tokens?) and sequences of3white-space characters (including comments).A source file shall not end in apartial preprocessing token or in a partial comment.Each comment is replaced byone space character.New-line characters are retained.Whether eachnonemptysequence of white-space characters other than new-line is retained or replaced byonespacecharacterisimplementation-defined.Preprocessing directives are executed, macro invocations are expanded, and4.Pragma unary operator expressions are executed. If a character sequence thatmatchesthesyntaxofauniversalcharacternameis producedbytokenconcatenation (6.10.3.3),thebehavior is undefined.A#includepreprocessingdirective causes the named header or source file to be processed from phase1through phase 4, recursively. All preprocessing directives are then deleted.5.Each sourcecharacter setmember and escape sequence incharacter constants andstringliteralsisconvertedtothecorrespondingmemberoftheexecutioncharacterset, if there is no corresponding member, it is converted to an implementation-defined member other than the null (wide) character.8)6.Adjacent string literal tokens areconcatenated1.White-space characters separating tokens are no longer significant. Eachpreprocessing token is converted into a token. The resulting tokens aresyntacticallyandsemanticallyanalyzedandtranslatedas atranslationunit.All external object and function references are resolved.Library components are8linked to satisfy external references to functions and objects not defined in thecurrent translation.All such translator output is collected into a program imagewhichcontainsinformationneededforexecutioninitsexecutionenvironmentForward references:universal character names (6.4.3), lexical elements (6.4)preprocessing directives (6.10), trigraph sequences (5.2.1.1), external definitions (6.9).7)As described in 6.4, the process of dividing a source file's characters into preprocessing tokens iscontext-dependent.For example, see the handling of<within a #includepreprocessing directive.8)An implementation need not convert all non-corresponding source characters to the same executioncharacter.11$5.1.1.2Environment
© ISO/IEC 2011 − All rights reserved ISO/IEC 9899:2011 (E) 2. Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. Only the last backslash on any physical source line shall be eligible for being part of such a splice. A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place. 3. The source file is decomposed into preprocessing tokens7) and sequences of white-space characters (including comments). A source file shall not end in a partial preprocessing token or in a partial comment. Each comment is replaced by one space character. New-line characters are retained. Whether each nonempty sequence of white-space characters other than new-line is retained or replaced by one space character is implementation-defined. 4. Preprocessing directives are executed, macro invocations are expanded, and _Pragma unary operator expressions are executed. If a character sequence that matches the syntax of a universal character name is produced by token concatenation (6.10.3.3), the behavior is undefined. A #include preprocessing directive causes the named header or source file to be processed from phase 1 through phase 4, recursively. All preprocessing directives are then deleted. 5. Each source character set member and escape sequence in character constants and string literals is converted to the corresponding member of the execution character set; if there is no corresponding member, it is converted to an implementationdefined member other than the null (wide) character.8) 6. Adjacent string literal tokens are concatenated. 7. White-space characters separating tokens are no longer significant. Each preprocessing token is converted into a token. The resulting tokens are syntactically and semantically analyzed and translated as a translation unit. 8. All external object and function references are resolved. Library components are linked to satisfy external references to functions and objects not defined in the current translation. All such translator output is collected into a program image which contains information needed for execution in its execution environment. Forward references: universal character names (6.4.3), lexical elements (6.4), preprocessing directives (6.10), trigraph sequences (5.2.1.1), external definitions (6.9). 7) As described in 6.4, the process of dividing a source file’s characters into preprocessing tokens is context-dependent. For example, see the handling of < within a #include preprocessing directive. 8) An implementation need not convert all non-corresponding source characters to the same execution character. §5.1.1.2 Environment 11
ISO/IEC9899:2011 (E)ISO/IEC2011-Allrightsreserved5.1.1.3 DiagnosticsA conforming implementation shall produce at least one diagnostic message (identified inan implementation-defined manner) if a preprocessing translation unit or translation unitcontains a violation of any syntax rule or constraint, even if the behavior is also explicitlyspecified as undefined or implementation-defined. Diagnostic messages need not beproduced inothercircumstances.9)EXAMPLEAn implementation is requiredto issue a diagnosticforthetranslation unit:2char i;int i;because in those cases where wording in this International Standard describes the behavior for a constructas being both a constraint error and resulting in undefined behavior, the constraint error shall be diagnosed5.1.2ExecutionenvironmentsTwo execution environments are defined:freestanding and hosted.In both cases,program startup occurs when a designated C function is called by theexecutionenvironment.All objects with static storage duration shall be initialized (set to theirinitial values)beforeprogram startup.The manner and timing of such initialization areotherwiseunspecified.Program termination returns control to the executionenvironment.Forward references: storage durations of objects (6.2.4), initialization (6.7.9)5.1.2.1FreestandingenvironmentIn a freestanding environment (in whichC program execution may take place without anybenefit of an operating system), the name and type of the function called at programstartup are implementation-defined. Any library facilities available to a freestandingprogram, other than theminimal set required by clause 4, are implementation-defined2The effect of program termination in a freestanding environment is implementation-defined.5.1.2.2 Hosted environmentA hosted environment need not be provided,but shall conform to thefollowingspecificationsif present.Theintentis that an implementation should identifythenatureof,and wherepossible localize,each9)violation.Ofcourse,an implementationis freeto produceanynumberof diagnostics as longas avalid program is still correctlytranslated.It mayalso successfullytranslate an invalid program12$5.1.2.2Environment
ISO/IEC 9899:2011 (E) © ISO/IEC 2011 − All rights reserved 5.1.1.3 Diagnostics 1 A conforming implementation shall produce at least one diagnostic message (identified in an implementation-defined manner) if a preprocessing translation unit or translation unit contains a violation of any syntax rule or constraint, even if the behavior is also explicitly specified as undefined or implementation-defined. Diagnostic messages need not be produced in other circumstances.9) 2 EXAMPLE An implementation is required to issue a diagnostic for the translation unit: char i; int i; because in those cases where wording in this International Standard describes the behavior for a construct as being both a constraint error and resulting in undefined behavior, the constraint error shall be diagnosed. 5.1.2 Execution environments 1 Tw o execution environments are defined: freestanding and hosted. In both cases, program startup occurs when a designated C function is called by the execution environment. All objects with static storage duration shall be initialized (set to their initial values) before program startup. The manner and timing of such initialization are otherwise unspecified. Program termination returns control to the execution environment. Forward references: storage durations of objects (6.2.4), initialization (6.7.9). 5.1.2.1 Freestanding environment 1 In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined. Any library facilities available to a freestanding program, other than the minimal set required by clause 4, are implementation-defined. 2 The effect of program termination in a freestanding environment is implementationdefined. 5.1.2.2 Hosted environment 1 A hosted environment need not be provided, but shall conform to the following specifications if present. 9) The intent is that an implementation should identify the nature of, and where possible localize, each violation. Of course, an implementation is free to produce any number of diagnostics as long as a valid program is still correctly translated. It may also successfully translate an invalid program. 12 Environment §5.1.2.2