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

+ Reply to Thread
Results 1 to 4 of 4

Inline Functions-What are they good for?

  1. Default 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.


  2. Default 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

  3. Default 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)


  4. Default 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



+ Reply to Thread

Similar Threads

  1. linkage of static and inline functions
    By Application Development in forum c++
    Replies: 5
    Last Post: 11-28-2007, 06:00 AM
  2. inline virtual functions
    By Application Development in forum c++
    Replies: 9
    Last Post: 07-04-2007, 03:22 PM
  3. How to dynamically call C functions using inline asm?
    By Application Development in forum c++
    Replies: 9
    Last Post: 06-15-2007, 06:36 PM
  4. inline all global functions in a lib?
    By Application Development in forum c++
    Replies: 1
    Last Post: 05-08-2007, 09:17 AM
  5. Re: inline member functions
    By Application Development in forum c++
    Replies: 0
    Last Post: 03-06-2007, 05:18 PM