tb0191.pp 743 B

123456789101112131415161718192021222324252627282930313233
  1. { Old file: tbs0225.pp }
  2. { Sigsegv when run with range checks on open arrays OK 0.99.11 (PFV) }
  3. program bug0255;
  4. {$mode objfpc}
  5. {$R+}
  6. function erwwert(const feld: array of LongInt):extended;
  7. var i: LongInt;
  8. begin
  9. Result:=0;
  10. for i:=low(feld) to high(feld)
  11. do begin
  12. writeln(i); // gives "0"
  13. Result:=Result+feld[i];
  14. end; //^^^^^^^ there occurs the segfault (216)
  15. // on the first loop
  16. Result:=Result/(high(feld)-low(feld)+1);
  17. end;
  18. var werte: array[0..299] of LongInt;
  19. i: LongInt;
  20. begin
  21. //init the array
  22. for i:=0 to 299
  23. do werte[i]:=Random(5)-2;
  24. //and do something with it
  25. writeln(erwwert(werte):6:5);
  26. end.