This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Language lawyer question
- From: Salvatore Filippone <sfilippone at uniroma2 dot it>
- To: fortran at gcc dot gnu dot org
- Date: Tue, 15 Feb 2005 15:08:40 +0100
- Subject: 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>