[comp.lang.fortran] Zero vs. One trip loops ... correction

mwolfe@ogccse.ogc.edu (Michael Wolfe) (09/01/89)

for future reference, the real Fortran-66 standard did specify that all
loops would 'trip' at least once.  It also specified that the loop upper
limit MUST BE GREATER THAN OR EQUAL TO the loop lower limit.  Thus, the
loop:
    N = 0
    DO 10 I = 1,N
10  CONTINUE
which trips zero times in Fortran-77, is NOT 'STANDARD-CONFORMING' according
to Fortran-66.  So, Fortran-77 did not break 'one-trip' loops, it only
defined what to do when the upper limit was less than the lower limit.

Fortran-66 did define different semantics for loop iteration processing,
and most (or for all I know, all) Fortran-66 implementations would allow
the above loop and would trip once.  So the implementations were
incompatible, but the standards weren't.

Just goes to show how few people read the -66 standard.

It's also interesting to see how small the -66 standard is, compared to the -77.

bam@bnlux0.bnl.gov (Bruce Martin) (09/08/89)

In article <4513@ogccse.ogc.edu> mwolfe@cse.ogc.edu (Michael Wolfe) writes:
>
>for future reference, the real Fortran-66 standard did specify that all
>loops would 'trip' at least once.  

Not quite.  There was no explict requirement that processors execute all loops
at least once.  The language disallows it, but the processor is unconstrained.

Altho your further comments clarify the point that a Fortran-66 program could
not contain a "zero-trip" loop, the lead statement could mislead others into 
propagating the myth that Fortran-77 somehow invalidated Fortran-66 programs in
this regard.  (None of the 24 conflicts between 66 and 77 involved trip count.)

Since X3.9-1966 made it impossible for a zero-trip loop to be *written*
(in a standard-conforming program), X3J3 was literally prohibited (by ANSI 
rules) from saying anything in the standard about the behavior of a processor 
when confronted with such a non-conforming statement.  In a language 
standard, the omission of a capability has exactly the same meaning as a rule 
making it illegal -- in either case, the behavior is "processor-dependent", 
["Error" detection might or might not be involved.  One vendor's error is 
another's extension -- and yet another's differently-interpreted feature.]


>and most (or for all I know, all) Fortran-66 implementations would allow
>the above loop and would trip once.  

Definitely not all of them.  

Some disallowed it in the reference manual, but very few of these tried to 
enforce the rule.  Forbidden states are often undetectable, and vendor 
attitude often was that the user "got what he deserved".  (Predicting thus 
became a passtime; exploiting it became an art!)

Some did it once, some looped forever, some executed the loop an unexpected
number of times (like 32767-J), and some aborted after several trips.  A number
of processors did it the "right" way (in retrospect).

Control Data (among others) had a switch:  a "FORTRAN VI PROGRAM" allowed
zero-trip loops, as well as some other stuff like delimited strings and
continued END statements; a "FORTRAN IV PROGRAM" did it IBM's way; and a 
"FORTRAN II PROGRAM" had such things as "SQRTF" plus some funny rules for 
inadvertently extending common via EQUIVALENCE.  (It seemed like CDC came 
out with zero-trip first, then bowed to pressure; but I've never been sure.)

Of course, the most common processor implementation was the plunge-ahead loop 
(which was originally motivated by an IBM 701 opcode:  "TXH", I think.)

DEC vetoed the Fortran-77 standard largely because the (then-secret) design
for their forthcoming machine (later to be known as VAX) had a neat little
benchmark-busting loop instruction which assumed a one-trip minimum.


>...how small the -66 standard is, compared to the -77.

I know you're not complaining, but it's still a bad rap.  X3.9-1966 was
criticized as being insufficiently readable [until X3.53 (PL/I) came along,
to make it seem like "See Spot Run"].  

The revision effort (resulting in X3.9-1978) was consciously concerned with 
making the revised standard much more readable.  Hence it is much wordier 
even when saying the same thing.  Compare, for instance, the text describing 
format rescan, or some other feature that did not change.  Also, a fair 
comparison should include X3.10 standard.


	Cheers!

	    -/s/-					BAM
	Bruce A. Martin	
	Grumman Aircraft Systems 	[Address given for identification only.]
	(Mailstop B02-106)		[Every conceivable disclaimer applies!!]
	Bethpage, NY  11714		[Opinions are mine only, & will change,]
	 (516) 577-1426			[without notice, whenever appropriate!!]