home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13679 < prev    next >
Encoding:
Text File  |  1992-09-15  |  2.0 KB  |  59 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!brunix!brunix!sdm
  3. From: sdm@cs.brown.edu (Scott Meyers)
  4. Subject: Re: inline virtual functions
  5. Message-ID: <1992Sep15.151014.14125@cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Brown University Department of Computer Science
  8. References: <1992Sep15.023336.1403@cs.brown.edu> <9226000.11363@mulga.cs.mu.OZ.AU>
  9. Date: Tue, 15 Sep 1992 15:10:14 GMT
  10. Lines: 47
  11.  
  12. In article <9226000.11363@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  13. | I just tested cfront 1.2.1, cfront 2.0, g++ 1.37.2, and g++ 2.2.2.
  14. | All of these except cfront 1.2.1 can successfully inline "inline virtual"
  15. | functions. Perhaps you made some mistake?
  16. | Here's the code I used:
  17. |     extern void ggggg();    // "ggggg" easy to find in the assembly output
  18. |     class A {
  19. |     public:
  20. |         inline virtual void fffff() { ggggg(); }
  21. |     };
  22. |     void foo() {
  23. |         A a;
  24. |         A& b = a;
  25. |         a.fffff();    // this gets inlined
  26. |         b.fffff();    // this doesn't :-(
  27. |     }
  28.  
  29. Note first that a.fffff() is not a virtual call -- only calls for pointers
  30. and references invoke the virtual mechanism.  That's why the call from a is
  31. inlined and the call from b is not.  Furthermore, running nm on the .o file
  32. from this source (after compiling with cfront 3.0.1) yields:
  33.  
  34.     000000b0 D ___ptbl_vec__fjh_C_foo_
  35.     00000098 D ___vtbl__1A__fjh_C
  36.     00000074 t _fffff__1AFv            // note static copy of A::fffff here
  37.     00000000 T _foo__Fv
  38.              U _ggggg__Fv
  39.  
  40. This static copy will remain even if you eliminate BOTH calls to fffff.
  41.  
  42. | >This is a pity, because it's the kind of rule that is easy to
  43. | >remember, hence people will continue to follow it even when C++ compilers
  44. | >become agressive enough in their optimization to be able to generate
  45. | >inlined calls to virtual functions.
  46. | Compilers are already that aggressive.
  47.  
  48. Only in my dreams.
  49.  
  50. Scott
  51.  
  52. -------------------------------------------------------------------------------
  53. What do you say to a convicted felon in Providence?  "Hello, Mr. Mayor."
  54.