[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: inheritance and sub-tables
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 27 Feb 2014 07:46:58 +0200
On Thu, Feb 27, 2014 at 12:42 AM, Javier Guerra Giraldez
<javier@guerrag.com> wrote:
> second, it's a little hairsplitting and somewhat personal opinion, but
> typically I call a value an object when it carries its own type
> information. C primitive values don't, and in structs you can (and
> it's sometimes good advice), but not automatically.
That feels like a good distinction - C values are (typically) dumb,
pointers point to exactly what you've declared, as you expect them to
be laid out in the struct, modulo padding.
However, instances of a C++ class with virtual methods [1] do carry
type information, even if it's just a VMT. A virtual method obj->M(a)
is implemented something like the pseudo-code[2]
obj->VMT[M_slot](obj,a) - which is not a million miles away from the
Lua definition. The difference is that 'slots' are indices into a
little array.
[1] "member function" is more correct, but clunky. Some would argue
that the word 'method' already includes the adjective 'virtual'.
[2] Standard does not dictate actually where the VMT is stored; that's
determined by the ABI (see
http://stackoverflow.com/questions/10925115/location-of-virtual-function-table-pointer-in-object)