﻿ Block statements, checked, and unchecked statements
﻿

ЗНАЕТЕ ЛИ ВЫ?

# Block statements, checked, and unchecked statements

The definite assignment state of v on the control transfer to the first statement of the statement list in the block (or to the end point of the block, if the statement list is empty) is the same as the definite assignment statement of v before the block, checked, or unchecked statement.

Expression statements

For an expression statement stmt that consists of the expression expr:

· v has the same definite assignment state at the beginning of expr as at the beginning of stmt.

· If v if definitely assigned at the end of expr, it is definitely assigned at the end point of stmt; otherwise; it is not definitely assigned at the end point of stmt.

Declaration statements

· If stmt is a declaration statement without initializers, then v has the same definite assignment state at the end point of stmt as at the beginning of stmt.

· If stmt is a declaration statement with initializers, then the definite assignment state for v is determined as if stmt were a statement list, with one assignment statement for each declaration with an initializer (in the order of declaration).

If statements

For an if statement stmt of the form:

if ( expr ) then-stmt else else-stmt

· v has the same definite assignment state at the beginning of expr as at the beginning of stmt.

· If v is definitely assigned at the end of expr, then it is definitely assigned on the control flow transfer to then-stmt and to either else-stmt or to the end-point of stmt if there is no else clause.

· If v has the state “definitely assigned after true expression” at the end of expr, then it is definitely assigned on the control flow transfer to then-stmt, and not definitely assigned on the control flow transfer to either else-stmt or to the end-point of stmt if there is no else clause.

· If v has the state “definitely assigned after false expression” at the end of expr, then it is definitely assigned on the control flow transfer to else-stmt, and not definitely assigned on the control flow transfer to then-stmt. It is definitely assigned at the end-point of stmt if and only if it is definitely assigned at the end-point of then-stmt.

· Otherwise, v is considered not definitely assigned on the control flow transfer to either the then-stmt or else-stmt, or to the end-point of stmt if there is no else clause.

Switch statements

In a switch statement stmt with a controlling expression expr:

· The definite assignment state of v at the beginning of expr is the same as the state of v at the beginning of stmt.

· The definite assignment state of v on the control flow transfer to a reachable switch block statement list is the same as the definite assignment state of v at the end of expr.

While statements

For a while statement stmt of the form:

while ( expr ) while-body

· v has the same definite assignment state at the beginning of expr as at the beginning of stmt.

· If v is definitely assigned at the end of expr, then it is definitely assigned on the control flow transfer to while-body and to the end point of stmt.

· If v has the state “definitely assigned after true expression” at the end of expr, then it is definitely assigned on the control flow transfer to while-body, but not definitely assigned at the end-point of stmt.

· If v has the state “definitely assigned after false expression” at the end of expr, then it is definitely assigned on the control flow transfer to the end point of stmt, but not definitely assigned on the control flow transfer to while-body.

Do statements

For a do statement stmt of the form:

do do-body while ( expr ) ;

· v has the same definite assignment state on the control flow transfer from the beginning of stmt to do-body as at the beginning of stmt.

· v has the same definite assignment state at the beginning of expr as at the end point of do-body.

· If v is definitely assigned at the end of expr, then it is definitely assigned on the control flow transfer to the end point of stmt.

· If v has the state “definitely assigned after false expression” at the end of expr, then it is definitely assigned on the control flow transfer to the end point of stmt.

For statements

Definite assignment checking for a for statement of the form:

for ( for-initializer ; for-condition ; for-iterator ) embedded-statement

is done as if the statement were written:

{
for-initializer ;
while ( for-condition ) {
embedded-statement ;
for-iterator ;
}
}

If the for-condition is omitted from the for statement, then evaluation of definite assignment proceeds as if for-condition were replaced with true in the above expansion.

﻿

Последнее изменение этой страницы: 2016-12-14; Нарушение авторского права страницы

infopedia.su Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Обратная связь - 3.216.79.60 (0.006 с.)