Skip to content

Instantly share code, notes, and snippets.

@an-dr
Last active January 1, 2019 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save an-dr/f8f76cfc6498ab4b04ffd31c4b3dd31d to your computer and use it in GitHub Desktop.
Save an-dr/f8f76cfc6498ab4b04ffd31c4b3dd31d to your computer and use it in GitHub Desktop.
#include <stdio.h>
void *stateStart();
void *state1();
void *state2();
void *stateEnd();
int main()
{
printf("StateMachine Demo\n");
void* (*state_func_p)();// pointer to function returning pointer to next function
state_func_p = stateStart; // init state
while(state_func_p)
{
state_func_p = state_func_p();
}
return 0;
}
void *stateStart()
{
printf("State0\n");
return state1;
}
void *state1()
{
printf("State1\n");
return state2;
}
void *state2()
{
printf("State2\n");
return stateEnd;
}
void *stateEnd()
{
printf("State3\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment