, . , , C, -
#define FSM
#define STATE(x) s_##x :
#define NEXTSTATE(x) goto s_##x
FSM {
STATE(x) {
...
NEXTSTATE(y);
}
STATE(y) {
...
if (x == 0)
NEXTSTATE(y);
else
NEXTSTATE(x);
}
}
Some people may refuse to use it gotoin any circumstances, but I think this is one implementation that really uses it pretty nicely.
So, in order to answer your question, yes, I not only think that function pointers may be redundant for FSM, but also tend to obfuscate the code.
source
share