In C, goto
only works within the scope of the current function, which tends to localise any potential bugs. setjmp
and longjmp
are far more dangerous, being non-local, complicated and implementation-dependent. In practice however, they're too obscure and uncommon to cause many problems.
I believe that the danger of goto
in C is greatly exaggerated. Remember that the original goto
arguments took place back in the days of languages like old-fashioned BASIC, where beginners would write spaghetti code like this:
3420 IF A > 2 THEN GOTO 1430
Here Linus describes an appropriate use of goto
: http://www.kernel.org/doc/Documentation/CodingStyle (chapter 7).