|
|
|
|
|
by SlowRobotAhead
2213 days ago
|
|
> It’s like a goto statement, but it can even be used to jump outside of a function. It’s also a lot more difficult to read than a goto, since it looks like a regular function call. Ah! Blood pressure rising! > Like with goto, the common advice is to avoid Whew. And then goes on to make a really good case for complicated task perform with simple error handling. It’s a good application for not exactly general use cooperative routines but a specific use case of performing multiple procedural steps. I think there it falls short and where an RTOS/OS will be more useful is when you have to wait on one of those steps. I think that’s the harder example with the example of an HTTP request is waiting for the response and keeping that context ready and blocking in a separate thread. That ends up being easy to read and maintainable. But I suppose there is no reason you can’t do both. |
|
Because the pattern that emerges with setjmp/longjmp is pretty similar, and that's the most common use: to simulate what other languages offer with exceptions. The most prominent libraries I can think of that force you to do this are image related, libpng and libjpeg both use longjmp to handle errors [though IIRC it's optional in the latter].