This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Base of a Class



Hi,

I was just fiddling around with g++ (2.7.2.3) when I noticed it wasn't
emitting inlined functions along with the class base member. So I made a
quick test program and ran it through my copy of eg++ (970904 snapshot)
and it did the same thing.

Tacked onto this message are the 3 files I used to demonstrate this.
  > eg++ -c t?.cc
  > nm --demangle --print-file-name t?.o
t1.o:00000000 W Test::~Test(void)
t1.o:00000000 T Test::Test(void)
t1.o:         U __builtin_delete
t1.o:00000004 C __eh_cleanup
t1.o:00000001 C __eh_in_catch
t1.o:00000004 C __eh_pc
t1.o:00000004 C __eh_type
t1.o:00000004 C __eh_value
t1.o:         U __rtti_user
t1.o:00000000 W Test type_info function
t1.o:00000008 C Test type_info node
t1.o:00000000 W Test virtual table
t1.o:00000000 t gcc2_compiled.
t2.o:00000000 T AFunc(void)
t2.o:00000000 W Test::TestFunc(void)
t2.o:00000000 W Test::TestInline(void)
t2.o:00000000 W Test::~Test(void)
t2.o:         U Test::Test(void)
t2.o:         U __builtin_delete
t2.o:00000004 C __eh_cleanup
t2.o:00000001 C __eh_in_catch
t2.o:00000004 C __eh_pc
t2.o:00000004 C __eh_type
t2.o:00000004 C __eh_value
t2.o:         U __get_dynamic_handler_chain
t2.o:         U __rtti_user
t2.o:00000000 W Test type_info function
t2.o:00000008 C Test type_info node
t2.o:00000000 W Test virtual table
t2.o:00000000 t gcc2_compiled.    

As you can see a significant portion of the class membership has been
emitted in both modules. This I found highly surprising (esp considering
what the info files in 2.7 said about template instantiations). 

One compiler I have used the past (High C++) had the notion of the 'base'
of a class. It was defined to be the file that contained the first non-
static non-inline member function. In my example this would be
Test::Test(). What the compiler would do is emit all the inline functions,
vtables and RTTI data into the compilation unit that contained this
function. All other units would not emit the object and simply reference
them as normal extern items.

Presumably this saves compilation time and code size on disk. I haven't
looked at what effect this has on shared libraries, but I suspect it would
increase the size of both the library and client?

Would a feature like this be easy to add and desirable for eg++? I checked
the web archives and I haven't seen any discussion of this topic.

Thanks,
Jason
----------
t.h:
class Test
{
   public:

   inline bool TestInline() {return true;};
   bool TestFunc() {return true;};

   Test();
   virtual ~Test() {};
};
--------------
t1.cc:
#include "t.h"

Test::Test()
{
}
---------------
t2.cc:
#include "t.h"

void AFunc()
{
   Test T;
   T.TestFunc();
   T.TestInline();
}    



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]