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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!brunix!brunix!sdm
  3. From: sdm@cs.brown.edu (Scott Meyers)
  4. Subject: inline virtual functions
  5. Message-ID: <1992Sep15.023336.1403@cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Brown University Department of Computer Science
  8. Date: Tue, 15 Sep 1992 02:33:36 GMT
  9. Lines: 28
  10.  
  11. For all the compilers with which I am familiar, inline virtual functions
  12. are oxymoronic:  the function bodies are never inlined, and the object file
  13. for each translation unit seeing the definition of the function receives a
  14. static copy of the function.  I tested this using cfront 3.0 and g++ 2.2.2,
  15. and both behaved as I have described, neither issuing a warning about not
  16. inlining a function.
  17.  
  18. Many people have discovered this behavior in current compilers, and so the
  19. following rule is widely followed: "never define an inline virtual
  20. function."  This is a pity, because it's the kind of rule that is easy to
  21. remember, hence people will continue to follow it even when C++ compilers
  22. become agressive enough in their optimization to be able to generate
  23. inlined calls to virtual functions.
  24.  
  25. I was involved in a discussion of this issue today when it was suggested
  26. that compilers should generate only a single copy of an out-of-line virtual
  27. function, and that the single translation unit in which the function
  28. definition should be generated should be the same as the one containing the
  29. class's vtbl.  This seems sensible to me, so I was wondering: is there some
  30. reason why compiler implementers don't do this?
  31.  
  32. Thanks,
  33.  
  34. Scott
  35.  
  36.  
  37. -------------------------------------------------------------------------------
  38. What do you say to a convicted felon in Providence?  "Hello, Mr. Mayor."
  39.