disable broken tests on net_4_0
[mcs.git] / docs / ecma334 / 25.5.3.xml
blob7cbd2690a77118c82513c1015c762c33dede56a7
1 <?xml version="1.0"?>
2 <clause number="25.5.3" title="Pointer element access">
3   <paragraph>A <non_terminal where="25.5.3">pointer-element-access</non_terminal> consists of a <non_terminal where="14.5">primary-no-array-creation-expression</non_terminal> followed by an expression enclosed in &quot;[&quot; and &quot;]&quot;. <grammar_production><name><non_terminal where="25.5.3">pointer-element-access</non_terminal></name> : <rhs><non_terminal where="14.5">primary-no-array-creation-expression</non_terminal><terminal>[</terminal><non_terminal where="14.14">expression</non_terminal><terminal>]</terminal></rhs></grammar_production></paragraph>
4   <paragraph>In a pointer element access of the form P[E], P must be an expression of a pointer type other than void*, and E must be an expression of a type that can be implicitly converted to <keyword>int</keyword>, <keyword>uint</keyword>, <keyword>long</keyword>, or <keyword>ulong</keyword>. </paragraph>
5   <paragraph>A pointer element access of the form P[E] is evaluated exactly as *(P + E). For a description of the pointer indirection operator (*), see <hyperlink>25.5.1</hyperlink>. For a description of the pointer addition operator (+), see <hyperlink>25.5.6</hyperlink>. </paragraph>
6   <paragraph>
7     <example>[Example: In the example <code_example><![CDATA[
8 class Test  
9 {  
10    static void Main() {  
11       unsafe {  
12          char* p = stackalloc char[256];  
13          for (int i = 0; i < 256; i++) p[i] = (char)i;  
14       }  
15    }  
16 }  
17 ]]></code_example>a pointer element access is used to initialize the character buffer in a for loop. Because the operation P[E] is precisely equivalent to *(P + E), the example could equally well have been written: <code_example><![CDATA[
18 class Test  
19 {  
20    static void Main() {  
21       unsafe {  
22          char* p = stackalloc char[256];  
23          for (int i = 0; i < 256; i++) *(p + i) = (char)i;  
24       }  
25    }  
26 }  
27 ]]></code_example>end example]</example>
28   </paragraph>
29   <paragraph>The pointer element access operator does not check for out-of-bounds errors and the behavior when accessing an out-of-bounds element is undefined. <note>[Note: This is the same as C and C++. end note]</note> </paragraph>
30 </clause>