Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C-sharp language specification.2004.pdf
Скачиваний:
14
Добавлен:
23.08.2013
Размер:
2.55 Mб
Скачать

C# LANGUAGE SPECIFICATION

1For a variable of a value-type, the default value is the same as the value computed by the value-type’s

2default constructor (§11.1.1).

3For a variable of a reference-type, the default value is null.

4[Note: Initialization to default values is typically done by having the memory manager or garbage collector

5initialize memory to all-bits-zero before it is allocated for use. For this reason, it is convenient to use all-bits-

6zero to represent the null reference. end note]

712.3 Definite assignment

8At a given location in the executable code of a function member, a variable is said to be definitely assigned

9if the compiler can prove, by a particular static flow analysis (§12.3.3), that the variable has been

10automatically initialized or has been the target of at least one assignment. [Note: Informally stated, the rules

11of definite assignment are:

12An initially assigned variable (§12.3.1) is always considered definitely assigned.

13An initially unassigned variable (§12.3.2) is considered definitely assigned at a given location if all

14possible execution paths leading to that location contain at least one of the following:

15o A simple assignment (§14.13.1) in which the variable is the left operand.

16o An invocation expression (§14.5.5) or object creation expression (§14.5.10.1) that passes the

17variable as an output parameter.

18o For a local variable, a local variable declaration (§15.5) that includes a variable initializer.

19The formal specification underlying the above informal rules is described in §12.3.1, §12.3.2, and §12.3.3.

20end note]

21The definite assignment states of instance variables of a struct-type variable are tracked individually as well

22as collectively. In additional to the rules above, the following rules apply to struct-type variables and their

23instance variables:

24An instance variable is considered definitely assigned if its containing struct-type variable is considered

25definitely assigned.

26A struct-type variable is considered definitely assigned if each of its instance variables is considered

27definitely assigned.

28Definite assignment is a requirement in the following contexts:

29A variable shall be definitely assigned at each location where its value is obtained. [Note: This ensures

30that undefined values never occur. end note] The occurrence of a variable in an expression is considered

31to obtain the value of the variable, except when

32o the variable is the left operand of a simple assignment,

33o the variable is passed as an output parameter, or

34o the variable is a struct-type variable and occurs as the left operand of a member access.

35A variable shall be definitely assigned at each location where it is passed as a reference parameter.

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

37initially assigned. end note]

38All output parameters of a function member shall be definitely assigned at each location where the

39function member returns (through a return statement or through execution reaching the end of the

40function member body). [Note: This ensures that function members do not return undefined values in

41output parameters, thus enabling the compiler to consider a function member invocation that takes a

42variable as an output parameter equivalent to an assignment to the variable. end note]

43The this variable of a struct-type instance constructor shall be definitely assigned at each location

44where that instance constructor returns.

118

Соседние файлы в предмете Электротехника