Article View: comp.lang.c.moderated
Article #2299Re: Some questions on coding
From: Richard A. O'Keefe
Date: Sat, 16 Mar 1996 14:50
Date: Sat, 16 Mar 1996 14:50
51 lines
2034 bytes
2034 bytes
hrubin@stat.purdue.edu (Herman Rubin) writes:
>Question 1. Is there a quick way of using a variable label?
In GCC, yes. In standard C, no.
>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?
In standard C, you will have to use an integer variable, and
jump to a switch statement full of jumps. Use an unsigned
int, and a compact range of numbers 0, 1, ..., n. Many C
compilers will take
switch (u) {
case 0: goto L0;
...
case n: goto Ln;
}
and generate code like
load u into register
compare u with n
if u > n then goto Fall_Through
goto Branch[u]
Branch:
.word L0
...
.word Ln
Fall_Through:
more code
This is going to cost at least
- one unsigned comparison
- one untaken branch
- one load from memory
more than a Fortran-style "assigned GOTO" would.
As I said, GCC has an extension for this.
>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.
No. In standard C and GNU C, the scope of a label is the entire
function it's declared in. This _does_ mean that you can jump
into a block from the outside. Such is C.
--
The election is over, and Australia lost; the idjits elected _politicians_!
Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.
Technical Details
Message-ID:
<4iekg8$9pa@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4hqef9$1oj@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: ok@cs.rmit.edu.au (Richard A. O'Keefe) Newsgroups: comp.lang.c.moderated Subject: Re: Some questions on coding Date: 16 Mar 1996 08:50:48 -0600 Organization: Comp Sci, RMIT, Melbourne, Australia Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4iekg8$9pa@solutions.solon.com> References: <4hqef9$1oj@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Newsreader: NN version 6.5.0 #0 (NOV)