Coroutines in C (2000)

Simon Tatham tackles the challenge of structuring large programs by exploring the relationship between data-producing and data-consuming code. He presents an elegant solution using Knuth’s coroutine concept to create a cooperative relationship between two functions. By leveraging a combination of the C preprocessor and switch statement, Tatham creates macros that allow for implicit state machines within functions, enabling the seamless passing of data between a producer and a consumer without extensive restructuring. While this technique may violate traditional coding standards by masking important control flow elements, Tatham argues that it enhances algorithmic clarity and should be considered in practical programming scenarios.

https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html

To top