[fpc-pascal] Strange "division by zero" error using variants
Thomas Kurz
fpc.2021 at t-net.ruhr
Tue May 24 19:28:44 CEST 2022
Dear all,
please consider the following code:
program Project1;
{$booleval off}
var
v1, v2: variant;
a: boolean;
b: integer;
begin
a := true;
b := 0;
// this works as expected:
if a and (b > 0) and ((0+1) mod b = 0) then Writeln ('ok');
v1 := true;
v2 := 0;
// this gives a "division by zero":
if v1 and (v2 > 0) and ((0+1) mod v2 = 0) then Writeln ('ok');
end.
The "variant" variant results in a "division by zero". Obviously, it tries to evaluate the modulo-expression even though this shouldn't happen because complete boolean evaluation is disabled and the "if"-result is already known to be false after checking "v2>0".
Can anyone explain this strange behavior?
Kind regards,
Thomas
More information about the fpc-pascal
mailing list