bug0225.pp 643 B

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