home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!brunix!brunix!sdm
- From: sdm@cs.brown.edu (Scott Meyers)
- Subject: Re: inline virtual functions
- Message-ID: <1992Sep15.151014.14125@cs.brown.edu>
- Sender: news@cs.brown.edu
- Organization: Brown University Department of Computer Science
- References: <1992Sep15.023336.1403@cs.brown.edu> <9226000.11363@mulga.cs.mu.OZ.AU>
- Date: Tue, 15 Sep 1992 15:10:14 GMT
- Lines: 47
-
- In article <9226000.11363@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- | 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 :-(
- | }
-
- Note first that a.fffff() is not a virtual call -- only calls for pointers
- and references invoke the virtual mechanism. That's why the call from a is
- inlined and the call from b is not. Furthermore, running nm on the .o file
- from this source (after compiling with cfront 3.0.1) yields:
-
- 000000b0 D ___ptbl_vec__fjh_C_foo_
- 00000098 D ___vtbl__1A__fjh_C
- 00000074 t _fffff__1AFv // note static copy of A::fffff here
- 00000000 T _foo__Fv
- U _ggggg__Fv
-
- This static copy will remain even if you eliminate BOTH calls to fffff.
-
- | >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.
-
- Only in my dreams.
-
- Scott
-
- -------------------------------------------------------------------------------
- What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."
-