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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:03:40+00:00 2026-05-10T20:03:40+00:00

I am working on an embedded application where the device is controlled through a

  • 0

I am working on an embedded application where the device is controlled through a command interface. I mocked the command dispatcher in VC and had it working to my satisfaction; but when I then moved the code over to the embedded environment, I found out that the compiler has a broken implementation of pointer-to-func’s.

Here’s how I originally implemented the code (in VC):

/* Relevant parts of header file  */ typedef struct command {   const char *code;   void *set_dispatcher;   void *get_dispatcher;   const char *_description; } command_t;  #define COMMAND_ENTRY(label,dispatcher,description) {(const char*)label, &set_##dispatcher, &get_##dispatcher, (const char*)description}    /* Dispatcher data structure in the C file */ const command_t commands[] = {   COMMAND_ENTRY('DH', Dhcp, 'DHCP (0=off, 1=on)'),   COMMAND_ENTRY('IP', Ip, 'IP Address (192.168.1.205)'),   COMMAND_ENTRY('SM', Subnet, 'Subunet Mask (255.255.255.0)'),   COMMAND_ENTRY('DR', DefaultRoute, 'Default router (192.168.1.1)'),   COMMAND_ENTRY('UN', Username, 'Web username'),   COMMAND_ENTRY('PW', Password, 'Web password'),   ... }   /* After matching the received command string to the command 'label', the command is dispatched */ if (pc->isGetter)   return ((get_fn_t)(commands[i].get_dispatcher))(pc); else   return ((set_fn_t)(commands[i].set_dispatcher))(pc);   } 

Without the use of function pointers, it seems like my only hope is to use switch()/case statements to call functions. But I’d like to avoid having to manually maintain a large switch() statement.

What I was thinking of doing is moving all the COMMAND_ENTRY lines into a separate include file. Then wraps that include file with varying #define and #undefines. Something like:

/* Create enum's labels */ #define COMMAND_ENTRY(label,dispatcher,description) SET_##dispatcher, GET_##dispatcher typedef enum command_labels = { #include 'entries.cinc'   DUMMY_ENUM_ENTRY} command_labels_t; #undefine COMMAND_ENTRY   /* Create command mapping table */ #define COMMAND_ENTRY(label,dispatcher,description) {(const char*)label, SET_##dispatcher, GET_##dispatcher, (const char*)description}  const command_t commands[] = { #include 'entries.cinc'   NULL /* dummy */ }; #undefine COMMAND_ENTRY  /*...*/  int command_dispatcher(command_labels_t dispatcher_id) { /* Create dispatcher switch statement */ #define COMMAND_ENTRY(label,dispatcher,description) case SET_##dispatcher: return set_##dispatcher(pc); case GET_##dispatcher: return get_##dispatcher(pc); switch(dispatcher_id) { #include 'entries.cinc' default:   return NOT_FOUND; } #undefine COMMAND_ENTRY } 

Does anyone see a better way to handle this situation? Sadly, ‘get another compiler’ is not a viable option. 🙁

— Edit to add: Just to clarify, the particular embedded environment is broken in that the compiler is supposed to create a ‘function-pointer table’ which is then used by the compiler to resolve calls to functions through a pointer. Unfortunately, the compiler is broken and doesn’t generate a correct function-table.

So I don’t have an easy way to extract the func address to invoke it.

— Edit #2: Ah, yes, the use of void *(set|get)_dispatcher was my attempt to see if the problem was with the typedefine of the func pointers. Originally, I had

typedef int (*set_fn_t)(cmdContext_t *pCmdCtx); typedef int (*get_fn_t)(cmdContext_t *pCmdCtx);  typedef struct command {   const char *code;   set_fn_t set_dispatcher;   get_fn_t get_dispatcher;   const char *_description; } command_t; 
  • 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-10T20:03:41+00:00Added an answer on May 10, 2026 at 8:03 pm

    You should try changing your struct command so the function pointers have the actual type:

    typedef struct command {   const char *code;   set_fn_t set_dispatcher;   get_fn_t get_dispatcher;   const char *_description; } command_t; 

    Unfortunately, function pointers are not guaranteed to be able to convert to/from void pointers (that applies only to pointers to objects).

    What’s the embedded environment?


    Given the information posted in the updates to the question, I see that it’s really a bugged compiler.

    I think that your proposed solution seems pretty reasonable – it’s probably similar to what I would have come up with.

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

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Below is my PHP implementation of my algorithm to calculate… May 12, 2026 at 12:33 am
  • Editorial Team
    Editorial Team added an answer The majority (if not all) of valid uses for setup… May 12, 2026 at 12:33 am
  • Editorial Team
    Editorial Team added an answer The way I would do it is to simply go… May 12, 2026 at 12:33 am

Related Questions

I've been looking around for quite a while and feel that I have a
I am working on an embedded application that uses NAND flash for storage. As
While prototyping, to what extent do you throw best practices out of the door
I am working on an application for Windows Mobile 6 (or maybe 5) that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.