I doubt it can be done portably, but are there any solutions out there? I think it could be done by creating an alternate stack and reseting SP,BP, and IP on function entry
This is an old thread, but I would like to suggest a hack using Duff's device that is not os-dependent (as far as I remember):
C coroutines using Duff's device
And as an example, here is a telnet library I modified to use coroutines instead of fork/threads: Telnet cli library using coroutines
And since standard C prior to C99 is essentially a true subset of C++, this works well in C++ too.