Goto Considered Harmless
bramadityaw.github.io
Goto Considered Harmless
1–10 of 13 posts
Re: Goto Considered Harmless
#2Re: Goto Considered Harmless
#3 int f()
{
foo:
return 0;
goto bar;
}
int g()
{
bar:
return 1;
goto foo;
}
int main()
{
return f();
}
It's treating both "foo" and "bar" like the equivalents of encapsulated subroutines, but the goto statements will NEVER be executed unless there's a C variant or compiler switch I'm unfamiliar with.Re: Goto Considered Harmless
#4Re: Goto Considered Harmless
#5Re: Goto Considered Harmless
#6Even though it’s not the main focus of the article, the sample code's odd structure is a bit distracting. int f() { foo: return 0; goto bar; } int g() { bar: return 1; goto foo; } int main() { return f(); } It's treating both "foo" and "bar" like the equivalents of encapsulated subroutines, but the goto statements will NEVER be executed unless there's a C variant or compiler switch I'm unfamiliar with.
Re: Goto Considered Harmless
#7Even though it’s not the main focus of the article, the sample code's odd structure is a bit distracting. int f() { foo: return 0; goto bar; } int g() { bar: return 1; goto foo; } int main() { return f(); } It's treating both "foo" and "bar" like the equivalents of encapsulated subroutines, but the goto statements will NEVER be executed unless there's a C variant or compiler switch I'm unfamiliar with.
Re: Goto Considered Harmless
#8Even though it’s not the main focus of the article, the sample code's odd structure is a bit distracting. int f() { foo: return 0; goto bar; } int g() { bar: return 1; goto foo; } int main() { return f(); } It's treating both "foo" and "bar" like the equivalents of encapsulated subroutines, but the goto statements will NEVER be executed unless there's a C variant or compiler switch I'm unfamiliar with.
Right? f runs and immediately returns 0
Re: Goto Considered Harmless
#9Goto 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 perfo…
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.
Re: Goto Considered Harmless
#10Java still allows you to continue/break to labels