You must have learned the yield in python before.Let’s say, we have the following code in python
1 | def traverse(max): |
The code above will print the 0,1,2,3,4,5
Of course the is the grammar sugar in python, the hack is coming—— how can we implement the code in C language?
Hack Begin
Considering jump, the first thing pop out from our mind is notorious goto isntruction. Regardless of the simplicity, we can introduce the goto to our first version of coroutine.
1 | int function() { |
Yet the goto is so ugly, let’s refract it with switch(in a way you have never seen before)
1 | int function() { |
Using line to universify it:
1 | int function(void) { |
The next step is the most important one
1 |
|
Now, I would like to introduce a new continuation implementation based on the spark above, you can checkout at the