I think you are in THE case where the computed GOTO is neat, clear
and efficient. Nobody seems to admit it.
BTW, I did program with computed GOTOs a couple of times, in the
distant past. It was always in situations of a SELECT CASE construct,
so I had to program like :
go to (101,102,103,104,105,106,107,108,109,110), index
110 stuff
...
goto 200
109 more stuff
...
goto 200
108 and so on
...
....
200 continue
Nowadays, I would use a bunch of IF THEN ELSE, one of the many
ways you could arrange them.
Have you thought of this one, which is the most efficient if
index=1 is the most frequent :
if ( index > 1 ) then
if ( index > 2 ) then
... and so on
if ( index > 9 ) then
stuff ! for case 10
endif
stuff ! for case 9
...
endif
stuff ! for case 1
I admit it´s ugly, even with indentation.
Last suggestion : Keep using a Computed GOTO!
In Fortran 2003, it is still obsolescent, but it has not been
transfered to the ¨deleted¨ section yet.
Bertrand Meltz
Commissariat a l´Energie Atomique | e-mail : [log in to unmask]
CEA / DIF , BP 12 | Tel : (33) [0] 1 69 26 57 83
91680 Bruyeres-le-Chatel , FRANCE | Fax : (33) [0] 1 69 26 70 93
Anthony Stone wrote:
> I have a program in which I use the structure
>
> go to (101,102,103,104,105,106,107,108,109,110), index
> 110 stuff
> ...
> 109 more stuff
> ...
> 108 and so on
> ...
> ....
>
>
> The computed GOTO used here is an obsolescent feature, but there
> doesn't seem to be an obvious replacement. A CASE construct isn't
> suitable, because there is no jump out at the end of each block --
> execution falls through to the next block, as in C, so if (say)
> index=9, the blocks of code labelled 108, 107 etc are to be executed
> as well as the block labelled 109. Each block is quite large, so
> repeating them is not sensible. I could get the same result using the
> code
>
> select case (index)
> case(10)
> goto 110
> case(9)
> goto 109
> ....
> end select
>
> but that is horribly clumsy. Arranging the blocks in the reverse order
> and testing index after each one is a bit better but still relatively
> clumsy.
>
> Is there a neat way to do what I want without using the computed GOTO?
> Could it be that (horrors) the computed GOTO has some uses after all?
>
> --
> Anthony Stone http://www-stone.ch.cam.ac.uk/
> University Chemical Laboratory, Email: [log in to unmask]
> Lensfield Road, Phone: +44 1223 336375
> Cambridge CB2 1EW Fax: +44 1223 336362
>
|