1 // Compiler options: -unsafe
5 class PointerArithmeticTest
7 unsafe public static int Main()
10 return CheckAdd((byte*)(-1), -1);
11 } catch (System.OverflowException) {}
15 return CheckSub((short*)(-1), int.MaxValue);
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))
25 Console.WriteLine ("OK");
29 unsafe static int* Conversions (long b)
34 unsafe static int CheckAdd(byte* ptr, int offset)
36 if (checked(ptr + offset < ptr))
42 unsafe static int CheckSub(short* ptr, int offset)
44 if (checked(ptr - offset < ptr))
50 unsafe static int CheckSub(short* ptr, long offset)
52 if (checked(ptr - offset < ptr))
58 unsafe static int CheckSub2(short* ptr, int offset)
60 short* b = ptr + offset;
61 if (checked(ptr - b < 0))