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:

  1. i'm not sure what's wrong code.
  2. where should allocate "low" component? in test_main or test_subroutine? word say, every component in pointer derived type need allocated before being passed?
  3. 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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -