fortran - Where should I allocate a pointer? -
ok..i edited whole question again.
in test_module, there's type "body" consists of array of pointers.
in test_subroutine, want input real number , output pointer instance of type "body".
i compiled , ran following code, got runtime error - "segmentation fault - invalid memory reference". questions are:
- i'm not sure what's wrong code.
- where should allocate "low" component? in test_main or test_subroutine? word say, every component in pointer derived type need allocated before being passed?
- how debug these memory bugs? tried gdb didn't enough useful info it.
test_module.f90
module test_module implicit none type body real,pointer :: low(:) => null() end type end module test_module
test_subroutine.f90
subroutine test_subroutine(input,output) use test_module implicit none real,intent(in) :: input type(body),pointer,intent(out) :: output !allocate(output%low(3)) ! put it? output%low = (/1,2,3/) end subroutine test_subroutine
test_main.f90
program test_main use test_module implicit none type(body),pointer :: sample(:) => null() allocate(sample(2)) allocate(sample(1)%low(3)) allocate(sample(2)%low(3)) call test_subroutine(1.0,sample(1)) end program test_main
Comments
Post a Comment