t65_array_access.pas 968 B

1234567891011121314151617181920212223242526272829303132
  1. program t65_array_access;
  2. { t65 -- array ELEMENT and record FIELD access, which is where the width
  3. matters. CALC does both at once: `Sheet[FX,FY].CellStatus'.
  4. The point of this fixture is that an element's WIDTH is not its array's. A
  5. constant subscript folds (index - lower bound) * element size into the
  6. address, and the value's width becomes the ELEMENT's - so `v[1] := 11' writes
  7. two bytes, not the whole ten-byte array. A field selection adds the field's
  8. offset and takes the field's width and class.
  9. `v[3] := v[1] + v[2]' reads two elements and writes a third, so a wrong
  10. scaling, a wrong lower-bound subtraction or a wrong store width all change
  11. the printed number. .out is 33 then 12. }
  12. type
  13. Rec = record
  14. A : Integer;
  15. B : Integer;
  16. end;
  17. var
  18. v : array [1..4] of Integer;
  19. r : Rec;
  20. begin
  21. v[1] := 11;
  22. v[2] := 22;
  23. v[3] := v[1] + v[2];
  24. writeln (v[3]);
  25. r.A := 5;
  26. r.B := 7;
  27. writeln (r.A + r.B)
  28. end.