I compiled the program with -Criot -gl
flags and instead of 1 I get a lot of results to my surpise (in fact, I was looking for fix a 216 error). The first is with the below code that's a simple hashing function. I have no idea how to fix this.
function HashStr(s : string) : integer;
var h : integer;
var c : char;
begin
h := 0;
for c in s do
h := ord(c) + 31 * h; { This is the line of error }
HashStr := h;
end;
How can this be out of ranges?
Easily, say you have a string "zzzzzzzzzzz". Ord(c) wil be 122, so the sequence is
Which exceeds the 32767 limit for 16 bit ints, if it's a 32 but int, it won't take many more iterations to exceed that limit.