5 ms·
This is one of those problems that Tail Call Elimination cleanly addresses. The "obvious" approach to writing an FSM does exactly what you'd expect.
by rmckayfleming 4y ago
This is one of those problems that Tail Call Elimination cleanly addresses. The "obvious" approach to writing an FSM does exactly what you'd expect.
- hgsgm 4y agoC does not guarantee tail call elimination. But you can do the same with an event loop that cleanly avoids goto.
- IncRnd 4y agoNowadays you can direct clang to require tail-call elimination in C. [1] In gcc you can provide the optimization flag, -foptimize-sibling-calls, which is automatically selected at -O2, -O3, or -Os. [2] [1] https://clang.llvm.org/docs/AttributeReference.html#musttail https://clang.llvm.org/docs/AttributeReference.html#musttail [2] https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
- DonHopkins 4y agoGotos are great approach for writing a Flying Spaghetti Monster!
- dcow 4y agoNot if you don't know how to write in only tail calls. Try explaining tail call elimination to one of these programmers learning how to write a state machine (=