Any coding standard which insists on syntactic clarity at the expense
of algorithmic clarity should be rewritten. If your employer fires you
for using this trick, tell them that repeatedly as the security staff
drag you out of the building. hahaha 作者: vupiggy 时间: 2010-12-17 00:25 本帖最后由 vupiggy 于 2010-12-16 17:31 编辑
好吧,没有人否认这种 Coroutine 的实现有很大的局限性,但是对于一些非常特定情况,譬如说中不溜的应用,过程调用层比较深,而各个过程的内部状态又比较复杂,譬如网络协议,则个方案有一定实用性。像 putty 的需求,就不是在外部多写一个个 for 或者是 while 可以解决的了。
我没找到其它的 C 下实现 coroutine 的方案,这是 C 自身特点所限,stack based function。用汇编做栈切换当然可以完美解决,“but on the other hand it beats having to write the stack switcher separately for every different platform and compiler on which I plan to run my code. Porting is more than enough hassle as it is...”--- Simon Tatham