Re: Cocoa-dev Digest, Vol 7, Issue 890
Re: Cocoa-dev Digest, Vol 7, Issue 890
- Subject: Re: Cocoa-dev Digest, Vol 7, Issue 890
- From: Quincey Morris <email@hidden>
- Date: Wed, 8 Sep 2010 11:50:55 -0700
On Sep 8, 2010, at 11:07, Chris Tracewell wrote:
> I am truly perplexed - the boolean YES is being returned as -256. I think my problem is with how BOOL is being passed, cast, interpreted... I know it is typedef, it's as if though something is getting "lost in translation. Take a look at the three following code fragments to see the strangeness. I should mention that the category this is being called from is in a private linked framework, if that makes any difference.
>
> The following are called by an NSDecimalNumber with a value of 192.2
>
> // ========== WORKS :: returns 0
>
> -(BOOL)isLessThanZero
> {
> if ([[NSDecimalNumber zero] compare:self] == NSOrderedDescending)
> {
> return [[NSDecimalNumber zero] compare:self] == NSOrderedDescending;
> }
>
> return NO;
> }
>
> // ========== DOES NOT WORK :: returns -256
>
> -(BOOL)isLessThanZero
> {
> if ([[NSDecimalNumber zero] compare:self] == NSOrderedDescending)
> {
> return YES;
> }
>
> return NO;
> }
>
>
> // ========== DOES NOT WORK :: returns -256
>
> -(BOOL)isLessThanZero
> {
> return [[NSDecimalNumber zero] compare:self] == NSOrderedDescending;
> }
It's not YES that's being "returned as" -256, but NO. (The answer is NO in all 3 cases.) -256 is 0xFFFFFF00, so you can see that NO (i.e. (signed char) 0) is being correctly returned in the low order byte, with trash in the high order bytes that's left over from earlier code.
So, the problem is not your 'isLessThanZero' method, but the calling code, which is treating the returned value as an int (or something). Presumably the calling code was compiled with an incompatible declaration of your method, or of the BOOL type.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden