• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa-dev Digest, Vol 7, Issue 890
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Cocoa-dev Digest, Vol 7, Issue 890
      • From: Kyle Sluder <email@hidden>
References: 
 >Re: Cocoa-dev Digest, Vol 7, Issue 890 (From: Chris Tracewell <email@hidden>)

  • Prev by Date: Re: NSNumber compare: Giving Unexpected Results
  • Next by Date: Re: NSTableView/NSOutlineView variable row height code has detected re-entry.
  • Previous by thread: Re: Cocoa-dev Digest, Vol 7, Issue 890
  • Next by thread: Re: Cocoa-dev Digest, Vol 7, Issue 890
  • Index(es):
    • Date
    • Thread