C++ inlining (request for better optimization).
Joe Buck
jbuck@synopsys.com
Thu Nov 27 13:12:00 GMT 1997
> 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.
More information about the Gcc
mailing list