DEV Community

Discussion on: Is goto all that bad?

Collapse
 
bleakview profile image
Mustafa Unal

The others mention the logical control problems which were first addressed by Dijkstra in 1968 but there is a more sinister problem with goto. Modern CPU's heavily relies on caching for performance improvement. When you use goto you may simply invalidate caches so CPU has to read all data from lower layers of memory which may cause CPU stall. And also you might cause a stack unwinding error which may corrupt memory. But in Linux kernel there are goto's so what is the logic here ? Goto is one is seemingly simple but a very advanced command which is very hard to master. You not only must know how your code is executed on the CPU but where your code and data is in memory system and what is the status of the stack while your goto is executed. Thats why although it's not recommended to use goto no one is removing them from the language. It's a powerful tool which must be used wisely.