Recent

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

440bx

  • Hero Member
  • *****
  • Posts: 1202
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.

using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 674
  • 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: 9190
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 »
also related to equus asinus.

ASerge

  • Hero Member
  • *****
  • Posts: 1412
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: 1202
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.
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 9190
Yes. As I showed before ASerge. Aside: it is indeed legacy..
also related to equus asinus.