Hi Greg,

On 14/10/2010, at 17:50, Greg Parker wrote:

> There's already a method -[NSArray initWithObjects:], but it accepts a 
> nil-terminated list of objects. The compiler warns if you call [array 
> initWithObjects:a, b, c] and forget the nil terminator.
> 
> `[self alloc]` returns `id`, so the compiler has to guess which method 
> prototype to use, yours or NSArray's. If it guesses wrong, you'll get that 
> warning. Sometimes you'll get crashes or incorrect parameter values when the 
> compiler guesses wrong, but in this case the generated code happens to work 
> correctly.
> 
> I'd recommend changing your method name. -initWithArray: would work, matching 
> -[NSArray initWithArray:(NSArray*)array]. 
> 
> The other workaround is to cast the result of +alloc: [(NSFSomeClass*)[self 
> alloc] initWithObjects:someObjects]. But that's fragile if you forget 
> somewhere.
> 
> 
>> Another observation:
>> 
>> GCC 4.0 = no warning
>> GCC 4.2 = warning
>> LLVM GCC 4.2 = warning
>> LLVM compiler 1.5 = no warning
>> 
>> Is this a GCC 4.2/LLVM GCC4.2 bug?
> 
> No. gcc-4.0 simply does not implement the sentinel warning for Objective-C 
> methods. If gcc-4.0 guesses wrong, there's no warning and the code happens to 
> run correctly.
> 
> 
>> And while we're at it... since the library I'm writing works on both Mac OS 
>> X and iOS, which compiler is recommended?
> 
> I'd recommend llvm-gcc on all current platforms and architectures.
> 
> 
> -- 
> Greg Parker     gpar...@apple.com     Runtime Wrangler

Done. Thanks again for the help,

-- Tito
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to