3 ms·
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
by themafia 1y ago
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.
- mgaunard 1y agosure, 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.
- 1718627440 1y ago> 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.