2010-09-08 81 views
1

我正在开发一个iphone应用程序,当我编译它时,我收到一些警告。该应用程序的工作原理,但可能删除所有警告不是很有趣吗?NSAllocateCollectable它可能与iPhone应用程序?

这是其中之一,我不能低估,基本上是因为我是一个iPhone SDK的“新手”,这个类来自另一个代码(免费代码)。

警告是:

警告:的功能隐式声明 'NSAllocateCollectable' 警告:初始化时将整数指针,未作铸造

的代码是这样的:

double *MatrixAllocateArray(NSUInteger rows, NSUInteger columns) 
{ 
    // Allocate an array to hold [rows][columns] matrix values 
    NSCParameterAssert(rows!=0); 
    NSCParameterAssert(columns!=0); 
    __strong double *array = NSAllocateCollectable(SIZEOFARRAY(rows,columns),0); //(WARNINGS APPEAR HERE) 
    NSCAssert2(array!=NULL,@"falled to allocate %dx%d matrix",rows,columns); 

    return array; 
} 

正如你可以看到这个函数试图分配一个矩阵,它被另一个函数调用。

double *MatrixAllocateEmptyArray(NSUInteger rows, NSUInteger columns) 
{ 
    // Allocate a matrix array and fill it with zeros 
    __strong double *emptyArray = MatrixAllocateArray(rows,columns); 
    bzero(emptyArray,SIZEOFARRAY(rows,columns)); 

    return emptyArray; 
} 

,这是由我执行的功能和需要调用:

- (id)initWithRows:(NSUInteger)rowCount columns:(NSUInteger)colCount 
{ 
    // Create an empty matrix 

    return [self initWithAllocatedArray:MatrixAllocateEmptyArray(rowCount,colCount) 
      rows:rowCount 
     columns:colCount]; 
} 

回答

2

有没有垃圾回收iPhone计划。分配可收集的内存在该守护程序中几乎没有意义,所以你可能运气不好。您应该修复您的程序和/或框架以使用传统的Objective-C内存管理实践。针对您的具体警告的原因:

  1. implicit declaration of function 'NSAllocateCollectable'

    没有的NSAllocateCollectable为你的iPhone应用程序的声明,所以编译器会回落到隐函数声明默认的C规则,这意味着它将假定它返回int

  2. initialization makes pointer from integer without a cast

    因为前面问题的隐式声明的,你的代码看起来编译好像它正试图分配intdouble *类型的变量 - 从整数类型隐式转换为指针是一个导致警告。

相关问题