Related articles |
---|
C++ - inlining of functions returning an unwindable object 0xCDCDCDCD@gmx.at (Martin B.) (2009-11-27) |
Re: C++ - inlining of functions returning an unwindable object roland.leissa@googlemail.com (=?ISO-8859-1?Q?Roland_Lei=DFa?=) (2009-12-07) |
Re: C++ - inlining of functions returning an unwindable object 0xCDCDCDCD@gmx.at (Martin B.) (2009-12-09) |
From: | =?ISO-8859-1?Q?Roland_Lei=DFa?= <roland.leissa@googlemail.com> |
Newsgroups: | comp.compilers |
Date: | Mon, 7 Dec 2009 19:24:47 -0800 (PST) |
Organization: | Compilers Central |
References: | 09-11-061 |
Keywords: | C++ |
Posted-Date: | 08 Dec 2009 21:37:54 EST |
Hi,
I tried your code with g++ 4.4.1 on amd64. g++ basically emits the
same code for testsimple and testsimple2 and does not call the getter.
I compiled with:
g++ test.cpp -c -O3 -S
Are you sure you turned on all optimizations? Perhaps declaring the
getter as
std::string get() const {
return s_;
}
helps.
Another important issue is the return value optimizatoin of C++.
http://en.wikipedia.org/wiki/Return_value_optimization (though the
article claims msvc++ supports this feature)
Yet another thing one should not forget is that a language allowing
pointers which may point to literally everywhere, pointer arithmetic
and so on really makes headaches for compiler writers. C/C++
enthusiasts often claim how fast pointers are but this is only the
case if the compiler is _really_ smart. That's why Fortran is
sometimes faster than C. And since std::string uses pointers
internally this may be the reason why msvc++ is not able to inline the
function.
Hope this helped a bit.
- Roland Leissa
Return to the
comp.compilers page.
Search the
comp.compilers archives again.