Re: Why can't I name a property `tag'?
Re: Why can't I name a property `tag'?
- Subject: Re: Why can't I name a property `tag'?
- From: an0 <email@hidden>
- Date: Thu, 10 Jul 2008 23:55:02 +0800
Sure.
I'm grateful that you tell me the internal truth instead of confusing
me even more by just saying it is my responsibility to tell compiler
more.
But if different return types cause different native code, how could
my program still work with the mistaken type(an NSString * returned
from the inner message is treated as an NSInteger at the first place,
then is passed as an NSString * to the outer message) guessed by
compiler?
On Thu, Jul 10, 2008 at 11:40 PM, Jens Alfke <email@hidden> wrote:
>
> On 10 Jul '08, at 8:19 AM, an0 wrote:
>
> However, if you don't know what exact type of Cocoa I am, how could
> you call me BlackCocoa so surely?
>
> Can we stop using confusing metaphors and just talk about OOP? :-p
> When the compiler parses a message-send expression ("[....]") it tries to
> figure out which declared method is being invoked. The most important reason
> for this is that it needs to know the return type of the method, because
> that can affect the machine code that's generated for the call.
> If the receiver of the expression is typed as "id", i.e. with no class, the
> compiler has no clues about what class to look for matching methods in. So
> it looks in any @interface blocks that it's already seen (i.e. ones in all
> #imported headers). If it finds one matching method, it uses it. If it finds
> more than one method, and the return types differ, then the situation is
> ambiguous … so it emits a warning.
> The short answer to your question, then, is that the compiler has to decide
> what method is being used, because that determines what machine code to
> generate. This is an ugly side effect of the fact that Objective-C compiles
> into native code and not some abstract bytecode like Java or Python. It's
> part of the price you pay as a developer for creating apps that run fast.
> —Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden