t73_varparam.pas 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. program t73_varparam;
  2. { t73 -- VAR parameters, and a parameter shadowing a global of the same name.
  3. CALC.INC has
  4. Ch : Char; (* a GLOBAL *)
  5. procedure IBMCh(var Ch: Char); ... Ch := ^E ... end;
  6. IBMCh(Ch);
  7. and expects the caller's Ch to change. This fixture is that shape:
  8. IBMCh's parameter is also named Ch, which ISO Pascal allows (the inner
  9. declaration shadows the outer one); DupTest used to reject it outright.
  10. Five calls, so every address path is exercised:
  11. * a global CHAR by reference (one byte through the pointer),
  12. * a global INTEGER by reference (two bytes through the pointer),
  13. * a LOCAL CHAR by reference (the caller passes LEA BP+off),
  14. * a VAR parameter passed ON to another VAR parameter (Relay -> IBMCh),
  15. * READ into a VAR parameter (ReadIt), which must store through the
  16. pointer, not into the parameter slot.
  17. A by-value implementation would print H, H, 41 and a; the .out is
  18. h, h, 42, ? and the character read by ReadIt. }
  19. var
  20. Ch : char;
  21. i : integer;
  22. procedure IBMCh (var Ch : Char);
  23. begin
  24. if Ch = 'H' then
  25. Ch := 'h'
  26. else
  27. Ch := '?'
  28. end;
  29. procedure Bump (var n : integer);
  30. begin
  31. n := n + 1
  32. end;
  33. procedure Relay (var c : char);
  34. begin
  35. IBMCh (c)
  36. end;
  37. procedure ReadIt (var c : char);
  38. begin
  39. read (c)
  40. end;
  41. procedure Local;
  42. var
  43. v : char;
  44. begin
  45. v := 'a';
  46. IBMCh (v);
  47. writeln (v)
  48. end;
  49. begin
  50. Ch := 'H';
  51. IBMCh (Ch);
  52. writeln (Ch);
  53. Ch := 'H';
  54. Relay (Ch);
  55. writeln (Ch);
  56. i := 41;
  57. Bump (i);
  58. writeln (i);
  59. Local;
  60. ReadIt (Ch);
  61. writeln (Ch)
  62. end.