- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a very simple question: What should a FORTRAN compiler do with a DO LOOP with an upper limit smaller than the lower limit and with a positive step?
I wrote a small code
program test_loop_1_0 integer :: i,imax imax=0 call loop(imax) end program c--------------------------- subroutine loop(imax) integer :: i,imax do i=1,imax PRINT*,"DBG",i enddo end subroutine loop
This code compiled with ifort shows that a DO i=1,0 ENDDO produces no iteration. Is this behavior written in the FORTRAN standards?
Thx a lot,
Best regards
Guillaume
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. it is the behavior defined in the fortran standard. For example, according to F2003 standard "8.1.6.4.1 Loop initiation" the loop iteration count of your code will be zero, then according to "8.1.6.4.2 The execution cycle" if the iteration count is zero the loop will terminate.
It is also written in Intel Fortran Compiler documentation at https://software.intel.com/en-us/node/579912
Thanks,
Xiaoping Duan
Intel Customer Support
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. it is the behavior defined in the fortran standard. For example, according to F2003 standard "8.1.6.4.1 Loop initiation" the loop iteration count of your code will be zero, then according to "8.1.6.4.2 The execution cycle" if the iteration count is zero the loop will terminate.
It is also written in Intel Fortran Compiler documentation at https://software.intel.com/en-us/node/579912
Thanks,
Xiaoping Duan
Intel Customer Support
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thx a lot for your quick reply!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This behavior has been required since the Fortran 77 standard. The original Fortran 66 standard didn't define trip count in this situation, although the most widely used compilers had the one-trip behavior, and programs were written frequently on that assumption.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page