3 ms·
On the contrary. Many passes in a compiler are simpler if the control-flow graph is reducible [1], which it is guaranteed to be if the program had been written
by Findecanor 3y ago
On the contrary. Many passes in a compiler are simpler if the control-flow graph is reducible [1], which it is guaranteed to be if the program had been written in structured programming without any gotos.
It is just that "goto" is closer to assembly code, and therefore used in intermediary code representations inside the compiler for that reason. But if the compiler had made sure beforehand that the control flow is reducible (and don't break that in an intermediary pass), then it will remain so.
I find that most uses of gotos in source code are still reducible control-flow, but which had just not been expressible using structured programming constructs in the language. For example jumping out of nested loops, "for-else" and error handling.
It is very rare that you see "spaghetti code" in practice.
1: https://en.wikipedia.org/wiki/Control-flow_graph#Reducibility https://en.wikipedia.org/wiki/Control-flow_graph#Reducibilit...