This is the mail archive of the gcc-help@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]
Other format: [Raw text]

efficiency of calling one virtual member of class from another


I have a base class and several subclasses.  They have several virtual
member functions.

class Base {
    ...
     virtual void *f(int a) = 0;
     virtual void *g(int a) = 0;
}

class Sub1 : Base {
    ...
     void *f(int a) {
         code_f;
         return something;
     }

     void *g(int a) {
         code_g1;
         void *r = f(a+1);     // question here
         code_g2;
         return r;
    }
}

class Sub2 : Base {
   similar...
}

I have not and do not intend to define any subclasses of Sub1 or the
other subclasses at this level.  Base and all the subclasses are in the
same .h file.

The question is, what happens when I call f() from g()?  At -O3?  Does
it go though the usual vector dispatch table, does it call code for the
same instance of f directly, does it inline f in g (separately for each
subclass), or something else?  Why?  And, has it recently or is it going
to change?

Is there a reference I should have read rather than asking this question?

Thanks, Bill





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