This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: On inlining in C++
- From: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- To: Thomas Kunert <kunert at physik dot tu-dresden dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 5 Aug 2003 11:37:08 +0200 (CEST)
- Subject: Re: On inlining in C++
On Tue, 5 Aug 2003, Thomas Kunert wrote:
> Richard Guenther wrote:
> >>- From how many places the function is being called throughout the program.
> >>
> >>- How often the function is called from a certain position.
> >>
> >>The programmer has the complete picture. He has an idea about the actual
> >>parameters passed to the function. He can actually measure the time.
> >>He knows if some function is critical or not.
> >
> >
> > For the last two points you made the problem is, that there is no
> > (portable) way to tell the compiler to inline into certain positions or in
> > certain cases.
>
> Of course there is:
>
> inline void inline_f()
> {
> // actual code
> }
>
> void noinline_f()
> {
> inline_f();
> }
>
> Then you can decide at each call if you want inlining or not. Or take
> the pow() example from the beginning of the thread. It doesn't really matter
> if it gets inlined for constant exponents, say pow(x,2), because everybody
> already has functions pow2(x), pow3(x), ... :-)
Of course - but this looks like a workaround for a C++ defect, not like a
good design principle ;) I'd rather like
void f(int) { ... }
void g(int i) {
inline f(5);
f(i);
}
to have one call inlined, not the other. But of course this aint C++...
Maybe
void g(int i) {
inline void (&f_inline)(int) = f;
f_inline(5);
f(i);
}
yields
inline2.cpp: In function `void g(int)':
inline2.cpp:5: `f_inline' declared as an `inline' variable
shouldnt an inline variable declaration look like
void (inline &f_inline)(int) = f;
? So the warning is bogous... (but of course this aint C++ either).
Richard.
--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/