Due to the value being a constant the compiler can check it. By using a variable the compiler can't check it that way.
Then word(8008) should deliver the correct result and it doesn't. Just tried ($ffff AND 8008) and it throws the same warning.[/quote]
No, that will not matter. If you use
Word(8008) or
($ffff AND 8008) then the compiler will expand the function to (using the first one as an example):
Result := Word((Word(8008) shr 8) or (Word(8008) shl 8));
The shifts will still result in 32-bit values that are then truncated by the typecast to
Word.
And the ctrl click took me to socketsh.inc file where it's defined as an inline. From there to winsock2.pp
function htons(hostshort: u_short): u_short; stdcall;external WINSOCK2_DLL name 'htons';
And at that point I got lost... But I think as it turns out it wouldn't have picked up on the compiler optimizing the code for a literal anyway.
When you're at the declaration of a function (in this case the one in
socketsh.inc) you need to use
Ctrl + Shift + Down to get to the implementation (in this case in
sockets.inc). Why Lazarus brings you to the next identifier with the same name if you use
Ctrl + Click again, I don't know right now.
Must be a compiler version issue because I just tried that using 3.0.4 in 64 bit windows and there is no warning.
It's an addition of 3.2.0 (revisions
42272 and
42275).