• 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: Why does NSArray count return NSUInteger?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does NSArray count return NSUInteger?


  • Subject: Re: Why does NSArray count return NSUInteger?
  • From: Kyle Sluder <email@hidden>
  • Date: Sun, 29 May 2011 13:14:11 -0700

On Sun, May 29, 2011 at 1:04 PM, julius <email@hidden> wrote:
> Hi,
> I have just spent time investigating why
> an if statement involving an [array count] was apparently misbehaving.
>
> The construct was this:
>        if(3 < ([zAry count] - 10))
> It delivers a (to me unexpected) result when [zAry count] < 10.
>
> In fact
>        if(3 >= ([zAry count] - 10))
> also returns an unexpected result for the same [zAry count] value.
>
> The reason is that [zAry count] returns a result of type NSUInteger!!!!
>
> Thus for this type of comparison I need to coerce the type to NSInteger i.e.
>        if(3 < ((NSInteger)[zAry count] - 10))
>
>
> Why might the Cocoa developers have chosen to do this?

Because it doesn't make sense for an array to have fewer than 0 elements?

Silent signed/unsigned promotion issues are known behavior in the C
language. It is your responsibility to understand the code you're
writing and anticipate them accordingly.

--Kyle Sluder
_______________________________________________

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

References: 
 >Why does NSArray count return NSUInteger? (From: julius <email@hidden>)

  • Prev by Date: Re: Why does NSArray count return NSUInteger?
  • Next by Date: Re: [super dealloc] when init fails. Was: Logging pointer EXC_BAD_ACCESS?
  • Previous by thread: Re: Why does NSArray count return NSUInteger?
  • Next by thread: Re: Why does NSArray count return NSUInteger?
  • Index(es):
    • Date
    • Thread