Forum > General
Odd range check warnings
PascalDragon:
--- Quote from: RememberTP on June 13, 2024, 09:15:11 pm ---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.
--- End quote ---
Of course it assumes the whole expression is unsigned, because grand does not have a type and both n and i are unsigned. The result of an expression does not depend on the result type, only on the involved parts.
RememberTP:
Yes, constants don't have a type, but if you 'type' a constant, it's no longer a constant but an initialised variable. (Thank you, Turbo Pascal...)
it's interesting to me that
--- 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";}};} --- result := (n + i) -1000;
is fine, even when it's known at compile time that both n and i = 1.
(And I still think the compiler should realise that the end result is an integer expression and not jump to conclusions just because evaluation of it starts with two words.)
Joanna:
I’m curious what kind of programming problem you are trying to solve ?Maybe it would be better to use integer, it is More versetile.
RememberTP:
The function is working out if something is good (+ve result) or bad (-ve result) so returns an integer. But the things it uses to work that out should all be positive.
If they're not, something's gone wrong so I'd like range checking to catch that, hence having them as words.
Does that make sense?
MarkMLl:
What if the result is zero?
I suggest that if you want a go/nogo result then you should be using a Boolean, and that would give you scope for using a larger variable type (or for that matter a log scale) internally.
FPC constants default to Int64, and IMO it would be better practice to finish of with an explicit comparison than by trying to base the returned value on casts.
MarkMLl
Navigation
[0] Message Index
[*] Previous page