|
|
Subscribe / Log in / New account

Rust bandwagon

Rust bandwagon

Posted Jan 3, 2023 20:26 UTC (Tue) by Wol (subscriber, #4433)
In reply to: Rust bandwagon by fenncruz
Parent article: Welcome to 2023

So I remembered incorrectly, BUT.

FORTRAN *would* execute the body of the loop. Once.

Fortran, as you say, wouldn't.

(Unless you use compiler specific extensions - the F77 compiler I used had a switch to enable the old FTN behaviour.)

I'm old enough to remember the difference between FORTRAN and Fortran :-) I've never heard of fortran.

Cheers,
Wol


to post comments

Rust bandwagon

Posted Jan 3, 2023 20:46 UTC (Tue) by Wol (subscriber, #4433) [Link] (2 responses)

Whoops, I think I'm misleading myself slightly (but my point still stands) ...

DO I=10,1 would probably do an implicit STEP -1

J=10
K=1
DO I=K,J would not execute in Fortran, but would execute once with I set to 10 in FORTRAN.

Cheers,
Wol

Rust bandwagon

Posted Jan 7, 2023 9:31 UTC (Sat) by joib (subscriber, #8541) [Link] (1 responses)

In Fortran 66 (the first published 'official' standard) zero trip DO loops are indeed not possible, but that is enforced via the requirement that for the DO statement

DO I=m1, m2

then m1 must be <= m2. So the loop in your example is invalid. You're most likely describing some compiler-specific extension (or accidental behavior later documented by the compiler developers as expected behavior. :) ).

Rust bandwagon

Posted Jan 7, 2023 17:25 UTC (Sat) by Wol (subscriber, #4433) [Link]

Actually, I suspect I'm describing the normal behaviour of FORTRAN IV ... :-)

Fortran allows a lot of (specified) behaviour in the name of optimisation, that can lead to unexpected results. Like storing the index of a do loop in a register, such that it can only safely be read, and not relied on when the loop exits. It seems highly likely that most FORTRAN compilers (and certainly the one I was using in 1983, iirc) did not bother to check the loop limits. Given that I understood that FORTRAN explicitly said the index,limit check was done at the *end* of the loop, I would be surprised if there was a special check on entering the loop.

When Fortran moved the check to the start of the loop, then it makes sense that loops can execute zero times.

Cheers,
Wol


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds