2010-09-08 78 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 *類型的變量 - 從整數類型隱式轉換爲指針是一個導致警告。

相關問題