Стандарт языка Си С99 TC (1113411), страница 5
Текст из файла (страница 5)
The description is conceptual only, and does not specify anyparticular implementation.§5.1.1.2Environment9ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N12562.Each instance of a backslash character (\) immediately followed by a new-linecharacter 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 suchsplicing takes place.3.The source file is decomposed into preprocessing tokens6) and sequences ofwhite-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 each nonemptysequence of white-space characters other than new-line is retained or replaced byone 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 thatmatches the syntax of a universal character name is produced by tokenconcatenation (6.10.3.3), the behavior is undefined. A #include preprocessingdirective causes the named header or source file to be processed from phase 1through phase 4, recursively. All preprocessing directives are then deleted.5.Each source character set member and escape sequence in character constants andstring literals is converted to the corresponding member of the execution characterset; if there is no corresponding member, it is converted to an implementationdefined member other than the null (wide) character.7)6.Adjacent string literal tokens are concatenated.7.White-space characters separating tokens are no longer significant.
Eachpreprocessing token is converted into a token. The resulting tokens aresyntactically and semantically analyzed and translated as a translation unit.8.All external object and function references are resolved. Library components arelinked to satisfy external references to functions and objects not defined in thecurrent translation. All such translator output is collected into a program imagewhich 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).6)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 #include preprocessing directive.7)An implementation need not convert all non-corresponding source characters to the same executioncharacter.10Environment§5.1.1.2WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC35.1.1.3 Diagnostics1A 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 in other circumstances.8)2EXAMPLEAn implementation shall 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 constructas being both a constraint error and resulting in undefined behavior, the constraint error shall be diagnosed.5.1.2 Execution environments1Two execution environments are defined: freestanding and hosted.
In both cases,program startup occurs when a designated C function is called by the executionenvironment. All objects with static storage duration shall be initialized (set to theirinitial values) before program startup. The manner and timing of such initialization areotherwise unspecified. Program termination returns control to the executionenvironment.Forward references: storage durations of objects (6.2.4), initialization (6.7.8).5.1.2.1 Freestanding environment1In a freestanding environment (in which C 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 the minimal set required by clause 4, are implementation-defined.2The effect of program termination in a freestanding environment is implementationdefined.5.1.2.2 Hosted environment1A hosted environment need not be provided, but shall conform to the followingspecifications if present.8)The intent is that an implementation should identify the nature of, and where possible localize, eachviolation.
Of course, an implementation is free to produce any number of diagnostics as long as avalid program is still correctly translated. It may also successfully translate an invalid program.§5.1.2.2Environment11ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N12565.1.2.2.1 Program startup1The function called at program startup is named main. The implementation declares noprototype for this function. It shall be defined with a return type of int and with noparameters:int main(void) { /* ...
*/ }or with two parameters (referred to here as argc and argv, though any names may beused, as they are local to the function in which they are declared):int main(int argc, char *argv[]) { /* ... */ }or equivalent;9) or in some other implementation-defined manner.2If they are declared, the parameters to the main function shall obey the followingconstraints:— The value of argc shall be nonnegative.— argv[argc] shall be a null pointer.— If the value of argc is greater than zero, the array members argv[0] throughargv[argc-1] inclusive shall contain pointers to strings, which are givenimplementation-defined values by the host environment prior to program startup. Theintent is to supply to the program information determined prior to program startupfrom elsewhere in the hosted environment.
If the host environment is not capable ofsupplying strings with letters in both uppercase and lowercase, the implementationshall ensure that the strings are received in lowercase.— If the value of argc is greater than zero, the string pointed to by argv[0]represents the program name; argv[0][0] shall be the null character if theprogram name is not available from the host environment.
If the value of argc isgreater than one, the strings pointed to by argv[1] through argv[argc-1]represent the program parameters.— The parameters argc and argv and the strings pointed to by the argv array shallbe modifiable by the program, and retain their last-stored values between programstartup and program termination.5.1.2.2.2 Program execution1In a hosted environment, a program may use all the functions, macros, type definitions,and objects described in the library clause (clause 7).9)12Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written aschar ** argv, and so on.Environment§5.1.2.2.2WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC35.1.2.2.3 Program termination1If the return type of the main function is a type compatible with int, a return from theinitial call to the main function is equivalent to calling the exit function with the valuereturned by the main function as its argument;10) reaching the } that terminates themain function returns a value of 0.
If the return type is not compatible with int, thetermination status returned to the host environment is unspecified.Forward references: definition of terms (7.1.1), the exit function (7.20.4.3).5.1.2.3 Program execution1The semantic descriptions in this International Standard describe the behavior of anabstract machine in which issues of optimization are irrelevant.2Accessing a volatile object, modifying an object, modifying a file, or calling a functionthat does any of those operations are all side effects,11) which are changes in the state ofthe execution environment. Evaluation of an expression may produce side effects.
Atcertain specified points in the execution sequence called sequence points, all side effectsof previous evaluations shall be complete and no side effects of subsequent evaluationsshall have taken place. (A summary of the sequence points is given in annex C.)3In the abstract machine, all expressions are evaluated as specified by the semantics. Anactual implementation need not evaluate part of an expression if it can deduce that itsvalue is not used and that no needed side effects are produced (including any caused bycalling a function or accessing a volatile object).4When the processing of the abstract machine is interrupted by receipt of a signal, only thevalues of objects as of the previous sequence point may be relied on. Objects that may bemodified between the previous sequence point and the next sequence point need not havereceived their correct values yet.5The least requirements on a conforming implementation are:— At sequence points, volatile objects are stable in the sense that previous accesses arecomplete and subsequent accesses have not yet occurred.10) In accordance with 6.2.4, the lifetimes of objects with automatic storage duration declared in mainwill have ended in the former case, even where they would not have in the latter.11) The IEC 60559 standard for binary floating-point arithmetic requires certain user-accessible statusflags and control modes.