Hacker News new | ask | show | jobs
by wcummings 4209 days ago
And C doesn't have exceptions, which otherwise would cover a lot of where goto's are used.
2 comments

There is a difference though. Exceptions can result in Stack Unwinding which is costly. Gotos are a jump which costs literally nothing.
In practice you will do the same thing as unwinding the stack. You'll jump to the end of a function where you'll likely free some heap buffers on your way out and you'll return error status to the caller. What will likely happen next is the caller will bubble up the error: free buffers and report error status to their caller. It works out to pretty much the same thing as a modern C++ code base using RAII, just more manual.
It does have longjmp, which can do basically the same, just without safety (surprise!)