allocate on assignment problem

marco restelli mrestelli@gmail.com
Wed Sep 3 22:44:00 GMT 2008


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?

Thank you,
   Marco Restelli


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



More information about the Fortran mailing list