Hacker News new | ask | show | jobs
by acdha 207 days ago
Goto can be used safely but that’s really just arguing that “harmful” should instead be something like “risky”. If you have robust flow analysis and testing, you can certainly find advantages but it’s kind of like seeing someone doing mountain bike tricks on YouTube and then asking whether you should try that on your commute to work. The Linux kernel developers are in an unusual position of being both extremely performance sensitive and supported with review and testing resources compared to almost anyone else.
1 comments

As far as I can tell, gotos are essential for maintainable c-code.

In particular, having an end label in a function that handles freeing intermediate variables that may or may not have been allocated is vital for functions with multiple (logical) return points. As are fail labels where appropriate.

Appropriate use of goto is literally written into the internal C style guide where I work. This is not about performance; it is entirely about avoiding memory bugs.

Maybe this will go away when defer becomes a thing. But seeing as people still target C99, that might take a while.