Re: Mysterious warning (initialization from distinct Objective-C type)
Re: Mysterious warning (initialization from distinct Objective-C type)
- Subject: Re: Mysterious warning (initialization from distinct Objective-C type)
- From: Mason Mark <email@hidden>
- Date: Wed, 21 Sep 2005 20:59:47 +0900
On Sep 21, 2005, at 8:33 PM, Cameron Hayne wrote:
On 21-Sep-05, at 1:35 AM, Mason Mark wrote:
warning: initialization from distinct Objective-C type
FSColoredView *v = [self mainView]; // returns an id: -(id)
mainView;
The line of code above generates the warning. I am not building a
universal binary.
I started getting this warning after upgrading to GCC 4.0.1.
I'm guessing that this is a new warning that is intended to warn
you about what the Obj-C document <http://developer.apple.com/
documentation/Cocoa/Conceptual/ObjectiveC/LanguageOverview/
chapter_3_section_8.html> says is "error-prone, but is allowed
nonetheless" - assigning an 'id' to a statically typed variable.
Yeah, you may be right about the intent, but I'd consider that a bug
if so. I interpret "allowed" to mean "won't generate a warning". (And
two sentences before noting it is "error-prone" the same doc states,
"A statically typed object can be freely assigned to an id, or an id
to a statically typed object.")
Although cognizant of the ways in which that can be error-prone, I do
it a lot myself, and a brief look at Omni's frameworks source code
and the other third party stuff I have laying around shows that they
do it also...
E.g., when using an enumerator, or any method to get something out of
an array or a dictionary, etc. etc., we tend to do stuff like:
NSString *myString = [arrayOfStrings objectAtIndex:5];
or
NSView *view = [_subviews objectAtIndex: viewIndex];
...and so forth.
Or, consider just about every object initialization:
SomeObject *foo = [[SomeObject alloc] init];
999.9 million times out of a billion, -init returns an id, so it's
the same thing.
What seems more likely to me is that this is just a GCC bug. In any
case, I work on a "zero-warnings" team, so I just want to make it go
away...
Cheers,
--
Mason Mark
Five Speed Software, Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden