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 5995021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:54:04+00:00 2026-05-22T23:54:04+00:00

Considering next simple example: The header: // a.hpp #ifndef A_HPP #define A_HPP #include <memory>

  • 0

Considering next simple example:

The header:

// a.hpp
#ifndef A_HPP
#define A_HPP
#include <memory>

class A
{
 public:
  A();

  int foo();

 private:
  struct Imp;
  std::auto_ptr< Imp > pimpl;
};

#endif // A_HPP

The implementation :

// a.cpp
#include "a.hpp"

struct A::Imp
{
 int foo()
 {
  // do something and return the result
 }
};

A::A() : pimpl( new Imp )
{}
int A::foo()
{
  return pimpl->foo();
}

The main :

// main.cpp
#include "header.hpp"
int main()
{
  A a;
  return a.foo();
}

The questions are :
Is the method A::Imp::foo going to get inlined into A::foo?
Does it depend on the implementation what is in that method?

PS
I am using gcc (4.3.0 if it matters).

EDIT

I guess I didn’t explain very well. What I exactly meant is this. If I use the maximum optimization level, is the // do something and return the result going to be placed in the A::foo() or A::Imp::foo()?
Without optimization, I see that this is not done (the pimpl->foo() is still called).

I understand that A::foo() will never get inlined in main(), but that is not what I am asking.

  • 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-22T23:54:05+00:00Added an answer on May 22, 2026 at 11:54 pm

    Herb Sutter once made a great article about inlining.

    The first question to ask is: when can inlining happen ?

    In C++:

    • it may happen at the compilation stage
    • it may happen at the link stage (LTO: Link Time Optimization)

    Both times, the mechanism is similar: if the compiler/linker knows about the implementation of the method, it may decide to copy/paste the implementation in place of emitting a call. This decision is based on complex heuristics, and I only know they exist, not what they are about.

    The critical point is therefore the knows about the implementation bit.

    • for the compiler: it means defined in the same translation unit
    • for the linker: it means defined in one of the translation units being linked OR in a static library it will linked to… afaik it won’t be optimized if the method resides in a DLL

    So here: yes, the call pimpl->foo() may be inlined within A::foo. It will depend on both the compiler and the compiling options.

    For gcc/clang, if A::Impl::foo is small enough, it could be optimized from O1 onward (unless you pass -fno-inline).

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

Sidebar

Related Questions

Considering such code: class ToBeTested { public: void doForEach() { for (vector<Contained>::iterator it =
We're considering writing the next version of out project in using .Net 3, but
My team is considering building our next web app using the ASP.NET MVC framework.
While considering the JS framework for my next project, I can see the scale
Considering private is the default access modifier for class Members, why is the keyword
I'm not sure about how pthread dataspecific works : considering the next code (found
Considering this code, can I be absolutely sure that the finally block always executes,
Considering the following architecture: a base object 'Entity' a derived object 'Entry:Base' and a
Considering the criteria listed below, which of Python, Groovy or Ruby would you use?
Considering a large system with hundreds of assemblies, what is the easiest way to

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.