3 ms·
I see setjmp/longjmp used a lot in recursive descent parsers in C. I think people got tired of using up their return values for error codes. And it is more ef
by chubot 10y ago
I see setjmp/longjmp used a lot in recursive descent parsers in C.
I think people got tired of using up their return values for error codes. And it is more efficient to use this style certainly than manually breaking out of each stack frame.
C is full of things like this which break abstractions -- it doesn't seem particularly odd to me. Though I do remember that it was one of the things at the end of C books that I didn't understand for a long time.
What's the downside?
It doesn't play well with C++ because destructors have to be run at the end of every scope, but that doesn't apply to C.
And I guess because it mutates globals, it is a bit confusing in a threaded context.
- gpderetta 10y ago> And I guess because it mutates globals, it is a bit confusing in a threaded context. What globals?
- chubot 10y agoMy understanding is it works a bit like errno. errno is global that is set by the callee and then the caller can check it whenever, not necessarily right after the call or in the same function. But it's actually a thread-local, so it works fine in a threaded context, but is just a little odd to look at.