C++ inlining (request for better optimization).

Sergei Organov osv@Javad.RU
Thu Nov 27 11:30: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:

> cat inline.cc
class A {

public:
  A() {}
  A(const A& a) { copy(a); }

private:
  char data[10];

  void copy(const A& a) {
    for(int i = 0; i < 10; ++i)
      data[i] = a.data[i];
  }

};

A foo() {
  A a;
  A a1(a);
  return a1;
}

> g++ -c -O6 -Wall -Winline inline.cc
inline.cc: In method `A::A(const class A &)':
inline.cc:10: warning: can't inline call to `void A::copy(const class A
&)'
inline.cc:5: warning: called from here

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).

Maybe this behavior is intended to force programmer to move function 
definitions out of class declaration?

Is it possible to fix that?

Thanks in advance.

Sergei Organov.



More information about the Gcc mailing list