Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can use goto to jump to one of several exit conditions based on the level of cleanup you need. It also nicely unifies all error exits into one place. The kernel makes heavy use of this style.


sure, but that has limitations as well, since gotos can't cross lexical scopes, so you can't introduce variables later on, and it's easy to mess up.

Destructors are a higher-level and safer approach.


> since gotos can't cross lexical scopes, so you can't introduce variables later on

That's a C++ specific limitation, it works just fine in C.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: