From b6b2121a9eee7cfad873fc6908f5053b7f943601 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 18 Dec 2016 23:15:15 -0600 Subject: [PATCH] Allow unsigned long values greater than 2^31 to be used as the second operand to % in constant expressions. The following is an example that would give a compile error before this patch: int main(void) { unsigned long i = 1 % 3000000000; } The remainder operation still does not work properly for signed types when either operand is negative. It gives either errors or incorrect values in various cases, both when evaluated at compile time and run time. Fully addressing this (including the run-time cases) would require library updates. --- Expression.pas | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Expression.pas b/Expression.pas index b4c16f6..7f79b76 100644 --- a/Expression.pas +++ b/Expression.pas @@ -1100,10 +1100,11 @@ var op1 := op1 div op2; end; percentch : begin {%} - if op2 <= 0 then begin - Error(109); - op2 := 1; - end; {if} + if op2 <= 0 then {FIXME: support negative values} + if (op2 = 0) or (not unsigned) then begin + Error(109); + op2 := 1; + end; {if} if unsigned then op1 := umod(op1,op2) else