www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Where does the classinfo property come from?

reply Chuck.Esterbrook /at/ gmail /dot/ com <Chuck.Esterbrook_member pathlink.com> writes:
The following wiki page shows that you can say "someObj.classinfo.name":
http://www.prowiki.org/wiki4d/wiki.cgi?HowTo/RealtimeTypeInformation

I verified this, but I'm wondering where it comes from? I don't recall reading
about the "classinfo" property in the language docs. I checked Object in the
Phobos docs and it's not there. I checked the definition of Object { } in
Object.d and it has no "classinfo". There *is* a "classinfo" in struct
Interface, but I don't see how that would be connected.

What is the connection that allows the D compiler to get from "someObj" to
"classinfo"? How come I don't see it in Object { ... } in Object.d as a field or
function?

Thanks in advance,

-Chuck
Aug 15 2005
parent "Ben Hinkle" <ben.hinkle gmail.com> writes:
"Chuck.Esterbrook /at/ gmail /dot/ com" 
<Chuck.Esterbrook_member pathlink.com> wrote in message 
news:ddpii5$e0a$1 digitaldaemon.com...
 The following wiki page shows that you can say "someObj.classinfo.name":
 http://www.prowiki.org/wiki4d/wiki.cgi?HowTo/RealtimeTypeInformation

 I verified this, but I'm wondering where it comes from? I don't recall 
 reading
 about the "classinfo" property in the language docs. I checked Object in 
 the
 Phobos docs and it's not there. I checked the definition of Object { } in
 Object.d and it has no "classinfo". There *is* a "classinfo" in struct
 Interface, but I don't see how that would be connected.
ClassInfo should be documented but isn't. I also thought TypeInfo was defined somewhere but it isn't either.
 What is the connection that allows the D compiler to get from "someObj" to
 "classinfo"?
When you define a class the compiler builds a ClassInfo instance and serializes it to the obj file. When you say "someObj.classinfo" you get a reference to that static ClassInfo instance.
 How come I don't see it in Object { ... } in Object.d as a field or
 function?
The compiler has a special check for it. At runtime the pointer to the classinfo is stored in the first slot of the vtable (it needs to be obtainable from the object ref in order to support RTTI).
 Thanks in advance,

 -Chuck

 
Aug 15 2005