Re: Future Objective-C changes
Re: Future Objective-C changes
- Subject: Re: Future Objective-C changes
- From: lbland <email@hidden>
- Date: Mon, 19 May 2003 13:19:53 -0400
On Monday, May 19, 2003, at 12:30 PM, Martin Hdcker wrote:
>
As far as I know it's dispatching a method call on the type of both
>
the argument and the receiver, thus effectively doing the (almost)
>
same thing as name mangling does. So this would allow code like this
>
to work:
>
>
- do:(id)anObject;
>
- do:(NSString *)aString;
>
>
Well... am I right on this? If so, what's the difference from the
>
effect created from name mangling?
your question can be interpreted in different ways, but here is one
answer:
if you implement those methods in a single class the compiler gives
this error:
MyController.m: At top level:
MyController.m:160: duplicate definition of instance method `do:'
MyController.m:160: redefinition of `-[MyController do:]'
MyController.m:154: `-[MyController do:]' previously defined here
MyController.m:160: warning: `-[MyController do:]' defined but not used
that is because obj-c does not mangle the name with type information
and any object cast (id <-> NSString * for example) is just a simple
pointer cast, less prototype resolution at compile time (no run time
resolution) which is an add on feature to obj-c (stepstone did not do
that in the original version).
If obj-c mangled the name then the methods above would form function
prototypes something like this in the compiler:
int _do_$2id(void *, SEL, void *,...)
int _do_$11ptrNSString(void *, SEL, void *,...)
but that does not happen because the argument type is a pointer cast,
nothing more.
to implement what you want in obj-c you would do this:
- (id)do:(id)anObject;
- (id)doWithString:(NSString *)aString;
and use it like this:
[controller do:anything];
[controller doWithString:myString];
noting the preposition "With", which would be different then:
[controller doToString:myString];
so that the meaning of the method is in the name of the method, as
opposed to C++ where everything looks like: "do" because of mangling.
IMHO
Lance Bland
mailto:email@hidden
VVI
888-VVI-PLOT
http://www.vvi.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.