Re: How to type braces for computed gotos

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Mon, 21 Jul 2014 16:19:44 +0000 (UTC)

          From comp.compilers

Related articles
Best "simple" C Compiler I've ever seen andrewchamberss@gmail.com (2014-05-04)
How to type braces for computed gotos (was: Best "simple" C Compiler I federation2005@netzero.com (2014-07-18)
Re: How to type braces for computed gotos gah@ugcs.caltech.edu (glen herrmannsfeldt) (2014-07-19)
Re: How to type braces for computed gotos ivan@ootbcomp.com (Ivan Godard) (2014-07-18)
Re: How to type braces for computed gotos (was: Best "simple" C Compil anton@mips.complang.tuwien.ac.at (2014-07-21)
Re: How to type braces for computed gotos gah@ugcs.caltech.edu (glen herrmannsfeldt) (2014-07-21)
Re: How to type braces for computed gotos federation2005@netzero.com (2014-07-21)
Re: How to type braces for computed gotos wclodius@earthlink.net (2014-07-21)
Re: How to type braces for computed gotos gah@ugcs.caltech.edu (glen herrmannsfeldt) (2014-07-23)
Re: How to type braces for computed gotos wclodius@earthlink.net (2014-07-22)
Re: How to type braces for computed gotos anton@mips.complang.tuwien.ac.at (2014-07-25)
| List of all articles for this month |

From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Mon, 21 Jul 2014 16:19:44 +0000 (UTC)
Organization: Aioe.org NNTP Server
References: 14-05-013 14-07-033 14-07-048
Keywords: Fortran, history
Posted-Date: 21 Jul 2014 13:22:56 EDT

Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:


(snip)


> I guess this compiler implements the labels-as-values extension of GNU
> C (aka "computed goto", but see the Fortran note below).


(snip)


> BTW, in Fortran this feature is called "assigned goto", and it uses
> integer variables (i.e., not a special type, either) for storing the
> labels (and therefore needs a separate syntax "assign 50 to l" instead
> of just writing "l=50").


The ASSIGN statement and assigned GOTO trace back to the original
Fortran compiler, now often called Fortran I.


The SUBROUTINE, CALL, and FUNCTION statements came in with Fortran II.
The only subroutine call mechanism available with the Fortran I system
was to ASSIGN a statement label to return to to some variable, GOTO to
the subroutine, and then at the end of the subroutine GOTO back. While
the computed-GOTO was also available, I suspect that the efficiency
gain (both speed and code size) on a 36 bit word vacuum tube computer
available, I believe, with between 8K and 32K words of magnetic core
memory.


But ASSIGN and the corresponding GOTO were removed from the standard
as of Fortran 95. The suggested replacement is the comptued GOTO.
Presumably someone should be able to write a program to automate the
conversion.


> Fortran also has a feature called "computed goto", but that is
> closer to a C switch than a GNU C "goto *".


The computed GOTO also traces back to Fortran I. It allows one to
select a statement label based on an index between 1 and the number of
labels available. The effect when the index variable is not in range
was undefined from Fortran I through the Fortran 66 standard. Fortran
77 defined an out of range index to continue on to the following
statement.


The computed GOTO is on the obsolescence list, though as of Fortran
2008 still hasn't been removed. As indicated, it can be replaced by a
SELECT CASE construct. But a SELECT CASE with a large number of GOTO
statement has to be uglier and less readable than a computed GOTO
statement.


-- glen


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.