I realize that I don't don't know the correct syntax to say:
typedef ResultType (*StateFunctionType)(StateFunctionType* currentStateFuncPtr, NewDataType newData);
so how do I do that? GCC gives me
error: unknown type name 'StateFunctionType'
I am writing a state machine that uses a function pointer to keep track of the current state and do what needs to get done in that state.
As things external to this state machine occur they will cause a call to the current state function with arguments that tell about these external changes. Occasionally the current state may need to change the current state to a different state. At first I was passing in a this*
to a struct containing some of the data that needed to be updated including the current state function pointer, but as I refined the code the only piece of data from that struct that the current state actually needs is a pointer to the current state so that it can update it.
I know that I can get around this with typecasting or just leaving the this*
to the structure that contains the state function pointer, but I want to avoid typecasting (letting the compiler yell at me about data type mistakes), and it really just bothers me that I can't think of how to concisely write something that's conceptually very simple (at least in my mind). I wish that I could even come up with a more concise way to ask this question.
(please don't be something extremely dumb on my part)