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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:26:38+00:00 2026-05-13T09:26:38+00:00

Where can I find some good, proven guidelines or examples on writing extensible, modular,

  • 0

Where can I find some good, proven guidelines or examples on writing extensible, modular, loosely-coupled code in C (if possible)?

Background of our problem is that we are maintaining large plain C, legacy code project for a low-cost microcontroller with limited computing and memory resources. Due to the fact that the system must be extremely reliable and the memory is rather limited, one of the first constraints is not to use dynamic memory allocation at all. All structures are mapped statically.

So we are looking for ways to make this code more maintainable and more modular.
We are not interested in coding standards, but rather design suggestions. We have good coding conventions (naming, organizing code, SVN) so this is not a problem.

From what I’ve seen on the web (I may be wrong), it seems most of the programmers which program exclusively in plain C or assembler, at least in the uC/Embedded community, restrain from using anything more that plain procedural programming.

For example, we could get most of the OOP benefits and decoupling in plain C using callback functions, structs containing function pointers and similar stuff (it wouldn’t require dynamic allocation, just passing around pointers to structs), but we would like to see if there are some proven methods already around.

Do you know of such resources, or have similar suggestions besides from “why don’t you switch to C++ or other programming language”?

[Edit]

Thanks a lot for all the answers, I haven’t had the time to examine them yet.
Platform is 16-bit (XC166 or similar) uC, naked hw (no RTOS).

  • 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-13T09:26:39+00:00Added an answer on May 13, 2026 at 9:26 am

    We’re in a similar situation. To address these concerns, we’ve implemented a build system that supports multiple implementations of desired interfaces (which implementation used is a function of the compilation target), and avoid use of API features that aren’t included in the portable wrappers. The wrapper definition lives in a .h file that #include‘s the implementation-specific header file. The following mock-up demonstrates how we might handle a semaphore interface:

    #ifndef __SCHEDULER_H
    #define __SCHEDULER_H
    
    /*! \addtogroup semaphore Routines for working with semaphores.
     * @{
     */
    
    /* impl/impl_scheduler.h gets copied into place before any file using
     * this interface gets compiled. */
    #include "impl/impl_scheduler.h"
    
    /* semaphore operation return values */
    typedef enum _semaphoreErr_e
    {
        SEMAPHORE_OK = impl_SEMAPHORE_OK,
        SEMAPHORE_TIMEOUT = impl_SEMAPHORE_TIMEOUT
    } semaphoreErr_e;
    
    /*! public data type - clients always use the semaphore_t type. */
    typedef impl_semaphore_t semaphore_t;
    
    /*! create a semaphore. */
    inline semaphore_t *semaphoreCreate(int InitialValue) {
      return impl_semaphoreCreate(InitialValue);
    }
    /*! block on a semaphore. */
    inline semaphoreErr_e semaphorePend(semaphore_t *Sem, int Timeout) {
      return impl_semaphorePend(Sem, Timeout);
    }
    /*! Allow another client to take a semaphore. */
    inline void semaphorePost(semaphore_t *Sem) {
      impl_semaphorePost(Sem);
    }
    
    /*! @} */
    
    #endif
    

    The public API is documented for use, and the implementation is hidden until compilation time. Using these wrappers also should not impose any overhead (though it might, depending on your compiler). There is a lot of purely mechanical typing involved, though.

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

Sidebar

Related Questions

Do you know where i can find some code examples for the new GWT
Where can I find some good pointers on best practices for running ASP.NET MVC
Were can I find some good Podcasts that talk about program with Delphi &
I came across this line in some code and can't find the syntax defined
Where can i find some .Net or conceptual resources to start working with Natural
For some reason I can't find a way to get the equivalents of sqlite's
I'm trying to find out some matrix multiplication/inversion benchmarks online. My C++ implementation can
I've done some Googling, and can't find anything, though maybe I'm just looking in
I'm doing some research on the feasibility of an iPhone application, and can't find
I've done some research and I can't really find a preferred way to do

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.