inline confusion

This is a discussion on inline confusion within the C++ Programming forums, part of the General Programming Boards category; Is there any gain in making member functions inline?...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    113

    inline confusion

    Is there any gain in making member functions inline?

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    The advantage of inline functions is avoiding the overhead of calling an actual function. Such overhead includes setting up stack frames, saving registers, and such. But with large functions the overhead isn't important.
    Sent from my iPadŽ

  3. #3

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    Thanks sunny,
    There is one more querry,how long function can be so that inling it is beneficial?

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    It's not as simple as how long is too long to inline? I quote from the text that sunny posted.

    There are no simple answers: You have to play with it to see what is best. Do not settle for simplistic answers like, "Never use inline functions" or "Always use inline functions" or "Use inline functions if and only if the function is less than N lines of code." These one-size-fits-all rules may be easy to write down, but they will produce sub-optimal results.
    Sent from my iPadŽ

  6. #6
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Just adding

    The inline keyword tells the compiler that inline expansion is preferred. However, the compiler can create a separate instance of the function (instantiate) and create standard calling linkages instead of inserting the code inline. Two cases where this can happen are:

    Recursive functions.

    Functions that are referred to through a pointer elsewhere in the translation unit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inline Definitions and Declarations?
    By legit in forum C++ Programming
    Replies: 1
    Last Post: 06-15-2009, 02:59 PM
  2. When to inline your *tors
    By Angus in forum C++ Programming
    Replies: 43
    Last Post: 10-29-2008, 04:38 PM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  4. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  5. inline??
    By bman1176 in forum C++ Programming
    Replies: 2
    Last Post: 06-25-2002, 06:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21