12.3.3.24 || expressions

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

12.3.3.24 || expressions

For an expression expr of the form expr-first || expr-second:

?The definite assignment state of v before expr-first is the same as the

definite assignment state of v

before expr.

?The definite assignment state of v before expr-second is definitely

assigned if the state of v after

expr-first is either definitely assigned or .definitely assigned after

false expression.. Otherwise, it is

not definitely assigned.

?The definite assignment statement of v after expr is determined by:

o If the state of v after expr-first is definitely assigned, then the state

of v after expr is

definitely assigned.

o Otherwise, if the state of v after expr-second is definitely assigned,

and the state of v after

expr-first is .definitely assigned after true expression., then the state

of v after expr is

definitely assigned.

Chapter 12 Variables

111

o Otherwise, if the state of v after expr-second is definitely assigned or

.definitely assigned

after false expression., then the state of v after expr is .definitely

assigned after false

expression..

o Otherwise, if the state of v after expr-first is .definitely assigned

after true expression., and

the state of v after expr-second is .definitely assigned after true

expression., then the state

of v after expr is .definitely assigned after true expression..

o Otherwise, the state of v after expr is not definitely assigned.

[Example: In the example

class A

{

static void G(int x, int y) {

int i;

if (x >= 0 || (i = y) >= 0) {

// i not definitely assigned

}

else {

// i definitely assigned

}

// i not definitely assigned

}

}

the variable i is considered definitely assigned in one of the embedded

statements of an if statement but not

in the other. In the if statement in method G, the variable i is definitely

assigned in the second embedded

statement because execution of the expression (i = y) always precedes

execution of this embedded

statement. In contrast, the variable i is not definitely assigned in the

first embedded statement, since

x >= 0 might have tested true, resulting in the variable i抯 being

unassigned. end example]

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