Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.fortran

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2012, 04:26 PM
Lynn McGuire
Guest
 
Posts: n/a
Default Long Live the GOTO Statement

Long Live the GOTO Statement:
http://adamjonrichardson.com/2012/02...oto-statement/

Interesting, I was just thinking this myself as we
convert our F77 code to C++.

Lynn
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 02-07-2012, 06:01 PM
Gib Bogle
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

On 8/02/2012 6:26 a.m., Lynn McGuire wrote:
> Long Live the GOTO Statement:
> http://adamjonrichardson.com/2012/02...oto-statement/


Quoting from the article:

"Let’s look at an example of some code that’s deeply nested. We’re going
to use PHP to craft our example because PHP offers a form of the goto
statement that significantly restricts its use:

Goto targets must point somewhere within the same file and context,
so goto cannot jump out of the current function/method.
Goto targets cannot be used to jump into a control structure, so
goto cannot jump into a loop or switch statement."

Do these restrictions differ from what's always been in Fortran?
Reply With Quote
  #3 (permalink)  
Old 02-07-2012, 06:14 PM
glen herrmannsfeldt
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

Gib Bogle <g.bogle@auckland.ac.nz> wrote:

(snip)
> Goto targets must point somewhere within the same file and context,
> so goto cannot jump out of the current function/method.


> Goto targets cannot be used to jump into a control structure, so
> goto cannot jump into a loop or switch statement."


> Do these restrictions differ from what's always been in Fortran?


If you don't count "extended range of the DO", I suppose not.

In days before SUBROUTINE and FUNCTION were added, tricks using
assigned GOTO were used for subroutines.

I believe that "exteneded range of the DO" has been removed, but
I don't remember when.

-- glen
Reply With Quote
  #4 (permalink)  
Old 02-07-2012, 06:19 PM
Richard Maine
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:

> I believe that "exteneded range of the DO" has been removed, but
> I don't remember when.


F77 removed it.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
Reply With Quote
  #5 (permalink)  
Old 02-07-2012, 06:41 PM
Lynn McGuire
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

On 2/7/2012 1:01 PM, Gib Bogle wrote:
> On 8/02/2012 6:26 a.m., Lynn McGuire wrote:
>> Long Live the GOTO Statement:
>> http://adamjonrichardson.com/2012/02...oto-statement/

>
> Quoting from the article:
>
> "Let’s look at an example of some code that’s deeply nested. We’re going to use PHP to craft our example because PHP offers a form of
> the goto statement that significantly restricts its use:
>
> Goto targets must point somewhere within the same file and context, so goto cannot jump out of the current function/method.
> Goto targets cannot be used to jump into a control structure, so goto cannot jump into a loop or switch statement."
>
> Do these restrictions differ from what's always been in Fortran?


Fortran 66 and before could jump anywhere, including
control structures but fortran 77 put a stop to that
nasty practice.

Lynn

Reply With Quote
  #6 (permalink)  
Old 02-07-2012, 07:02 PM
timprince
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

On 2/7/2012 2:19 PM, Richard Maine wrote:
> glen herrmannsfeldt<gah@ugcs.caltech.edu> wrote:
>
>> I believe that "exteneded range of the DO" has been removed, but
>> I don't remember when.

>
> F77 removed it.
>

But there was no requirement for a facility to warn you about it until
f90, and this involves setting a standards checking option on many
compilers. It could be very difficult for a compiler to distinguish
something which fit a pre-f77 extended DO range from an outright mistake.

--
Tim Prince
Reply With Quote
  #7 (permalink)  
Old 02-07-2012, 07:02 PM
timprince
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

On 2/7/2012 2:19 PM, Richard Maine wrote:
> glen herrmannsfeldt<gah@ugcs.caltech.edu> wrote:
>
>> I believe that "exteneded range of the DO" has been removed, but
>> I don't remember when.

>
> F77 removed it.
>

But there was no requirement for a facility to warn you about it until
f90, and this involves setting a standards checking option on many
compilers. It could be very difficult for a compiler to distinguish
something which fit a pre-f77 extended DO range from an outright mistake.

--
Tim Prince
Reply With Quote
  #8 (permalink)  
Old 02-07-2012, 07:03 PM
timprince
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

On 2/7/2012 2:19 PM, Richard Maine wrote:
> glen herrmannsfeldt<gah@ugcs.caltech.edu> wrote:
>
>> I believe that "exteneded range of the DO" has been removed, but
>> I don't remember when.

