This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

c program

hello;
i want to know that where we use link list, function pointer, generic pointer in embedded programming

Parents
  • If each case just calls a function, those functions might happen to have switch statement inside, but won't cause readability and indentation problems.

    Exactly, thanks for guessing my thoughts.

    #define STATE_INIT 0
    #define STATE_WORK 1
    
    void state_machine()
    {
       static int current_state = STATE_INIT;
    
       switch(current_state)
       {
          case STATE_INIT:
             current_state = state_init();
             break;
          case STATE_WORK:
             current_state = state_work();
             break;
          default:
             current_state = STATE_INIT;
             break;
       }
    }
    
    int state_init()
    {
       return(STATE_WORK);
    }
    
    int state_work()
    {
       return(STATE_WORK);
    }
    
    

    Something along those lines.

Reply
  • If each case just calls a function, those functions might happen to have switch statement inside, but won't cause readability and indentation problems.

    Exactly, thanks for guessing my thoughts.

    #define STATE_INIT 0
    #define STATE_WORK 1
    
    void state_machine()
    {
       static int current_state = STATE_INIT;
    
       switch(current_state)
       {
          case STATE_INIT:
             current_state = state_init();
             break;
          case STATE_WORK:
             current_state = state_work();
             break;
          default:
             current_state = STATE_INIT;
             break;
       }
    }
    
    int state_init()
    {
       return(STATE_WORK);
    }
    
    int state_work()
    {
       return(STATE_WORK);
    }
    
    

    Something along those lines.

Children
No data