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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:07:06+00:00 2026-05-28T16:07:06+00:00

My application is written in C. I have a module that uses some data

  • 0

My application is written in C. I have a module that uses some data from a certain given global structure. I now have to extend the module to optionally work against a different given global structure, which basically provides the same fields (as far as my module is concerned), but under different names.

Here’s a car analogy to hopefully make my problem clearer. I’ve got these two global structures I have no control over.

struct {
   unsigned char manufacturer_id;
   unsigned short top_speed;
} Car;

struct {
   RGB_t color;
   unsigned short topSpeed;
   unsigned char mfr;
} Automobile;

Let’s say my Car Manager module uses information from Automobile. E.g.,

const char *car_manager__get_manufacturer_name(car_manager_t *self)
{
    return self->manufacturers[Automobile.mfr];
}

I’d like to extend Car Manager to optionally (perhaps decided by a flag in the car_manager_t instance) use the same information from Car, so the above function would return self->manufacturers[Car.manufacturer_id]. I don’t want to duplicate any logic in the module while adding this functionality.

I assume I’ll have to put an interface on the access to the global structures. Any suggestions on how to do that?

  • 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-28T16:07:07+00:00Added an answer on May 28, 2026 at 4:07 pm

    I would define functions for getting the needed values, and pass pointers to the functions. You could even pass a struct which contains the needed function pointers.

    struct Interface {
      unsigned char  (*manufacturer)(void);
      unsigned short (*top_speed)(void);
    }
    struct Interface CarInterface  = {&Car_manufacturer, &Car_top_speed};
    struct Interface AutoInterface = {&Auto_manufacturer, &Auto_top_speed};
    
    const char *car_manager__get_manufacturer_name(car_manager_t *self, Interface i)
    {
      return self->manufacturers[(*i.manufacturer)()];
    }
    

    I haven’t written any C for a long time; please correct my syntax if necessary!

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

Sidebar

Related Questions

I have a ASP.NET application that we've written our own logging module for. My
I have written an IIS module (base IHttpModule) that does some custom (OpenAuth) authentication
I have a VB6 application that uses a COM DLL. The DLL is written
I have a legacy system that I'd like to extend with an application written
Background: I have an application written in native C++ which uses the wxWidgets toolkit's
i have written an application, but for some reason it keeps peaking at 100%.
I have developed an application written in unmanaged C++ that makes use of OpenCV
Currently, I have an application which uses the cmd.Cmd module for the command line
I have written a really small 64-bit application that crashes on clean installations of
I am having some strange problem. I have written a small module in VC++

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.