2 ms·
Not every use of goto is a sin, at least according to Linus. How would you write it without goto? Duplicate the code at the bottom, then return? Abstract wha
by retrac 5y ago
Not every use of goto is a sin, at least according to Linus.
How would you write it without goto? Duplicate the code at the bottom, then return? Abstract what is clearly part of that function, into a new function, pass acct to it, call it twice? Neither seems much better to me. And both lead to multiple return statements in the function, which is also considered poor style by some.
Goto common code at the end of a function, such as error handling or clean-up, is idiomatic C. Often where you'd use an exception or conditional execution, in another language. I mostly avoid it myself. Outside of that use, it's probably most common in the drivers as a way to simply implement a state machine.