fork download
  1. using System;
  2. using System.Diagnostics.Contracts;
  3.  
  4. public class Test
  5. {
  6. unsafe static char* MatchChars(char* p, char* p2) {
  7. Console.WriteLine("MatchChars:");
  8. if (*p2 == '\0') {
  9. Console.WriteLine("return null; (1)");
  10. return null;
  11. }
  12. for (; (*p2 != '\0'); p++, p2++) {
  13. if (*p != *p2) {
  14. Console.WriteLine("return null; (2)");
  15. return null;
  16. }
  17. }
  18. Console.WriteLine("return p;");
  19. return p;
  20. }
  21.  
  22. unsafe static int* MatchInts(int* p, int* p2) {
  23. Console.WriteLine("MatchInts:");
  24. if (*p2 == '\0') {
  25. Console.WriteLine("return null; (1)");
  26. return null;
  27. }
  28. for (; (*p2 != 0); p++, p2++) {
  29. if (*p != *p2) {
  30. Console.WriteLine("return null; (2)");
  31. return null;
  32. }
  33. }
  34. Console.WriteLine("return p;");
  35. return p;
  36. }
  37.  
  38. unsafe public static void Main()
  39. {
  40. fixed (char* p1 = new char[] { '.', '5' } )
  41. {
  42. fixed (char* p2 = ".")
  43. {
  44. MatchChars(p1, p2);
  45. }
  46. }
  47. Console.WriteLine("------------------");
  48. fixed (int* p1 = new int[] { 5, 10, 15, 20 } )
  49. {
  50. fixed (int* p2 = new int [] { 5 } )
  51. {
  52. MatchInts(p1, p2);
  53. }
  54. }
  55. Console.WriteLine("------------------");
  56.  
  57. }
  58. }
Success #stdin #stdout 0.02s 14564KB
stdin
Standard input is empty
stdout
MatchChars:
return p;
------------------
MatchInts:
return p;
------------------