| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- program t73_varparam;
- { t73 -- VAR parameters, and a parameter shadowing a global of the same name.
- CALC.INC has
- Ch : Char; (* a GLOBAL *)
- procedure IBMCh(var Ch: Char); ... Ch := ^E ... end;
- IBMCh(Ch);
- and expects the caller's Ch to change. This fixture is that shape:
- IBMCh's parameter is also named Ch, which ISO Pascal allows (the inner
- declaration shadows the outer one); DupTest used to reject it outright.
- Five calls, so every address path is exercised:
- * a global CHAR by reference (one byte through the pointer),
- * a global INTEGER by reference (two bytes through the pointer),
- * a LOCAL CHAR by reference (the caller passes LEA BP+off),
- * a VAR parameter passed ON to another VAR parameter (Relay -> IBMCh),
- * READ into a VAR parameter (ReadIt), which must store through the
- pointer, not into the parameter slot.
- A by-value implementation would print H, H, 41 and a; the .out is
- h, h, 42, ? and the character read by ReadIt. }
- var
- Ch : char;
- i : integer;
- procedure IBMCh (var Ch : Char);
- begin
- if Ch = 'H' then
- Ch := 'h'
- else
- Ch := '?'
- end;
- procedure Bump (var n : integer);
- begin
- n := n + 1
- end;
- procedure Relay (var c : char);
- begin
- IBMCh (c)
- end;
- procedure ReadIt (var c : char);
- begin
- read (c)
- end;
- procedure Local;
- var
- v : char;
- begin
- v := 'a';
- IBMCh (v);
- writeln (v)
- end;
- begin
- Ch := 'H';
- IBMCh (Ch);
- writeln (Ch);
- Ch := 'H';
- Relay (Ch);
- writeln (Ch);
- i := 41;
- Bump (i);
- writeln (i);
- Local;
- ReadIt (Ch);
- writeln (Ch)
- end.
|