Allocatables in derived types and functions
- From: "Arno" <arnoinperu@xxxxxxxxxxx>
- Date: 11 Oct 2006 07:58:24 -0700
Dear all,
I am using derived types. To retrieve content from a derived type I
usually write a function rather than using the %-symbol. I reckon that
I can use the following function to extract 'i' from an object (assume
that i is properly allocated and set):
type my_obj
integer,dimension(:),allocatable :: i
end type my_obj
contains
!----------------------------------------------------------------------
function get_i(this) result(res)
type (my_obj),intent(in) :: this
integer,dimension(:),allocatable :: res
allocate(res(size(this%i)))
res = this%i
end function get_i
!----------------------------------------------------------------------
Now I was wondering if I am allowed to use this function as an argument
in a function call?
For example:
call write_i(get_i(object))
!----------------------------------------------------------------------
subroutine write_i(i)
integer,dimension(:),intent(in) :: i
write(*,*) i
end subroutine write_i
!----------------------------------------------------------------------
If I try this, it compiles and gives a the right results. However, in a
slightly more elaborate program it segfaults exactly at the write
statement. So, I was wondering if I am allowed to use these kind of
constructs. If so, I am happy to post the piece of code that crashes
(also not too many lines).
I am using the intel compiler (build 20060706). All seems to work with
g95.
Thanks,
Arno
.
- Follow-Ups:
- Re: Allocatables in derived types and functions
- From: Richard E Maine
- Re: Allocatables in derived types and functions
- From: Steve Lionel
- Re: Allocatables in derived types and functions
- Prev by Date: Re: Very small numbers & formatting
- Next by Date: Re: Allocatables in derived types and functions
- Previous by thread: the transfer of two dimension array
- Next by thread: Re: Allocatables in derived types and functions
- Index(es):
Relevant Pages
|