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]

question about assumed shape arrays in gfortran



I'm re-sending this message to the list as it appears not to have got through. Hopefully, it won't end up with a duplicate post on the list.



While debugging a rather old Fortran 77 program which dimensioned arrays of
indeterminate size in subroutines with "(1)" (which is a fairly common practice
in older Fortran 77 programs and may actually be legal Fortran 77 although it
defeats using bounds-checking options in compilers, I think), I came across an
issue with assumed shape arrays.  I tried using Fortran 90 assumed shape arrays
in the code as I was compiling with gfortran which is a Fortran 90 compiler, of
course.  This caused a lot of crashes in the program which I thought may be due
to bugs in the program.  However, changing to Fortran 77 style assumed size
arrays (i.e. dimensioning with "(*)") appeared to get round these problems.  I
later wrote a short test program using assumed shape arrays  and this also
crashes.  If I have an additional code using "CONTAINS" then I find that the
program does not crash.  However, it seems that the simpler test program should
just work, so could this be a bug in the gfortran compiler?  The code for the
test program using an assumed shape array, but without "CONTAINS", etc is below:


program basictest C parameter (n=10) integer nums(n) C do i=1,n nums(i)=i enddo C call mysub(nums, n) C stop C end C C C subroutine mysub(nums, n) C integer, dimension(:) :: nums integer :: n C write(*, *) 'n: ',n do i=1, n write(*,*) nums(i) enddo C return C end


And below is the variant of the program with "CONTAINS", etc that compiles into an executable that does not crash:

        program basictest2
C
        parameter (n=10)
        integer  nums(n)
C
        do i=1,n
          nums(i)=i
        enddo
C
        call mysub(nums, n)
C
        stop
C
C
C
C
        contains
        subroutine mysub(nums, n)
C
        integer, dimension(:) :: nums
        integer :: n
C
        write(*, *) 'n: ',n
        do i=1, n
          write(*,*) nums(i)
        enddo
C
        return
C
         end subroutine
C
        end program basictest2


Assuming this behaviour of the gfortran compiler is a bug then it poses a problem for stepwise introduction of Fortran 90 code into old legacy Fortran 77 programs. (Actually I suppose it is a problem for upgrading programs from Fortran 77 to Fortran 90 whether or not the gfortran compiler is compliant with some Fortran standard.) The first program will also compile and run successfully without crashing if I change to assumed size arrays (i.e. replace the line "integer, dimension(:) :: nums" with "integer nums(*)".) It crashes if I use the alternative syntax for assumed shape arrays "integer :: nums(:)".

By the way, I have also posted the above question to the "help@gfortran.org"
list.  After further investigation it appears that fortran@gcc.gnu.org is the
one I want.  Does anybody know how the help@gfortran.org and
fortran@gcc.gnu.org lists differ in what sort of posts are expected?  Based on a
glance at the archives, it looks like fortran@gcc.gnu.org is much more active.
Also, it looks like a bug fix is more likely to result from posting to the
latter list although using Bugzilla is preferred based on what it says on the
page at http://gcc.gnu.org/fortran/ (or at least some page on that site),

William


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