Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: goto's in C: an opinion... Message-ID: <6178@brl-smoke.ARPA> Date: Sun, 26-Jul-87 00:37:05 EDT Article-I.D.: brl-smok.6178 Posted: Sun Jul 26 00:37:05 1987 Date-Received: Sun, 26-Jul-87 05:35:55 EDT References: <3289@bigburd.PRC.Unisys.COM> <7571@beta.UUCP> <6603@think.UUCP> <1125@nu3b2.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB)) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 Keywords: C, goto, style In article <1125@nu3b2.UUCP> rwhite@nu3b2.UUCP (Robert C. White Jr.) writes: >In all your goto stuff I find that yhat you really want is the >setjump() longjump() construct... NO! longjmp() is for emergency use only; it suffers from several problems: (1) It's a non-local goto, which is even worse than a local goto from the standpoint of style. It is also more complex because of the implied conditional test. (2) setjmp()/longjmp() have to save and restore considerable context and usually involve run-time library function calls, so it is much less efficient than goto. (3) It is sometimes very hard to implement setjmp()/longjmp() in such a way that something doesn't get messed up at run time, usually by reentrancy from a signal handler or at least corruption of register variables. I don't recommend setjmp()/longjmp() at all, but if you need to leap out from the middle of deeply nested function invocations to the "top" of a master control loop, they are useful for that. Beware of longjmp() from a signal handler, though; no telling what corruption of data structures that may cause.