[Bug fortran/33525] crash in if ( i .gt. 0 .and. a(i) .gt. 0 ) when a(0) is out of bounds

kargl at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Sep 21 23:03:00 GMT 2007



------- Comment #1 from kargl at gcc dot gnu dot org  2007-09-21 23:03 -------
The Fortran language does not guarantee the order of the
evaluation of the logical expression in your IF statement.
A fortran processor can try to evaluate "a(0) .gt. 0" before
the "i .gt. 0" expression.  Your code is broken and possibly
illegal Fortran.  Rewrite your code as you meant:

       i = 0
       if ( i .gt. 0) then
          if (a(i) .gt. 0 ) then
             i = i + 1
             write(*,*) i
          end if
       end if


-- 

kargl at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33525



More information about the Gcc-bugs mailing list