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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:08:49+00:00 2026-06-15T23:08:49+00:00

This question asks about a finite state machine with 100 states and each state

  • 0

This question asks about a finite state machine with 100 states and each state having 100 events, and then does a brief comparison of using an if-else, switch statement, or function pointers to implement the state machine.

My question is: if using function pointers, how would the function pointers be appropriately set? With an if-else or a switch statement (in which case, would function pointers be more of a hybrid solution)? Or is there another way this is commonly done?

  • 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-06-15T23:08:51+00:00Added an answer on June 15, 2026 at 11:08 pm

    You could do something like below:

    typedef int (*current_state) (void);
    typedef int (*nextnew_state) (void);
    struct FuncPointerState
    {
      current_state curr_state;
      nextnew_state next_state;
    }; 
    
    
    /*init_state is the initial function state*/
    struct FuncPointerState FpState = {init_state, NULL};     
    int iRet = 0;
    
    while(1)
    {
    
       iRet = FpState.curr_state();
       if(iRet<= 0 )
       {
          return iRet;
       }
       if(NULL==FpState.next_state)
       {
         /* State Machine finished it's job */
          break;
       }
       FpState.curr_state = FpState.next_state;
    
    }
    

    Each state function should populate the next_state pointer. Also, you can modify the function pointers to take input arguments.

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

Sidebar

Related Questions

This question asks about file name the servers sends and the fix was quite
This other SO question asks about an autocomplete textbox in WPF. Several people have
Somewhat on the back of this question that asks about the behaviour of the
This question asks about storing a single graph in a relational database. The solution
This question relates to my previous question which asks about loading a page into
Having just implemented this, I have a pretty basic question about how authentication and
This question asks about the disadvantages of 'cgi-bin based' services. As far as I
This question asks the general question. I'm asking about VHDL in particular, since the
In this question superwiren asks about the pitfalls for converting a .net 2.0 solution
This question asks about getting a random(ish) sample of records on SQL Server and

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.