This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
efficiency of calling one virtual member of class from another
- From: Bill Mann <bmann at vertica dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 23 Apr 2008 23:12:28 -0400
- Subject: 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