The check for overflow is obviously implemented different in 2.0.0 and 2.1.1
This is the line d := Ord(a)-Ord(b) in the function, translation result to assembler: with 2.0.0 (win32): .Ll2: .stabn 68,0,6,.Ll2 - P$TORD_D$CHAR$CHAR$$SMALLINT # [6] d := Ord(a)-Ord(b); movzbl -4(%ebp),%edx movzbl -8(%ebp),%eax subl %eax,%edx jno .L8 call FPC_OVERFLOW .L8: movl %edx,%eax subl $-32768,%eax cmpl $65535,%eax jbe .L9 call FPC_RANGEERROR .L9: movw %dx,-12(%ebp) .Ll3: with 2.1.1 (win32): .Ll2: .stabn 68,0,6,.Ll2 - P$TORD_D$CHAR$CHAR$$SMALLINT # [6] d := Ord(a)-Ord(b); movzbl -4(%ebp),%edx movzbl -8(%ebp),%eax subl %eax,%edx jae .L8 call FPC_OVERFLOW .L8: movl %edx,%eax cmpl $32767,%eax jbe .L9 call FPC_RANGEERROR .L9: movw %dx,-12(%ebp) .Ll3: A solution would be to replace that line by: d := integer(Ord(a))-Ord(b) It seems that the compiler now sees a "ord(c)" to be a BYTE, and BYTE - BYTE shall give a BYTE, and -1 is not in the range allowed for a BYTE. The line " i := Ord('0')-Ord('1') " in the main program is not interesting, since it contains a constant expression and is converted to " i := -1 " by the compiler. Greetings gs ----- Original Message ----- From: "Colin Western" <[EMAIL PROTECTED]> To: "FPC developers' list" <fpc-devel@lists.freepascal.org> Sent: Saturday, June 04, 2005 1:38 PM Subject: [fpc-devel] Bug 4004 > Can I ask somebody to have another look at this bug - it was flagged > unreproducable on the web system, but I still get it from the current > svn as shown below. > (Note that the orginal report was on ppc but I have the same fault on i386) > Colin > > $ fpc ord.pas > Free Pascal Compiler version 2.1.1 [2005/06/04] for i386 > Copyright (c) 1993-2005 by Florian Klaempfl > Target OS: Linux for i386 > Compiling ord.pas > Linking ord > 13 Lines compiled, 0.0 sec > $ ./ord > -1 > Runtime error 215 at $080480C5 > $080480C5 > $0804813A > > $ more ord.pas > {$R+}{$Q+} > function d(a,b:Char):Integer; > begin > d := Ord(a)-Ord(b); > end; > > var > i: Integer; > begin > i := Ord('0')-Ord('1'); > WriteLn(i); > WriteLn(d('0','1')); > end. > > > _______________________________________________ > fpc-devel maillist - fpc-devel@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel