Take stars out of types where they make more sense.
[mono-project.git] / mcs / tests / test-643.cs
blobc88ac8885e5c075d882071ae3aa485b599ff5091
1 // Compiler options: -unsafe
3 using System;
5 class PointerArithmeticTest
7 unsafe public static int Main()
9 try {
10 return CheckAdd((byte*)(-1), -1);
11 } catch (System.OverflowException) {}
13 try {
14 if (IntPtr.Size <= 4)
15 return CheckSub((short*)(-1), int.MaxValue);
16 else
17 return CheckSub((short*)(-1), long.MaxValue);
18 } catch (System.OverflowException) {}
20 CheckSub2((short*)(-1), int.MaxValue);
22 if ((long)Conversions (long.MaxValue) != (IntPtr.Size <= 4 ? uint.MaxValue : long.MaxValue))
23 return 5;
25 Console.WriteLine ("OK");
26 return 0;
29 unsafe static int* Conversions (long b)
31 return (int*)b;
34 unsafe static int CheckAdd(byte* ptr, int offset)
36 if (checked(ptr + offset < ptr))
37 return 1;
39 return 101;
42 unsafe static int CheckSub(short* ptr, int offset)
44 if (checked(ptr - offset < ptr))
45 return 2;
47 return 102;
50 unsafe static int CheckSub(short* ptr, long offset)
52 if (checked(ptr - offset < ptr))
53 return 2;
55 return 102;
58 unsafe static int CheckSub2(short* ptr, int offset)
60 short* b = ptr + offset;
61 if (checked(ptr - b < 0))
62 return 3;
64 return 0;