[fpc-pascal] subtract longwords with rollover
Klaus Hartnegg
hartnegg at gmx.de
Fri Nov 29 11:00:49 CET 2013
On 28.11.2013 18:32, Tomas Hajny wrote:
> On Thu, November 28, 2013 18:12, Klaus Hartnegg wrote:
>> Sorry, I forgot to mention there is {$Q-} in the source.
>
> I believe that $Q- covers overflow checks, not range checks.
Thanks, this showed me the right direction.
Explanation: I'm trying to port code from Turbo Pascal. There
word1-word2 does wrap around with {$Q-}{$R+}. And dec(word1) never
checks for overflow, even with {$Q+}{$R+}.
FreePascal seems to have a wider definition of Range Check, and the
inc() and dec() functions do check for overflow.
The longint trick prevents runtime error 201, but causes runtime error
215 if the longword value does not fit into longint.
On closer look this is all behaving like documented, just different from
TurboPascal (maybe it would have worked in TP-compatibility-mode).
The correct fix is to simply add {$R-} to the code wherever it currently
has {$Q-}. I have just done this, and now it passes the test.
Klaus
More information about the fpc-pascal
mailing list