This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ inlining (request for better optimization).
- To: osv at javad dot ru (Sergei Organov)
- Subject: Re: C++ inlining (request for better optimization).
- From: Joe Buck <jbuck at synopsys dot com>
- Date: Thu, 27 Nov 97 13:12:26 PST
- Cc: egcs at cygnus dot com
> The progress in 'egcs' development is really exciting, thanks to all
> involved. One thing, however, bothers me: it seems 'g++' could do
> better function inlining:
Yes, in examples that require two or more levels of lookahead inlining
can fail: if an inline function includes another inline function that
appears later, inlining usually fails.
> Such behavior forces me to arrange code according to the 'egcs'
> preferences
> instead of style (moving body of 'copy' before the call solves the
> problem).
An alternative to putting private before public members is something
like this:
class foo {
public:
// foo calls private inline message 'init'
inline foo(unsigned n);
private:
void init(unsigned n) {
for (int i = 0; i < n; i++)
data[i] = i;
}
...
};
inline foo::foo(unsigned n) { init(n);}
> Maybe this behavior is intended to force programmer to move function
> definitions out of class declaration?
I think it's kind of an accident caused by the order that g++ scans
the code.
> Is it possible to fix that?
Anything's possible. However, if the fix is to make multiple passes
over the source, thereby slowing down compilation, I'd rather do -Winline
and rearrange my code. I don't think it should be a high priority.