• 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: "Clark Cox" <email@hidden>
  • Date: Sun, 14 Sep 2008 21:48:12 -0700

On Sun, Sep 14, 2008 at 9:44 PM, Alex Reynolds <email@hidden> wrote:
> The %lu with casting seems to run into the same issue as %u:
>
> ...
> 2008-09-14 21:43:07.241 NSUIntTest[19779:10b] NSUInteger: 2
> 2008-09-14 21:43:07.259 NSUIntTest[19779:10b] NSUInteger: 1
> 2008-09-14 21:43:07.260 NSUIntTest[19779:10b] NSUInteger: 0
> 2008-09-14 21:43:07.261 NSUIntTest[19779:10b] NSUInteger: 4294967295
> 2008-09-14 21:43:07.262 NSUIntTest[19779:10b] NSUInteger: 4294967294

The results will be very different in a 64-bit program :)

The general point is that the NSLog is irrelevant. You are testing
that an unsigned variable is >= 0. An unsigned variable is *always*
>=0 ... it's *unsigned*. This is the reason that your loop isn't
performing to your expectations; it's doing what you said, not what
you meant :).

--
Clark S. Cox III
email@hidden
_______________________________________________

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: j o a r <email@hidden>)
 >Re: NSUInteger in for-loop? (From: Alex Reynolds <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