Re: NSAssert question
Re: NSAssert question
- Subject: Re: NSAssert question
- From: Fritz Anderson <email@hidden>
- Date: Sun, 21 Dec 2003 22:03:17 -0600
On Dec 21, 2003, at 8:32 PM, matt neuburg wrote:
I'm saying this:
NSAssert (((n <= [arr count]) && (n >= -1)), @"Out of range error.");
The assertion is being raised and I don't understand why. By setting a
breakpoint at [NSException raise] I can stop right at the point where
this
assertion is raised. At that moment, n is -1, and [arr count] is 2.
Well, -1
is less than 2 and -1 is greater-than-or-equal to -1 (namely equal).
So what's
the problem here?
The result of -[NSArray count] is an unsigned int. Unless I am much
mistaken, when int n is compared to an unsigned int, it is first
promoted to unsigned int = 0xffffffff = 4G, which is apt to be much
greater than the size of your array. The assertion will therefore
always trigger for n < 0.
-- F
_______________________________________________
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.