allocate on assignment problem

Daniel Kraft d@domob.eu
Thu Sep 4 07:13:00 GMT 2008


marco restelli wrote:
> Dear list,
>    the attached code compiles with gfortran but produces segmentation
> fault at execution. Is this a gfortran problem in the allocation on
> assignment or is it me missing something?

Hi Marco,

I don't think allocation on assignment is implemented in gfortran, see 
http://gcc.gnu.org/wiki/Fortran2003Status and thus you would try to 
write into an unallocated array and cause the segfault.  I'm not 100% 
sure about this, however.

Cheers,
Daniel

> gfortran -v
> Using built-in specs.
> Target: x86_64-unknown-linux-gnu
> Configured with: /projects/tob/gcc/configure
> --with-gmp-lib=/projects/tob/gcc-build/lib-aux
> --with-mpfr-lib=/projects/tob/gcc-build/lib-aux
> --enable-languages=c,fortran --prefix=/projects/tob/gcc-trunk
> Thread model: posix
> gcc version 4.4.0 20080902 (experimental) [trunk revision 139884] (GCC)
> 
> 
> module my_mod
> 
>   implicit none
> 
>  contains
> 
>   function my_fun(n) result(y)
>     integer, intent(in) :: n
>     real, allocatable :: y(:)
> 
>     integer :: i
> 
>     allocate(y(n))
>     y = (/ (real(i),i=1,n) /)
> 
>   end function my_fun
> 
> end module my_mod
> 
> 
> program test_all
> 
>   use my_mod
> 
>   implicit none
> 
>   real, allocatable :: ps(:)
> 
>   !allocate(ps(4))
>   ps = my_fun(4)
> 
>   write(*,*) ps
> 
> end program test_all
> 


-- 
Done:     Arc-Bar-Cav-Sam-Val-Wiz, Dwa-Elf-Gno-Hum-Orc, Law-Neu-Cha, Fem-Mal
To go:    Hea-Kni-Mon-Pri-Ran-Rog-Tou



More information about the Fortran mailing list