RE: differences of memory layout of virtual function table.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Eljay,

I find in GCC and VC++ the pointer to the virtual table is the first pointer
of the object. Is there any other known compiler to you that synthesizes a
C++ object a different way ?.

Regarding the Virtual table, offsets and function pointer ordering , I find
its compiler dependant.

>-----Original Message-----
>From: Eljay Love-Jensen [mailto:eljay@xxxxxxxxx]
>Sent: Wednesday, November 19, 2003 6:49 PM
>To: Susantha Kumara
>Subject: Re: differences of memory layout of virtual function table.
>
>
>Hi Susantha,
>
>One C++ layout is adding an entry into a map of <addr,vtable> which is then
accessed when fetching the vtable (which includes RTTI).
>

Which compilers do have this way ? Is this when we have virtual base classes
?

>Another one is having the entire C++ vtable precede each object.  (There
are situations where this is preferable.)

Is this preffered for performance reasons or comply with a common standard
with the compilers ?

>
>For GCC in particular, I don't have any specific insight.
>
>But I suspect that what you want to do could better be done by making entry
point static functions that do something like this:
>
>class Foo
>{
>public:
>  virtual int zap(int i, int j);
>  static int Zap(Foo* p, int i, int j);
>};
>
>// Thunk function.
>int Foo::Zap(Foo* p, int i, int j)
>{
>  return p->zap(i, j);
>}
I will try this way and let you know if I succeeds. thanks for the idea.
>
>That's more portable, and can be called from C (albeit with name
mangling... I consider that a different issue and there are means to address
that as well).
>
>Yet another radical alternative is to implement classes as C structs and
hand-cobble the vtable.
This is I think what I do. Here we have to know how each compiler do.

>
>HTH,
>--Eljay
>

Thanks,

Susantha.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux