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

That means you cannot use early exit, and all your variables must be checked as to whether they were initialized (which on top of the checks might also require further state).


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: