home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: inline virtual functions
- Message-ID: <9226000.11363@mulga.cs.mu.OZ.AU>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <1992Sep15.023336.1403@cs.brown.edu>
- Date: Tue, 15 Sep 1992 14:31:30 GMT
- Lines: 48
-
- sdm@cs.brown.edu (Scott Meyers) writes:
-
- >For all the compilers with which I am familiar, inline virtual functions
- >are oxymoronic: the function bodies are never inlined, and the object file
- >for each translation unit seeing the definition of the function receives a
- >static copy of the function. I tested this using cfront 3.0 and g++ 2.2.2,
- >and both behaved as I have described, neither issuing a warning about not
- >inlining a function.
-
- I just tested cfront 1.2.1, cfront 2.0, g++ 1.37.2, and g++ 2.2.2.
- All of these except cfront 1.2.1 can successfully inline "inline virtual"
- functions. Perhaps you made some mistake?
-
- Here's the code I used:
-
- extern void ggggg(); // "ggggg" easy to find in the assembly output
-
- class A {
- public:
- inline virtual void fffff() { ggggg(); }
- };
-
- void foo() {
- A a;
- A& b = a;
- a.fffff(); // this gets inlined
- b.fffff(); // this doesn't :-(
- }
-
- >Many people have discovered this behavior in current compilers, and so the
- >following rule is widely followed: "never define an inline virtual
- >function."
-
- Not by me!
- That would not be a good rule to follow.
-
- >This is a pity, because it's the kind of rule that is easy to
- >remember, hence people will continue to follow it even when C++ compilers
- >become agressive enough in their optimization to be able to generate
- >inlined calls to virtual functions.
-
- Compilers are already that aggressive.
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature virus is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-