🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Some questions on coding

#2246
From: Andrew Snyder
Date: Tue, 12 Mar 1996 01:29
60 lines
2362 bytes
hrubin@stat.purdue.edu (Herman Rubin) wrote:

>Two questions have arisen.  Both of these are in connection with
>statement labels and gotos, which I know will irritate many; these
>questions are raised in connection with certain types of programs
>in which the use of goto-less code must be less efficient.

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

>Question 2.  Is there a way of declaring "local", so that
>labels in one block of a coding unit can be the same as
>labels in another?  The labels are within the block only,
>but the various blocks are connected with gotos, not calls.

>-- 
>Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399
>hrubin@stat.purdue.edu	 Phone: (317)494-6054	FAX: (317)494-0558
I've worked with code that looks like what you are proposing, and it
was just too ugly to bother with. 


Imagine code like this:

/* somewhere in the code */
comfrom = label1;
goto MESS;
LABEL1:
...
/* somewhere else in the code */
comfrom = label2;
goto MESS;
LABEL2:
...
/* elsewhere in the code */
MESS:
/* stuff */
if (comefrom == label1)
   goto LABEL1;
if (comefrom == label2)
   goto LABEL2;
...


I rewrote this code, which admitely had other problems too, in a 4gl
using subroutines and still got an order of magnitude improvement in
speed.  And it was _much_ easier to read.

I recomend rethinking your aproach before you start hand coding
assembly in C.



Andrew Snyder
a1s@ix.netcom.com
char disclaimer[] = {'\0'}; /* I'm on cash net */
Technical Details
Message-ID: <4i2k2e$8lf@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4hqef9$1oj@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: a1s@ix.netcom.com (Andrew Snyder)
Newsgroups: comp.lang.c.moderated
Subject: Re: Some questions on coding
Date: 11 Mar 1996 19:29:50 -0600
Organization: Netcom
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4i2k2e$8lf@solutions.solon.com>
References: <4hqef9$1oj@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-NETCOM-Date: Mon Mar 11 10:03:08 AM CST 1996
X-Newsreader: Forte Free Agent 1.0.82