预期在unsigned int时返回unsigned long的分歧

时间:2012-03-26 11:45:29

标签: objective-c cocoa types core-foundation nsuinteger

我正在一个类上实现-hash方法,该方法应返回NSUInteger。我的实现与此类似:

- (NSUInteger) hash {
    return CFHash(self->cfObj);
}

现在,CFHash返回CFHashCodetypedef编辑unsigned long,但就我所知,NSUInteger或者是unsigned long unsigned intunsigned long

如果我在应用程序需要unsigned int时返回{{1}},我会遇到哪些问题?

1 个答案:

答案 0 :(得分:3)

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

我认为即使在iOS或32位OS X应用上你也应该是安全的。 docs描述了CFHash的返回类型:

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

这不是一个令人信服的理由,而是default implementation of hash apparently uses CFHash anyway

相关问题