Skip to content

Usage of 'goto' #205

Answered by mtijanic
ApplePie420 asked this question in Q&A
May 16, 2022 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Thank you for the interest in our codebase.

goto is a tool of the language like any other. Knives are sharper than forks, so you ought to be more careful when using them, but you're gonna have a bad time eliminating all knife use when making food, even if technically doable.

Generally the goto cleanup; idiom is used a lot in C code, as it is the safest way to ensure all cleanup is performed on every function exit path. It's not just a matter of minimizing duplicated lines either. When adding the cleanup calls (s_unmap_kernel_space() in your example) directly before every return, you have two common failure modes:

  • You added a new return path, but forgot to perform all cleanup
  • You added a …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@ApplePie420
Comment options

@mtijanic
Comment options

@ApplePie420
Comment options

@Evernow
Comment options

Answer selected by mtijanic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants