Visualization of every goto statement in the Linux 6.17 source code.Commentary from a 2003 linux-kernel mailing list discussion about the use of goto.Created...
IIRC, this is because gcc optimizes goto very well, or at least it did back in the day. It also is a genuinely workable solution for error handling in C.
Consider if you need to setup three things, do something with them, and then tear them down in reverse order. If there’s an error on the second thing, you want to jump right to the part where you tear down the first thing. Using goto tends to make cleaner code for that in C compared to, say, nested conditionals.
IIRC, this is because gcc optimizes goto very well, or at least it did back in the day. It also is a genuinely workable solution for error handling in C.
Consider if you need to setup three things, do something with them, and then tear them down in reverse order. If there’s an error on the second thing, you want to jump right to the part where you tear down the first thing. Using goto tends to make cleaner code for that in C compared to, say, nested conditionals.