Add a more functional (i.e. fewer-stubs) implementation of System.Data.Linq.
[mono.git] / mcs / docs / ecma334 / 25.1.xml
1 <?xml version="1.0"?>
2 <clause number="25.1" title="Unsafe contexts">
3   <paragraph>The unsafe features of C# are available only in unsafe contexts. An unsafe context is introduced by including an unsafe modifier in the declaration of a type or member, or by employing an unsafe-statement: <list><list_item> A declaration of a class, struct, interface, or delegate may include an unsafe modifier, in which case the entire textual extent of that type declaration (including the body of the class, struct, or interface) is considered an unsafe context. </list_item><list_item> A declaration of a field, method, property, event, indexer, operator, instance constructor, destructor, or static constructor may include an unsafe modifier, in which case, the entire textual extent of that member declaration is considered an unsafe context. </list_item><list_item> An <non_terminal where="25.1">unsafe-statement</non_terminal> enables the use of an unsafe context within a block. The entire textual extent of the associated block is considered an unsafe context. </list_item></list></paragraph>
4   <paragraph>The associated grammar extensions are shown below. For brevity, ellipses (...) are used to represent productions that appear in preceding chapters. <grammar_production><name><non_terminal where="17.1.1">class-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="18.1.1">struct-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="20.1.1">interface-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="22.1">delegate-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="17.4">field-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="17.5">method-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="17.6">property-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="17.7">event-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="17.8">indexer-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="17.9">operator-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="17.10">constructor-modifier</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><keyword>unsafe</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="17.12">destructor-declaration</non_terminal></name> : <rhs><non_terminal where="24.2">attributes</non_terminal><opt/><keyword>extern</keyword><opt/><keyword>unsafe</keyword><opt/><terminal>~</terminal><non_terminal where="9.4.2">identifier</non_terminal><terminal>(</terminal><terminal>)</terminal><non_terminal where="17.12">destructor-body</non_terminal></rhs><rhs><non_terminal where="24.2">attributes</non_terminal><opt/><keyword>unsafe</keyword><opt/><keyword>extern</keyword><opt/><terminal>~</terminal><non_terminal where="9.4.2">identifier</non_terminal><terminal>(</terminal><terminal>)</terminal><non_terminal where="17.12">destructor-body</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="17.11">static-constructor-declaration</non_terminal></name> : <rhs><non_terminal where="24.2">attributes</non_terminal><opt/><keyword>extern</keyword><opt/><keyword>unsafe</keyword><opt/><keyword>static</keyword><non_terminal where="9.4.2">identifier</non_terminal><terminal>(</terminal><terminal>)</terminal><non_terminal where="17.11">static-constructor-body</non_terminal></rhs><rhs><non_terminal where="24.2">attributes</non_terminal><opt/><keyword>unsafe</keyword><opt/><keyword>extern</keyword><opt/><keyword>static</keyword><non_terminal where="9.4.2">identifier</non_terminal><terminal>(</terminal><terminal>)</terminal><non_terminal where="17.11">static-constructor-body</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="15">embedded-statement</non_terminal></name> : <rhs><terminal>...</terminal></rhs><rhs><non_terminal where="25.1">unsafe-statement</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="25.1">unsafe-statement</non_terminal></name> : <rhs><keyword>unsafe</keyword><non_terminal where="15.2">block</non_terminal></rhs></grammar_production></paragraph>
5   <paragraph>
6     <example>[Example: In the example <code_example><![CDATA[
7 public unsafe struct Node  
8 {  
9    public int Value;  
10    public Node* Left;  
11    public Node* Right;  
12 }  
13 ]]></code_example>the unsafe modifier specified in the struct declaration causes the entire textual extent of the struct declaration to become an unsafe context. Thus, it is possible to declare the Left and Right fields to be of a pointer type. The example above could also be written <code_example><![CDATA[
14 public struct Node  
15 {  
16    public int Value;  
17    public unsafe Node* Left;  
18    public unsafe Node* Right;  
19 }  
20 ]]></code_example></example>
21   </paragraph>
22   <paragraph>
23     <example>Here, the unsafe modifiers in the field declarations cause those declarations to be considered unsafe contexts. end example]</example>
24   </paragraph>
25   <paragraph>Other than establishing an unsafe context, thus permitting the use of pointer types, the unsafe modifier has no effect on a type or a member. <example>[Example: In the example <code_example><![CDATA[
26 public class A  
27 {  
28    public unsafe virtual void F() {  
29       char* p;  
30       ...  
31    }  
32 }  
33 public class B: A  
34 {  
35    public override void F() {  
36       base.F();  
37       ...  
38    }  
39 }  
40 ]]></code_example>the unsafe modifier on the F method in A simply causes the textual extent of F to become an unsafe context in which the unsafe features of the language can be used. In the override of F in B, there is no need to re-specify the unsafe modifier-unless, of course, the F method in B itself needs access to unsafe features. </example></paragraph>
41   <paragraph>
42     <example>The situation is slightly different when a pointer type is part of the method's signature <code_example><![CDATA[
43 public unsafe class A  
44 {  
45    public virtual void F(char* p) {...}  
46 }  
47 public class B: A  
48 {  
49    public unsafe override void F(char* p) {...}  
50 }  
51 ]]></code_example></example>
52   </paragraph>
53   <paragraph>
54     <example>Here, because F's signature includes a pointer type, it can only be written in an unsafe context. However, the unsafe context can be introduced by either making the entire class unsafe, as is the case in A, or by including an unsafe modifier in the method declaration, as is the case in B. end example]</example>
55   </paragraph>
56 </clause>