• 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: NSUInteger in for-loop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSUInteger in for-loop?


  • Subject: Re: NSUInteger in for-loop?
  • From: Jerry Krinock <email@hidden>
  • Date: Sun, 14 Sep 2008 21:37:26 -0700


On 2008 Sep, 14, at 21:31, Nathan Kinsinger wrote:

On Sep 14, 2008, at 10:15 PM, Alex Reynolds wrote:

NSLog(@"NSUInteger: %d", counter);


The correct type modifier for unsigned integers is %u not %d. Switch it and try again to see what's really happening.

Ah, I believe he'll probably see all positive numbers.

Look at it this way. By definition, an NSUInteger or a unit is always >= 0. I believe that explains all the results.

From a more practical perspective, think of that most significant bit as a 'carry' bit or 'overflow' indicator. You need it to tell when you're greater than all ffff's. Bottom line, I suppose, is to always use signed integers in this type of situation. It seems unfair to be cutting your available range in half, but remember it's only one bit!

_______________________________________________

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: 
 >NSUInteger in for-loop? (From: Alex Reynolds <email@hidden>)
 >Re: NSUInteger in for-loop? (From: Nathan Kinsinger <email@hidden>)

  • Prev by Date: Re: NSUInteger in for-loop?
  • Next by Date: Re: NSUInteger in for-loop?
  • Previous by thread: Re: NSUInteger in for-loop?
  • Next by thread: Re: NSUInteger in for-loop?
  • Index(es):
    • Date
    • Thread