Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Efficient compilation of virtual functions Message-ID: <417@taumet.com> Date: 24 Aug 90 15:59:02 GMT References: <1990Aug22.193347.18486@ux1.cso.uiuc.edu> <6428@wolfen.cc.uow.oz> Organization: Taumetric Corporation, San Diego Lines: 45 amanda@iesd.auc.dk (Per Abrahamsen) writes: |>>>>> On 22 Aug 90 23:40:48 GMT, pejn@wolfen.cc.uow.oz (Paul Nulsen) said: |Paul> The problem then is that the compiler needs to know that subclass has |Paul> nothing derived from it. This is not possible with separate compilation. |It would be nice to be able to declare a class or even a member |function as "leaf". Even if we disregard the possible optimizations, |it would add to the programmers ability to document the classes. I don't think I agree with this. If you declared a leaf node, you would be prohibiting further reuse of the class by deriving from it. How do you know that another object with slightly more specialized behavior will never be needed in the future? Someone needing this capability while also using your code would be required to duplicate the existing code with new names, then create conversion functions to your old class hierarchy. This seems like a steep price to pay for some special-case micro-optimization. I believe the original poster wanted to optimize calls to a virtual function of the current class. While this is potentially dangerous, the language already provides the mechanism to do this. Example: class C { ... virtual foo(); bar(); }; C::bar() { ... foo(); // virtual call ... C::foo(); // not a virtual call ... } In the second call, the compiler must make a direct call to C::foo, with no virtual function call overhead. -- Steve Clamage, TauMetric Corp, steve@taumet.com