This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Language lawyer question


Hi there, 
While preparing course notes I encountered the following problem. 
M&R state: "The number of iterations of a do construct is given bi the
formula
max((expr2-expr1+expr3)/expr3,0)"
Apply this to 
------------
  integer, parameter :: ik1=selected_int_kind(2)
  integer(kind=ik1)  :: i, j

  print *, 'Integer kind ',ik1, huge(i)
  i=j-(-j)+1
  print *, i
  do i=-j,j
     ! do something
  enddo
----------
With gfortran on i686 linux I get ik1=1 and huge(ik1)=127, after the
assignment  I get i=-125, and yet the do loop is executed. 
Which can only be interpreted as if in the do loop iteration count
calculations the result is promoted to a KIND greater than that of i,j. 
Is this correct behaviour, wrong, or unspecified by the standard? 
Thanks in advance

-- 
Salvatore Filippone <sfilippone@uniroma2.it>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]