On Sun, May 29, 2011 at 1:04 PM, julius <jul...@juliuspaintings.co.uk> 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com