Message from discussion longjmp vs goto
From: Dan....@cern.ch (Dan Pop)
Subject: Re: longjmp vs goto
Date: 2 Feb 2004 17:54:23 GMT
Organization: DESY Zeuthen
X-Trace: sunnews.cern.ch 1075744463 21587 (None) 220.127.116.11
In <8b0c42d.0401301406.5fb0a...@posting.google.com> nimmi_srivas...@yahoo.com (Nimmi Srivastav) writes:
>Can someone kindly clarify the distinction between long jumps and
Try any good book on C.
>Why is one frowned upon and not the other?
Neither is frowned upon by the competent programmer, but goto is more
likely to be abused by the incompetent programmer.
>Is there really any situation where use of longjmp becomes inevitable?
No, but there are many situations where the use of longjmp greatly
simplifies the code structure. Imagine a program with multiple levels
of menus. Each menu must contain a "return to main menu" option. This
option can be trivially implemented with a longjmp call.
Another popular use is for error handling when the error was detected
deep in the function call chain. Instead of propagating the error back
through all the call chain, up to the function that is supposed to do
something about it, you get there with a single longjmp call.
Try to implement both examples without using longjmp and you'll see that,
although you can live without it, it's a lot more comfortable to live
DESY Zeuthen, RZ group