4 ms·
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
by mgaunard 1y ago
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).
- themafia 1y agoYou 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.