Re: 0 < -1 !!
Re: 0 < -1 !!
- Subject: Re: 0 < -1 !!
- From: John <email@hidden>
- Date: Thu, 22 Jul 2004 22:23:09 -0500
On Jul 22, 2004, at 9:48 PM, Jerry LeVan wrote:
[snip]
When currentIndex was zero and [excutedStatements count] was zero
the method was returning YES ie 0 < -1 is true !
[snip]
After squandering several hours ( it took a while to see what the
problem was).
I Read The Fine Manual and it told me that the count method returns an
"unsigned"
The signed integer -1 is stored in hexadecimal as 0xFFFFFFFF. This
number, when evaluated as an unsigned int, is the decimal number
4294967295. When 0 is compared to 0xFFFFFFFF, and the latter is
interpreted as unsigned, you're evaluating 0 < 4294967295, not 0 < -1.
I guess I have to go back and review how expressions are evaluated.
The fix was....
currentIndex < (int)[executedStatements count] - 1
The cast forces 0xFFFFFFFF be evaluated as signed, which means -1 when
count == 0.
Hope this helps.
John
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: | |
| >0 < -1 !! (From: Jerry LeVan <email@hidden>) |