3 ms·
GOTO should be used when it makes the code less repetitive, easier to follow, and less error prone. One alternative is to encapsulate the state of various resou
by kstenerud 14y ago
GOTO should be used when it makes the code less repetitive, easier to follow, and less error prone. One alternative is to encapsulate the state of various resource allocations, and then call a single cleanup function at every exit point from the function that uses those resources (or take advantage of RAII, if supported by the language). However, in C this is cumbersome at best, and error prone at worst. Using GOTO for a common cleanup point is a perfectly valid use of the keyword.