2007-05-25 Jonathan Chambers <joncham@gmail.com>
[mcs.git] / tests / test-401.cs
blob7293b24e93d3dad7cd239f7289e69a16035202fa
1 // Compiler options: -unsafe
3 //
4 // This test excercises stackalloc, some pointer arithmetic,
5 // and dereferences
6 //
7 using System;
8 unsafe class X {
9 static int Main ()
11 char *ptr = stackalloc char [10];
12 char *cptr = ptr;
13 int i;
14 long l = 0;
15 ulong ul = 0;
16 byte b = 0;
18 for (i = 0; i < 10; i++)
19 ptr [i] = (char) (i + 10);
21 for (i = 0; i < 10; i++){
22 if (*ptr != (char) (i + 10))
23 return 200 + i;
24 ptr++;
28 // Now test index access with longs
29 if (cptr [l] != 10){
30 return 1;
32 if (cptr [ul] != 10)
33 return 2;
34 if (cptr [b] != 10)
35 return 3;
38 // Try to compile non-int values
40 byte* bptr = (byte*) 5;
41 ushort us = 3;
42 byte* ret = (byte*) (bptr + us);
44 Console.WriteLine ("Ok");
45 return 0;