tw1622.pp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. { Source provided for Free Pascal Bug Report 1622 }
  2. { Submitted by "Henrik C. Jessen" on 2001-09-28 }
  3. { e-mail: [email protected] }
  4. PROGRAM Test;
  5. {$ifdef go32v2}
  6. CONST
  7. SomeSegment = $B800;
  8. SomeOffset = $0000;
  9. VAR
  10. AbsOne : Word ABSOLUTE $B800:$0000;
  11. { -- accepted by FPC }
  12. AbsTwo : Word ABSOLUTE SomeSegment:SomeOffset;
  13. { -- NOT accepted by FPC }
  14. AbsThree : Word ABSOLUTE $B000+$400*2:24*16+4-32;
  15. AbsFour : Word ABSOLUTE SomeSegment+$400*2:SomeOffset*4-32;
  16. { The two variables above are at the same }
  17. { address; that is correctly recognized }
  18. { by Borland Pascal. }
  19. {-----------------------------------------}
  20. {$endif go32v2}
  21. { Adding some test code for normal absolute stuff }
  22. procedure testabs(var x : longint);
  23. var
  24. y : longint absolute x;
  25. begin
  26. y:=x+1;
  27. end;
  28. { If x is diclared as const parametr
  29. the compilation should fail }
  30. procedure testabs2({const }x : longint);
  31. var
  32. y : longint absolute x;
  33. begin
  34. y:=x+1;
  35. end;
  36. procedure teststring(s : string);
  37. var
  38. y : byte absolute s;
  39. begin
  40. { this will truncate the string to 4 chars }
  41. y:=4;
  42. Writeln(s);
  43. end;
  44. procedure teststringvar(var s : string);
  45. var
  46. y : byte absolute s;
  47. begin
  48. { this will truncate the string to 4 chars }
  49. y:=4;
  50. Writeln(s);
  51. end;
  52. procedure test_global_var;
  53. var
  54. y : integer absolute system.exitcode;
  55. begin
  56. y := 315;
  57. end;
  58. const
  59. x : longint = 5;
  60. y : longint = 7;
  61. var
  62. s : string;
  63. BEGIN
  64. testabs(x);
  65. if x<>6 then
  66. begin
  67. Writeln('Error in absolute handling');
  68. Halt(1);
  69. end;
  70. testabs2(y);
  71. if y<>7 then
  72. begin
  73. Writeln('Error in absolute handling');
  74. Halt(1);
  75. end;
  76. s:='Test dummy string';
  77. teststring(s);
  78. if s<>'Test dummy string' then
  79. begin
  80. Writeln('Error in absolute handling for strings');
  81. Halt(1);
  82. end;
  83. teststringvar(s);
  84. if s<>'Test' then
  85. begin
  86. Writeln('Error in absolute handling for strings');
  87. Halt(1);
  88. end;
  89. test_global_var;
  90. if exitcode<>315 then
  91. begin
  92. Writeln('Error in absolute handling');
  93. Halt(1);
  94. end;
  95. exitcode:=0;
  96. END.