Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion longjmp vs goto

Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nnx.oleane.net!oleane!in2p3.fr!irazu.switch.ch!switch.ch!cern.ch!news
From: Dan....@cern.ch (Dan Pop)
Newsgroups: comp.lang.c,comp.sources.d
Subject: Re: longjmp vs goto
Date: 2 Feb 2004 17:54:23 GMT
Organization: DESY Zeuthen
Lines: 33
Message-ID: <bvm2sf$l2j$3@sunnews.cern.ch>
References: <8b0c42d.0401301406.5fb0ac79@posting.google.com>
NNTP-Posting-Host: lxplus086.cern.ch
X-Trace: sunnews.cern.ch 1075744463 21587 (None) 137.138.4.111
X-Complaints-To: news@sunnews.cern.ch
User-Agent: nn/6.6.2

In <8b0c42d.0401301406.5fb0a...@posting.google.com> nimmi_srivas...@yahoo.com (Nimmi Srivastav) writes:

>Can someone kindly clarify the distinction between long jumps and
>gotos? 

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 
with it.

Dan
-- 
Dan Pop
DESY Zeuthen, RZ group
Email: Dan....@ifh.de