Saturday, 14 March 2009

Coroutines in C

this article by Simon tathan is fascinating.

Simon explains how we can use some very dirty tricks to create coroutines directly in C, without using the setcontext functions.
It relies on a very strange feature of C that I didn't know about : being able to put a case statement inside a sub-block of the matching switch statement !

I really recommend the lecture of the article to anybody interested in coroutines, even though as Simon says : "this trick violates every coding standard in the book. Try doing this in your company's code and you will probably be subject to a stern telling off if not disciplinary action!"