Re: Instance Variable access
Re: Instance Variable access
- Subject: Re: Instance Variable access
- From: Andy Lee <email@hidden>
- Date: Sat, 8 May 2004 20:20:30 -0400
On May 8, 2004, at 2:40 PM, Allan Odgaard wrote:
On 8. May 2004, at 19:16, Andy Lee wrote:
Which means if you want an instance of the subclass to invoke its
superclass's version of the member function, you have to cast it to
the superclass.
Sort of, yes. You do something like:
struct Base {
void foo () { printf("base\n"); }
};
struct Derived : public Base {
void foo () { Base::foo(); }
};
Thanks -- I had forgotten about the double-colon notation. Here's what
I meant about casting:
struct MoreDerived : public Derived {
void foo () { printf("derived\n"); }
void bar ()
{
foo(); // prints "derived"
Derived::foo(); // prints "base"
Base::foo(); // prints "base"
((Base *)this)->foo(); // also prints "base" (I think)
}
};
There are some hidden branches in the ObjC-version, because it is
run-time linked and thus goes through a Mach-o stub.
That whooshing you hear is the sound of that last sentence going over
my head. :) I don't know what a Mach-o stub is.
but it seems to me Objective-C *could* use a vtable-type
implementation where vtables happen to be changeable at run time, in
which case the difference should be pretty small.
No, this is not possible without some very huge method tables,
That's assuming the method lookup table is an array like a vtable is,
which I didn't mean to imply. It just has to be a data structure on
which you can perform lookups, where the lookup key is some unique
surrogate for the method name and the returned value is a function
pointer.
In C++, conveniently enough, the data structure can be a packed array
and the lookup key can be an array index. In Objective-C, the lookup
key is a SEL, which does not afford the same luxuries because of the
dynamic nature of the language. The challenge then would to come up
with a data structure that uses reasonable space and a fast (though
obviously not constant-time) lookup algorithm.
Furthermore there is the problem of having code compiled in different
environments arrive at the same index numbers for the same method.
I wouldn't think that would be a huge problem if SEL values are
generated as necessary at class-load time.
--Andy
_______________________________________________
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.