Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 499717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:00:50+00:00 2026-05-13T06:00:50+00:00

I know that inline is a hint or request to the compiler and is

  • 0

I know that inline is a hint or request to the compiler and is used to avoid function call overheads.

So, on what basis one can determine whether a function is a candidate for inlining or not?
In which case one should avoid inlining?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:00:51+00:00Added an answer on May 13, 2026 at 6:00 am

    Avoiding the cost of a function call is only half the story.

    do:

    • use inline instead of #define
    • very small functions are good candidates for inline: faster code and smaller executables (more chances to stay in the code cache)
    • the function is small and called very often

    don’t:

    • large functions: leads to larger executables, which significantly impairs performance regardless of the faster execution that results from the calling overhead
    • inline functions that are I/O bound
    • the function is seldom used
    • constructors and destructors: even when empty, the compiler generates code for them
    • breaking binary compatibility when developing libraries:
      • inline an existing function
      • change an inline function or make an inline function non-inline: prior version of the library call the old implementation

    when developing a library, in order to make a class extensible in the future you should:

    • add non-inline virtual destructor even if the body is empty
    • make all constructors non-inline
    • write non-inline implementations of the copy constructor and assignment operator unless the class cannot be copied by value

    Remember that the inline keyword is a hint to the compiler: the compiler may decide not to inline a function and it can decide to inline functions that were not marked inline in the first place. I generally avoid marking function inline (apart maybe when writing very very small functions).

    About performance, the wise approach is (as always) to profile the application, then eventually inline a set of functions representing a bottleneck.

    References:

    • To Inline or Not To Inline
    • [9] Inline functions
    • Policies/Binary Compatibility Issues With C++
    • GotW #33: Inline
    • Inline Redux
    • Effective C++ – Item 33: Use inlining judiciously

    EDIT: Bjarne Stroustrup, The C++ Programming Language:

    A function can be defined to be inline. For example:

    inline int fac(int n)
    {
      return (n < 2) ? 1 : n * fac(n-1);
    }
    

    The inline specifier is a hint to the compiler that it should attempt to generate code for a call of fac() inline rather than laying down the code for the function once and then calling through the usual function call mechanism. A clever compiler can generate the constant 720 for a call fac(6). The possibility of mutually recursive inline functions, inline functions that recurse or not depending on input, etc., makes it impossible to guarantee that every call of an inline function is actually inlined. The degree of cleverness of a compiler cannot be legislated, so one compiler might generate 720, another 6 * fac(5), and yet another an un-inlined call fac(6).

    To make inlining possible in the absence of unusually clever compilation and linking facilities, the definition–and not just the declaration–of an inline function must be in scope (§9.2). An inline especifier does not affect the semantics of a function. In particular, an inline function still has a unique address and so has static variables (§7.1.2) of an inline function.

    EDIT2: ISO-IEC 14882-1998, 7.1.2 Function specifiers

    A function declaration (8.3.5, 9.3, 11.4) with an inline specifier declares an inline function. The inline specifier indicates to the implementation that inline substitution of the function body at the point of call is to be preferred to the usual function call mechanism. An implementation is not required to perform this inline substitution at the point of call; however, even if this inline substitution is omitted, the other rules for inline functions defined by 7.1.2 shall still be respected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.