4 ms·
It's also important to realize that the "go to" Dijkstra is complaining about isn't seen in modern languages. It's the goto of unstructured Basic and early For
by bcoates 14y ago
It's also important to realize that the "go to" Dijkstra is complaining about isn't seen in modern languages. It's the goto of unstructured Basic and early Fortran where you're doing an unconstrained jump to some other part of the program source by line number. It has no real counterpart in C. Unless your entire program is one long main() function, forward and even backwards C goto within a function is a tamed HLL version that can be reasoned about.
- unwind 14y agoIt is possible to reason about the effects of a goto into the middle of a for loop (or switch case), of course, but doing so is likely to make you angry. :) I believe those are reason enough to avoid doing those particular things, even if the global jumping of assembly of course is even worse.
- nitrogen 14y agoOf course, this is the part where someone mentions Duff's Device, which uses a do..while spanning multiple switch labels. This is possible because switch works a lot like goto. http://en.wikipedia.org/wiki/Duffs_device http://en.wikipedia.org/wiki/Duffs_device
- pi18n 14y agoI agree in the general case but there are many cases where a goto statement is actually more readable than the alternatives in C. Especially if you choose descriptive labels.
- jacques_chester 14y agoLabelled goto statements were around as early as ALGOL-60.
- heja2009 14y agoHowever, an unconstrained goto in C can be realized via the setjmp() longjump() library functions.