views:

29

answers:

1

Hi!

I'm developing an iphone application and when I compile it I receive some warnings. The application works, but probably it is interesting to delete all the warnings no?

This is one of them, that I can't undersand, basically because I'm a "rookie" with iPhone SDK and this class comes from another code (free code)

Anyone can help me??

The warning are: warning: implicit declaration of function 'NSAllocateCollectable' warning: initialization makes pointer from integer without a cast

The code is this:

 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;
}

As you can see this function try to allocate a matrix, and it is called by another function.

  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;
}

And this is called by the function which I execute and need

    - (id)initWithRows:(NSUInteger)rowCount columns:(NSUInteger)colCount
{
 // Create an empty matrix
 return [self initWithAllocatedArray:MatrixAllocateEmptyArray(rowCount,colCount)
           rows:rowCount
        columns:colCount];
}

Thanks so much Toni

+2  A: 

There's no garbage collector for iPhone programs. Allocating collectable memory is pretty much meaningless in that sitaution, so you're probably out of luck. You should probably fix your program and/or framework to use the traditional Objective-C memory management practices. The reasons for your specific warnings:

  1. implicit declaration of function 'NSAllocateCollectable'

    There is no declaration of NSAllocateCollectable for your iPhone app, so the compiler is going to fall back to the default C rules for implicit function declarations, meaning it will assume it returns int.

  2. initialization makes pointer from integer without a cast

    Because of the previous problem with the implicit declaration, your code looks to the compiler like it is trying to assign an int to a variable of type double * - implicit conversions from integer types to pointers are a cause for warnings.

Carl Norum