Forum > General

Compiler [Hints] in Laz 2.2.0

(1/1)

J-G:
Now I've upgraded to Laz 2.2.0 (I know 2.2.2 is available  ::) )  I've noticed that I'm getting [Hints] that "Converting the operands to "Int64" before doing the add could prevent overflow errors."

This is in connection with 6 variables that I've declared as 'Word' - all of which will only ever be in the range 0..560 - so I'm just curious to know what advantage there might be that would out-weigh the extra 36 bytes needed.



howardpc:
This has to do with the way you have declared the result variable of adding two words also to be of word size.
You as programmer know the potential ranges of your variables, but the compiler does not. It knows only that adding a Word to a Word can easily give a value that overflows a Word. So it warns you that there (might) be a problem. Only you know if there really is a problem.

Hence a Hint, rather than a Warning.

MarkMLl:

--- Quote from: J-G on May 22, 2022, 11:49:07 am ---This is in connection with 6 variables that I've declared as 'Word' - all of which will only ever be in the range 0..560

--- End quote ---

But does the compiler know that? What happens if you explicitly define them as a subrange?

MarkMLl

J-G:

--- Quote from: howardpc on May 22, 2022, 01:10:59 pm ---This has to do with the way you have declared the result variable of adding two words also to be of word size.
You as programmer know the potential ranges of your variables, but the compiler does not. It knows only that adding a Word to a Word can easily give a value that overflows a Word. So it warns you that there (might) be a problem. Only you know if there really is a problem.

Hence a Hint, rather than a Warning.
--- End quote ---

D'oh!   -  why didn't I think of that  :-[

Quite obvious  -   and I was/am only curious -- I like to see no 'notes' at the end of a successful compilation.

wp:

--- Quote from: J-G on May 22, 2022, 02:29:58 pm ---I like to see no 'notes' at the end of a successful compilation.

--- End quote ---
When you know that a compiler message is not relevant you can right-click on it in the message windows and select "Hide message by inserting IDE directive {%H-}"

Navigation

[0] Message Index

Go to full version