Boost logo

Boost :

Subject: Re: [boost] Is there a special reason to use inline before template functions?
From: David Abrahams (dave_at_[hidden])
Date: 2008-12-09 08:49:24


on Mon Dec 08 2008, Brian Ravnsgaard Riis <brian-AT-ravnsgaard.net> wrote:

> Michael Marcin wrote:
>> Thomas Klimpel wrote:
>>> I would expect that current compilers know better when inlining a
>>> function provides a benefit than the programmer.
>>
>> They don't.
>
> This is really sorta off-topic here, but I find that statement hard to
> believe. Can you in any way substantiate that argument? I personally
> *never* use the keyword inline, since the compiler is free to ignore it,
> and may choose to inline functions I have not declared inline.
>
> What little I do know about compiler internals would lead me to believe
> that they could - and should - indeed know better than the programmer
> when it makes sense to inline a function.

It has been known to be a problem for people using Visual C++ that they
couldn't get it to inline the functions that really needed to be inlined
without using a proprietary __forceinline (or some such) extension.

> To complicate matters further, inlining a given function may make sense
> in certain contexts but not others. I believe Herb Sutter has given the
> subject thorough treatment some years gone. Nothing I have experienced
> has caused me to doubt his words in this matter.

You should talk to more people who care about high performance. Most of
the time, you probably want the compiler to choose, but sometimes you
really need the control.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk