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] |
$ gfc basictest1.f basictest1.f:9.18:
-------- Original Message -------- Subject: [Help] question about assumed shape arrays in gfortran Date: Mon, 4 Apr 2011 07:21:40 -0700 (PDT) From: William Nicholson <william_v_nicholson@yahoo.com> To: help@gfortran.org
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(:)",
Attachment:
Attached Message Part
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |