3 ms·
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 t
by stormbrew 11y ago
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.
- mikeash 11y agoI did the clang blocks thing: https://mikeash.com/pyblog/friday-qa-2009-10-30-generators-in-objective-c.html 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.
- com2kid 11y agoIn 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. :)
- apaprocki 11y agoI'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.
- deleted 11y ago[deleted]