🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2254

Re: Some questions on coding

#2254
From: S. Lee
Date: Tue, 12 Mar 1996 02:49
44 lines
1893 bytes
In article <4hv065$jao@solutions.solon.com>,
Konrad Schwarz <schwarz@a2.complang.tuwien.ac.at> wrote:
 >In article <4hqef9$1oj@solutions.solon.com>, hrubin@stat.purdue.edu (Herman Rubin) writes:
 >|> Question 1.  Is there a quick way of using a variable label?
 >|> The way it would be used is to identify the label to which one
 >|> wants to transfer, and then have some other place or places 
 >|> transfer to that point?  Transfers, loads, and stores take a
 >|> significant part of the running time of the algorithm, and
 >|> so something like setjmp and longjmp are to be avoided.
 >
 >An approach in ANSI C: use a giant switch statement inside of an endless loop
 >and program something similar to a finite-state machine.  Map labels to
 >integers, use a integer variable as the controlling expression of the switch
 >statement, and when you want to use a goto, assign the number of the
 >appropriate label to the integer variable and jump to the switch statement.
 >
 >For example:
 >
 >	register label = 0;
 >dispatch: switch (label) {
 >	case 10:
 >		do_something;
 >		label = 12;
 >		goto dispatch;
 >	...
 >	}
 >	
 >The disadvantage is that twice as many jumps are performed.

Which might be easier coded as

int label = 0;
while (1) {
    switch (label) {
    case 10:
	do_something();
	label = 12;
	continue;
    ...
    }
}

sl14@cornell.edu
Witty .sig under construction.
Technical Details
Message-ID: <4i2oof$9lg@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4hqef9$1oj@solutions.solon.com> <4hv065$jao@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: sl14@crux3.cit.cornell.edu (S. Lee)
Newsgroups: comp.lang.c.moderated
Subject: Re: Some questions on coding
Date: 11 Mar 1996 20:49:51 -0600
Organization: Nekomi Institute of Technology
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4i2oof$9lg@solutions.solon.com>
References: <4hqef9$1oj@solutions.solon.com> <4hv065$jao@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com