[cfe-dev] Comparison of pointers between Objc subclasses

Thomas Clement thomascl at free.fr
Tue Jul 1 14:33:33 PDT 2008


Hi,

I'm not sure if this has already been discussed earlier, sorry if  
that's the case.

I noticed that clang (-fsyntax-only) produces the following warning:

MyClass.m:15:11: warning: comparison of distinct pointer types  
('NSMutableArray *' and 'NSArray *')
if (array != newArray)
     ~~~~~ ^  ~~~~~~~~

Since NSMutableArray is a subclass of NSArray, the warning doesn't  
seem really appropriate.


Thanks,
Thomas


#import <Foundation/Foundation.h>

@interface MyClass
{
	NSMutableArray *array;
}
- (void)setArray:(NSArray *)newArray;
@end

@implementation MyClass
- (void)setArray:(NSArray *)newArray
{
	if (array != newArray)
	{
		[array release];
		array = [newArray mutableCopy];
	}
}
@end




More information about the cfe-dev mailing list