Linguagem de Programação C - NORMA ISO/IEC 9899TC2

Linguagem de Programação C - NORMA ISO/IEC 9899TC2

(Parte 5 de 11)

Forward references:universal character names (6.4.3), lexical elements (6.4), preprocessing directives(6.10), trigraph sequences (, external definitions (6.9).

6)As described in 6.4, the process of dividing a source file’scharacters into preprocessing tokens is context-dependent. For example, see the handling of<within a#includepreprocessing directive.

7)An implementation need not convert all non-corresponding source characters to the same execution character.

10 Environment §

WG14/N1124 CommitteeDraft — May 6, 2005ISO/IEC 9899:TC2 Diagnostics

1Aconforming 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 anysyntax rule or constraint, evenifthe behavior is also explicitly specified as undefined or implementation-defined.Diagnostic messages need not be produced in other circumstances.8)

2EXAMPLE Animplementation 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 construct as being both a constraint error and resulting in undefined behavior,the constraint error shall be diagnosed.

5.1.2 Execution environments

1Tw oexecution environments are defined:freestandingandhosted.Inboth cases, programstartupoccurs when a designated C function is called by the execution environment. Allobjects with static storage duration shall beinitialized(set to their initial values) before program startup.The manner and timing of such initialization are otherwise unspecified.Programterminationreturns control to the execution environment.

Forward references:storage durations of objects (6.2.4), initialization (6.7.8). Freestanding environment

1In a freestanding environment (in which C program execution may takeplace without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined.Anylibrary facilities available to a freestanding program, other than the minimal set required by clause 4, are implementation-defined.

2The effect of program termination in a freestanding environment is implementationdefined. Hosted environment

1Ahosted environment need not be provided, but shall conform to the following specifications if present.

8)The intent is that an implementation should identify the nature of, and where possible localize, each violation. Ofcourse, an implementation is free to produce anynumber of diagnostics as long as a valid program is still correctly translated.It may also successfully translate an invalid program.

§ Environment 1

ISO/IEC 9899:TC2Committee Draft — May 6, 2005WG14/N1124 Program startup

1The function called at program startup is namedmain.The implementation declares no prototype for this function.It shall be defined with a return type ofintand with no parameters:

int main(void) { /*...*/ } or with twoparameters (referred to here asargcandargv,though anynames may be used, as theyare local to the function in which theyare declared):

int main(int argc, char *argv[]) { /*...*/ } or equivalent;9)or in some other implementation-defined manner.

2If theyare declared, the parameters to themainfunction shall obeythe following constraints:

—The value ofargcshall be nonnegative.

—argv[argc]shall be a null pointer.

—Ifthe value ofargcis greater than zero, the array membersargv[0]through argv[argc-1]inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup.The intent is to supply to the program information determined prior to program startup from elsewhere in the hosted environment. Ifthe host environment is not capable of supplying strings with letters in both uppercase and lowercase, the implementation shall ensure that the strings are receivedinlowercase.

—Ifthe value ofargcis greater than zero, the string pointed to byargv[0] represents theprogramname;argv[0][0]shall be the null character if the program name is not available from the host environment. Ifthe value ofargcis greater than one, the strings pointed to byargv[1]throughargv[argc-1] represent the program parameters.

—The parametersargcandargvand the strings pointed to by theargvarray shall be modifiable by the program, and retain their last-stored values between program startup and program termination. Program execution

1In a hosted environment, a program may use all the functions, macros, type definitions, and objects described in the library clause (clause 7).

9)Thus,intcan be replaced by a typedef name defined asint,orthe type ofargvcan be written as char ** argv,and so on.

12 Environment §

WG14/N1124 CommitteeDraft — May 6, 2005ISO/IEC 9899:TC2 Program termination

1If the return type of themainfunction is a type compatible withint,areturn from the initial call to themainfunction is equivalent to calling theexitfunction with the value returned by themainfunction as its argument;10)reaching the}that terminates the mainfunction returns a value of 0.If the return type is not compatible withint,the termination status returned to the host environment is unspecified.

Forward references:definition of terms (7.1.1), theexitfunction ( Program execution

1The semantic descriptions in this International Standard describe the behavior of an abstract machine in which issues of optimization are irrelevant.

2Accessing a volatile object, modifying an object, modifying a file, or calling a function that does anyofthose operations are allside effects,1)which are changes in the state of the execution environment. Evaluation of an expression may produce side effects. At certain specified points in the execution sequence calledsequence points,all side effects of previous evaluations shall be complete and no side effects of subsequent evaluations shall have taken place.(A summary of the sequence points is giveninannexC.)

3In the abstract machine, all expressions are evaluated as specified by the semantics.An actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no needed side effects are produced (including anycaused by calling a function or accessing a volatile object).

4When the processing of the abstract machine is interrupted by receipt of a signal, only the values of objects as of the previous sequence point may be relied on.Objects that may be modified between the previous sequence point and the next sequence point need not have receivedtheir correct values yet.

5The least requirements on a conforming implementation are:

—Atsequence points, volatile objects are stable in the sense that previous accesses are complete and subsequent accesses have not yet occurred.

10)In accordance with 6.2.4, the lifetimes of objects with automatic storage duration declared inmain will have ended in the former case, evenwhere theywould not have inthe latter.

1)The IEC60559 standard for binary floating-point arithmetic requires certain user-accessible status flags and control modes.Floating-point operations implicitly set the status flags; modes affect result values of floating-point operations.Implementations that support such floating-point state are required to regard changes to it as side effects — see annexFfor details.The floating-point environment library<fenv.h>provides a programming facility for indicating when these side effects matter,freeing the implementations in other cases.

§ Environment 13

ISO/IEC 9899:TC2Committee Draft — May 6, 2005WG14/N1124

—Atprogram termination, all data written into files shall be identical to the result that execution of the program according to the abstract semantics would have produced.

—The input and output dynamics of interactive devices shall takeplace as specified in 7.19.3. Theintent of these requirements is that unbuffered or line-buffered output appear as soon as possible, to ensure that prompting messages actually appear prior to aprogram waiting for input.

6What constitutes an interactive device is implementation-defined.

(Parte 5 de 11)