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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:01:11+00:00 2026-05-16T09:01:11+00:00

Optimizations such as constant propagation are possible across functions within the same compilation unit

  • 0

Optimizations such as constant propagation are possible across functions within the same compilation unit (ie. same file).

For example :

int f(int x)
{
    return 3 + x;
}

int main(void)
{
    printf("%d\n", 1 + f(4));
    return 0;
}

In that example, I think that a sufficiently smart compiler can propagate the ‘4’ constant to the function ‘f’, solving the integer arithmetic with
the other constant ‘3’, and propagates back the result value thus folding everything to the final value ‘8’.

(Well, correct me if I’m wrong..)

However, what is happening if the function ‘f’ is in another compilation unit. Since they both units are compiled separately, the compiler can’t
optimize that way.

Does it mean that optimizations are only possible within the same compilation unit, or is there some form late optimizations performed of link-time?

  • 1 1 Answer
  • 2 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-16T09:01:11+00:00Added an answer on May 16, 2026 at 9:01 am

    Both MSVC (since 8.0: VS2005) and GCC (since 4.5) support the concept.

    • MSVC uses a compiler switch /GL and linker switch /LTCG. Documentation

    • GCC must have it enabled and uses the -flto, -fwhole-program, -fwhopr, and/or -combine to the same effect. Documentation (search for the options in your browser)

    The “problem” is that every compilation unit (source file) (and in the case of MSVC every library) needs to be compiled with this, so you can’t use old binary object files compiled without it. It also makes debugging harder, because the optimizer is a lot more aggressive and unpredictable.

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

Sidebar

Related Questions

How do modern optimizing compilers determine when to apply certain optimizations such as loop
Are there any optimizations, such as dead code elimination, involved when translating java source
Now that LINQ is such an integral part of .NET, are their optimizations at
I am working on performance optimizations of ARM C/C++ code, compiled with GCC. CPU
I'm currently doing some last-measure optimizations, mostly for fun and learning, and discovered something
I've been curious as to all the optimizations that go into the building of
I have a question about structure padding and memory alignment optimizations regarding structures in
It is always better for contants such as PI to #define them or declare
Linq does a lot of clever things such as returning the result of the
I was just wondering where I could find more information on these optimizations? Google

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.