This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CLASS array patch latest


Hello,

2011/11/13 Paul Richard Thomas <paul.richard.thomas@gmail.com>:

> ?subroutine reallocate (a)
> ? ?class(base_type), dimension(:), allocatable, intent(inout) :: a
> ? ?class(base_type), dimension(:), allocatable :: tmp
>
> ? ?allocate (tmp (2 * size (a))) ! how to alloc b with same type as a ?
>
> ! This is one way how!
> ! ? ?select type (a)
> ! ? ? ?type is (base_type); ? ? ?allocate (base_type :: tmp (2 * size (a)))
> ! ? ? ?type is (extended_type); ?allocate (extended_type :: tmp (2 * size (a)))
> ! ? ?end select
>

You can use the source= keyword, can't you?

allocate( tmp(2*size(a), source = a(1) )

(I think the a(1) is required, as the contents of a are copied)

Regards,

Arjen


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]