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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:00:05+00:00 2026-05-11T11:00:05+00:00

I have a legacy firmware application that requires new functionality. The size of the

  • 0

I have a legacy firmware application that requires new functionality. The size of the application was already near the limited flash capacity of the device and the few new functions and variables pushed it over the edge. Turning on compiler optimization does the trick, but the customer is wary of doing so because they have caused failures in the past. So, what are some common things to look for when refactoring C code to produce smaller output?

  • 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. 2026-05-11T11:00:05+00:00Added an answer on May 11, 2026 at 11:00 am
    • Use generation functions instead of data tables where possible
    • Disable inline functions
    • Turn frequently used macros into functions
    • Reduce resolution for variables larger than the native machine size (ie, 8 bit micro, try to get rid of 16 and 32 bit variables – doubles and quadruples some code sequences)
    • If the micro has a smaller instruction set (Arm thumb) enable it in the compiler
    • If the memory is segmented (ie, paged or nonlinear) then
      • Rearrange code so that fewer global calls (larger call instructions) need to be used
      • Rearrange code and variable usage to eliminate global memory calls
      • Re-evaluate global memory usage – if it can be placed on the stack then so much the better
    • Make sure you’re compiling with debug turned off – on some processors it makes a big difference
    • Compress data that can’t be generated on the fly – then decompress into ram at startup for fast access
    • Delve into the compiler options – it may be that every call is automatically global, but you might be able to safely disable that on a file by file basis to reduce size (sometimes significantly)

    If you still need more space than with compile with optimizations turned on, then look at the generated assembly versus unoptimized code. Then re-write the code where the biggest changes took place so that the compiler generates the same optimizations based on tricky C re-writes with optimization turned off.

    For instance, you may have several ‘if’ statements that make similar comparisons:

    if(A && B && (C || D)){} if(A && !B && (C || D)){} if(!A && B && (C || D)){} 

    Then creating anew variable and making some comparisons in advance will save the compiler from duplicating code:

    E = (C || D);  if(A && B && E){} if(A && !B && E){} if(!A && B && E){} 

    This is one of the optimizations the compiler does for you automatically if you turn it on. There are many, many others, and you might consider reading a bit of compiler theory if you want to learn how to do this by hand in the C code.

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

Sidebar

Related Questions

We have a legacy WinCE device that's been working fine for years when it
We have a legacy system that requires a format which is not html but
I have a legacy VB6 application that has the following structure defined: Public Type
Have a legacy LAMP application that I'm in the process of converting over to
I have a legacy application that used binary serialisation to persist the data. Now
I have a legacy application and third party software that both require NTFS volumes
I have a legacy ASP application that I support. By support I mean that
I have legacy DB that store dates that means no-date as 9999-21-31, The column
I have a legacy MFC C++ application for Win CE 4.2 (x86 ONLY) which
I have one legacy web application based on struts2 (primarily using annotation). While debugging

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.