5 ms·
Serious question, what's the difference between this and a class?
by AndyKelley 8y ago
Serious question, what's the difference between this and a class?
- BeeOnRope 8y agoI guess when you call an entry point the second time it restores the existing context at the point of the previous yield. So you have mix of shared state (class members) and local state between the various entry point. Just a guess though.
- AndyKelley 8y agoIf the local state was accessed across a suspend point that would be undefined behavior. So it would have to be spilled into the coroutine frame. So it would be the same as a class.
- kbwt 8y agoIf you try to implement a class in C, you always end up with duplicated cleanup code between your "constructor" and your "destructor". Being able to jump from the constructor to the corresponding part of the destructor when the construction of a subobject fails would get rid of this often buggy/untested secondary code path. Some idioms have been developed over time, such as first initializing in a failsafe manner all the object's fields to a value that prevents deinitialization, but they add complexity to the code where it is not needed.