...Although we could've done without goto, doing so would've been much more difficult...
Which is why I never use it. Most of the time I see it being used 'lazily' to solve a problem that can be done with better code.
Goto is nasty. Those of you who know asm somewhat will already realize that there are about a trillion short jumps and maybe even hundreds of long jumps in your code already. But the whole issue comes down to the fact that C provides other more polished mechanism by which to accomplish what goto does. Goto is hard to trace, hard to debug, ugly, and violates one entry one exit. Jumping to a label in C is assinine and for those of you who blast me for assembly - you are basically adding jumps to the assembly that need not be there.
Try to put the following in asm:
Code:
switch (x)
{
case 1: DoOne();break;
case 2: DoTwo();break;
case 3: goto Assinine
}
goto SkipAssinine:
Assinine:
DoSomethingElse();
SkipAssinine:
ContinueWithProgram();
See how the goto requires you to almost use assembly language fall-through in C? Very ugly. One use of goto often requires yet another uglier use of the same.
Code:
mov eax,[x]
cmp eax,1
jne Compare2
call DoOne
jmp EndOfCompare ;only here if break is used
Compare2:
cmp eax,2
jne Compare3
call DoTwo
jmp EndOfCompare ;only if break is used
Compare3:
cmp eax,3
jne EndofCompare
jmp Assinine
Assinine:
call DoSomethingElse
;Fall through to EndOfCompare
EndOfCompare:
call ContinueWithProgram