>
> F77 removed it.
>

But there was no requirement for a facility to warn you about it until
f90, and this involves setting a standards checking option on many
compilers. It could be very difficult for a compiler to distinguish
something which fit a pre-f77 extended DO range from an outright mistake.

--
Tim Prince
Reply With Quote
  #9 (permalink)  
Old 02-07-2012, 07:12 PM
Richard Maine
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

Lynn McGuire <lmc@winsim.com> wrote:

> Fortran 66 and before could jump anywhere, including
> control structures but fortran 77 put a stop to that
> nasty practice.


Well, f66 didn't have any "control structures" other than the DO loop.
While jumps into a DO loop were allowed in some cases, they were pretty
restricted cases. That was the "extended range of a DO loop", which Glen
alluded to. You could not just willy-nilly jump into any old DO loop.

Whether compilers would catch the error would be a different question. I
recall on occasion fixing code where someone had invalidly jumped into a
DO loop in ways that did not have anything to do with the extended range
of a DO. Sometimes the code even happened to work the way that was
intended when run on the compiler it was developed on, but that was more
a matter of particular compiler behavior than of being part of the
language. Other times, the code was just plain broken, but testing (if
any at all beyond the level of "it ran and printed results":-() had not
uncovered the error.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
Reply With Quote
  #10 (permalink)  
Old 02-07-2012, 07:24 PM
Richard Maine
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

timprince <tprince@computer.org> wrote:

> On 2/7/2012 2:19 PM, Richard Maine wrote:
> > glen herrmannsfeldt<gah@ugcs.caltech.edu> wrote:
> >
> >> I believe that "exteneded range of the DO" has been removed, but
> >> I don't remember when.

> >
> > F77 removed it.
> >

> But there was no requirement for a facility to warn you about it until
> f90, and this involves setting a standards checking option on many
> compilers. It could be very difficult for a compiler to distinguish
> something which fit a pre-f77 extended DO range from an outright mistake.


Yep. Prior to f90, there was no requirement for a compiler to warn you
about *ANYTHING*. All a compiler had to do was be able to run
standard-conforming programs. And well, not necessarily even all of
those. (Yes, there is a list of reasons why a compiler can be standard
conforming and still refuse to run some standard conforming programs;
for example, there can be compiler limits on size and complexity.) If
your program was nonstandard in any way, or even if your program was
standard conforming, but fell under one of the loopholes, you were
completely at the mercy of the compiler developer as to what happened.
That was a quality of implementation issue.

And yes, I understand the difficulty of compiler diagnosis of the
validity. Heck, it wouldn't be hard at all to come up with an example
where the validity depended on run-time input data.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
Reply With Quote
  #11 (permalink)  
Old 02-07-2012, 07:33 PM
glen herrmannsfeldt
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

Richard Maine <nospam@see.signature> wrote:
> Lynn McGuire <lmc@winsim.com> wrote:


>> Fortran 66 and before could jump anywhere, including
>> control structures but fortran 77 put a stop to that
>> nasty practice.


(snip on Extended range of the DO)

> Whether compilers would catch the error would be a different
> question. I recall on occasion fixing code where someone had
> invalidly jumped into a DO loop in ways that did not have
> anything to do with the extended range of a DO.


The need to support Extended range of the DO likely restricts
some optimizations that compilers might otherwise make, and
that would cause problems. It also makes it harder for
compilers to test for the illegal cases.

> Sometimes the code even happened to work the way that was
> intended when run on the compiler it was developed on, but
> that was more a matter of particular compiler behavior than
> of being part of the language.


One I remember from many years ago was an FFT routine that
used nested DO loops to do the bit-reversed path through
the arrays. They put in enough DO loops for the largest
case needed, a GOTO into the appropriate loop, and GOTO out
before the end of the loop. The latter being important
in many cases. (Though no less illegal.)

> Other times, the code was just plain broken, but testing (if
> any at all beyond the level of "it ran and printed results":-()
> had not uncovered the error.


-- glen
Reply With Quote
  #12 (permalink)  
Old 02-07-2012, 09:28 PM
Phillip Helbig---undress to reply
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

In article <1kf3gny.159wdcv1gl3ggN%nospam@see.signature>,
nospam@see.signature (Richard Maine) writes:

> Yes, there is a list of reasons why a compiler can be standard
> conforming and still refuse to run some standard conforming programs;
> for example, there can be compiler limits on size and complexity.


I once wrote a standard-conforming compiler on VMS entirely in DCL:

$ WRITE SYS$OUTPUT "Program too complex for processor"
$ EXIT

I even ported it to unix:

echo "Program too complex for processor"

The quality of implementation is pretty low, though.

Reply With Quote
  #13 (permalink)  
Old 02-07-2012, 09:51 PM
Keith Refson
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

On 07/02/12 22:28, Phillip Helbig---undress to reply wrote:

> I once wrote a standard-conforming compiler on VMS entirely in DCL:
>
> $ WRITE SYS$OUTPUT "Program too complex for processor"
> $ EXIT


And some surviving major vendors still follow exactly the same approach.....

Keith Refson
Reply With Quote
  #14 (permalink)  
Old 02-07-2012, 11:27 PM
Richard Maine
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

Phillip Helbig---undress to reply <helbig@astro.multiCLOTHESvax.de>
wrote:

> In article <1kf3gny.159wdcv1gl3ggN%nospam@see.signature>,
> nospam@see.signature (Richard Maine) writes:
>
> > Yes, there is a list of reasons why a compiler can be standard
> > conforming and still refuse to run some standard conforming programs;
> > for example, there can be compiler limits on size and complexity.

>
> I once wrote a standard-conforming compiler on VMS entirely in DCL:
>
> $ WRITE SYS$OUTPUT "Program too complex for processor"
> $ EXIT
>
> I even ported it to unix:
>
> echo "Program too complex for processor"
>
> The quality of implementation is pretty low, though.


That's a bit of overkill for an f77 compiler, as it isn't required to
tell the user that the complexity is the reason for failure. Seems to me
that you could have omitted the WRITE command and still had a standard
conforming f77 compiler, albeit a little lower still on that quality of
implementation curve. For f90, you do have had to have the diagnostic.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
Reply With Quote
  #15 (permalink)  
Old 02-08-2012, 01:56 AM
Dick Hendrickson
Guest
 
Posts: n/a
Default Re: Long Live the GOTO Statement

On 2/7/12 2:24 PM, Richard Maine wrote:
> timprince<tprince@computer.org> wrote:
>
>> On 2/7/2012 2:19 PM, Richard Maine wrote:
>>> glen herrmannsfeldt<gah@ugcs.caltech.edu> wrote:
>>>
>>>> I believe that "exteneded range of the DO" has been removed, but
>>>> I don't remember when.
>>>
>>> F77 removed it.
>>>

>> But there was no requirement for a facility to warn you about it until
>> f90, and this involves setting a standards checking option on many
>> compilers. It could be very difficult for a compiler to distinguish
>> something which fit a pre-f77 extended DO range from an outright mistake.

>
> Yep. Prior to f90, there was no requirement for a compiler to warn you
> about *ANYTHING*.


For any compiler that still supports the ASSIGNed GOTO statement (e. g.
all F90 compilers), there is no requirement to diagnose all jumps into
DO loops. I think something like
assign 50 to joe
...
DO 10 ...
...
if (whatever) assign 10 to joe
...
go to joe
...
10 continue
...
50 read *, test
if (test) assign 20 to joe
go to joe
...
20 continue

is perfectly standard conforming at "compile time". It imposes user
requirements on the run-time values of "whatever" and "test"; but
nothing on the compiler.

F2003 says "Transfer of control to the interior of a block from outside
the block is prohibited", but I don't think there are prohibitions on
statements like GOTO 10 from appearing outside of a DO loop like the
above, the prohibitions are that the statements can't be executed and
that's a user, not compiler, restriction.

Dick Hendrickson

All a compiler had to do was be able to run
> standard-conforming programs. And well, not necessarily even all of
> those. (Yes, there is a list of reasons why a compiler can be standard
> conforming and still refuse to run some standard conforming programs;
> for example, there can be compiler limits on size and complexity.) If
> your program was nonstandard in any way, or even if your program was
> standard conforming, but fell under one of the loopholes, you were
> completely at the mercy of the compiler developer as to what happened.
> That was a quality of implementation issue.
>
> And yes, I understand the difficulty of compiler diagnosis of the
> validity. Heck, it wouldn't be hard at all to come up with an example
> where the validity depended on run-time input data.
>


Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 05:14 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.