Jon Jagger
jon@jaggersoft.com
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 25 Unsafe codeprevious at this levelnext at this level 25.5 Pointers in expressionsprevious at this levelnext at this level 25.5.3 Pointer element access Paragraph 11 A pointer-element-access consists of a primary-no-array-creation-expression followed by an expression enclosed in "[" and "]". pointer-element-access : primary-no-array-creation-expression [ expression ] Paragraph 21 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 int, uint, long, or ulong. Paragraph 31 A pointer element access of the form P[E] is evaluated exactly as *(P + E). 2 For a description of the pointer indirection operator (*), see §25.5.1. 3 For a description of the pointer addition operator (+), see §25.5.6. [Example: In the example
class Test  
{  
   static void Main() {  
      unsafe {  
         char* p = stackalloc char[256];  
         for (int i = 0; i < 256; i++) p[i] = (char)i;  
      }  
   }  
}  
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:
class Test  
{  
   static void Main() {  
      unsafe {  
         char* p = stackalloc char[256];  
         for (int i = 0; i < 256; i++) *(p + i) = (char)i;  
      }  
   }  
}  
end example]
Paragraph 41 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: This is the same as C and C++. end note]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS