Comment by knome
14 days ago
https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
'computed goto' is used in gcc to mean the same as assigned goto in Fortran. The Fortran variation appears to have more restrictions than the gnuc one.
14 days ago
https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
'computed goto' is used in gcc to mean the same as assigned goto in Fortran. The Fortran variation appears to have more restrictions than the gnuc one.
I may be dumb, but what is "goto *ptr;" useful for? Or &&foo.
It's used in VMs, emulators, and other interpreters for making a dispatch loop with less branching than a standard loop with a switch inside it.
https://eli.thegreenplace.net/2012/07/12/computed-goto-for-e...
No, it has the same number of branches as a switch inside. The only difference is that computed goto switches miss the initial range check. And proper switch implementations by a better compiler would be more optimizable. But we are waiting more than 20 years for that already. Sparse switch dispatch tables are also compiled horribly.
1 reply →
error conditions when you don't have exceptions:
is a pretty normal one. This basically allows you to emulate a "finally".
State machines are another big one, which look much nicer with computed goto than a switch statement.