The more general POV is that "setjmp" defines a continuation and "longjmp" invokes it.
While the most frequent use of explicit continuations is for implementing exceptions, you are right that there are many other programming techniques based on explicit continuations.
I'm now wondering if anyone has written an actual continuation library in C (ie saving and restoring the whole stack). Is it possible?
yes and yes.
Coroutines are one good example.
Re:Let's write a setjmp
by someweirdperson on Sunday February 12, 2023 @05:35AM
(#34761749)
> They can be used for many other things.
The underlying primitive offers even more flexibility, but exceptions (in the sense of programming languages) can also be used for many other things than exceptions (in the sense of natural language, to handle exceptional cases).
>"... but exceptions (in the sense of programming languages) can also be used for many other things than exceptions ..."
Can you elaborate? What are the other ways exceptions are used when not used to handle exceptional situations?
Correct, but reductive.
They can be used for many other things.