Forgot to commit
[mono.git] / mcs / docs / ecma334 / 25.5.2.xml
1 <?xml version="1.0"?>
2 <clause number="25.5.2" title="Pointer member access">
3   <paragraph>A <non_terminal where="25.5.2">pointer-member-access</non_terminal> consists of a <non_terminal where="14.5">primary-expression</non_terminal>, followed by a &quot;-&gt;&quot; token, followed by an identifier. <grammar_production><name><non_terminal where="25.5.2">pointer-member-access</non_terminal></name> : <rhs><non_terminal where="14.5">primary-expression</non_terminal><terminal>-&gt;</terminal><non_terminal where="9.4.2">identifier</non_terminal></rhs></grammar_production></paragraph>
4   <paragraph>In a pointer member access of the form P-&gt;I, P must be an expression of a pointer type other than void*, and I must denote an accessible member of the type to which P points. </paragraph>
5   <paragraph>A pointer member access of the form P-&gt;I is evaluated exactly as (*P).I. For a description of the pointer indirection operator (*), see <hyperlink>25.5.1</hyperlink>. For a description of the member access operator (.), see <hyperlink>14.5.4</hyperlink>. </paragraph>
6   <paragraph>
7     <example>[Example: In the example <code_example><![CDATA[
8 struct Point  
9 {  
10    public int x;  
11    public int y;  
12    public override string ToString() {  
13       return "(" + x + "," + y + ")";  
14    }  
15 }  
16 using System;  
17 class Test  
18 {  
19    static void Main() {  
20       Point point;  
21       unsafe {  
22          Point* p = &point;  
23          p->x = 10;  
24          p->y = 20;  
25          Console.WriteLine(p->ToString());  
26       }  
27    }  
28 }  
29 ]]></code_example>the -&gt; operator is used to access fields and invoke a method of a struct through a pointer. Because the operation P-&gt;I is precisely equivalent to (*P).I, the Main method could equally well have been written: <code_example><![CDATA[
30 using System;  
31 class Test  
32 {  
33    static void Main() {  
34       Point point;  
35       unsafe {  
36          Point* p = &point;  
37          (*p).x = 10;  
38          (*p).y = 20;  
39          Console.WriteLine((*p).ToString());  
40       }  
41    }  
42 }  
43 ]]></code_example>end example]</example>
44   </paragraph>
45 </clause>