c - Are function pointers really needed for implementing a FSM? -
i reading http://www.netrino.com/embedded-systems/how-to/state-machines-event-driven-systems later in article provide implementation of small fsm in c language.
i don't quite understand why chose function pointers. in understanding pointers functions useful when 1 needs same interface, different types of "events", example parsing internet protocol packet (it's convenient register 1 pointer function , assign different functions, 1 parse http, second parse ftp , on. merely example, think got point).
but not see in article, imho state machine astraightforward implementation suffice, or may i'm wrong?
first, have this answer, (in opinion) easier understand 1 posted.
second, right: function pointers useful implement different behavior same "event pattern". called polymorphism in oop (have this wikipedia article).
so, if think it... need fsm: react in different ways same event, is: implement different function each state transition in fsm.
at first glance, "classic" switch statement enough implement this, flexibility , opportunity extend function-pointer implementation reward in long term.
Comments
Post a Comment