News for hackers. Stuff that matters.
Re:Coroutines in C (2000) by stormbrew on Saturday February 06, 2016 @11:29PM (#11051604)
Some extra fun (and obscene) things along this line:

- Use __LINE__ to make it so you don't have to manually specify the continuation number (with the caveat that you can't have more than one on a line).

- Use computed goto and labels rather than a switch and you can make it work even inside a switch (&&label to take the address, goto *addr to goto). This is a gcc extension.

- Use clang blocks to save state and return the block for continuation, saving you from needing to use static functions. Perhaps you could also use C++ lambdas along the same line, but I'm not sure if they mix well with the &&label thing.

Re:Coroutines in C (2000) by mikeash on Sunday February 07, 2016 @12:02AM (#11051704)
I did the clang blocks thing:

https://mikeash.com/pyblog/friday-qa-2009-10-30-generators-i...

I think it turned out pretty well, but I never used it in real code. The ability to avoid global state is great, anyway.

Re:Coroutines in C (2000) by com2kid on Sunday February 07, 2016 @12:39AM (#11051784)
In embedded land, you can just make something that works like setjmp and memcopy the stack off to someplace convenient.

Super useful if you want something resembling modern programming in an embedded context. It is a bit better than callback hell, but you do end up using memory for all those saved off stacks, so that limits how many co-routines can be in play at once. Thankfully embedded projects tend to have small stacks. :)

Re:Coroutines in C (2000) by apaprocki on Sunday February 07, 2016 @01:45AM (#11051960)
I'm pretty sure the code in the article could use __COUNTER__ followed by __COUNTER__-1 in the macro to avoid the __LINE__ collision and allow more than one yield on the same line.