Thread: Pass arguments though lookup table

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    22

    Pass arguments though lookup table

    Code:
        enum states { STATE_1, STATE_2, STATE_3 MAX_STATES } current_state;
        enum events { EVENT_1, MAX_EVENTS } new_event;
        
    
        void action_s1_e1 (struct call_info_s *p);
        void action_s2_e1 (struct call_info_s *p);
        void action_s3_e1 (struct call_info_s *p);
    
        void (*const state_table [MAX_STATES][MAX_EVENTS]) (void) = {
        { action_s1_e1}, 
        { action_s2_e1}, 
        { action_s3_e1},
        };
    ------------------------------------------------------------------------

    Code:
    new_event = get_new_event();
    
        if (((new_event >= 0) && (new_event < MAX_EVENTS))
        && ((current_state >= 0) && (current_state < MAX_STATES))) {
        
            state_table [current_state][new_event]();
    
        } else {
    
        }
    ------------------------------------------------------------------------

    Code:
    void action_s1_e1 (struct call_info_s *call_info)
    {
        dosomething(call_info);
    
    
    }
    I am trying to get this state machine code that i found on the net to work. At this step I am trying to figure out how to pass argument through the lookup table.


    Code:
    void (*const state_table [MAX_STATES][MAX_EVENTS]) (void) = {
        { action_s1_e1},

    In the example action prototypes defines argumenttype for action_s1_e1(). stable_table prototype defines the functions to be called. What do I need to do to include passing arguments. For example dosomething function receiving struct pointer
    Last edited by robi; 10-15-2011 at 07:29 PM.

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    231
    Quote Originally Posted by robi View Post
    Code:
    void (*const state_table [MAX_STATES][MAX_EVENTS]) (void) = {
        { action_s1_e1},
    If you need a parameter in your action functions, you must declare this also in your 2dim function-pointer like
    Code:
    void (*const state_table [MAX_STATES][MAX_EVENTS]) (struct call_info_s *) = {
        { action_s1_e1},

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick log lookup table
    By R.Stiltskin in forum C++ Programming
    Replies: 19
    Last Post: 12-04-2008, 12:39 PM
  2. Making a lookup table?
    By username101 in forum C Programming
    Replies: 7
    Last Post: 05-09-2008, 09:10 AM
  3. using a shared lookup table
    By zxcv in forum C Programming
    Replies: 1
    Last Post: 02-21-2008, 12:10 AM
  4. Lookup Table Reference???
    By gvector1 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2003, 05:03 PM
  5. Table Lookup Processing
    By muffin in forum C Programming
    Replies: 1
    Last Post: 08-29-2001, 12:07 PM