Coroutines in C (2000)

Coroutines in C (2000)

If you rewrite the decompressor in the form shown, so that it returns one character every time it’s called, then the original parser code can replace calls to with calls to , and the program will be happy. Languages like C depend utterly on their stack-based structure, so whenever control passes from any function to any other, one must be the caller and the other must be the callee. A function built of small blocks of the form

is not very different, to a reader, from a function built of small blocks of the form

One is caller and the other is callee, true, but the visual structure of the functions are the same, and the insights they provide into their underlying algorithms are exactly as small as each other.

Source: www.chiark.greenend.org.uk