我可以放心地UInt32的存储NSUInteger? [英] Can I safely store UInt32 to NSUInteger?
问题描述
在标题中,定义如下:
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif
也是如此没有问题,到NSUInteger(一个unsigned int)的UInt32的配合?哪里是UInt32的和unsigned int的区别?
So does an UInt32 fit without problems into an NSUInteger (an unsigned int)? Where's the difference between UInt32 and unsigned int?
和我假设一个unsigned long比一个unsigned int更大?
And I assume that an unsigned long is bigger than an unsigned int?
推荐答案
我想一个 UInt32的
和 unsigned int类型之间的唯一区别
是一个 UInt32的
保证是32位长,而一个 unsigned int类型
在技术上可能是较短如果你正在运行的(比如说)< 32位操作系统。
I suppose the only difference between a UInt32
and an unsigned int
is that a UInt32
is guaranteed to be 32 bits long, whereas an unsigned int
technically could be shorter if you were running (say) on a < 32-bit operating system.
不过,鉴于苹果和iPhone都至少有32位系统,它的安全使用 unsigned int类型
, UInt32的
和 NSUInteger
合理互换。这里唯一的不同是, NSUInteger
可能是64位长(在Mac上,为x86_64的编译时)。
However, given that the Mac and the iPhone are both at least 32-bit systems, it's safe to use unsigned int
, UInt32
, and NSUInteger
reasonably interchangeably. The only difference here is that a NSUInteger
might be 64 bits long (on the Mac, when compiling for x86_64).
至于你的问题无符号长
与 unsigned int类型
, UInt32的
的typedef定义一个无符号长
,再次表明它是安全的交替使用。一个无符号长
是保证至少大如 unsigned int类型
。
As for your question of unsigned long
versus unsigned int
, UInt32
is typedef'd to an unsigned long
, again indicating that it's safe to use interchangeably. An unsigned long
is guaranteed to be at least as big as an unsigned int
.
这篇关于我可以放心地UInt32的存储NSUInteger?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!