From: "Alexander S. Klenin" Newsgroups: comp.os.msdos.djgpp Subject: Template inlining Date: Thu, 16 Oct 97 19:10:28 +1100 Distribution: world Organization: TOO Kern Message-ID: Sender: news-service AT kiae DOT su Reply-To: root AT kern DOT marine DOT su Lines: 98 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hi, Here is a (long) question: I have a following class template: // test.h template class C { T a; // some data here... public: C(const T &t): a(t) {} // some useful functions... }; And then use it: //test.cpp #include"test.h" main() { C c(5); } Template functions are not inlined, so I got: .file "test.cc" gcc2_compiled.: ___gnu_compiled_cplusplus: .text .globl _main _main: pushl %ebp movl %esp,%ebp subl $8,%esp movl $5,-8(%ebp) leal -8(%ebp),%edx leal -4(%ebp),%eax call ___t1C1ZiRCi <----- This call is not inlined :( xorl %eax,%eax leave ret ___t1C1ZiRCi: pushl %ebp [code skipped] leave ret To fix this, I pre-declared template instantiation: //test1.cpp template class C; main() { C c(5); } And then functions get inlined indeed, but they are also generated as non-inline, this time _all_ of them, not only those I call: .file "test.cc" gcc2_compiled.: ___gnu_compiled_cplusplus: .text .globl ___t1C1ZiRCi ___t1C1ZiRCi: pushl %ebp [some code] leave ret .globl _main _main: pushl %ebp movl %esp,%ebp subl $8,%esp movl $5,-8(%ebp) <----- now inline works ok movl $5,-4(%ebp) xorl %eax,%eax leave ret .globl ___as__t1C1ZiRCt1C1Zi ___as__t1C1ZiRCt1C1Zi: pushl %ebp [some unneeded code] leave ret .globl ___t1C1ZiRCt1C1Zi ___t1C1ZiRCt1C1Zi: pushl %ebp [even more code] leave ret Even worse, since all the above declared with .globl, all the bloat gets linked right into .exe! No the question is: is there any way to avoid this? Alex