Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why is Integer (-1) <> DWord(-1)?

464 views
Skip to first unread message

Rolf Frei

unread,
Mar 31, 2003, 8:25:57 AM3/31/03
to
Why does teh following code not display "Is True"?

procedure TForm1.FormCreate(Sender: TObject);
var
r: Integer;
begin
r := -1;
if r = DWord(-1) then
ShowMessage('Is True');
end;

Regards
Rolf

Luke

unread,
Mar 31, 2003, 8:35:37 AM3/31/03
to
You are not performing a bitwise comparison, you're performing a comparison
betweeen types that evalates to false because dword range is 0..ffffffff
positive, -1 is not a valid dword value.
You should also see a compiler warning that says "comparison always
evaluates to false"

"Rolf Frei" <ro...@eicom.ch> wrote in message
news:3e8841e5$1...@newsgroups.borland.com...

Romulo A. Ceccon

unread,
Mar 31, 2003, 8:40:19 AM3/31/03
to
Because DWord(-1) is equal to 4294967295, which is out of the bounds of the
Integer data type (which ranges from -2147483648 to 2147483647). Then, the
compiler needs to promote both variables to a quadword (Int64) (the smaller data
type that supports both -1 and 4294967295) before evaluating the comparison. And
Int64(-1) is different from Int64(DWord(-1)). You are really comparing -1 to
4294967295, which are obviously different.

Romulo

"Rolf Frei" <ro...@eicom.ch> escreveu na mensagem
news:3e8841e5$1...@newsgroups.borland.com...

Rolf Frei

unread,
Mar 31, 2003, 2:19:47 PM3/31/03
to
Thank you to clear me up. It's logical.

Regards
Rolf

"Romulo A. Ceccon" <romuloceccon 'at' yahoo 'dot' com 'dot' br> schrieb im
Newsbeitrag news:3e88...@newsgroups.borland.com...

Rudy Velthuis (TeamB)

unread,
Mar 31, 2003, 3:30:34 PM3/31/03
to
In <3e88...@newsgroups.borland.com>, Rolf Frei wrote:

> Thank you to clear me up. It's logical.

Rolf, please don't overquote.

But I think you should have found this by yourself, if you had seen the
hint or warning you get when sigend and unsigned operands are expanded to
64 bit.
--
Rudy Velthuis (TeamB)

Posted with XanaNews 1.14.2.1

0 new messages