* man/mono-shlib-cop.1: Add man page for mono-shlib-cop program.
[mono.git] / mcs / tests / unsafe-2.cs
1 // Compiler options: -unsafe
2
3 //
4 // This test excercises stackalloc, some pointer arithmetic,
5 // and dereferences
6 //
7 using System;
8 unsafe class X {
9         static int Main ()
10         {
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;
17                 
18                 for (i = 0; i < 10; i++)
19                         ptr [i] = (char) (i + 10);
20
21                 for (i = 0; i < 10; i++){
22                         if (*ptr != (char) (i + 10))
23                                 return 200 + i;
24                         ptr++;
25                 }
26
27
28                 // Now test index access with longs
29                 if (cptr [l] != 10){
30                         return 1;
31                 }
32                 if (cptr [ul] != 10)
33                         return 2;
34                 if (cptr [b] != 10)
35                         return 3;
36
37                 //
38                 // Try to compile non-int values
39                 //
40                 byte* bptr = (byte*) 5;
41                 ushort us = 3;
42                 byte* ret = (byte*) (bptr + us);
43                         
44                 Console.WriteLine ("Ok");
45                 return 0;
46         }
47 }       
48
49