Re:Windows File System Proxy – FUSE-Like Capability for Windows
by jessedhillon on Thursday July 21, 2016 @02:31AM
(#12135136)
I'm wondering what the rationale is for the usage of `goto` in the C source? It looks like it's exclusively used to implement a pattern of exiting or failing early and in a common way. Is this something that's common in modern C?
[ Parent
| on HN ]
Re:Windows File System Proxy – FUSE-Like Capability for Windows
by rossy on Thursday July 21, 2016 @02:49AM
(#12135206)
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)
FWIW, it seems to be the primary use of 'goto' in these projects: https://github.com/torvalds/linux/search?q=goto https://github.com/FFmpeg/FFmpeg/search?q=goto https://github.com/antirez/redis/search?q=goto
Re:Windows File System Proxy – FUSE-Like Capability for Windows
by saynsedit on Thursday July 21, 2016 @02:40AM
(#12135172)
Yes, goto exit and cleanup resources on error is a common and not frowned upon idiom in C. See Python source.
Re:Windows File System Proxy – FUSE-Like Capability for Windows
by creshal on Thursday July 21, 2016 @03:17AM
(#12135286)
Or the Linux kernel.
(Or Apple's "goto fail" bug for a somewhat infamous example how to not use it.)
Re:Windows File System Proxy – FUSE-Like Capability for Windows
by krylon on Thursday July 21, 2016 @06:56AM
(#12136007)
> Or Apple's "goto fail" bug for a somewhat infamous example how to not use it.
But that problem was not because of the goto, strictly speaking.
Re:Windows File System Proxy – FUSE-Like Capability for Windows
by mhogomchungu on Thursday July 21, 2016 @08:22AM
(#12136329)
I dont use "goto" in C but a specialized static function that does more or less the same thing. Example is the zuluExit "goto" function: https://github.com/mhogomchungu/zuluCrypt/blob/master/zuluCr...
Re:Windows File System Proxy – FUSE-Like Capability for Windows
by ryan-c on Thursday July 21, 2016 @11:13AM
(#12137385)
I don't think that solution works well in general. If you want to do cleanup of local variables, I don't see how you'd do that with a static function unless you're using globals everywhere, some awful god object, or terrible varargs hacks.