Re: [OFFTOPIC] Re: C++ in kernel (was Re: exception in a device

kwrohrer@ce.mediaone.net
Wed, 13 Jan 1999 21:16:45 -0600 (EST)


And lo, Nate Tuck saith unto me:
> At 04:01 AM 1/14/99 +0300, Khimenko Victor wrote:
> >Since there are virtual calls in both C++ and C sample. C++ VIRTUAL CALL
> >requires one additional inevitable memory reference over C VIRTUAL CALL.
> >But looks like all your brain is wasted for C++ are no more room for any
> >new information.
>
> All your examples show is that inheritance in C++ is usually implemented
> with a pointer to a vtable, and that the compiler isn't quite smart enough
> to figure out that you only have 1 virtual function in your class and that
> it could replace the vtable ptr with the contents of the vtable ptr.

The compiler couldn't know that there won't ever be a child class with two
(or more) virtual functions, so this optimization would be incorrect, or
at least silly. Should that child class have two function pointers, or
a function pointer and a vtbl pointer? It can't have just the one vtbl
to preserve compatibility with objects of its parent class. What if the
child class (with two inline function pointers) had a child class which
added more virtual functions, what goes then? Two pointers and a vtbl
pointer? Where does it end?

Usually the right answer to "where does it end" is "it doesn't start".

Keith (does C++ have a keyword to do that manually?)

-- 
 "Well, look at that.  The sun's   | Linux: http://www.linuxhq.com     |"Zooty,
  coming up." -- John Sheridan,    | KDE:   http://www.kde.org         | zoot
  "Sleeping in Light", Babylon 5   | Keith: kwrohrer@enteract.com      | zoot!"
www.midwinter.com/lurk/lurker.html | http://www.enteract.com/~kwrohrer | --Rebo

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/