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

  • SEARCH
  • Home
  • 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 562909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:36:15+00:00 2026-05-13T12:36:15+00:00

Many years ago, C compilers were not particularly smart. As a workaround K&R invented

  • 0

Many years ago, C compilers were not particularly smart. As a workaround K&R invented the register keyword, to hint to the compiler, that maybe it would be a good idea to keep this variable in an internal register. They also made the tertiary operator to help generate better code.

As time passed, the compilers matured. They became very smart in that their flow analysis allowing them to make better decisions about what values to hold in registers than you could possibly do. The register keyword became unimportant.

FORTRAN can be faster than C for some sorts of operations, due to alias issues. In theory with careful coding, one can get around this restriction to enable the optimizer to generate faster code.

What coding practices are available that may enable the compiler/optimizer to generate faster code?

  • Identifying the platform and compiler you use, would be appreciated.
  • Why does the technique seem to work?
  • Sample code is encouraged.

Here is a related question

[Edit] This question is not about the overall process to profile, and optimize. Assume that the program has been written correctly, compiled with full optimization, tested and put into production. There may be constructs in your code that prohibit the optimizer from doing the best job that it can. What can you do to refactor that will remove these prohibitions, and allow the optimizer to generate even faster code?

[Edit] Offset related link

  • 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-13T12:36:15+00:00Added an answer on May 13, 2026 at 12:36 pm

    Write to local variables and not output arguments! This can be a huge help for getting around aliasing slowdowns. For example, if your code looks like

    void DoSomething(const Foo& foo1, const Foo* foo2, int numFoo, Foo& barOut)
    {
        for (int i=0; i<numFoo, i++)
        {
             barOut.munge(foo1, foo2[i]);
        }
    }
    

    the compiler doesn’t know that foo1 != barOut, and thus has to reload foo1 each time through the loop. It also can’t read foo2[i] until the write to barOut is finished. You could start messing around with restricted pointers, but it’s just as effective (and much clearer) to do this:

    void DoSomethingFaster(const Foo& foo1, const Foo* foo2, int numFoo, Foo& barOut)
    {
        Foo barTemp = barOut;
        for (int i=0; i<numFoo, i++)
        {
             barTemp.munge(foo1, foo2[i]);
        }
        barOut = barTemp;
    }
    

    It sounds silly, but the compiler can be much smarter dealing with the local variable, since it can’t possibly overlap in memory with any of the arguments. This can help you avoid the dreaded load-hit-store (mentioned by Francis Boivin in this thread).

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

Sidebar

Related Questions

Background: Many years ago, I inherited a codebase that was using the Visual Studio
HI: I've a Delphi 7 program that I wrote many years ago, but I've
I can understand that many years ago there would be this kind of limitation,
I used a script many years ago that was basically and administrative backend where
I can remember that many years ago (in 2005) I was using BackgroundWorker in
When I started OO programming many years ago I gained the impression that variables
I've got an application here that I wrote many years ago that consists of
I made a program many years ago, that connects to a SQL Server database
It's been awhile since I've wrote applications that dealt with money. Many years ago,
I had a Delphi 4 program that I developed many years ago that used

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.