Rust bandwagon
Rust bandwagon
Posted Jan 3, 2023 20:46 UTC (Tue) by Wol (subscriber, #4433)In reply to: Rust bandwagon by Wol
Parent article: Welcome to 2023
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
Posted Jan 7, 2023 9:31 UTC (Sat)
by joib (subscriber, #8541)
[Link] (1 responses)
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. :) ).
Posted Jan 7, 2023 17:25 UTC (Sat)
by Wol (subscriber, #4433)
[Link]
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,
Rust bandwagon
Rust bandwagon
Wol