Inline Functions-What are they good for?

D

D. Susman

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.
 
B

Barry

D. Susman said:
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.
 
P

Pete Becker

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.
 
B

Bo Persson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,062
Members
48,769
Latest member
Clifft

Latest Threads

Top