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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:47:47+00:00 2026-05-24T00:47:47+00:00

My question is at which level compiler applies optimization. Is it at the level

  • 0

My question is at which level compiler applies optimization. Is it at the level of different code files? If that is the case then isn’t it more inefficient than say if it were applied across the whole code? Secondly, what happens when one of the source file was compiled with no optimization and then linked with one with -O3 level optimization?

I am especially interested in knowing how gcc handle such things.

  • 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-24T00:47:49+00:00Added an answer on May 24, 2026 at 12:47 am

    Individual translation units can be compiled with separate optimization flags, that’s generally not a problem. Compile-time optimizations usually only affect the visible code within one TU.

    An exception to that rule is the flag -fwhole-program, which indicates that your source code constitutes the entire program and allows for more aggressive optimization:

    gcc -o prog *.c -O3 -fwhole-program -s
    

    That said, GCC has recently introduced another layer of optimisations at link time; to use this, compile everything with -flto (GCC 4.6). However, this is also independent of the optimization flags for each TU:

    gcc -c module1.c -flto -O2
    gcc -c module2.c -flto -O3 -fno-strict-aliasing
    gcc -c module3.c -flto -O0
    gcc -c module4.c -O1
    gcc -o prog module*.o -flto -s
    

    Finally, you can also specify an independent -O* option at link stage, but I don’t know if that makes any difference.

    Also note that precompiled header files cannot be independently optmizied; a PCH is only eligible if it was compiled with the same optimization settings as the TU.

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

Sidebar

Related Questions

This isn't a holy war, this isn't a question of which is better. What
This question originally asked which is the best method for uploading files via SFTP
I have a question concerning this code which I want to run on QNX:
If you code in C and configure your compiler to insist that all functions
This is a high-level question about web frameworks, that as a desktop app developer,
This question is related to another question which I asked yesterday! List all links
I know about this question: Which (third-party) debug visualizers for Visual Studio 2005/2008 do
I asked a question earlier which elicited some great responses. Here's the earlier question
This may be a painfully simply question for which I will be mocked but
I just want to clarify one thing. This is not a question on which

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.