X hits on this document

772 views

0 shares

0 downloads

0 comments

108 / 396

Chapter ‎18   Unsafe code

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”.

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”.

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

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.

5.3.3.25 ! expressions

For an expression expr of the form ! expr-operand:

The definite assignment state of v before expr-operand is the same as the definite assignment state of v before expr.

The definite assignment state of v after expr is determined by:

If the state of v after expr-operand is definitely assigned, then the state of v after expr is definitely assigned.

If the state of v after expr-operand is not definitely assigned, then the state of v after expr is not definitely assigned.

If the state of v after expr-operand is “definitely assigned after false expression”, then the state of v after expr is “definitely assigned after true expression”.

If the state of v after expr-operand is “definitely assigned after true expression”, then the state of v after expr is “definitely assigned after false expression”.

5.3.3.26 ?: expressions

For an expression expr of the form expr-cond ? expr-true : expr-false:

The definite assignment state of v before expr-cond is the same as the state of v before expr.

The definite assignment state of v before expr-true is definitely assigned if and only if the state of v after expr-cond is definitely assigned or “definitely assigned after true expression”.

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.95

Document info
Document views772
Page views772
Page last viewedSat Dec 03 05:28:36 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments