12.3 Definite assignment

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

if the compiler can prove, by a particular static flow analysis (?2.3.3),

that the variable has been

automatically initialized or has been the target of at least one

assignment. [Note: Informally stated, the rules

of definite assignment are:

?An initially assigned variable (?2.3.1) is always considered definitely

assigned.

?An initially unassigned variable (?2.3.2) is considered definitely

assigned at a given location if all

possible execution paths leading to that location contain at least one of

the following:

A simple assignment (?4.13.1) in which the variable is the left operand.

An invocation expression (?4.5.5) or object creation expression (?4.5.10.1)

that passes the variable as an

output parameter.

For a local variable, a local variable declaration (?5.5) that includes a

variable initializer.

The formal specification underlying the above informal rules is described

in ?2.3.1, ?2.3.2, and ?2.3.3.

end note]

The definite assignment states of instance variables of a struct-type

variable are tracked individually as well

as collectively. In additional to the rules above, the following rules

apply to struct-type variables and their

instance variables:

?An instance variable is considered definitely assigned if its containing

struct-type variable is considered

definitely assigned.

?A struct-type variable is considered definitely assigned if each of its

instance variables is considered

definitely assigned.

Definite assignment is a requirement in the following contexts:

?A variable must be definitely assigned at each location where its value

is obtained. [Note: This ensures

that undefined values never occur. end note] The occurrence of a variable

in an expression is considered

to obtain the value of the variable, except when

the variable is the left operand of a simple assignment,

the variable is passed as an output parameter, or

the variable is a struct-type variable and occurs as the left operand of a

member access.

?A variable must be definitely assigned at each location where it is

passed as a reference parameter.

[Note: This ensures that the function member being invoked can consider the

reference parameter

initially assigned. end note]

?All output parameters of a function member must be definitely assigned at

each location where the

function member returns (through a return statement or through execution

reaching the end of the

function member body). [Note: This ensures that function members do not

return undefined values in

output parameters, thus enabling the compiler to consider a function member

invocation that takes a

variable as an output parameter equivalent to an assignment to the

variable. end note]

?The this variable of a struct-type instance constructor must be

definitely assigned at each location

where that instance constructor returns.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航