我有一个简单的警告在我的iphone dev代码。使指针从整数没有演员
NSUInteger *startIndex = 20;
此代码的工作,但我有一个警告:
警告:传递“setStartIndex:”的参数1时将整数指针不进行强制转换
感谢您的帮助。
我有一个简单的警告在我的iphone dev代码。使指针从整数没有演员
NSUInteger *startIndex = 20;
此代码的工作,但我有一个警告:
警告:传递“setStartIndex:”的参数1时将整数指针不进行强制转换
感谢您的帮助。
警告几乎说明了一切:你是初始化startIndex
,这是一个指针到NSUInteger
,到20
,这是一个整数文字。你需要分配空间来保存整数本身。
它可能是你想要的是更多的东西是这样的:
NSUInteger *startIndex = malloc(sizeof(NSUInteger));
*startIndex = 20;
或许
static NSUInteger startIndex = 20;
NSUInteger *startIndexPtr = &startIndex;
但考虑到变数名称,看来你也可以得过且过的语义有点,可能真的只是想:
NSUInteger startIndex = 20;
NSUInteger是标量类型(定义为typedef unsigned int NSUInteger;
)。更正您的代码:
NSUInteger startIndex = 20;
你可以用它直接之后(或&的startIndex如果你需要一个指针传递给NSUInteger)。