Recent

Author Topic: Compiler [Hints] in Laz 2.2.0  (Read 806 times)

J-G

  • Hero Member
  • *****
  • Posts: 953
Compiler [Hints] in Laz 2.2.0
« on: May 22, 2022, 11:49:07 am »
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.



FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Compiler [Hints] in Laz 2.2.0
« Reply #1 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.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Compiler [Hints] in Laz 2.2.0
« Reply #2 on: May 22, 2022, 01:35:17 pm »
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

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

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: Compiler [Hints] in Laz 2.2.0
« Reply #3 on: May 22, 2022, 02:29:58 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.

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.

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Compiler [Hints] in Laz 2.2.0
« Reply #4 on: May 22, 2022, 04:08:28 pm »
I like to see no 'notes' at the end of a successful compilation.
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-}"

 

TinyPortal © 2005-2018