Related articles |
---|
[3 earlier articles] |
Re: C++ virtual function calls genew@mindlink.bc.ca (1995-10-23) |
Re: C++ virtual function calls cliffc@ami.sps.mot.com (1995-10-25) |
Re: C++ virtual function calls joe@sanskrit.ho.att.com (1995-10-30) |
Re: C++ virtual function calls jplevyak@violet-femmes.cs.uiuc.edu (John B. Plevyak) (1995-11-09) |
Re: C++ virtual function calls cliffc@ami.sps.mot.com (1995-11-05) |
Re: C++ virtual function calls martelli@cadlab.it (1995-11-05) |
Re: C++ virtual function calls bothner@cygnus.com (Per Bothner) (1995-11-06) |
C++ virtual function calls fjh@cs.mu.OZ.AU (1995-11-12) |
Re: C++ virtual function calls jplevyak@pink-panther.cs.uiuc.edu (1995-11-16) |
Newsgroups: | comp.compilers |
From: | Per Bothner <bothner@cygnus.com> |
Keywords: | C++, optimize |
Organization: | Cygnus Support, Mountain View, CA |
References: | 95-10-029 <95-11-020@comp.compile |
Date: | Mon, 6 Nov 1995 07:03:48 GMT |
Joe Orost <joe@sanskrit.ho.att.com> wrote:
>I don't think it is legal to hoist the virtual function lookup
>out of the loop:
>
>for( ...) {
> p->virt_func();
>}
>
>because "p" is passed to virt_func as "this", and therefore the
>function could change the subtype of "p", causing a different
>function to be called next time around the loop!
How? The virt_func cannot change the p pointer (since the address
'this' is passed by value, not by reference), and it cannot
change the type of *p (or any of its sub-objects), since the only
time objects change type in C++ is as they are being constructed
or destroyed.
--Per Bothner
Cygnus Support bothner@cygnus.com
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.