Re: NSUInteger question
Re: NSUInteger question
- Subject: Re: NSUInteger question
- From: Corbin Dunn <email@hidden>
- Date: Wed, 09 Apr 2008 10:43:34 -0700
On Apr 9, 2008, at 9:39 AM, Michael Ash wrote:
On Wed, Apr 9, 2008 at 12:30 PM, Corbin Dunn <email@hidden>
wrote:
On Apr 8, 2008, at 5:30 PM, Timothy Reaves wrote:
What advantage does NSUinteger have over uint32? I realize
that
on a 64 bit machine, it would be a uint64.
I think everyone is missing the point. The advantage is not "None".
Chris Parker already gave the first good advantage. The second is
this: Use
NSInteger/NSUInteger everywhere in your app. Recompile it for 64-
bit and you
instantly have a fully 64-bit version with very little work. That's
a huge
advantage.
But the same effect could be had simply by using "long" and "unsigned
long".
No, the same effect could not have been done, for one of the reasons
you mention below.
If those are not well defined enough for you then you can use
the types in stdint.h or sys/types.h so that you can pick a type which
means exactly what you want. For example, if you're worried about
future compatibility on an LLP64 system, intptr_t and uintptr_t are
essentially equivalent to NS[U]Integer in meaning.
My understanding is that the main advantage of NS[U]Integer is that
it's still an int, not a long, on 32-bit. While the two types are
essentially identical in the 32-bit world, they do have different
@encode strings, so using NS[U]Integer avoids changing the signatures
of methods which existed prior to 10.5.
Yes, this is true.
IMO it's dangerous to talk about a 64-bit conversion in this manner.
I disagree. It eases transition for apps that use the NSInteger type.
Please read our release notes on the subject:
http://developer.apple.com/releasenotes/Cocoa/Foundation.html#64Bit
and the documentation:
http://developer.apple.com/documentation/Cocoa/Conceptual/Cocoa64BitGuide/Introduction/chapter_1_section_1.html
Much like any other architecture change, there are a lot of different
effects and blindly using "safe" types is not guaranteed to make your
app work after a recompile.
Yes; there are many cases where blindly using NSInteger/NSUInteger can
get you unexpected results. But, we document the typical pitfalls, and
they are easy to avoid. Certain apps (like TextEdit) can simply be
recompiled.
Likewise an application which uses
non-NSInteger types may be written to Just Work when recompiled as
64-bit.
That is true too. You can easily recompile an app that uses int/float
and still having it do most of its computations with 32-bit values, or
use appropriate types where applicable. But that isn't a full 64-bit
app unless you convert all uses of int to a larger type. You wouldn't
write this on 32-bit:
for (short i = 0; i < ..; i++)
And similarly, you shouldn't write this on 64-bit:
for (int i = 0; i < ..; i++)
If you are using any Cocoa API's you should be using NSInteger/
NSUInteger, and not doing so would require much more work.
The question was "what advantage is there for using NSInteger/
NSUInteger". The answer is 64-bit transition of your Cocoa apps.
-corbin
_______________________________________________
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