Inline only previously seen and marked inline function?

Marco Man-Fai Yu yumf@cisc
Sun Aug 16 20:01:00 GMT 1998


Hi,

    The following code seems to suggest that egcs only inline a
function f of class A if either 1) f is defined in class definition,
or 2) the caller of f is seen by the compiler after f's body is
defined. For example, if we reverse the order of definition of main()
and A::Outside() in the following code, A::Outside() would be
inlined. A::Inside() is always inlined. Can the creators of egcs
confirm this? It seems to be a limitation because the opportunity to
inline now strongly depends on how the inline functions are arranged
in the source file and its includes. Hence the performance of the code
depends on the order of #include's and the order of function
definitions in the .cc file.

struct A {
  void Inside(void) { }
  void Outside(void);
};

int main(int, char**) {
  A a;
  a.Inside();
  a.Outside();
}

inline void A::Outside(void) { }

The above is compiled with egcs-1.0.3a on Linux/x86.

g++ -v -Winline -O -o foo foo.cc
Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.29/specs
gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)
 /usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.29/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -Di386 -D__ELF__ -Dunix -Dlinux -D__i386__ -D__ELF__ -D__unix__ -D__linux__ -D__i386 -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -D__OPTIMIZE__ -Winline -Di386 -Di586 -Asystem(unix) -Acpu(i386) -Amachine(i386) -D__i386__ -D__i586__ -Asystem(unix) -Acpu(i386) -Amachine(i386) foo.cc /tmp/cca19732.ii
GNU CPP version egcs-2.90.29 980515 (egcs-1.0.3 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/g++
 /usr/local/include
 /usr/local/i586-pc-linux-gnulibc1/include
 /usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.29/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.29/cc1plus /tmp/cca19732.ii -quiet -dumpbase foo.cc -O -Winline -version -o /tmp/cca19732.s
GNU C++ version egcs-2.90.29 980515 (egcs-1.0.3 release) (i586-pc-linux-gnulibc1) compiled by GNU C version 2.7.2.1.

foo.cc:19: warning: `void A::Outside()' was used before it was declared inline
foo.cc:7: warning: previous non-inline declaration here
^^^^^^^^^^^

 as -V -Qy -o /tmp/cca197321.o /tmp/cca19732.s
GNU assembler version 970202 (i486-linux), using BFD version 2.7.0.9
 /usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.29/ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.1 -o foo /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.29/crtbegin.o -L/usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.29 -L/usr/local/lib /tmp/cca197321.o -lstdc++ -lm -lgcc -lc -lgcc /usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.90.29/crtend.o /usr/lib/crtn.o

Compilation finished at Sun Aug 16 19:38:56

---------------------------------------------------------------------

Note that egcs warns even when A::Outside is defined with the inline
keyword. Even when the inline keyword is used in the class declaration,
egcs still won't inline A::Outside.

Marco Yu
yumf@ultimatech.com



More information about the Gcc mailing list