Last active
January 1, 2019 11:27
-
-
Save an-dr/f8f76cfc6498ab4b04ffd31c4b3dd31d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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