Dear all,
I’m trying to use a modified version of an old fortran program (I believe at first it was written in fortran 77 or older), on linux (Fedora 40, x86_64).
The program works fine when compiled using Intel ifx/ifort 2024.2, but does NOT when compiled with gfortran 14.2.1 20240912 (Red Hat 14.2.1-3).
The program uses deferred-length arrays of real, integer and character. Inspecting with a debugger (gdb), it seems to me that the allocation of, or the assignment to the deferred-length character arrays do not work when compiled with gfortran (deferred-length integer/real arrays work properly):
ptype
ing returnstype = Type End Type
- elements of the array are emtpy after assignments.
Compiled using ifort, ptype
on the same character array returns, say, type = character*6, allocatable (8,3)
or something like that.
The attached program (defchararr.f90
) and module (arraymod.f90
) contains the essence of the corresponding routines in the failed program (although these are embedded several layers below the main routine). Strange enough, when the attached program is compiled using gfortran, the assignment works OK (and prints “ahoaho”) although ptype
ing over the array shows nothing (the same as above, that is, type = Type
and End Type
(with ifx/ifort, ptype
returns type = character*6, allocatable (8,3)
and it also prints “ahoaho”).
Could someone suggest me what’s wrong with the failed program and how I can fix it? Are there any restrictions on the use of the deferred-length character arrays? (I’m an old-time fortran (77) user and the knowledge on the modern standards is very limited…)
As I’m new to this discourse group I can not upload files, I’ll show the contents of defchararr.f90
below.
Thanks in advance.
Kazuyoshi
defchararr.f90:
program defchararr
use arraymod
character*6 aho
call aloc_arr(3)
chararr(1,1)=aho()
print *, chararr(1,1)
end program defchararr
character*6 function aho()
aho="ahoaho"
return
end function aho
arraymod.f90:
module arraymod
parameter(num=8)
character(len=:), allocatable :: chararr(:,:)
contains
subroutine aloc_arr(nregs)
allocate(character(len=6) :: chararr(num,nregs))
end subroutine aloc_arr
end module arraymod