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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:28:19+00:00 2026-05-25T00:28:19+00:00

I was working on an embedded program using C. There are tons of hardware

  • 0

I was working on an embedded program using C.

There are tons of hardware macros like

#ifdef HardwareA 
do A 
#endif

It’s not readable, and hard to cover all the different paths with unit tests.

So, I decided to move the hardware related code to arch folders, and using macros in the makefile to decide which arch folder is linked. Like in the Linux kernel code.

But when I saw the Linux kernel, I noticed there are so many duplicates in the arch folders.

How do they make the changes to all related hardware when a bug was found in one hardware, but might affect all others?

I think doing this way will inevitably bring duplicates into the code base.

Does anyone have experience with this type of problem?

How to unit test on code which has lots of hardware macros?

Refactoring the code to move hardware macros off source code?

  • 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-25T00:28:20+00:00Added an answer on May 25, 2026 at 12:28 am

    It sounds like you are replacing a function like this:

    somefunc()
    {
        /* generic code ... */
    
        #ifdef HardwareA 
        do A 
        #endif
    
        /* more generic code ... */
    }
    

    with multiple implementations, one in each arch folder, like this:

    somefunc()
    {
        /* generic code ... */
    
        /* more generic code ... */
    }
    
    somefunc()
    {
        /* generic code ... */
    
        do A 
    
        /* more generic code ... */
    }
    

    The duplication of the generic code is what you’re worried about. Don’t do that: instead, have one implementation of the function like this:

    somefunc()
    {
        /* generic code ... */
    
        do_A();
    
        /* more generic code ... */
    }
    

    ..and then implement do_A() in the arch folders: on Hardware A it has the code for that hardware, and on the other hardware, it is an empty function.

    Don’t be afraid of empty functions – if you make them inline functions defined in the arch header file, they’ll be completely optimised out.

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

Sidebar

Related Questions

I am working in embedded system domain. I would like to know how a
I'm working on an embedded Linux project that interfaces an ARM9 to a hardware
I'm working on an embedded device that does not support unaligned memory accesses. For
I am working a C firmware program for an embedded device. I want to
I'm having trouble getting Jackson mixins working for embedded types when using @ResponseBody. I'm
I'm working with some embedded hardware, a Rabbit SBC, which uses Dynamic C 9.
I'm working on a lighttpd server in an embedded system that is not configured
I'm working with embedded C for the first time. Although my C is rusty,
I am working on embedded device with 266 Mhz processor and 32 Bit bus
I mostly use SlickEdit and eclipse while working on embedded systems. Once in a

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.