I am getting unreliable results from a small function using the latest
prepackaged Mac OS build (PPC) available from the wiki download page.  The
function behaves correctly if an otherwise irrelevant write statement is added.
 When the statement is removed, the function returns gibberish.  This is
ancient code which worked on older versions of gfortran, so hopefully I haven't
overlooked an obvious problem...

$ uname -a
Darwin Numenor 9.5.0 Darwin Kernel Version 9.5.0: Wed Sep  3 11:29:43 PDT 2008;
root:xnu-1228.7.58~1/RELEASE_I386 i386

$ gfortran --version
GNU Fortran (GCC) 4.4.0 20080823 (experimental) [trunk revision 139508]

$ cat xx.f
        program xx
        real xa(102)
        do 10 i=1,100
10      xa(i)=float(i)
        call scale (xa,23.,100,1)
        write (*,*) xa(101), xa(102)        
        end


        subroutine scale(arr,axlen,npts,kcycle)
        real :: arr(*),axlen,minval,maxval,val
        integer :: npts,kcycle
        minval = +INF
        maxval = -INF
        do i=0,npts-1
                val=arr(1+kcycle*i)
                minval=amin1(val,minval)
                maxval=amax1(val,maxval)
        end do
        arr(npts*kcycle+1)=minval
        arr(npts*kcycle+kcycle+1)=(maxval-minval)/axlen
c       If the following line is uncommented, the function will work
c       write (*,*) 3
        end subroutine scale


# Correct function result (write statement is left in)
$ gfortran -o xx xx.f
$ xx
           3
   0.0000000       4.3478260    

# Incorrect function result (write statement is commented out)
$ gfortran -o xx xx.f
$ xx
 -2.13906214E+09  1.86005408E+08


-- 
           Summary: Inconsistent function results depending on irrelevant
                    write statement
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dojo at masterleep dot com


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

Reply via email to