Re: NSUInteger in for-loop?
Re: NSUInteger in for-loop?
- Subject: Re: NSUInteger in for-loop?
- From: Jason Coco <email@hidden>
- Date: Mon, 15 Sep 2008 00:47:39 -0400
On Sep 15, 2008, at 00:42 , Alex Reynolds wrote:
Interesting:
...
2008-09-14 21:38:56.311 NSUIntTest[19750:10b] NSUInteger: 2
2008-09-14 21:38:56.329 NSUIntTest[19750:10b] NSUInteger: 1
2008-09-14 21:38:56.341 NSUIntTest[19750:10b] NSUInteger: 0
2008-09-14 21:38:56.344 NSUIntTest[19750:10b] NSUInteger: 4294967295
2008-09-14 21:38:56.344 NSUIntTest[19750:10b] NSUInteger: 4294967294
2008-09-14 21:38:56.346 NSUIntTest[19750:10b] NSUInteger: 4294967293
2008-09-14 21:38:56.354 NSUIntTest[19750:10b] NSUInteger: 4294967292
...
I will say that the NSLog was done for this particular example, just
to see what's going on.
The loop otherwise keeps rolling along, with or without an NSLog, %d
or %u.
Going without an NSLog is how I initially found out about this
issue, in that my program would run into other problems related to
this loop going past its bounds.
NSUInteger is an unsigned integer... thus, it can't be negative and
your variable is underflowing. The various uint types are the same...
unsigned integers. Disassemble your code in the debugger :) you'll see
that since an unsigned integer ALWAYS evaluates to >= 0 by definition,
the compiler has optimized out the comparison and simply generated an
infinite loop.
NSUInteger is from 0 to NSUIntegerMax and NSInteger ranges between
NSIntegerMin and NSIntegerMax. These types change size depending on
whether you build a 64-bit app or a 32-bit app.
Jason
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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