Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2014-04

Overflow checks differ between constants and variables

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

In the below example range and overflow checks are off.

The "a-b" line gives the result "2". (As expected after the overflow)

Doing the same operation with constants, does not compile, due to an overflow error (despite $Q-). Why?

program Project1;
{$R-}{$Q-}
var a, b: qword;
begin
   a := 1;
   b := qword($ffffffffffffffff);
   writeln(a-b);
   writeln( qword(1) - qword($ffffffffffffffff) );    //
project1.lpr(7,21) Error: Overflow in arithmetic operation
   readln;
end.

Reply by email