Recent

Author Topic: Mismatch in header notification definitions causes not-applicable warnings  (Read 2306 times)

440bx

  • Hero Member
  • *****
  • Posts: 3946
Hello,

The Header control notifications are defined as being negative constants but, the NMHDR.code they are compared against is defined as a longword.

This causes warnings from FPC. Specifically:

Warning: range check error while evaluating constants (-306 must be between 0 and 4294967295)

This occurs for all the notification codes used by the header control.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Would you mind providing a bit more context, please? Cause right now it isn't really clear what exactly you're talking about.

Thaddy

  • Hero Member
  • *****
  • Posts: 14211
  • Probably until I exterminate Putin.
NMHDR record member constants itself are declared as signed integers (probably legacy) but the winapi NMHDR expects  longword members. Hence the compiler barks.
(/win/wininc/struct.inc is correct, messages.inc isn't)

To suppress, cast to longword on use as a work-around.
Solution is possibly to redeclare
Code: Pascal  [Select][+][-]
  1. const
  2.   HDM_TESTDUMMY = longword(-321); // instead of HDM_TESTDUMMY = -(321)
  3. var i:longint;
  4.     j:longword;  
  5. begin
  6.     i:=HDM_TESTDUMMY;  // testlongword.pas(6,8) Warning: Range check error while evaluating constants (4294966975 must be between -2147483648 and 2147483647)
  7.     j:=HDM_TESTDUMMY;  // OK.
  8.     writeln(i,'|',j);
  9. end.
Is that enough context?
[edit]
reported in Mantis as #0035324

p.s. the example actually reverses the issue to make it clear.
« Last Edit: April 05, 2019, 10:57:06 am by Thaddy »
Specialize a type, not a var.

ASerge

  • Hero Member
  • *****
  • Posts: 2223
For clarification.
SDK defines such const as unsigned (commctrl.h):
Code: C  [Select][+][-]
  1. #define HDN_FIRST               (0U-300U)       // header
But FPC as signed (commctrl.pp)
Code: Pascal  [Select][+][-]
  1. HDN_FIRST                      = (0-300);          // header
So it will be enough to specify
Code: Pascal  [Select][+][-]
  1. HDN_FIRST                      = LongWord(0-300);          // header

440bx

  • Hero Member
  • *****
  • Posts: 3946
Code: Pascal  [Select][+][-]
  1. HDN_FIRST                      = (0-300);          // header
So it will be enough to specify
Code: Pascal  [Select][+][-]
  1. HDN_FIRST                      = LongWord(0-300);          // header
Yes, fortunately, it is a very simple thing to fix.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14211
  • Probably until I exterminate Putin.
Yes. As I showed before ASerge. Aside: it is indeed legacy..
Specialize a type, not a var.

 

TinyPortal © 2005-2018