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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:31:21+00:00 2026-05-20T13:31:21+00:00

I have searched and have been unable to verify how the GCC compiler will

  • 0

I have searched and have been unable to verify how the GCC compiler will handle inlining getters and setters when declaration is in .h file and definition is in .cpp file.

Most seem to say that GCC can’t see across these source file barriers and won’t be able to inline these at all, while others disagree. I have looked at the documentation and I can’t find the answer there either. Did I miss it?

I do realize that inlining is a choice made by the compiler and is not always guaranteed, but assuming optimal situations, is it at least possible?

  • 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-20T13:31:22+00:00Added an answer on May 20, 2026 at 1:31 pm

    (What you really meant to ask is about the situation where the definition is in a different .cpp file to the one you’re currently compiling, and then linked in later. The compiler doesn’t care about .hpp or .cpp, but about translation units.)

    Anyway, on http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html, scroll down to “flno”:

    This option runs the standard link-time optimizer.
    […]
    The first two invocations to GCC will save a bytecode representation of GIMPLE into special ELF sections inside foo.o and bar.o. The final invocation will read the GIMPLE bytecode from foo.o and bar.o, merge the two files into a single internal image, and compile the result as usual. Since both foo.o and bar.o are merged into a single image, this causes all the inter-procedural analyses and optimizations in GCC to work across the two files as if they were a single one. This means, for example, that the inliner will be able to inline functions in bar.o into functions in foo.o and vice-versa.

    So, yes, it’s possible to optimise inlines across module boundaries.

    However, C++ still makes its requirement of:

    An inline function shall be defined in every translation unit in which it is used. [3.2/3, C++03]

    So in fact you may not write your code to take advantage of this if you used the inline keyword; you are instead reliant on the linker “just deciding” to inline your function if it sees fit. So it’s not an option that’s going to allow you to move your code around.

    Remember, writing inline in your code does not have a one-to-one relationship with a function actually getting physically inlined; it’s only a hint to the compiler (or linker, if you have the above mentioned link-time optimisations turned on).

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

Sidebar

Related Questions

I've searched for an answer to this question and have been unable to find
I have searched but been unable to find anything that does what I need.
I have searched for the past two hours and have been unable to find
I've searched SO and have been unable to find this question asked before, but
I have searched the web and stack overflow questions but been unable to find
I have searched far and wide and been completely unable to find any good
I have searched around but have been unsuccessful in determining whether the following approach
I have searched around and have not been able to find a solution for
I realize this is a basic question but I have searched online, been to
I asked this question earlier and I have been reading the answers and searched

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.