【问题标题】:NSAllocateCollectable it is possible with iPhone application?NSAllocateCollectable 是否可以使用 iPhone 应用程序?
【发布时间】:2010-09-08 21:21:39
【问题描述】:

我正在开发一个 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];
}

【问题讨论】:

    标签: iphone objective-c xcode


    【解决方案1】:

    iPhone 程序没有垃圾收集器。在那种情况下分配可收集的内存几乎没有意义,所以你可能不走运。您可能应该修复您的程序和/或框架以使用传统的 Objective-C 内存管理实践。您发出具体警告的原因:

    1. implicit declaration of function 'NSAllocateCollectable'

      您的 iPhone 应用程序没有 NSAllocateCollectable 声明,因此编译器将回退到隐式函数声明的默认 C 规则,这意味着它将假定它返回 int

    2. initialization makes pointer from integer without a cast

      由于隐式声明的前一个问题,您的代码看起来像是试图将 int 分配给 double * 类型的变量 - 从整数类型到指针的隐式转换是导致警告的原因.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-31
      相关资源
      最近更新 更多