Inline Functions-What are they good for? - c++
This is a discussion on Inline Functions-What are they good for? - c++ ; Hi,
Isn't the whole point of inline functions "to try to eliminate
function call overhead by simply substituting the call with the
function body"? And I know it is a safer substitution than macros.
But I came across this paragraph ...
-
Inline Functions-What are they good for?
Hi,
Isn't the whole point of inline functions "to try to eliminate
function call overhead by simply substituting the call with the
function body"? And I know it is a safer substitution than macros.
But I came across this paragraph below in the site "Programming in C+
+, Rules and Recommendations" and got confused:
"Functions, which invoke other inline functions, often become too
complex for the compiler to be able to make them inline despite their
apparent smallness."
If so, what are inline functions good for? For accessor methods
mostly?
Thanks.
-
Re: Inline Functions-What are they good for?
D. Susman wrote:
> Hi,
>
> Isn't the whole point of inline functions "to try to eliminate
> function call overhead by simply substituting the call with the
> function body"? And I know it is a safer substitution than macros.
>
> But I came across this paragraph below in the site "Programming in C+
> +, Rules and Recommendations" and got confused:
>
> "Functions, which invoke other inline functions, often become too
> complex for the compiler to be able to make them inline despite their
> apparent smallness."
>
> If so, what are inline functions good for? For accessor methods
> mostly?
>
Inline, as it literally means, the code is expanded on the spot where is
function is called.
The cost of creating a new stack frame is kinda expensive;
the expansion eliminates the function call, so no new stack frame is needed.
Cons: Inline function increases the binary size of the program, as it
expands each time when it called.
--
Thanks
Barry
-
Re: Inline Functions-What are they good for?
On 2007-09-21 10:35:39 -0400, Barry <dhb2000@gmail.com> said:
>
> Cons: Inline function increases the binary size of the program, as it
> expands each time when it called.
Not necessarily. If a function is simple enough (for example, returning
the value of a data member of a class), it's inline expansion can be
shorter than the corresponding function call.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
-
Re: Inline Functions-What are they good for?
D. Susman wrote:
:: Hi,
::
:: Isn't the whole point of inline functions "to try to eliminate
:: function call overhead by simply substituting the call with the
:: function body"? And I know it is a safer substitution than macros.
::
:: But I came across this paragraph below in the site "Programming in
:: C+ +, Rules and Recommendations" and got confused:
::
:: "Functions, which invoke other inline functions, often become too
:: complex for the compiler to be able to make them inline despite
:: their apparent smallness."
Where did the "often" come from?
In my experience, it is rather "occationally". And compilers improve
all the time.
Bo Persson
Similar Threads
-
By Application Development in forum c++
Replies: 5
Last Post: 11-28-2007, 06:00 AM
-
By Application Development in forum c++
Replies: 9
Last Post: 07-04-2007, 03:22 PM
-
By Application Development in forum c++
Replies: 9
Last Post: 06-15-2007, 06:36 PM
-
By Application Development in forum c++
Replies: 1
Last Post: 05-08-2007, 09:17 AM
-
By Application Development in forum c++
Replies: 0
Last Post: 03-06-2007, 05:18 PM