13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATION[Note: Initialization to default values is typically done by having the memory manager or garbage collectorinitialize memory to all-bits-zero before it is allocated for use. For this reason, it is convenient to use all-bitszeroto represent the null reference. end note]12.3 Definite assignmentAt a given location in the executable code of a function member, a variable is said to be definitely assignedif the compiler can prove, by a particular static flow analysis (§12.3.3), that the variable has beenautomatically initialized or has been the target of at least one assignment. [Note: Informally stated, the rulesof definite assignment are:• An initially assigned variable (§12.3.1) is always considered definitely assigned.• An initially unassigned variable (§12.3.2) is considered definitely assigned at a given location if allpossible execution paths leading to that location contain at least one of the following:A simple assignment (§14.13.1) in which the variable is the left operand.An invocation expression (§14.5.5) or object creation expression (§14.5.10.1) that passes the variable as anoutput parameter.For a local variable, a local variable declaration (§15.5) that includes a variable initializer.The formal specification underlying the above informal rules is described in §12.3.1, §12.3.2, and §12.3.3.end note]The definite assignment states of instance variables of a struct-type variable are tracked individually as wellas collectively. In additional to the rules above, the following rules apply to struct-type variables and theirinstance variables:• An instance variable is considered definitely assigned if its containing struct-type variable is considereddefinitely assigned.• A struct-type variable is considered definitely assigned if each of its instance variables is considereddefinitely 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 ensuresthat undefined values never occur. end note] The occurrence of a variable in an expression is consideredto obtain the value of the variable, except whenthe variable is the left operand of a simple assignment,the variable is passed as an output parameter, orthe 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 parameterinitially assigned. end note]• All output parameters of a function member must be definitely assigned at each location where thefunction member returns (through a return statement or through execution reaching the end of thefunction member body). [Note: This ensures that function members do not return undefined values inoutput parameters, thus enabling the compiler to consider a function member invocation that takes avariable 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 locationwhere that instance constructor returns.12.3.1 Initially assigned variablesThe following categories of variables are classified as initially assigned:102

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!