Hi fortran gurus !
After several hours of head-scratching, I found a strange behaviour
of my fortran compilers against arrays of size 0.
I reduced the problem to the source code below.
In fortran 90, one can allocate an array with a size of 0.
What I understand is that, on this zero-size array,
the "allocated" intrinsic answers "T" and the "size" intrinsic answers
0.
In my case, this situation appears because of a recursive function,
because the algorithm is based on a "divide and conquer" method.
What I do not understand is why the zero-size array of the following
code appears to be un-allocated only with gfortran compiler,
although I know that it really is allocated !
module testmod
type, public :: t_type
character(LEN=3D1), dimension(:), allocatable :: chars
end type t_type
contains
recursive function recursivefunc ( this ) result ( match )
type(t_type), intent(in) :: this
type(t_type) :: subpattern
logical :: thisalloc
integer :: thislength
logical :: match
thisalloc =3D allocated ( this % chars )
if ( .NOT. thisalloc ) then
write ( 6 , * ) "STOP with error !"
stop
endif
thislength =3D size ( this % chars )
if ( thislength =3D=3D 0 ) then
match =3D .true.
return
endif
allocate ( subpattern % chars (0) )
match =3D recursivefunc ( subpattern )
end function recursivefunc
end module testmod
program testprog
use testmod
implicit none
type(t_type) :: this
logical :: match
allocate ( this % chars ( 10 ))
match =3D recursivefunc ( this )
print * , "match :", match
end program testprog
What I don't understand is that my code does not behave the
same with g95, gfortran and IVF 8.0.
With gfortran :
> gfortran test.f90 -o test.exe
> test.exe
STOP with error !
With g95 :
> g95 test.f90 -o test.exe
> test.exe
match : T
Intel Visual Fortran 8 exhibits the same behaviour as g95.
In fact, I don't really known what the fortran 90 standard says about
0-size arrays ?
Any help will be appreciated.
Best regards,
Micha=EBl


|