Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 当需要unsigned int时返回unsigned long的后果_Objective C_Cocoa_Types_Core Foundation_Nsuinteger - Fatal编程技术网

Objective c 当需要unsigned int时返回unsigned long的后果

Objective c 当需要unsigned int时返回unsigned long的后果,objective-c,cocoa,types,core-foundation,nsuinteger,Objective C,Cocoa,Types,Core Foundation,Nsuinteger,我正在类上实现-hash方法,该方法应该返回整数。我对它的实现将类似于: - (NSUInteger) hash { return CFHash(self->cfObj); } 现在,CFHash返回一个CFHashCode,它是typedefedunsigned long,但据我所知,nsuiger要么是unsigned long要么是unsigned int 当应用程序需要一个无符号int时,如果我返回一个无符号long,我会遇到什么样的问题?您编译的平台是什么?正如您所指出

我正在类上实现
-hash
方法,该方法应该返回
整数。我对它的实现将类似于:

- (NSUInteger) hash {
    return CFHash(self->cfObj);
}
现在,
CFHash
返回一个
CFHashCode
,它是
typedef
ed
unsigned long
,但据我所知,
nsuiger
要么是
unsigned long
要么是
unsigned int


当应用程序需要一个
无符号int
时,如果我返回一个
无符号long
,我会遇到什么样的问题?

您编译的平台是什么?正如您所指出的,
NSUInteger
是无符号长整数还是无符号整数取决于您的体系结构是32位还是64位。对于64位OS X应用程序,这显然是好的

我认为即使在iOS或32位OSX应用程序上,你也应该是安全的。描述
CFHash
的返回类型:

An integer of type CFHashCode that represents a hashing value for cf.

这不是一个令人信服的理由,但是。

您编译的是什么平台?正如您所指出的,
NSUInteger
是无符号长整数还是无符号整数取决于您的体系结构是32位还是64位。对于64位OS X应用程序,这显然是好的

我认为即使在iOS或32位OSX应用程序上,你也应该是安全的。描述
CFHash
的返回类型:

An integer of type CFHashCode that represents a hashing value for cf.

这不是一个令人信服的理由,但是。

我认为不会有任何问题,即使存在哈希冲突,也应该正确处理。我认为不会有任何问题,即使存在哈希冲突,也应该正确处理。我正在为ios编译,但我不确定这是32位还是64位。我主要担心的是返回long会在32位系统上造成某种溢出,但是从你的回答来看,这不是我必须担心的事情?你应该会没事的-iOS是32位的,但是使用
CFHash
和整数不应该有任何冲突。我是为iOS编译的,但我不确定这是32位还是64位。我主要担心的是返回long会在32位系统上造成某种溢出,但是从你的回答来看,这不是我必须担心的事情?你应该会没事的-iOS是32位的,但是使用
CFHash
和整数不应该有任何冲突。