tprocaddr1.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. { test applies only to these memory models: }
  2. {$if defined(FPC_MM_MEDIUM) or defined(FPC_MM_LARGE) or defined(FPC_MM_HUGE)}
  3. {$mode TP}
  4. {$F-}
  5. { should be near, since we are in $F- mode }
  6. procedure myproc;
  7. begin
  8. Writeln('myproc');
  9. end;
  10. procedure mynearproc; near;
  11. begin
  12. Writeln('mynearproc');
  13. end;
  14. procedure myfarproc; far;
  15. begin
  16. Writeln('myfarproc');
  17. end;
  18. type
  19. TMyObject = object
  20. procedure RegularMethod;
  21. end;
  22. procedure TMyObject.RegularMethod;
  23. begin
  24. Writeln('TMyObject.RegularMethod');
  25. end;
  26. procedure Error;
  27. begin
  28. Writeln('Error!');
  29. Halt(1);
  30. end;
  31. var
  32. prcn: Procedure; near;
  33. prc: Procedure;
  34. prcf: Procedure; far;
  35. ptr_prcn: Word absolute prcn;
  36. ptr_prc: FarPointer absolute prc;
  37. ptr_prcf: FarPointer absolute prcf;
  38. w: Word;
  39. P, PA: CodePointer;
  40. begin
  41. prcn := myproc;
  42. prcn;
  43. prcn := mynearproc;
  44. prcn;
  45. prc := myfarproc;
  46. prc;
  47. prcf := myfarproc;
  48. prcf;
  49. prcn := myproc;
  50. w := Ofs(myproc);
  51. P := @myproc;
  52. PA := Addr(myproc);
  53. if ptr_prcn <> w then
  54. Error;
  55. if P <> PA then
  56. Error;
  57. if Ofs(P^) <> w then
  58. Error;
  59. if Seg(P^) <> Seg(myproc) then
  60. Error;
  61. prcn := mynearproc;
  62. w := Ofs(mynearproc);
  63. P := @mynearproc;
  64. PA := Addr(mynearproc);
  65. if ptr_prcn <> w then
  66. Error;
  67. if P <> PA then
  68. Error;
  69. if Ofs(P^) <> w then
  70. Error;
  71. if Seg(P^) <> Seg(mynearproc) then
  72. Error;
  73. prcf := myfarproc;
  74. w := Ofs(myfarproc);
  75. P := @myfarproc;
  76. PA := Addr(myfarproc);
  77. if ptr_prcf <> P then
  78. Error;
  79. if P <> PA then
  80. Error;
  81. if Ofs(P^) <> w then
  82. Error;
  83. if Seg(P^) <> Seg(myfarproc) then
  84. Error;
  85. P := @TMyObject.RegularMethod;
  86. PA := Addr(TMyObject.RegularMethod);
  87. w := Ofs(TMyObject.RegularMethod);
  88. if P <> PA then
  89. Error;
  90. if Ofs(P^) <> w then
  91. Error;
  92. if Seg(P^) <> Seg(TMyObject.RegularMethod) then
  93. Error;
  94. Writeln('Ok!');
  95. end.
  96. {$else}
  97. begin
  98. { silently succeed in the other memory models }
  99. end.
  100. {$endif}