Ideally, in a real application, you would want to be able to call the same function in several different contexts, and at each call in a given context, have control resume just after the last return in the same context. This is easily enough done. But it removes the problems with re-entrancy, and still hasn't impacted the structure of the routine. Included here is a C header file that implements this coroutine trick as a set of pre-defined macros. There are two sets of macros defined in the file, prefixed scr and ccr .
Full documentation is given in a comment in the header file itself.
Follow this link for coroutine.h . Thanks for reading. References Donald Knuth, The Art of Computer Programming , Volume 1. Note, right at the bottom, a hint that Duff might also have independently invented this coroutine trick or something very like it. PuTTY is a Win32 Telnet and SSH client.