- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This do loop example has NO passes thru it.
dk4=100000000
khi4=huge(k4)/2 ! nowhere near upper limit
klo4=-khi4 ! nowhere near lower limit
kount=(khi4-klo4)/dk4+1
print *,"klo,hi=",klo4,khi4," kount 4=",kount
do k4=klo4,khi4,dk4
print *,"k4=",k4
enddo
It gives the correct result (22) for KOUNT, but the compiler apparently gives ZERO for the same thing.
All variables are integer(4)
Link Copied
- « Previous
-
- 1
- 2
- Next »
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I agree that having a non-integer for the LOOP index variable is pretty awkward.
My understanding of a "scalar" is a non-array, i.e. you cannot have DO i(3) = i1,i2,10
It would be pretty easy for the compiler to just skip over the DO LOOP if STOP < START, regardless of what expressions
were used.
However, for the START, STOP, and STEP values, you can still have integer expressions.
And those parameters can be in arrays, as well.
We still have a problem when STOP - START > Huge() though, unless one uses a higher # of bytes
for the calculation. For 1 and 2 byte LOOP values, INTEL apparently uses 4 byte arithmetic.
I have seen code examples where you can vary the parameters inside the DO LOOP, and the compiler does NOT
complain. Wouldn't that give unpredictable results?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The compiler does not complain? Got an example?
C:\Projects>type t.f90 do i=1,10 i = i + 1 print *, i end do end C:\Projects>ifort t.f90 Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Version 15.0.2.179 Build 20150121 Copyright (C) 1985-2015 Intel Corporation. All rights reserved. t.f90(2): error #8093: A do-variable within a DO body shall not appear in a variable definition context. i = i + 1 ^ compilation aborted for t.f90 (code 1)
In the case where the compiler can't be sure if you modified the variable, it will generate alternate code that tests the variable rather than a count. Since it can't see if you did the modification, it doesn't warn.
If you mean changing the start or end values after the loop starts, that has no effect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was referring to the LOOP PARAMETERS, not the index variable.
Meddling with those inside the loop doesn't make much sense - -
Are you saying there is a way to TEST the INDEX on each step?
(other than coding it myself, that is)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Meddling with the loop parameters inside the loop does nothing useful, as they are not looked at again.
What I meant was that the compiler might choose to do a test rather than use a count, if it feels it is appropriate/optimal. You don't have control over this. Perhaps you want DO WHILE.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- « Previous
-
- 1
- 2
- Next »