Forum > General

Odd range check warnings

(1/2) > >>

RememberTP:
When I compile the following..


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program canIReproduceThis; {$R-} const  grand = 1000; function xxx(i: word): integer;var  n: word;begin  n := 1;  result := -grand + (n + i);  (* produces warning?? *)end; function yyy(i: word): integer;var  n: word;begin  n := 1;  exit(-grand + (n + i));      (* produces warning?? *)end; function zzz(i: word): integer;var  n: word;begin  n := 1;  zzz := -grand + (n + i);     (* produces warning?? *)end; function aaa(i: word): integer;var  n: word;begin  n := 1 + i;  result := -grand + (n);      (* no warning?? *)end; function bbb(i: word): integer;var  n: word;begin  n := 1;  i := i + n ;  result := -grand + (i);      (* no warning?? *)end; function ccc(i: word): integer;var  n: word;begin  n := 1;  result := -grand + n + i;    (* no warning?? *)end; function ddd(i: word): integer;var  n: word;begin  n := 1;  result := -grand + (n) + (i);    (* no warning?? *)end; begin  writeln(xxx(1));   writeln(yyy(1));   writeln(zzz(1));   writeln(aaa(1));   writeln(bbb(1));   writeln(ccc(1));   writeln(ddd(1));end.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---$ fpc -S2 cirt.pas Free Pascal Compiler version 3.2.2 [2021/07/09] for x86_64Copyright (c) 1993-2021 by Florian Klaempfl and othersTarget OS: Linux for x86-64Compiling cirt.pasfpc-poss-bug.pas(13,13) Warning: range check error while evaluating constants (-1000 must be between 0 and 18446744073709551615)fpc-poss-bug.pas(21,8) Warning: range check error while evaluating constants (-1000 must be between 0 and 18446744073709551615)fpc-poss-bug.pas(29,10) Warning: range check error while evaluating constants (-1000 must be between 0 and 18446744073709551615)Linking fpc-poss-bug79 lines compiled, 0.1 sec3 warning(s) issued
Why the warnings?

If I have range-checking on, they're fatal errors.

RememberTP:
The program that this is boiled down from has a slightly more complicated expression for the result - the parentheses are there for my benefit to make sure I have the operator precedence right!

Joanna:
Word type is for positive numbers only.

RememberTP:
Ah, it works if I cast the problematic bit of the expression to be an integer, but it's odd (to me) that the compiler adds two words and then assumes the whole expression must be type word unless I do this.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function www(i: word): integer;var  n: word;begin  n := 1;  result := -grand + integer(n + i);  (* no warning?? *)end;

RememberTP:

--- Quote from: Joanna on June 13, 2024, 09:14:23 pm ---Word type is for positive numbers only.
--- End quote ---

Mmm, yes indeed, but the function for which this is a result returns an integer.

Navigation

[0] Message Index

[#] Next page

Go to full version