[sdiy] C coding
Cornutt, David K
david.k.cornutt at boeing.com
Wed Feb 4 23:10:53 CET 2004
I have to post a caveat to something I said earlier, because
if I don't you guys will call me on it. :-)
> Now the C longjmp can definitely take you out of the function,
> but that isn't the same thing and it doesn't work the same way.
> Even in the case of a longjmp, the stack should (if the compiler
> isn't broken) unwind cleanly to the point of the preceding
> setjmp.
This is only true if the longjmp call takes place in the
same function as the setjmp, or in a function that was
called by the function that called setjmp. If the function
calls setjmp and then returns, a subsequent longjmp call
is invalid because the stored stack pointer that setjmp
memorized points to a frame that isn't there any more.
(Setjmp/longjmp were put in as a klugey way of doing exception
handling early in on the language's history. Ritchie has long
since admitted that there are better ways of doing that, such
as the try/catch statements in C++ and Java.)
More information about the Synth-diy
mailing list