Re: NSAssert question
Re: NSAssert question
- Subject: Re: NSAssert question
- From: "Louis C. Sacha" <email@hidden>
- Date: Sun, 21 Dec 2003 20:00:31 -0800 (PST)
Hello...
Well, assuming arr is an instance of NSArray or a similar class, the
returned value for [arr count] is an unsigned integer. Is it possible that
n is being cast/converted to an unsigned integer as part of the first
comparison? Then -1 == 0xFFFFFFFF which is significantly greater than 2,
and would raise your out of range error...
Louis
>
I'm sure this is a dumb question, but hey, C isn't my first language, and
>
macros *really* aren't my first language.
>
>
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?
>
>
If I copy the condition right out of this line and paste it into gdb and ask
>
for an evaluation, it is true:
>
>
p ((n <= [arr count]) && (n >= -1)) [Result is 1, i.e. true.]
>
>
So if it's true in the mind of gdb, and it's true in the mind of me, why
is it
>
false in the mind of the assertion handling mechanism? I'm guessing it's
>
something about how macros work.
>
>
Meanwhile I've commented out the NSAssert line and the program runs fine. m.
>
--
>
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
>
pantes anthropoi tou eidenai oregontai phusei
>
AppleScript: the Definitive Guide! NOW SHIPPING...! (Finally.)
>
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
>
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
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.