4 ms·
I'm not entirely sure how common it is in modern projects, but I use it a lot. I find functions that use this kind of centralized cleanup code a lot easier to r
by rossy 10y ago
I'm not entirely sure how common it is in modern projects, but I use it a lot. I find functions that use this kind of centralized cleanup code a lot easier to read than functions that avoid 'goto' by duplicating the cleanup code or handling errors with deep nested if blocks. The Linux kernel coding style guide recommends it as well (see "Centralized exiting of functions" in https://www.kernel.org/doc/Documentation/CodingStyle https://www.kernel.org/doc/Documentation/CodingStyle)
FWIW, it seems to be the primary use of 'goto' in these projects:
https://github.com/torvalds/linux/search?q=goto https://github.com/torvalds/linux/search?q=goto
https://github.com/FFmpeg/FFmpeg/search?q=goto https://github.com/FFmpeg/FFmpeg/search?q=goto
https://github.com/antirez/redis/search?q=goto https://github.com/antirez/redis/search?q=goto